Skip to content

Build service documentation as a reusable crate and WebAssembly module - #230

Merged
tnkuehne merged 4 commits into
mainfrom
feat/service-docs-wasm
Nov 20, 2026
Merged

tnkuehne merged 4 commits into
mainfrom
feat/service-docs-wasm

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Service documentation extraction moves from the CLI into platform-service-docs, so a server-side build can produce the same service_documentation as widefleet deploy. The library takes the file system as a parameter: the CLI passes the operating system's, and the new platform-service-docs-wasm crate passes a host file system when built for wasm32-wasip1. The module uses tsrs's WebAssembly ABI and host protocol, so tsrs's JavaScript host runs it unchanged.

An entry mode checks the original entry module instead of the bundle. The bundle mode remains the CLI's behavior; it maps bundled exports back through the source map and therefore also supports generated entry modules. Entry mode documents only declarations from the app's own sources, as the bundle mode recovers only those. For the Gmail, GitHub and OneDrive templates both modes produce byte-identical documentation, natively and in WebAssembly; the entry mode's program needs 75 MiB of linear memory instead of 113 MiB because it excludes the bundled dependencies.

The wasm Cargo profile builds the module at 10.6 MB with tsrs's size settings. CI installs the target from rust-toolchain.toml, lints the crate for wasm32-wasip1 and builds the module in the Rust suite.

This is the first part of one-click template installs: a later change runs this module next to @cloudflare/worker-bundler to document template APIs during a server-side build.

Validation: cargo fmt --check, cargo clippy --workspace --all-targets -D warnings, the WebAssembly clippy and build, cargo test --workspace, and RUN_CLI_TESTS=1 for service-documentation.test.ts and app-services-cli.test.ts (52 tests) pass. New tests cover entry-mode documentation and skipping services declared by dependencies.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no blocking issues were found.

Summary

Service documentation moves into a shared Rust library that both the CLI and a new WebAssembly module can use.

  • Service documentation analysis now lives in a shared Rust crate.
  • Service docs can come from the original app entry module.
  • JavaScript callers can run service docs in WebAssembly.

The four earlier concerns are addressed: wrapped handlers resolve correctly, configured app declaration files remain included, library edits trigger CLI releases, and CI runs the built module. No new actionable issues were found.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  CLI[CLI deploy] --> Adapter[CLI extraction adapter]
  Adapter --> Library[Shared documentation library]
  Adapter --> OS[Operating system files]
  JS[JavaScript documentServices] --> WASM[WebAssembly module]
  WASM --> Library
  WASM --> Host[Host file calls]
  Host --> Files[In-memory files]
  Library --> JSON[Service documentation JSON]
Loading

Reviews (6) · Last reviewed commit: "Match the service documentation crates t..." · Reviewed by Greptile

Comment thread crates/platform-service-docs/src/lib.rs Resolved
Comment thread crates/platform-cli/Cargo.toml Resolved
Comment thread .github/workflows/check-suites.yaml Resolved
@tnkuehne
tnkuehne force-pushed the feat/service-docs-wasm branch from 499d1d8 to 40ab0a0 Compare November 19, 2026 17:24
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs d0cdca9 Nov 19 2026, 11:38 PM

Move the CLI's service documentation extraction into platform-service-docs
with an injected file system, so the same implementation runs natively in the
CLI and as a wasm32-wasip1 module (platform-service-docs-wasm) over a host file
system. An entry mode checks the original entry module instead of the bundle,
which keeps the type-checking program small enough for a Worker isolate.
Entry mode now follows identifiers to their declarations, so
`export default (handler satisfies Handler)` is documented, and keeps the
app's own declaration files from tsconfig, such as global interfaces.

A shared fixture checks native and WebAssembly output against one expected
result. The new @platform/service-docs package runs the module over an
in-memory file system; CI runs it after building the module. The new crate is
a CLI release input.
The app builder typechecks it with @cloudflare/workers-types.
@tnkuehne
tnkuehne force-pushed the feat/service-docs-wasm branch from dbb661b to d0cdca9 Compare November 19, 2026 23:37
@tnkuehne
tnkuehne merged commit a913b40 into main Nov 20, 2026
17 checks passed
@tnkuehne
tnkuehne deleted the feat/service-docs-wasm branch November 20, 2026 00:32
tnkuehne added a commit that referenced this pull request Nov 20, 2026
`@platform/app-builder` turns an app project's source files into what
`widefleet deploy` uploads: the bundled `worker.js`, its source map, the
Worker metadata and the service documentation. It is the build service
for one-click template installs and runs in workerd and celld.

