Skip to content

Commit

Permalink
make transpilePackages stable
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding committed Dec 20, 2022
1 parent 2b3a38e commit 31185c7
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 24 deletions.
4 changes: 1 addition & 3 deletions packages/next/build/jest/jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ export default function nextJest(options: { dir?: string } = {}) {
await lockfilePatchPromise.cur
}

const transpiled = (
nextConfig?.experimental?.transpilePackages ?? []
).join('|')
const transpiled = (nextConfig?.transpilePackages ?? []).join('|')
return {
...resolvedJestConfig,

Expand Down
11 changes: 6 additions & 5 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1255,10 +1255,10 @@ export default async function getBaseWebpackConfig(

// 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.
if (config.experimental.transpilePackages && !resolvedExternalPackageDirs) {
if (config.transpilePackages && !resolvedExternalPackageDirs) {
resolvedExternalPackageDirs = new Map()
// 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(
dir,
config.experimental.esmExternals,
Expand All @@ -1281,7 +1281,7 @@ export default async function getBaseWebpackConfig(
const shouldBeBundled =
isResourceInPackages(
res,
config.experimental.transpilePackages,
config.transpilePackages,
resolvedExternalPackageDirs
) ||
(isEsm && config.experimental.appDir)
Expand Down Expand Up @@ -1319,7 +1319,7 @@ export default async function getBaseWebpackConfig(
}

const shouldIncludeExternalDirs =
config.experimental.externalDir || !!config.experimental.transpilePackages
config.experimental.externalDir || !!config.transpilePackages

const codeCondition = {
test: /\.(tsx|ts|js|cjs|mjs|jsx)$/,
Expand All @@ -1334,7 +1334,7 @@ export default async function getBaseWebpackConfig(

const shouldBeBundled = isResourceInPackages(
excludePath,
config.experimental.transpilePackages
config.transpilePackages
)
if (shouldBeBundled) return false

Expand Down Expand Up @@ -2400,6 +2400,7 @@ export default async function getBaseWebpackConfig(
future: config.future,
experimental: config.experimental,
disableStaticImages: config.images.disableStaticImages,
transpilePackages: config.transpileModules,
})

// @ts-ignore Cache exists
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/webpack/config/blocks/css/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export const css = curry(async function css(
)

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.
fns.push(
Expand Down
3 changes: 3 additions & 0 deletions packages/next/build/webpack/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export async function buildConfiguration(
sassOptions,
productionBrowserSourceMaps,
future,
transpilePackages,
experimental,
disableStaticImages,
}: {
Expand All @@ -36,6 +37,7 @@ export async function buildConfiguration(
assetPrefix: string
sassOptions: any
productionBrowserSourceMaps: boolean
transpilePackages: NextConfigComplete['transpilePackages']
future: NextConfigComplete['future']
experimental: NextConfigComplete['experimental']
disableStaticImages: NextConfigComplete['disableStaticImages']
Expand All @@ -59,6 +61,7 @@ export async function buildConfiguration(
: '',
sassOptions,
productionBrowserSourceMaps,
transpilePackages,
future,
experimental,
}
Expand Down
2 changes: 2 additions & 0 deletions packages/next/build/webpack/config/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export type ConfigurationContext = {
sassOptions: any
productionBrowserSourceMaps: boolean

transpilePackages: NextConfigComplete['transpilePackages']

future: NextConfigComplete['future']
experimental: NextConfigComplete['experimental']
}
Expand Down
2 changes: 1 addition & 1 deletion packages/next/cli/next-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ const nextDev: cliCommand = async (argv) => {
`The only configurations options supported are:\n - ${chalk.cyan(
'experimental.serverComponentsExternalPackages'
)}\n - ${chalk.cyan(
'experimental.transpilePackages'
'transpilePackages'
)}\n To use Turbopack, remove other configuration options.`
)} `
}
Expand Down
12 changes: 6 additions & 6 deletions packages/next/server/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,6 @@ const configSchema = {
},
type: 'array',
},
transpilePackages: {
items: {
type: 'string',
},
type: 'array',
},
scrollRestoration: {
type: 'boolean',
},
Expand Down Expand Up @@ -706,6 +700,12 @@ const configSchema = {
trailingSlash: {
type: 'boolean',
},
transpilePackages: {
items: {
type: 'string',
},
type: 'array',
},
typescript: {
additionalProperties: false,
properties: {
Expand Down
6 changes: 3 additions & 3 deletions packages/next/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@ export interface ExperimentalConfig {
// A list of packages that should be treated as external in the RSC server build
serverComponentsExternalPackages?: string[]

// A list of packages that should always be transpiled and bundled in the server
transpilePackages?: string[]

fontLoaders?: Array<{ loader: string; options?: any }>

webVitalsAttribution?: Array<typeof WEB_VITALS[number]>
Expand Down Expand Up @@ -507,6 +504,9 @@ export interface NextConfig extends Record<string, any> {

output?: 'standalone'

// A list of packages that should always be transpiled and bundled in the server
transpilePackages?: string[]

/**
* Enable experimental features. Note that all experimental features are subject to breaking changes in the future.
*/
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app-external/next.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
reactStrictMode: true,
transpilePackages: ['untranspiled-module', 'css', 'font'],
experimental: {
appDir: true,
serverComponentsExternalPackages: ['conditional-exports-optout'],
transpilePackages: ['untranspiled-module', 'css', 'font'],
},
}
4 changes: 1 addition & 3 deletions test/e2e/transpile-packages/npm/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module.exports = {
experimental: {
transpilePackages: ['css'],
},
transpilePackages: ['css'],
}
2 changes: 1 addition & 1 deletion test/production/jest/transpile-packages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('next/jest', () => {
})`,
'jest.config.js': `module.exports = require('next/jest')({ dir: './' })()`,
'next.config.js': `module.exports = {
experimental: { transpilePackages: ['@hashicorp/platform-util'] },
transpilePackages: ['@hashicorp/platform-util'],
}`,
},
packageJson: {
Expand Down

0 comments on commit 31185c7

Please sign in to comment.