Skip to content

Commit

Permalink
chore: refresh the infra (#915)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn authored Oct 27, 2024
1 parent 0313600 commit ef96dda
Show file tree
Hide file tree
Showing 54 changed files with 873 additions and 1,227 deletions.
50 changes: 49 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,60 @@ jobs:
run: yarn lint

- name: TypeCheck
run: yarn typecheck
run: yarn build:ts

- name: Cargo fmt
run: cargo fmt -- --check

- name: Clippy
run: cargo clippy
bench:
name: Bench
runs-on: ${{ matrix.settings.host }}
strategy:
fail-fast: false
matrix:
settings:
- target: 'x86_64-unknown-linux-gnu'
host: ubuntu-latest
- target: 'aarch64-apple-darwin'
host: macos-latest
steps:
- uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
~/.napi-rs
target
key: bench-cargo-registry-${{ matrix.settings.target }}

- name: Install
uses: ./.github/actions/setup-rust
with:
targets: ${{ matrix.settings.target }}

- name: Setup macos
if: ${{ matrix.settings.host == 'macos-latest' }}
run: brew install python-setuptools

- name: 'Install dependencies'
run: yarn install

- name: build
run: yarn build

- name: Bench
run: yarn workspaces foreach -A -j 1 --no-private run bench

build:
strategy:
fail-fast: false
Expand Down Expand Up @@ -578,6 +625,7 @@ jobs:
runs-on: ubuntu-latest
needs:
- lint
- bench
- build-freebsd
- test-linux-x64-gnu-binding
- test-linux-x64-musl-binding
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ resolver = "2"
rand_core = { version = "0.6", features = ["getrandom"] }
serde = "1.0"
serde_json = "1.0"
xxhash-rust = { version = "0.8", features = ["xxh32", "xxh64", "xxh3"] }
xxhash-rust = { version = "0.8", features = ["xxh32", "const_xxh32", "xxh64", "const_xxh64", "xxh3", "const_xxh3"] }
[profile.release]
codegen-units = 1
lto = true
Expand Down
13 changes: 0 additions & 13 deletions ava.config.mjs

This file was deleted.

2 changes: 1 addition & 1 deletion depracted/deno-lint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"typanion": "^3.14.0"
},
"devDependencies": {
"@napi-rs/cli": "^3.0.0-alpha.63",
"@napi-rs/cli": "^3.0.0-alpha.64",
"@types/webpack": "^5.28.5"
},
"funding": {
Expand Down
26 changes: 16 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,30 @@
],
"scripts": {
"artifacts": "yarn workspaces foreach -A --no-private run artifacts",
"bench": "lerna run bench --concurrency 1 --stream --no-prefix",
"build": "yarn workspaces foreach -A --no-private -j 1 run build",
"build:ts": "tsc -b tsconfig.project.json -verbose",
"build:ts": "tsc -b tsconfig.json -verbose",
"lint": "oxlint .",
"test": "ava",
"format": "run-p format:prettier format:rs format:toml",
"format:prettier": "prettier --config ./package.json -w .",
"format:rs": "cargo fmt --all",
"format:toml": "taplo format",
"typecheck": "tsc -b tsconfig.project.json -verbose",
"postinstall": "husky install"
},
"devDependencies": {
"@napi-rs/cli": "^3.0.0-alpha.63",
"@napi-rs/cli": "^3.0.0-alpha.64",
"@napi-rs/wasm-runtime": "^0.2.5",
"@swc-node/core": "^1.13.3",
"@swc-node/register": "^1.10.9",
"@swc/core": "^1.7.26",
"@taplo/cli": "^0.7.0",
"@tybys/wasm-util": "^0.9.0",
"@types/node": "^22.7.4",
"ava": "^6.1.3",
"benchmark": "^2.1.4",
"codecov": "^3.8.3",
"cross-env": "^7.0.3",
"husky": "^9.1.6",
"lerna": "^8.1.8",
"lint-staged": "^15.2.10",
"npm-run-all2": "^7.0.0",
"oxlint": "^0.10.0",
"prettier": "^3.3.3",
"ts-node": "^10.9.2",
"tslib": "^2.7.0",
"typescript": "^5.6.2"
},
Expand All @@ -60,6 +52,20 @@
"cargo fmt --"
]
},
"ava": {
"extensions": {
"ts": "module"
},
"nodeArguments": [
"--import",
"@oxc-node/core/register"
],
"timeout": "1m",
"cache": false,
"files": [
"packages/*/__test__/**/*.spec.ts"
]
},
"prettier": {
"printWidth": 120,
"semi": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/argon2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ It has a simple design aimed at the highest memory filling rate and effective us

# Benchmarks

See [benchmark/](benchmark/argon2.js).
See [benchmark/](benchmark/argon2.ts).

## API

Expand Down
3 changes: 3 additions & 0 deletions packages/argon2/__test__/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const HASHED = await hash(PASSWORD, {
parallelism: CORES,
})

const bench = new Bench('Hash with all cores')
const bench = new Bench()

bench
.add('@node-rs/argon hash', async () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/argon2/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// prettier-ignore
/* eslint-disable */
// @ts-nocheck
/* auto-generated by NAPI-RS */

const { readFileSync } = require('fs')
const { createRequire } = require('node:module')
require = createRequire(__filename)

const { readFileSync } = require('node:fs')
let nativeBinding = null
const loadErrors = []

Expand Down
4 changes: 2 additions & 2 deletions packages/argon2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@
},
"scripts": {
"artifacts": "napi artifacts -d ../../artifacts",
"bench": "cross-env NODE_ENV=production node benchmark/argon2.js",
"bench": "cross-env NODE_ENV=production node --import @oxc-node/core/register benchmark/argon2.ts",
"build": "napi build --platform --release",
"build:debug": "napi build --platform",
"prepublishOnly": "napi prepublish",
"version": "napi version && git add npm"
},
"devDependencies": {
"@napi-rs/cli": "^3.0.0-alpha.63",
"@napi-rs/cli": "^3.0.0-alpha.64",
"argon2": "^0.41.0",
"cross-env": "^7.0.3",
"tinybench": "^2.9.0"
Expand Down
9 changes: 9 additions & 0 deletions packages/argon2/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"composite": true
},
"exclude": ["dist"],
"include": ["benchmark", "__tests__"]
}
6 changes: 3 additions & 3 deletions packages/bcrypt/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ export declare function genSalt(round: number, version?: '2a' | '2x' | '2y' | '2

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

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

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

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

export declare function verifySync(input: string | Buffer, hash: string | Buffer): boolean
export declare function verifySync(input: string | Uint8Array, hash: string | Uint8Array): boolean
5 changes: 4 additions & 1 deletion packages/bcrypt/binding.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// prettier-ignore
/* eslint-disable */
// @ts-nocheck
/* auto-generated by NAPI-RS */

const { readFileSync } = require('fs')
const { createRequire } = require('node:module')
require = createRequire(__filename)

const { readFileSync } = require('node:fs')
let nativeBinding = null
const loadErrors = []

Expand Down
4 changes: 2 additions & 2 deletions packages/bcrypt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
},
"scripts": {
"artifacts": "napi artifacts -d ../../artifacts",
"bench": "cross-env NODE_ENV=production node --import @swc-node/register/esm-register benchmark/bcrypt.ts",
"bench": "cross-env NODE_ENV=production node --import @oxc-node/core/register benchmark/bcrypt.ts",
"build": "napi build --platform --release --js binding.js --dts binding.d.ts",
"build:debug": "napi build --platform",
"prepublishOnly": "napi prepublish",
Expand All @@ -72,7 +72,7 @@
"devDependencies": {
"@cwasm/openbsd-bcrypt": "^0.1.0",
"@cwasm/openwall-bcrypt": "^0.1.0",
"@napi-rs/cli": "^3.0.0-alpha.63",
"@napi-rs/cli": "^3.0.0-alpha.64",
"@types/bcrypt": "^5.0.2",
"@types/bcryptjs": "^2.4.6",
"bcrypt": "^5.1.1",
Expand Down
31 changes: 10 additions & 21 deletions packages/bcrypt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,37 +44,35 @@ pub fn gen_salt_js(
}

#[napi]
#[inline]
pub fn hash_sync(
input: Either<String, Buffer>,
input: Either<String, &[u8]>,
cost: Option<u32>,
salt: Option<Either<String, Buffer>>,
salt: Option<Either<String, &[u8]>>,
) -> Result<String> {
let salt = if let Some(salt) = salt {
let mut s = [0u8; 16];
let buf = either_string_buffer_as_bytes(&salt);
let buf = salt.as_ref();
// make sure salt buffer length should be 16
let copy_length = cmp::min(buf.len(), s.len());
s[..copy_length].copy_from_slice(&buf[..copy_length]);
s
} else {
gen_salt()
rand::random()
};
match input {
Either::A(s) => HashTask::hash(s.as_bytes(), salt, cost.unwrap_or(DEFAULT_COST)),
Either::B(b) => HashTask::hash(b.as_ref(), salt, cost.unwrap_or(DEFAULT_COST)),
}
HashTask::hash(input.as_ref(), salt, cost.unwrap_or(DEFAULT_COST))
}

#[napi]
pub fn hash(
input: Either<Uint8Array, String>,
cost: Option<u32>,
salt: Option<Either<String, Buffer>>,
salt: Option<Either<String, &[u8]>>,
signal: Option<AbortSignal>,
) -> Result<AsyncTask<HashTask>> {
let salt = if let Some(salt) = salt {
let mut s = [0u8; 16];
let buf = either_string_buffer_as_bytes(&salt);
let buf = salt.as_ref();
// make sure salt buffer length should be 16
let copy_length = cmp::min(buf.len(), s.len());
s[..copy_length].copy_from_slice(&buf[..copy_length]);
Expand All @@ -87,20 +85,11 @@ pub fn hash(
}

#[napi]
pub fn verify_sync(input: Either<String, Buffer>, hash: Either<String, Buffer>) -> Result<bool> {
let input = either_string_buffer_as_bytes(&input);
let hash = either_string_buffer_as_bytes(&hash);
#[inline]
pub fn verify_sync(input: Either<String, &[u8]>, hash: Either<String, &[u8]>) -> Result<bool> {
VerifyTask::verify(input, hash)
}

#[inline(always)]
fn either_string_buffer_as_bytes(input: &Either<String, Buffer>) -> &[u8] {
match input {
Either::A(s) => s.as_bytes(),
Either::B(b) => b.as_ref(),
}
}

#[napi]
pub fn verify(
password: Either<Uint8Array, String>,
Expand Down
3 changes: 2 additions & 1 deletion packages/bcrypt/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist"
"outDir": "dist",
"composite": true
},
"exclude": ["dist"],
"include": ["__tests__"]
Expand Down
18 changes: 0 additions & 18 deletions packages/crc32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,6 @@ js_crc32 for inputs 16931844B, avg 2066B x 22.12 ops/sec ±5.20% (40 runs sample
+---------------------+-------------------+----------------------+
```

## Support matrix

| | node12 | node14 | node16 | node18 |
| ---------------- | ------ | ------ | ------ | ------ |
| Windows x64 |||||
| Windows x32 |||||
| Windows arm64 |||||
| macOS x64 |||||
| macOS arm64 |||||
| Linux x64 gnu |||||
| Linux x64 musl |||||
| Linux arm gnu |||||
| Linux arm64 gnu |||||
| Linux arm64 musl |||||
| Android arm64 |||||
| Android armv7 |||||
| FreeBSD x64 |||||

## API

> The type of **input initial crc** and **output crc number** is `u32`
Expand Down
2 changes: 1 addition & 1 deletion packages/crc32/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from 'ava'
import { crc32 as nodeCrc32 } from 'crc'

import { crc32c, crc32 } from '../index'
import { crc32c, crc32 } from '../index.js'

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

Expand Down
3 changes: 3 additions & 0 deletions packages/crc32/__tests__/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
Loading

0 comments on commit ef96dda

Please sign in to comment.