Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unsafe reuse of broccoli trees in OneShot #1064

Merged
merged 1 commit into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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