Skip to content

Commit ef96dda

Browse files
authored
chore: refresh the infra (#915)
1 parent 0313600 commit ef96dda

Some content is hidden

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

54 files changed

+873
-1227
lines changed

.github/workflows/ci.yaml

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,60 @@ jobs:
4242
run: yarn lint
4343

4444
- name: TypeCheck
45-
run: yarn typecheck
45+
run: yarn build:ts
4646

4747
- name: Cargo fmt
4848
run: cargo fmt -- --check
4949

5050
- name: Clippy
5151
run: cargo clippy
52+
bench:
53+
name: Bench
54+
runs-on: ${{ matrix.settings.host }}
55+
strategy:
56+
fail-fast: false
57+
matrix:
58+
settings:
59+
- target: 'x86_64-unknown-linux-gnu'
60+
host: ubuntu-latest
61+
- target: 'aarch64-apple-darwin'
62+
host: macos-latest
63+
steps:
64+
- uses: actions/checkout@v4
65+
66+
- name: Setup node
67+
uses: actions/setup-node@v4
68+
with:
69+
node-version: 20
70+
71+
- name: Cache cargo registry
72+
uses: actions/cache@v4
73+
with:
74+
path: |
75+
~/.cargo/registry
76+
~/.cargo/git
77+
~/.napi-rs
78+
target
79+
key: bench-cargo-registry-${{ matrix.settings.target }}
80+
81+
- name: Install
82+
uses: ./.github/actions/setup-rust
83+
with:
84+
targets: ${{ matrix.settings.target }}
85+
86+
- name: Setup macos
87+
if: ${{ matrix.settings.host == 'macos-latest' }}
88+
run: brew install python-setuptools
89+
90+
- name: 'Install dependencies'
91+
run: yarn install
92+
93+
- name: build
94+
run: yarn build
95+
96+
- name: Bench
97+
run: yarn workspaces foreach -A -j 1 --no-private run bench
98+
5299
build:
53100
strategy:
54101
fail-fast: false
@@ -578,6 +625,7 @@ jobs:
578625
runs-on: ubuntu-latest
579626
needs:
580627
- lint
628+
- bench
581629
- build-freebsd
582630
- test-linux-x64-gnu-binding
583631
- test-linux-x64-musl-binding

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ resolver = "2"
2323
rand_core = { version = "0.6", features = ["getrandom"] }
2424
serde = "1.0"
2525
serde_json = "1.0"
26-
xxhash-rust = { version = "0.8", features = ["xxh32", "xxh64", "xxh3"] }
26+
xxhash-rust = { version = "0.8", features = ["xxh32", "const_xxh32", "xxh64", "const_xxh64", "xxh3", "const_xxh3"] }
2727
[profile.release]
2828
codegen-units = 1
2929
lto = true

ava.config.mjs

Lines changed: 0 additions & 13 deletions
This file was deleted.

depracted/deno-lint/package.json

Lines changed: 1 addition & 1 deletion
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.63",
76+
"@napi-rs/cli": "^3.0.0-alpha.64",
7777
"@types/webpack": "^5.28.5"
7878
},
7979
"funding": {

package.json

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,30 @@
1111
],
1212
"scripts": {
1313
"artifacts": "yarn workspaces foreach -A --no-private run artifacts",
14-
"bench": "lerna run bench --concurrency 1 --stream --no-prefix",
1514
"build": "yarn workspaces foreach -A --no-private -j 1 run build",
16-
"build:ts": "tsc -b tsconfig.project.json -verbose",
15+
"build:ts": "tsc -b tsconfig.json -verbose",
1716
"lint": "oxlint .",
1817
"test": "ava",
1918
"format": "run-p format:prettier format:rs format:toml",
2019
"format:prettier": "prettier --config ./package.json -w .",
2120
"format:rs": "cargo fmt --all",
2221
"format:toml": "taplo format",
23-
"typecheck": "tsc -b tsconfig.project.json -verbose",
2422
"postinstall": "husky install"
2523
},
2624
"devDependencies": {
27-
"@napi-rs/cli": "^3.0.0-alpha.63",
25+
"@napi-rs/cli": "^3.0.0-alpha.64",
2826
"@napi-rs/wasm-runtime": "^0.2.5",
29-
"@swc-node/core": "^1.13.3",
30-
"@swc-node/register": "^1.10.9",
31-
"@swc/core": "^1.7.26",
3227
"@taplo/cli": "^0.7.0",
3328
"@tybys/wasm-util": "^0.9.0",
3429
"@types/node": "^22.7.4",
3530
"ava": "^6.1.3",
36-
"benchmark": "^2.1.4",
37-
"codecov": "^3.8.3",
3831
"cross-env": "^7.0.3",
3932
"husky": "^9.1.6",
4033
"lerna": "^8.1.8",
4134
"lint-staged": "^15.2.10",
4235
"npm-run-all2": "^7.0.0",
4336
"oxlint": "^0.10.0",
4437
"prettier": "^3.3.3",
45-
"ts-node": "^10.9.2",
4638
"tslib": "^2.7.0",
4739
"typescript": "^5.6.2"
4840
},
@@ -60,6 +52,20 @@
6052
"cargo fmt --"
6153
]
6254
},
55+
"ava": {
56+
"extensions": {
57+
"ts": "module"
58+
},
59+
"nodeArguments": [
60+
"--import",
61+
"@oxc-node/core/register"
62+
],
63+
"timeout": "1m",
64+
"cache": false,
65+
"files": [
66+
"packages/*/__test__/**/*.spec.ts"
67+
]
68+
},
6369
"prettier": {
6470
"printWidth": 120,
6571
"semi": false,

packages/argon2/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ It has a simple design aimed at the highest memory filling rate and effective us
2929

3030
# Benchmarks
3131

32-
See [benchmark/](benchmark/argon2.js).
32+
See [benchmark/](benchmark/argon2.ts).
3333

3434
## API
3535

packages/argon2/__test__/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "module"
3+
}

