@@ -1823,6 +1823,177 @@ export default async function build(
18231823 traceMemoryUsage ( 'Finished type checking' , nextBuildSpan )
18241824 }
18251825
1826+ const requiredServerFilesManifest = await nextBuildSpan
1827+ . traceChild ( 'generate-required-server-files' )
1828+ . traceAsyncFn ( async ( ) => {
1829+ const normalizedCacheHandlers : Record < string , string > = { }
1830+
1831+ for ( const [ key , value ] of Object . entries (
1832+ config . cacheHandlers || { }
1833+ ) ) {
1834+ if ( key && value ) {
1835+ normalizedCacheHandlers [ key ] = path . relative ( distDir , value )
1836+ }
1837+ }
1838+
1839+ const serverFilesManifest : RequiredServerFilesManifest = {
1840+ version : 1 ,
1841+ config : {
1842+ ...config ,
1843+ configFile : undefined ,
1844+ ...( ciEnvironment . hasNextSupport
1845+ ? {
1846+ compress : false ,
1847+ }
1848+ : { } ) ,
1849+ cacheHandler : config . cacheHandler
1850+ ? path . relative ( distDir , config . cacheHandler )
1851+ : config . cacheHandler ,
1852+ cacheHandlers : normalizedCacheHandlers ,
1853+ experimental : {
1854+ ...config . experimental ,
1855+ trustHostHeader : ciEnvironment . hasNextSupport ,
1856+ isExperimentalCompile : isCompileMode ,
1857+ } ,
1858+ } ,
1859+ appDir : dir ,
1860+ relativeAppDir : path . relative ( outputFileTracingRoot , dir ) ,
1861+ files : [
1862+ ROUTES_MANIFEST ,
1863+ path . relative ( distDir , pagesManifestPath ) ,
1864+ BUILD_MANIFEST ,
1865+ PRERENDER_MANIFEST ,
1866+ path . join ( SERVER_DIRECTORY , FUNCTIONS_CONFIG_MANIFEST ) ,
1867+ path . join ( SERVER_DIRECTORY , MIDDLEWARE_MANIFEST ) ,
1868+ path . join ( SERVER_DIRECTORY , MIDDLEWARE_BUILD_MANIFEST + '.js' ) ,
1869+ ...( bundler !== Bundler . Turbopack
1870+ ? [
1871+ path . join (
1872+ SERVER_DIRECTORY ,
1873+ MIDDLEWARE_REACT_LOADABLE_MANIFEST + '.js'
1874+ ) ,
1875+ REACT_LOADABLE_MANIFEST ,
1876+ ]
1877+ : [ ] ) ,
1878+ ...( appDir
1879+ ? [
1880+ ...( config . experimental . sri
1881+ ? [
1882+ path . join (
1883+ SERVER_DIRECTORY ,
1884+ SUBRESOURCE_INTEGRITY_MANIFEST + '.js'
1885+ ) ,
1886+ path . join (
1887+ SERVER_DIRECTORY ,
1888+ SUBRESOURCE_INTEGRITY_MANIFEST + '.json'
1889+ ) ,
1890+ ]
1891+ : [ ] ) ,
1892+ path . join ( SERVER_DIRECTORY , APP_PATHS_MANIFEST ) ,
1893+ path . join ( APP_PATH_ROUTES_MANIFEST ) ,
1894+ path . join (
1895+ SERVER_DIRECTORY ,
1896+ SERVER_REFERENCE_MANIFEST + '.js'
1897+ ) ,
1898+ path . join (
1899+ SERVER_DIRECTORY ,
1900+ SERVER_REFERENCE_MANIFEST + '.json'
1901+ ) ,
1902+ ]
1903+ : [ ] ) ,
1904+ ...( pagesDir && bundler !== Bundler . Turbopack
1905+ ? [
1906+ DYNAMIC_CSS_MANIFEST + '.json' ,
1907+ path . join ( SERVER_DIRECTORY , DYNAMIC_CSS_MANIFEST + '.js' ) ,
1908+ ]
1909+ : [ ] ) ,
1910+ BUILD_ID_FILE ,
1911+ path . join ( SERVER_DIRECTORY , NEXT_FONT_MANIFEST + '.js' ) ,
1912+ path . join ( SERVER_DIRECTORY , NEXT_FONT_MANIFEST + '.json' ) ,
1913+ path . join ( SERVER_FILES_MANIFEST + '.js' ) ,
1914+ path . join ( SERVER_FILES_MANIFEST + '.json' ) ,
1915+ ]
1916+ . filter ( nonNullable )
1917+ . map ( ( file ) => path . join ( config . distDir , file ) ) ,
1918+ ignore : [ ] as string [ ] ,
1919+ }
1920+
1921+ if ( hasInstrumentationHook ) {
1922+ serverFilesManifest . files . push (
1923+ path . join ( SERVER_DIRECTORY , `${ INSTRUMENTATION_HOOK_FILENAME } .js` )
1924+ )
1925+ // If there are edge routes, append the edge instrumentation hook
1926+ // Turbopack generates this chunk with a hashed name and references it in middleware-manifest.
1927+ let edgeInstrumentationHook = path . join (
1928+ SERVER_DIRECTORY ,
1929+ `edge-${ INSTRUMENTATION_HOOK_FILENAME } .js`
1930+ )
1931+ if (
1932+ bundler !== Bundler . Turbopack &&
1933+ existsSync ( path . join ( distDir , edgeInstrumentationHook ) )
1934+ ) {
1935+ serverFilesManifest . files . push ( edgeInstrumentationHook )
1936+ }
1937+ }
1938+
1939+ if ( config . experimental . optimizeCss ) {
1940+ const globOrig =
1941+ require ( 'next/dist/compiled/glob' ) as typeof import ( 'next/dist/compiled/glob' )
1942+
1943+ const cssFilePaths = await new Promise < string [ ] > (
1944+ ( resolve , reject ) => {
1945+ globOrig (
1946+ '**/*.css' ,
1947+ { cwd : path . join ( distDir , 'static' ) } ,
1948+ ( err , files ) => {
1949+ if ( err ) {
1950+ return reject ( err )
1951+ }
1952+ resolve ( files )
1953+ }
1954+ )
1955+ }
1956+ )
1957+
1958+ serverFilesManifest . files . push (
1959+ ...cssFilePaths . map ( ( filePath ) =>
1960+ path . join ( config . distDir , 'static' , filePath )
1961+ )
1962+ )
1963+ }
1964+
1965+ // Under standalone mode, we need to ensure that the cache entry debug
1966+ // handler is copied so that it can be used in the test. This is required
1967+ // for the turbopack test to run as it's more strict about the build
1968+ // directories. This is only used for testing and is not used in
1969+ // production.
1970+ if (
1971+ process . env . __NEXT_TEST_MODE &&
1972+ process . env . NEXT_PRIVATE_DEBUG_CACHE_ENTRY_HANDLERS
1973+ ) {
1974+ serverFilesManifest . files . push (
1975+ path . relative (
1976+ dir ,
1977+ path . isAbsolute (
1978+ process . env . NEXT_PRIVATE_DEBUG_CACHE_ENTRY_HANDLERS
1979+ )
1980+ ? process . env . NEXT_PRIVATE_DEBUG_CACHE_ENTRY_HANDLERS
1981+ : path . join (
1982+ dir ,
1983+ process . env . NEXT_PRIVATE_DEBUG_CACHE_ENTRY_HANDLERS
1984+ )
1985+ )
1986+ )
1987+ }
1988+
1989+ return serverFilesManifest
1990+ } )
1991+
1992+ await writeRequiredServerFilesManifest (
1993+ distDir ,
1994+ requiredServerFilesManifest
1995+ )
1996+
18261997 const numberOfWorkers = getNumberOfWorkers ( config )
18271998 const collectingPageDataStart = process . hrtime ( )
18281999 const postCompileSpinner = createSpinner (
@@ -2412,126 +2583,6 @@ export default async function build(
24122583 )
24132584 }
24142585
2415- const { cacheHandler } = config
2416-
2417- const instrumentationHookEntryFiles : string [ ] = [ ]
2418- if ( hasInstrumentationHook ) {
2419- instrumentationHookEntryFiles . push (
2420- path . join ( SERVER_DIRECTORY , `${ INSTRUMENTATION_HOOK_FILENAME } .js` )
2421- )
2422- // If there's edge routes, append the edge instrumentation hook
2423- // Turbopack generates this chunk with a hashed name and references it in middleware-manifest.
2424- if (
2425- bundler !== Bundler . Turbopack &&
2426- ( edgeRuntimeAppCount || edgeRuntimePagesCount )
2427- ) {
2428- instrumentationHookEntryFiles . push (
2429- path . join (
2430- SERVER_DIRECTORY ,
2431- `edge-${ INSTRUMENTATION_HOOK_FILENAME } .js`
2432- )
2433- )
2434- }
2435- }
2436-
2437- const requiredServerFilesManifest = nextBuildSpan
2438- . traceChild ( 'generate-required-server-files' )
2439- . traceFn ( ( ) => {
2440- const normalizedCacheHandlers : Record < string , string > = { }
2441-
2442- for ( const [ key , value ] of Object . entries (
2443- config . cacheHandlers || { }
2444- ) ) {
2445- if ( key && value ) {
2446- normalizedCacheHandlers [ key ] = path . relative ( distDir , value )
2447- }
2448- }
2449-
2450- const serverFilesManifest : RequiredServerFilesManifest = {
2451- version : 1 ,
2452- config : {
2453- ...config ,
2454- configFile : undefined ,
2455- ...( ciEnvironment . hasNextSupport
2456- ? {
2457- compress : false ,
2458- }
2459- : { } ) ,
2460- cacheHandler : cacheHandler
2461- ? path . relative ( distDir , cacheHandler )
2462- : config . cacheHandler ,
2463- cacheHandlers : normalizedCacheHandlers ,
2464- experimental : {
2465- ...config . experimental ,
2466- trustHostHeader : ciEnvironment . hasNextSupport ,
2467- isExperimentalCompile : isCompileMode ,
2468- } ,
2469- } ,
2470- appDir : dir ,
2471- relativeAppDir : path . relative ( outputFileTracingRoot , dir ) ,
2472- files : [
2473- ROUTES_MANIFEST ,
2474- path . relative ( distDir , pagesManifestPath ) ,
2475- BUILD_MANIFEST ,
2476- PRERENDER_MANIFEST ,
2477- path . join ( SERVER_DIRECTORY , FUNCTIONS_CONFIG_MANIFEST ) ,
2478- path . join ( SERVER_DIRECTORY , MIDDLEWARE_MANIFEST ) ,
2479- path . join ( SERVER_DIRECTORY , MIDDLEWARE_BUILD_MANIFEST + '.js' ) ,
2480- ...( bundler !== Bundler . Turbopack
2481- ? [
2482- path . join (
2483- SERVER_DIRECTORY ,
2484- MIDDLEWARE_REACT_LOADABLE_MANIFEST + '.js'
2485- ) ,
2486- REACT_LOADABLE_MANIFEST ,
2487- ]
2488- : [ ] ) ,
2489- ...( appDir
2490- ? [
2491- ...( config . experimental . sri
2492- ? [
2493- path . join (
2494- SERVER_DIRECTORY ,
2495- SUBRESOURCE_INTEGRITY_MANIFEST + '.js'
2496- ) ,
2497- path . join (
2498- SERVER_DIRECTORY ,
2499- SUBRESOURCE_INTEGRITY_MANIFEST + '.json'
2500- ) ,
2501- ]
2502- : [ ] ) ,
2503- path . join ( SERVER_DIRECTORY , APP_PATHS_MANIFEST ) ,
2504- path . join ( APP_PATH_ROUTES_MANIFEST ) ,
2505- path . join (
2506- SERVER_DIRECTORY ,
2507- SERVER_REFERENCE_MANIFEST + '.js'
2508- ) ,
2509- path . join (
2510- SERVER_DIRECTORY ,
2511- SERVER_REFERENCE_MANIFEST + '.json'
2512- ) ,
2513- ]
2514- : [ ] ) ,
2515- ...( pagesDir && bundler !== Bundler . Turbopack
2516- ? [
2517- DYNAMIC_CSS_MANIFEST + '.json' ,
2518- path . join ( SERVER_DIRECTORY , DYNAMIC_CSS_MANIFEST + '.js' ) ,
2519- ]
2520- : [ ] ) ,
2521- BUILD_ID_FILE ,
2522- path . join ( SERVER_DIRECTORY , NEXT_FONT_MANIFEST + '.js' ) ,
2523- path . join ( SERVER_DIRECTORY , NEXT_FONT_MANIFEST + '.json' ) ,
2524- SERVER_FILES_MANIFEST ,
2525- ...instrumentationHookEntryFiles ,
2526- ]
2527- . filter ( nonNullable )
2528- . map ( ( file ) => path . join ( config . distDir , file ) ) ,
2529- ignore : [ ] as string [ ] ,
2530- }
2531-
2532- return serverFilesManifest
2533- } )
2534-
25352586 const middlewareFile = normalizePathSep (
25362587 proxyFilePath || middlewareFilePath || ''
25372588 )
@@ -2646,52 +2697,6 @@ export default async function build(
26462697
26472698 await writeBuildId ( distDir , buildId )
26482699
2649- if ( config . experimental . optimizeCss ) {
2650- const globOrig =
2651- require ( 'next/dist/compiled/glob' ) as typeof import ( 'next/dist/compiled/glob' )
2652-
2653- const cssFilePaths = await new Promise < string [ ] > ( ( resolve , reject ) => {
2654- globOrig (
2655- '**/*.css' ,
2656- { cwd : path . join ( distDir , 'static' ) } ,
2657- ( err , files ) => {
2658- if ( err ) {
2659- return reject ( err )
2660- }
2661- resolve ( files )
2662- }
2663- )
2664- } )
2665-
2666- requiredServerFilesManifest . files . push (
2667- ...cssFilePaths . map ( ( filePath ) =>
2668- path . join ( config . distDir , 'static' , filePath )
2669- )
2670- )
2671- }
2672-
2673- // Under standalone mode, we need to ensure that the cache entry debug
2674- // handler is copied so that it can be used in the test. This is required
2675- // for the turbopack test to run as it's more strict about the build
2676- // directories. This is only used for testing and is not used in
2677- // production.
2678- if (
2679- process . env . __NEXT_TEST_MODE &&
2680- process . env . NEXT_PRIVATE_DEBUG_CACHE_ENTRY_HANDLERS
2681- ) {
2682- requiredServerFilesManifest . files . push (
2683- path . relative (
2684- dir ,
2685- path . isAbsolute ( process . env . NEXT_PRIVATE_DEBUG_CACHE_ENTRY_HANDLERS )
2686- ? process . env . NEXT_PRIVATE_DEBUG_CACHE_ENTRY_HANDLERS
2687- : path . join (
2688- dir ,
2689- process . env . NEXT_PRIVATE_DEBUG_CACHE_ENTRY_HANDLERS
2690- )
2691- )
2692- )
2693- }
2694-
26952700 const features : EventBuildFeatureUsage [ ] = [
26962701 {
26972702 featureName : 'experimental/cacheComponents' ,
@@ -2727,11 +2732,6 @@ export default async function build(
27272732 } )
27282733 )
27292734
2730- await writeRequiredServerFilesManifest (
2731- distDir ,
2732- requiredServerFilesManifest
2733- )
2734-
27352735 // we don't need to inline for turbopack build as
27362736 // it will handle it's own caching separate of compile
27372737 if ( isGenerateMode && bundler !== Bundler . Turbopack ) {
0 commit comments