forked from rollup/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(wasm): work with service workers (rollup#334)
BREAKING CHANGES: This change leverages `globalThis` and will fail in older environments where `globalThis` is not implemented. See https://caniuse.com/#search=WebAssembly and https://caniuse.com/#search=globalThis. If your environment doesn't support `globalThis`, please use an earlier version of this plugin. * Make wasm plugin work with service workers The code generated by @rollup/plugin-wasm breaks when executed in a service worker because window is undefined. * Add test for worker scenario and simplify the fix Instead of checking whether window is defined, we can just use globalThis. * Only run worker test if worker_threads supported
- Loading branch information
1 parent
8821991
commit f5cb556
Showing
3 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import sample from './sample.wasm'; | ||
// atob doesn't exist in node, so we fake it | ||
// in the browser, globalThis.atob will exist | ||
// eslint-disable-next-line no-undef | ||
globalThis.atob = (str) => Buffer.from(str, 'base64').toString('binary'); | ||
// trick the wasm loader into thinking we are in the browser | ||
const realProcess = process; | ||
// eslint-disable-next-line no-global-assign, no-undefined | ||
process = undefined; | ||
sample({}); | ||
realProcess.exit(0); |
This file contains 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