Skip to content

refactor: consolidate fileURLToPath path resolution into resolveEntryPath()#702

Merged
james-elicx merged 1 commit intomainfrom
opencode/shiny-falcon
Mar 28, 2026
Merged

refactor: consolidate fileURLToPath path resolution into resolveEntryPath()#702
james-elicx merged 1 commit intomainfrom
opencode/shiny-falcon

Conversation

@james-elicx
Copy link
Copy Markdown
Collaborator

Summary

  • Adds resolveEntryPath(rel, base) to entries/runtime-entry-module.ts as the single owner of the fileURLToPath(new URL(rel, base)).replace(/\\/g, "/") idiom
  • Replaces 16 hand-rolled call sites in app-rsc-entry.ts and 8 in pages-server-entry.ts with the shared helper; resolveRuntimeEntryModule also delegates to it
  • Replaces const __dirname = path.dirname(fileURLToPath(import.meta.url)) in index.ts and cloudflare/tpr.ts with import.meta.dirname (Node 22+, already used throughout the test suite), removing now-unused imports

…Path()

Replace the repeated `fileURLToPath(new URL(rel, import.meta.url)).replace(/\\/g, "/")`
idiom across entry generators with a single shared utility. Add `resolveEntryPath(rel, base)`
to runtime-entry-module.ts, then use it in app-rsc-entry.ts (16 call sites),
pages-server-entry.ts (8 call sites), and have resolveRuntimeEntryModule delegate to it.
Replace `const __dirname = path.dirname(fileURLToPath(import.meta.url))` in index.ts and
tpr.ts with `import.meta.dirname` (Node 22+, already used throughout the test suite).
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 28, 2026

Open in StackBlitz

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

commit: aae0ba7

@james-elicx
Copy link
Copy Markdown
Collaborator Author

/bigbonk review

@github-actions
Copy link
Copy Markdown

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

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 refactor. Verified the following:

resolveEntryPath is a correct drop-in replacement. Every replaced call site used exactly fileURLToPath(new URL(rel, base)).replace(/\\/g, "/") — the helper encapsulates this precisely. No call sites had variations (different base, missing backslash replace, etc.).

resolveRuntimeEntryModule delegation is safe. The old code applied replace(/\\/g, "/") only on the return value, not on the filePath passed to fs.existsSync. The new code applies it before existsSync, but this is fine — fs.existsSync accepts forward slashes on Windows, and on POSIX there are no backslashes to replace.

import.meta.dirname replacements in index.ts and tpr.ts are correct. Both files are regular source modules (not generated entries), so import.meta.dirname (Node 22+, already used elsewhere in the codebase per the PR description) is a safe substitute for path.dirname(fileURLToPath(import.meta.url)). The tpr.ts change is slightly more subtle — old code used new URL(".", import.meta.url) to get the directory, but the result is the same.

pages-server-entry.ts sanitizeDestination import — the old code used path.resolve(__dirname, "../config/config-matchers.js").replace(/\\/g, "/") where __dirname was derived from fileURLToPath(import.meta.url). The new code uses resolveEntryPath("../config/config-matchers.js", import.meta.url) which is semantically identical.

No remaining hand-rolled call sites. Searched for fileURLToPath(new URL( in packages/vinext/src/ — the only real usage is the consolidated one in runtime-entry-module.ts. Remaining matches are in comments or generated code for unrelated purposes (og-inline/resvg WASM inlining).

No path.dirname(fileURLToPath(import.meta.url)) patterns left — verified no remaining instances.

Net -17 lines with a single source of truth for the idiom. LGTM.

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Mar 28, 2026

Reviewed and approved PR #702. Here's a summary of what I verified:

  • resolveEntryPath is a correct, exact consolidation of the fileURLToPath(new URL(rel, base)).replace(/\\/g, "/") pattern used across all 24 call sites (16 in app-rsc-entry.ts, 8 in pages-server-entry.ts).
  • resolveRuntimeEntryModule now delegates to the shared helper correctly. The subtle difference (backslash replace now happens before fs.existsSync instead of only on return) is safe because fs.existsSync accepts forward slashes on all platforms.
  • import.meta.dirname replacements in index.ts and tpr.ts are semantically identical to the old path.dirname(fileURLToPath(import.meta.url)) pattern. Both files are regular source modules (not generated entries), so this is safe.
  • No missed call sites — no remaining hand-rolled fileURLToPath(new URL(...)) patterns in the source (only in comments and unrelated generated code for resvg WASM inlining).
  • Pure refactor — no behavioral changes, net -17 lines.

github run

@james-elicx james-elicx marked this pull request as ready for review March 28, 2026 10:39
@james-elicx james-elicx merged commit 3757b0f into main Mar 28, 2026
31 checks passed
@james-elicx james-elicx deleted the opencode/shiny-falcon branch March 28, 2026 10:39
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