Skip to content

Commit c109389

Browse files
authored
Merge pull request #62 from simonihmig/better-fatal-error
Throw SilentError when preprocessor could not be instantiated
2 parents 62a6d8e + cc2e35f commit c109389

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

index.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
/* eslint-env node */
22

3-
let TsPreprocessor;
4-
try {
5-
TsPreprocessor = require('./lib/typescript-preprocessor');
6-
} catch (ex) {
7-
// Do nothing; we just won't have the plugin available. This means that if you
8-
// somehow end up in a state where it doesn't load, the preprocessor *will*
9-
// fail, but this is necessary because the preprocessor depends on packages
10-
// which aren't installed until the
11-
}
3+
const fs = require('fs');
4+
const path = require('path');
5+
const SilentError = require('silent-error');
6+
const TsPreprocessor = require('./lib/typescript-preprocessor');
7+
128

139
module.exports = {
1410
name: 'ember-cli-typescript',
1511

1612
setupPreprocessorRegistry(type, registry) {
17-
if (!TsPreprocessor) {
18-
this.ui.write(
19-
'Note: TypeScript preprocessor not available -- some dependencies not installed. ' +
20-
'(If this is during installation of the add-on, this is as expected. If it is ' +
21-
'while building, serving, or testing the application, this is an error.)'
13+
if (!fs.existsSync(path.join(this.project.root, 'tsconfig.json'))) {
14+
// Do nothing; we just won't have the plugin available. This means that if you
15+
// somehow end up in a state where it doesn't load, the preprocessor *will*
16+
// fail, but this is necessary because the preprocessor depends on packages
17+
// which aren't installed until the default blueprint is run
18+
19+
this.ui.writeInfoLine(
20+
'Skipping TypeScript preprocessing as there is no tsconfig.json. ' +
21+
'(If this is during installation of the add-on, this is as expected. If it is ' +
22+
'while building, serving, or testing the application, this is an error.)'
2223
);
2324
return;
2425
}
@@ -28,10 +29,7 @@ module.exports = {
2829
ui: this.ui
2930
}));
3031
} catch (ex) {
31-
this.ui.write(
32-
'Missing or invalid tsconfig.json, please fix or run `ember generate ember-cli-typescript`.'
33-
);
34-
this.ui.write(' ' + ex.toString());
32+
throw new SilentError(`Failed to instantiate TypeScript preprocessor, probably due to an invalid tsconfig.json. Please fix or run \`ember generate ember-cli-typescript\`.\n${ex}`);
3533
}
3634
},
3735
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"broccoli-stew": "^1.4.0",
3838
"broccoli-typescript-compiler": "^2.0.0",
3939
"debug": "^2.2.0",
40-
"ember-cli-babel": "^6.3.0"
40+
"ember-cli-babel": "^6.3.0",
41+
"silent-error": "^1.1.0"
4142
},
4243
"devDependencies": {
4344
"@types/ember": "^2.7.43",

0 commit comments

Comments
 (0)