Skip to content

Commit 83037ac

Browse files
authored
fix(*): update wasi bindings (#831)
* fix(*): update wasi bindings * Add architecture
1 parent 69e7f80 commit 83037ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+187
-116
lines changed

.github/workflows/ci.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ jobs:
263263
with:
264264
node-version: ${{ matrix.node }}
265265
cache: yarn
266+
architecture: x64
266267

267268
- name: Install dependencies
268269
run: yarn install --immutable --mode=skip-build

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
"postinstall": "husky install"
2525
},
2626
"devDependencies": {
27-
"@napi-rs/cli": "^3.0.0-alpha.52",
28-
"@napi-rs/wasm-runtime": "^0.2.0",
27+
"@napi-rs/cli": "^3.0.0-alpha.53",
28+
"@napi-rs/wasm-runtime": "^0.2.3",
2929
"@swc-node/core": "^1.13.0",
3030
"@swc-node/register": "^1.9.0",
3131
"@swc/core": "^1.4.16",

packages/argon2/argon2.wasi-browser.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync,
33
getDefaultContext as __emnapiGetDefaultContext,
44
WASI as __WASI,
5+
createOnMessage as __wasmCreateOnMessageForFsProxy,
56
} from '@napi-rs/wasm-runtime'
67

78
import __wasmUrl from './argon2.wasm32-wasi.wasm?url'
@@ -29,9 +30,11 @@ const {
2930
asyncWorkPoolSize: 4,
3031
wasi: __wasi,
3132
onCreateWorker() {
32-
return new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
33+
const worker = new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
3334
type: 'module',
3435
})
36+
37+
return worker
3538
},
3639
overwriteImports(importObject) {
3740
importObject.env = {

packages/argon2/argon2.wasi.cjs

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33

44
/* auto-generated by NAPI-RS */
55

6-
const __nodeFs= require('node:fs')
6+
const __nodeFs = require('node:fs')
77
const __nodePath = require('node:path')
88
const { WASI: __nodeWASI } = require('node:wasi')
99
const { Worker } = require('node:worker_threads')
1010

1111
const {
1212
instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
1313
getDefaultContext: __emnapiGetDefaultContext,
14+
createOnMessage: __wasmCreateOnMessageForFsProxy,
1415
} = require('@napi-rs/wasm-runtime')
1516

1617
const __rootDir = __nodePath.parse(process.cwd()).root
@@ -57,10 +58,14 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
5758
})(),
5859
wasi: __wasi,
5960
onCreateWorker() {
60-
return new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
61+
const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
6162
env: process.env,
6263
execArgv: ['--experimental-wasi-unstable-preview1'],
6364
})
65+
worker.onmessage = ({ data }) => {
66+
__wasmCreateOnMessageForFsProxy(__nodeFs)(data)
67+
}
68+
return worker
6469
},
6570
overwriteImports(importObject) {
6671
importObject.env = {

packages/argon2/npm/wasm32-wasi/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@
3939
},
4040
"browser": "argon2.wasi-browser.js",
4141
"dependencies": {
42-
"@napi-rs/wasm-runtime": "^0.2.0"
42+
"@napi-rs/wasm-runtime": "^0.2.3"
4343
}
4444
}

packages/argon2/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"version": "napi version && git add npm"
6363
},
6464
"devDependencies": {
65-
"@napi-rs/cli": "^3.0.0-alpha.52",
65+
"@napi-rs/cli": "^3.0.0-alpha.53",
6666
"argon2": "^0.40.1",
6767
"cross-env": "^7.0.3"
6868
}

packages/argon2/wasi-worker-browser.mjs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import { instantiateNapiModuleSync, MessageHandler, WASI } from '@napi-rs/wasm-runtime'
1+
import { instantiateNapiModuleSync, MessageHandler, WASI, createFsProxy } from '@napi-rs/wasm-runtime'
22

33
const fs = null
44

