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

Ensure build trace ignores apply correctly when nested (#42606)

x-ref: [slack
thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1667821787658109?thread_ts=1667480066.387989&cid=C03S8ED1DKM)

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`
parent 2e3e56d9
...@@ -1809,28 +1809,30 @@ export default async function build( ...@@ -1809,28 +1809,30 @@ export default async function build(
showAll: config.experimental.turbotrace.logAll, showAll: config.experimental.turbotrace.logAll,
}) })
} else { } else {
const ignores = [
'**/next/dist/pages/**/*',
'**/next/dist/compiled/webpack/(bundle4|bundle5).js',
'**/node_modules/webpack5/**/*',
'**/next/dist/server/lib/squoosh/**/*.wasm',
...(ciEnvironment.hasNextSupport
? [
// only ignore image-optimizer code when
// this is being handled outside of next-server
'**/next/dist/server/image-optimizer.js',
'**/node_modules/sharp/**/*',
]
: []),
...(!hasSsrAmpPages
? ['**/next/dist/compiled/@ampproject/toolbox-optimizer/**/*']
: []),
]
const ignoreFn = (pathname: string) => {
return isMatch(pathname, ignores, { contains: true, dot: true })
}
serverResult = await nodeFileTrace(toTrace, { serverResult = await nodeFileTrace(toTrace, {
base: root, base: root,
processCwd: dir, processCwd: dir,
ignore: [ ignore: ignoreFn,
'**/next/dist/pages/**/*',
'**/next/dist/compiled/webpack/(bundle4|bundle5).js',
'**/node_modules/webpack5/**/*',
'**/next/dist/server/lib/squoosh/**/*.wasm',
...(ciEnvironment.hasNextSupport
? [
// only ignore image-optimizer code when
// this is being handled outside of next-server
'**/next/dist/server/image-optimizer.js',
'**/node_modules/sharp/**/*',
]
: []),
...(!hasSsrAmpPages
? [
'**/next/dist/compiled/@ampproject/toolbox-optimizer/**/*',
]
: []),
],
}) })
const tracedFiles = new Set() const tracedFiles = new Set()
......
...@@ -16,6 +16,7 @@ import { ...@@ -16,6 +16,7 @@ import {
} from '../../webpack-config' } from '../../webpack-config'
import { NextConfigComplete } from '../../../server/config-shared' import { NextConfigComplete } from '../../../server/config-shared'
import { loadBindings } from '../../swc' import { loadBindings } from '../../swc'
import { isMatch } from 'next/dist/compiled/micromatch'
const PLUGIN_NAME = 'TraceEntryPointsPlugin' const PLUGIN_NAME = 'TraceEntryPointsPlugin'
const TRACE_IGNORES = [ const TRACE_IGNORES = [
...@@ -173,7 +174,11 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance { ...@@ -173,7 +174,11 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance {
return return
} }
} }
const ignores = [...TRACE_IGNORES, ...this.excludeFiles]
const ignoreFn = (path: string) => {
return isMatch(path, ignores, { contains: true, dot: true })
}
const result = await nodeFileTrace([...chunksToTrace], { const result = await nodeFileTrace([...chunksToTrace], {
base: this.tracingRoot, base: this.tracingRoot,
processCwd: this.appDir, processCwd: this.appDir,
...@@ -204,7 +209,7 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance { ...@@ -204,7 +209,7 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance {
}, },
readlink, readlink,
stat, stat,
ignore: [...TRACE_IGNORES, ...this.excludeFiles], ignore: ignoreFn,
mixedModules: true, mixedModules: true,
}) })
const reasons = result.reasons const reasons = result.reasons
...@@ -456,6 +461,15 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance { ...@@ -456,6 +461,15 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance {
} }
let fileList: Set<string> let fileList: Set<string>
let reasons: NodeFileTraceReasons let reasons: NodeFileTraceReasons
const ignores = [
...TRACE_IGNORES,
...this.excludeFiles,
'**/node_modules/**',
]
const ignoreFn = (path: string) => {
return isMatch(path, ignores, { contains: true, dot: true })
}
await finishModulesSpan await finishModulesSpan
.traceChild('node-file-trace', { .traceChild('node-file-trace', {
traceEntryCount: entriesToTrace.length + '', traceEntryCount: entriesToTrace.length + '',
...@@ -472,11 +486,7 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance { ...@@ -472,11 +486,7 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance {
return doResolve(id, parent, job, !isCjs) return doResolve(id, parent, job, !isCjs)
} }
: undefined, : undefined,
ignore: [ ignore: ignoreFn,
...TRACE_IGNORES,
...this.excludeFiles,
'**/node_modules/**',
],
mixedModules: true, mixedModules: true,
}) })
// @ts-ignore // @ts-ignore
......
...@@ -43,6 +43,22 @@ describe('pnpm support', () => { ...@@ -43,6 +43,22 @@ describe('pnpm support', () => {
const html = await renderViaHTTP(next.url, '/') const html = await renderViaHTTP(next.url, '/')
expect(html).toContain('Hello World') expect(html).toContain('Hello World')
const manifest = JSON.parse(
await next.readFile('.next/next-server.js.nft.json')
)
for (const ignore of ['next/dist/pages', '.wasm', 'compiled/@ampproject']) {
let matchingFile
try {
matchingFile = manifest.files.some((file) => file.includes(ignore))
expect(!!matchingFile).toBe(false)
} catch (err) {
require('console').error(
`Found unexpected file in manifest ${matchingFile} matched ${ignore}`
)
throw err
}
}
}) })
it('should execute client-side JS on each page in output: "standalone"', async () => { it('should execute client-side JS on each page in output: "standalone"', async () => {
......
...@@ -22,9 +22,15 @@ describe('should set-up next', () => { ...@@ -22,9 +22,15 @@ describe('should set-up next', () => {
let stderr = '' let stderr = ''
let requiredFilesManifest let requiredFilesManifest
beforeAll(async () => { const setupNext = async ({
nextEnv,
minimalMode,
}: {
nextEnv?: boolean
minimalMode?: boolean
}) => {
// test build against environment with next support // test build against environment with next support
process.env.NOW_BUILDER = '1' process.env.NOW_BUILDER = nextEnv ? '1' : ''
next = await createNext({ next = await createNext({
files: { files: {
...@@ -103,7 +109,7 @@ describe('should set-up next', () => { ...@@ -103,7 +109,7 @@ describe('should set-up next', () => {
testServer, testServer,
(await fs.readFile(testServer, 'utf8')) (await fs.readFile(testServer, 'utf8'))
.replace('console.error(err)', `console.error('top-level', err)`) .replace('console.error(err)', `console.error('top-level', err)`)
.replace('conf:', 'minimalMode: true,conf:') .replace('conf:', `minimalMode: ${minimalMode},conf:`)
) )
appPort = await findPort() appPort = await findPort()
server = await initNextServerScript( server = await initNextServerScript(
...@@ -124,6 +130,10 @@ describe('should set-up next', () => { ...@@ -124,6 +130,10 @@ describe('should set-up next', () => {
}, },
} }
) )
}
beforeAll(async () => {
await setupNext({ nextEnv: true, minimalMode: true })
}) })
afterAll(async () => { afterAll(async () => {
await next.destroy() await next.destroy()
...@@ -1243,7 +1253,10 @@ describe('should set-up next', () => { ...@@ -1243,7 +1253,10 @@ describe('should set-up next', () => {
}) })
it('should run middleware correctly without minimalMode', async () => { it('should run middleware correctly without minimalMode', async () => {
await next.destroy()
await killApp(server) await killApp(server)
await setupNext({ nextEnv: false, minimalMode: false })
const testServer = join(next.testDir, 'standalone/server.js') const testServer = join(next.testDir, 'standalone/server.js')
await fs.writeFile( await fs.writeFile(
testServer, testServer,
......
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