expose this._compilation to webpack loaders in Turbopack #89600
+245
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds
this._compilationto the webpack loader context in turbopack.In webpack, loaders can use
this._compilationas a WeakMap key to cache expensive work for the duration of a compilation. This is useful for loaders that evaluate shared dependencies — e.g. next-yak evaluates design token files for every component that uses them, and without per-compilation caching the same file gets evaluated once per dependent component per batch.The implementation piggybacks on the existing file watcher batching. A
u64counter onDiskFileSystemInnerincrements on each batch flush and gets passed through the IPCEvaluatemessage to the Node.js loader process. The counter is deliberately kept out ofWebpackLoaderContext.argsso it doesn't affect turbo-tasks memoization. On the JS side, a new frozen object is created whenever the counter changes.Includes an e2e test that verifies the object is shared within a batch and changes between batches.
Fixes #89599