Skip to content

Commit

Permalink
feat: upgrade napi-rs to v2 (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Dec 17, 2021
1 parent f07c601 commit 7914fd5
Show file tree
Hide file tree
Showing 106 changed files with 3,821 additions and 1,936 deletions.
8 changes: 0 additions & 8 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ env:

plugins:
- import
- sonarjs

extends:
- eslint:recommended
- plugin:sonarjs/recommended
- plugin:prettier/recommended

rules:
Expand Down Expand Up @@ -55,12 +53,6 @@ rules:
},
]

'sonarjs/cognitive-complexity': 0
'sonarjs/no-duplicate-string': 0
'sonarjs/no-big-function': 0
'sonarjs/no-identical-functions': 0
'sonarjs/no-small-switch': 0

overrides:
- files:
- packages/**/*.ts
Expand Down
39 changes: 32 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,38 @@ jobs:
matrix:
settings:
- host: macos-latest
architecture: x64
target: 'x86_64-apple-darwin'
build: |
yarn build
strip -x packages/*/*.node
- host: windows-latest
architecture: x64
build: yarn build
target: 'x86_64-pc-windows-msvc'
- host: windows-latest
architecture: x86
build: |
export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=32;
export CARGO_PROFILE_RELEASE_LTO=false
npx lerna exec "yarn build --target i686-pc-windows-msvc" --concurrency 1 --stream --no-prefix
yarn test
target: 'i686-pc-windows-msvc'
setup: |
choco install nodejs-lts --x86 -y --force
echo "C:\\Program Files (x86)\\nodejs" >> $GITHUB_PATH
- host: ubuntu-latest
architecture: x64
target: 'x86_64-unknown-linux-gnu'
docker: |
docker pull $DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-debian
docker tag $DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-debian builder
build: |
docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/build -w /build builder yarn build
- host: ubuntu-latest
architecture: x64
target: 'x86_64-unknown-linux-musl'
docker: |
docker pull $DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-alpine
docker tag $DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-alpine builder
build: docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/build -w /build builder yarn build
- host: macos-latest
architecture: x64
target: 'aarch64-apple-darwin'
build: |
sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/*;
Expand All @@ -61,31 +62,47 @@ jobs:
npx lerna exec "yarn build --target aarch64-apple-darwin" --concurrency 1 --stream --no-prefix
strip -x packages/*/*.node
- host: ubuntu-latest
architecture: x64
target: 'aarch64-unknown-linux-gnu'
setup: |
sudo apt-get update
sudo apt-get install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu -y
build: npx lerna exec "yarn build --target aarch64-unknown-linux-gnu" --concurrency 1 --stream --no-prefix
- host: ubuntu-latest
architecture: x64
target: 'armv7-unknown-linux-gnueabihf'
setup: |
sudo apt-get update
sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y
build: npx lerna exec "yarn build --target armv7-unknown-linux-gnueabihf" --concurrency 1 --stream --no-prefix
- host: ubuntu-latest
target: 'aarch64-linux-android'
architecture: x64
target: aarch64-linux-android
build: |
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"
export CC="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"
export CXX="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang++"
export PATH="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin:${PATH}"
npx lerna exec "yarn build --target aarch64-linux-android" --concurrency 1 --stream --no-prefix
- host: ubuntu-latest
architecture: x64
target: armv7-linux-androideabi
build: |
export CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang"
export CC="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang"
export CXX="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang++"
export PATH="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin:${PATH}"
npx lerna exec "yarn build --target armv7-linux-androideabi" --concurrency 1 --stream --no-prefix
- host: ubuntu-latest
architecture: x64
target: 'aarch64-unknown-linux-musl'
downloadTarget: 'aarch64-unknown-linux-musl'
docker: |
docker pull ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
docker tag ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine builder
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"
- host: windows-latest
architecture: x64
target: 'aarch64-pc-windows-msvc'
build: npx lerna exec "yarn build --target aarch64-pc-windows-msvc" --concurrency 1 --stream --no-prefix

Expand All @@ -100,6 +117,8 @@ jobs:
with:
node-version: 16
check-latest: true
cache: yarn
architecture: ${{ matrix.settings.architecture }}

- name: Install
uses: actions-rs/toolchain@v1
Expand Down Expand Up @@ -273,6 +292,7 @@ jobs:
with:
node-version: ${{ matrix.node }}
check-latest: true
cache: yarn

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

- name: Install dependencies
run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
Expand Down Expand Up @@ -389,6 +410,7 @@ jobs:
image: ghcr.io/napi-rs/napi-rs/nodejs:aarch64-${{ matrix.node }}
options: -v ${{ github.workspace }}:/build -w /build
run: |
set -e
yarn build:ts
yarn test
ls -la
Expand Down Expand Up @@ -428,6 +450,7 @@ jobs:
image: multiarch/alpine:aarch64-latest-stable
options: -v ${{ github.workspace }}:/build -w /build
run: |
set -e
apk add nodejs npm yarn
yarn build:ts
yarn test
Expand Down Expand Up @@ -470,6 +493,7 @@ jobs:
image: ghcr.io/napi-rs/napi-rs/nodejs:armhf-${{ matrix.node }}
options: -v ${{ github.workspace }}:/build -w /build
run: |
set -e
yarn build:ts
yarn test
ls -la
Expand All @@ -490,8 +514,9 @@ jobs:
- name: Setup node
uses: actions/setup-node@v2-beta
with:
node-version: 14
node-version: 16
check-latest: true
cache: yarn

