-
-
Notifications
You must be signed in to change notification settings - Fork 484
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: setup wasm parser for npm (#2221)
- Loading branch information
Showing
16 changed files
with
492 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
name: Release WASM | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- wasm/parser/package.json # Please only commit this file, so we don't need to wait for all the other CI jobs to finish. | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
check: | ||
name: Check version | ||
runs-on: ubuntu-latest | ||
outputs: | ||
version: ${{ steps.version.outputs.version }} | ||
version_changed: ${{ steps.version.outputs.changed }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Check version changes | ||
uses: EndBug/version-check@v2 | ||
id: version | ||
with: | ||
static-checking: localIsNew | ||
file-url: https://unpkg.com/@oxc-parser@wasm/package.json | ||
file-name: wasm/parser/package.json | ||
|
||
- name: Set version name | ||
if: steps.version.outputs.changed == 'true' | ||
run: | | ||
echo "Version change found! New version: ${{ steps.version.outputs.version }} (${{ steps.version.outputs.version_type }})" | ||
build: | ||
needs: check | ||
if: needs.check.outputs.version_changed == 'true' | ||
name: Release WASM | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write # for `npm publish --provenance` | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Install Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: Install Rust Toolchain | ||
uses: ./.github/actions/rustup | ||
with: | ||
shared-key: 'wasm' | ||
|
||
- name: Build | ||
working-directory: wasm/parser | ||
run: | | ||
rustup target add wasm32-unknown-unknown | ||
corepack enable | ||
pnpm install | ||
pnpm run build | ||
- name: Publish | ||
working-directory: npm/parser-wasm | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: npm publish --tag latest --provenance --access public |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
[workspace] | ||
resolver = "2" | ||
members = ["crates/*", "tasks/*", "napi/*"] | ||
members = ["crates/*", "tasks/*", "napi/*", "wasm/*"] | ||
exclude = ["tasks/lint_rules"] | ||
|
||
[workspace.package] | ||
authors = ["Boshen <[email protected]>", "Oxc contributors"] | ||
categories = ["development-tools", "web-programming", "compilers"] | ||
description = "Oxc is a JavaScript / TypeScript tooling suite." | ||
description = "A collection of JavaScript tools written in Rust." | ||
edition = "2021" | ||
homepage = "https://oxc-project.github.io" | ||
keywords = ["JavaScript", "TypeScript", "parser", "linter", "minifier"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
bin/ | ||
pkg/ | ||
node_modules/ | ||
wasm-pack.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[package] | ||
name = "oxc_parser_wasm" | ||
version = "0.0.1" | ||
publish = false | ||
authors.workspace = true | ||
description.workspace = true | ||
edition.workspace = true | ||
homepage.workspace = true | ||
keywords.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
rust-version.workspace = true | ||
categories.workspace = true | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
test = false | ||
doctest = false | ||
|
||
[features] | ||
default = ["console_error_panic_hook"] | ||
|
||
[dependencies] | ||
oxc = { workspace = true, features = ["serde", "wasm"] } | ||
serde = { workspace = true } | ||
|
||
wasm-bindgen = { workspace = true } | ||
serde-wasm-bindgen = { workspace = true } | ||
tsify = { workspace = true } | ||
|
||
# The `console_error_panic_hook` crate provides better debugging of panics by | ||
# logging them with `console.error`. This is great for development, but requires | ||
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for | ||
# code size when deploying. | ||
console_error_panic_hook = { version = "0.1.7", optional = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
## About | ||
|
||
Experimental wasm package for the oxc parser, with full TypeScript typings support. | ||
|
||
This package is built with `wasm-pack build --release --target web` for bundler (webpack / vite) consumption. | ||
Checkout [oxc-parser](https://www.npmjs.com/package/oxc-parser) for usage in node.js. | ||
|
||
Source code: https://github.com/oxc-project/oxc/tree/main/wasm/parser | ||
|
||
## 🚴 Usage | ||
|
||
```js | ||
import initWasm, { parseSync } from "@oxc-parser/wasm"; | ||
|
||
async function main() { | ||
await initWasm(); | ||
|
||
const code = "let foo"; | ||
const result = parseSync(code, { filename: "test.ts" }); | ||
console.log(result); | ||
} | ||
|
||
main(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "@oxc-parser/wasm", | ||
"version": "0.0.1", | ||
"description": "Wasm target for the oxc parser.", | ||
"keywords": [ | ||
"JavaScript", | ||
"TypeScript", | ||
"parser" | ||
], | ||
"author": "Boshen and oxc contributors", | ||
"license": "MIT", | ||
"homepage": "https://oxc-project.github.io", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/oxc-project/oxc", | ||
"directory": "wasm/parser" | ||
}, | ||
"funding": { | ||
"url": "https://github.com/sponsors/Boshen" | ||
}, | ||
"files": [ | ||
"oxc_parser_wasm.d.ts", | ||
"oxc_parser_wasm.js", | ||
"oxc_parser_wasm_bg.wasm", | ||
"oxc_parser_wasm_bg.wasm.d.ts", | ||
"README.md" | ||
], | ||
"module": "oxc_parser_wasm.js", | ||
"types": "oxc_parser_wasm.d.ts", | ||
"scripts": { | ||
"build": "wasm-pack build --release --no-pack --target web --out-dir ../../npm/parser-wasm . && cp ./package.json ../../npm/parser-wasm/package.json" | ||
}, | ||
"devDependencies": { | ||
"wasm-pack": "^0.12.1" | ||
} | ||
} |
Oops, something went wrong.