Skip to content

Commit

Permalink
Add support for node worker threads
Browse files Browse the repository at this point in the history
  • Loading branch information
surma committed Aug 21, 2020
1 parent 8cda3c6 commit 209852e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A small library to detect which features of WebAssembly are supported.
- ✅ Runs in Node
- ✅ Provided as an ES6 module, CommonJS and UMD module.
- ✅ CSP compatible
- ✅ Only ~520B gzipped
- ✅ Only ~550B gzipped

## Installation

Expand Down
1 change: 1 addition & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default ["esm", "cjs", "umd"].map(format => ({
preferConst: true,
esModule: false
},
external: ["worker_threads"],
plugins: [
indexGenerator({
indexPath: "./src/index.js",
Expand Down
5 changes: 4 additions & 1 deletion src/detectors/threads/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@

export default async moduleBytes => {
try {
const MessageChannelConstructor = await import("worker_threads")
.then(m => m.MessageChannel)
.catch(() => MessageChannel);
// Test for transferability of SABs (needed for Firefox)
// https://groups.google.com/forum/#!msg/mozilla.dev.platform/IHkBZlHETpA/dwsMNchWEQAJ
new MessageChannel().port1.postMessage(new SharedArrayBuffer(1));
new MessageChannelConstructor().port1.postMessage(new SharedArrayBuffer(1));
return WebAssembly.validate(moduleBytes);
} catch (e) {
return false;
Expand Down

0 comments on commit 209852e

Please sign in to comment.