Skip to content

Commit

Permalink
Merge pull request #1064 from embroider-build/cached-one-shot
Browse files Browse the repository at this point in the history
Fix unsafe reuse of broccoli trees in OneShot
  • Loading branch information
ef4 authored Jan 6, 2022
2 parents 6a2e220 + 8f45383 commit 85e6743
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/compat/src/build-compat-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import EmptyPackageTree from './empty-package-tree';
export default function cachedBuildCompatAddon(originalPackage: Package, v1Cache: V1InstanceCache): Node {
let tree = buildCompatAddon(originalPackage, v1Cache);
if (!originalPackage.mayRebuild) {
tree = new OneShot(tree, originalPackage.name);
tree = OneShot.create(tree, originalPackage.name);
}
return tree;
}
Expand Down
13 changes: 12 additions & 1 deletion packages/compat/src/one-shot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,23 @@ class NerfHeimdallBuilder extends Builder {
buildHeimdallTree() {}
}

let seen = new WeakMap<Node, Node>();

// Wraps a broccoli tree such that it (and everything it depends on) will only
// build a single time.
export default class OneShot extends Plugin {
private builder: NerfHeimdallBuilder | null;

constructor(originalTree: Node, private addonName: string) {
static create(originalTree: Node, privateAddonName: string) {
let output = seen.get(originalTree);
if (!output) {
output = new this(originalTree, privateAddonName);
seen.set(originalTree, output);
}
return output;
}

private constructor(originalTree: Node, private addonName: string) {
// from broccoli's perspective, we don't depend on any input trees!
super([], {
annotation: `@embroider/compat: ${addonName}`,
Expand Down

0 comments on commit 85e6743

Please sign in to comment.