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

Update turbopack warning #49051

Merged
merged 4 commits into from May 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
128 changes: 67 additions & 61 deletions packages/next/src/lib/turbopack-warning.ts
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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
Expand Down Expand Up @@ -94,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
}

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))
}

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 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)
}
Expand Down Expand Up @@ -188,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('')} `
)} `
}
Expand Down