()
| 65 | reuseWorker: true, |
| 66 | wasi: __wasi, |
| 67 | onCreateWorker() { |
| 68 | const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), { |
| 69 | env: process.env, |
| 70 | }); |
| 71 | worker.onmessage = ({ data }) => { |
| 72 | __wasmCreateOnMessageForFsProxy(__nodeFs)(data); |
| 73 | }; |
| 74 | |
| 75 | // The main thread of Node.js waits for all the active handles before exiting. |
| 76 | // But Rust threads are never waited without `thread::join`. |
| 77 | // So here we hack the code of Node.js to prevent the workers from being referenced (active). |
| 78 | // According to https://github.com/nodejs/node/blob/19e0d472728c79d418b74bddff588bea70a403d0/lib/internal/worker.js#L415, |
| 79 | // a worker is consist of two handles: kPublicPort and kHandle. |
| 80 | { |
| 81 | const kPublicPort = Object.getOwnPropertySymbols(worker).find((s) => s.toString().includes('kPublicPort')); |
| 82 | if (kPublicPort) { |
| 83 | worker[kPublicPort].ref = () => {}; |
| 84 | } |
| 85 | |
| 86 | const kHandle = Object.getOwnPropertySymbols(worker).find((s) => s.toString().includes('kHandle')); |
| 87 | if (kHandle) { |
| 88 | worker[kHandle].ref = () => {}; |
| 89 | } |
| 90 | |
| 91 | worker.unref(); |
| 92 | } |
| 93 | return worker; |
| 94 | }, |
| 95 | overwriteImports(importObject) { |
| 96 | importObject.env = { |
| 97 | ...importObject.env, |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…