From babdca51d56946911d135f048abb53a133a21872 Mon Sep 17 00:00:00 2001 From: bokuweb Date: Wed, 2 Oct 2024 19:54:57 +0900 Subject: [PATCH] wip --- js/entry.ts | 2 ++ js/index.ts | 4 ++-- js/package.json | 2 +- js/worker.ts | 6 ++++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/js/entry.ts b/js/entry.ts index ef46c4b9..a5c83595 100644 --- a/js/entry.ts +++ b/js/entry.ts @@ -17,6 +17,8 @@ export type CompareOutput = { diffDir: string, }; +console.log(workerData.argv, 'arg') + const wasi = new WASI({ version: 'preview1', args: workerData.argv, diff --git a/js/index.ts b/js/index.ts index 0bbeed71..6fa45124 100644 --- a/js/index.ts +++ b/js/index.ts @@ -17,7 +17,7 @@ export const run = (argv: string[]): EventEmitter => { const workers = [worker]; const spawn = (startArg: number, threadId: Int32Array, memory: WebAssembly.Memory) => { - const worker = new Worker(join(dir(), `./worker.${resolveExtention()}`)); + const worker = new Worker(join(dir(), `./worker.${resolveExtention()}`), { workerData: { argv } }); workers.push(worker); @@ -111,7 +111,7 @@ export const compare = (input: CompareInput): EventEmitter => { actualDir, expectedDir, diffDir, - ...Object.entries(rest).flatMap(([k, v]) => (v == null ? [] : [`--${k}`, String(v)])), + ...Object.entries(rest).flatMap(([k, v]) => (v == null || v === '' ? [] : [`--${k}`, String(v)])), ]; return run(args); }; diff --git a/js/package.json b/js/package.json index 07c23a47..92f0b150 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "reg-cli", - "version": "0.0.0-experimental-wasm10", + "version": "0.0.0-experimental-wasm13", "description": "", "type": "module", "start": "node ./dist/cli.mjs", diff --git a/js/worker.ts b/js/worker.ts index 34823d19..1d1c2160 100644 --- a/js/worker.ts +++ b/js/worker.ts @@ -1,4 +1,4 @@ -import { parentPort } from 'node:worker_threads'; +import { parentPort, workerData } from 'node:worker_threads'; import fs from 'node:fs'; import { WASI, type IFs } from '@tybys/wasm-util'; import { argv, env } from 'node:process'; @@ -6,9 +6,11 @@ import { readWasm, resolveExtention } from './utils'; // https://github.com/toyobayashi/emnapi/blob/5ab92c706c7cd4a0a30759e58f26eedfb0ded591/packages/wasi-threads/src/wasi-threads.ts#L288-L335 import { createInstanceProxy } from './proxy'; +console.log(workerData.argv, 'arg') + const wasi = new WASI({ version: 'preview1', - args: argv, + args: workerData.argv, env: env as Record, returnOnExit: true, preopens: { './': './' },