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

Improve experimental feature naming #41060

Merged
merged 2 commits into from Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 15 additions & 6 deletions packages/next/build/webpack-config.ts
Expand Up @@ -124,6 +124,12 @@ function errorIfEnvConflicted(config: NextConfigComplete, key: string) {
}
}

function isResourceInPackages(resource: string, packageNames?: string[]) {
return packageNames?.some((p: string) =>
new RegExp('[/\\\\]node_modules[/\\\\]' + p + '[/\\\\]').test(resource)
)
}

export function getDefineEnv({
dev,
config,
Expand Down Expand Up @@ -1131,8 +1137,9 @@ export default async function getBaseWebpackConfig(
if (layer === WEBPACK_LAYERS.server) {
// All packages should be bundled for the server layer if they're not opted out.
if (
config.experimental.optoutServerComponentsBundle?.some((p: string) =>
new RegExp('node_modules[/\\\\]' + p + '[/\\\\]').test(res)
isResourceInPackages(
res,
config.experimental.serverComponentsExternalPackages
)
) {
return `${externalType} ${request}`
Expand Down Expand Up @@ -1508,16 +1515,18 @@ export default async function getBaseWebpackConfig(
{
issuerLayer: WEBPACK_LAYERS.server,
test: (req: string) => {
// If it's not a source code file, or has been opted out of
// bundling, don't resolve it.
if (
!codeCondition.test.test(req) ||
config.experimental.optoutServerComponentsBundle?.some(
(mod) => {
return req.includes('/node_modules/' + mod + '/')
}
isResourceInPackages(
req,
config.experimental.serverComponentsExternalPackages
)
) {
return false
}

return true
},
resolve: process.env.__NEXT_REACT_CHANNEL
Expand Down
2 changes: 1 addition & 1 deletion packages/next/server/config-schema.ts
Expand Up @@ -320,7 +320,7 @@ const configSchema = {
optimisticClientCache: {
type: 'boolean',
},
optoutServerComponentsBundle: {
serverComponentsExternalPackages: {
items: {
type: 'string',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/next/server/config-shared.ts
Expand Up @@ -153,7 +153,7 @@ export interface ExperimentalConfig {
adjustFontFallbacks?: boolean

// A list of packages that should be treated as external in the RSC server build
optoutServerComponentsBundle?: string[]
serverComponentsExternalPackages?: string[]

fontLoaders?: { [fontLoader: string]: any }
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/rsc-basic/next.config.js
Expand Up @@ -5,7 +5,7 @@ module.exports = {
},
experimental: {
appDir: true,
optoutServerComponentsBundle: ['conditional-exports-optout'],
serverComponentsExternalPackages: ['conditional-exports-optout'],
},
rewrites: async () => {
return {
Expand Down