- `POST /bundle` installs the project's npm dependencies with
`@cloudflare/worker-bundler`, bundles the Wrangler entry like the CLI
and returns the module, source map and metadata (bindings, compatibility
flags, crons, queue consumers, entrypoints, build ID).
- `POST /document` installs the declarations of the dependencies and of
the development dependencies the sources or tsconfig reference, runs the
service documentation module from #230 in entry mode and returns any
declaration install warnings.

The two phases are separate requests, so a hosted installation can
deploy the Worker twice and keep their memory in separate isolates. Only
the control plane reaches the builder, through service bindings or a
private network that no other workload joins. `NPM_REGISTRY` selects a
registry such as a company mirror. Syntax errors and imports that do not
resolve are reported as build errors, as the CLI's bundler reports them;
the source map module is named by its digest, as the CLI names it, so
the build ID covers the map. Projects with static assets keep deploying
through the CLI.

For the Gmail, GitHub and OneDrive templates the builder's module and
source map positions are byte-identical across workerd and celld, and
the documentation is identical to the CLI's. Remaining bundle
differences come from dependency versions installed from npm. Source
maps contain positions only: the control plane maps stack traces by
position, and documentation reads the original files.

The pinned `@cloudflare/[email protected]` patch:
- resolves packages with the bundle's export conditions and browser
fields, which selects the `workerd` builds of `@better-auth/core` and
`@better-auth/utils` as esbuild does for the CLI;
- matches externals exactly, so `fs` does not externalize `fs-extra`;
- streams package archives, unpacks at most three at once and keeps only
the files each phase reads, including empty modules;
- forwards `sourcesContent` and stops esbuild between builds, whose heap
otherwise keeps its largest size.

On Cloudflare a full Gmail build kept 56 MiB below the isolate memory
limit, and six consecutive builds succeeded; with the unpatched bundler
a single build exceeded it. Builds take 3–7 seconds in celld.

Stacked on #230. Later changes deploy the builder for hosted and
self-hosted installations and add template installs to the control
plane, API and CLI.

Validation: `pnpm check`; `RUN_BUILDER_TESTS=1` runs the built Worker in
Miniflare against a synthetic npm registry. It covers CLI-equivalent
metadata, the `workerd` export condition, empty modules and code named
like documentation, the `require` bridge and source map offset, the
build ID, documentation including type-only development dependencies,
and project and source errors. The main test fails with the unpatched
bundler. CI builds the documentation module and the Worker before these
tests.












<!-- greptile_comment -->

<!-- greptile_summary -->

<h2><a
href="https://app.greptile.com/api/retrigger?id=113052135&amp;sig=539e63bc66cd3e73b79b3ef5e4c3a19b8c60ef795adac929748b90ade0552214"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img
alt="Retrigger"
src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"
align="right"></picture></a><a
href="https://app.greptile.com/-/switch-tenant?tenant=mendra&amp;next=%2Fwidefleet%2Fwidefleet%2Fpull%2F232&amp;utm_source=greptile_review&amp;utm_medium=github&amp;utm_campaign=view_in_greptile"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptileDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"><img
alt="View in Greptile"
src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"
align="right"></picture></a>Confidence Score: 5/5</h2>

<!-- greptile-impact-verdict --> The follow-up appears safe to merge; no
new blocking issues were found.

<details open><summary><h3>Summary</h3></summary>

Adds a server-side Worker that builds app source files and generates
service documentation in separate requests.

- The builder turns Wrangler projects into deploy-ready Worker bundles.
- The builder creates service docs from project files and type
declarations.
- Package downloads and bundling use less memory per build.

tnkuehne accepts leaving unresolved `require()` calls for runtime so
optional dependencies inside `try` blocks can build.
</details>

<!-- greptile_confidence_score:5 -->

<sub>Reviews (8) · Last reviewed commit: ["Leave unresolved require()
calls for
run..."](1a5282c)
· [Reviewed by
Greptile](https://www.greptile.com/?utm_source=greptile_review&utm_medium=github&utm_campaign=review_public&utm_content=widefleet/widefleet)</sub>

<!-- /greptile_comment -->
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