From 3c213fafca4746fd0a4866ec10f48619c2564b5e Mon Sep 17 00:00:00 2001 From: Matthew Runyon Date: Sun, 14 Jul 2024 00:37:22 -0500 Subject: [PATCH 01/16] Publish wasm API to npm --- .github/workflows/ci.yaml | 2 +- .github/workflows/publish-wasm.yml | 49 +++++++++++++++++++++++++++++ .github/workflows/release.yml | 17 +++++++++- Cargo.lock | 50 +++++++++++++++--------------- Cargo.toml | 2 +- crates/ruff_wasm/Cargo.toml | 4 +-- crates/ruff_wasm/README.md | 41 ++++++++++++++++++++++++ crates/ruff_wasm/tests/api.rs | 2 +- playground/src/Editor/Editor.tsx | 2 +- pyproject.toml | 1 + 10 files changed, 138 insertions(+), 32 deletions(-) create mode 100644 .github/workflows/publish-wasm.yml create mode 100644 crates/ruff_wasm/README.md diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b5b35ed0637bd..b7cbe23c481ce 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -111,7 +111,7 @@ jobs: - name: "Clippy" run: cargo clippy --workspace --all-targets --all-features --locked -- -D warnings - name: "Clippy (wasm)" - run: cargo clippy -p ruff_wasm --target wasm32-unknown-unknown --all-features --locked -- -D warnings + run: cargo clippy -p ruff-api --target wasm32-unknown-unknown --all-features --locked -- -D warnings cargo-test-linux: name: "cargo test (linux)" diff --git a/.github/workflows/publish-wasm.yml b/.github/workflows/publish-wasm.yml new file mode 100644 index 0000000000000..e10e9b81e8029 --- /dev/null +++ b/.github/workflows/publish-wasm.yml @@ -0,0 +1,49 @@ +# Build and publish ruff-api for wasm. +# +# Assumed to run as a subworkflow of .github/workflows/release.yml; specifically, as a publish +# job within `cargo-dist`. +name: "Build wasm" + +on: + workflow_call: + inputs: + plan: + required: true + type: string + pull_request: + paths: + - .github/workflows/build-wasm.yml + +env: + CARGO_INCREMENTAL: 0 + CARGO_NET_RETRY: 10 + CARGO_TERM_COLOR: always + RUSTUP_MAX_RETRIES: 10 + +jobs: + ruff_wasm: + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v4 + - name: "Install Rust toolchain" + run: rustup target add wasm32-unknown-unknown + - uses: jetli/wasm-pack-action@v0.4.0 + - uses: jetli/wasm-bindgen-action@v0.2.0 + - name: "Run wasm-pack build" + run: wasm-pack build --target web --scope astral-sh crates/ruff_wasm + - run: cd crates/ruff_wasm/pkg + + # Need to setup node after moving into generated pkg + # Otherwise, the .npmrc generated by the action does not get used since there is no root package.json + # The generated .npmrc reads from $NODE_AUTH_TOKEN for npm auth + - uses: actions/setup-node@v4 + with: + node-version: 18 + registry-url: "https://registry.npmjs.org" + - name: "Publish" + run: npm publish --provenance --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7132970c36a57..4791aa237a92f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -214,16 +214,31 @@ jobs: "id-token": "write" "packages": "write" + custom-publish-wasm: + needs: + - plan + - host + if: ${{ !fromJson(needs.plan.outputs.val).announcement_is_prerelease || fromJson(needs.plan.outputs.val).publish_prereleases }} + uses: ./.github/workflows/publish-wasm.yml + with: + plan: ${{ needs.plan.outputs.val }} + secrets: inherit + # publish jobs get escalated permissions + permissions: + "id-token": "write" + "packages": "write" + # Create a GitHub Release while uploading all files to it announce: needs: - plan - host - custom-publish-pypi + - custom-publish-wasm # use "always() && ..." to allow us to wait for all publish jobs while # still allowing individual publish jobs to skip themselves (for prereleases). # "host" however must run to completion, no skipping allowed! - if: ${{ always() && needs.host.result == 'success' && (needs.custom-publish-pypi.result == 'skipped' || needs.custom-publish-pypi.result == 'success') }} + if: ${{ always() && needs.host.result == 'success' && (needs.custom-publish-pypi.result == 'skipped' || needs.custom-publish-pypi.result == 'success') && (needs.custom-publish-wasm.result == 'skipped' || needs.custom-publish-wasm.result == 'success') }} runs-on: "ubuntu-20.04" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Cargo.lock b/Cargo.lock index 77ac3ebd97838..024ad0ab90193 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2051,6 +2051,31 @@ dependencies = [ "wild", ] +[[package]] +name = "ruff-api" +version = "0.5.1" +dependencies = [ + "console_error_panic_hook", + "console_log", + "js-sys", + "log", + "ruff_formatter", + "ruff_linter", + "ruff_python_ast", + "ruff_python_codegen", + "ruff_python_formatter", + "ruff_python_index", + "ruff_python_parser", + "ruff_python_trivia", + "ruff_source_file", + "ruff_text_size", + "ruff_workspace", + "serde", + "serde-wasm-bindgen", + "wasm-bindgen", + "wasm-bindgen-test", +] + [[package]] name = "ruff_benchmark" version = "0.0.0" @@ -2496,31 +2521,6 @@ dependencies = [ "static_assertions", ] -[[package]] -name = "ruff_wasm" -version = "0.0.0" -dependencies = [ - "console_error_panic_hook", - "console_log", - "js-sys", - "log", - "ruff_formatter", - "ruff_linter", - "ruff_python_ast", - "ruff_python_codegen", - "ruff_python_formatter", - "ruff_python_index", - "ruff_python_parser", - "ruff_python_trivia", - "ruff_source_file", - "ruff_text_size", - "ruff_workspace", - "serde", - "serde-wasm-bindgen", - "wasm-bindgen", - "wasm-bindgen-test", -] - [[package]] name = "ruff_workspace" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index 0cb4f2e88ea17..761b3c5f3d39c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -272,7 +272,7 @@ build-local-artifacts = false # Local artifacts jobs to run in CI local-artifacts-jobs = ["./build-binaries", "./build-docker"] # Publish jobs to run in CI -publish-jobs = ["./publish-pypi"] +publish-jobs = ["./publish-pypi", "./publish-wasm"] # Announcement jobs to run in CI post-announce-jobs = ["./notify-dependents", "./publish-docs", "./publish-playground"] # Custom permissions for GitHub Jobs diff --git a/crates/ruff_wasm/Cargo.toml b/crates/ruff_wasm/Cargo.toml index 3761f63e1e67f..8b4d01c74226b 100644 --- a/crates/ruff_wasm/Cargo.toml +++ b/crates/ruff_wasm/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "ruff_wasm" -version = "0.0.0" +name = "ruff-api" +version = "0.5.1" publish = false authors = { workspace = true } edition = { workspace = true } diff --git a/crates/ruff_wasm/README.md b/crates/ruff_wasm/README.md new file mode 100644 index 0000000000000..1af190b16e1e1 --- /dev/null +++ b/crates/ruff_wasm/README.md @@ -0,0 +1,41 @@ +# Ruff API + +[**Docs**](https://docs.astral.sh/ruff/) | [**Playground**](https://play.ruff.rs/) + +An extremely fast Python linter and code formatter, written in Rust. + +This is a WASM version of the Ruff API which can be used to lint/format Python in a browser environment. + +## Usage + +```ts +import init, { Workspace, type Diagnostic } from '@astral-sh/ruff-api'; + +const exampleDocument = `print('hello'); print("world")` + +await init(); // Initializes WASM module + +// These are default settings just to illustrate configuring Ruff +// Settings info: https://docs.astral.sh/ruff/settings +const workspace = new Workspace({ + 'line-length': 88, + 'indent-width': 4, + format: { + 'indent-style': 'space', + 'quote-style': 'double', + }, + lint: { + select: [ + 'E4', + 'E7', + 'E9', + 'F' + ], + }, +}); + +// Will contain 1 diagnostic code for E702: Multiple statements on one line +const diagnostics: Diagnostic[] = workspace.check(exampleDocument); + +const formatted = workspace.format(exampleDocument); +``` \ No newline at end of file diff --git a/crates/ruff_wasm/tests/api.rs b/crates/ruff_wasm/tests/api.rs index 50811299fc307..da8ff83c0c869 100644 --- a/crates/ruff_wasm/tests/api.rs +++ b/crates/ruff_wasm/tests/api.rs @@ -4,7 +4,7 @@ use wasm_bindgen_test::wasm_bindgen_test; use ruff_linter::registry::Rule; use ruff_source_file::{OneIndexed, SourceLocation}; -use ruff_wasm::{ExpandedMessage, Workspace}; +use ruff_api::{ExpandedMessage, Workspace}; macro_rules! check { ($source:expr, $config:expr, $expected:expr) => {{ diff --git a/playground/src/Editor/Editor.tsx b/playground/src/Editor/Editor.tsx index 5bfc5bc1cf28c..dfabe5b1a616e 100644 --- a/playground/src/Editor/Editor.tsx +++ b/playground/src/Editor/Editor.tsx @@ -7,7 +7,7 @@ import { } from "react"; import { Panel, PanelGroup } from "react-resizable-panels"; import { DEFAULT_PYTHON_SOURCE } from "../constants"; -import init, { Diagnostic, Workspace } from "../pkg/ruff_wasm"; +import init, { Diagnostic, Workspace } from "../pkg/ruff_api"; import { ErrorMessage } from "./ErrorMessage"; import Header from "./Header"; import PrimarySideBar from "./PrimarySideBar"; diff --git a/pyproject.toml b/pyproject.toml index 326eb0121a260..fc4f073b38bd5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -108,5 +108,6 @@ version_files = [ "docs/integrations.md", "crates/ruff/Cargo.toml", "crates/ruff_linter/Cargo.toml", + "crates/ruff_wasm/Cargo.toml", "scripts/benchmarks/pyproject.toml", ] From 4074b52eab37c3e42c006a1d914d739e49d87dcc Mon Sep 17 00:00:00 2001 From: Matthew Runyon Date: Sun, 14 Jul 2024 00:50:25 -0500 Subject: [PATCH 02/16] Update action name --- .github/workflows/publish-wasm.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-wasm.yml b/.github/workflows/publish-wasm.yml index e10e9b81e8029..f821be7c7db20 100644 --- a/.github/workflows/publish-wasm.yml +++ b/.github/workflows/publish-wasm.yml @@ -2,7 +2,7 @@ # # Assumed to run as a subworkflow of .github/workflows/release.yml; specifically, as a publish # job within `cargo-dist`. -name: "Build wasm" +name: "Build and publish wasm" on: workflow_call: From df3cd2a493392c6aba17e7474bbea5695a2a200c Mon Sep 17 00:00:00 2001 From: Matthew Runyon Date: Sun, 14 Jul 2024 00:51:47 -0500 Subject: [PATCH 03/16] Remove unnecessary action check --- .github/workflows/publish-wasm.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/publish-wasm.yml b/.github/workflows/publish-wasm.yml index f821be7c7db20..c93b1c4fb8138 100644 --- a/.github/workflows/publish-wasm.yml +++ b/.github/workflows/publish-wasm.yml @@ -10,9 +10,6 @@ on: plan: required: true type: string - pull_request: - paths: - - .github/workflows/build-wasm.yml env: CARGO_INCREMENTAL: 0 From bc420b08316f8e98e79dbaef65bcedb7b5cf6c59 Mon Sep 17 00:00:00 2001 From: Matthew Runyon Date: Sun, 14 Jul 2024 01:48:17 -0500 Subject: [PATCH 04/16] Fix action --- .github/workflows/publish-wasm.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/publish-wasm.yml b/.github/workflows/publish-wasm.yml index c93b1c4fb8138..2165ee6667ecc 100644 --- a/.github/workflows/publish-wasm.yml +++ b/.github/workflows/publish-wasm.yml @@ -31,16 +31,11 @@ jobs: - uses: jetli/wasm-bindgen-action@v0.2.0 - name: "Run wasm-pack build" run: wasm-pack build --target web --scope astral-sh crates/ruff_wasm - - run: cd crates/ruff_wasm/pkg - - # Need to setup node after moving into generated pkg - # Otherwise, the .npmrc generated by the action does not get used since there is no root package.json - # The generated .npmrc reads from $NODE_AUTH_TOKEN for npm auth - uses: actions/setup-node@v4 with: node-version: 18 registry-url: "https://registry.npmjs.org" - name: "Publish" - run: npm publish --provenance --access public + run: npm publish --provenance --access public crates/ruff_wasm/pkg env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file From 723718147170ad8bede6c0338603b0f10dd38233 Mon Sep 17 00:00:00 2001 From: Matthew Runyon Date: Sun, 14 Jul 2024 02:04:30 -0500 Subject: [PATCH 05/16] Add license copy --- .github/workflows/publish-wasm.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/publish-wasm.yml b/.github/workflows/publish-wasm.yml index 2165ee6667ecc..21b1efe45556a 100644 --- a/.github/workflows/publish-wasm.yml +++ b/.github/workflows/publish-wasm.yml @@ -35,6 +35,7 @@ jobs: with: node-version: 18 registry-url: "https://registry.npmjs.org" + - run: cp LICENSE crates/ruff_wasm/pkg # wasm-pack does not put the LICENSE file in the pkg - name: "Publish" run: npm publish --provenance --access public crates/ruff_wasm/pkg env: From fbe914e3e2ae197c5aca704ca019813f9ea4e03d Mon Sep 17 00:00:00 2001 From: Matthew Runyon Date: Sun, 14 Jul 2024 17:27:16 -0500 Subject: [PATCH 06/16] Fix test failures --- .github/workflows/publish-wasm.yml | 2 +- crates/ruff_wasm/README.md | 2 +- crates/ruff_wasm/tests/api.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish-wasm.yml b/.github/workflows/publish-wasm.yml index 21b1efe45556a..4bf81d13808e1 100644 --- a/.github/workflows/publish-wasm.yml +++ b/.github/workflows/publish-wasm.yml @@ -39,4 +39,4 @@ jobs: - name: "Publish" run: npm publish --provenance --access public crates/ruff_wasm/pkg env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/crates/ruff_wasm/README.md b/crates/ruff_wasm/README.md index 1af190b16e1e1..ca80cc45a19ec 100644 --- a/crates/ruff_wasm/README.md +++ b/crates/ruff_wasm/README.md @@ -38,4 +38,4 @@ const workspace = new Workspace({ const diagnostics: Diagnostic[] = workspace.check(exampleDocument); const formatted = workspace.format(exampleDocument); -``` \ No newline at end of file +``` diff --git a/crates/ruff_wasm/tests/api.rs b/crates/ruff_wasm/tests/api.rs index da8ff83c0c869..ffd853b9a21f6 100644 --- a/crates/ruff_wasm/tests/api.rs +++ b/crates/ruff_wasm/tests/api.rs @@ -2,9 +2,9 @@ use wasm_bindgen_test::wasm_bindgen_test; +use ruff_api::{ExpandedMessage, Workspace}; use ruff_linter::registry::Rule; use ruff_source_file::{OneIndexed, SourceLocation}; -use ruff_api::{ExpandedMessage, Workspace}; macro_rules! check { ($source:expr, $config:expr, $expected:expr) => {{ From a37949584ce3a11cd0c650e52e8c5846725b668b Mon Sep 17 00:00:00 2001 From: Matthew Runyon Date: Mon, 15 Jul 2024 02:22:38 -0500 Subject: [PATCH 07/16] Address review comments --- .github/workflows/ci.yaml | 2 +- .github/workflows/publish-wasm.yml | 4 ++++ crates/ruff_wasm/Cargo.toml | 4 ++-- crates/ruff_wasm/README.md | 3 +++ crates/ruff_wasm/tests/api.rs | 2 +- playground/src/Editor/Editor.tsx | 2 +- 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b7cbe23c481ce..b5b35ed0637bd 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -111,7 +111,7 @@ jobs: - name: "Clippy" run: cargo clippy --workspace --all-targets --all-features --locked -- -D warnings - name: "Clippy (wasm)" - run: cargo clippy -p ruff-api --target wasm32-unknown-unknown --all-features --locked -- -D warnings + run: cargo clippy -p ruff_wasm --target wasm32-unknown-unknown --all-features --locked -- -D warnings cargo-test-linux: name: "cargo test (linux)" diff --git a/.github/workflows/publish-wasm.yml b/.github/workflows/publish-wasm.yml index 4bf81d13808e1..c181f4b426ac7 100644 --- a/.github/workflows/publish-wasm.yml +++ b/.github/workflows/publish-wasm.yml @@ -35,6 +35,10 @@ jobs: with: node-version: 18 registry-url: "https://registry.npmjs.org" + - name: "Rename generated package" + run: | # Replace the package name w/ jq + jq '.name="@astral-sh/ruff-api-web"' crates/ruff_wasm/pkg/package.json > /tmp/package.json + mv /tmp/package.json crates/ruff_wasm/pkg - run: cp LICENSE crates/ruff_wasm/pkg # wasm-pack does not put the LICENSE file in the pkg - name: "Publish" run: npm publish --provenance --access public crates/ruff_wasm/pkg diff --git a/crates/ruff_wasm/Cargo.toml b/crates/ruff_wasm/Cargo.toml index 8b4d01c74226b..70abe3e7a32a2 100644 --- a/crates/ruff_wasm/Cargo.toml +++ b/crates/ruff_wasm/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "ruff-api" -version = "0.5.1" +name = "ruff_wasm" +version = "0.5.2" publish = false authors = { workspace = true } edition = { workspace = true } diff --git a/crates/ruff_wasm/README.md b/crates/ruff_wasm/README.md index ca80cc45a19ec..70397ad1b7d66 100644 --- a/crates/ruff_wasm/README.md +++ b/crates/ruff_wasm/README.md @@ -1,5 +1,8 @@ # Ruff API +> [!WARNING] +> This API is experimental and may change at any time + [**Docs**](https://docs.astral.sh/ruff/) | [**Playground**](https://play.ruff.rs/) An extremely fast Python linter and code formatter, written in Rust. diff --git a/crates/ruff_wasm/tests/api.rs b/crates/ruff_wasm/tests/api.rs index ffd853b9a21f6..50811299fc307 100644 --- a/crates/ruff_wasm/tests/api.rs +++ b/crates/ruff_wasm/tests/api.rs @@ -2,9 +2,9 @@ use wasm_bindgen_test::wasm_bindgen_test; -use ruff_api::{ExpandedMessage, Workspace}; use ruff_linter::registry::Rule; use ruff_source_file::{OneIndexed, SourceLocation}; +use ruff_wasm::{ExpandedMessage, Workspace}; macro_rules! check { ($source:expr, $config:expr, $expected:expr) => {{ diff --git a/playground/src/Editor/Editor.tsx b/playground/src/Editor/Editor.tsx index dfabe5b1a616e..5bfc5bc1cf28c 100644 --- a/playground/src/Editor/Editor.tsx +++ b/playground/src/Editor/Editor.tsx @@ -7,7 +7,7 @@ import { } from "react"; import { Panel, PanelGroup } from "react-resizable-panels"; import { DEFAULT_PYTHON_SOURCE } from "../constants"; -import init, { Diagnostic, Workspace } from "../pkg/ruff_api"; +import init, { Diagnostic, Workspace } from "../pkg/ruff_wasm"; import { ErrorMessage } from "./ErrorMessage"; import Header from "./Header"; import PrimarySideBar from "./PrimarySideBar"; From 89c615f2f42b7b29ff8f423a4142129a31f33efe Mon Sep 17 00:00:00 2001 From: Matthew Runyon Date: Mon, 15 Jul 2024 02:28:27 -0500 Subject: [PATCH 08/16] Fix cargo.lock --- Cargo.lock | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 024ad0ab90193..efffff748f4dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2051,31 +2051,6 @@ dependencies = [ "wild", ] -[[package]] -name = "ruff-api" -version = "0.5.1" -dependencies = [ - "console_error_panic_hook", - "console_log", - "js-sys", - "log", - "ruff_formatter", - "ruff_linter", - "ruff_python_ast", - "ruff_python_codegen", - "ruff_python_formatter", - "ruff_python_index", - "ruff_python_parser", - "ruff_python_trivia", - "ruff_source_file", - "ruff_text_size", - "ruff_workspace", - "serde", - "serde-wasm-bindgen", - "wasm-bindgen", - "wasm-bindgen-test", -] - [[package]] name = "ruff_benchmark" version = "0.0.0" @@ -2521,6 +2496,31 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "ruff_wasm" +version = "0.5.2" +dependencies = [ + "console_error_panic_hook", + "console_log", + "js-sys", + "log", + "ruff_formatter", + "ruff_linter", + "ruff_python_ast", + "ruff_python_codegen", + "ruff_python_formatter", + "ruff_python_index", + "ruff_python_parser", + "ruff_python_trivia", + "ruff_source_file", + "ruff_text_size", + "ruff_workspace", + "serde", + "serde-wasm-bindgen", + "wasm-bindgen", + "wasm-bindgen-test", +] + [[package]] name = "ruff_workspace" version = "0.0.0" From e7c5bf1ff5b55e9d8fc8c5d846d5e8a02df08be5 Mon Sep 17 00:00:00 2001 From: Matthew Runyon Date: Mon, 15 Jul 2024 02:44:46 -0500 Subject: [PATCH 09/16] Add other targets --- .github/workflows/publish-wasm.yml | 7 +++++-- crates/ruff_wasm/README.md | 14 +++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish-wasm.yml b/.github/workflows/publish-wasm.yml index c181f4b426ac7..cc93796271339 100644 --- a/.github/workflows/publish-wasm.yml +++ b/.github/workflows/publish-wasm.yml @@ -23,6 +23,9 @@ jobs: permissions: contents: read id-token: write + strategy: + matrix: + target: [web, node, bundler, deno] steps: - uses: actions/checkout@v4 - name: "Install Rust toolchain" @@ -30,14 +33,14 @@ jobs: - uses: jetli/wasm-pack-action@v0.4.0 - uses: jetli/wasm-bindgen-action@v0.2.0 - name: "Run wasm-pack build" - run: wasm-pack build --target web --scope astral-sh crates/ruff_wasm + run: wasm-pack build --target ${{ matrix.target }} crates/ruff_wasm - uses: actions/setup-node@v4 with: node-version: 18 registry-url: "https://registry.npmjs.org" - name: "Rename generated package" run: | # Replace the package name w/ jq - jq '.name="@astral-sh/ruff-api-web"' crates/ruff_wasm/pkg/package.json > /tmp/package.json + jq '.name="@astral-sh/ruff-wasm-${{ matrix.target }}"' crates/ruff_wasm/pkg/package.json > /tmp/package.json mv /tmp/package.json crates/ruff_wasm/pkg - run: cp LICENSE crates/ruff_wasm/pkg # wasm-pack does not put the LICENSE file in the pkg - name: "Publish" diff --git a/crates/ruff_wasm/README.md b/crates/ruff_wasm/README.md index 70397ad1b7d66..3c6fb6dd235ba 100644 --- a/crates/ruff_wasm/README.md +++ b/crates/ruff_wasm/README.md @@ -1,7 +1,6 @@ -# Ruff API +# Ruff WASM -> [!WARNING] -> This API is experimental and may change at any time +### ⚠️ WARNING: This API is experimental and may change at any time [**Docs**](https://docs.astral.sh/ruff/) | [**Playground**](https://play.ruff.rs/) @@ -9,8 +8,17 @@ An extremely fast Python linter and code formatter, written in Rust. This is a WASM version of the Ruff API which can be used to lint/format Python in a browser environment. +There are multiple versions for the different wasm-pack targets. See [here](https://rustwasm.github.io/docs/wasm-bindgen/reference/deployment.html) for more info on targets. + +- [Bundler](https://www.npmjs.com/package/@astral-sh/ruff-wasm-bundler) +- [Web](https://www.npmjs.com/package/@astral-sh/ruff-wasm-web) +- [Node.js](https://www.npmjs.com/package/@astral-sh/ruff-wasm-nodejs) +- [Deno](https://www.npmjs.com/package/@astral-sh/ruff-wasm-deno) + ## Usage +This example uses the wasm-pack web target and is known to work with Vite. + ```ts import init, { Workspace, type Diagnostic } from '@astral-sh/ruff-api'; From 3ade79bd4ddb9b3c649b5c0545aebfaac7f7760f Mon Sep 17 00:00:00 2001 From: Matthew Runyon Date: Mon, 15 Jul 2024 02:46:57 -0500 Subject: [PATCH 10/16] Fix nodejs target --- .github/workflows/publish-wasm.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-wasm.yml b/.github/workflows/publish-wasm.yml index cc93796271339..40583970ad1dc 100644 --- a/.github/workflows/publish-wasm.yml +++ b/.github/workflows/publish-wasm.yml @@ -25,7 +25,7 @@ jobs: id-token: write strategy: matrix: - target: [web, node, bundler, deno] + target: [web, bundler, nodejs, deno] steps: - uses: actions/checkout@v4 - name: "Install Rust toolchain" From 8e425ab8a63beaf8c69465e0e5ee154abcd16db1 Mon Sep 17 00:00:00 2001 From: Matthew Runyon Date: Mon, 15 Jul 2024 02:55:07 -0500 Subject: [PATCH 11/16] Remove deno target --- .github/workflows/publish-wasm.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-wasm.yml b/.github/workflows/publish-wasm.yml index 40583970ad1dc..f68be3d801efb 100644 --- a/.github/workflows/publish-wasm.yml +++ b/.github/workflows/publish-wasm.yml @@ -25,7 +25,7 @@ jobs: id-token: write strategy: matrix: - target: [web, bundler, nodejs, deno] + target: [web, bundler, nodejs] steps: - uses: actions/checkout@v4 - name: "Install Rust toolchain" From 9f24ad56bf5a02be20314683a381c641f81d2143 Mon Sep 17 00:00:00 2001 From: Matthew Runyon Date: Mon, 15 Jul 2024 02:56:43 -0500 Subject: [PATCH 12/16] Remove deno from readme --- crates/ruff_wasm/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/ruff_wasm/README.md b/crates/ruff_wasm/README.md index 3c6fb6dd235ba..7f81e92cfc946 100644 --- a/crates/ruff_wasm/README.md +++ b/crates/ruff_wasm/README.md @@ -13,7 +13,6 @@ There are multiple versions for the different wasm-pack targets. See [here](http - [Bundler](https://www.npmjs.com/package/@astral-sh/ruff-wasm-bundler) - [Web](https://www.npmjs.com/package/@astral-sh/ruff-wasm-web) - [Node.js](https://www.npmjs.com/package/@astral-sh/ruff-wasm-nodejs) -- [Deno](https://www.npmjs.com/package/@astral-sh/ruff-wasm-deno) ## Usage From 733d6357d51cb1626b3c89a4e3d2772585720826 Mon Sep 17 00:00:00 2001 From: Matthew Runyon Date: Mon, 15 Jul 2024 03:09:51 -0500 Subject: [PATCH 13/16] Change warning to blockquote --- crates/ruff_wasm/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ruff_wasm/README.md b/crates/ruff_wasm/README.md index 7f81e92cfc946..59f5b486b194e 100644 --- a/crates/ruff_wasm/README.md +++ b/crates/ruff_wasm/README.md @@ -1,6 +1,6 @@ # Ruff WASM -### ⚠️ WARNING: This API is experimental and may change at any time +> **⚠️ WARNING: This API is experimental and may change at any time** [**Docs**](https://docs.astral.sh/ruff/) | [**Playground**](https://play.ruff.rs/) From 4558d0d0ed5e88930db3c938beb4c5155cb5bcbc Mon Sep 17 00:00:00 2001 From: Matthew Runyon Date: Tue, 16 Jul 2024 14:54:12 -0500 Subject: [PATCH 14/16] Add dry-run to action --- .github/workflows/publish-wasm.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish-wasm.yml b/.github/workflows/publish-wasm.yml index f68be3d801efb..c6326b100290a 100644 --- a/.github/workflows/publish-wasm.yml +++ b/.github/workflows/publish-wasm.yml @@ -5,6 +5,7 @@ name: "Build and publish wasm" on: + workflow_dispatch: workflow_call: inputs: plan: @@ -34,16 +35,21 @@ jobs: - uses: jetli/wasm-bindgen-action@v0.2.0 - name: "Run wasm-pack build" run: wasm-pack build --target ${{ matrix.target }} crates/ruff_wasm - - uses: actions/setup-node@v4 - with: - node-version: 18 - registry-url: "https://registry.npmjs.org" - name: "Rename generated package" run: | # Replace the package name w/ jq jq '.name="@astral-sh/ruff-wasm-${{ matrix.target }}"' crates/ruff_wasm/pkg/package.json > /tmp/package.json mv /tmp/package.json crates/ruff_wasm/pkg - run: cp LICENSE crates/ruff_wasm/pkg # wasm-pack does not put the LICENSE file in the pkg + + - uses: actions/setup-node@v4 + with: + node-version: 18 + registry-url: "https://registry.npmjs.org" + - name: "Publish (dry-run)" + if: ${{ inputs.plan == '' || fromJson(inputs.plan).announcement_tag_is_implicit }} + run: npm publish --dry-run crates/ruff_wasm/pkg - name: "Publish" + if: ! ${{ inputs.plan == '' || fromJson(inputs.plan).announcement_tag_is_implicit }} run: npm publish --provenance --access public crates/ruff_wasm/pkg env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} From 6338eb2ae76a49c48fb2297144259421a0739c4a Mon Sep 17 00:00:00 2001 From: Matthew Runyon Date: Tue, 16 Jul 2024 15:01:53 -0500 Subject: [PATCH 15/16] Disable fail-fast matrix behavior --- .github/workflows/publish-wasm.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-wasm.yml b/.github/workflows/publish-wasm.yml index c6326b100290a..0969fc29d1ec6 100644 --- a/.github/workflows/publish-wasm.yml +++ b/.github/workflows/publish-wasm.yml @@ -27,6 +27,7 @@ jobs: strategy: matrix: target: [web, bundler, nodejs] + fail-fast: false steps: - uses: actions/checkout@v4 - name: "Install Rust toolchain" @@ -40,7 +41,6 @@ jobs: jq '.name="@astral-sh/ruff-wasm-${{ matrix.target }}"' crates/ruff_wasm/pkg/package.json > /tmp/package.json mv /tmp/package.json crates/ruff_wasm/pkg - run: cp LICENSE crates/ruff_wasm/pkg # wasm-pack does not put the LICENSE file in the pkg - - uses: actions/setup-node@v4 with: node-version: 18 From 339d30c34a17e76fe4cb1a72680df98f26b72609 Mon Sep 17 00:00:00 2001 From: Matthew Runyon Date: Tue, 16 Jul 2024 15:05:16 -0500 Subject: [PATCH 16/16] Fix conditional check --- .github/workflows/publish-wasm.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-wasm.yml b/.github/workflows/publish-wasm.yml index 0969fc29d1ec6..2cab1a873c65b 100644 --- a/.github/workflows/publish-wasm.yml +++ b/.github/workflows/publish-wasm.yml @@ -49,7 +49,7 @@ jobs: if: ${{ inputs.plan == '' || fromJson(inputs.plan).announcement_tag_is_implicit }} run: npm publish --dry-run crates/ruff_wasm/pkg - name: "Publish" - if: ! ${{ inputs.plan == '' || fromJson(inputs.plan).announcement_tag_is_implicit }} + if: ${{ inputs.plan != '' && !fromJson(inputs.plan).announcement_tag_is_implicit }} run: npm publish --provenance --access public crates/ruff_wasm/pkg env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}