Skip to content

Commit 7914fd5

Browse files
authored
feat: upgrade napi-rs to v2 (#561)
1 parent f07c601 commit 7914fd5

File tree

106 files changed

+3821
-1936
lines changed

Some content is hidden

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

106 files changed

+3821
-1936
lines changed

.eslintrc.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ env:
1111

1212
plugins:
1313
- import
14-
- sonarjs
1514

1615
extends:
1716
- eslint:recommended
18-
- plugin:sonarjs/recommended
1917
- plugin:prettier/recommended
2018

2119
rules:
@@ -55,12 +53,6 @@ rules:
5553
},
5654
]
5755

58-
'sonarjs/cognitive-complexity': 0
59-
'sonarjs/no-duplicate-string': 0
60-
'sonarjs/no-big-function': 0
61-
'sonarjs/no-identical-functions': 0
62-
'sonarjs/no-small-switch': 0
63-
6456
overrides:
6557
- files:
6658
- packages/**/*.ts

.github/workflows/ci.yaml

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,38 @@ jobs:
2020
matrix:
2121
settings:
2222
- host: macos-latest
23+
architecture: x64
2324
target: 'x86_64-apple-darwin'
2425
build: |
2526
yarn build
2627
strip -x packages/*/*.node
2728
- host: windows-latest
29+
architecture: x64
2830
build: yarn build
2931
target: 'x86_64-pc-windows-msvc'
3032
- host: windows-latest
33+
architecture: x86
3134
build: |
32-
export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=32;
33-
export CARGO_PROFILE_RELEASE_LTO=false
3435
npx lerna exec "yarn build --target i686-pc-windows-msvc" --concurrency 1 --stream --no-prefix
3536
yarn test
3637
target: 'i686-pc-windows-msvc'
37-
setup: |
38-
choco install nodejs-lts --x86 -y --force
39-
echo "C:\\Program Files (x86)\\nodejs" >> $GITHUB_PATH
4038
- host: ubuntu-latest
39+
architecture: x64
4140
target: 'x86_64-unknown-linux-gnu'
4241
docker: |
4342
docker pull $DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-debian
4443
docker tag $DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-debian builder
4544
build: |
4645
docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/build -w /build builder yarn build
4746
- host: ubuntu-latest
47+
architecture: x64
4848
target: 'x86_64-unknown-linux-musl'
4949
docker: |
5050
docker pull $DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-alpine
5151
docker tag $DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-alpine builder
5252
build: docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/build -w /build builder yarn build
5353
- host: macos-latest
54+
architecture: x64
5455
target: 'aarch64-apple-darwin'
5556
build: |
5657
sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/*;
@@ -61,31 +62,47 @@ jobs:
6162
npx lerna exec "yarn build --target aarch64-apple-darwin" --concurrency 1 --stream --no-prefix
6263
strip -x packages/*/*.node
6364
- host: ubuntu-latest
65+
architecture: x64
6466
target: 'aarch64-unknown-linux-gnu'
6567
setup: |
6668
sudo apt-get update
6769
sudo apt-get install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu -y
6870
build: npx lerna exec "yarn build --target aarch64-unknown-linux-gnu" --concurrency 1 --stream --no-prefix
6971
- host: ubuntu-latest
72+
architecture: x64
7073
target: 'armv7-unknown-linux-gnueabihf'
7174
setup: |
7275
sudo apt-get update
7376
sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y
7477
build: npx lerna exec "yarn build --target armv7-unknown-linux-gnueabihf" --concurrency 1 --stream --no-prefix
7578
- host: ubuntu-latest
76-
target: 'aarch64-linux-android'
79+
architecture: x64
80+
target: aarch64-linux-android
7781
build: |
7882
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"
83+
export CC="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"
84+
export CXX="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang++"
7985
export PATH="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin:${PATH}"
8086
npx lerna exec "yarn build --target aarch64-linux-android" --concurrency 1 --stream --no-prefix
8187
- host: ubuntu-latest
88+
architecture: x64
89+
target: armv7-linux-androideabi
90+
build: |
91+
export CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang"
92+
export CC="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang"
93+
export CXX="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang++"
94+
export PATH="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin:${PATH}"
95+
npx lerna exec "yarn build --target armv7-linux-androideabi" --concurrency 1 --stream --no-prefix
96+
- host: ubuntu-latest
97+
architecture: x64
8298
target: 'aarch64-unknown-linux-musl'
8399
downloadTarget: 'aarch64-unknown-linux-musl'
84100
docker: |
85101
docker pull ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
86102
docker tag ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine builder
87103
build: docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/node-rs -w /node-rs builder sh -c "rustup toolchain install $(cat ./rust-toolchain) && rustup target add aarch64-unknown-linux-musl && yarn global add lerna && lerna exec \"yarn build --target aarch64-unknown-linux-musl\" --concurrency 1 --stream --no-prefix"
88104
- host: windows-latest
105+
architecture: x64
89106
target: 'aarch64-pc-windows-msvc'
90107
build: npx lerna exec "yarn build --target aarch64-pc-windows-msvc" --concurrency 1 --stream --no-prefix
91108

@@ -100,6 +117,8 @@ jobs:
100117
with:
101118
node-version: 16
102119
check-latest: true
120+
cache: yarn
121+
architecture: ${{ matrix.settings.architecture }}
103122

104123
- name: Install
105124
uses: actions-rs/toolchain@v1
@@ -273,6 +292,7 @@ jobs:
273292
with:
274293
node-version: ${{ matrix.node }}
275294
check-latest: true
295+
cache: yarn
276296

277297
- name: Install dependencies
278298
run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
@@ -321,6 +341,7 @@ jobs:
321341
with:
322342
node-version: ${{ matrix.node }}
323343
check-latest: true
344+
cache: yarn
324345

325346
- name: Install dependencies
326347
run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
@@ -389,6 +410,7 @@ jobs:
389410
image: ghcr.io/napi-rs/napi-rs/nodejs:aarch64-${{ matrix.node }}
390411
options: -v ${{ github.workspace }}:/build -w /build
391412
run: |
413+
set -e
392414
yarn build:ts
393415
yarn test
394416
ls -la
@@ -428,6 +450,7 @@ jobs:
428450
image: multiarch/alpine:aarch64-latest-stable
429451
options: -v ${{ github.workspace }}:/build -w /build
430452
run: |
453+
set -e
431454
apk add nodejs npm yarn
432455
yarn build:ts
433456
yarn test
@@ -470,6 +493,7 @@ jobs:
470493
image: ghcr.io/napi-rs/napi-rs/nodejs:armhf-${{ matrix.node }}
471494
options: -v ${{ github.workspace }}:/build -w /build
472495
run: |
496+
set -e
473497
yarn build:ts
474498
yarn test
475499
ls -la
@@ -490,8 +514,9 @@ jobs:
490514
- name: Setup node
491515
uses: actions/setup-node@v2-beta
492516
with:
493-
node-version: 14
517+
node-version: 16
494518
check-latest: true
519+
cache: yarn
495520

496521
- name: Cache NPM dependencies
497522
uses: actions/cache@v2

package.json

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,66 +5,72 @@
55
"author": "LongYinan <[email protected]>",
66
"license": "MIT",
77
"private": true,
8-
"workspaces": ["packages/*"],
8+
"workspaces": [
9+
"packages/*"
10+
],
911
"scripts": {
1012
"artifacts": "lerna run artifacts",
1113
"bench": "lerna run bench --concurrency 1 --stream --no-prefix",
1214
"build": "lerna run build --concurrency 1 --stream --no-prefix",
1315
"build:ts": "tsc -b tsconfig.project.json -verbose",
1416
"lint": "eslint . -c ./.eslintrc.yml \"packages/**/*.{ts,js}\"",
1517
"test": "ava",
16-
"format": "run-p format:md format:json format:yaml format:source",
17-
"format:md": "prettier --parser markdown --write \"./**/*.md\"",
18-
"format:json": "prettier --parser json --write \"./**/*.json\"",
19-
"format:source": "prettier --config ./package.json --write \"./**/*.{js,ts}\"",
20-
"format:yaml": "prettier --parser yaml --write \"./**/*.{yml,yaml}\"",
18+
"format": "run-p format:prettier format:rs",
19+
"format:prettier": "prettier --config ./package.json -w .",
20+
"format:rs": "cargo fmt --all",
2121
"typecheck": "tsc -b tsconfig.project.json -verbose",
2222
"postinstall": "husky install"
2323
},
2424
"devDependencies": {
25-
"@napi-rs/cli": "^1.3.5",
26-
"@swc-node/register": "^1.4.0",
27-
"@types/node": "^16.11.12",
28-
"@typescript-eslint/eslint-plugin": "^4.33.0",
29-
"@typescript-eslint/parser": "^4.33.0",
25+
"@napi-rs/cli": "^2.0.0",
26+
"@swc-node/register": "^1.4.2",
27+
"@types/node": "^17.0.0",
28+
"@typescript-eslint/eslint-plugin": "^5.7.0",
29+
"@typescript-eslint/parser": "^5.7.0",
3030
"ava": "^3.15.0",
3131
"benchmark": "^2.1.4",
3232
"codecov": "^3.8.3",
3333
"cross-env": "^7.0.3",
34-
"eslint": "^7.32.0",
34+
"eslint": "^8.4.1",
3535
"eslint-config-prettier": "^8.3.0",
3636
"eslint-plugin-import": "^2.25.3",
3737
"eslint-plugin-prettier": "^4.0.0",
38-
"eslint-plugin-sonarjs": "^0.11.0",
3938
"husky": "^7.0.4",
4039
"lerna": "^4.0.0",
4140
"lint-staged": "^12.1.2",
4241
"npm-run-all": "^4.1.5",
4342
"nyc": "^15.1.0",
4443
"prettier": "^2.5.1",
4544
"tslib": "^2.3.1",
46-
"typescript": "^4.5.3"
45+
"typescript": "^4.5.4"
4746
},
4847
"ava": {
49-
"extensions": ["ts"],
50-
"require": ["@swc-node/register"],
51-
"files": ["packages/**/*.spec.ts"],
48+
"extensions": [
49+
"ts"
50+
],
51+
"require": [
52+
"@swc-node/register"
53+
],
54+
"files": [
55+
"packages/**/*.spec.ts"
56+
],
5257
"environmentVariables": {
5358
"TS_NODE_PROJECT": "./tsconfig.test.json"
5459
}
5560
},
5661
"lint-staged": {
57-
"*.@(js|ts|tsx)": ["prettier --write", "eslint -c .eslintrc.yml --fix"],
58-
"*.@(yml|yaml)": ["prettier --parser yaml --write"],
59-
"*.json": ["prettier --parser json --write"],
60-
"*.md": ["prettier --parser markdown --write"]
62+
"*.@(js|ts|tsx)": [
63+
"eslint -c .eslintrc.yml --fix"
64+
],
65+
"*.@(js|ts|tsx|yml|yaml|json|md)": [
66+
"prettier --write"
67+
]
6168
},
6269
"prettier": {
6370
"printWidth": 120,
6471
"semi": false,
6572
"trailingComma": "all",
6673
"singleQuote": true,
67-
"arrowParens": "always",
68-
"parser": "typescript"
74+
"arrowParens": "always"
6975
}
7076
}