packages/argon2/benchmark/argon2.js renamed to packages/argon2/benchmark/argon2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const HASHED = await hash(PASSWORD, {
1313
parallelism: CORES,
1414
})
1515

16-
const bench = new Bench('Hash with all cores')
16+
const bench = new Bench()
1717

1818
bench
1919
.add('@node-rs/argon hash', async () => {

packages/argon2/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// prettier-ignore
22
/* eslint-disable */
3+
// @ts-nocheck
34
/* auto-generated by NAPI-RS */
45

5-
const { readFileSync } = require('fs')
6+
const { createRequire } = require('node:module')
7+
require = createRequire(__filename)
68

9+
const { readFileSync } = require('node:fs')
710
let nativeBinding = null
811
const loadErrors = []
912

packages/argon2/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@
5555
},
5656
"scripts": {
5757
"artifacts": "napi artifacts -d ../../artifacts",
58-
"bench": "cross-env NODE_ENV=production node benchmark/argon2.js",
58+
"bench": "cross-env NODE_ENV=production node --import @oxc-node/core/register benchmark/argon2.ts",
5959
"build": "napi build --platform --release",
6060
"build:debug": "napi build --platform",
6161
"prepublishOnly": "napi prepublish",
6262
"version": "napi version && git add npm"
6363
},
6464
"devDependencies": {
65-
"@napi-rs/cli": "^3.0.0-alpha.63",
65+
"@napi-rs/cli": "^3.0.0-alpha.64",
6666
"argon2": "^0.41.0",
6767
"cross-env": "^7.0.3",
6868
"tinybench": "^2.9.0"

packages/argon2/tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "dist",
5+
"composite": true
6+
},
7+
"exclude": ["dist"],
8+
"include": ["benchmark", "__tests__"]
9+
}

