diff --git a/.prettierignore b/.prettierignore index 6d81dff6..6bc66d8a 100644 --- a/.prettierignore +++ b/.prettierignore @@ -5,3 +5,5 @@ triples/index.js examples/napi/index.d.ts .yarn yarn.lock +examples/napi/wasi-worker.mjs +examples/napi/index.wasi.mjs diff --git a/cli/package.json b/cli/package.json index efaab191..8f6ca146 100644 --- a/cli/package.json +++ b/cli/package.json @@ -73,7 +73,7 @@ "colorette": "^2.0.20", "debug": "^4.3.4", "emnapi": "0.44.0", - "inquirer": "^9.2.11", + "inquirer": "^9.2.12", "js-yaml": "^4.1.0", "lodash-es": "^4.17.21", "toml": "^3.0.0", @@ -82,14 +82,14 @@ "devDependencies": { "@emnapi/core": "0.44.0", "@emnapi/runtime": "0.44.0", - "@types/debug": "^4.1.10", - "@types/inquirer": "^9.0.6", - "@types/js-yaml": "^4.0.8", - "@types/lodash-es": "^4.17.10", + "@types/debug": "^4.1.12", + "@types/inquirer": "^9.0.7", + "@types/js-yaml": "^4.0.9", + "@types/lodash-es": "^4.17.11", "ava": "^5.3.1", "env-paths": "^3.0.0", "esbuild": "^0.19.5", - "prettier": "^3.0.3", + "prettier": "^3.1.0", "ts-node": "^10.9.1", "tslib": "^2.6.2", "typescript": "^5.2.2" diff --git a/examples/napi/__tests__/tsfn-error.cjs b/examples/napi/__tests__/tsfn-error.cjs index 91c2019e..19ac08c1 100644 --- a/examples/napi/__tests__/tsfn-error.cjs +++ b/examples/napi/__tests__/tsfn-error.cjs @@ -1,3 +1,5 @@ -import('../index.js').then(({ default: { threadsafeFunctionFatalModeError } }) => { - return threadsafeFunctionFatalModeError(() => {}) -}) +import('../index.js').then( + ({ default: { threadsafeFunctionFatalModeError } }) => { + return threadsafeFunctionFatalModeError(() => {}) + }, +) diff --git a/examples/napi/__tests__/unload.spec.js b/examples/napi/__tests__/unload.spec.js index 6b995e93..dd4594bb 100644 --- a/examples/napi/__tests__/unload.spec.js +++ b/examples/napi/__tests__/unload.spec.js @@ -19,8 +19,8 @@ test('unload module', (t) => { test('load module multi times', (t) => { const { add } = require('../index.node') t.is(add(1, 2), 3) - const { add: add2 } = require(path.toNamespacedPath( - path.join(__dirname, '../index.node'), - )) + const { add: add2 } = require( + path.toNamespacedPath(path.join(__dirname, '../index.node')), + ) t.is(add2(1, 2), 3) }) diff --git a/examples/napi/__tests__/worker.cjs b/examples/napi/__tests__/worker.cjs index 2fd25686..4c97f3cd 100644 --- a/examples/napi/__tests__/worker.cjs +++ b/examples/napi/__tests__/worker.cjs @@ -2,54 +2,56 @@ const { parentPort } = require('worker_threads') const isWasiTest = !!process.env.WASI_TEST -import('../index.js').then(({ default: native }) => { - parentPort.on('message', ({ type }) => { - switch (type) { - case 'require': - parentPort.postMessage( - native.Animal.withKind(native.Kind.Cat).whoami() + native.DEFAULT_COST, - ) - break - case 'async:buffer': - Promise.all( - Array.from({ length: isWasiTest ? 2 : 100 }).map(() => - native.bufferPassThrough(Buffer.from([1, 2, 3])), - ), - ) - .then(() => { - parentPort.postMessage('done') - }) - .catch((e) => { - throw e - }) - break - case 'async:arraybuffer': - Promise.all( - Array.from({ length: isWasiTest ? 2 : 100 }).map(() => - native.arrayBufferPassThrough(Uint8Array.from([1, 2, 3])), - ), - ) - .then(() => { - parentPort.postMessage('done') - }) - .catch((e) => { - throw e - }) +import('../index.js') + .then(({ default: native }) => { + parentPort.on('message', ({ type }) => { + switch (type) { + case 'require': + parentPort.postMessage( + native.Animal.withKind(native.Kind.Cat).whoami() + + native.DEFAULT_COST, + ) + break + case 'async:buffer': + Promise.all( + Array.from({ length: isWasiTest ? 2 : 100 }).map(() => + native.bufferPassThrough(Buffer.from([1, 2, 3])), + ), + ) + .then(() => { + parentPort.postMessage('done') + }) + .catch((e) => { + throw e + }) + break + case 'async:arraybuffer': + Promise.all( + Array.from({ length: isWasiTest ? 2 : 100 }).map(() => + native.arrayBufferPassThrough(Uint8Array.from([1, 2, 3])), + ), + ) + .then(() => { + parentPort.postMessage('done') + }) + .catch((e) => { + throw e + }) - break - case 'constructor': - let ellie - for (let i = 0; i < (isWasiTest ? 10 : 10000); i++) { - ellie = new native.Animal(native.Kind.Cat, 'Ellie') - } - parentPort.postMessage(ellie.name) - break - default: - throw new TypeError(`Unknown message type: ${type}`) - } + break + case 'constructor': + let ellie + for (let i = 0; i < (isWasiTest ? 10 : 10000); i++) { + ellie = new native.Animal(native.Kind.Cat, 'Ellie') + } + parentPort.postMessage(ellie.name) + break + default: + throw new TypeError(`Unknown message type: ${type}`) + } + }) + }) + .catch((e) => { + console.error(e) + process.exit(1) }) -}).catch((e) => { - console.error(e) - process.exit(1) -}) - diff --git a/examples/napi/electron-renderer/index.html b/examples/napi/electron-renderer/index.html index 275509d9..c01514ba 100644 --- a/examples/napi/electron-renderer/index.html +++ b/examples/napi/electron-renderer/index.html @@ -1,16 +1,14 @@ +
+ + + +