@@ -117,7 +117,7 @@ export const initCommand = async (options: InitCommandOptions) => {
117
117
logger . info ( "📁 Detected use of src directory" ) ;
118
118
}
119
119
120
- const nextJsDir = await detectPagesOrAppDir ( resolvedPath , usesSrcDir , isTypescriptProject ) ;
120
+ const nextJsDir = await detectPagesOrAppDir ( resolvedPath , usesSrcDir ) ;
121
121
122
122
const routeDir = pathModule . join ( resolvedPath , usesSrcDir ? "src" : "" ) ;
123
123
@@ -283,7 +283,6 @@ async function detectUseOfSrcDir(path: string): Promise<boolean> {
283
283
async function detectPagesOrAppDir (
284
284
path : string ,
285
285
usesSrcDir = false ,
286
- isTypescriptProject = false
287
286
) : Promise < "pages" | "app" > {
288
287
const nextConfigPath = pathModule . join ( path , "next.config.js" ) ;
289
288
const importedConfig = await import ( pathToFileURL ( nextConfigPath ) . toString ( ) ) . catch ( ( ) => ( { } ) ) ;
@@ -296,14 +295,16 @@ async function detectPagesOrAppDir(
296
295
// If so then we return app
297
296
// If not return pages
298
297
299
- const extension = isTypescriptProject ? "tsx" : "js" ;
298
+ const extensionsToCheck = [ "jsx" , "tsx" , "js" , "ts" ] ;
299
+ const basePath = pathModule . join ( path , usesSrcDir ? "src" : "" , "app" , `page.` ) ;
300
300
301
- const appPagePath = pathModule . join ( path , usesSrcDir ? "src" : "" , "app" , `page.${ extension } ` ) ;
301
+ for ( const extension of extensionsToCheck ) {
302
+ const appPagePath = basePath + extension ;
303
+ const appPageExists = await pathExists ( appPagePath ) ;
302
304
303
- const appPageExists = await pathExists ( appPagePath ) ;
304
-
305
- if ( appPageExists ) {
306
- return "app" ;
305
+ if ( appPageExists ) {
306
+ return "app" ;
307
+ }
307
308
}
308
309
309
310
return "pages" ;
0 commit comments