packages/bcrypt/binding.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ export declare function genSalt(round: number, version?: '2a' | '2x' | '2y' | '2
66

77
export declare function genSaltSync(round: number, version?: '2a' | '2x' | '2y' | '2b'): string
88

9-
export declare function hash(input: Uint8Array | string, cost?: number | undefined | null, salt?: string | Buffer | undefined | null, signal?: AbortSignal | undefined | null): Promise<string>
9+
export declare function hash(input: Uint8Array | string, cost?: number | undefined | null, salt?: string | Uint8Array | undefined | null, signal?: AbortSignal | undefined | null): Promise<string>
1010

11-
export declare function hashSync(input: string | Buffer, cost?: number | undefined | null, salt?: string | Buffer | undefined | null): string
11+
export declare function hashSync(input: string | Uint8Array, cost?: number | undefined | null, salt?: string | Uint8Array | undefined | null): string
1212

1313
export declare function verify(password: Uint8Array | string, hash: Uint8Array | string, signal?: AbortSignal | undefined | null): Promise<boolean>
1414

15-
export declare function verifySync(input: string | Buffer, hash: string | Buffer): boolean
15+
export declare function verifySync(input: string | Uint8Array, hash: string | Uint8Array): boolean

packages/bcrypt/binding.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// prettier-ignore
22
/* eslint-disable */
3+
// @ts-nocheck
34
/* auto-generated by NAPI-RS */
45

5-
const { readFileSync } = require('fs')
6+
const { createRequire } = require('node:module')
7+
require = createRequire(__filename)
68

9+
const { readFileSync } = require('node:fs')
710
let nativeBinding = null
811
const loadErrors = []
912

packages/bcrypt/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
},
6161
"scripts": {
6262
"artifacts": "napi artifacts -d ../../artifacts",
63-
"bench": "cross-env NODE_ENV=production node --import @swc-node/register/esm-register benchmark/bcrypt.ts",
63+
"bench": "cross-env NODE_ENV=production node --import @oxc-node/core/register benchmark/bcrypt.ts",
6464
"build": "napi build --platform --release --js binding.js --dts binding.d.ts",
6565
"build:debug": "napi build --platform",
6666
"prepublishOnly": "napi prepublish",
@@ -72,7 +72,7 @@
7272
"devDependencies": {
7373
"@cwasm/openbsd-bcrypt": "^0.1.0",
7474
"@cwasm/openwall-bcrypt": "^0.1.0",
75-
"@napi-rs/cli": "^3.0.0-alpha.63",
75+
"@napi-rs/cli": "^3.0.0-alpha.64",
7676
"@types/bcrypt": "^5.0.2",
7777
"@types/bcryptjs": "^2.4.6",
7878
"bcrypt": "^5.1.1",

packages/bcrypt/src/lib.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,37 +44,35 @@ pub fn gen_salt_js(
4444
}
4545

4646
#[napi]
47+
#[inline]
4748
pub fn hash_sync(
48-
input: Either<String, Buffer>,
49+
input: Either<String, &[u8]>,
4950
cost: Option<u32>,
50-
salt: Option<Either<String, Buffer>>,
51+
salt: Option<Either<String, &[u8]>>,
5152
) -> Result<String> {
5253
let salt = if let Some(salt) = salt {
5354
let mut s = [0u8; 16];
54-
let buf = either_string_buffer_as_bytes(&salt);
55+
let buf = salt.as_ref();
5556
// make sure salt buffer length should be 16
5657
let copy_length = cmp::min(buf.len(), s.len());
5758
s[..copy_length].copy_from_slice(&buf[..copy_length]);
5859
s
5960
} else {
60-
gen_salt()
61+
rand::random()
6162
};
62-
match input {
63-
Either::A(s) => HashTask::hash(s.as_bytes(), salt, cost.unwrap_or(DEFAULT_COST)),
64-
Either::B(b) => HashTask::hash(b.as_ref(), salt, cost.unwrap_or(DEFAULT_COST)),
65-
}
63+
HashTask::hash(input.as_ref(), salt, cost.unwrap_or(DEFAULT_COST))
6664
}
6765

6866
#[napi]
6967
pub fn hash(
7068
input: Either<Uint8Array, String>,
7169
cost: Option<u32>,
72-
salt: Option<Either<String, Buffer>>,
70+
salt: Option<Either<String, &[u8]>>,
7371
signal: Option<AbortSignal>,
7472
) -> Result<AsyncTask<HashTask>> {
7573
let salt = if let Some(salt) = salt {
7674
let mut s = [0u8; 16];
77-
let buf = either_string_buffer_as_bytes(&salt);
75+
let buf = salt.as_ref();
7876
// make sure salt buffer length should be 16
7977
let copy_length = cmp::min(buf.len(), s.len());
8078
s[..copy_length].copy_from_slice(&buf[..copy_length]);
@@ -87,20 +85,11 @@ pub fn hash(
8785
}
8886

8987
#[napi]
90-
pub fn verify_sync(input: Either<String, Buffer>, hash: Either<String, Buffer>) -> Result<bool> {
91-
let input = either_string_buffer_as_bytes(&input);
92-
let hash = either_string_buffer_as_bytes(&hash);
88+
#[inline]
89+
pub fn verify_sync(input: Either<String, &[u8]>, hash: Either<String, &[u8]>) -> Result<bool> {
9390
VerifyTask::verify(input, hash)
9491
}
9592

96-
#[inline(always)]
97-
fn either_string_buffer_as_bytes(input: &Either<String, Buffer>) -> &[u8] {
98-
match input {
99-
Either::A(s) => s.as_bytes(),
100-
Either::B(b) => b.as_ref(),
101-
}
102-
}
103-
10493
#[napi]
10594
pub fn verify(
10695
password: Either<Uint8Array, String>,

packages/bcrypt/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
4-
"outDir": "dist"
4+
"outDir": "dist",
5+
"composite": true
56
},
67
"exclude": ["dist"],
78
"include": ["__tests__"]

packages/crc32/README.md

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,6 @@ js_crc32 for inputs 16931844B, avg 2066B x 22.12 ops/sec ±5.20% (40 runs sample
4040
+---------------------+-------------------+----------------------+
4141
```
4242

43-
## Support matrix
44-
45-
| | node12 | node14 | node16 | node18 |
46-
| ---------------- | ------ | ------ | ------ | ------ |
47-
| Windows x64 |||||
48-
| Windows x32 |||||
49-
| Windows arm64 |||||
50-
| macOS x64 |||||
51-
| macOS arm64 |||||
52-
| Linux x64 gnu |||||
53-
| Linux x64 musl |||||
54-
| Linux arm gnu |||||
55-
| Linux arm64 gnu |||||
56-
| Linux arm64 musl |||||
57-
| Android arm64 |||||
58-
| Android armv7 |||||
59-
| FreeBSD x64 |||||
60-
6143
## API
6244

6345
> The type of **input initial crc** and **output crc number** is `u32`

packages/crc32/__tests__/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import test from 'ava'
22
import { crc32 as nodeCrc32 } from 'crc'
33

4-
import { crc32c, crc32 } from '../index'
4+
import { crc32c, crc32 } from '../index.js'
55

66
const fx = Buffer.from('crc32c - test')
77

packages/crc32/__tests__/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "module"
3+
}

0 commit comments

Comments
 (0)