SIGN IN SIGN UP
denoland / deno UNCLAIMED

A modern runtime for JavaScript and TypeScript.

0 0 17 Rust

fix(compile): bundle workers separately under --bundle (#34531)

Before this change, `new Worker(new URL("./w.ts",
import.meta.url), { type: "module" })` in source compiled with
\`--bundle\` failed at runtime: the bundle preserves the URL string
but the original worker source isn't in the VFS, so the worker thread
can't load.

This scans the main bundle output for the
\`new Worker(new URL(..., import.meta.url))\` shape, bundles each
unique target as its own entrypoint (the existing path-rewriter and
CJS-shim detection both run on the worker bundles too), writes each
next to the main bundle as \`.deno_compile_worker_*.mjs\`, and
rewrites the URL literals in the main bundle to point at those files.
The worker bundles are pushed onto \`--include\` so they ship in the
VFS; the \`needs_npm_embed\` signal ORs the workers' results so a
worker with CJS deps still pulls the npm tree along.

Tested with a main + 1 worker exchanging a single message; spec test
lives at \`tests/specs/compile/bundle/worker/\`.

Known limitation: only the exact
\`new Worker(new URL("X", import.meta.url), ...)\` shape is detected.
Computed URLs, workers spawned by transitive dependencies, and
minified bundles (where the pattern is mangled) will still fail with a
path-not-found at runtime.
B
Bartek Iwańczuk committed
2329258091b9ea0e0e2b121bee470292e19ebcc9
Parent: 215d1fc
Committed by GitHub <noreply@github.com> on 6/1/2026, 12:16:16 PM