Skip to content

Commit 6f21209

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

File tree

1 file changed

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

1 file changed

+14
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { createConfigLoader } from "../config/config";
99
import { generate } from "./generate";
1010
import type { Context } from "./context";
1111
import { getTypesDir, getTypesPath } from "./paths";
12+
import type { RouteManifestEntry } from "../config/routes";
1213

1314
export async function run(rootDirectory: string) {
1415
const ctx = await createContext({ rootDirectory, watch: false });
@@ -71,11 +72,24 @@ async function createContext({
7172
};
7273
}
7374

75+
function isRouteInAppDirectory(ctx: Context, route: RouteManifestEntry) {
76+
const absoluteRoutePath = Path.isAbsolute(route.file)
77+
? route.file
78+
: Path.resolve(ctx.config.appDirectory, route.file);
79+
80+
return absoluteRoutePath.startsWith(ctx.config.appDirectory);
81+
}
82+
7483
async function writeAll(ctx: Context): Promise<void> {
7584
const typegenDir = getTypesDir(ctx);
7685

7786
fs.rmSync(typegenDir, { recursive: true, force: true });
7887
Object.values(ctx.config.routes).forEach((route) => {
88+
// We only generate types for routes in the app directory
89+
if (!isRouteInAppDirectory(ctx, route)) {
90+
return;
91+
}
92+
7993
const typesPath = getTypesPath(ctx, route);
8094
const content = generate(ctx, route);
8195
fs.mkdirSync(Path.dirname(typesPath), { recursive: true });

0 commit comments

Comments
 (0)