From 93b28e033ab34f391f9a7e188686b76aad7f2c78 Mon Sep 17 00:00:00 2001 From: Kayla Cinnamon Date: Thu, 30 Jul 2026 17:48:55 -0400 Subject: [PATCH] fix: use pathToFileURL for cross-platform seed main guard 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 #35" --- db/seed.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/db/seed.ts b/db/seed.ts index 7c489ec..ebdc055 100644 --- a/db/seed.ts +++ b/db/seed.ts @@ -1,6 +1,6 @@ import { readFileSync } from 'node:fs'; -import { fileURLToPath } from 'node:url'; -import { dirname, join } from 'node:path'; +import { fileURLToPath, pathToFileURL } from 'node:url'; +import { dirname, join, resolve } from 'node:path'; import { eq } from 'drizzle-orm'; import { createDatabase, type Database } from '../src/lib/db'; import { categories, games, publishers } from './schema'; @@ -73,7 +73,9 @@ export async function seedDatabase(db: Database, csvPath: string = join(here, 'g } // Allow running directly: `tsx db/seed.ts` -if (import.meta.url === `file://${process.argv[1]}`) { +// pathToFileURL normalises Windows backslashes and slash count, making the +// comparison safe on all platforms when invoked via `tsx db/seed.ts`. +if (import.meta.url === pathToFileURL(resolve(process.argv[1])).href) { const db = createDatabase(); seedDatabase(db) .then(() => {