From 2a7f5cdb0a81a04ef2cb7cb447d7fa8a4d84d9ac Mon Sep 17 00:00:00 2001 From: Jimmy Lai Date: Tue, 12 Sep 2023 15:15:43 +0200 Subject: [PATCH] build: fix minimal trace caching (#55279) This PR fixes a small issue where we would not save nor read the minimal server trace file from the cache, meaning that whenever you would do two builds in a row, the build would skip the tracing of the server as expected but not include a minimal server trace in the dist folder. --- packages/next/src/build/index.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/next/src/build/index.ts b/packages/next/src/build/index.ts index 8d92c8ae5587..16944bde6fc1 100644 --- a/packages/next/src/build/index.ts +++ b/packages/next/src/build/index.ts @@ -2045,6 +2045,10 @@ export default async function build( distDir, 'cache/next-server.js.nft.json' ) + const minimalCachedTracePath = path.join( + distDir, + 'cache/next-minimal-server.js.nft.json' + ) if ( lockFiles.length > 0 && @@ -2072,9 +2076,19 @@ export default async function build( const existingTrace = JSON.parse( await fs.readFile(cachedTracePath, 'utf8') ) + const existingMinimalTrace = JSON.parse( + await fs.readFile(minimalCachedTracePath, 'utf8') + ) - if (existingTrace.cacheKey === cacheKey) { + if ( + existingTrace.cacheKey === cacheKey && + existingMinimalTrace.cacheKey === cacheKey + ) { await fs.copyFile(cachedTracePath, nextServerTraceOutput) + await fs.copyFile( + minimalCachedTracePath, + nextMinimalTraceOutput + ) return } } catch {} @@ -2301,9 +2315,13 @@ export default async function build( ]) await fs.unlink(cachedTracePath).catch(() => {}) + await fs.unlink(minimalCachedTracePath).catch(() => {}) await fs .copyFile(nextServerTraceOutput, cachedTracePath) .catch(() => {}) + await fs + .copyFile(nextMinimalTraceOutput, minimalCachedTracePath) + .catch(() => {}) }) }