Add key option to registerSharedWorker() #3006
Closed
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.
Motivation
We'd like to use TypeScript for shared workers.
We're currently using esbuild-register for JIT transpilation for all TS files loaded by Ava, but this doesn't work when loading shared workers. We made a small worker wrapper that allows us to load TS files as workers:
get-typescript-worker.mjs
:Problem
However, this approach means that the wrapper file is the only file ever registered with
registerSharedWorker()
. Since workers are currently de-duped based on the source filename, we can only load 1 TS worker in this manner.Solution
An optional, user-specified
key
parameter is added toregisterSharedWorker()
that overrides the implicit filename key for de-duping.After building this out, I realized that there's a second solution: when calling
registerSharedWorker()
, you can add a unique hash to the filename that acts as a key:register-typescript-worker.ts
:But this feels kinda weird and it would be nice to have an officially supported
key
parameter.