From f3e3bcb565a79582f44ad218911cb1653492bf15 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 18 Sep 2024 14:50:31 -0700 Subject: [PATCH] Re-add internal env for providing page paths (#70235) This re-adds internal env variables to allow providing page paths directly for debugging purposes. This is NOT a public API and should not be leveraged outside of internal Next.js debugging. x-ref: https://github.com/vercel/next.js/pull/67134 x-ref: [slack thread](https://vercel.slack.com/archives/C04DUD7EB1B/p1726519130567199) --- packages/next/src/build/index.ts | 39 ++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 14 deletions(-) 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