Repository navigation
module: add "worker" condition for Web Worker threads - #66635
Open
guybedford wants to merge 1 commit into
Open
guybedford wants to merge 1 commit into
guybedford wants to merge 1 commit into
Conversation
Collaborator
|
Review requested:
|
Adds a "worker" package condition that is applied within Web Worker threads created via the `Worker` global, for the worker entry point, its dependencies, `import()`, `require()` and `import.meta.resolve()`. Threads created via `worker_threads`, including from within a Web Worker, do not apply the condition. Other conditions are unaffected. Assisted-by: OpenCode Signed-off-by: Guy Bedford <guybedford@gmail.com>
guybedford
force-pushed
the
worker-condition
branch
from
October 10, 2026 04:17
b5a4450 to
f38c589
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #66635 +/- ##
==========================================
- Coverage 92.78% 90.43% -2.35%
==========================================
Files 422 791 +369
Lines 193692 276617 +82925
Branches 29881 53130 +23249
==========================================
+ Hits 179718 250162 +70444
- Misses 13645 16864 +3219
- Partials 329 9591 +9262
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 a
"worker"package condition which is enabled for Web Worker threads when created via theWorkerglobal (--experimental-web-worker).Web Workers currently inherit the parent's conditions verbatim, with no way for a package to provide a worker-specific entry point. Since Web Workers are a web platform API, a
"worker"condition matching within them aligns Node.js with the bundler and runtime ecosystem.workeris applied in Web Worker threads to the entry point, its static dependencies,import(),require()(classic workers andcreateRequire), andimport.meta.resolve().worker_threadsdo not get the condition, including threads created from within a Web Worker; nested Web Workers retain it.workerincontext.conditionson the hooks thread.node,import,require,node-addons,module-sync,--conditions) are unaffected.Internally this is tracked per-thread in
internal/modules/helpersset from the worker bootstrap whenwebWorkerDatais present, and spliced into both the ESM and CJS default conditions.Test coverage in
test/parallel/test-webworker-conditions.jscovers all of the above cases, including the main thread andworker_threadsnot matching the condition. Docs updated inpackages.mdandglobals.md.