Unverified Commit 70c6f155 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Add experimental outputFileTracingIgnores config (#43103)

This allows filtering out known traces that should be ignored even if
`node-file-trace` detects them as being potentially used.

x-ref: [slack
thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1668761350086149)


## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
parent 24867fd7
...@@ -1993,13 +1993,15 @@ export default async function getBaseWebpackConfig( ...@@ -1993,13 +1993,15 @@ export default async function getBaseWebpackConfig(
config.outputFileTracing && config.outputFileTracing &&
(isNodeServer || isEdgeServer) && (isNodeServer || isEdgeServer) &&
!dev && !dev &&
new (require('./webpack/plugins/next-trace-entrypoints-plugin').TraceEntryPointsPlugin)( new (require('./webpack/plugins/next-trace-entrypoints-plugin')
.TraceEntryPointsPlugin as typeof import('./webpack/plugins/next-trace-entrypoints-plugin').TraceEntryPointsPlugin)(
{ {
appDir: dir, appDir: dir,
esmExternals: config.experimental.esmExternals, esmExternals: config.experimental.esmExternals,
outputFileTracingRoot: config.experimental.outputFileTracingRoot, outputFileTracingRoot: config.experimental.outputFileTracingRoot,
appDirEnabled: hasAppDir, appDirEnabled: hasAppDir,
turbotrace: config.experimental.turbotrace, turbotrace: config.experimental.turbotrace,
traceIgnores: config.experimental.outputFileTracingIgnores || [],
} }
), ),
// Moment.js is an extremely popular library that bundles large locale files // Moment.js is an extremely popular library that bundles large locale files
......
...@@ -92,7 +92,7 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance { ...@@ -92,7 +92,7 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance {
private appDirEnabled?: boolean private appDirEnabled?: boolean
private tracingRoot: string private tracingRoot: string
private entryTraces: Map<string, Set<string>> private entryTraces: Map<string, Set<string>>
private excludeFiles: string[] private traceIgnores: string[]
private esmExternals?: NextConfigComplete['experimental']['esmExternals'] private esmExternals?: NextConfigComplete['experimental']['esmExternals']
private turbotrace?: NextConfigComplete['experimental']['turbotrace'] private turbotrace?: NextConfigComplete['experimental']['turbotrace']
private chunksToTrace: string[] = [] private chunksToTrace: string[] = []
...@@ -102,14 +102,14 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance { ...@@ -102,14 +102,14 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance {
constructor({ constructor({
appDir, appDir,
appDirEnabled, appDirEnabled,
excludeFiles, traceIgnores,
esmExternals, esmExternals,
outputFileTracingRoot, outputFileTracingRoot,
turbotrace, turbotrace,
}: { }: {
appDir: string appDir: string
appDirEnabled?: boolean appDirEnabled?: boolean
excludeFiles?: string[] traceIgnores?: string[]
outputFileTracingRoot?: string outputFileTracingRoot?: string
esmExternals?: NextConfigComplete['experimental']['esmExternals'] esmExternals?: NextConfigComplete['experimental']['esmExternals']
turbotrace?: NextConfigComplete['experimental']['turbotrace'] turbotrace?: NextConfigComplete['experimental']['turbotrace']
...@@ -118,7 +118,7 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance { ...@@ -118,7 +118,7 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance {
this.entryTraces = new Map() this.entryTraces = new Map()
this.esmExternals = esmExternals this.esmExternals = esmExternals
this.appDirEnabled = appDirEnabled this.appDirEnabled = appDirEnabled
this.excludeFiles = excludeFiles || [] this.traceIgnores = traceIgnores || []
this.tracingRoot = outputFileTracingRoot || appDir this.tracingRoot = outputFileTracingRoot || appDir
this.turbotrace = turbotrace this.turbotrace = turbotrace
} }
...@@ -174,7 +174,7 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance { ...@@ -174,7 +174,7 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance {
return return
} }
} }
const ignores = [...TRACE_IGNORES, ...this.excludeFiles] const ignores = [...TRACE_IGNORES, ...this.traceIgnores]
const ignoreFn = (path: string) => { const ignoreFn = (path: string) => {
return isMatch(path, ignores, { contains: true, dot: true }) return isMatch(path, ignores, { contains: true, dot: true })
...@@ -463,7 +463,7 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance { ...@@ -463,7 +463,7 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance {
let reasons: NodeFileTraceReasons let reasons: NodeFileTraceReasons
const ignores = [ const ignores = [
...TRACE_IGNORES, ...TRACE_IGNORES,
...this.excludeFiles, ...this.traceIgnores,
'**/node_modules/**', '**/node_modules/**',
] ]
const ignoreFn = (path: string) => { const ignoreFn = (path: string) => {
......
...@@ -335,6 +335,9 @@ const configSchema = { ...@@ -335,6 +335,9 @@ const configSchema = {
minLength: 1, minLength: 1,
type: 'string', type: 'string',
}, },
outputFileTracingIgnores: {
type: 'array',
},
pageEnv: { pageEnv: {
type: 'boolean', type: 'boolean',
}, },
......
...@@ -121,6 +121,7 @@ export interface ExperimentalConfig { ...@@ -121,6 +121,7 @@ export interface ExperimentalConfig {
fullySpecified?: boolean fullySpecified?: boolean
urlImports?: NonNullable<webpack.Configuration['experiments']>['buildHttp'] urlImports?: NonNullable<webpack.Configuration['experiments']>['buildHttp']
outputFileTracingRoot?: string outputFileTracingRoot?: string
outputFileTracingIgnores?: string[]
modularizeImports?: Record< modularizeImports?: Record<
string, string,
{ {
......
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