fix: use pathToFileURL for cross-platform seed main guard - #36
Merged
GeekTrainer merged 1 commit intoJul 30, 2026
Merged
Conversation
The previous check `import.meta.url === \`file://${process.argv[1]}\``
never matched on Windows because tsx normalises import.meta.url to
triple-slash forward-slash form (file:///C:/path) while the manual
construction produced double-slash backslash form (file://C:\path).
Replace with pathToFileURL(resolve(process.argv[1])).href which
produces the same normalised URL on all platforms.
Fixes github-samples#35"
There was a problem hiding this comment.
Pull request overview
Fixes the db/seed.ts “run-as-main” guard so npm run db:seed (and therefore predev/prebuild) correctly executes seedDatabase() on Windows, avoiding an empty database caused by mismatched file:// URL formatting.
Changes:
- Replaced the manual
file://${process.argv[1]}URL construction withpathToFileURL(resolve(process.argv[1])).hreffor cross-platform URL normalization. - Updated
node:url/node:pathimports to includepathToFileURLandresolve. - Added an inline comment explaining why
pathToFileURLis required for Windows compatibility.
Show a summary per file
| File | Description |
|---|---|
db/seed.ts |
Uses pathToFileURL(resolve(process.argv[1])).href in the main guard so seeding runs reliably on Windows under tsx. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
jamesmontemagno
approved these changes
Jul 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fix the \db/seed.ts\ main guard so that
pm run db:seed\ (and the \predev/\prebuild\ scripts) actually run \seedDatabase()\ on Windows.
The previous check used manual string construction:
\\ s
if (import.meta.url === \ile://\) {
\\
On Windows, \ sx\ normalises \import.meta.url\ to triple-slash forward-slash form (\ile:///C:/path/to/seed.ts), while the manual construction produces double-slash backslash form (\ile://C:\path\to\seed.ts). These strings never match, so the seed silently exits with code 0 but inserts nothing — the database stays empty and the site builds with no game pages.
Related Issue
Closes #35
Type of Change
Changes Made
ode:url\ import and
esolve\ to the
ode:path\ import
Testing
Data Layer Changes
pm run test:unit\ - all tests pass
pm run db:generate) for any schema change
Frontend Changes
pm run test:e2e\ - all tests pass
pm run build)
Checklist
Additional Notes
Verified on Windows 11 ARM64 with Node 20 + tsx. After the fix,
pm run db:seed\ logs \Database seeded.\ and the build generates all 21 game pages correctly. The fix is a no-op on macOS/Linux since \pathToFileURL\ produces the same result as the manual construction on those platforms.