Skip to content

fix(deploy): bundle framework Workers with Cloudflare module rules and Worker conditions - #540

Merged
Brooooooklyn merged 3 commits into
voidzero-dev:mainfrom
Pleasurecruise:fix/framework-worker-bundle
Oct 22, 2026
Merged

Brooooooklyn merged 3 commits into
voidzero-dev:mainfrom
Pleasurecruise:fix/framework-worker-bundle

Conversation

@Pleasurecruise

@Pleasurecruise Pleasurecruise commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #539

prepareBundledBuildOutput bundles framework Worker output again with a plain Vite lib build. It now matches @cloudflare/vite-plugin in two ways:

  • Additional modules. A plugin applies the Cloudflare Vite plugin's module rules: .wasm and .wasm?module, .bin, .txt, .html and .sql, including # subpath imports that resolve to them. Matching imports stay external, and each file is emitted beside the bundle with a path relative to the chunk that imports it. copyBundle already uploads these files as wasm, data and text modules. The Cloudflare plugin does not export its rules, so the plugin repeats them.
  • Resolve conditions. The build uses WORKER_CONDITIONS, which Void's other Worker bundles already use. The constant moves from wrapper.ts to its own module so that cf-build-output.ts still loads Vite lazily.

Both changes apply to every bundle that prepareBundledBuildOutput builds, including the static Worker.

Tests

packages/void/test/unit/cf-build-output.test.ts:

  • A framework Worker with wasm-bindgen-style and plain Wasm, text and data imports, a # subpath import and a dynamic import produces wasm, text and data modules and passes the cf dry run.
  • A dependency with workerd and browser exports resolves to its workerd build.

Each test fails when its change is removed. vp run test, vp run --filter ./packages/void typecheck, vp lint and vp fmt --check pass.

I also prepared the output of a SvelteKit app that uses @resvg/resvg-wasm and micromark: index_bg.wasm is uploaded as a wasm module, and the bundle contains the Worker build of decode-named-character-reference.

Follow-up changes (21e826b, 1cb2d9f)

import './a.txt'  ─┐                          ┌─> a.txt   (text)
import './a.bin'  ─┤  same bytes, before: ──> │   one file, one type ✗
                   │  same bytes, now:   ──>  └─> a.txt (text) + a.bin (data) ✓
import './sa"me.bin'   before: ENOENT ✗   now: sa_me.bin ✓
esm-env DEV            before: not folded  now: folded to false ✓
  • Each module file is emitted once per source path, with its own name and extension. Files with the same bytes are no longer merged, so each import keeps its module type.
  • The external id holds a counter key instead of the path, and emitted names keep only letters, digits, ., _ and -. A quote in a path no longer breaks the import.
  • The build adds the production condition, like @cloudflare/vite-plugin does for production builds. It is fixed rather than taken from NODE_ENV, because a deploy bundle is always a production build. Without it, the SvelteKit playground bundle lost the production build of esm-env.
  • The reference regex is replaced by a small indexOf loop. Each build uses a random marker, so app strings that look like a module id stay as they are.

Tests: the Wasm test adds same-bytes .txt/.bin files, a quoted file name (' on Windows) and an app string that looks like the old marker; the conditions test adds a package with development/production exports.

Left out, since they behave the same before this PR (and in @cloudflare/vite-plugin for the second):

  • Packages without exports still prefer the browser main field.
  • Wasm reached through an export subpath without a .wasm suffix is not kept as a module.

🤖 Generated with Claude Code

Pleasurecruise and others added 2 commits October 21, 2026 22:59
…d Worker conditions

The framework Worker bundle now keeps Wasm, data and text imports as Worker
modules, as the Cloudflare Vite plugin does, and resolves dependencies with
Worker conditions.
- Emit each Wasm, data or text module once per source file with its own
  name and extension, so files with the same bytes keep their module type.
- Key the external id by a counter, and keep emitted names to safe
  characters, so quotes in a path no longer break the import string.
- Resolve with the 'production' condition, like @cloudflare/vite-plugin,
  so packages such as esm-env fold their production build.
- Replace the reference regex with a small indexOf loop.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T05:33:15.487136Z 1cb2d9f New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 21e826bd3f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/void/test/unit/cf-build-output.test.ts Outdated
Comment thread packages/void/src/cli/cf-build-output.ts
- Each build picks a random marker for module ids, so app strings that
  look like an id are no longer rewritten.
- The quoted-name test uses `'` on Windows, which does not allow `"`.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Brooooooklyn
Brooooooklyn merged commit 70c275d into voidzero-dev:main Oct 22, 2026
18 checks passed
@Pleasurecruise
Pleasurecruise deleted the fix/framework-worker-bundle branch October 22, 2026 13:38
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.

Native deploy mishandles Wasm, text and data imports and package exports in framework Workers

2 participants