Skip to content
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

Allow dedicated Workers to inherit the creator's import map #1

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nicolo-ribaudo
Copy link
Owner

@nicolo-ribaudo nicolo-ribaudo commented Nov 26, 2024

This PR could land either with both commits, or just with the first one.

Allow dedicated Workers to inherit the creator's import map

This option adds an importMap: "none" | "clone" option to the Worker
constructor, which defaults to "none". When this option is set to
"clone", the Worker constructor will take a snapshot of the current
import map and use it as the import map inside the worker.

Passing the importMap option to SharedWorker is an error, to make it
possible to give it a meaning in the future.

Support passing an object as the import map to Worker

This commit allows passing a JavaScript object to Worker's importMap
option, which is validated and used as the worker's import map.

The existing validation of the JSON import map has been delegated to
WebIDL, so that it can be re-used for this option's value.


  • At least two implementers are interested (and none opposed):
  • Tests are written and can be reviewed and commented upon at:
  • Implementation bugs are filed:
    • Chromium: …
    • Gecko: …
    • WebKit: …
    • Deno (only for timers, structured clone, base64 utils, channel messaging, module resolution, web workers, and web storage): (NOTE: Deno behaves like importMap: "clone" by default)
    • Node.js (only for timers, structured clone, base64 utils, channel messaging, and module resolution): … (NOTE: Node.js does not support import maps)
  • MDN issue is filed: …
  • The top of this comment includes a clear commit message to use.

(See WHATWG Working Mode: Changes for more details.)

This option adds an `importMap: "none" | "clone"` option to the `Worker`
constructor, which defaults to `"none"`. When this option is set to
`"clone"`, the `Worker` constructor will take a snapshot of the current
import map and use it as the import map inside the worker.

Passing the `importMap` option to `SharedWorker` is an error, to make it
possible to give it a meaning in the future.
This commit allows passing a JavaScript object to `Worker`'s `importMap`
option, which is validated and used as the worker's import map.

The existing validation of the JSON import map has been delegated to
WebIDL, so that it can be re-used for this option's value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant