Skip to content

Commit 6902a87

Browse files
committed
Only generate types for route modules in a projects app directory
1 parent 74fed50 commit 6902a87

File tree

1 file changed

+11
-0
lines changed
  • packages/react-router-dev/typegen

1 file changed

+11
-0
lines changed

packages/react-router-dev/typegen/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import pc from "picocolors";
55
import type vite from "vite";
66

77
import { createConfigLoader } from "../config/config";
8+
import type { RouteManifestEntry } from "../config/routes";
89

910
import { generate } from "./generate";
1011
import type { Context } from "./context";
@@ -71,11 +72,21 @@ async function createContext({
7172
};
7273
}
7374

75+
function isRouteInAppDirectory(ctx: Context, route: RouteManifestEntry) {
76+
const absoluteRoutePath = Path.resolve(ctx.config.appDirectory, route.file);
77+
return absoluteRoutePath.startsWith(ctx.config.appDirectory);
78+
}
79+
7480
async function writeAll(ctx: Context): Promise<void> {
7581
const typegenDir = getTypesDir(ctx);
7682

7783
fs.rmSync(typegenDir, { recursive: true, force: true });
7884
Object.values(ctx.config.routes).forEach((route) => {
85+
// We only generate types for routes in the app directory
86+
if (!isRouteInAppDirectory(ctx, route)) {
87+
return;
88+
}
89+
7990
const typesPath = getTypesPath(ctx, route);
8091
const content = generate(ctx, route);
8192
fs.mkdirSync(Path.dirname(typesPath), { recursive: true });

0 commit comments

Comments
 (0)