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

Deterministic Bundle Trees #309

Closed
Closed
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
19 changes: 15 additions & 4 deletions src/Bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,22 +323,33 @@ class Bundler extends EventEmitter {
}

// Process asset dependencies
await Promise.all(
const applyFunctions = await Promise.all(
dependencies.map(async dep => {
let applyFunction;
let assetDep = await this.resolveDep(asset, dep);
if (dep.includedInParent) {
// This dependency is already included in the parent's generated output,
// so no need to load it. We map the name back to the parent asset so
// that changing it triggers a recompile of the parent.
this.loadedAssets.set(dep.name, asset);
applyFunction = () => this.loadedAssets.set(dep.name, asset);
} else {
asset.dependencies.set(dep.name, dep);
asset.depAssets.set(dep.name, assetDep);
applyFunction = () => {
asset.dependencies.set(dep.name, dep);
asset.depAssets.set(dep.name, assetDep);
};
await this.loadAsset(assetDep);
}
return applyFunction;
})
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is applyFunctions only job to be run later. Then would it be leaner to chain .forEach(fn => fn()) do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would work as well. I felt the current was more readable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good. Confirmed test is stable on my end now.


/*
* Add processed dependencies to `asset` in their originally resolved order.
* This ensures consistent bundle trees by removing the randomness of concurrent
* processing via promises.
*/
for (const fn of applyFunctions) fn();

this.buildQueue.delete(asset);
}

Expand Down