Skip to content

Commit cf0183a

Browse files
committed
build(DiffingPluginWrapper): ignore null/undefined input trees
this is handy to conditionally create build graph but keep mergeTree() declarative - any input tree passed into mergeTree that is null or undefined will simply be ignored
1 parent 2ce9e95 commit cf0183a

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

tools/broccoli/diffing-broccoli-plugin.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export {DiffResult} from './tree-differ';
2020
* an instance of BroccoliTree.
2121
*
2222
* @param pluginClass
23-
* @returns {DiffingPlugin}
23+
* @returns {DiffingBroccoliPlugin}
2424
*/
2525
export function wrapDiffingPlugin(pluginClass): DiffingPluginWrapperFactory {
2626
return function() { return new DiffingPluginWrapper(pluginClass, arguments); };
@@ -160,10 +160,19 @@ class DiffingPluginWrapper implements BroccoliTree {
160160
private stabilizeTrees(trees: BroccoliTree[]) {
161161
// Prevent extensions to prevent array from being mutated from the outside.
162162
// For-loop used to avoid re-allocating a new array.
163+
var stableTrees = [];
163164
for (let i = 0; i < trees.length; ++i) {
164-
trees[i] = this.stabilizeTree(trees[i]);
165+
// ignore null/undefined input tries in order to support conditional build pipelines
166+
if (trees[i]) {
167+
stableTrees.push(this.stabilizeTree(trees[i]));
168+
}
169+
}
170+
171+
if (stableTrees.length === 0) {
172+
throw new Error('No input trees provided!');
165173
}
166-
return Object.freeze(trees);
174+
175+
return Object.freeze(stableTrees);
167176
}
168177

169178

@@ -172,7 +181,7 @@ class DiffingPluginWrapper implements BroccoliTree {
172181
// so we need to stabilize them.
173182
// Since it's not safe to use instanceof operator in node, we are checking the constructor.name.
174183
//
175-
// New-styler/rebuild trees should always be stable.
184+
// New-style/rebuild trees should always be stable.
176185
let isNewStyleTree = !!(tree['newStyleTree'] || typeof tree.rebuild === 'function' ||
177186
tree['isReadAPICompatTree'] || tree.constructor['name'] === 'Funnel');
178187

0 commit comments

Comments
 (0)