Unverified Commit 04daf7eb authored by Shu Ding's avatar Shu Ding Committed by GitHub

Move `transpilePackages` out of experimental (#44194)

Should be good to land and it got tests covered.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
Co-authored-by: 's avatarJJ Kasper <22380829+ijjk@users.noreply.github.com>
parent cafb886e
...@@ -95,9 +95,7 @@ export default function nextJest(options: { dir?: string } = {}) { ...@@ -95,9 +95,7 @@ export default function nextJest(options: { dir?: string } = {}) {
await lockfilePatchPromise.cur await lockfilePatchPromise.cur
} }
const transpiled = ( const transpiled = (nextConfig?.transpilePackages ?? []).join('|')
nextConfig?.experimental?.transpilePackages ?? []
).join('|')
return { return {
...resolvedJestConfig, ...resolvedJestConfig,
......
...@@ -1255,10 +1255,10 @@ export default async function getBaseWebpackConfig( ...@@ -1255,10 +1255,10 @@ export default async function getBaseWebpackConfig(
// If a package should be transpiled by Next.js, we skip making it external. // If a package should be transpiled by Next.js, we skip making it external.
// It doesn't matter what the extension is, as we'll transpile it anyway. // It doesn't matter what the extension is, as we'll transpile it anyway.
if (config.experimental.transpilePackages && !resolvedExternalPackageDirs) { if (config.transpilePackages && !resolvedExternalPackageDirs) {
resolvedExternalPackageDirs = new Map() resolvedExternalPackageDirs = new Map()
// We need to resolve all the external package dirs initially. // We need to resolve all the external package dirs initially.
for (const pkg of config.experimental.transpilePackages) { for (const pkg of config.transpilePackages) {
const pkgRes = await resolveExternal( const pkgRes = await resolveExternal(
dir, dir,
config.experimental.esmExternals, config.experimental.esmExternals,
...@@ -1281,7 +1281,7 @@ export default async function getBaseWebpackConfig( ...@@ -1281,7 +1281,7 @@ export default async function getBaseWebpackConfig(
const shouldBeBundled = const shouldBeBundled =
isResourceInPackages( isResourceInPackages(
res, res,
config.experimental.transpilePackages, config.transpilePackages,
resolvedExternalPackageDirs resolvedExternalPackageDirs
) || ) ||
(isEsm && config.experimental.appDir) (isEsm && config.experimental.appDir)
...@@ -1319,7 +1319,7 @@ export default async function getBaseWebpackConfig( ...@@ -1319,7 +1319,7 @@ export default async function getBaseWebpackConfig(
} }
const shouldIncludeExternalDirs = const shouldIncludeExternalDirs =
config.experimental.externalDir || !!config.experimental.transpilePackages config.experimental.externalDir || !!config.transpilePackages
const codeCondition = { const codeCondition = {
test: /\.(tsx|ts|js|cjs|mjs|jsx)$/, test: /\.(tsx|ts|js|cjs|mjs|jsx)$/,
...@@ -1334,7 +1334,7 @@ export default async function getBaseWebpackConfig( ...@@ -1334,7 +1334,7 @@ export default async function getBaseWebpackConfig(
const shouldBeBundled = isResourceInPackages( const shouldBeBundled = isResourceInPackages(
excludePath, excludePath,
config.experimental.transpilePackages config.transpilePackages
) )
if (shouldBeBundled) return false if (shouldBeBundled) return false
...@@ -2399,6 +2399,7 @@ export default async function getBaseWebpackConfig( ...@@ -2399,6 +2399,7 @@ export default async function getBaseWebpackConfig(
future: config.future, future: config.future,
experimental: config.experimental, experimental: config.experimental,
disableStaticImages: config.images.disableStaticImages, disableStaticImages: config.images.disableStaticImages,
transpilePackages: config.transpilePackages,
}) })
// @ts-ignore Cache exists // @ts-ignore Cache exists
......
...@@ -222,7 +222,7 @@ export const css = curry(async function css( ...@@ -222,7 +222,7 @@ export const css = curry(async function css(
) )
const shouldIncludeExternalCSSImports = const shouldIncludeExternalCSSImports =
!!ctx.experimental.craCompat || !!ctx.experimental.transpilePackages !!ctx.experimental.craCompat || !!ctx.transpilePackages
// CSS modules & SASS modules support. They are allowed to be imported in anywhere. // CSS modules & SASS modules support. They are allowed to be imported in anywhere.
fns.push( fns.push(
......
...@@ -22,6 +22,7 @@ export async function buildConfiguration( ...@@ -22,6 +22,7 @@ export async function buildConfiguration(
sassOptions, sassOptions,
productionBrowserSourceMaps, productionBrowserSourceMaps,
future, future,
transpilePackages,
experimental, experimental,
disableStaticImages, disableStaticImages,
}: { }: {
...@@ -36,6 +37,7 @@ export async function buildConfiguration( ...@@ -36,6 +37,7 @@ export async function buildConfiguration(
assetPrefix: string assetPrefix: string
sassOptions: any sassOptions: any
productionBrowserSourceMaps: boolean productionBrowserSourceMaps: boolean
transpilePackages: NextConfigComplete['transpilePackages']
future: NextConfigComplete['future'] future: NextConfigComplete['future']
experimental: NextConfigComplete['experimental'] experimental: NextConfigComplete['experimental']
disableStaticImages: NextConfigComplete['disableStaticImages'] disableStaticImages: NextConfigComplete['disableStaticImages']
...@@ -59,6 +61,7 @@ export async function buildConfiguration( ...@@ -59,6 +61,7 @@ export async function buildConfiguration(
: '', : '',
sassOptions, sassOptions,
productionBrowserSourceMaps, productionBrowserSourceMaps,
transpilePackages,
future, future,
experimental, experimental,
} }
......
...@@ -20,6 +20,8 @@ export type ConfigurationContext = { ...@@ -20,6 +20,8 @@ export type ConfigurationContext = {
sassOptions: any sassOptions: any
productionBrowserSourceMaps: boolean productionBrowserSourceMaps: boolean
transpilePackages: NextConfigComplete['transpilePackages']
future: NextConfigComplete['future'] future: NextConfigComplete['future']
experimental: NextConfigComplete['experimental'] experimental: NextConfigComplete['experimental']
} }
......
...@@ -300,7 +300,7 @@ const nextDev: cliCommand = async (argv) => { ...@@ -300,7 +300,7 @@ const nextDev: cliCommand = async (argv) => {
`The only configurations options supported are:\n - ${chalk.cyan( `The only configurations options supported are:\n - ${chalk.cyan(
'experimental.serverComponentsExternalPackages' 'experimental.serverComponentsExternalPackages'
)}\n - ${chalk.cyan( )}\n - ${chalk.cyan(
'experimental.transpilePackages' 'transpilePackages'
)}\n To use Turbopack, remove other configuration options.` )}\n To use Turbopack, remove other configuration options.`
)} ` )} `
} }
......
...@@ -363,12 +363,6 @@ const configSchema = { ...@@ -363,12 +363,6 @@ const configSchema = {
}, },
type: 'array', type: 'array',
}, },
transpilePackages: {
items: {
type: 'string',
},
type: 'array',
},
scrollRestoration: { scrollRestoration: {
type: 'boolean', type: 'boolean',
}, },
...@@ -706,6 +700,12 @@ const configSchema = { ...@@ -706,6 +700,12 @@ const configSchema = {
trailingSlash: { trailingSlash: {
type: 'boolean', type: 'boolean',
}, },
transpilePackages: {
items: {
type: 'string',
},
type: 'array',
},
typescript: { typescript: {
additionalProperties: false, additionalProperties: false,
properties: { properties: {
......
...@@ -159,9 +159,6 @@ export interface ExperimentalConfig { ...@@ -159,9 +159,6 @@ export interface ExperimentalConfig {
// A list of packages that should be treated as external in the RSC server build // A list of packages that should be treated as external in the RSC server build
serverComponentsExternalPackages?: string[] serverComponentsExternalPackages?: string[]
// A list of packages that should always be transpiled and bundled in the server
transpilePackages?: string[]
fontLoaders?: Array<{ loader: string; options?: any }> fontLoaders?: Array<{ loader: string; options?: any }>
webVitalsAttribution?: Array<typeof WEB_VITALS[number]> webVitalsAttribution?: Array<typeof WEB_VITALS[number]>
...@@ -504,6 +501,9 @@ export interface NextConfig extends Record<string, any> { ...@@ -504,6 +501,9 @@ export interface NextConfig extends Record<string, any> {
output?: 'standalone' output?: 'standalone'
// A list of packages that should always be transpiled and bundled in the server
transpilePackages?: string[]
allowMiddlewareResponseBody?: boolean allowMiddlewareResponseBody?: boolean
skipMiddlewareUrlNormalize?: boolean skipMiddlewareUrlNormalize?: boolean
......
...@@ -605,6 +605,16 @@ function assignDefaults(dir: string, userConfig: { [key: string]: any }) { ...@@ -605,6 +605,16 @@ function assignDefaults(dir: string, userConfig: { [key: string]: any }) {
result.output = 'standalone' result.output = 'standalone'
} }
if (
result.experimental &&
'transpilePackages' in (result.experimental as any)
) {
Log.warn(
`\`transpilePackages\` has been moved out of \`experimental\`. Please update your ${configFileName} file accordingly.`
)
result.transpilePackages = (result.experimental as any).transpilePackages
}
if ( if (
result.experimental?.outputFileTracingRoot && result.experimental?.outputFileTracingRoot &&
!isAbsolute(result.experimental.outputFileTracingRoot) !isAbsolute(result.experimental.outputFileTracingRoot)
......
module.exports = { module.exports = {
reactStrictMode: true, reactStrictMode: true,
transpilePackages: ['untranspiled-module', 'css', 'font'],
experimental: { experimental: {
appDir: true, appDir: true,
serverComponentsExternalPackages: ['conditional-exports-optout'], serverComponentsExternalPackages: ['conditional-exports-optout'],
transpilePackages: ['untranspiled-module', 'css', 'font'],
}, },
} }
module.exports = { module.exports = {
experimental: { transpilePackages: ['css'],
transpilePackages: ['css'],
},
} }
...@@ -17,7 +17,7 @@ describe('next/jest', () => { ...@@ -17,7 +17,7 @@ describe('next/jest', () => {
})`, })`,
'jest.config.js': `module.exports = require('next/jest')({ dir: './' })()`, 'jest.config.js': `module.exports = require('next/jest')({ dir: './' })()`,
'next.config.js': `module.exports = { 'next.config.js': `module.exports = {
experimental: { transpilePackages: ['@hashicorp/platform-util'] }, transpilePackages: ['@hashicorp/platform-util'],
}`, }`,
}, },
packageJson: { packageJson: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment