Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/void/src/drizzle/discover.ts
Original file line number Diff line number Diff line change
@@ -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 };

Expand All @@ -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 };
}
Expand Down
15 changes: 5 additions & 10 deletions packages/void/src/plugin-drizzle.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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));
}
},
},
Expand Down
Loading