Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show the new key of experimental config change warnings #65651

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions packages/next/src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,16 @@ export function warnOptionHasBeenDeprecated(

export function warnOptionHasBeenMovedOutOfExperimental(
config: NextConfig,
oldKey: string,
oldExperimentalKey: string,
newKey: string,
configFileName: string,
silent: boolean
) {
if (config.experimental && oldKey in config.experimental) {
if (config.experimental && oldExperimentalKey in config.experimental) {
if (!silent) {
Log.warn(
`\`${oldKey}\` has been moved out of \`experimental\`` +
(newKey.includes('.') ? ` and into \`${newKey}\`` : '') +
`. Please update your ${configFileName} file accordingly.`
`\`experimental.${oldExperimentalKey}\` has been moved to \`${newKey}\`. ` +
`Please update your ${configFileName} file accordingly.`
)
}

Expand All @@ -153,7 +152,7 @@ export function warnOptionHasBeenMovedOutOfExperimental(
current[key] = current[key] || {}
current = current[key]
}
current[newKeys.shift()!] = (config.experimental as any)[oldKey]
current[newKeys.shift()!] = (config.experimental as any)[oldExperimentalKey]
}

return config
Expand Down
25 changes: 23 additions & 2 deletions test/unit/warn-removed-experimental-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('warnOptionHasBeenMovedOutOfExperimental', () => {

expect(spy).toHaveBeenCalledWith(
expect.stringContaining('⚠'),
'`skipTrailingSlashRedirect` has been moved out of `experimental`. Please update your next.config.js file accordingly.'
'`experimental.skipTrailingSlashRedirect` has been moved to `skipTrailingSlashRedirect`. Please update your next.config.js file accordingly.'
)
})

Expand All @@ -65,7 +65,7 @@ describe('warnOptionHasBeenMovedOutOfExperimental', () => {

expect(spy).toHaveBeenCalledWith(
expect.stringContaining('⚠'),
'`relay` has been moved out of `experimental` and into `compiler.relay`. Please update your next.config.js file accordingly.'
'`experimental.relay` has been moved to `compiler.relay`. Please update your next.config.js file accordingly.'
)
})

Expand Down Expand Up @@ -104,6 +104,27 @@ describe('warnOptionHasBeenMovedOutOfExperimental', () => {
expect(config.experimental.foo).toBe('bar')
expect(config.deep.prop.baz).toBe('bar')
})

it('should show the new key name in the warning', () => {
const config = {
experimental: {
bundlePagesExternals: true,
},
} as any

warnOptionHasBeenMovedOutOfExperimental(
config,
'bundlePagesExternals',
'bundlePagesRouterDependencies',
'next.config.js',
false
)

expect(spy).toHaveBeenCalledWith(
expect.stringContaining('⚠'),
'`experimental.bundlePagesExternals` has been moved to `bundlePagesRouterDependencies`. Please update your next.config.js file accordingly.'
)
})
})

describe('warnOptionHasBeenDeprecated', () => {
Expand Down
Loading