@@ -9,6 +9,7 @@ import { createConfigLoader } from "../config/config";
9
9
import { generate } from "./generate" ;
10
10
import type { Context } from "./context" ;
11
11
import { getTypesDir , getTypesPath } from "./paths" ;
12
+ import type { RouteManifestEntry } from "../config/routes" ;
12
13
13
14
export async function run ( rootDirectory : string ) {
14
15
const ctx = await createContext ( { rootDirectory, watch : false } ) ;
@@ -71,11 +72,24 @@ async function createContext({
71
72
} ;
72
73
}
73
74
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
+
74
83
async function writeAll ( ctx : Context ) : Promise < void > {
75
84
const typegenDir = getTypesDir ( ctx ) ;
76
85
77
86
fs . rmSync ( typegenDir , { recursive : true , force : true } ) ;
78
87
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
+
79
93
const typesPath = getTypesPath ( ctx , route ) ;
80
94
const content = generate ( ctx , route ) ;
81
95
fs . mkdirSync ( Path . dirname ( typesPath ) , { recursive : true } ) ;
0 commit comments