diff --git a/.github/actions/setup-rust/action.yaml b/.github/actions/setup-rust/action.yaml new file mode 100644 index 00000000..aae32903 --- /dev/null +++ b/.github/actions/setup-rust/action.yaml @@ -0,0 +1,25 @@ +name: 'Setup Rust' +description: 'Set up the Rust toolchain' +inputs: + targets: + description: 'The target to install' + required: true + components: + description: 'The components to install' + required: false +runs: + using: 'composite' + steps: + - name: Print rustup toolchain version + shell: bash + id: rustup-version + run: | + export RUST_TOOLCHAIN_VERSION="$(grep 'channel' rust-toolchain.toml | head -1 | awk -F '"' '{print $2}')" + echo "Rust toolchain version: $RUST_TOOLCHAIN_VERSION" + echo "RUST_TOOLCHAIN_VERSION=$RUST_TOOLCHAIN_VERSION" >> "$GITHUB_OUTPUT" + - name: Install + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ inputs.targets }} + toolchain: ${{ steps.rustup-version.outputs.RUST_TOOLCHAIN_VERSION }} + components: ${{ inputs.components }} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6ac43d04..ca78f386 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,6 +18,37 @@ on: pull_request: jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Install + uses: ./.github/actions/setup-rust + with: + targets: x86_64-unknown-linux-gnu + components: rustfmt, clippy + + - name: 'Install dependencies' + run: yarn install --mode=skip-build + + - name: ESLint + run: yarn lint + + - name: TypeCheck + run: yarn typecheck + + - name: Cargo fmt + run: cargo fmt -- --check + + - name: Clippy + run: cargo clippy build: strategy: fail-fast: false @@ -87,9 +118,8 @@ jobs: cache: yarn - name: Install - uses: dtolnay/rust-toolchain@stable + uses: ./.github/actions/setup-rust with: - toolchain: nightly-2023-12-23 targets: ${{ matrix.settings.target }} - name: Cache cargo registry @@ -175,7 +205,8 @@ jobs: sudo pkg install -y -f curl node libnghttp2 npm sudo npm install -g yarn --ignore-scripts curl https://sh.rustup.rs -sSf --output rustup.sh - sh rustup.sh -y --default-toolchain nightly-2023-12-23 + export RUST_TOOLCHAIN_VERSION="$(grep 'channel' rust-toolchain.toml | head -1 | awk -F '"' '{print $2}')" + sh rustup.sh -y --default-toolchain "${RUST_TOOLCHAIN_VERSION}" source "$HOME/.cargo/env" echo "~~~~ rustc --version ~~~~" rustc --version @@ -570,6 +601,7 @@ jobs: name: Publish runs-on: ubuntu-latest needs: + - lint - build-freebsd - test-linux-x64-gnu-binding - test-linux-x64-centos-7 diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml deleted file mode 100644 index 592f1252..00000000 --- a/.github/workflows/lint.yaml +++ /dev/null @@ -1,42 +0,0 @@ -name: Lint - -on: - push: - branches: - - main - tags-ignore: - - '**' - pull_request: - -jobs: - lint: - name: Lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Setup node - uses: actions/setup-node@v4 - with: - node-version: 18 - - - name: Install - uses: dtolnay/rust-toolchain@stable - with: - toolchain: nightly-2023-12-23 - components: rustfmt, clippy - - - name: 'Install dependencies' - run: yarn install --mode=skip-build - - - name: ESLint - run: yarn lint - - - name: TypeCheck - run: yarn typecheck - - - name: Cargo fmt - run: cargo fmt -- --check - - - name: Clippy - run: cargo clippy diff --git a/packages/argon2/build.rs b/packages/argon2/build.rs index 1f866b6a..bbfc9e4b 100644 --- a/packages/argon2/build.rs +++ b/packages/argon2/build.rs @@ -1,5 +1,3 @@ -extern crate napi_build; - fn main() { napi_build::setup(); } diff --git a/packages/bcrypt/binding.d.ts b/packages/bcrypt/binding.d.ts index bf9b22cd..78da03fe 100644 --- a/packages/bcrypt/binding.d.ts +++ b/packages/bcrypt/binding.d.ts @@ -7,23 +7,11 @@ export function genSalt(round: number, version?: '2a' | '2x' | '2y' | '2b', sign export function genSaltSync(round: number, version?: '2a' | '2x' | '2y' | '2b'): string -export function hash( - input: string | Buffer, - cost?: number | undefined | null, - salt?: Buffer | undefined | null, - signal?: AbortSignal | undefined | null, -): Promise - -export function hashSync( - input: string | Buffer, - cost?: number | undefined | null, - salt?: Buffer | undefined | null, -): string - -export function verify( - password: string | Buffer, - hash: string | Buffer, - signal?: AbortSignal | undefined | null, -): Promise +export function hash(input: string | Buffer, cost?: number | undefined | null, salt?: Buffer | undefined | null, signal?: AbortSignal | undefined | null): Promise + +export function hashSync(input: string | Buffer, cost?: number | undefined | null, salt?: Buffer | undefined | null): string + +export function verify(password: string | Buffer, hash: string | Buffer, signal?: AbortSignal | undefined | null): Promise export function verifySync(input: string | Buffer, hash: string | Buffer): boolean + diff --git a/packages/bcrypt/binding.js b/packages/bcrypt/binding.js index e857088e..ebcf4d4a 100644 --- a/packages/bcrypt/binding.js +++ b/packages/bcrypt/binding.js @@ -94,7 +94,9 @@ switch (platform) { case 'win32': switch (arch) { case 'x64': - localFileExisted = existsSync(join(__dirname, 'bcrypt.win32-x64-msvc.node')) + localFileExisted = existsSync( + join(__dirname, 'bcrypt.win32-x64-msvc.node') + ) try { if (localFileExisted) { nativeBinding = require('./bcrypt.win32-x64-msvc.node') @@ -106,7 +108,9 @@ switch (platform) { } break case 'ia32': - localFileExisted = existsSync(join(__dirname, 'bcrypt.win32-ia32-msvc.node')) + localFileExisted = existsSync( + join(__dirname, 'bcrypt.win32-ia32-msvc.node') + ) try { if (localFileExisted) { nativeBinding = require('./bcrypt.win32-ia32-msvc.node') @@ -118,7 +122,9 @@ switch (platform) { } break case 'arm64': - localFileExisted = existsSync(join(__dirname, 'bcrypt.win32-arm64-msvc.node')) + localFileExisted = existsSync( + join(__dirname, 'bcrypt.win32-arm64-msvc.node') + ) try { if (localFileExisted) { nativeBinding = require('./bcrypt.win32-arm64-msvc.node') @@ -157,7 +163,9 @@ switch (platform) { } break case 'arm64': - localFileExisted = existsSync(join(__dirname, 'bcrypt.darwin-arm64.node')) + localFileExisted = existsSync( + join(__dirname, 'bcrypt.darwin-arm64.node') + ) try { if (localFileExisted) { nativeBinding = require('./bcrypt.darwin-arm64.node') @@ -191,7 +199,9 @@ switch (platform) { switch (arch) { case 'x64': if (isMusl()) { - localFileExisted = existsSync(join(__dirname, 'bcrypt.linux-x64-musl.node')) + localFileExisted = existsSync( + join(__dirname, 'bcrypt.linux-x64-musl.node') + ) try { if (localFileExisted) { nativeBinding = require('./bcrypt.linux-x64-musl.node') @@ -202,7 +212,9 @@ switch (platform) { loadError = e } } else { - localFileExisted = existsSync(join(__dirname, 'bcrypt.linux-x64-gnu.node')) + localFileExisted = existsSync( + join(__dirname, 'bcrypt.linux-x64-gnu.node') + ) try { if (localFileExisted) { nativeBinding = require('./bcrypt.linux-x64-gnu.node') @@ -216,7 +228,9 @@ switch (platform) { break case 'arm64': if (isMusl()) { - localFileExisted = existsSync(join(__dirname, 'bcrypt.linux-arm64-musl.node')) + localFileExisted = existsSync( + join(__dirname, 'bcrypt.linux-arm64-musl.node') + ) try { if (localFileExisted) { nativeBinding = require('./bcrypt.linux-arm64-musl.node') @@ -227,7 +241,9 @@ switch (platform) { loadError = e } } else { - localFileExisted = existsSync(join(__dirname, 'bcrypt.linux-arm64-gnu.node')) + localFileExisted = existsSync( + join(__dirname, 'bcrypt.linux-arm64-gnu.node') + ) try { if (localFileExisted) { nativeBinding = require('./bcrypt.linux-arm64-gnu.node') @@ -240,7 +256,9 @@ switch (platform) { } break case 'arm': - localFileExisted = existsSync(join(__dirname, 'bcrypt.linux-arm-gnueabihf.node')) + localFileExisted = existsSync( + join(__dirname, 'bcrypt.linux-arm-gnueabihf.node') + ) try { if (localFileExisted) { nativeBinding = require('./bcrypt.linux-arm-gnueabihf.node') @@ -253,7 +271,9 @@ switch (platform) { break case 'riscv64': if (isMusl()) { - localFileExisted = existsSync(join(__dirname, 'bcrypt.linux-riscv64-musl.node')) + localFileExisted = existsSync( + join(__dirname, 'bcrypt.linux-riscv64-musl.node') + ) try { if (localFileExisted) { nativeBinding = require('./bcrypt.linux-riscv64-musl.node') @@ -264,7 +284,9 @@ switch (platform) { loadError = e } } else { - localFileExisted = existsSync(join(__dirname, 'bcrypt.linux-riscv64-gnu.node')) + localFileExisted = existsSync( + join(__dirname, 'bcrypt.linux-riscv64-gnu.node') + ) try { if (localFileExisted) { nativeBinding = require('./bcrypt.linux-riscv64-gnu.node') @@ -277,7 +299,9 @@ switch (platform) { } break case 's390x': - localFileExisted = existsSync(join(__dirname, 'bcrypt.linux-s390x-gnu.node')) + localFileExisted = existsSync( + join(__dirname, 'bcrypt.linux-s390x-gnu.node') + ) try { if (localFileExisted) { nativeBinding = require('./bcrypt.linux-s390x-gnu.node') diff --git a/packages/bcrypt/build.rs b/packages/bcrypt/build.rs index 1f866b6a..bbfc9e4b 100644 --- a/packages/bcrypt/build.rs +++ b/packages/bcrypt/build.rs @@ -1,5 +1,3 @@ -extern crate napi_build; - fn main() { napi_build::setup(); } diff --git a/packages/crc32/Cargo.toml b/packages/crc32/Cargo.toml index 1c3e649d..e69744e1 100644 --- a/packages/crc32/Cargo.toml +++ b/packages/crc32/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] crc32c = { version = "0.6" } -crc32fast = { version = "1.3", features = ["nightly"] } +crc32fast = { version = "1.4", features = ["nightly"] } global_alloc = { path = "../../crates/alloc" } napi = { version = "2", default-features = false, features = ["napi3"] } napi-derive = { version = "2" } diff --git a/packages/deno-lint/Cargo.toml b/packages/deno-lint/Cargo.toml index b99e16dc..b01ac3e0 100644 --- a/packages/deno-lint/Cargo.toml +++ b/packages/deno-lint/Cargo.toml @@ -10,17 +10,18 @@ crate-type = ["cdylib"] [dependencies] annotate-snippets = { version = "0.10" } anyhow = "1" -deno_ast = "=1.0.1" -deno_lint = "=0.55.2" +deno_ast = "=0.33.2" +deno_lint = "=0.56.0" env_logger = "0.11" global_alloc = { path = "../../crates/alloc" } globwalk = "0.9" ignore = "0.4" -miette = { version = "5", features = ["fancy-no-backtrace"] } +miette = { version = "7", features = ["fancy-no-backtrace"] } napi = { version = "2", default-features = false, features = ["napi3"] } napi-derive = { version = "2" } serde = "1" serde_json = "1" +url = "2.5" [build-dependencies] napi-build = "2" diff --git a/packages/deno-lint/build.rs b/packages/deno-lint/build.rs index 1f866b6a..bbfc9e4b 100644 --- a/packages/deno-lint/build.rs +++ b/packages/deno-lint/build.rs @@ -1,5 +1,3 @@ -extern crate napi_build; - fn main() { napi_build::setup(); } diff --git a/packages/deno-lint/src/diagnostics.rs b/packages/deno-lint/src/diagnostics.rs index 14d04acc..4e4b3a32 100644 --- a/packages/deno-lint/src/diagnostics.rs +++ b/packages/deno-lint/src/diagnostics.rs @@ -31,7 +31,6 @@ pub fn display_diagnostics( .collect() } -#[derive(Debug)] struct MietteDiagnostic<'a> { source_code: &'a MietteSourceCode<'a>, lint_diagnostic: &'a LintDiagnostic, @@ -39,6 +38,12 @@ struct MietteDiagnostic<'a> { impl std::error::Error for MietteDiagnostic<'_> {} +impl std::fmt::Debug for MietteDiagnostic<'_> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(&self.lint_diagnostic.message) + } +} + impl Display for MietteDiagnostic<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(&self.lint_diagnostic.message) @@ -62,10 +67,9 @@ impl miette::Diagnostic for MietteDiagnostic<'_> { } fn labels(&self) -> Option + '_>> { - let len = - self.lint_diagnostic.range.end.byte_index - self.lint_diagnostic.range.start.byte_index; - let start = miette::SourceOffset::from(self.lint_diagnostic.range.start.byte_index); - let len = miette::SourceOffset::from(len); + let len = self.lint_diagnostic.range.end - self.lint_diagnostic.range.start; + let start = + miette::SourceOffset::from(self.lint_diagnostic.range.start.as_byte_pos().0 as usize); let span = miette::SourceSpan::new(start, len); let text = self .lint_diagnostic @@ -114,8 +118,7 @@ impl miette::SourceCode for MietteSourceCode<'_> { let byte_range = range.as_byte_range(start_pos); let name = Some(self.filename.to_string()); let start = miette::SourceOffset::from(byte_range.start); - let len = miette::SourceOffset::from(byte_range.len()); - let span = miette::SourceSpan::new(start, len); + let span = miette::SourceSpan::new(start, byte_range.len()); Ok(Box::new(SpanContentsImpl { data: src_text, diff --git a/packages/deno-lint/src/lib.rs b/packages/deno-lint/src/lib.rs index 8b20dd2d..08b83801 100644 --- a/packages/deno-lint/src/lib.rs +++ b/packages/deno-lint/src/lib.rs @@ -40,7 +40,7 @@ fn lint( source_code: Either, all_rules: Option>, ) -> Result> { - let linter = LinterBuilder::default() + let linter: deno_lint::linter::Linter = LinterBuilder::default() .rules(match all_rules { Some(r) => match r { Either::A(a) => { @@ -73,8 +73,13 @@ fn lint( let (s, file_diagnostics) = linter .lint_file(LintFileOptions { media_type: get_media_type(Path::new(file_name.as_str())), - filename: file_name.clone(), source_code: source_string.to_owned(), + specifier: url::Url::parse(&file_name).map_err(|e| { + Error::new( + Status::GenericFailure, + format!("Parse specifier failed: {e}"), + ) + })?, }) .map_err(|e| { Error::new( @@ -181,10 +186,12 @@ fn denolint(__dirname: String, config_path: String) -> Result { let (s, file_diagnostics) = linter .lint_file(LintFileOptions { source_code: file_content, - filename: p - .to_str() - .ok_or_else(|| Error::from_reason(format!("Convert path to string failed: {:?}", &p)))? - .to_owned(), + specifier: url::Url::from_file_path(p).map_err(|_| { + Error::new( + Status::GenericFailure, + format!("Parse specifier failed: {p:?}"), + ) + })?, media_type: get_media_type(p), }) .map_err(|e| { diff --git a/packages/deno-lint/tsconfig.json b/packages/deno-lint/tsconfig.json index 4ae69857..b05522b7 100644 --- a/packages/deno-lint/tsconfig.json +++ b/packages/deno-lint/tsconfig.json @@ -7,8 +7,8 @@ "sourceMap": true, "inlineSourceMap": false, "noEmitHelpers": false, - "importHelpers": false + "importHelpers": false, }, "include": ["."], - "exclude": ["*.js", "*.d.ts"] + "exclude": ["*.js", "*.d.ts"], } diff --git a/packages/helper/tsconfig.json b/packages/helper/tsconfig.json index a8f01478..fe5eaa42 100644 --- a/packages/helper/tsconfig.json +++ b/packages/helper/tsconfig.json @@ -7,7 +7,7 @@ "sourceMap": false, "inlineSourceMap": false, "noEmitHelpers": false, - "importHelpers": false + "importHelpers": false, }, - "include": ["./src"] + "include": ["./src"], } diff --git a/packages/jieba/build.rs b/packages/jieba/build.rs index 1f866b6a..bbfc9e4b 100644 --- a/packages/jieba/build.rs +++ b/packages/jieba/build.rs @@ -1,5 +1,3 @@ -extern crate napi_build; - fn main() { napi_build::setup(); } diff --git a/packages/jsonwebtoken/build.rs b/packages/jsonwebtoken/build.rs index 1f866b6a..bbfc9e4b 100644 --- a/packages/jsonwebtoken/build.rs +++ b/packages/jsonwebtoken/build.rs @@ -1,5 +1,3 @@ -extern crate napi_build; - fn main() { napi_build::setup(); } diff --git a/packages/xxhash/build.rs b/packages/xxhash/build.rs index 1f866b6a..bbfc9e4b 100644 --- a/packages/xxhash/build.rs +++ b/packages/xxhash/build.rs @@ -1,5 +1,3 @@ -extern crate napi_build; - fn main() { napi_build::setup(); } diff --git a/rust-toolchain b/rust-toolchain deleted file mode 100644 index aeccb7e8..00000000 --- a/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -nightly-2023-12-23 diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 00000000..686495ce --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "nightly-2024-02-14" +profile = "default" diff --git a/tsconfig.json b/tsconfig.json index 60f09fbe..20cedc8d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,9 +25,9 @@ "baseUrl": "./packages", "paths": { "jsonwebtoken": ["node_modules/*"], - "@node-rs/*": ["./*/src"] + "@node-rs/*": ["./*/src"], }, - "lib": ["dom", "ES5", "ES2015", "ES2016", "ES2017", "ES2018", "ES2019", "ES2020", "esnext"] + "lib": ["dom", "ES5", "ES2015", "ES2016", "ES2017", "ES2018", "ES2019", "ES2020", "esnext"], }, - "exclude": ["node_modules"] + "exclude": ["node_modules"], }