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
9 changes: 6 additions & 3 deletions packages/void/src/codegen/project-tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function ensureProjectTsconfig(
hasRouteTypes?: boolean,
hasDb?: boolean,
hasSchema?: boolean,
options: { redirectDbModule?: boolean } = {},
): void {
const outDir = join(root, ".void");
mkdirSync(outDir, { recursive: true });
Expand All @@ -30,13 +31,15 @@ export function ensureProjectTsconfig(
const tsconfig: Record<string, unknown> = { files };

if (hasDb) {
const paths: Record<string, string[]> = {
const paths: Record<string, string[]> = {};

if (options.redirectDbModule !== false) {
// Redirect void/db to the generated db.d.ts so TypeScript uses
// schema-aware types instead of the generic base module.
// (moduleResolution: "bundler" ignores ambient `declare module`
// when the module resolves to a real file — paths is the fix.)
"void/db": ["./db.d.ts"],
};
paths["void/db"] = ["./db.d.ts"];
}

if (hasSchema) {
// Determine whether schema is a file or directory
Expand Down
6 changes: 5 additions & 1 deletion packages/void/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ export function voidPlugin(options?: {
// all other Class A frameworks and vinext Pages Router use plain SSR.
const viteEnvironment: { name: string; childEnvironments?: string[] } =
framework === "vinext-app" ? { name: "rsc", childEnvironments: ["ssr"] } : { name: "ssr" };
const redirectDbTypePaths = framework !== "vinext-app" && framework !== "vinext-pages";

// vinext injects vite-tsconfig-paths which spams warnings for every
// tsconfig that extends a non-existent .void/tsconfig.json. Void
Expand Down Expand Up @@ -752,7 +753,10 @@ export function voidPlugin(options?: {
bindingWatchPlugin,
envPlugin,
clientStubsPlugin,
drizzlePlugin(root, false, getDatabaseDialect(config), { forceVirtualDb: authEnabled }),
drizzlePlugin(root, false, getDatabaseDialect(config), {
forceVirtualDb: authEnabled,
redirectDbTypePaths,
}),
migrationPlugin(root, getDatabaseDialect(config)),
...(vinextCompat ? [vinextCompat] : []),
...cloudflare({
Expand Down
5 changes: 4 additions & 1 deletion packages/void/src/plugin-drizzle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const DRIZZLE_OPERATORS =

interface DrizzlePluginOptions {
forceVirtualDb?: boolean;
redirectDbTypePaths?: boolean;
}

/**
Expand All @@ -44,7 +45,9 @@ export function drizzlePlugin(
const hasDbRuntime = schema != null || options.forceVirtualDb === true;

// Always write tsconfig (for routes.d.ts, queues.d.ts, etc.)
ensureProjectTsconfig(root, hasRouteTypes, hasDbRuntime, schema != null);
ensureProjectTsconfig(root, hasRouteTypes, hasDbRuntime, schema != null, {
redirectDbModule: options.redirectDbTypePaths,
});

// Generate db.d.ts when void/db is available, even without a user schema.
if (hasDbRuntime) {
Expand Down
10 changes: 10 additions & 0 deletions packages/void/test/unit/plugin-drizzle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,14 @@ describe("drizzlePlugin db typing generation", () => {
expect(code).not.toContain("import * as schema");
expect(code).toContain("drizzle(getConnectionString())");
});

it("can keep void/db off tsconfig paths for metaframeworks that materialize aliases", () => {
const root = createProjectRoot();

drizzlePlugin(root, false, "sqlite", { redirectDbTypePaths: false });

const tsconfig = JSON.parse(readFileSync(join(root, ".void", "tsconfig.json"), "utf8"));
expect(tsconfig.compilerOptions.paths["void/db"]).toBeUndefined();
expect(tsconfig.compilerOptions.paths["@schema"]).toEqual(["../db/schema.ts"]);
});
});
2 changes: 1 addition & 1 deletion playground/vinext-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"react": "^19.2.4",
"react-dom": "^19.2.4",
"react-server-dom-webpack": "^19.2.4",
"vinext": "^0.0.18"
"vinext": "^0.0.35"
},
"devDependencies": {
"@types/react": "^19.2.14",
Expand Down
2 changes: 1 addition & 1 deletion playground/vinext-pages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dependencies": {
"react": "^19.2.4",
"react-dom": "^19.2.4",
"vinext": "^0.0.18"
"vinext": "^0.0.35"
},
"devDependencies": {
"@types/react": "^19.2.14",
Expand Down
32 changes: 22 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading