[wasm] Add infrastructure for building WebWorkers (#70220)
authorAleksey Kliger (λgeek) <aleksey@lambdageek.org>
Fri, 10 Jun 2022 04:22:27 +0000 (00:22 -0400)
committerGitHub <noreply@github.com>
Fri, 10 Jun 2022 04:22:27 +0000 (00:22 -0400)
commite026f392b2bb93bc9509ac5403d3e8cd7d3eee72
tree819f4bc973864826239f3198d1a753bbed2d27cf
parentb2add4986c2da96e6e5fbf6f1fbb947cc7e33b42
[wasm] Add infrastructure for building WebWorkers (#70220)

* [wasm] Add infrastructure for building WebWorkers

- Modify the rollup.config.js script to look for webworkers and to
  roll them up into IIFE js files in the ${nativeBinDir}/src artifacts
  directory
   - A "webworker" is any file in `src/mono/wasm/runtime/workers/` that
looks like `dotnet-{workerName}-worker.ts` or `.js`.  It can also
include other files (ideally by defining them in files in
subdirectories for that worker
`src/mono/wasm/runtime/workers/dotnet-{workerName}-worker/utility.ts`)
   - Other changes still have to be done manually in wasm.proj, and
   elsewhere in order to place the bundled JS file in the right place.

- Adds a tsconfig.json for the workers to typecheck using the
DedicatedWorkerGlobalScope and without the DOM globals (`window`, etc)

- This doesn't convert dotnet-crypto-worker.js into TypeScript, but it
does turn on TypeScript checking using a JSDoc comment.
  To convert that file to typescript:
  1. rename `workers/dotnet-crypto-worker.js` to
  `workers/dotnet-crypto-worker.ts`
  2. replace uses of `var` by `let` or `const`
  3. add `:any` in various places.

* use fast-glob instead of fs.readdir

* add fast-glob to devDependencies
src/mono/wasm/runtime/package-lock.json
src/mono/wasm/runtime/package.json
src/mono/wasm/runtime/rollup.config.js
src/mono/wasm/runtime/workers/README.md [new file with mode: 0644]
src/mono/wasm/runtime/workers/dotnet-crypto-worker.js [moved from src/mono/wasm/runtime/dotnet-crypto-worker.js with 98% similarity]
src/mono/wasm/runtime/workers/tsconfig.json [new file with mode: 0644]
src/mono/wasm/wasm.proj