> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tuturuuu.com/llms.txt
> Use this file to discover all available pages before exploring further.

# cf Build Output module discovery

> How wave-1 cf Build Output emits choose Worker modules, and the checks that stop a dropped module graph from shipping.

`discoverCfBuildOutputEsmModules` (in `scripts/ci/cf-build-output-publisher.mjs`)
chooses the Worker modules that a wave-1 cf Build Output emit uploads.

## Why it changed

The emit used to walk only `dist/server/.vite/manifest.json`, which belongs to
the ssr environment. A Vite RSC Worker reaches its second environment with
`import.meta.viteRsc.loadModule`, which compiles to
``import(`./rsc/bridge-api.js`)``. The `rsc/` graph and
`__vite_rsc_assets_manifest.js` are absent from that manifest.

As a result, Finance `831c6aae6f` uploaded 222 of its 470 modules through cf. The
Worker started cleanly, but the top-level `import()` rejected, so every route
returned 500 from the outer response-policy catch. `wrangler deploy --no-bundle`
uploads every module that matches its rules, so it was unaffected.

## Emit rule

The emit uploads every sealed `.js`/`.mjs` module that the Wrangler rules match
under `dist/server`, as `--no-bundle` does. Rule globs match the bundle-relative
path: `**/` spans directories, `*` and `?` stay within one segment, and `{a,b}`
alternates (nesting allowed). Every other character is literal. Backslashes are
path separators, so there is no escape syntax, and unbalanced braces fail. Source maps and dot directories are
skipped, and symlinks (files or directories) are refused. Modules are sorted, so
`worker.config.json` is byte-stable.

A caller can drop unimported files only by listing them in `excludedOrphans`.
Each listed file must be sealed, must not be the main module and must not be in
the Vite graph. Excluding orphans fails if any emitted module calls `import()`
with anything other than one constant string or template literal (a variable,
concatenation or `` `${base}/x.js` ``), because that import could load an
excluded file. No wave-1 caller excludes orphans today.

## Independent checks

These checks run before any upload in the production path:
`wave1-cf-output.mjs` `buildInput` → `discoverCfBuildOutputEsmModules`.

* **Vite graph presence.** Every module in the ssr manifest graph, following
  `imports` and `dynamicImports`, must exist and be emitted.
* **Relative-import closure (`assertModuleClosure`).** This check scans each
  emitted module for relative static and dynamic specifiers. That includes
  comments inside `import(` and constant template literals, and it ignores
  `?query` and `#hash` suffixes. Emission fails if a specifier names an existing
  ES module that is not emitted: one outside the bundle root (after resolving
  symlinks), in a dot directory, or excluded. A non-ESM file inside the root,
  such as `.wasm` or text, fails as unsupported by this emit. Directories and
  non-ESM files outside the root pass, because specifier text also appears in
  comments and strings. Specifiers that name no file pass, such as JSDoc
  `@import` comments or prose.
* **Count.** `wave1-cf-output` logs the emitted count against the sealed count.

Regression coverage is in `scripts/ci/cf-build-output-publisher.test.mjs` and
`scripts/ci/wave1-cf-output.test.mjs`. It covers the RSC layout, a manifest-only
negative control, computed imports, root and dot-directory escapes, a symlinked
directory, explicit orphan exclusion, non-ESM imports, comment and directory
noise, rule globs including nested and unbalanced braces, the computed-import
detector's documented limits, and the published-set comparison.

## Published-version comparison (not yet wired)

`assertUploadedModuleSet(uploadedNames, manifest)` compares a published
version's module names with the emitted manifest. It normalizes `./`, a leading
`/` and backslashes, and fails on missing, extra or repeated names. No publish
path calls it yet.

Cloudflare has no names-only endpoint for a version's modules.
`GET /accounts/<account>/workers/workers/<worker>/versions/<id>` returns no
module data, and `include=modules_metadata` is ignored. `?include=modules`
returns every module's name and base64 bytes, which is about 17 MB for Finance.

To wire the comparison without raising the 1 MiB control-plane JSON cap, read
that response with a separate streaming reader. The reader keeps only
`result.modules[].name` and `result.main_module`, discards `content_base64` as
it streams, and bounds the total bytes by the measured upload size. Run it after
`cf workers versions create` and before any traffic split.

## Source maps over the upload limit

Cloudflare rejects a version whose source maps exceed 60 MiB encoded or 15 MiB
gzipped (API error 10021; `uploadLimits` in
`scripts/ci/wave1-native-upload-limits.mjs`). When a Void emit uploads maps
(`upload_source_maps: true`) and they exceed either limit,
`scripts/ci/void-cf-sourcemaps.mjs` keeps the main module's map first, then
the smallest maps, while the kept total stays within 90% of both limits, and
drops the rest. Maps that cannot fit are all dropped. The emit makes this
choice, so `measureBuildOutputUpload` (which counts the `.map` files in the
Build Output) and the upload see the same maps. `void-cf-receipt.json` records
`sourceMaps` with the limits, totals, kept names and each dropped map's name
and bytes. Only maps are dropped: JS and other modules, the module manifest's
non-map entries, the module-set compare and the closure checks are unchanged.
`scripts/ci/void-cf-sourcemaps.test.mjs` covers each case.

## Auditing a hosted version

* `GET /workers/scripts/<name>/content/v2` ignores `?version=` and returns the
  latest upload. Do not use it to compare versions.
* `GET /workers/workers/<name>/versions/<id>?include=modules` returns the module
  names and bytes of the version that actually serves traffic. A closure walk
  from `main_module` over those bytes shows whether any imported module is
  missing.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.