diff --git a/packages/void/src/drizzle/discover.ts b/packages/void/src/drizzle/discover.ts index b8fa02f200..4a1a9bfd53 100644 --- a/packages/void/src/drizzle/discover.ts +++ b/packages/void/src/drizzle/discover.ts @@ -1,5 +1,6 @@ import { existsSync, statSync } from "node:fs"; import { join } from "node:path"; +import { toSlash } from "../shared/utils"; export type SchemaLocation = { type: "file"; path: string } | { type: "directory"; path: string }; @@ -13,12 +14,12 @@ export type SchemaLocation = { type: "file"; path: string } | { type: "directory * Returns null if no schema is found. */ export function discoverSchema(root: string): SchemaLocation | null { - const filePath = join(root, "db", "schema.ts"); + const filePath = toSlash(join(root, "db", "schema.ts")); if (existsSync(filePath) && statSync(filePath).isFile()) { return { type: "file", path: filePath }; } - const dirPath = join(root, "db", "schema"); + const dirPath = toSlash(join(root, "db", "schema")); if (existsSync(dirPath) && statSync(dirPath).isDirectory()) { return { type: "directory", path: dirPath }; } diff --git a/packages/void/src/plugin-drizzle.ts b/packages/void/src/plugin-drizzle.ts index 44db9b7c48..88a24735fb 100644 --- a/packages/void/src/plugin-drizzle.ts +++ b/packages/void/src/plugin-drizzle.ts @@ -1,6 +1,6 @@ import { existsSync, mkdirSync, readdirSync, writeFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; -import { join } from "node:path"; +import { join, posix } from "node:path"; import { normalizePath, type Plugin } from "vite"; import { discoverSchema, type SchemaLocation } from "./drizzle/discover"; import { ensureProjectTsconfig } from "./codegen/project-tsconfig"; @@ -89,16 +89,11 @@ export function drizzlePlugin( // (virtual:void-db imports the schema, which imports void/db). // Schema files only need SQL helpers, not the runtime DB instance. if (schema && importer) { - // Normalize separators for Windows — Vite uses forward slashes, - // but schema.path from Node's path.join uses backslashes on Windows. + // Normalize separators for Windows compatibility const normalizedImporter = normalizePath(importer); - const normalizedSchemaPath = normalizePath(schema.path); - if (schema.type === "file" && normalizedImporter === normalizedSchemaPath) + if (schema.type === "file" && normalizedImporter === schema.path) return VIRTUAL_SCHEMA_DB_ID; - if ( - schema.type === "directory" && - normalizedImporter.startsWith(normalizedSchemaPath) - ) { + if (schema.type === "directory" && normalizedImporter.startsWith(schema.path)) { return VIRTUAL_SCHEMA_DB_ID; } } @@ -110,7 +105,7 @@ export function drizzlePlugin( // where Vite's config-level resolve.alias may not be applied. if (schema && (id === "@schema" || id.startsWith("@schema/"))) { if (id === "@schema") return schema.path; - return join(schema.path, id.slice("@schema/".length)); + return posix.join(schema.path, id.slice("@schema/".length)); } }, },