From 4c6e8d480c10879c65b0ce0b10abfb44c8436c79 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Fri, 24 Feb 2023 16:51:07 -0800 Subject: [PATCH] Add relative app dir field (#46393) This adds a relative app dir field to the required files manifest so that we don't rely on absolute paths from a cached build since the cache can be restored in a separate context where the value no longer applies. x-ref: https://github.com/vercel/next.js/pull/45864 ## Bug - [ ] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) --- packages/next/src/build/index.ts | 11 ++++++----- .../required-server-files.test.ts | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/next/src/build/index.ts b/packages/next/src/build/index.ts index 7b38541d7ca9c..5e6c245026d04 100644 --- a/packages/next/src/build/index.ts +++ b/packages/next/src/build/index.ts @@ -896,6 +896,9 @@ export default async function build( ) ) + const outputFileTracingRoot = + config.experimental.outputFileTracingRoot || dir + const manifestPath = path.join(distDir, SERVER_DIRECTORY, PAGES_MANIFEST) const requiredServerFiles = nextBuildSpan @@ -923,6 +926,7 @@ export default async function build( }, }, appDir: dir, + relativeAppDir: path.relative(outputFileTracingRoot, dir), files: [ ROUTES_MANIFEST, path.relative(distDir, manifestPath), @@ -1926,8 +1930,8 @@ export default async function build( const root = config.experimental?.turbotrace?.contextDirectory ?? - config.experimental?.outputFileTracingRoot ?? - dir + outputFileTracingRoot + const nextServerEntry = require.resolve( 'next/dist/server/next-server' ) @@ -2172,9 +2176,6 @@ export default async function build( ) ) - const outputFileTracingRoot = - config.experimental.outputFileTracingRoot || dir - if (config.output === 'standalone') { await nextBuildSpan .traceChild('copy-traced-files') diff --git a/test/production/standalone-mode/required-server-files/required-server-files.test.ts b/test/production/standalone-mode/required-server-files/required-server-files.test.ts index 2168708023d6d..4c91078c04b5c 100644 --- a/test/production/standalone-mode/required-server-files/required-server-files.test.ts +++ b/test/production/standalone-mode/required-server-files/required-server-files.test.ts @@ -321,6 +321,8 @@ describe('should set-up next', () => { expect(typeof requiredFilesManifest.config.configFile).toBe('undefined') expect(typeof requiredFilesManifest.config.trailingSlash).toBe('boolean') expect(typeof requiredFilesManifest.appDir).toBe('string') + // not in a monorepo so relative app dir is empty string + expect(requiredFilesManifest.relativeAppDir).toBe('') }) it('should de-dupe HTML/data requests', async () => {