-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Packager request #6379
Packager request #6379
Conversation
This pull request has been linked to and will mark 2 tasks as "Done" when merged:
|
@@ -1458,7 +1450,9 @@ export default class BundleGraph { | |||
|
|||
getHash(bundle: Bundle): string { | |||
let hash = new Hash(); | |||
hash.writeString(bundle.id + this.getContentHash(bundle)); | |||
hash.writeString( | |||
bundle.id + bundle.target.publicUrl + this.getContentHash(bundle), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Target options aren't in the environment hash and aren't tracked in the graph. This is kinda assuming that packagers will use the publicUrl in some way, but currently this is only true of the HTML packager. Perhaps we can make this more granular in the future somehow...
|
||
await this.#packagerRunner.writeBundles(bundleGraph); | ||
assertSignalNotAborted(signal); | ||
} = await this.#requestTracker.runRequest(request, {force: true}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently we force the parcel build request to run every time, even when nothing changed. This doesn't cause the sub-requests to re-run – they will return cached results. But if we want to emit a build success event with the bundle graph for builds where nothing actually changed, we need to do this to get the results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could the the parcel build request do api.storeResult
instead of only returning it? Not sure if that's more overhead than just rerunning
} | ||
|
||
_getOptimizerNodes( | ||
filePath: FilePath, | ||
pipeline: ?string, | ||
): PureParcelConfigPipeline { | ||
// If a pipeline is specified, but it doesn't exist in the optimizers config, ignore it. | ||
// Pipelines for bundles come from their entry assets, so the pipeline likely exists in transformers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes #5755
@@ -282,7 +283,26 @@ export class PackagedBundle extends NamedBundle implements IPackagedBundle { | |||
return packagedBundle; | |||
} | |||
|
|||
static getWithInfo( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't get Flow to let me add an additional argument to the existing get
function...
// Watch the bundle and source map for deletion. | ||
// Also watch the dist dir because invalidateOnFileDelete does not currently | ||
// invalidate when a parent directory is deleted. | ||
// TODO: do we want to also watch for file edits? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it might be weird if a user wanted to manually edit a file in the dist directory for some reason (e.g. debugging), and Parcel immediately overwrote it
/** | ||
* Packages, optimizes, and writes all bundles to the dist directory. | ||
*/ | ||
export default function createWriteBundlesRequest( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better name for this request? It's very similar to the singular WriteBundleRequest
. This one does the entire process of packaging, optimizing, and writing every bundle. Open to name suggestions here.
get filePath(): string { | ||
return nullthrows(this.#bundle.filePath); | ||
return nullthrows(this.#bundleInfo).filePath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, we mutated the bundle after packaging to set the file path we actually wrote to. This has a number of problems with caching, so I moved this to a separate bundle info object. It's transparent to the end user, but internally, this is not stored on the actual bundle node.
One other question is how granular we want to get. Right now, packaging and optimizing a bundle is a single request, and they are cached together, but we could make the separate requests if we wanted. |
Benchmark ResultsKitchen Sink ✅
Timings
Cold Bundles
Cached Bundles
React HackerNews ✅
Timings
Cold Bundles
Cached Bundles
AtlasKit Editor ✅
Timings
Cold Bundles
Cached Bundles
Three.js ✅
Timings
Cold BundlesNo bundle changes detected. Cached Bundles
|
# Conflicts: # Cargo.lock # Cargo.toml # packages/core/core/src/BundleGraph.js # packages/core/core/src/PackagerRunner.js # packages/core/core/src/RequestTracker.js # packages/core/core/src/Transformation.js # packages/core/core/src/requests/ConfigRequest.js # packages/packagers/js/src/index.js # packages/transformers/postcss/src/PostCSSTransformer.js # packages/utils/hash/index.js # packages/utils/hash/index.js.flow # packages/utils/hash/package.json
// TODO: should we be mutating this here? | ||
requestedAssetIds.clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe leave this part in Parcel.js and do it after the build request finished?
optionsRef, | ||
}); | ||
|
||
// $FlowFixMe Added in Flow 0.121.0 upgrade in #4381 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// $FlowFixMe Added in Flow 0.121.0 upgrade in #4381 |
Depends on #6373. Closes T-764 T-765. Fixes #5755
This refactors packaging and optimizing into requests like everything else in Parcel, and adds invalidations to the request graph for everything that might cause us to need to repackage/optimize. This includes dev dependencies, config, options, etc.
In addition to packaging and optimizing, the process of writing each bundle to the dist directory is also a request now, which means we avoid the work of writing bundles to dist that haven't changed. This also tracks if the dist file was deleted manually by the user and rewrites it if needed.
Finally, the entire Parcel build process is now a request as well. Rather than the
Parcel
class calling each step, there is a singleParcelBuildRequest
that treats each of these steps as sub-requests. This ensures that old sub-requests get deleted from the request graph properly instead of leaking orphaned nodes.