Unverified Commit e8a1320e authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure next-server tracing uses tracing root config (#37888)

As noticed in https://github.com/vercel/next.js/pull/37596 it seems we aren't locking the `next-server` tracing to the tracing root which can allow files outside of the folder to be included unexpectedly.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
parent ff55e4a7
...@@ -1444,7 +1444,7 @@ export default async function build( ...@@ -1444,7 +1444,7 @@ export default async function build(
} catch (_) {} } catch (_) {}
} }
const root = path.parse(dir).root const root = config.experimental.outputFileTracingRoot || dir
const toTrace = [require.resolve('next/dist/server/next-server')] const toTrace = [require.resolve('next/dist/server/next-server')]
// ensure we trace any dependencies needed for custom // ensure we trace any dependencies needed for custom
...@@ -1454,6 +1454,7 @@ export default async function build( ...@@ -1454,6 +1454,7 @@ export default async function build(
require.resolve(config.experimental.incrementalCacheHandlerPath) require.resolve(config.experimental.incrementalCacheHandlerPath)
) )
} }
const serverResult = await nodeFileTrace(toTrace, { const serverResult = await nodeFileTrace(toTrace, {
base: root, base: root,
processCwd: dir, processCwd: dir,
......
...@@ -103,6 +103,21 @@ describe('Production Usage', () => { ...@@ -103,6 +103,21 @@ describe('Production Usage', () => {
file.includes('next/dist/server/send-payload/index.js') file.includes('next/dist/server/send-payload/index.js')
) )
).toBe(true) ).toBe(true)
const repoRoot = join(__dirname, '../../../../')
expect(
serverTrace.files.some((file) => {
const fullPath = join(__dirname, '../.next', file)
if (!fullPath.startsWith(repoRoot)) {
console.error(`Found next-server trace file outside repo root`, {
repoRoot,
fullPath,
file,
})
return true
}
return false
})
).toBe(false)
expect( expect(
serverTrace.files.some((file) => serverTrace.files.some((file) =>
file.includes('next/dist/shared/lib/page-path/normalize-page-path.js') file.includes('next/dist/shared/lib/page-path/normalize-page-path.js')
......
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