diff --git a/packages/next/src/build/index.ts b/packages/next/src/build/index.ts index bed34bfa85d27..766df924bd9ee 100644 --- a/packages/next/src/build/index.ts +++ b/packages/next/src/build/index.ts @@ -912,8 +912,13 @@ export default async function build( appDir ) - let pagesPaths = - !appDirOnly && pagesDir + const providedPagePaths: string[] = JSON.parse( + process.env.NEXT_PRIVATE_PAGE_PATHS || '[]' + ) + + let pagesPaths = Boolean(process.env.NEXT_PRIVATE_PAGE_PATHS) + ? providedPagePaths + : !appDirOnly && pagesDir ? await nextBuildSpan.traceChild('collect-pages').traceAsyncFn(() => recursiveReadDir(pagesDir, { pathnameFilter: validFileMatcher.isPageFile, @@ -1008,18 +1013,24 @@ export default async function build( } if (appDir) { - let appPaths = await nextBuildSpan - .traceChild('collect-app-paths') - .traceAsyncFn(() => - recursiveReadDir(appDir, { - pathnameFilter: (absolutePath) => - validFileMatcher.isAppRouterPage(absolutePath) || - // For now we only collect the root /not-found page in the app - // directory as the 404 fallback - validFileMatcher.isRootNotFound(absolutePath), - ignorePartFilter: (part) => part.startsWith('_'), - }) - ) + const providedAppPaths: string[] = JSON.parse( + process.env.NEXT_PRIVATE_APP_PATHS || '[]' + ) + + let appPaths = Boolean(process.env.NEXT_PRIVATE_APP_PATHS) + ? providedAppPaths + : await nextBuildSpan + .traceChild('collect-app-paths') + .traceAsyncFn(() => + recursiveReadDir(appDir, { + pathnameFilter: (absolutePath) => + validFileMatcher.isAppRouterPage(absolutePath) || + // For now we only collect the root /not-found page in the app + // directory as the 404 fallback + validFileMatcher.isRootNotFound(absolutePath), + ignorePartFilter: (part) => part.startsWith('_'), + }) + ) if (appPaths && isFullFlyingShuttle) { await nextBuildSpan