@@ -7,7 +7,6 @@ import { sep } from 'path'
77import { verifyRootLayout } from '../../../lib/verifyRootLayout'
88import * as Log from '../../../build/output/log'
99import { APP_DIR_ALIAS } from '../../../lib/constants'
10- import { resolveFileBasedMetadataForLoader } from '../../../lib/metadata/resolve-metadata'
1110
1211const FILE_TYPES = {
1312 layout : 'layout' ,
@@ -37,26 +36,21 @@ async function createTreeCodeFromPath({
3736 resolveParallelSegments,
3837} : {
3938 pagePath : string
40- resolve : (
41- pathname : string ,
42- resolveDir ?: boolean
43- ) => Promise < string | undefined >
39+ resolve : ( pathname : string ) => Promise < string | undefined >
4440 resolveParallelSegments : (
4541 pathname : string
4642 ) => [ key : string , segment : string ] [ ]
4743} ) {
4844 const splittedPath = pagePath . split ( / [ \\ / ] / )
4945 const appDirPrefix = splittedPath [ 0 ]
5046 const pages : string [ ] = [ ]
51-
5247 let rootLayout : string | undefined
5348 let globalError : string | undefined
5449
5550 async function createSubtreePropsFromSegmentPath (
5651 segments : string [ ]
5752 ) : Promise < {
5853 treeCode : string
59- treeMetadataCode : string
6054 } > {
6155 const segmentPath = segments . join ( '/' )
6256
@@ -71,26 +65,12 @@ async function createTreeCodeFromPath({
7165 parallelSegments . push ( ...resolveParallelSegments ( segmentPath ) )
7266 }
7367
74- let metadataCode = ''
75-
7668 for ( const [ parallelKey , parallelSegment ] of parallelSegments ) {
7769 if ( parallelSegment === PAGE_SEGMENT ) {
7870 const matchedPagePath = `${ appDirPrefix } ${ segmentPath } /page`
7971 const resolvedPagePath = await resolve ( matchedPagePath )
8072 if ( resolvedPagePath ) pages . push ( resolvedPagePath )
8173
82- metadataCode += `{
83- type: 'page',
84- layer: ${
85- // There's an extra virtual segment.
86- segments . length - 1
87- } ,
88- mod: () => import(/* webpackMode: "eager" */ ${ JSON . stringify (
89- resolvedPagePath
90- ) } ),
91- path: ${ JSON . stringify ( resolvedPagePath ) } ,
92- },`
93-
9474 // Use '' for segment as it's the page. There can't be a segment called '' so this is the safest way to add it.
9575 props [ parallelKey ] = `['', {}, {
9676 page: [() => import(/* webpackMode: "eager" */ ${ JSON . stringify (
@@ -100,8 +80,9 @@ async function createTreeCodeFromPath({
10080 }
10181
10282 const parallelSegmentPath = segmentPath + '/' + parallelSegment
103- const { treeCode : subtreeCode , treeMetadataCode : subTreeMetadataCode } =
104- await createSubtreePropsFromSegmentPath ( [ ...segments , parallelSegment ] )
83+ const { treeCode : subtreeCode } = await createSubtreePropsFromSegmentPath (
84+ [ ...segments , parallelSegment ]
85+ )
10586
10687 // `page` is not included here as it's added above.
10788 const filePaths = await Promise . all (
@@ -120,27 +101,6 @@ async function createTreeCodeFromPath({
120101 rootLayout = layoutPath
121102 }
122103
123- // Collect metadata for the layout
124- if ( layoutPath ) {
125- metadataCode += `{
126- type: 'layout',
127- layer: ${ segments . length } ,
128- mod: () => import(/* webpackMode: "eager" */ ${ JSON . stringify (
129- layoutPath
130- ) } ),
131- path: ${ JSON . stringify ( layoutPath ) } ,
132- },`
133- }
134- metadataCode += await resolveFileBasedMetadataForLoader (
135- segments . length ,
136- ( await resolve ( `${ appDirPrefix } ${ parallelSegmentPath } /` , true ) ) !
137- )
138- metadataCode += subTreeMetadataCode
139-
140- if ( ! rootLayout ) {
141- rootLayout = layoutPath
142- }
143-
144104 if ( ! globalError ) {
145105 globalError = await resolve (
146106 `${ appDirPrefix } ${ parallelSegmentPath } /${ GLOBAL_ERROR_FILE_TYPE } `
@@ -173,16 +133,13 @@ async function createTreeCodeFromPath({
173133 . map ( ( [ key , value ] ) => `${ key } : ${ value } ` )
174134 . join ( ',\n' ) }
175135 }` ,
176- treeMetadataCode : metadataCode ,
177136 }
178137 }
179138
180- const { treeCode, treeMetadataCode } =
181- await createSubtreePropsFromSegmentPath ( [ ] )
139+ const { treeCode } = await createSubtreePropsFromSegmentPath ( [ ] )
182140 return {
183141 treeCode : `const tree = ${ treeCode } .children;` ,
184- treeMetadataCode : `const metadata = [${ treeMetadataCode } ];` ,
185- pages : `const pages = ${ JSON . stringify ( pages ) } ;` ,
142+ pages,
186143 rootLayout,
187144 globalError,
188145 }
@@ -240,7 +197,7 @@ const nextAppLoader: webpack.LoaderDefinitionFunction<{
240197 const rest = path . slice ( pathname . length + 1 ) . split ( '/' )
241198
242199 let matchedSegment = rest [ 0 ]
243- // It is the actual page, mark it specially .
200+ // It is the actual page, mark it sepcially .
244201 if ( rest . length === 1 && matchedSegment === 'page' ) {
245202 matchedSegment = PAGE_SEGMENT
246203 }
@@ -255,11 +212,7 @@ const nextAppLoader: webpack.LoaderDefinitionFunction<{
255212 return Object . entries ( matched )
256213 }
257214
258- const resolver = async ( pathname : string , resolveDir ?: boolean ) => {
259- if ( resolveDir ) {
260- return createAbsolutePath ( appDir , pathname )
261- }
262-
215+ const resolver = async ( pathname : string ) => {
263216 try {
264217 const resolved = await resolve ( this . rootContext , pathname )
265218 this . addDependency ( resolved )
@@ -277,17 +230,12 @@ const nextAppLoader: webpack.LoaderDefinitionFunction<{
277230 }
278231 }
279232
280- const {
281- treeCode,
282- treeMetadataCode,
283- pages : pageListCode ,
284- rootLayout,
285- globalError,
286- } = await createTreeCodeFromPath ( {
287- pagePath,
288- resolve : resolver ,
289- resolveParallelSegments,
290- } )
233+ const { treeCode, pages, rootLayout, globalError } =
234+ await createTreeCodeFromPath ( {
235+ pagePath,
236+ resolve : resolver ,
237+ resolveParallelSegments,
238+ } )
291239
292240 if ( ! rootLayout ) {
293241 const errorMessage = `${ chalk . bold (
@@ -315,8 +263,7 @@ const nextAppLoader: webpack.LoaderDefinitionFunction<{
315263
316264 const result = `
317265 export ${ treeCode }
318- export ${ treeMetadataCode }
319- export ${ pageListCode }
266+ export const pages = ${ JSON . stringify ( pages ) }
320267
321268 export { default as AppRouter } from 'next/dist/client/components/app-router'
322269 export { default as LayoutRouter } from 'next/dist/client/components/layout-router'
0 commit comments