Skip to content

refactor(routing): dedupe findFileWithExtensions helper#1076

Merged
james-elicx merged 2 commits intomainfrom
refactor/dedupe-find-file-with-extensions
May 5, 2026
Merged

refactor(routing): dedupe findFileWithExtensions helper#1076
james-elicx merged 2 commits intomainfrom
refactor/dedupe-find-file-with-extensions

Conversation

@james-elicx
Copy link
Copy Markdown
Collaborator

Summary

  • Extract the matcher.dottedExtensions.some((ext) => existsSync(basePath + ext)) one-liner into a single shared helper in routing/file-matcher.ts.
  • Replace the two identical local copies in build/prerender.ts and server/dev-server.ts with the shared export.
  • Pure refactor: same return type, same semantics. Follow-up to refactor(routing): dedupe param decoding into shared helper #1058.

Files changed

  • packages/vinext/src/routing/file-matcher.ts — add findFileWithExtensions export (+ existsSync import).
  • 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-unused import 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 --write on touched files
  • pnpm knip (clean)

🤖 Generated with Claude Code

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>
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 5, 2026

Open in StackBlitz

npm i https://pkg.pr.new/vinext@1076

commit: db6277c

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

Example Preview Production Original
app-router-cloudflare preview production
pages-router-cloudflare preview production
app-router-playground preview production original
realworld-api-rest preview production
nextra-docs-template preview production
benchmarks preview production
hackernews preview production original

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>
@james-elicx
Copy link
Copy Markdown
Collaborator Author

/bigbonk review

Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean dedupe. Reviewed all three files:

  • file-matcher.ts: New findFileWithExtensions is a standalone pure function next to the ValidFileMatcher type it consumes — good home for it. The existsSync import is the only new side-effect import; file-matcher.ts already imports from node:fs/promises, so adding node:fs is fine.

  • prerender.ts: Drops the local copy and the now-unnecessary type ValidFileMatcher import (the type flows through createValidFileMatcher's return type). fs default import is retained — still used in 14 call sites for mkdirSync/writeFileSync.

  • dev-server.ts: Drops both the local copy and the import fs from "node:fs" that was only there to support it. Confirmed fs. has zero remaining references in the file.

No semantic change, no new call sites introduced. LGTM.

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented May 5, 2026

Approved PR #1076. The refactor is clean — both local copies of findFileWithExtensions are replaced by a single shared export in routing/file-matcher.ts, and the now-unused import fs from "node:fs" in dev-server.ts is correctly removed (no remaining fs. references). No semantic changes.

github run

@james-elicx james-elicx marked this pull request as ready for review May 5, 2026 18:54
@james-elicx james-elicx merged commit d2da43b into main May 5, 2026
31 of 32 checks passed
@james-elicx james-elicx deleted the refactor/dedupe-find-file-with-extensions branch May 5, 2026 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant