Skip to content

fix: use pathToFileURL for cross-platform seed main guard - #36

Merged
GeekTrainer merged 1 commit into
github-samples:mainfrom
cinnamon-msft:fix/seed-windows-main-guard
Jul 30, 2026
Merged

fix: use pathToFileURL for cross-platform seed main guard#36
GeekTrainer merged 1 commit into
github-samples:mainfrom
cinnamon-msft:fix/seed-windows-main-guard

Conversation

@cinnamon-msft

Copy link
Copy Markdown
Contributor

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

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • \db/seed.ts: replaced \ ile://\\ with \pathToFileURL(resolve(process.argv[1])).href\ — produces a correctly normalised URL on all platforms (macOS, Linux, Windows x64, Windows ARM64)
  • Added \pathToFileURL\ to the
    ode:url\ import and
    esolve\ to the
    ode:path\ import

Testing

Data Layer Changes

  • Ran
    pm run test:unit\ - all tests pass
  • Added/updated Vitest tests for data-layer changes
  • Generated a migration (
    pm run db:generate) for any schema change

Frontend Changes

  • Ran
    pm run test:e2e\ - all tests pass
  • Verified build succeeds (
    pm run build)

Checklist

  • My code follows the project's coding standards
  • I have used explicit TypeScript types for function parameters and return values
  • My changes are focused on a single concern
  • I have written clear commit messages explaining what and why

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.

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"
Copilot AI review requested due to automatic review settings July 30, 2026 21:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 with pathToFileURL(resolve(process.argv[1])).href for cross-platform URL normalization.
  • Updated node:url / node:path imports to include pathToFileURL and resolve.
  • Added an inline comment explaining why pathToFileURL is 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

@GeekTrainer
GeekTrainer merged commit e7ab3ef into github-samples:main Jul 30, 2026
4 checks passed
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.

Bug: db/seed.ts main guard never runs on Windows due to URL format mismatch

4 participants