Skip to content

Commit 4c6e8d4

Browse files
authored
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: #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)
1 parent c533613 commit 4c6e8d4

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

packages/next/src/build/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,9 @@ export default async function build(
896896
)
897897
)
898898

899+
const outputFileTracingRoot =
900+
config.experimental.outputFileTracingRoot || dir
901+
899902
const manifestPath = path.join(distDir, SERVER_DIRECTORY, PAGES_MANIFEST)
900903

901904
const requiredServerFiles = nextBuildSpan
@@ -923,6 +926,7 @@ export default async function build(
923926
},
924927
},
925928
appDir: dir,
929+
relativeAppDir: path.relative(outputFileTracingRoot, dir),
926930
files: [
927931
ROUTES_MANIFEST,
928932
path.relative(distDir, manifestPath),
@@ -1926,8 +1930,8 @@ export default async function build(
19261930

19271931
const root =
19281932
config.experimental?.turbotrace?.contextDirectory ??
1929-
config.experimental?.outputFileTracingRoot ??
1930-
dir
1933+
outputFileTracingRoot
1934+
19311935
const nextServerEntry = require.resolve(
19321936
'next/dist/server/next-server'
19331937
)
@@ -2172,9 +2176,6 @@ export default async function build(
21722176
)
21732177
)
21742178

2175-
const outputFileTracingRoot =
2176-
config.experimental.outputFileTracingRoot || dir
2177-
21782179
if (config.output === 'standalone') {
21792180
await nextBuildSpan
21802181
.traceChild('copy-traced-files')

test/production/standalone-mode/required-server-files/required-server-files.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ describe('should set-up next', () => {
321321
expect(typeof requiredFilesManifest.config.configFile).toBe('undefined')
322322
expect(typeof requiredFilesManifest.config.trailingSlash).toBe('boolean')
323323
expect(typeof requiredFilesManifest.appDir).toBe('string')
324+
// not in a monorepo so relative app dir is empty string
325+
expect(requiredFilesManifest.relativeAppDir).toBe('')
324326
})
325327

326328
it('should de-dupe HTML/data requests', async () => {

0 commit comments

Comments
 (0)