Repository navigation
fix(cloudflare): read v1 Build Output alongside v0 - #4704
Conversation
|
/bigbonk review for issues |
@vinext/cloudflare
create-vinext-app
@vinext/types
vinext
@cloudflare/workers-response-store
commit: |
| root, | ||
| ".cloudflare/output/v0/workers/default/worker.config.json", | ||
| ); | ||
| const buildOutputConfigPath = resolveBuildOutputDefaultWorkerConfigPath(root); |
There was a problem hiding this comment.
[warning] v1 Worker configs allow domains entries such as { hostname, production, previews }, but the extraction below accepts only strings. A valid v1 config using a production-enabled object therefore falls through to no custom domain and silently disables traffic-aware warming. Please normalize both schema forms (and select an object enabled for production). The v1 schema is defined in cloudflare/workers-sdk#16917 (DomainSchema).
There was a problem hiding this comment.
Fixed in a9a291e: TPR now takes the first string domain or the first object domain with production: true, with a test covering the object form.
|
Review: 1 finding. Posted 1 actionable inline comment. |
Performance benchmarksCompared 2 improved · 0 regressed · 5 within ±1.5%
View detailed results and traces 🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head |
|
|
/bigbonk review for issues |
|
LGTM! |
There was a problem hiding this comment.
Superseded by the review of
b1e77cab.
This review, of a9a291e3
💬 Approved with comments — The change is correct and well scoped. There is one INFO note about a mismatch with the cacheability scanner when both output versions exist, and one optional SUGGESTION to align the CI check with the helper.
Findings: 1 info · 1 suggestion (2 are inline comments on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 1 info · 1 suggestion
The helper is used consistently. Two minor consistency notes.
Recommendation: 💬 Optional Nits
- [INFO] The helper picks v1 when both versions have a default Worker config, but cacheability-artifact.ts throws unless exactly one does. (
packages/cloudflare/src/build-output.ts:14) - [SUGGESTION] The CI check uses
test -d v1, but the helper checks for v1/workers/default/worker.config.json. (.github/workflows/ci.yml:462)
View full review
- Dual-version output (INFO).
resolveBuildOutputDirprefersv1when bothv0andv1have a default Worker config.resolveBuildOutputArtifactincacheability-artifact.ts:189-204throws unless exactly one version has one, so two-stage CDN warming still fails if a stalev0sits next to a freshv1. That was already true before this change. Consider sharing one resolver, or documenting that output with both versions is unsupported. - Workflow check vs helper (SUGGESTION). The workflows choose
v1withtest -d, but the helper requiresv1/workers/default/worker.config.json. Checking for that file in the workflows would make them select the same directory as the helper.
✅ All other checks passed
🔒 Security: ✅ LGTM
No security issues found in the Build Output path resolution or the domain parsing.
📖 AGENTS.md: ✅ LGTM
Nothing in this pull request needs a change to the agent guidelines.
⚡ Performance: ✅ LGTM
No performance concerns. The new code is a few deploy-time existence checks.
📝 Documentation: ✅ LGTM
The new helper is documented clearly.
Reviewed commit: a9a291e3
| */ | ||
| export function resolveBuildOutputDir(root: string): string { | ||
| const outputDir = path.join(root, ".cloudflare", "output"); | ||
| for (const version of BUILD_OUTPUT_VERSIONS) { |
There was a problem hiding this comment.
ℹ️ INFO · Code Quality
The helper picks v1 when both versions have a default Worker config, but cacheability-artifact.ts throws unless exactly one does.
If v0 and v1 both have workers/default/worker.config.json (say a stale v0 left behind after an upgrade), this resolver returns v1. resolveBuildOutputArtifact in cacheability-artifact.ts still requires exactly one such config, so two-stage CDN warming throws in that state. That was already the case before this change. Consider having the scanner use this resolver, or documenting that output with both versions is unsupported.
There was a problem hiding this comment.
Fixed in b1e77ca: cacheability-artifact.ts now uses the shared resolver, so a stale v0 next to v1 resolves to v1 there too, with a test.
| test -f .cloudflare/output/v0/workers/default/worker.config.json | ||
| test -f .cloudflare/output/v0/workers/cva-cloudflare-response-store/worker.config.json | ||
| OUTPUT_DIR=.cloudflare/output/v1 | ||
| test -d "$OUTPUT_DIR" || OUTPUT_DIR=.cloudflare/output/v0 |
There was a problem hiding this comment.
💬 SUGGESTION · Code Quality
The CI check uses test -d v1, but the helper checks for v1/workers/default/worker.config.json.
The helper treats v1 as present only when workers/default/worker.config.json exists, but this check accepts any v1 directory. An empty or partial v1 next to a complete v0 would make this step assert against v1 and fail, while the deploy code would use v0. Testing for the worker config file here (and in the create-app workflows) would keep the two in sync.
There was a problem hiding this comment.
Fixed in b1e77ca: all three workflows now pick v1 only when v1/workers/default/worker.config.json exists.
… the Build Output helper
|
clanky review |
|
/bigbonk review for issues |
There was a problem hiding this comment.
Superseded by the review of
4b65f074.
This review, of b1e77cab
✅ Approved — Both earlier notes are fixed at b1e77ca and no new issues were found in the changed code.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security issues found in the Build Output path resolution, the domain parsing or the workflow changes.
📖 AGENTS.md: ✅ LGTM
Nothing in this pull request needs a change to the agent guidelines.
📋 Code Quality: ✅ LGTM
Both earlier notes are fixed. cacheability-artifact.ts now uses the shared resolver, and the workflows check for v1/workers/default/worker.config.json before choosing v1. When neither version has a config, the code still falls back to v0, so a missing build reports the same errors as before.
⚡ Performance: ✅ LGTM
No performance concerns. The new code adds only a few file-existence checks at deploy time.
📝 Documentation: ✅ LGTM
The new helper is documented clearly.
Reviewed commit: b1e77cab
|
Review: 1 findings.
|
|
/bigbonk review for issues |
There was a problem hiding this comment.
Superseded by the review of
83cb25ea.
This review, of 4b65f074
✅ Approved — No issues found in the code changed since the last review. Multi-version Build Output is rejected consistently, and production object domains are handled correctly.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security issues in the path resolution, the domain parsing or the workflow changes.
📖 AGENTS.md: ✅ LGTM
Nothing in this pull request needs a change to the agent guidelines.
📋 Code Quality: ✅ LGTM
The resolver falls back to v0 and rejects output in more than one version. findProductionDomain handles string and production object domains, and falls back to the wrangler custom domain otherwise. The new tests cover v1 output, the multi-version rejection and object domains.
⚡ Performance: ✅ LGTM
The change adds only a single directory read at deploy time.
📝 Documentation: ✅ LGTM
The new helper's JSDoc describes the fallback and the multi-version rejection accurately.
Reviewed commit: 4b65f074
| `Found Cloudflare Build Output in more than one format (${versions.join(", ")}) in ${outputDir}. Delete ${outputDir} and rebuild.`, | ||
| ); | ||
| } | ||
| return path.join(outputDir, versions[0] ?? "v0"); |
There was a problem hiding this comment.
[warning] A sole v2 (or any future vN) directory is returned as usable even though this code only understands the v0/v1 workers/default layout and config schema. Build Output explicitly guarantees only the v<N> directory naming convention; everything inside is version-specific, and Cloudflare's v1 readBuildOutput() rejects newer versions. This can make vinext read or rewrite an incompatible bundle before cf rejects it. Please allow only v0 and v1 here and throw for any other detected version. Reference: https://github.com/cloudflare/workers-sdk/blob/b8ae10f9b4c31d50b55a05cf87d397f9d00f3948/packages/build-output-utils/src/read.ts#L178-L232
There was a problem hiding this comment.
Fixed in 83cb25e: a sole version other than v0/v1 is now rejected with an upgrade error, with a test.
| .readdirSync(outputDir, { withFileTypes: true }) | ||
| .filter( | ||
| (entry) => | ||
| (entry.isDirectory() || entry.isSymbolicLink()) && |
There was a problem hiding this comment.
[warning] A sole version symlink is accepted and every caller follows it; the cacheability path can then write modules through that link outside the Build Output tree. Cloudflare's reader counts version symlinks during detection only so its subsequent symlink validation rejects them, and it also rejects linked .cloudflare/output paths. Reject linked path components before returning this directory so --warm-cache cannot mutate linked content before cf fails. Reference: https://github.com/cloudflare/workers-sdk/blob/b8ae10f9b4c31d50b55a05cf87d397f9d00f3948/packages/build-output-utils/src/read.ts#L234-L286
There was a problem hiding this comment.
Fixed in 83cb25e: a symlinked version directory, .cloudflare or output is now rejected before any caller reads or writes through it, with tests.
|
Review: 2 findings. Posted 2 actionable inline comments. |
|
/bigbonk review for issues |
There was a problem hiding this comment.
✅ Approved — No issues in the code changed since the last review. Symlinked, unsupported-version and multi-version Build Output are all rejected consistently, and the new tests cover each case.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
A linked .cloudflare, output or version directory is rejected before any caller reads or writes through it, including the cacheability artifact path that writes modules.
📖 AGENTS.md: ✅ LGTM
Nothing in this pull request needs a change to the agent guidelines.
📋 Code Quality: ✅ LGTM
resolveBuildOutputDir uses lstat to reject a symlinked .cloudflare or output. It also rejects a symlinked version directory, because Dirent.isSymbolicLink() does not follow links. Output in more than one version is rejected before the v0/v1 check, and a lone unsupported version fails with an upgrade error. With no version directory it still falls back to v0. The new tests in tests/deploy.test.ts cover v2, a symlinked v1 and a symlinked .cloudflare.
⚡ Performance: ✅ LGTM
The resolver adds a few lstat/stat calls and one small readdir, and only at deploy time.
📝 Documentation: ✅ LGTM
The JSDoc on resolveBuildOutputDir correctly describes the v0 fallback and the rejection of multi-version, unsupported and linked output.
Reviewed commit: 83cb25ea
|
Review: 1 findings.
|
The typed
cfdeploy flow hardcoded.cloudflare/output/v0when locating the generated default Worker, so a Build Output written underv1would be missed.Changes
packages/cloudflare/src/build-output.ts, which resolves the versioned Build Output directory (v0,v1, …). Like cf's Build Output reader (@cloudflare/build-output-utils), it rejects output in more than one version with "Delete .cloudflare/output and rebuild" rather than guessing between them. Builds clean the whole.cloudflare/output, so this only happens with leftover or hand-copied output. With no version directory it returns thev0path, so existing missing-build errors are unchanged.v0path was hardcoded or scanned:deploy.ts: the Worker bundle and assets directories for prerendering, and the version-metadata check before CDN warmup.tpr.ts: readingdomainsfrom the Worker config (typed configs only). This also accepts object domains ({ hostname, production, previews }) and picks the first production one.version-deploy.ts: reading the Worker name.cacheability-artifact.ts: locating the Worker config for two-stage CDN warming.v1whenv1/workers/default/worker.config.jsonexists and fall back tov0.cfbuild output now go through the helper. Tests that write their ownv0files are unchanged and still coverv0.Tests
v1Build Output for prerender dirs, the Worker name, and the cacheability manifest; rejection when bothv0andv1exist; production object domains for TPR.vp test runontests/deploy.test.ts,tests/cloudflare-version-deploy.test.ts,tests/cloudflare-cdn-warm-deploy.test.ts,tests/tpr-routes.test.tsandtests/deploy-prerender-config.test.ts: all pass.vp checkis clean on the changed files.No build or dev runtime code is touched, so there are no perf numbers here.