mirror of
https://github.com/hanzoai/swc.git
synced 2026-10-30 19:42:53 +00:00
**Description:** Adds an independent Rust/WebAssembly binding at `bindings/binding_nodejs_support_wasm`, published as `@swc/nodejs-support-wasm`. The package has its own Rust crate, sources, build scripts, tests, README, Cargo entry, and npm workspace entry. It does not build from `binding_typescript_wasm` and does not add features or exports to the existing `@swc/wasm-typescript` or `@swc/wasm-typescript-esm` packages. The new CommonJS package embeds its wasm binary and exposes these APIs at the top level: - `transform` - `transformSync` - `transformModuleSyntax` - `getFirstExpression` - `isValidSyntax` - `isRecoverableError` It also exports the related `Options`, `TransformOutput`, and `ModuleSyntaxTransformOutput` TypeScript types. The npm publish matrix, wasm CI matrix, release versioning, Cargo lockfile, and pnpm lockfile now reference the standalone `binding_nodejs_support_wasm` crate. Validation performed: - `git submodule update --init --recursive` - `cargo fmt --all -- --check` - `cargo test -p binding_typescript_wasm -p binding_nodejs_support_wasm` - `cargo clippy --all --all-targets -- -D warnings` - `(cd bindings/binding_nodejs_support_wasm && ./scripts/test.sh)` - `(cd bindings/binding_typescript_wasm && ./scripts/test.sh)` - `(cd bindings/binding_core_wasm && ./scripts/test.sh)` - `(cd bindings/binding_minifier_wasm && ./scripts/test.sh)` - `(cd bindings/binding_es_ast_viewer && ./scripts/test.sh)` - `(cd bindings/binding_nodejs_support_wasm/pkg && npm pack --dry-run --json)` - `pnpm install --frozen-lockfile --ignore-scripts` - `go run github.com/rhysd/actionlint/cmd/actionlint@latest .github/workflows/CI.yml .github/workflows/publish-npm-package.yml` **BREAKING CHANGE:** None. The existing TypeScript wasm packages and their public APIs are unchanged. **Related issue (if exists):** - Supports nodejs/node#64034 - Follow-up context from swc-project/swc#11973
32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
import fs from "node:fs/promises";
|
|
|
|
const rawWasmPath = "pkg/wasm_bg.wasm";
|
|
const wasmJsPath = "pkg/wasm.js";
|
|
const packageJsonPath = "pkg/package.json";
|
|
const rawWasmFile = await fs.readFile(rawWasmPath);
|
|
const origJsFile = await fs.readFile(wasmJsPath, "utf8");
|
|
|
|
const base64 = rawWasmFile.toString("base64");
|
|
const patchedJsFile = origJsFile
|
|
.replace(
|
|
`const path = require('path').join(__dirname, 'wasm_bg.wasm');`,
|
|
""
|
|
)
|
|
.replace(", fatal: true", "")
|
|
.replace(
|
|
`const bytes = require('fs').readFileSync(path);`,
|
|
`
|
|
const { Buffer } = require('node:buffer');
|
|
const bytes = Buffer.from('${base64}', 'base64');`
|
|
);
|
|
|
|
await fs.writeFile(wasmJsPath, patchedJsFile);
|
|
await fs.unlink(rawWasmPath);
|
|
|
|
const pkgJsonFile = await fs.readFile(packageJsonPath, "utf8");
|
|
const pkgJson = JSON.parse(pkgJsonFile);
|
|
pkgJson.name = "@swc/nodejs-support-wasm";
|
|
pkgJson.description = "SWC WebAssembly helpers for Node.js";
|
|
pkgJson.files = pkgJson.files.filter((file) => file !== "wasm_bg.wasm");
|
|
await fs.writeFile(packageJsonPath, JSON.stringify(pkgJson, null, 2));
|