feat: WebAssembly build and browser entry - #4
Merged
Merged
Conversation
Ship the generator as a wasm32-wasip1-threads build published as
@avsystem/openapi-ng-wasm32-wasi, and make browser.js a working entry
backed by it.
- The native export returns a { result, error } outcome instead of
throwing, so typed GenerateErrors are identical on native and WASI;
the JS wrappers construct the error.
- wasm32-wasip1-threads joins the napi targets; emnapi pinned via the
workspace overrides; CI builds it, runs the suite forced to WASI plus
a native run with a WASI cross-check, and gates publish on it.
- browser.js re-exports lib/browser.js (inputContents only, lazy import
of the wasm package, E_UNSUPPORTED_RUNTIME on load failure); a typed
./browser subpath exposes createGenerate.
- Under the Node WASI fallback, relative paths and the banner resolve
against the host cwd via PWD.
- napi, napi-derive and napi-build are pinned to the last releases that
link against the emnapi 1.x archive: napi-build 2.4 exports the
emnapi v2 entry points, and rustc 1.98's linker rejects the missing
symbols instead of ignoring them.
- Runtime and Node API docs describe the browser path.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011t8uBVY6h4kfN5cXHXuCpR
pkurcx
force-pushed
the
feat/wasi-build
branch
from
September 3, 2026 16:13
8b9883d to
66f241d
Compare
pkurcx
added a commit
that referenced
this pull request
Sep 4, 2026
Adds an interactive playground to the docs site at /playground/: paste or open an OpenAPI spec, edit the generator config as JSONC, and see the generated files in the browser. It runs the wasm32-wasi build shipped in #4, so the site needs no backend. - Three CodeMirror panes (spec, config, output) with a file tree, an "Open file…" button and drag-and-drop, and a console footer with diagnostics coloured by severity. - JSONC config with a template listing mappedTypes, responseTypeMapping and naming at their defaults; enabling all of them leaves the output unchanged, which an e2e test checks. - Editors painted from Starlight's Night Owl palette; highlight.js is gone. - A Docs / Playground switch in the header replaces the sidebar entry. - website joins the root pnpm workspace; the docs workflow type-checks and runs the unit and Playwright suites. - ava is scoped to __test__/**/*.spec.ts so it skips the website's tests. - The StackBlitz demo app is tracked in stackblitz/ and linked from the README next to the playground. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011t8uBVY6h4kfN5cXHXuCpR
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ships the generator as a
wasm32-wasip1-threadsbuild published as@avsystem/openapi-ng-wasm32-wasi, and turnsbrowser.jsinto a working browser entry backed by it. Groundwork for a paste-a-spec playground on the docs site (follow-up PR).Changes
generateNativereturns{ result, error }instead of throwing. The JS wrappers constructGenerateError, so codes, subcodes, paths and warnings are identical on native and WASI (under emnapi the thrown-Error decoration was lost).build.rsno longer propagates the error marker.napi.targets;emnapi/@emnapi/*1.11.3 pinned through the workspaceoverrides(next to the existing tar/glob pins); build outputs gitignored; the unsupported-platform message innative.jsmentions the wasm fallback.browser.jsre-exportslib/browser.js:inputContentsonly (inputPath/outputPath→E_INVALID_OPTION), lazyimport()of the wasm package,E_UNSUPPORTED_RUNTIMEwhen it cannot load. New typed./browsersubpath exportingcreateGeneratefor hosts that serve the wasm files themselves.inputPath/outputPathand the banner now resolve throughPWD(src/io/host_cwd.rs); native behaviour unchanged bycfg.test-wasm-bindingjob runs the full ava suite withNAPI_RS_FORCE_WASI=trueand a native run with a fail-if-skipped WASI-vs-native cross-check;publishdepends on it.napi3.11.0,napi-derive3.5.10 andnapi-build2.3.2 are the last releases that link against the emnapi 1.x archive. napi-build 2.4 exports the emnapi v2 entry points (emnapi_create_env), which emnapi 1.11 does not define; rustc 1.98's linker rejects the missing export where 1.95 ignored it. Lifting the pin means moving the JS runtime to emnapi 2 once it is stable.Testing
cargo test --all-targets: 304 passed.cargo clippy,oxlintclean.pnpm testnative: 333 passed.NAPI_RS_FORCE_WASI=true NODE_OPTIONS=--no-warnings pnpm test: 333 passed against the WASI binding (verified viarequire.cache).OPENAPI_NG_EXPECT_WASI_BINDING=1 pnpm test: cross-check tests run against both bindings and produce identical artifacts.Notes
NAPI_RS_FORCE_WASI=errormust not be used in this repo: it also forces@oxc-node/core(ava's TS loader) onto a WASI build it does not ship.E_UNEXPECTEDwith a different message; the panic-message assertion is native-only.PWDis absent on Windows, so a Windows WASI fallback still needs absolute paths.GenerateError's declared constructor requires a full payload while the runtime accepts a partial one.Release
Intended to ship as v0.5.0 after this merges; the playground PR depends on the wasm package being on npm.
🤖 Generated with Claude Code