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 config validation for latest turbopack changes #44223

Merged
merged 1 commit into from Dec 21, 2022
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
74 changes: 13 additions & 61 deletions packages/next/cli/next-dev.ts
Expand Up @@ -161,10 +161,8 @@ const nextDev: cliCommand = async (argv) => {
port,
}

// check for postcss, babelrc, swc plugins
// check for babelrc, swc plugins
async function validateNextConfig(isCustomTurbopack: boolean) {
const { findConfigPath } =
require('../lib/find-config') as typeof import('../lib/find-config')
const { getPkgManager } =
require('../lib/helpers/get-pkg-manager') as typeof import('../lib/helpers/get-pkg-manager')
const { getBabelConfigFile } =
Expand All @@ -175,8 +173,6 @@ const nextDev: cliCommand = async (argv) => {
require('next/dist/compiled/chalk') as typeof import('next/dist/compiled/chalk')
const { interopDefault } =
require('../lib/interop-default') as typeof import('../lib/interop-default')
const findUp =
require('next/dist/compiled/find-up') as typeof import('next/dist/compiled/find-up')

// To regenerate the TURBOPACK gradient require('gradient-string')('blue', 'red')('>>> TURBOPACK')
const isTTY = process.stdout.isTTY
Expand All @@ -190,13 +186,10 @@ const nextDev: cliCommand = async (argv) => {
let thankYouMsg = `Thank you for trying Next.js v13 with Turbopack! As a reminder,\nTurbopack is currently in alpha and not yet ready for production.\nWe appreciate your ongoing support as we work to make it ready\nfor everyone.\n`

let unsupportedParts = ''
// TODO: warning for postcss mentioning sidecar
let babelrc = await getBabelConfigFile(dir)
if (babelrc) babelrc = path.basename(babelrc)

let hasNonDefaultConfig
let postcssFile
let tailwindFile
let rawNextConfig: NextConfig = {}

try {
Expand All @@ -220,7 +213,7 @@ const nextDev: cliCommand = async (argv) => {
if (
configKey === 'serverComponentsExternalPackages' ||
configKey === 'appDir' ||
configKey === 'transpilePackages' ||
configKey === 'images' ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong, probably needs a separate line?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transpilePackages is not supported afaik, not sure why it was here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We added it initially as it was mentioned that turbopack just transpiled everything so it kinda sorta supported the config

configKey === 'reactStrictMode' ||
configKey === 'swcMinify' ||
configKey === 'configFileName'
Expand Down Expand Up @@ -248,29 +241,11 @@ const nextDev: cliCommand = async (argv) => {
hasNonDefaultConfig = Object.keys(rawNextConfig).some((key) =>
checkUnsupportedCustomConfig(key, rawNextConfig, defaultConfig)
)

const packagePath = findUp.sync('package.json', { cwd: dir })
let hasSideCar = false

if (packagePath) {
const pkgData = require(packagePath)
hasSideCar = Object.values(
(pkgData.scripts || {}) as Record<string, string>
).some(
(script) => script.includes('tailwind') || script.includes('postcss')
)
}
postcssFile = !hasSideCar && (await findConfigPath(dir, 'postcss'))
tailwindFile = !hasSideCar && (await findConfigPath(dir, 'tailwind'))

if (postcssFile) postcssFile = path.basename(postcssFile)
if (tailwindFile) tailwindFile = path.basename(tailwindFile)
} catch (e) {
console.error('Unexpected error occurred while checking config', e)
}

const hasWarningOrError =
tailwindFile || postcssFile || babelrc || hasNonDefaultConfig
const hasWarningOrError = babelrc || hasNonDefaultConfig
if (!hasWarningOrError) {
thankYouMsg = chalk.dim(thankYouMsg)
}
Expand All @@ -297,40 +272,19 @@ const nextDev: cliCommand = async (argv) => {
unsupportedParts += `\n\n- Unsupported Next.js configuration option(s) (${chalk.cyan(
'next.config.js'
)})\n ${chalk.dim(
`The only configurations options supported are:\n - ${chalk.cyan(
'experimental.serverComponentsExternalPackages'
)}\n - ${chalk.cyan(
'transpilePackages'
)}\n To use Turbopack, remove other configuration options.`
`The only configurations options supported are:\n${[
'reactStrictMode',
'experimental.appDir',
'experimental.serverComponentsExternalPackages',
'images',
'swcMinify',
'configFileName',
]
.map((name) => ` - ${chalk.cyan(name)}\n`)
.join('')} To use Turbopack, remove other configuration options.`
)} `
}

if (postcssFile || tailwindFile) {
console.warn(
`${chalk.bold.yellow(
'Warning:'
)} You are using configuration that may require additional\nsetup with Turbopack. If you already made these changes please\nignore this warning.\n`
)
}

if (postcssFile) {
console.warn(
`- PostCSS detected (${chalk.cyan(postcssFile)})\n` +
` ${chalk.dim(
'PostCSS is not yet supported by Next.js v13 with Turbopack.\n To use with Turbopack, see: https://nextjs.link/turbopack-postcss'
)}\n`
)
}

if (tailwindFile) {
console.warn(
`- Tailwind detected (${chalk.cyan(tailwindFile)})\n` +
` ${chalk.dim(
'Tailwind is not yet supported by Next.js v13 with Turbopack.\n To use with Turbopack, see: https://nextjs.link/turbopack-tailwind'
)}\n`
)
}

if (unsupportedParts) {
const pkgManager = getPkgManager(dir)

Expand Down Expand Up @@ -425,8 +379,6 @@ If you cannot make the changes above, but still want to try out\nNext.js v13 wit
: packagePath
? path.dirname(packagePath)
: undefined),
serverComponentsExternalPackages:
rawNextConfig.experimental?.serverComponentsExternalPackages,
})
// Start preflight after server is listening and ignore errors:
preflight().catch(() => {})
Expand Down