-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Publish wasm API to npm #12317
Publish wasm API to npm #12317
Changes from all commits
3c213fa
4074b52
df3cd2a
bc420b0
7237181
fbe914e
a379495
89c615f
e7c5bf1
3ade79b
8e425ab
9f24ad5
733d635
4558d0d
6338eb2
339d30c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# 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 and publish wasm" | ||
|
||
on: | ||
workflow_dispatch: | ||
workflow_call: | ||
inputs: | ||
plan: | ||
required: true | ||
type: string | ||
|
||
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 | ||
strategy: | ||
matrix: | ||
target: [web, bundler, nodejs] | ||
fail-fast: false | ||
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 ${{ matrix.target }} crates/ruff_wasm | ||
- 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 }} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to add the Lines 105 to 112 in 7a7c601
or it won't get automatically updated when doing the next release. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Ruff WASM | ||
|
||
> **⚠️ WARNING: This API is experimental and may change at any time** | ||
|
||
[**Docs**](https://docs.astral.sh/ruff/) | [**Playground**](https://play.ruff.rs/) | ||
MichaReiser marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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) | ||
|
||
## 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'; | ||
|
||
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); | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most our workflows use
taiki-e/install-action
for fast installation of cargo dependenciesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I stole this setup from the playground workflow, so might want to update both at some point