Skip to content

feat: add @microsoft/fast-build npm package with WASM CLI#7358

Merged
janechu merged 7 commits into
mainfrom
users/janechu/wrap-rust-backend-for-use-with-npm
Apr 1, 2026
Merged

feat: add @microsoft/fast-build npm package with WASM CLI#7358
janechu merged 7 commits into
mainfrom
users/janechu/wrap-rust-backend-for-use-with-npm

Conversation

@janechu
Copy link
Copy Markdown
Collaborator

@janechu janechu commented Mar 31, 2026

Summary

Wraps the microsoft-fast-build Rust crate as a WebAssembly module and exposes it as a new npm package @microsoft/fast-build with a fast build CLI.

Changes

crates/microsoft-fast-build

  • Added crate-type = ["cdylib", "rlib"] to Cargo.toml to support WASM compilation
  • Added wasm-bindgen as a conditional WASM-only dependency — native targets remain zero-dependency
  • Added src/wasm.rs exposing two #[wasm_bindgen] functions:
    • render(entry, state) — render a template with JSON state
    • render_with_templates(entry, templates_json, state) — render with custom element templates passed as a JSON map

packages/fast-build (new)

  • package.json@microsoft/fast-build, no runtime npm dependencies; includes a build script to regenerate the WASM via wasm-pack
  • bin/fast.js — CLI supporting fast build with:
    • --templates="<glob>" — glob pattern(s) for custom element HTML templates; warns if not provided or no files match
    • --output="output.html" — output file (default: output.html)
    • --entry="index.html" — entry HTML template (default: index.html)
    • --state="state.json" — state JSON file (default: state.json)
  • wasm/ — pre-built WASM module and JS bindings (generated by wasm-pack --target nodejs)

Notes

  • All file I/O and glob resolution is done in plain Node.js with no external dependencies
  • The existing Rust unit test suite continues to pass

@janechu janechu force-pushed the users/janechu/wrap-rust-backend-for-use-with-npm branch 2 times, most recently from 93ca1dd to 29e64f7 Compare March 31, 2026 23:55
janechu and others added 6 commits March 31, 2026 17:03
- Add wasm-bindgen as a conditional WASM-target dependency to the
  microsoft-fast-build Rust crate (zero-dependency for native targets)
- Add src/wasm.rs exposing render() and render_with_templates() via
  wasm-bindgen for use in Node.js
- Build the crate to WASM (NodeJS target) with wasm-pack
- Create packages/fast-build/ with:
  - package.json (@microsoft/fast-build, no runtime npm dependencies)
  - bin/fast.js: CLI supporting `fast build` with arguments:
      --templates="<glob>"  custom element HTML templates (warns if missing)
      --output="output.html" (default: output.html)
      --entry="index.html"  (default: index.html)
      --state="state.json"  (default: state.json)
  - wasm/: compiled WASM module and JS bindings

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The build/ workspace already uses @microsoft/fast-build. Rename the
new package to @microsoft/fast-html-build and regenerate package-lock.json.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…uild

Rename build/ workspace from @microsoft/fast-build to
@microsoft/fast-build-tools so the new packages/fast-build package
can use the @microsoft/fast-build name as intended.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
sites/website/scripts/generate-docs.cjs imports this utility from
@microsoft/fast-build. Move it from build/ into packages/fast-build
so the import continues to resolve now that this package owns the name.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The WASM output is pre-built and committed. Renaming the script from
'build' to 'build:wasm' prevents the workspace-wide 'npm run build'
from failing in environments without wasm-pack installed. Developers
can still regenerate the WASM explicitly with 'npm run build:wasm'.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@janechu janechu force-pushed the users/janechu/wrap-rust-backend-for-use-with-npm branch from 3031fc5 to acac11b Compare April 1, 2026 00:03
@janechu janechu merged commit 4450aef into main Apr 1, 2026
14 checks passed
@janechu janechu deleted the users/janechu/wrap-rust-backend-for-use-with-npm branch April 1, 2026 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant