Skip to content

Commit

Permalink
Ensure next-server tracing uses tracing root config (#37888)
Browse files Browse the repository at this point in the history
As noticed in #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`
  • Loading branch information
ijjk committed Jun 21, 2022
1 parent ff55e4a commit e8a1320
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ export default async function build(
} catch (_) {}
}

const root = path.parse(dir).root
const root = config.experimental.outputFileTracingRoot || dir
const toTrace = [require.resolve('next/dist/server/next-server')]

// ensure we trace any dependencies needed for custom
Expand All @@ -1454,6 +1454,7 @@ export default async function build(
require.resolve(config.experimental.incrementalCacheHandlerPath)
)
}

const serverResult = await nodeFileTrace(toTrace, {
base: root,
processCwd: dir,
Expand Down
15 changes: 15 additions & 0 deletions test/integration/production/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,21 @@ describe('Production Usage', () => {
file.includes('next/dist/server/send-payload/index.js')
)
).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(
serverTrace.files.some((file) =>
file.includes('next/dist/shared/lib/page-path/normalize-page-path.js')
Expand Down

0 comments on commit e8a1320

Please sign in to comment.