@@ -240,25 +240,63 @@ async function installDeps(projectDir: string, packageManager: PackageManager, d
240
240
export async function getNextAppDetails ( projectDir : string ) : Promise < NextAppDetails > {
241
241
const isSrcDir = fs . existsSync ( path . resolve ( projectDir , 'src' ) )
242
242
243
+ // Match next.config.js, next.config.ts, next.config.mjs, next.config.cjs
243
244
const nextConfigPath : string | undefined = (
244
- await globby ( 'next.config.* (t|j)s' , { absolute : true , cwd : projectDir } )
245
+ await globby ( 'next.config.(\\w)? (t|j)s' , { absolute : true , cwd : projectDir } )
245
246
) ?. [ 0 ]
246
247
247
248
if ( ! nextConfigPath || nextConfigPath . length === 0 ) {
248
249
return {
249
250
hasTopLevelLayout : false ,
250
251
isSrcDir,
252
+ isSupportedNextVersion : false ,
251
253
nextConfigPath : undefined ,
254
+ nextVersion : null ,
252
255
}
253
256
}
254
257
255
258
const packageObj = await fse . readJson ( path . resolve ( projectDir , 'package.json' ) )
259
+ // Check if Next.js version is new enough
260
+ let nextVersion = null
261
+ if ( packageObj . dependencies ?. next ) {
262
+ nextVersion = packageObj . dependencies . next
263
+ // Match versions using regex matching groups
264
+ const versionMatch = / (?< major > \d + ) / . exec ( nextVersion )
265
+ if ( ! versionMatch ) {
266
+ p . log . warn ( `Could not determine Next.js version from ${ nextVersion } ` )
267
+ return {
268
+ hasTopLevelLayout : false ,
269
+ isSrcDir,
270
+ isSupportedNextVersion : false ,
271
+ nextConfigPath,
272
+ nextVersion,
273
+ }
274
+ }
275
+
276
+ const { major } = versionMatch . groups as { major : string }
277
+ const majorVersion = parseInt ( major )
278
+ if ( majorVersion < 15 ) {
279
+ return {
280
+ hasTopLevelLayout : false ,
281
+ isSrcDir,
282
+ isSupportedNextVersion : false ,
283
+ nextConfigPath,
284
+ nextVersion,
285
+ }
286
+ }
287
+ }
288
+
289
+ const isSupportedNextVersion = true
290
+
291
+ // Check if Payload already installed
256
292
if ( packageObj . dependencies ?. payload ) {
257
293
return {
258
294
hasTopLevelLayout : false ,
259
295
isPayloadInstalled : true ,
260
296
isSrcDir,
297
+ isSupportedNextVersion,
261
298
nextConfigPath,
299
+ nextVersion,
262
300
}
263
301
}
264
302
@@ -281,7 +319,15 @@ export async function getNextAppDetails(projectDir: string): Promise<NextAppDeta
281
319
? fs . existsSync ( path . resolve ( nextAppDir , 'layout.tsx' ) )
282
320
: false
283
321
284
- return { hasTopLevelLayout, isSrcDir, nextAppDir, nextConfigPath, nextConfigType : configType }
322
+ return {
323
+ hasTopLevelLayout,
324
+ isSrcDir,
325
+ isSupportedNextVersion,
326
+ nextAppDir,
327
+ nextConfigPath,
328
+ nextConfigType : configType ,
329
+ nextVersion,
330
+ }
285
331
}
286
332
287
333
function getProjectType ( args : {
0 commit comments