@@ -1823,6 +1823,176 @@ 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+ SERVER_FILES_MANIFEST ,
1914+ ]
1915+ . filter ( nonNullable )
1916+ . map ( ( file ) => path . join ( config . distDir , file ) ) ,
1917+ ignore : [ ] as string [ ] ,
1918+ }
1919+
1920+ if ( hasInstrumentationHook ) {
1921+ serverFilesManifest . files . push (
1922+ path . join ( SERVER_DIRECTORY , `${ INSTRUMENTATION_HOOK_FILENAME } .js` )
1923+ )
1924+ // If there are edge routes, append the edge instrumentation hook
1925+ // Turbopack generates this chunk with a hashed name and references it in middleware-manifest.
1926+ let edgeInstrumentationHook = path . join (
1927+ SERVER_DIRECTORY ,
1928+ `edge-${ INSTRUMENTATION_HOOK_FILENAME } .js`
1929+ )
1930+ if (
1931+ bundler !== Bundler . Turbopack &&
1932+ existsSync ( path . join ( distDir , edgeInstrumentationHook ) )
1933+ ) {
1934+ serverFilesManifest . files . push ( edgeInstrumentationHook )
1935+ }
1936+ }
1937+
1938+ if ( config . experimental . optimizeCss ) {
1939+ const globOrig =
1940+ require ( 'next/dist/compiled/glob' ) as typeof import ( 'next/dist/compiled/glob' )
1941+
1942+ const cssFilePaths = await new Promise < string [ ] > (
1943+ ( resolve , reject ) => {
1944+ globOrig (
1945+ '**/*.css' ,
1946+ { cwd : path . join ( distDir , 'static' ) } ,
1947+ ( err , files ) => {
1948+ if ( err ) {
1949+ return reject ( err )
1950+ }
1951+ resolve ( files )
1952+ }
1953+ )
1954+ }
1955+ )
1956+
1957+ serverFilesManifest . files . push (
1958+ ...cssFilePaths . map ( ( filePath ) =>
1959+ path . join ( config . distDir , 'static' , filePath )
1960+ )
1961+ )
1962+ }
1963+
1964+ // Under standalone mode, we need to ensure that the cache entry debug
1965+ // handler is copied so that it can be used in the test. This is required
1966+ // for the turbopack test to run as it's more strict about the build
1967+ // directories. This is only used for testing and is not used in
1968+ // production.
1969+ if (
1970+ process . env . __NEXT_TEST_MODE &&
1971+ process . env . NEXT_PRIVATE_DEBUG_CACHE_ENTRY_HANDLERS
1972+ ) {
1973+ serverFilesManifest . files . push (
1974+ path . relative (
1975+ dir ,
1976+ path . isAbsolute (
1977+ process . env . NEXT_PRIVATE_DEBUG_CACHE_ENTRY_HANDLERS
1978+ )
1979+ ? process . env . NEXT_PRIVATE_DEBUG_CACHE_ENTRY_HANDLERS
1980+ : path . join (
1981+ dir ,
1982+ process . env . NEXT_PRIVATE_DEBUG_CACHE_ENTRY_HANDLERS
1983+ )
1984+ )
1985+ )
1986+ }
1987+
1988+ return serverFilesManifest
1989+ } )
1990+
1991+ await writeRequiredServerFilesManifest (
1992+ distDir ,
1993+ requiredServerFilesManifest
1994+ )
1995+
18261996 const numberOfWorkers = getNumberOfWorkers ( config )
18271997 const collectingPageDataStart = process . hrtime ( )
18281998 const postCompileSpinner = createSpinner (
@@ -2412,126 +2582,6 @@ export default async function build(
24122582 )
24132583 }
24142584
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-
25352585 const middlewareFile = normalizePathSep (
25362586 proxyFilePath || middlewareFilePath || ''
25372587 )
@@ -2646,52 +2696,6 @@ export default async function build(
26462696
26472697 await writeBuildId ( distDir , buildId )
26482698
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-
26952699 const features : EventBuildFeatureUsage [ ] = [
26962700 {
26972701 featureName : 'experimental/cacheComponents' ,
@@ -2727,11 +2731,6 @@ export default async function build(
27272731 } )
27282732 )
27292733
2730- await writeRequiredServerFilesManifest (
2731- distDir ,
2732- requiredServerFilesManifest
2733- )
2734-
27352734 // we don't need to inline for turbopack build as
27362735 // it will handle it's own caching separate of compile
27372736 if ( isGenerateMode && bundler !== Bundler . Turbopack ) {
0 commit comments