From 9c87ea5a3d45c64da220e1013a4fe802935b2b31 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Wed, 25 Oct 2023 09:08:14 -0700 Subject: [PATCH] Fix logging removed experiments in start logs (#57373) Do not log the removed experiments in the start server logs, for instance `experimental.appDir` should get warned as unexpected option but it's not the valid experiment anymore --- packages/next/src/server/config-shared.ts | 1 - packages/next/src/server/config.ts | 3 +- .../test/index.test.js | 44 ++++++++++++++++--- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/packages/next/src/server/config-shared.ts b/packages/next/src/server/config-shared.ts index 282ca2d2b2fb9..2b6bae32a99bf 100644 --- a/packages/next/src/server/config-shared.ts +++ b/packages/next/src/server/config-shared.ts @@ -277,7 +277,6 @@ export interface ExperimentalConfig { /** * Generate Route types and enable type checking for Link and Router.push, etc. - * This option requires `appDir` to be enabled first. * @see https://nextjs.org/docs/app/api-reference/next-config-js/typedRoutes */ typedRoutes?: boolean diff --git a/packages/next/src/server/config.ts b/packages/next/src/server/config.ts index 8184ecfb71fa7..56a811c5d5d34 100644 --- a/packages/next/src/server/config.ts +++ b/packages/next/src/server/config.ts @@ -1084,8 +1084,9 @@ export function getEnabledExperimentalFeatures( userNextConfigExperimental ) as (keyof ExperimentalConfig)[]) { if ( + featureName in defaultConfig.experimental && userNextConfigExperimental[featureName] !== - defaultConfig.experimental[featureName] + defaultConfig.experimental[featureName] ) { enabledExperiments.push(featureName) } diff --git a/test/integration/config-experimental-warning/test/index.test.js b/test/integration/config-experimental-warning/test/index.test.js index 97b5ae2e42722..49713d32ff651 100644 --- a/test/integration/config-experimental-warning/test/index.test.js +++ b/test/integration/config-experimental-warning/test/index.test.js @@ -8,7 +8,9 @@ import { File, nextBuild, nextStart, + check, } from 'next-test-utils' +import stripAnsi from 'strip-ansi' const appDir = join(__dirname, '..') const configFile = new File(join(appDir, '/next.config.js')) @@ -107,8 +109,8 @@ describe('Config Experimental Warning', () => { `) const stdout = await collectStdoutFromDev(appDir) - expect(stdout).not.toMatch(' - Experiments (use at your own risk):') - expect(stdout).not.toMatch(' · workerThreads') + expect(stdout).not.toContain(' - Experiments (use at your own risk):') + expect(stdout).not.toContain(' · workerThreads') }) it('should show warning with config from object with experimental and multiple keys', async () => { @@ -122,9 +124,9 @@ describe('Config Experimental Warning', () => { `) const stdout = await collectStdoutFromDev(appDir) - expect(stdout).toMatch(' - Experiments (use at your own risk):') - expect(stdout).toMatch(' · workerThreads') - expect(stdout).toMatch(' · scrollRestoration') + expect(stdout).toContain(' - Experiments (use at your own risk):') + expect(stdout).toContain(' · workerThreads') + expect(stdout).toContain(' · scrollRestoration') }) it('should not show next app info in next start', async () => { @@ -168,4 +170,36 @@ describe('Config Experimental Warning', () => { expect(stdout).toMatch(' · scrollRestoration') expect(stdout).toMatch(' · instrumentationHook') }) + + it('should show unrecognized experimental features in warning but not in start log experiments section', async () => { + configFile.write(` + module.exports = { + experimental: { + appDir: true + } + } + `) + + await collectStdoutFromBuild(appDir) + const port = await findPort() + let stdout = '' + let stderr = '' + app = await nextStart(appDir, port, { + onStdout(msg) { + stdout += msg + }, + onStderr(msg) { + stderr += msg + }, + }) + + await check(() => { + const cliOutput = stripAnsi(stdout) + const cliOutputErr = stripAnsi(stderr) + expect(cliOutput).not.toContain(' - Experiments (use at your own risk):') + expect(cliOutputErr).toContain( + `Unrecognized key(s) in object: 'appDir' at "experimental"` + ) + }) + }) })