Skip to content

Commit cafed5b

Browse files
committed
🙈
1 parent 65e8792 commit cafed5b

File tree

5 files changed

+47
-49
lines changed

5 files changed

+47
-49
lines changed

‎index.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,12 @@ module.exports = {
197197

198198
let docsTree = new MergeTrees(docsTrees);
199199

200-
let searchIndexInput = new MergeTrees([docsTree]);
201-
let searchIndexTree = new SearchIndexer(searchIndexInput, {
200+
let templateContentsTree = this.getBroccoliBridge().placeholderFor('template-contents');
201+
let searchIndexTree = new SearchIndexer(new MergeTrees([docsTree, templateContentsTree]), {
202202
outputFile: 'ember-cli-addon-docs/search-index.json',
203203
config: this.project.config(EmberApp.env())
204204
});
205205

206-
this.getBroccoliBridge().register({
207-
name: 'search-index-input',
208-
tree: searchIndexInput,
209-
dependencies: ['template-contents']
210-
});
211-
212206
return new MergeTrees([ defaultTree, docsTree, searchIndexTree ]);
213207
},
214208

‎lib/broccoli/bridge.js

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,60 @@
1+
const Plugin = require('broccoli-plugin');
2+
const symlinkOrCopy = require('symlink-or-copy');
3+
const fs = require('fs-extra');
4+
15
module.exports = class Bridge {
26
constructor() {
37
this._members = new Map();
48
}
59

6-
register({ name, tree, dependencies = [] }) {
10+
fulfill(name, tree) {
711
if (this._members.has(name)) {
8-
throw new Error(`Duplicate tree '${name}' in bridge.`);
9-
}
10-
11-
let newMember = new Member(name, tree, dependencies);
12-
13-
for (let existingMember of this._members.values()) {
14-
newMember.link(existingMember);
15-
existingMember.link(newMember);
12+
let existing = this._members.get(name);
13+
if (existing instanceof Placeholder) {
14+
existing.fulfill(tree);
15+
} else {
16+
throw new Error(`A tree named '${name}' was already registered with this Bridge instance.`);
17+
}
18+
} else {
19+
this._members.set(name, tree);
1620
}
17-
18-
this._members.set(name, newMember);
19-
this._patchBuild(name, tree);
2021
}
2122

22-
_patchBuild(name, tree) {
23-
if (typeof tree.build !== 'function') return;
24-
25-
let { dependencies } = this._members.get(name);
26-
let oldBuild = tree.build.bind(tree);
27-
tree.build = () => {
28-
if (dependencies.size > 0) {
29-
throw new Error(`Tree '${name}' is missing dependencies: ${[...dependencies].join(',')}`);
30-
}
31-
32-
return oldBuild();
33-
};
23+
placeholderFor(name) {
24+
if (this._members.has(name)) {
25+
return this._members.get(name);
26+
} else {
27+
let placeholder = new Placeholder(name);
28+
this._members.set(name, placeholder);
29+
return placeholder;
30+
}
3431
}
3532
}
3633

37-
class Member {
38-
constructor(name, tree, dependencies) {
39-
this.name = name;
40-
this.tree = tree;
41-
this.dependencies = new Set(dependencies);
34+
class Placeholder extends Plugin {
35+
constructor(name) {
36+
super([]);
37+
this.name;
38+
this._hasLinked = false;
4239
}
4340

44-
needs(dep) {
45-
return this.dependencies.has(dep.name);
41+
fulfill(tree) {
42+
if (this._inputNodes.length) {
43+
throw new Error(`BroccoliBridge placeholder '${this.name}' was fulfilled more than once.`);
44+
}
45+
46+
this._inputNodes.push(tree);
4647
}
4748

48-
link(dep) {
49-
if (this.needs(dep)) {
50-
this.dependencies.delete(dep.name);
51-
this.tree._inputNodes.push(dep.tree);
49+
build() {
50+
if (!this._inputNodes.length) {
51+
throw new Error(`BroccoliBridge placeholder '${this.name}' was never fulfilled.`);
52+
}
53+
54+
if (!this._hasLinked) {
55+
fs.removeSync(this.outputPath);
56+
symlinkOrCopy.sync(this.inputPaths[0], this.outputPath);
57+
this._hasLinked = true;
5258
}
5359
}
5460
}

‎lib/preprocessors/hbs-content-extractor.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ module.exports = class HBSContentExtractor {
1010
}
1111

1212
toTree(tree) {
13-
this._bridge.register({
14-
name: 'template-contents',
15-
tree: new HBSContentFilter(tree),
16-
});
17-
13+
let contentsTree = new HBSContentFilter(tree);
14+
this._bridge.fulfill('template-contents', contentsTree);
1815
return tree;
1916
}
2017
};

‎package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"resolve": "^1.5.0",
7272
"semver": "^5.5.0",
7373
"striptags": "^3.1.1",
74+
"symlink-or-copy": "^1.2.0",
7475
"walk-sync": "^0.3.2",
7576
"yuidocjs": "^0.10.2"
7677
},

‎yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8620,7 +8620,7 @@ [email protected]:
86208620
version "3.2.2"
86218621
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.2.tgz#ae27db38f660a7ae2e1c3b7d1bc290819b8519e6"
86228622

8623-
symlink-or-copy@^1.0.0, symlink-or-copy@^1.0.1, symlink-or-copy@^1.1.8:
8623+
symlink-or-copy@^1.0.0, symlink-or-copy@^1.0.1, symlink-or-copy@^1.1.8, symlink-or-copy@^1.2.0:
86248624
version "1.2.0"
86258625
resolved "https://registry.yarnpkg.com/symlink-or-copy/-/symlink-or-copy-1.2.0.tgz#5d49108e2ab824a34069b68974486c290020b393"
86268626

0 commit comments

Comments
 (0)