[wrangler] Allow test harness to reuse dry-run output - #15000
Conversation
🦋 Changeset detectedLatest commit: efb2464 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
f14eb8f to
efb2464
Compare
|
✅ All changesets look good |
@cloudflare/autoconfig
@cloudflare/build-output-utils
@cloudflare/config
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-functions
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
|
Codeowners approval required for this PR:
Show detailed file reviewers |
| const outputFileName = config.no_bundle | ||
| ? path.basename(main) | ||
| : `${path.parse(main).name}.js`; | ||
| main = path.join(outDir, outputFileName); |
There was a problem hiding this comment.
🟡 Prebuilt-output reuse always fails for projects that turn off bundling
The prebuilt entrypoint is looked for inside the output folder (fs.existsSync(main) at packages/wrangler/src/api/test-harness.ts:560) even for projects that disable bundling, where the build never copies the entry file there, so the test harness always fails to start with a message telling the user to re-run a build they already ran.
Impact: Anyone using this new build-once option on a project configured with bundling disabled cannot start the test harness at all.
Why the entry file is absent from the output directory when bundling is disabled
When no_bundle is set, wrangler deploy --dry-run --outdir X goes through noBundleWorker() (packages/wrangler/src/deployment-bundle/no-bundle-worker.ts:8-29), which only calls writeAdditionalModules(modules, outDir) and returns resolvedEntryPointPath: entry.file — i.e. the original source path. Nothing writes the entry module into the outdir (packages/wrangler/src/deployment-bundle/maybe-build-worker.ts:139-145; only the esbuild path at :146-189 writes into destination).
So outputFileName = path.basename(main) resolved against outDir (e.g. worker-output/index.js) never exists, and resolveWorkerConfig throws the Could not find the prebuilt Worker entrypoint ... UserError, instructing the user to run exactly the command they already ran.
The non-no_bundle branch (${path.parse(main).name}.js) is correct — esbuild sets entryNames: path.parse(entryFile).name with outdir: destination (packages/wrangler/src/deployment-bundle/bundle.ts:382-386).
A reasonable fix is to keep using the original config.main when the source config has no_bundle: true (the emitted additional modules already live in outDir), rather than expecting a copy of the entrypoint in the output directory.
Prompt for agents
In packages/wrangler/src/api/test-harness.ts, resolveWorkerConfig() computes the expected prebuilt entrypoint filename as path.basename(main) when the user's Wrangler config sets no_bundle: true. That assumption is wrong: `wrangler deploy --dry-run --outdir <dir>` with no_bundle goes through noBundleWorker() (packages/wrangler/src/deployment-bundle/no-bundle-worker.ts), which only writes the *additional* modules into the outdir and returns the original source file as resolvedEntryPointPath. The entry module itself is never copied into the outdir, so fs.existsSync() always fails and the harness throws the 'Could not find the prebuilt Worker entrypoint' UserError with an instruction to run a command the user already ran successfully.
Decide on the right behavior for no_bundle projects: either keep pointing `main` at the original (source) entry file while still setting base_dir to the outDir so the emitted additional modules are picked up, or explicitly reject the outDir option for no_bundle configs with a clear explanation. Add an e2e case covering a no_bundle config alongside the existing bundled case in packages/wrangler/e2e/createTestHarness.test.ts.
Was this helpful? React with 👍 or 👎 to provide feedback.
workers-devprod
left a comment
There was a problem hiding this comment.
Codeowners reviews satisfied
Allow Wrangler projects to build a Worker once with
wrangler deploy --dry-run --outdirand reuse that output withcreateTestHarness(). The harness retains the Wrangler configuration and selected environment while avoiding rebuilds during startup and reset.A picture of a cute animal (not mandatory, but encouraged)
Note
This is a contribution from an AI agent: Codex, GPT-5.