feat(cloudflare/Worker): Add option (bundle:false) to skip bundling by Rolldown#117
Open
czxtm wants to merge 6 commits into
Open
feat(cloudflare/Worker): Add option (bundle:false) to skip bundling by Rolldown#117czxtm wants to merge 6 commits into
bundle:false) to skip bundling by Rolldown#117czxtm wants to merge 6 commits into
Conversation
…r-byte When deploying a Worker whose `main` already points at a complete, runtime-ready ESM bundle produced by an external tool (OpenNext, wrangler, custom build pipelines, etc.), alchemy still runs that artifact through `cloudflareRolldown`. `isExternal: true` already disables alchemy's Effect-wrapping virtual entry, but `prepareBundle` still calls `Bundle.build(...)` with `cloudflareRolldown` on the way through. There is currently no way to opt out of that re-bundle. This adds a new `WorkerProps.bundle?: boolean` (default `true`). When set to `false`, `prepareBundle` reads `props.main` directly and returns a synthetic single-file `Bundle.BundleOutput` whose `content` is the file's bytes verbatim and whose `hash` is sha256(bytes). The downstream upload path is unchanged. The accompanying integration test works as follows: 1. Deploy a hand-written ESM bundle that contains a SENTINEL comment 2. Verify the resulting `worker.hash?.bundle` equals `sha256(sourceBytes)` (which is impossible to satisfy if rolldown ran on the file) 3. Round-trip a request through the deployed Worker to confirm the literal sentinel string survives.
Contributor
|
cc @john-royal |
Contributor
isExternal is Effect vs Async style. It should not skip bundling |
Contributor
|
Can we add an example that exercises this code path? Maybe examples/cloudflare-nextjs, is that what you're doing? |
Contributor
Author
|
Yeah, I'll move the one in the repro to examples |
Minimal Next.js + OpenNext app deployed via `Cloudflare.Worker` with `bundle: false`, demonstrating the new opt-out for alchemy's rolldown step on pre-built worker bundles. Condensed from the upstream repro (czxtm/repro-alchemy-bundle-false) — 11 files instead of ~36, no Fumadocs/MDX/AI/Tailwind scaffolding.
Contributor
Author
|
@sam-goodwin is this still useful? |
Contributor
@john-royal can you look at this and decide what we should do here? |
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.
I discovered this when trying to deploy Fumadocs. This PR unblocks the ability to deploy Fumadocs and probably many other Next.js apps using
@opennextjs/cloudflare:When deploying a Worker whose
mainalready points at a complete, runtime-ready ESM bundle produced by an external tool (OpenNext, wrangler, custom build pipelines, etc.), alchemy still runs that artifact throughcloudflareRolldown.isExternal: truealready disables alchemy's Effect-wrapping virtual entry, butprepareBundlestill callsBundle.build(...)withcloudflareRolldownon the way through. There is currently no way to opt out of that re-bundle.This adds a new
WorkerProps.bundle?: boolean(defaulttrue). When set tofalse,prepareBundlereadsprops.maindirectly and returns a synthetic single-fileBundle.BundleOutputwhosecontentis the file's bytes verbatim and whosehashis sha256(bytes). The downstream upload path is unchanged.The accompanying integration test works as follows:
worker.hash?.bundleequalssha256(sourceBytes)(which is impossible to satisfy if rolldown ran on the file)A reproduction of a failing deploy of Fumadocs (using
bunx create-fumadocs-app) is available here: https://github.com/czxtm/repro-alchemy-bundle-falseThe main branch is a failing reproduction while the fix-bundle-false branch contains a patched version of alchemy that includes the changes introduced in this PR.
If
isExternal: trueis actually supposed to skip the re-bundling as well and just needs a bugfix, then this PR is not the right solution and can be closed.