From 9a573e419b77861f9c7e44635b91f89b9128c869 Mon Sep 17 00:00:00 2001 From: shulaoda <165626830+shulaoda@users.noreply.github.com> Date: Fri, 3 Apr 2026 15:56:55 +0800 Subject: [PATCH] Revert "fix: normalize Drizzle schema paths for Windows compatibility (#75)" This reverts commit e4ab41f915b82a1bc1e0c348e6e7013fdf929761. --- packages/void/src/drizzle/discover.ts | 5 ++--- packages/void/src/plugin-drizzle.ts | 15 ++++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/void/src/drizzle/discover.ts b/packages/void/src/drizzle/discover.ts index 4a1a9bfd53..b8fa02f200 100644 --- a/packages/void/src/drizzle/discover.ts +++ b/packages/void/src/drizzle/discover.ts @@ -1,6 +1,5 @@ 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 }; @@ -14,12 +13,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 = toSlash(join(root, "db", "schema.ts")); + const filePath = join(root, "db", "schema.ts"); if (existsSync(filePath) && statSync(filePath).isFile()) { return { type: "file", path: filePath }; } - const dirPath = toSlash(join(root, "db", "schema")); + const dirPath = 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 88a24735fb..44db9b7c48 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, posix } from "node:path"; +import { join } from "node:path"; import { normalizePath, type Plugin } from "vite"; import { discoverSchema, type SchemaLocation } from "./drizzle/discover"; import { ensureProjectTsconfig } from "./codegen/project-tsconfig"; @@ -89,11 +89,16 @@ 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 compatibility + // Normalize separators for Windows — Vite uses forward slashes, + // but schema.path from Node's path.join uses backslashes on Windows. const normalizedImporter = normalizePath(importer); - if (schema.type === "file" && normalizedImporter === schema.path) + const normalizedSchemaPath = normalizePath(schema.path); + if (schema.type === "file" && normalizedImporter === normalizedSchemaPath) return VIRTUAL_SCHEMA_DB_ID; - if (schema.type === "directory" && normalizedImporter.startsWith(schema.path)) { + if ( + schema.type === "directory" && + normalizedImporter.startsWith(normalizedSchemaPath) + ) { return VIRTUAL_SCHEMA_DB_ID; } } @@ -105,7 +110,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 posix.join(schema.path, id.slice("@schema/".length)); + return join(schema.path, id.slice("@schema/".length)); } }, },