55
const handler = new MessageHandler({
66
onLoad({ wasmModule, wasmMemory }) {
77
const wasi = new WASI({
88
fs,
9+
preopens: {
10+
'/': '/',
11+
},
912
print: function () {
1013
// eslint-disable-next-line no-console
1114
console.log.apply(console, arguments)

packages/argon2/wasi-worker.mjs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from "node:fs";
22
import { createRequire } from "node:module";
3+
import { parse } from "node:path";
34
import { WASI } from "node:wasi";
45
import { parentPort, Worker } from "node:worker_threads";
56

@@ -27,15 +28,17 @@ Object.assign(globalThis, {
2728
},
2829
});
2930

30-
const emnapiContext = getDefaultContext()
31+
const emnapiContext = getDefaultContext();
32+
33+
const __rootDir = parse(process.cwd()).root;
3134

3235
const handler = new MessageHandler({
3336
onLoad({ wasmModule, wasmMemory }) {
3437
const wasi = new WASI({
3538
version: 'preview1',
3639
env: process.env,
3740
preopens: {
38-
'/': '/',
41+
[__rootDir]: __rootDir,
3942
},
4043
});
4144

packages/bcrypt/bcrypt.wasi-browser.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync,
33
getDefaultContext as __emnapiGetDefaultContext,
44
WASI as __WASI,
5+
createOnMessage as __wasmCreateOnMessageForFsProxy,
56
} from '@napi-rs/wasm-runtime'
67

78
import __wasmUrl from './bcrypt.wasm32-wasi.wasm?url'
@@ -29,9 +30,11 @@ const {
2930
asyncWorkPoolSize: 4,
3031
wasi: __wasi,
3132
onCreateWorker() {
32-
return new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
33+
const worker = new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
3334
type: 'module',
3435
})
36+
37+
return worker
3538
},
3639
overwriteImports(importObject) {
3740
importObject.env = {

packages/bcrypt/bcrypt.wasi.cjs

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33

44
/* auto-generated by NAPI-RS */
55

6-
const __nodeFs= require('node:fs')
6+
const __nodeFs = require('node:fs')
77
const __nodePath = require('node:path')
88
const { WASI: __nodeWASI } = require('node:wasi')
99
const { Worker } = require('node:worker_threads')
1010

1111
const {
1212
instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
1313
getDefaultContext: __emnapiGetDefaultContext,
14+
createOnMessage: __wasmCreateOnMessageForFsProxy,
1415
} = require('@napi-rs/wasm-runtime')
1516

1617
const __rootDir = __nodePath.parse(process.cwd()).root
@@ -57,10 +58,14 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
5758
})(),
5859
wasi: __wasi,
5960
onCreateWorker() {
60-
return new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
61+
const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
6162
env: process.env,
6263
execArgv: ['--experimental-wasi-unstable-preview1'],
6364
})
65+
worker.onmessage = ({ data }) => {
66+
__wasmCreateOnMessageForFsProxy(__nodeFs)(data)
67+
}
68+
return worker
6469
},
6570
overwriteImports(importObject) {
6671
importObject.env = {

packages/bcrypt/npm/wasm32-wasi/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@
4343
},
4444
"browser": "bcrypt.wasi-browser.js",
4545
"dependencies": {
46-
"@napi-rs/wasm-runtime": "^0.2.0"
46+
"@napi-rs/wasm-runtime": "^0.2.3"
4747
}
4848
}

packages/bcrypt/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"url": "https://github.com/napi-rs/node-rs/issues"
7171
},
7272
"devDependencies": {
73-
"@napi-rs/cli": "^3.0.0-alpha.52",
73+
"@napi-rs/cli": "^3.0.0-alpha.53",
7474
"@types/bcrypt": "^5.0.2",
7575
"bcrypt": "^5.1.1",
7676
"bcryptjs": "^2.4.3",

packages/bcrypt/wasi-worker-browser.mjs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import { instantiateNapiModuleSync, MessageHandler, WASI } from '@napi-rs/wasm-runtime'
1+
import { instantiateNapiModuleSync, MessageHandler, WASI, createFsProxy } from '@napi-rs/wasm-runtime'
22

33
const fs = null
44

55
const handler = new MessageHandler({
66
onLoad({ wasmModule, wasmMemory }) {
77
const wasi = new WASI({
88
fs,
9+
preopens: {
10+
'/': '/',
11+
},
912
print: function () {
1013
// eslint-disable-next-line no-console
1114
console.log.apply(console, arguments)

packages/bcrypt/wasi-worker.mjs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from "node:fs";
22
import { createRequire } from "node:module";
3+
import { parse } from "node:path";
34
import { WASI } from "node:wasi";
45
import { parentPort, Worker } from "node:worker_threads";
56

@@ -27,15 +28,17 @@ Object.assign(globalThis, {
2728
},
2829
});
2930

30-
const emnapiContext = getDefaultContext()
31+
const emnapiContext = getDefaultContext();
32+
33+
const __rootDir = parse(process.cwd()).root;
3134

3235
const handler = new MessageHandler({
3336
onLoad({ wasmModule, wasmMemory }) {
3437
const wasi = new WASI({
3538
version: 'preview1',
3639
env: process.env,
3740
preopens: {
38-
'/': '/',
41+
[__rootDir]: __rootDir,
3942
},
4043
});
4144

packages/crc32/crc32.wasi-browser.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync,
33
getDefaultContext as __emnapiGetDefaultContext,
44
WASI as __WASI,
5+
createOnMessage as __wasmCreateOnMessageForFsProxy,
56
} from '@napi-rs/wasm-runtime'
67

78
import __wasmUrl from './crc32.wasm32-wasi.wasm?url'
@@ -29,9 +30,11 @@ const {
2930
asyncWorkPoolSize: 4,
3031
wasi: __wasi,
3132
onCreateWorker() {
32-
return new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
33+
const worker = new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
3334
type: 'module',
3435
})
36+
37+
return worker
3538
},
3639
overwriteImports(importObject) {
3740
importObject.env = {

packages/crc32/crc32.wasi.cjs

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33

44
/* auto-generated by NAPI-RS */
55

6-
const __nodeFs= require('node:fs')
6+
const __nodeFs = require('node:fs')
77
const __nodePath = require('node:path')
88
const { WASI: __nodeWASI } = require('node:wasi')
99
const { Worker } = require('node:worker_threads')
1010

1111
const {
1212
instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
1313
getDefaultContext: __emnapiGetDefaultContext,
14+
createOnMessage: __wasmCreateOnMessageForFsProxy,
1415
} = require('@napi-rs/wasm-runtime')
1516

1617
const __rootDir = __nodePath.parse(process.cwd()).root
@@ -57,10 +58,14 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
5758
})(),
5859
wasi: __wasi,
5960
onCreateWorker() {
60-
return new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
61+
const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
6162
env: process.env,
6263
execArgv: ['--experimental-wasi-unstable-preview1'],
6364
})
65+
worker.onmessage = ({ data }) => {
66+
__wasmCreateOnMessageForFsProxy(__nodeFs)(data)
67+
}
68+
return worker
6469
},
6570
overwriteImports(importObject) {
6671
importObject.env = {

packages/crc32/npm/wasm32-wasi/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@
4040
},
4141
"browser": "crc32.wasi-browser.js",
4242
"dependencies": {
43-
"@napi-rs/wasm-runtime": "^0.2.0"
43+
"@napi-rs/wasm-runtime": "^0.2.3"
4444
}
4545
}

packages/crc32/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"url": "https://github.com/napi-rs/node-rs/issues"
6565
},
6666
"devDependencies": {
67-
"@napi-rs/cli": "^3.0.0-alpha.52",
67+
"@napi-rs/cli": "^3.0.0-alpha.53",
6868
"@types/crc": "^3.8.3",
6969
"buffer": "^6.0.3",
7070
"crc": "^4.3.2",

packages/crc32/wasi-worker-browser.mjs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import { instantiateNapiModuleSync, MessageHandler, WASI } from '@napi-rs/wasm-runtime'
1+
import { instantiateNapiModuleSync, MessageHandler, WASI, createFsProxy } from '@napi-rs/wasm-runtime'
22

33
const fs = null
44

55
const handler = new MessageHandler({
66
onLoad({ wasmModule, wasmMemory }) {
77
const wasi = new WASI({
88
fs,
9+
preopens: {
10+
'/': '/',
11+
},
912
print: function () {
1013
// eslint-disable-next-line no-console
1114
console.log.apply(console, arguments)

packages/crc32/wasi-worker.mjs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from "node:fs";
22
import { createRequire } from "node:module";
3+
import { parse } from "node:path";
34
import { WASI } from "node:wasi";
45
import { parentPort, Worker } from "node:worker_threads";
56

@@ -27,15 +28,17 @@ Object.assign(globalThis, {
2728
},
2829
});
2930

30-
const emnapiContext = getDefaultContext()
31+
const emnapiContext = getDefaultContext();
32+
33+
const __rootDir = parse(process.cwd()).root;
3134

3235
const handler = new MessageHandler({
3336
onLoad({ wasmModule, wasmMemory }) {
3437
const wasi = new WASI({
3538
version: 'preview1',
3639
env: process.env,
3740
preopens: {
38-
'/': '/',
41+
[__rootDir]: __rootDir,
3942
},
4043
});
4144

packages/deno-lint/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"typanion": "^3.14.0"
7474
},
7575
"devDependencies": {
76-
"@napi-rs/cli": "^3.0.0-alpha.52",
76+
"@napi-rs/cli": "^3.0.0-alpha.53",
7777
"@types/webpack": "^5.28.5"
7878
},
7979
"funding": {

packages/jieba/jieba.wasi-browser.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync,
33
getDefaultContext as __emnapiGetDefaultContext,
44
WASI as __WASI,
5+
createOnMessage as __wasmCreateOnMessageForFsProxy,
56
} from '@napi-rs/wasm-runtime'
67

78
import __wasmUrl from './jieba.wasm32-wasi.wasm?url'
@@ -29,9 +30,11 @@ const {
2930
asyncWorkPoolSize: 4,
3031
wasi: __wasi,
3132
onCreateWorker() {
32-
return new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
33+
const worker = new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
3334
type: 'module',
3435
})
36+
37+
return worker
3538
},
3639
overwriteImports(importObject) {
3740
importObject.env = {

0 commit comments

Comments
 (0)