X Tutup
Skip to content

Commit 41ae8e7

Browse files
committed
feat(diffing-broccoli-plugin): support multiple inputTrees
Closes #1815 Closes #2064
1 parent 8a52375 commit 41ae8e7

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

tools/broccoli/diffing-broccoli-plugin.ts

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function wrapDiffingPlugin(pluginClass): DiffingPluginWrapperFactory {
2828

2929

3030
export interface DiffingBroccoliPlugin {
31-
rebuild(diff: DiffResult): (Promise<any>| void);
31+
rebuild(diff: (DiffResult | DiffResult[])): (Promise<any>| void);
3232
cleanup ? () : void;
3333
}
3434

@@ -38,7 +38,8 @@ type DiffingPluginWrapperFactory = (inputTrees: (BroccoliTree | BroccoliTree[]),
3838

3939

4040
class DiffingPluginWrapper implements BroccoliTree {
41-
treeDiffer: TreeDiffer;
41+
treeDiffer: TreeDiffer = null;
42+
treeDiffers: TreeDiffer[] = null;
4243
initialized = false;
4344
wrappedPlugin: DiffingBroccoliPlugin = null;
4445
inputTree = null;
@@ -47,6 +48,7 @@ class DiffingPluginWrapper implements BroccoliTree {
4748

4849
// props monkey-patched by broccoli builder:
4950
inputPath = null;
51+
inputPaths = null;
5052
cachePath = null;
5153
outputPath = null;
5254

@@ -61,13 +63,29 @@ class DiffingPluginWrapper implements BroccoliTree {
6163
}
6264

6365

66+
private calculateDiff(firstRun: boolean): (DiffResult | DiffResult[]) {
67+
if (this.treeDiffer) {
68+
let diffResult = this.treeDiffer.diffTree();
69+
diffResult.log(!firstRun);
70+
return diffResult;
71+
} else if (this.treeDiffers) {
72+
return this.treeDiffers.map((treeDiffer) => treeDiffer.diffTree())
73+
.map((diffResult) => {
74+
diffResult.log(!firstRun);
75+
return diffResult;
76+
});
77+
} else {
78+
throw new Error("Missing TreeDiffer");
79+
}
80+
}
81+
82+
6483
rebuild() {
6584
try {
6685
let firstRun = !this.initialized;
6786
this.init();
6887

69-
let diffResult = this.treeDiffer.diffTree();
70-
diffResult.log(!firstRun);
88+
let diffResult = this.calculateDiff(firstRun);
7189

7290
var rebuildPromise = this.wrappedPlugin.rebuild(diffResult);
7391

@@ -101,11 +119,18 @@ class DiffingPluginWrapper implements BroccoliTree {
101119
if (!this.initialized) {
102120
let includeExtensions = this.pluginClass.includeExtensions || [];
103121
let excludeExtensions = this.pluginClass.excludeExtensions || [];
122+
let description = this.description;
104123
this.initialized = true;
105-
this.treeDiffer =
106-
new TreeDiffer(this.description, this.inputPath, includeExtensions, excludeExtensions);
107-
this.wrappedPlugin =
108-
new this.pluginClass(this.inputPath, this.cachePath, this.wrappedPluginArguments[1]);
124+
if (this.inputPaths) {
125+
this.treeDiffers =
126+
this.inputPaths.map((inputPath) => new TreeDiffer(
127+
description, inputPath, includeExtensions, excludeExtensions));
128+
} else if (this.inputPath) {
129+
this.treeDiffer =
130+
new TreeDiffer(description, this.inputPath, includeExtensions, excludeExtensions);
131+
}
132+
this.wrappedPlugin = new this.pluginClass(this.inputPaths || this.inputPath, this.cachePath,
133+
this.wrappedPluginArguments[1]);
109134
}
110135
}
111136

0 commit comments

Comments
 (0)
X Tutup