Unverified Commit 4c6e8d48 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

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)
parent c5336132
...@@ -896,6 +896,9 @@ export default async function build( ...@@ -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 manifestPath = path.join(distDir, SERVER_DIRECTORY, PAGES_MANIFEST)
const requiredServerFiles = nextBuildSpan const requiredServerFiles = nextBuildSpan
...@@ -923,6 +926,7 @@ export default async function build( ...@@ -923,6 +926,7 @@ export default async function build(
}, },
}, },
appDir: dir, appDir: dir,
relativeAppDir: path.relative(outputFileTracingRoot, dir),
files: [ files: [
ROUTES_MANIFEST, ROUTES_MANIFEST,
path.relative(distDir, manifestPath), path.relative(distDir, manifestPath),
...@@ -1926,8 +1930,8 @@ export default async function build( ...@@ -1926,8 +1930,8 @@ export default async function build(
const root = const root =
config.experimental?.turbotrace?.contextDirectory ?? config.experimental?.turbotrace?.contextDirectory ??
config.experimental?.outputFileTracingRoot ?? outputFileTracingRoot
dir
const nextServerEntry = require.resolve( const nextServerEntry = require.resolve(
'next/dist/server/next-server' 'next/dist/server/next-server'
) )
...@@ -2172,9 +2176,6 @@ export default async function build( ...@@ -2172,9 +2176,6 @@ export default async function build(
) )
) )
const outputFileTracingRoot =
config.experimental.outputFileTracingRoot || dir
if (config.output === 'standalone') { if (config.output === 'standalone') {
await nextBuildSpan await nextBuildSpan
.traceChild('copy-traced-files') .traceChild('copy-traced-files')
......
...@@ -321,6 +321,8 @@ describe('should set-up next', () => { ...@@ -321,6 +321,8 @@ describe('should set-up next', () => {
expect(typeof requiredFilesManifest.config.configFile).toBe('undefined') expect(typeof requiredFilesManifest.config.configFile).toBe('undefined')
expect(typeof requiredFilesManifest.config.trailingSlash).toBe('boolean') expect(typeof requiredFilesManifest.config.trailingSlash).toBe('boolean')
expect(typeof requiredFilesManifest.appDir).toBe('string') 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 () => { it('should de-dupe HTML/data requests', async () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment