refactor(routing): dedupe findFileWithExtensions helper#1076
refactor(routing): dedupe findFileWithExtensions helper#1076james-elicx merged 2 commits intomainfrom
Conversation
Extract the matcher.dottedExtensions.some(existsSync) one-liner used by both prerender.ts and dev-server.ts into routing/file-matcher.ts. Follow-up to #1058. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
commit: |
|
The type is no longer used after delegating to the shared findFileWithExtensions helper. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
/bigbonk review |
There was a problem hiding this comment.
Clean dedupe. Reviewed all three files:
-
file-matcher.ts: NewfindFileWithExtensionsis a standalone pure function next to theValidFileMatchertype it consumes — good home for it. TheexistsSyncimport is the only new side-effect import;file-matcher.tsalready imports fromnode:fs/promises, so addingnode:fsis fine. -
prerender.ts: Drops the local copy and the now-unnecessarytype ValidFileMatcherimport (the type flows throughcreateValidFileMatcher's return type).fsdefault import is retained — still used in 14 call sites formkdirSync/writeFileSync. -
dev-server.ts: Drops both the local copy and theimport fs from "node:fs"that was only there to support it. Confirmedfs.has zero remaining references in the file.
No semantic change, no new call sites introduced. LGTM.
|
Approved PR #1076. The refactor is clean — both local copies of |
Summary
matcher.dottedExtensions.some((ext) => existsSync(basePath + ext))one-liner into a single shared helper inrouting/file-matcher.ts.build/prerender.tsandserver/dev-server.tswith the shared export.Files changed
packages/vinext/src/routing/file-matcher.ts— addfindFileWithExtensionsexport (+existsSyncimport).packages/vinext/src/build/prerender.ts— drop local helper, import shared one.packages/vinext/src/server/dev-server.ts— drop local helper, import shared one. Removed now-unusedimport fs from "node:fs".Test plan
pnpm vp test run tests/app-router.test.ts tests/pages-router.test.ts(508 tests pass)pnpm fmt --writeon touched filespnpm knip(clean)🤖 Generated with Claude Code