Skip to content

Commit 456722b

Browse files
committed
Aaaaand, one last fix for using b-c-ts 2.0 correctly.
1 parent 3e4382e commit 456722b

File tree

4 files changed

+47
-37
lines changed

4 files changed

+47
-37
lines changed

blueprints/ember-cli-typescript/files/tsconfig.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
"moduleResolution": "node",
66
"noEmitOnError": false,
77
"noEmit": true,
8-
"baseUrl": ".",
9-
"outDir": "dist",
108
"sourceMap": true,
9+
"baseUrl": ".",
1110
"paths": {
1211
"<%= dasherizedPackageName %>/tests/*": ["tests/*"],
1312
"<%= dasherizedPackageName %>/*": ["app/*"]
1413
}
1514
},
16-
"include": [
17-
"app/**/*",
18-
"tests/**/*"
15+
"exclude": [
16+
"tmp",
17+
"dist",
18+
"node_modules",
19+
"bower_components"
1920
]
2021
}

index.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,7 @@ try {
1414
module.exports = {
1515
name: 'ember-cli-typescript',
1616

17-
included(app) {
18-
this._super.included.apply(this, arguments);
19-
this.app = app;
20-
},
21-
22-
blueprintsPath() {
23-
return path.join(__dirname, 'blueprints');
24-
},
25-
26-
setupPreprocessorRegistry: function(type, registry) {
17+
setupPreprocessorRegistry(type, registry) {
2718
if (!TsPreprocessor) {
2819
this.ui.write(
2920
'Note: TypeScript preprocessor not available -- some dependencies not installed. ' +
@@ -34,8 +25,7 @@ module.exports = {
3425
}
3526

3627
try {
37-
const plugin = new TsPreprocessor({ includeExtensions: ['.ts', '.js'] });
38-
registry.add('js', plugin);
28+
registry.add('js', new TsPreprocessor());
3929
} catch (ex) {
4030
this.ui.write(
4131
'Missing or invalid tsconfig.json, please fix or run `ember generate ember-cli-typescript`.'

lib/typescript-preprocessor.js

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,59 @@
11
/* eslint-env node */
2+
const fs = require('fs');
3+
const path = require('path');
24

35
const debug = require('debug')('ember-cli-typescript');
4-
const Funnel = require('broccoli-funnel');
5-
const MergeTrees = require('broccoli-merge-trees');
6+
const funnel = require('broccoli-funnel');
7+
const mergeTrees = require('broccoli-merge-trees');
68
const tsc = require('broccoli-typescript-compiler').typescript;
79

10+
const BroccoliDebug = require('broccoli-debug');
11+
12+
let tag = 0;
13+
814
class TypeScriptPreprocessor {
915
constructor(options) {
10-
debug('creating new instance with options ', options);
1116
this.name = 'ember-cli-typescript';
12-
this.ext = 'ts';
13-
this.options = JSON.parse(JSON.stringify(options));
17+
this._tag = tag++;
18+
19+
// Update the config for how Broccoli handles the file system: no need for
20+
// includes, always emit, and let Broccoli manage any outDir.
21+
this.config = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'tsconfig.json')));
22+
this.config.compilerOptions.noEmit = false;
23+
delete this.config.compilerOptions.outDir;
24+
delete this.config.include;
1425
}
1526

16-
toTree(inputNode /* , inputPath, outputPath */) {
17-
const js = new Funnel(inputNode, {
27+
toTree(inputNode, inputPath, outputPath) {
28+
const js = funnel(inputNode, {
1829
exclude: ['**/*.ts'],
1930
annotation: 'JS files',
2031
});
2132

22-
const tsFiles = new Funnel(inputNode, {
23-
include: ['**/*.ts'],
24-
annotation: 'TS files',
25-
});
33+
const debugTree = BroccoliDebug.buildDebugCallback('ember-cli-typescript');
2634

27-
const ts = tsc(tsFiles, {
28-
annotation: 'Compiled TS files',
29-
compilerOptions: {
30-
allowJs: false, // don't compile JS here; let Babel manage that
31-
noEmit: false, // we *must* emit for Broccoli to do its thing
32-
},
33-
});
35+
const uncompiledTs = debugTree(
36+
funnel(inputNode, {
37+
include: ['**/*.ts'],
38+
annotation: 'uncompiled TS files',
39+
}),
40+
`${this._tag}`
41+
);
42+
43+
const ts = debugTree(
44+
tsc(uncompiledTs, {
45+
throwOnError: true,
46+
annotation: 'Compiled TS files',
47+
include: ['**/*'],
48+
tsconfig: this.config,
49+
}),
50+
`${this._tag}`
51+
);
3452

3553
// Put everything together.
36-
return new MergeTrees([js, ts], {
54+
return mergeTrees([js, ts], {
3755
overwrite: true,
38-
annotation: 'compiled TypeScript',
56+
annotation: 'merged JS & compiled TS',
3957
});
4058
}
4159
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"test": "ember try:each"
2929
},
3030
"dependencies": {
31+
"broccoli-debug": "^0.6.3",
3132
"broccoli-funnel": "^1.0.6",
3233
"broccoli-merge-trees": "^1.1.4",
3334
"broccoli-plugin": "^1.2.1",

0 commit comments

Comments
 (0)