packages/bcrypt/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ crate-type = ["cdylib"]
1111
blowfish = {version = "0.8", features = ["bcrypt"]}
1212
byteorder = "1"
1313
global_alloc = {path = "../../crates/alloc"}
14-
napi = "1"
15-
napi-derive = "1"
14+
napi = {version = "2"}
15+
napi-derive = {version = "2"}
1616
phf = {version = "0.10", features = ["macros"]}
1717
radix64 = "0.6"
1818
rand = "0.8"
@@ -21,4 +21,4 @@ rand = "0.8"
2121
quickcheck = "1.0"
2222

2323
[build-dependencies]
24-
napi-build = "1.1.0"
24+
napi-build = "1"

packages/bcrypt/index.d.ts

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
export const DEFAULT_COST: 12
1+
/* eslint-disable */
22

3-
export function hashSync(password: string | Buffer, round?: number): string
4-
export function hash(password: string | Buffer, round?: number): Promise<string>
5-
export function verifySync(password: string | Buffer, hash: string | Buffer): boolean
6-
export function verify(password: string | Buffer, hash: string | Buffer): Promise<boolean>
7-
/**
8-
* The same with `verifySync`
9-
*/
10-
export function compareSync(password: string | Buffer, hash: string | Buffer): boolean
11-
/**
12-
* The same with `verify`
13-
*/
14-
export function compare(password: string | Buffer, hash: string | Buffer): Promise<boolean>
15-
16-
export type Version = '2a' | '2x' | '2y' | '2b'
17-
/**
18-
* @param round default 10
19-
* @param version default '2b'
20-
*/
21-
export function genSaltSync(round?: number, version?: Version): string
22-
/**
23-
* @param round default 10
24-
* @param version default '2b'
25-
*/
26-
export function genSalt(round?: number, version?: Version): Promise<string>
3+
export class ExternalObject<T> {
4+
readonly '': {
5+
readonly '': unique symbol
6+
[K: symbol]: T
7+
}
8+
}
9+
export const DEFAULT_COST: number
10+
export function genSaltSync(round: number, version: string): string
11+
export function genSalt(round: number, version: string, signal?: AbortSignal | undefined | null): Promise<string>
12+
export function hashSync(input: string | Buffer, cost?: number | undefined | null): string
13+
export function hash(
14+
input: string | Buffer,
15+
cost?: number | undefined | null,
16+
signal?: AbortSignal | undefined | null,
17+
): Promise<string>
18+
export function verifySync(input: string | Buffer, hash: string | Buffer): boolean
19+
export function verify(
20+
password: string | Buffer,
21+
hash: string | Buffer,
22+
signal?: AbortSignal | undefined | null,
23+
): Promise<boolean>

0 commit comments

Comments
 (0)