@@ -117,7 +117,7 @@ export const initCommand = async (options: InitCommandOptions) => {
117117 logger . info ( "📁 Detected use of src directory" ) ;
118118 }
119119
120- const nextJsDir = await detectPagesOrAppDir ( resolvedPath , usesSrcDir , isTypescriptProject ) ;
120+ const nextJsDir = await detectPagesOrAppDir ( resolvedPath , usesSrcDir ) ;
121121
122122 const routeDir = pathModule . join ( resolvedPath , usesSrcDir ? "src" : "" ) ;
123123
@@ -283,7 +283,6 @@ async function detectUseOfSrcDir(path: string): Promise<boolean> {
283283async function detectPagesOrAppDir (
284284 path : string ,
285285 usesSrcDir = false ,
286- isTypescriptProject = false
287286) : Promise < "pages" | "app" > {
288287 const nextConfigPath = pathModule . join ( path , "next.config.js" ) ;
289288 const importedConfig = await import ( pathToFileURL ( nextConfigPath ) . toString ( ) ) . catch ( ( ) => ( { } ) ) ;
@@ -296,14 +295,16 @@ async function detectPagesOrAppDir(
296295 // If so then we return app
297296 // If not return pages
298297
299- const extension = isTypescriptProject ? "tsx" : "js" ;
298+ const extensionsToCheck = [ "jsx" , "tsx" , "js" , "ts" ] ;
299+ const basePath = pathModule . join ( path , usesSrcDir ? "src" : "" , "app" , `page.` ) ;
300300
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 ) ;
302304
303- const appPageExists = await pathExists ( appPagePath ) ;
304-
305- if ( appPageExists ) {
306- return "app" ;
305+ if ( appPageExists ) {
306+ return "app" ;
307+ }
307308 }
308309
309310 return "pages" ;
0 commit comments