mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #1077] [MERGED] refactor(build): dedupe JSON file safe-read pattern #1074
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#1074
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/1077
Author: @james-elicx
Created: 5/5/2026
Status: ✅ Merged
Merged: 5/5/2026
Merged by: @james-elicx
Base:
main← Head:refactor/dedupe-json-file-read📝 Commits (1)
2047044refactor(build): dedupe JSON file safe-read pattern📊 Changes
3 files changed (+37 additions, -15 deletions)
View changed files
📝
packages/vinext/src/build/server-manifest.ts(+3 -7)📝
packages/vinext/src/build/standalone.ts(+10 -8)➕
packages/vinext/src/utils/safe-json-file.ts(+24 -0)📄 Description
Summary
Follow-up to #1058. Extracts the repeated
try { JSON.parse(readFileSync(...)) } catchpattern from build pipeline files into a single shared helper.New helper:
packages/vinext/src/utils/safe-json-file.tsReturns
nullon any read/parse failure. OptionalonErrorlets callers log/observe errors while still receivingnull. Callers mapnullto whatever fallback they need (?? [],?? undefined, etc.).Files changed
packages/vinext/src/utils/safe-json-file.ts— new helper.packages/vinext/src/build/server-manifest.ts—readPrerenderSecretnow usesreadJsonFile. Public signature unchanged (string | undefined).packages/vinext/src/build/standalone.ts—readServerExternalsManifestnow usesreadJsonFilewith the existingonErrorwarning preserved. TheexistsSyncgate is kept so an existing-but-malformed file still triggers the warning.Subtle differences between the original sites
readPrerenderSecretswallowed errors silently and returnedundefined— preserved by mapping the helper'snulltoundefinedvia optional chaining on the parsed object.readServerExternalsManifestlogged viaconsole.warnand returned[]— preserved by passing anonErrorcallback and using?? [].readPackageJsoninstandalone.tsis not the same pattern — it is a thin parse wrapper with no try/catch and no fallback (it propagates errors). Left untouched to preserve its throwing semantics; callers rely on it.Test plan
pnpm vp test run tests/app-router.test.ts tests/pages-router.test.ts— 508 passedpnpm fmt --writeon touched filespnpm knip— clean (no unused exports)🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.