@@ -54,6 +54,8 @@ import {
54
54
SERVER_FILES_MANIFEST ,
55
55
STATIC_STATUS_PAGES ,
56
56
MIDDLEWARE_MANIFEST ,
57
+ APP_PATHS_MANIFEST ,
58
+ APP_PATH_ROUTES_MANIFEST ,
57
59
} from '../shared/lib/constants'
58
60
import { getSortedRoutes , isDynamicRoute } from '../shared/lib/router/utils'
59
61
import { __ApiPreviewProps } from '../server/api-utils'
@@ -114,6 +116,7 @@ import { getNamedRouteRegex } from '../shared/lib/router/utils/route-regex'
114
116
import { flatReaddir } from '../lib/flat-readdir'
115
117
import { RemotePattern } from '../shared/lib/image-config'
116
118
import { eventSwcPlugins } from '../telemetry/events/swc-plugins'
119
+ import { normalizeAppPath } from '../shared/lib/router/utils/app-paths'
117
120
118
121
export type SsgRoute = {
119
122
initialRevalidateSeconds : number | false
@@ -385,10 +388,10 @@ export default async function build(
385
388
} )
386
389
)
387
390
388
- let mappedappPaths : { [ page : string ] : string } | undefined
391
+ let mappedAppPaths : { [ page : string ] : string } | undefined
389
392
390
393
if ( appPaths && appDir ) {
391
- mappedappPaths = nextBuildSpan
394
+ mappedAppPaths = nextBuildSpan
392
395
. traceChild ( 'create-app-mapping' )
393
396
. traceFn ( ( ) =>
394
397
createPagesMapping ( {
@@ -427,7 +430,7 @@ export default async function build(
427
430
rootDir : dir ,
428
431
rootPaths : mappedRootPaths ,
429
432
appDir,
430
- appPaths : mappedappPaths ,
433
+ appPaths : mappedAppPaths ,
431
434
pageExtensions : config . pageExtensions ,
432
435
} )
433
436
)
@@ -574,21 +577,36 @@ export default async function build(
574
577
defaultLocale : string
575
578
localeDetection ?: false
576
579
}
577
- } = nextBuildSpan . traceChild ( 'generate-routes-manifest' ) . traceFn ( ( ) => ( {
578
- version : 3 ,
579
- pages404 : true ,
580
- basePath : config . basePath ,
581
- redirects : redirects . map ( ( r : any ) => buildCustomRoute ( r , 'redirect' ) ) ,
582
- headers : headers . map ( ( r : any ) => buildCustomRoute ( r , 'header' ) ) ,
583
- dynamicRoutes : getSortedRoutes ( pageKeys )
584
- . filter ( isDynamicRoute )
585
- . map ( pageToRoute ) ,
586
- staticRoutes : getSortedRoutes ( pageKeys )
587
- . filter ( ( page ) => ! isDynamicRoute ( page ) && ! isReservedPage ( page ) )
588
- . map ( pageToRoute ) ,
589
- dataRoutes : [ ] ,
590
- i18n : config . i18n || undefined ,
591
- } ) )
580
+ } = nextBuildSpan . traceChild ( 'generate-routes-manifest' ) . traceFn ( ( ) => {
581
+ const sortedRoutes = getSortedRoutes ( [
582
+ ...pageKeys ,
583
+ ...Object . keys ( mappedAppPaths || { } ) . map ( ( key ) =>
584
+ normalizeAppPath ( key )
585
+ ) ,
586
+ ] )
587
+ const dynamicRoutes : Array < ReturnType < typeof pageToRoute > > = [ ]
588
+ const staticRoutes : typeof dynamicRoutes = [ ]
589
+
590
+ for ( const route of sortedRoutes ) {
591
+ if ( isDynamicRoute ( route ) ) {
592
+ dynamicRoutes . push ( pageToRoute ( route ) )
593
+ } else if ( ! isReservedPage ( route ) ) {
594
+ staticRoutes . push ( pageToRoute ( route ) )
595
+ }
596
+ }
597
+
598
+ return {
599
+ version : 3 ,
600
+ pages404 : true ,
601
+ basePath : config . basePath ,
602
+ redirects : redirects . map ( ( r : any ) => buildCustomRoute ( r , 'redirect' ) ) ,
603
+ headers : headers . map ( ( r : any ) => buildCustomRoute ( r , 'header' ) ) ,
604
+ dynamicRoutes,
605
+ staticRoutes,
606
+ dataRoutes : [ ] ,
607
+ i18n : config . i18n || undefined ,
608
+ }
609
+ } )
592
610
593
611
if ( rewrites . beforeFiles . length === 0 && rewrites . fallback . length === 0 ) {
594
612
routesManifest . rewrites = rewrites . afterFiles . map ( ( r : any ) =>
@@ -689,6 +707,7 @@ export default async function build(
689
707
REACT_LOADABLE_MANIFEST ,
690
708
config . optimizeFonts ? path . join ( serverDir , FONT_MANIFEST ) : null ,
691
709
BUILD_ID_FILE ,
710
+ appDir ? path . join ( serverDir , APP_PATHS_MANIFEST ) : null ,
692
711
]
693
712
. filter ( nonNullable )
694
713
. map ( ( file ) => path . join ( config . distDir , file ) ) ,
@@ -1618,6 +1637,24 @@ export default async function build(
1618
1637
'utf8'
1619
1638
)
1620
1639
1640
+ if ( appDir ) {
1641
+ const appPathsManifest = JSON . parse (
1642
+ await promises . readFile (
1643
+ path . join ( distDir , serverDir , APP_PATHS_MANIFEST ) ,
1644
+ 'utf8'
1645
+ )
1646
+ )
1647
+ const appPathRoutes : Record < string , string > = { }
1648
+
1649
+ Object . keys ( appPathsManifest ) . forEach ( ( entry ) => {
1650
+ appPathRoutes [ entry ] = normalizeAppPath ( entry ) || '/'
1651
+ } )
1652
+ await promises . writeFile (
1653
+ path . join ( distDir , APP_PATH_ROUTES_MANIFEST ) ,
1654
+ JSON . stringify ( appPathRoutes , null , 2 )
1655
+ )
1656
+ }
1657
+
1621
1658
const middlewareManifest : MiddlewareManifest = JSON . parse (
1622
1659
await promises . readFile (
1623
1660
path . join ( distDir , serverDir , MIDDLEWARE_MANIFEST ) ,
0 commit comments