Skip to content

Commit 8bc3be7

Browse files
authored
Merge pull request #132 from typed-ember/app-file-precedence
Expose app files via a preprocessor so they take precedence
2 parents 264585b + e4d4a19 commit 8bc3be7

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
'use strict';
33

44
const IncrementalTypescriptCompiler = require('./lib/incremental-typescript-compiler');
5+
const Funnel = require('broccoli-funnel');
6+
const MergeTrees = require('broccoli-merge-trees');
57

68
module.exports = {
79
name: 'ember-cli-typescript',
@@ -24,6 +26,24 @@ module.exports = {
2426
}
2527
},
2628

29+
setupPreprocessorRegistry(type, registry) {
30+
if (type !== 'parent') {
31+
return;
32+
}
33+
34+
registry.add('js', {
35+
name: 'ember-cli-typescript',
36+
toTree: (original, inputPath, outputPath) => {
37+
if (!this.compiler || inputPath !== '/') {
38+
return original;
39+
}
40+
41+
let ts = new Funnel(this.compiler.treeForHost(), { destDir: outputPath });
42+
return new MergeTrees([original, ts], { overwrite: true });
43+
},
44+
});
45+
},
46+
2747
treeForApp() {
2848
if (this.compiler) {
2949
let tree = this.compiler.treeForApp();

lib/incremental-typescript-compiler.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,7 @@ module.exports = class IncrementalTypescriptCompiler {
3838
this._didAutoresolve = false;
3939
}
4040

41-
treeForApp() {
42-
// This could be more efficient, but we can hopefully assume there won't be dozens
43-
// or hundreds of TS addons in dev mode all at once.
44-
// Using node-merge-trees in the TypescriptOutput plugin would allow for mappings
45-
// like { foo: 'out', bar: 'out' } so we'd only need one Broccoli node for this.
46-
let addonAppTrees = this.addons.map(addon => {
47-
return new TypescriptOutput(this, {
48-
[`${this._relativeAddonRoot(addon)}/app`]: 'app',
49-
});
50-
});
51-
41+
treeForHost() {
5242
let triggerTree = new Funnel(this._triggerDir, { destDir: 'app' });
5343

5444
let appTree = new TypescriptOutput(this, {
@@ -60,10 +50,23 @@ module.exports = class IncrementalTypescriptCompiler {
6050
[mirage]: 'app/mirage',
6151
});
6252

63-
let tree = new MergeTrees(addonAppTrees.concat([triggerTree, appTree, mirageTree].filter(Boolean)), { overwrite: true });
53+
let tree = new MergeTrees([triggerTree, mirageTree, appTree].filter(Boolean), { overwrite: true });
6454
return new Funnel(tree, { srcDir: 'app' });
6555
}
6656

57+
// Returns any developing addons' app trees. Note that the host app itself is managed
58+
// by treeForHost() above, as it needs to be treated specially by the build to always
59+
// 'win' when the host and an addon have clashing files.
60+
treeForApp() {
61+
let addonAppTrees = this.addons.map(addon => {
62+
return new TypescriptOutput(this, {
63+
[`${this._relativeAddonRoot(addon)}/app`]: 'app',
64+
});
65+
});
66+
67+
return new MergeTrees(addonAppTrees, { overwrite: true });
68+
}
69+
6770
treeForAddons() {
6871
let paths = {};
6972
for (let addon of this.addons) {

0 commit comments

Comments
 (0)