diff --git a/js/index.ts b/js/index.ts index b617f3ff..87b7acd6 100644 --- a/js/index.ts +++ b/js/index.ts @@ -1,16 +1,17 @@ import EventEmitter from 'node:events'; import { Worker } from 'node:worker_threads'; -import { resolveExtention } from './utils'; +import { dir, resolveExtention } from './utils'; +import { join } from 'node:path'; export const run = (argv: string[]): EventEmitter => { const emitter = new EventEmitter(); - const worker = new Worker(`./entry.${resolveExtention()}`, { workerData: { argv } }); + const worker = new Worker(join(dir(), `./entry.${resolveExtention()}`), { workerData: { argv } }); let nextTid = 1; const workers = [worker]; const spawn = (startArg: number, threadId: Int32Array, memory: WebAssembly.Memory) => { - const worker = new Worker(`./worker.${resolveExtention()}`); + const worker = new Worker(join(dir(), `./worker.${resolveExtention()}`)); workers.push(worker); diff --git a/js/package.json b/js/package.json index 73596ddd..fb87f868 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "reg-cli", - "version": "0.0.0-experimental-wasm0", + "version": "0.0.0-experimental-wasm1", "description": "", "type": "module", "start": "node ./dist/cli.mjs", diff --git a/js/utils.ts b/js/utils.ts index c457a693..bd698e9f 100644 --- a/js/utils.ts +++ b/js/utils.ts @@ -5,10 +5,13 @@ import { join } from 'node:path'; const isCJS = typeof __dirname !== 'undefined'; -export const readWasm = () => { +export const dir = (): string => { const dir = isCJS ? __dirname : path.dirname(fileURLToPath(import.meta.url)); + return dir; +}; - const file = readFile(join(dir, './reg.wasm')); +export const readWasm = () => { + const file = readFile(join(dir(), './reg.wasm')); return file; };