Skip to content

Commit

Permalink
Add relative app dir field (#46393)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
ijjk authored Feb 25, 2023
1 parent c533613 commit 4c6e8d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -923,6 +926,7 @@ export default async function build(
},
},
appDir: dir,
relativeAppDir: path.relative(outputFileTracingRoot, dir),
files: [
ROUTES_MANIFEST,
path.relative(distDir, manifestPath),
Expand Down Expand Up @@ -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'
)
Expand Down Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 4c6e8d4

Please sign in to comment.