Skip to content

Commit df0e331

Browse files
authored
fix(node-runtime-worker-thread): Read worker source and eval instead of passing path to the worker constructor (#679)
This fixes an issue of using the worker from electron asar bundle that doesn't allow worker to resolve the path correctly.
1 parent 3557e73 commit df0e331

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/node-runtime-worker-thread/src/child-process-proxy.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@
1515
*/
1616
import { once } from 'events';
1717
import { SHARE_ENV, Worker } from 'worker_threads';
18+
import fs from 'fs';
1819
import path from 'path';
1920
import { exposeAll, createCaller } from './rpc';
2021
import { InterruptHandle, interrupt as nativeInterrupt } from 'interruptor';
2122

2223
const workerRuntimeSrcPath = path.resolve(__dirname, 'worker-runtime.js');
2324

24-
const workerProcess = new Worker(workerRuntimeSrcPath, { env: SHARE_ENV });
25+
const workerProcess = new Worker(
26+
// It's fine in this use-case: this process is spawned so we are not blocking
27+
// anything in the main process
28+
// eslint-disable-next-line no-sync
29+
fs.readFileSync(workerRuntimeSrcPath, 'utf8'),
30+
{ env: SHARE_ENV, eval: true }
31+
);
2532

2633
// We expect the amount of listeners to be more than the default value of 10 but
2734
// probably not more than ~25 (all exposed methods on

0 commit comments

Comments
 (0)