[turbopack] Remove worker helpers from the default runtime (#94372)
This PR is looking to reduce the size of the runtime we're shipping. The
goal is to not include worker helpers in the default runtime, if workers
aren't being used / imported.
The `createWorker()` function has been removed from the runtime. It now
exists in `turbopack-ecmascript/js/src/worker/browser/createWorker.ts`
and `turbopack-ecmascript/js/src/worker/node/createWorker.ts`. The
reason behind having them in `turbopack-ecmascript` is that in
`turbopack-ecmascript/src/worker_chunk/module.rs` we can then create a
worker module (see `create_worker_module()`). This is then returned by
`references()` as a `SingleChunkableModuleReference`.
Instead of using `createWorker()` from the runtime we can instead now
import it from that module.
There are a couple of things in this PR that I'd like to flag for
discussion:
1) The location of the JavaScript. Shipping it in `turbopack-ecmascript`
doesn't quite feel natural; however, `turbopack-ecmascript-runtime`
imports `turbopack-ecmascript` so I didn't want to create a circular
dependency by importing `turbopack-ecmascript-runtime` in
`turbopack-ecmascript`.
2) There a couple of things in the runtime that we need inside of
`createWorker()`, they are:
```javascript
TURBOPACK_ASSET_SUFFIX, TURBOPACK_CHUNK_BASE_PATH
```
which are values from the runtime we needed to references
and:
```javascript
function getChunkRelativeUrl(
chunkPath: ChunkPath | ChunkListPath,
basePath: string = CHUNK_BASE_PATH
): ChunkUrl
```
which is `TURBOPACK_CHUNK_RELATIVE_URL`.
These currently exist in the runtime. To make them available, I've
placed them in `browserContextPrototype` and `contextPrototype` in the
node version.
We also have a code gen that inserts the values of
`_TURBOPACK_WORKER_FORWARDED_GLOBALS_` and
`_TURBOPACK_WORKER_BASE_PATH_` during the analyzer's pass through free
variables (takes them out of the chunking context).
@lukesandberg curious to hear your thoughts about these!
---------
Co-authored-by:
vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Showing
This source diff could not be displayed because it is too large.
You can
view the blob
instead.
This source diff could not be displayed because it is too large.
You can
view the blob
instead.
File moved
File moved
This source diff could not be displayed because it is too large.
You can
view the blob
instead.
This source diff could not be displayed because it is too large.
You can
view the blob
instead.
This source diff could not be displayed because it is too large.
You can
view the blob
instead.
This source diff could not be displayed because it is too large.
You can
view the blob
instead.
This source diff could not be displayed because it is too large.
You can
view the blob
instead.
This source diff could not be displayed because it is too large.
You can
view the blob
instead.
This source diff could not be displayed because it is too large.
You can
view the blob
instead.
Please
register
or
sign in
to comment