Content-Length: 546373 | pFad | http://github.com/classicvalues/next.js/commit/16cf88e569552fe5060f1d28a657b749b967528d

56 Add experimental flag for providing entry paths (#67134) · classicvalues/next.js@16cf88e · GitHub
Skip to content

Commit 16cf88e

Browse files
authored
Add experimental flag for providing entry paths (vercel#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.
1 parent b68caaf commit 16cf88e

File tree

4 files changed

+92
-21
lines changed

4 files changed

+92
-21
lines changed

packages/next/src/build/index.ts

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -866,14 +866,20 @@ export default async function build(
866866
appDir
867867
)
868868

869-
const pagesPaths =
870-
!appDirOnly && pagesDir
871-
? await nextBuildSpan.traceChild('collect-pages').traceAsyncFn(() =>
872-
recursiveReadDir(pagesDir, {
873-
pathnameFilter: validFileMatcher.isPageFile,
874-
})
875-
)
876-
: []
869+
const providedPagePaths: string[] = JSON.parse(
870+
process.env.NEXT_PROVIDED_PAGE_PATHS || '[]'
871+
)
872+
873+
let pagesPaths =
874+
providedPagePaths.length > 0
875+
? providedPagePaths
876+
: !appDirOnly && pagesDir
877+
? await nextBuildSpan.traceChild('collect-pages').traceAsyncFn(() =>
878+
recursiveReadDir(pagesDir, {
879+
pathnameFilter: validFileMatcher.isPageFile,
880+
})
881+
)
882+
: []
877883

878884
const middlewareDetectionRegExp = new RegExp(
879885
`^${MIDDLEWARE_FILENAME}\\.(?:${config.pageExtensions.join('|')})$`
@@ -936,18 +942,25 @@ export default async function build(
936942
let denormalizedAppPages: string[] | undefined
937943

938944
if (appDir) {
939-
const appPaths = await nextBuildSpan
940-
.traceChild('collect-app-paths')
941-
.traceAsyncFn(() =>
942-
recursiveReadDir(appDir, {
943-
pathnameFilter: (absolutePath) =>
944-
validFileMatcher.isAppRouterPage(absolutePath) ||
945-
// For now we only collect the root /not-found page in the app
946-
// directory as the 404 fallback
947-
validFileMatcher.isRootNotFound(absolutePath),
948-
ignorePartFilter: (part) => part.startsWith('_'),
949-
})
950-
)
945+
const providedAppPaths: string[] = JSON.parse(
946+
process.env.NEXT_PROVIDED_APP_PATHS || '[]'
947+
)
948+
949+
let appPaths =
950+
providedAppPaths.length > 0
951+
? providedAppPaths
952+
: await nextBuildSpan
953+
.traceChild('collect-app-paths')
954+
.traceAsyncFn(() =>
955+
recursiveReadDir(appDir, {
956+
pathnameFilter: (absolutePath) =>
957+
validFileMatcher.isAppRouterPage(absolutePath) ||
958+
// For now we only collect the root /not-found page in the app
959+
// directory as the 404 fallback
960+
validFileMatcher.isRootNotFound(absolutePath),
961+
ignorePartFilter: (part) => part.startsWith('_'),
962+
})
963+
)
951964

952965
mappedAppPages = await nextBuildSpan
953966
.traceChild('create-app-mapping')

packages/next/src/server/config-shared.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ export const defaultConfig: NextConfig = {
921921
output: !!process.env.NEXT_PRIVATE_STANDALONE ? 'standalone' : undefined,
922922
modularizeImports: undefined,
923923
experimental: {
924-
flyingShuttle: false,
924+
flyingShuttle: Boolean(process.env.NEXT_PRIVATE_FLYING_SHUTTLE),
925925
prerenderEarlyExit: true,
926926
serverMinification: true,
927927
serverSourceMaps: false,
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { nextTestSetup } from 'e2e-utils'
2+
import glob from 'glob'
3+
import path from 'path'
4+
5+
describe('Provided page/app paths', () => {
6+
const { next, isNextDev } = nextTestSetup({
7+
files: __dirname,
8+
dependencies: {
9+
nanoid: '4.0.1',
10+
},
11+
env: {
12+
NEXT_PROVIDED_PAGE_PATHS: JSON.stringify(['/index.js', '/ssg.js']),
13+
NEXT_PROVIDED_APP_PATHS: JSON.stringify([
14+
'/dashboard/page.js',
15+
'/(newroot)/dashboard/another/page.js',
16+
]),
17+
},
18+
})
19+
20+
if (isNextDev) {
21+
it('should skip dev', () => {})
22+
return
23+
}
24+
25+
it('should only build the provided paths', async () => {
26+
const appPaths = await glob.sync('**/*.js', {
27+
cwd: path.join(next.testDir, '.next/server/app'),
28+
})
29+
const pagePaths = await glob.sync('**/*.js', {
30+
cwd: path.join(next.testDir, '.next/server/pages'),
31+
})
32+
33+
expect(appPaths).toEqual([
34+
'_not-found/page_client-reference-manifest.js',
35+
'_not-found/page.js',
36+
'(newroot)/dashboard/another/page_client-reference-manifest.js',
37+
'(newroot)/dashboard/another/page.js',
38+
'dashboard/page_client-reference-manifest.js',
39+
'dashboard/page.js',
40+
])
41+
expect(pagePaths).toEqual([
42+
'_app.js',
43+
'_document.js',
44+
'_error.js',
45+
'ssg.js',
46+
])
47+
48+
for (const pathname of ['/', '/ssg', '/dashboard', '/dashboard/another']) {
49+
const res = await next.fetch(pathname)
50+
expect(res.status).toBe(200)
51+
}
52+
})
53+
})

test/turbopack-build-tests-manifest.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"version": 2,
33
"suites": {
4+
"test/e2e/app-dir/app/provide-paths.test.ts": {
5+
"passed": [],
6+
"pending": [],
7+
"failed": ["Provided page/app paths should only build the provided paths"]
8+
},
49
"test/e2e/404-page-router/index.test.ts": {
510
"passed": [
611
"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",

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/classicvalues/next.js/commit/16cf88e569552fe5060f1d28a657b749b967528d

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy