Skip to content

Commit 4fb4bcc

Browse files
authored
chore(*): upgrade NAPI-RS and bindings (#825)
1 parent c518732 commit 4fb4bcc

Some content is hidden

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

55 files changed

+907
-1876
lines changed

.github/workflows/ci.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ jobs:
101101
target: 'aarch64-pc-windows-msvc'
102102
build: yarn build --target aarch64-pc-windows-msvc
103103
- host: ubuntu-latest
104-
target: 'wasm32-wasi-preview1-threads'
105-
build: yarn workspaces foreach -A --no-private -j 1 --exclude "@node-rs/deno-lint" run build --target wasm32-wasi-preview1-threads
104+
target: 'wasm32-wasip1-threads'
105+
build: yarn workspaces foreach -A --no-private -j 1 --exclude "@node-rs/deno-lint" run build --target wasm32-wasip1-threads
106106

107107
name: stable - ${{ matrix.settings.target }} - node@20
108108
runs-on: ${{ matrix.settings.host }}
@@ -166,22 +166,22 @@ jobs:
166166

167167
- name: Upload artifact
168168
uses: actions/upload-artifact@v4
169-
if: ${{ matrix.settings.target != 'wasm32-wasi-preview1-threads' }}
169+
if: ${{ matrix.settings.target != 'wasm32-wasip1-threads' }}
170170
with:
171171
name: bindings-${{ matrix.settings.target }}
172172
path: packages/*/*.node
173173
if-no-files-found: error
174174

175175
- name: Upload artifact
176176
uses: actions/upload-artifact@v4
177-
if: ${{ matrix.settings.target == 'wasm32-wasi-preview1-threads' }}
177+
if: ${{ matrix.settings.target == 'wasm32-wasip1-threads' }}
178178
with:
179179
name: bindings-${{ matrix.settings.target }}
180180
path: packages/*/*.wasm
181181
if-no-files-found: error
182182

183183
build-freebsd:
184-
runs-on: macos-12
184+
runs-on: macos-13
185185
name: Build FreeBSD
186186
steps:
187187
- uses: actions/checkout@v4
@@ -583,7 +583,7 @@ jobs:
583583
- name: Download artifacts
584584
uses: actions/download-artifact@v4
585585
with:
586-
name: bindings-wasm32-wasi-preview1-threads
586+
name: bindings-wasm32-wasip1-threads
587587
path: artifacts
588588
- name: Move artifacts
589589
run: yarn artifacts

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cargo-features = ["strip"]
2-
31
[workspace]
42
members = [
53
"./crates/alloc",

package.json

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"bench": "lerna run bench --concurrency 1 --stream --no-prefix",
1515
"build": "yarn workspaces foreach -A --no-private -j 1 run build",
1616
"build:ts": "tsc -b tsconfig.project.json -verbose",
17-
"lint": "eslint . -c ./.eslintrc.yml \"packages/**/*.{ts,js}\"",
17+
"lint": "oxlint .",
1818
"test": "ava",
1919
"format": "run-p format:prettier format:rs format:toml",
2020
"format:prettier": "prettier --config ./package.json -w .",
@@ -24,37 +24,31 @@
2424
"postinstall": "husky install"
2525
},
2626
"devDependencies": {
27-
"@napi-rs/cli": "^3.0.0-alpha.43",
28-
"@napi-rs/wasm-runtime": "^0.1.1",
29-
"@swc-node/core": "^1.12.0",
30-
"@swc-node/register": "^1.8.0",
31-
"@swc/core": "^1.4.2",
27+
"@napi-rs/cli": "^3.0.0-alpha.51",
28+
"@napi-rs/wasm-runtime": "^0.2.0",
29+
"@swc-node/core": "^1.13.0",
30+
"@swc-node/register": "^1.9.0",
31+
"@swc/core": "^1.4.16",
3232
"@taplo/cli": "^0.7.0",
3333
"@tybys/wasm-util": "^0.8.1",
34-
"@types/node": "^20.11.21",
35-
"@typescript-eslint/eslint-plugin": "^7.1.0",
36-
"@typescript-eslint/parser": "^7.1.0",
37-
"ava": "^6.1.1",
34+
"@types/node": "^20.12.7",
35+
"ava": "^6.1.2",
3836
"benchmark": "^2.1.4",
3937
"codecov": "^3.8.3",
4038
"cross-env": "^7.0.3",
41-
"eslint": "^8.57.0",
42-
"eslint-config-prettier": "^9.1.0",
43-
"eslint-plugin-import": "^2.29.1",
44-
"eslint-plugin-prettier": "^5.1.3",
4539
"husky": "^9.0.11",
4640
"lerna": "^8.1.2",
4741
"lint-staged": "^15.2.2",
48-
"memfs-browser": "^4.6.0",
4942
"npm-run-all2": "^6.1.2",
43+
"oxlint": "^0.2.17",
5044
"prettier": "^3.2.5",
5145
"ts-node": "^10.9.2",
5246
"tslib": "^2.6.2",
53-
"typescript": "^5.3.3"
47+
"typescript": "^5.4.5"
5448
},
5549
"lint-staged": {
5650
"*.@(js|ts|tsx)": [
57-
"eslint -c .eslintrc.yml --fix"
51+
"oxlint --fix"
5852
],
5953
"*.@(js|ts|tsx|yml|yaml|json|md)": [
6054
"prettier --write"

packages/argon2/argon2.wasi-browser.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,18 @@ import {
33
getDefaultContext as __emnapiGetDefaultContext,
44
WASI as __WASI,
55
} from '@napi-rs/wasm-runtime'
6-
import { Volume as __Volume, createFsFromVolume as __createFsFromVolume } from '@napi-rs/wasm-runtime/fs'
76

87
import __wasmUrl from './argon2.wasm32-wasi.wasm?url'
98

10-
const __fs = __createFsFromVolume(
11-
__Volume.fromJSON({
12-
'/': null,
13-
}),
14-
)
15-
169
const __wasi = new __WASI({
1710
version: 'preview1',
18-
fs: __fs,
1911
})
2012

2113
const __emnapiContext = __emnapiGetDefaultContext()
2214

2315
const __sharedMemory = new WebAssembly.Memory({
24-
initial: 1024,
25-
maximum: 10240,
16+
initial: 4000,
17+
maximum: 65536,
2618
shared: true,
2719
})
2820

packages/argon2/argon2.wasi.cjs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,30 @@ const {
1313
getDefaultContext: __emnapiGetDefaultContext,
1414
} = require('@napi-rs/wasm-runtime')
1515

16+
const __rootDir = __nodePath.parse(process.cwd()).root
17+
1618
const __wasi = new __nodeWASI({
1719
version: 'preview1',
1820
env: process.env,
1921
preopens: {
20-
'/': '/'
22+
[__rootDir]: __rootDir,
2123
}
2224
})
2325

2426
const __emnapiContext = __emnapiGetDefaultContext()
2527

2628
const __sharedMemory = new WebAssembly.Memory({
27-
initial: 1024,
28-
maximum: 10240,
29+
initial: 4000,
30+
maximum: 65536,
2931
shared: true,
3032
})
3133

3234
let __wasmFilePath = __nodePath.join(__dirname, 'argon2.wasm32-wasi.wasm')
35+
const __wasmDebugFilePath = __nodePath.join(__dirname, 'argon2.wasm32-wasi.debug.wasm')
3336

34-
if (!__nodeFs.existsSync(__wasmFilePath)) {
37+
if (__nodeFs.existsSync(__wasmDebugFilePath)) {
38+
__wasmFilePath = __wasmDebugFilePath
39+
} else if (!__nodeFs.existsSync(__wasmFilePath)) {
3540
try {
3641
__wasmFilePath = __nodePath.resolve('@node-rs/argon2-wasm32-wasi')
3742
} catch {

packages/argon2/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* auto-generated by NAPI-RS */
22
/* eslint-disable */
3-
43
export const enum Algorithm {
54
/**
65
* Optimizes against GPU cracking attacks but vulnerable to side-channels.

packages/argon2/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,20 @@ function requireNative() {
246246

247247
}
248248
} else if (process.arch === 'arm') {
249+
if (isMusl()) {
250+
try {
251+
return require('./argon2.linux-arm-musleabihf.node')
252+
} catch (e) {
253+
loadErrors.push(e)
254+
}
249255
try {
256+
return require('@node-rs/argon2-linux-arm-musleabihf')
257+
} catch (e) {
258+
loadErrors.push(e)
259+
}
260+
261+
} else {
262+
try {
250263
return require('./argon2.linux-arm-gnueabihf.node')
251264
} catch (e) {
252265
loadErrors.push(e)
@@ -257,6 +270,7 @@ function requireNative() {
257270
loadErrors.push(e)
258271
}
259272

273+
}
260274
} else if (process.arch === 'riscv64') {
261275
if (isMusl()) {
262276
try {
@@ -283,6 +297,18 @@ function requireNative() {
283297
}
284298

285299
}
300+
} else if (process.arch === 'ppc64') {
301+
try {
302+
return require('./argon2.linux-ppc64-gnu.node')
303+
} catch (e) {
304+
loadErrors.push(e)
305+
}
306+
try {
307+
return require('@node-rs/argon2-linux-ppc64-gnu')
308+
} catch (e) {
309+
loadErrors.push(e)
310+
}
311+
286312
} else if (process.arch === 's390x') {
287313
try {
288314
return require('./argon2.linux-s390x-gnu.node')
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# `@node-rs/argon2-wasm32-wasi`
22

3-
This is the **wasm32-wasi-preview1-threads** binary for `@node-rs/argon2`
3+
This is the **wasm32-wasip1-threads** binary for `@node-rs/argon2`

packages/argon2/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"x86_64-unknown-freebsd",
3434
"i686-pc-windows-msvc",
3535
"armv7-linux-androideabi",
36-
"wasm32-wasi-preview1-threads"
36+
"wasm32-wasip1-threads"
3737
]
3838
},
3939
"files": [
@@ -62,7 +62,7 @@
6262
"version": "napi version && git add npm"
6363
},
6464
"devDependencies": {
65-
"@napi-rs/cli": "^3.0.0-alpha.43",
65+
"@napi-rs/cli": "^3.0.0-alpha.51",
6666
"argon2": "^0.40.1",
6767
"cross-env": "^7.0.3"
6868
}

packages/argon2/wasi-worker.mjs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import fs from "node:fs";
22
import { createRequire } from "node:module";
3+
import { WASI } from "node:wasi";
34
import { parentPort, Worker } from "node:worker_threads";
45

5-
import { instantiateNapiModuleSync, MessageHandler, WASI } from "@napi-rs/wasm-runtime";
6-
76
const require = createRequire(import.meta.url);
87

8+
const { instantiateNapiModuleSync, MessageHandler, getDefaultContext } = require("@napi-rs/wasm-runtime");
9+
910
if (parentPort) {
1011
parentPort.on("message", (data) => {
1112
globalThis.onmessage({ data });
@@ -26,13 +27,22 @@ Object.assign(globalThis, {
2627
},
2728
});
2829

30+
const emnapiContext = getDefaultContext()
31+
2932
const handler = new MessageHandler({
3033
onLoad({ wasmModule, wasmMemory }) {
31-
const wasi = new WASI({ fs });
34+
const wasi = new WASI({
35+
version: 'preview1',
36+
env: process.env,
37+
preopens: {
38+
'/': '/',
39+
},
40+
});
3241

3342
return instantiateNapiModuleSync(wasmModule, {
3443
childThread: true,
3544
wasi,
45+
context: emnapiContext,
3646
overwriteImports(importObject) {
3747
importObject.env = {
3848
...importObject.env,

packages/bcrypt/bcrypt.wasi-browser.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,18 @@ import {
33
getDefaultContext as __emnapiGetDefaultContext,
44
WASI as __WASI,
55
} from '@napi-rs/wasm-runtime'
6-
import { Volume as __Volume, createFsFromVolume as __createFsFromVolume } from '@napi-rs/wasm-runtime/fs'
76

87
import __wasmUrl from './bcrypt.wasm32-wasi.wasm?url'
98

10-
const __fs = __createFsFromVolume(
11-
__Volume.fromJSON({
12-
'/': null,
13-
}),
14-
)
15-
169
const __wasi = new __WASI({
1710
version: 'preview1',
18-
fs: __fs,
1911
})
2012

2113
const __emnapiContext = __emnapiGetDefaultContext()
2214

2315
const __sharedMemory = new WebAssembly.Memory({
24-
initial: 1024,
25-
maximum: 10240,
16+
initial: 4000,
17+
maximum: 65536,
2618
shared: true,
2719
})
2820

packages/bcrypt/bcrypt.wasi.cjs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,30 @@ const {
1313
getDefaultContext: __emnapiGetDefaultContext,
1414
} = require('@napi-rs/wasm-runtime')
1515

16+
const __rootDir = __nodePath.parse(process.cwd()).root
17+
1618
const __wasi = new __nodeWASI({
1719
version: 'preview1',
1820
env: process.env,
1921
preopens: {
20-
'/': '/'
22+
[__rootDir]: __rootDir,
2123
}
2224
})
2325

2426
const __emnapiContext = __emnapiGetDefaultContext()
2527

2628
const __sharedMemory = new WebAssembly.Memory({
27-
initial: 1024,
28-
maximum: 10240,
29+
initial: 4000,
30+
maximum: 65536,
2931
shared: true,
3032
})
3133

3234
let __wasmFilePath = __nodePath.join(__dirname, 'bcrypt.wasm32-wasi.wasm')
35+
const __wasmDebugFilePath = __nodePath.join(__dirname, 'bcrypt.wasm32-wasi.debug.wasm')
3336

34-
if (!__nodeFs.existsSync(__wasmFilePath)) {
37+
if (__nodeFs.existsSync(__wasmDebugFilePath)) {
38+
__wasmFilePath = __wasmDebugFilePath
39+
} else if (!__nodeFs.existsSync(__wasmFilePath)) {
3540
try {
3641
__wasmFilePath = __nodePath.resolve('@node-rs/bcrypt-wasm32-wasi')
3742
} catch {

packages/bcrypt/binding.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* auto-generated by NAPI-RS */
22
/* eslint-disable */
3-
43
export const DEFAULT_COST: number
54

65
export function genSalt(round: number, version?: '2a' | '2x' | '2y' | '2b', signal?: AbortSignal): Promise<string>

0 commit comments

Comments
 (0)