Skip to content

Commit

Permalink
revert serverComponentsExternalPackages rename
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony committed Aug 20, 2024
1 parent 5636d37 commit 8cc3957
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
25 changes: 9 additions & 16 deletions crates/next-core/src/next_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,6 @@ pub struct NextConfig {
pub output: Option<OutputType>,
pub analytics_id: Option<String>,

/// Enables the bundling of node_modules packages (externals) for pages
/// server-side bundles.
///
/// [API Reference](https://nextjs.org/docs/pages/api-reference/next-config-js/bundlePagesRouterDependencies)
pub bundle_pages_router_dependencies: Option<bool>,

/// A list of packages that should be treated as external on the server
/// build.
///
/// [API Reference](https://nextjs.org/docs/app/api-reference/next-config-js/serverExternalPackages)
pub server_external_packages: Option<Vec<RcStr>>,

#[serde(rename = "_originalRedirects")]
pub original_redirects: Option<Vec<Redirect>>,

Expand Down Expand Up @@ -455,6 +443,10 @@ pub struct ExperimentalConfig {
/// For use with `@next/mdx`. Compile MDX files using the new Rust compiler.
/// @see [api reference](https://nextjs.org/docs/app/api-reference/next-config-js/mdxRs)
mdx_rs: Option<MdxRsOptions>,
/// A list of packages that should be treated as external in the RSC server
/// build. @see [api reference](https://nextjs.org/docs/app/api-reference/next-config-js/server_components_external_packages)
pub server_components_external_packages: Option<Vec<RcStr>>,
pub bundle_pages_externals: Option<bool>,
pub strict_next_head: Option<bool>,
pub swc_plugins: Option<Vec<(RcStr, serde_json::Value)>>,
pub turbo: Option<ExperimentalTurboConfig>,
Expand Down Expand Up @@ -740,8 +732,8 @@ impl NextConfig {
}

#[turbo_tasks::function]
pub fn bundle_pages_router_dependencies(&self) -> Vc<bool> {
Vc::cell(self.bundle_pages_router_dependencies.unwrap_or_default())
pub fn bundle_pages_externals(&self) -> Vc<bool> {
Vc::cell(self.experimental.bundle_pages_externals.unwrap_or_default())
}

#[turbo_tasks::function]
Expand All @@ -750,10 +742,11 @@ impl NextConfig {
}

#[turbo_tasks::function]
pub async fn server_external_packages(self: Vc<Self>) -> Result<Vc<Vec<RcStr>>> {
pub async fn server_component_externals(self: Vc<Self>) -> Result<Vc<Vec<RcStr>>> {
Ok(Vc::cell(
self.await?
.server_external_packages
.experimental
.server_components_external_packages
.as_ref()
.cloned()
.unwrap_or_default(),
Expand Down
16 changes: 8 additions & 8 deletions crates/next-core/src/next_server/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ pub async fn get_server_resolve_options_context(
.cloned(),
);

let server_external_packages = &*next_config.server_external_packages().await?;
let server_component_externals = &*next_config.server_component_externals().await?;

let conflicting_packages = transpiled_packages
.iter()
.filter(|package| server_external_packages.contains(package))
.filter(|package| server_component_externals.contains(package))
.collect::<Vec<_>>();

if !conflicting_packages.is_empty() {
Expand All @@ -169,13 +169,13 @@ pub async fn get_server_resolve_options_context(
}

// Add the config's own list of external packages.
external_packages.extend(server_external_packages.iter().cloned());
external_packages.extend(server_component_externals.iter().cloned());

external_packages.retain(|item| !transpiled_packages.contains(item));

let ty = ty.into_value();

let server_external_packages_plugin = ExternalCjsModulesResolvePlugin::new(
let server_component_externals_plugin = ExternalCjsModulesResolvePlugin::new(
project_path,
project_path.root(),
ExternalPredicate::Only(Vc::cell(external_packages)).cell(),
Expand All @@ -196,8 +196,8 @@ pub async fn get_server_resolve_options_context(
custom_conditions.push("react-server".into());
};

let external_cjs_modules_plugin = if *next_config.bundle_pages_router_dependencies().await? {
server_external_packages_plugin
let external_cjs_modules_plugin = if *next_config.bundle_pages_externals().await? {
server_component_externals_plugin
} else {
ExternalCjsModulesResolvePlugin::new(
project_path,
Expand Down Expand Up @@ -244,7 +244,7 @@ pub async fn get_server_resolve_options_context(
| ServerContextType::AppRoute { .. } => {
vec![
Vc::upcast(next_node_shared_runtime_plugin),
Vc::upcast(server_external_packages_plugin),
Vc::upcast(server_component_externals_plugin),
Vc::upcast(next_external_plugin),
]
}
Expand All @@ -254,7 +254,7 @@ pub async fn get_server_resolve_options_context(
ServerContextType::Instrumentation { .. } => {
vec![
Vc::upcast(next_node_shared_runtime_plugin),
Vc::upcast(server_external_packages_plugin),
Vc::upcast(server_component_externals_plugin),
Vc::upcast(next_external_plugin),
]
}
Expand Down
9 changes: 5 additions & 4 deletions crates/next-core/src/next_server/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,9 @@ impl AfterResolvePlugin for ExternalCjsModulesResolvePlugin {
"The request could not be resolved by Node.js from the importing module. The \
way Node.js resolves modules is slightly different from the way Next.js \
resolves modules. Next.js was able to resolve it, while Node.js would not be \
able to.\nTry to remove this package from serverExternalPackages.\nOr update \
the import side to use a compatible request that can be resolved by Node.js.",
able to.\nTry to remove this package from \
serverComponentsExternalPackages.\nOr update the import side to use a \
compatible request that can be resolved by Node.js.",
);
};
break result_from_original_location;
Expand Down Expand Up @@ -494,7 +495,7 @@ impl Issue for UnableToExternalize {
StyledString::Text("Package ".into()),
StyledString::Code(package),
StyledString::Text(" (".into()),
StyledString::Code("serverExternalPackages".into()),
StyledString::Code("serverComponentsExternalPackages".into()),
StyledString::Text(" or default list) can't be external".into()),
])
.cell())
Expand All @@ -518,7 +519,7 @@ impl Issue for UnableToExternalize {
StyledString::Text("The request ".into()),
StyledString::Code(self.request.clone()),
StyledString::Text(" matches ".into()),
StyledString::Code("serverExternalPackages".into()),
StyledString::Code("serverComponentsExternalPackages".into()),
StyledString::Text(" (or the default list), but it can't be external:".into()),
]),
StyledString::Line(vec![StyledString::Text(self.reason.clone())]),
Expand Down

0 comments on commit 8cc3957

Please sign in to comment.