- name: Cache NPM dependencies
uses: actions/cache@v2
Expand Down
52 changes: 29 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,72 @@
"author": "LongYinan <lynweklm@gmail.com>",
"license": "MIT",
"private": true,
"workspaces": ["packages/*"],
"workspaces": [
"packages/*"
],
"scripts": {
"artifacts": "lerna run artifacts",
"bench": "lerna run bench --concurrency 1 --stream --no-prefix",
"build": "lerna run build --concurrency 1 --stream --no-prefix",
"build:ts": "tsc -b tsconfig.project.json -verbose",
"lint": "eslint . -c ./.eslintrc.yml \"packages/**/*.{ts,js}\"",
"test": "ava",
"format": "run-p format:md format:json format:yaml format:source",
"format:md": "prettier --parser markdown --write \"./**/*.md\"",
"format:json": "prettier --parser json --write \"./**/*.json\"",
"format:source": "prettier --config ./package.json --write \"./**/*.{js,ts}\"",
"format:yaml": "prettier --parser yaml --write \"./**/*.{yml,yaml}\"",
"format": "run-p format:prettier format:rs",
"format:prettier": "prettier --config ./package.json -w .",
"format:rs": "cargo fmt --all",
"typecheck": "tsc -b tsconfig.project.json -verbose",
"postinstall": "husky install"
},
"devDependencies": {
"@napi-rs/cli": "^1.3.5",
"@swc-node/register": "^1.4.0",
"@types/node": "^16.11.12",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"@napi-rs/cli": "^2.0.0",
"@swc-node/register": "^1.4.2",
"@types/node": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^5.7.0",
"@typescript-eslint/parser": "^5.7.0",
"ava": "^3.15.0",
"benchmark": "^2.1.4",
"codecov": "^3.8.3",
"cross-env": "^7.0.3",
"eslint": "^7.32.0",
"eslint": "^8.4.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-sonarjs": "^0.11.0",
"husky": "^7.0.4",
"lerna": "^4.0.0",
"lint-staged": "^12.1.2",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"prettier": "^2.5.1",
"tslib": "^2.3.1",
"typescript": "^4.5.3"
"typescript": "^4.5.4"
},
"ava": {
"extensions": ["ts"],
"require": ["@swc-node/register"],
"files": ["packages/**/*.spec.ts"],
"extensions": [
"ts"
],
"require": [
"@swc-node/register"
],
"files": [
"packages/**/*.spec.ts"
],
"environmentVariables": {
"TS_NODE_PROJECT": "./tsconfig.test.json"
}
},
"lint-staged": {
"*.@(js|ts|tsx)": ["prettier --write", "eslint -c .eslintrc.yml --fix"],
"*.@(yml|yaml)": ["prettier --parser yaml --write"],
"*.json": ["prettier --parser json --write"],
"*.md": ["prettier --parser markdown --write"]
"*.@(js|ts|tsx)": [
"eslint -c .eslintrc.yml --fix"
],
"*.@(js|ts|tsx|yml|yaml|json|md)": [
"prettier --write"
]
},
"prettier": {
"printWidth": 120,
"semi": false,
"trailingComma": "all",
"singleQuote": true,
"arrowParens": "always",
"parser": "typescript"
"arrowParens": "always"
}
}
6 changes: 3 additions & 3 deletions packages/bcrypt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ crate-type = ["cdylib"]
blowfish = {version = "0.8", features = ["bcrypt"]}
byteorder = "1"
global_alloc = {path = "../../crates/alloc"}
napi = "1"
napi-derive = "1"
napi = {version = "2"}
napi-derive = {version = "2"}
phf = {version = "0.10", features = ["macros"]}
radix64 = "0.6"
rand = "0.8"
Expand All @@ -21,4 +21,4 @@ rand = "0.8"
quickcheck = "1.0"

[build-dependencies]
napi-build = "1.1.0"
napi-build = "1"
47 changes: 22 additions & 25 deletions packages/bcrypt/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
export const DEFAULT_COST: 12
/* eslint-disable */

export function hashSync(password: string | Buffer, round?: number): string
export function hash(password: string | Buffer, round?: number): Promise<string>
export function verifySync(password: string | Buffer, hash: string | Buffer): boolean
export function verify(password: string | Buffer, hash: string | Buffer): Promise<boolean>
/**
* The same with `verifySync`
*/
export function compareSync(password: string | Buffer, hash: string | Buffer): boolean
/**
* The same with `verify`
*/
export function compare(password: string | Buffer, hash: string | Buffer): Promise<boolean>

export type Version = '2a' | '2x' | '2y' | '2b'
/**
* @param round default 10
* @param version default '2b'
*/
export function genSaltSync(round?: number, version?: Version): string
/**
* @param round default 10
* @param version default '2b'
*/
export function genSalt(round?: number, version?: Version): Promise<string>
export class ExternalObject<T> {
readonly '': {
readonly '': unique symbol
[K: symbol]: T
}
}
export const DEFAULT_COST: number
export function genSaltSync(round: number, version: string): string
export function genSalt(round: number, version: string, signal?: AbortSignal | undefined | null): Promise<string>
export function hashSync(input: string | Buffer, cost?: number | undefined | null): string
export function hash(
input: string | Buffer,
cost?: number | undefined | null,
signal?: AbortSignal | undefined | null,
): Promise<string>
export function verifySync(input: string | Buffer, hash: string | Buffer): boolean
export function verify(
password: string | Buffer,
hash: string | Buffer,
signal?: AbortSignal | undefined | null,
): Promise<boolean>

0 comments on commit 7914fd5

Please sign in to comment.