Skip to content

Commit 9592fd3

Browse files
committed
fix: delay addon discovery until we know it will be needed (i.e. the addon will be built)
This allows us to always load devDeps as addons. We used to only load devDeps for root builders, but that becomes problematic for addons that are build on the fly, i.e. symlinked or git dep addons. SO now we always load devDeps for an addon that is being built, since if the addon its being built, it will likely need any devDep addons like language compilers
1 parent 43f3e4f commit 9592fd3

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

lib/builders/base.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default class BaseBuilder {
6767

6868
unitTestDir = path.join('test', 'unit');
6969

70-
packageFiles = [ 'package.json' ];
70+
packageFiles: string[] = [];
7171

7272
private _cachedTree: Tree;
7373

@@ -91,22 +91,22 @@ export default class BaseBuilder {
9191
this.debug = createDebug(`denali-cli:builder:${ this.logicalDependencyPath.join('>') }`);
9292
this.debug(`created builder for ${ this.pkg.name }@${ this.pkg.version }`);
9393

94-
this.addons = this.discoverAddons();
9594
}
9695

9796
/**
9897
* Look for addons in the node_modules folder. Only search packages explicitly
9998
* mentioned in package.json, and look for the `denali-addon` keyword in their
10099
* package.json's. Then create a Builder for each one.
101100
*/
102-
protected discoverAddons(): AddonBuilder[] {
101+
protected discoverAddons(options: { include: string[] } = { include: [] }): AddonBuilder[] {
103102
this.debug(`searching for child addons in ${ this.dir }`);
104103
return findPlugins({
105104
dir: this.dir,
106105
keyword: 'denali-addon',
107106
sort: true,
108-
includeDev: !this.parent, // only include devdeps if this is the root builder
109-
configName: 'denali'
107+
includeDev: true,
108+
configName: 'denali',
109+
include: options.include
110110
}).map((addon) => {
111111
this.debug(`discovered child addon: ${ addon.pkg.name }`);
112112
return <AddonBuilder>BaseBuilder.createFor(addon.dir, this.environment, this);
@@ -134,6 +134,7 @@ export default class BaseBuilder {
134134
* Assemble the main build pipeline
135135
*/
136136
assembleTree() {
137+
this.addons = this.discoverAddons();
137138
let baseTree = this.toBaseTree();
138139
let finalTrees: Tree[] = [];
139140

lib/builders/dummy.ts

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
import * as path from 'path';
2+
import * as fs from 'fs';
3+
import * as assert from 'assert';
24
import AppBuilder from './app';
35
import AddonBuilder from './addon';
46
import * as MergeTree from 'broccoli-merge-trees';
7+
import * as writeFile from 'broccoli-file-creator';
58
import * as Funnel from 'broccoli-funnel';
69

710
export default class DummyBuilder extends AppBuilder {
811

12+
packageFiles = [ 'package.json' ];
13+
914
addonBuilderUnderTest: AddonBuilder;
1015

16+
get addonDirUnderTest() {
17+
return path.join(this.dir, '..', '..');
18+
}
19+
1120
discoverAddons(): AddonBuilder[] {
12-
let addons = super.discoverAddons();
21+
let addons = super.discoverAddons({ include: [ this.addonDirUnderTest ] });
1322
this.flagAddonUnderTest(addons);
1423
return addons;
1524
}
@@ -23,8 +32,8 @@ export default class DummyBuilder extends AppBuilder {
2332
* We should find a better way to detect the addon under test.
2433
*/
2534
protected flagAddonUnderTest(addons: AddonBuilder[]) {
26-
let dirForAddonUnderTest = path.join(this.dir, '..', '..');
27-
this.addonBuilderUnderTest = addons.find((addonBuilder) => addonBuilder.dir === dirForAddonUnderTest);
35+
this.addonBuilderUnderTest = addons.find((addonBuilder) => addonBuilder.dir === this.addonDirUnderTest);
36+
assert(this.addonBuilderUnderTest, 'Unable to find the builder for the addon under test');
2837
this.addonBuilderUnderTest.underTest = true;
2938
}
3039

@@ -51,11 +60,14 @@ export default class DummyBuilder extends AppBuilder {
5160
// should work automatically, since node will walk up from tmp/-dummy to
5261
// find the addon's real node_modules folder, and check there. But this
5362
// won't work for the addon itself, hence:
63+
let addonPackageFiles = [ 'denali-build.js', 'package.json' ].map((file) => {
64+
return writeFile(path.join('node_modules', this.addonBuilderUnderTest.pkg.name, file), fs.readFileSync(path.join(this.addonBuilderUnderTest.dir, file), 'utf-8'));
65+
});
5466
let compiledAddon = new Funnel(addonTree, {
5567
exclude: [ 'test' ],
56-
destDir: `node_modules/${this.addonBuilderUnderTest.pkg.name}`
68+
destDir: `node_modules/${this.addonBuilderUnderTest.pkg.name}/dist`
5769
});
58-
return new MergeTree([ tree, addonTests, compiledAddon ], { annotation: 'merge addon tests into dummy' });
70+
return new MergeTree([ tree, addonTests, ...addonPackageFiles, compiledAddon ], { overwrite: true, annotation: 'merge addon tests into dummy' });
5971
}
6072

6173
}

0 commit comments

Comments
 (0)