Unverified Commit 16cf88e5 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Add experimental flag for providing entry paths (#67134)

Adds a flag for experimentally building on specifically provided entry
paths. This should not be relied on as it is NOT a public facing API.
parent b68caaf8
...@@ -866,14 +866,20 @@ export default async function build( ...@@ -866,14 +866,20 @@ export default async function build(
appDir appDir
) )
const pagesPaths = const providedPagePaths: string[] = JSON.parse(
!appDirOnly && pagesDir process.env.NEXT_PROVIDED_PAGE_PATHS || '[]'
? await nextBuildSpan.traceChild('collect-pages').traceAsyncFn(() => )
recursiveReadDir(pagesDir, {
pathnameFilter: validFileMatcher.isPageFile, let pagesPaths =
}) providedPagePaths.length > 0
) ? providedPagePaths
: [] : !appDirOnly && pagesDir
? await nextBuildSpan.traceChild('collect-pages').traceAsyncFn(() =>
recursiveReadDir(pagesDir, {
pathnameFilter: validFileMatcher.isPageFile,
})
)
: []
const middlewareDetectionRegExp = new RegExp( const middlewareDetectionRegExp = new RegExp(
`^${MIDDLEWARE_FILENAME}\\.(?:${config.pageExtensions.join('|')})$` `^${MIDDLEWARE_FILENAME}\\.(?:${config.pageExtensions.join('|')})$`
...@@ -936,18 +942,25 @@ export default async function build( ...@@ -936,18 +942,25 @@ export default async function build(
let denormalizedAppPages: string[] | undefined let denormalizedAppPages: string[] | undefined
if (appDir) { if (appDir) {
const appPaths = await nextBuildSpan const providedAppPaths: string[] = JSON.parse(
.traceChild('collect-app-paths') process.env.NEXT_PROVIDED_APP_PATHS || '[]'
.traceAsyncFn(() => )
recursiveReadDir(appDir, {
pathnameFilter: (absolutePath) => let appPaths =
validFileMatcher.isAppRouterPage(absolutePath) || providedAppPaths.length > 0
// For now we only collect the root /not-found page in the app ? providedAppPaths
// directory as the 404 fallback : await nextBuildSpan
validFileMatcher.isRootNotFound(absolutePath), .traceChild('collect-app-paths')
ignorePartFilter: (part) => part.startsWith('_'), .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('_'),
})
)
mappedAppPages = await nextBuildSpan mappedAppPages = await nextBuildSpan
.traceChild('create-app-mapping') .traceChild('create-app-mapping')
......
...@@ -921,7 +921,7 @@ export const defaultConfig: NextConfig = { ...@@ -921,7 +921,7 @@ export const defaultConfig: NextConfig = {
output: !!process.env.NEXT_PRIVATE_STANDALONE ? 'standalone' : undefined, output: !!process.env.NEXT_PRIVATE_STANDALONE ? 'standalone' : undefined,
modularizeImports: undefined, modularizeImports: undefined,
experimental: { experimental: {
flyingShuttle: false, flyingShuttle: Boolean(process.env.NEXT_PRIVATE_FLYING_SHUTTLE),
prerenderEarlyExit: true, prerenderEarlyExit: true,
serverMinification: true, serverMinification: true,
serverSourceMaps: false, serverSourceMaps: false,
......
import { nextTestSetup } from 'e2e-utils'
import glob from 'glob'
import path from 'path'
describe('Provided page/app paths', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
dependencies: {
nanoid: '4.0.1',
},
env: {
NEXT_PROVIDED_PAGE_PATHS: JSON.stringify(['/index.js', '/ssg.js']),
NEXT_PROVIDED_APP_PATHS: JSON.stringify([
'/dashboard/page.js',
'/(newroot)/dashboard/another/page.js',
]),
},
})
if (isNextDev) {
it('should skip dev', () => {})
return
}
it('should only build the provided paths', async () => {
const appPaths = await glob.sync('**/*.js', {
cwd: path.join(next.testDir, '.next/server/app'),
})
const pagePaths = await glob.sync('**/*.js', {
cwd: path.join(next.testDir, '.next/server/pages'),
})
expect(appPaths).toEqual([
'_not-found/page_client-reference-manifest.js',
'_not-found/page.js',
'(newroot)/dashboard/another/page_client-reference-manifest.js',
'(newroot)/dashboard/another/page.js',
'dashboard/page_client-reference-manifest.js',
'dashboard/page.js',
])
expect(pagePaths).toEqual([
'_app.js',
'_document.js',
'_error.js',
'ssg.js',
])
for (const pathname of ['/', '/ssg', '/dashboard', '/dashboard/another']) {
const res = await next.fetch(pathname)
expect(res.status).toBe(200)
}
})
})
{ {
"version": 2, "version": 2,
"suites": { "suites": {
"test/e2e/app-dir/app/provide-paths.test.ts": {
"passed": [],
"pending": [],
"failed": ["Provided page/app paths should only build the provided paths"]
},
"test/e2e/404-page-router/index.test.ts": { "test/e2e/404-page-router/index.test.ts": {
"passed": [ "passed": [
"404-page-router 404-page-router with basePath of false and i18n of false and middleware false for /error should have the correct router parameters after it is ready", "404-page-router 404-page-router with basePath of false and i18n of false and middleware false for /error should have the correct router parameters after it is ready",
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment