From e93ed159eb9fb0dc203bf37106747d3f14086c70 Mon Sep 17 00:00:00 2001 From: Maia Teegarden Date: Mon, 1 May 2023 10:50:06 -0700 Subject: [PATCH 1/2] Allow more next config options --- packages/next/src/lib/turbopack-warning.ts | 30 +++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/packages/next/src/lib/turbopack-warning.ts b/packages/next/src/lib/turbopack-warning.ts index 2d4261cc218f..eb027e8d3c8c 100644 --- a/packages/next/src/lib/turbopack-warning.ts +++ b/packages/next/src/lib/turbopack-warning.ts @@ -6,13 +6,9 @@ import { PHASE_DEVELOPMENT_SERVER } from '../shared/lib/constants' const supportedTurbopackNextConfigOptions = [ 'configFileName', 'env', - 'experimental.appDir', 'modularizeImports', 'compiler.emotion', 'compiler.styledComponents', - 'experimental.serverComponentsExternalPackages', - 'experimental.turbo', - 'experimental.mdxRs', 'images', 'pageExtensions', 'onDemandEntries', @@ -22,14 +18,27 @@ const supportedTurbopackNextConfigOptions = [ 'reactStrictMode', 'swcMinify', 'transpilePackages', + 'experimental.appDir', + 'experimental.serverComponentsExternalPackages', + 'experimental.turbo', + 'experimental.mdxRs', 'experimental.swcFileReading', 'experimental.forceSwcTransforms', + // options below are not really supported, but ignored + 'devIndicators', + 'onDemandEntries', + 'experimental.cpus', + 'experimental.sharedPool', + 'experimental.proxyTimeout', + 'experimental.isrFlushToDisk', + 'experimental.workerThreads', + 'experimenatl.pageEnv', ] // The following will need to be supported by `next build --turbo` const prodSpecificTurboNextConfigOptions = [ - 'eslint.ignoreDuringBuilds', - 'typescript.ignoreDuringBuilds', + 'eslint', + 'typescript', 'staticPageGenerationTimeout', 'outputFileTracing', 'output', @@ -39,6 +48,15 @@ const prodSpecificTurboNextConfigOptions = [ 'productionBrowserSourceMaps', 'optimizeFonts', 'poweredByHeader', + 'staticPageGenerationTimeout', + 'compiler.reactRemoveProperties', + 'compiler.removeConsole', + 'experimental.turbotrace', + 'experimental.outputFileTracingRoot', + 'experimental.outputFileTracingExcludes', + 'experimental.outputFileTracingIgnores', + 'experiemental.outputFileTracingIncludes', + 'experimental.gzipSize', ] // check for babelrc, swc plugins From a75c7133ebe6cf02839af0e7b262d4b9192a72ab Mon Sep 17 00:00:00 2001 From: Maia Teegarden Date: Mon, 1 May 2023 11:46:41 -0700 Subject: [PATCH 2/2] Improve supported key checking --- packages/next/src/lib/turbopack-warning.ts | 98 ++++++++++------------ 1 file changed, 43 insertions(+), 55 deletions(-) diff --git a/packages/next/src/lib/turbopack-warning.ts b/packages/next/src/lib/turbopack-warning.ts index eb027e8d3c8c..b02ba373d9e6 100644 --- a/packages/next/src/lib/turbopack-warning.ts +++ b/packages/next/src/lib/turbopack-warning.ts @@ -112,65 +112,57 @@ export async function validateTurboNextConfig({ }) } - let supported = isDev - ? supportedTurbopackNextConfigOptions - : [ - ...supportedTurbopackNextConfigOptions, - ...prodSpecificTurboNextConfigOptions, - ] - const checkUnsupportedCustomConfig = ( - configKey = '', - parentUserConfig: any, - parentDefaultConfig: any - ): boolean => { - try { - // these should not error - if ( - // we only want the key after the dot for experimental options - supported - .map((key) => key.split('.').splice(-1)[0]) - .includes(configKey) - ) { - return false - } + const flattenKeys = (obj: any, prefix: string = ''): string[] => { + let keys: string[] = [] - // experimental options are checked separately - if (configKey === 'experimental') { - return false + for (const key in obj) { + if (typeof obj[key] === 'undefined') { + continue } - let userValue = parentUserConfig?.[configKey] - let defaultValue = parentDefaultConfig?.[configKey] + const pre = prefix.length ? `${prefix}.` : '' - if (typeof defaultValue !== 'object') { - return defaultValue !== userValue + if ( + typeof obj[key] === 'object' && + !Array.isArray(obj[key]) && + obj[key] !== null + ) { + keys = keys.concat(flattenKeys(obj[key], pre + key)) + } else { + keys.push(pre + key) } - return Object.keys(userValue || {}).some((key: string) => { - return checkUnsupportedCustomConfig(key, userValue, defaultValue) - }) - } catch (e) { - console.error( - `Unexpected error occurred while checking ${configKey}`, - e - ) - return false } + + return keys } - unsupportedConfig = [ - ...Object.keys(rawNextConfig).filter((key) => - checkUnsupportedCustomConfig(key, rawNextConfig, defaultConfig) - ), - ...Object.keys(rawNextConfig.experimental ?? {}) - .filter((key) => - checkUnsupportedCustomConfig( - key, - rawNextConfig?.experimental, - defaultConfig?.experimental - ) - ) - .map((key) => `experimental.${key}`), - ] + const getDeepValue = (obj: any, keys: string | string[]): any => { + if (typeof keys === 'string') { + keys = keys.split('.') + } + if (keys.length === 1) { + return obj[keys[0]] + } + return getDeepValue(obj[keys[0]], keys.slice(1)) + } + + const customKeys = flattenKeys(rawNextConfig) + + let supportedKeys = isDev + ? [ + ...supportedTurbopackNextConfigOptions, + ...prodSpecificTurboNextConfigOptions, + ] + : supportedTurbopackNextConfigOptions + + for (const key of customKeys) { + let isSupported = + supportedKeys.some((supportedKey) => key.startsWith(supportedKey)) || + getDeepValue(rawNextConfig, key) === getDeepValue(defaultConfig, key) + if (!isSupported) { + unsupportedConfig.push(key) + } + } } catch (e) { console.error('Unexpected error occurred while checking config', e) } @@ -206,10 +198,6 @@ export async function validateTurboNextConfig({ )})\n ${chalk.dim( `To use Turbopack, remove the following configuration options:\n${unsupportedConfig .map((name) => ` - ${chalk.red(name)}\n`) - .join( - '' - )} The only supported configurations options are:\n${supportedTurbopackNextConfigOptions - .map((name) => ` - ${chalk.cyan(name)}\n`) .join('')} ` )} ` }