Unverified Commit 96a7efab authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

[Turbopack] allow to disable tree shaking (#71114)

### What?

This fixes `experimental.turbo.treeShaking: false` and allows to disable tree shaking
parent 39833fdf
...@@ -1140,15 +1140,25 @@ impl NextConfig { ...@@ -1140,15 +1140,25 @@ impl NextConfig {
} }
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn tree_shaking_mode_for_user_code( pub fn tree_shaking_mode_for_user_code(&self, is_development: bool) -> Vc<OptionTreeShaking> {
self: Vc<Self>, let tree_shaking = self
is_development: bool, .experimental
) -> Vc<OptionTreeShaking> { .turbo
Vc::cell(Some(if is_development { .as_ref()
TreeShakingMode::ReexportsOnly .and_then(|v| v.tree_shaking);
} else {
TreeShakingMode::ModuleFragments OptionTreeShaking(match tree_shaking {
})) Some(false) => Some(TreeShakingMode::ReexportsOnly),
Some(true) => Some(TreeShakingMode::ModuleFragments),
None => {
if is_development {
Some(TreeShakingMode::ReexportsOnly)
} else {
Some(TreeShakingMode::ModuleFragments)
}
}
})
.cell()
} }
#[turbo_tasks::function] #[turbo_tasks::function]
......
...@@ -23,7 +23,7 @@ use turbopack_core::{ ...@@ -23,7 +23,7 @@ use turbopack_core::{
environment::{Environment, ExecutionEnvironment, NodeJsEnvironment, RuntimeVersions}, environment::{Environment, ExecutionEnvironment, NodeJsEnvironment, RuntimeVersions},
free_var_references, free_var_references,
}; };
use turbopack_ecmascript::{references::esm::UrlRewriteBehavior, TreeShakingMode}; use turbopack_ecmascript::references::esm::UrlRewriteBehavior;
use turbopack_ecmascript_plugins::transform::directives::{ use turbopack_ecmascript_plugins::transform::directives::{
client::ClientDirectiveTransformer, client_disallowed::ClientDisallowedDirectiveTransformer, client::ClientDirectiveTransformer, client_disallowed::ClientDisallowedDirectiveTransformer,
}; };
...@@ -898,20 +898,6 @@ pub async fn get_server_module_options_context( ...@@ -898,20 +898,6 @@ pub async fn get_server_module_options_context(
Ok(module_options_context) Ok(module_options_context)
} }
#[turbo_tasks::function]
pub fn get_build_module_options_context() -> Vc<ModuleOptionsContext> {
ModuleOptionsContext {
ecmascript: EcmascriptOptionsContext {
enable_typescript_transform: Some(Default::default()),
esm_url_rewrite_behavior: Some(UrlRewriteBehavior::Full),
..Default::default()
},
tree_shaking_mode: Some(TreeShakingMode::ModuleFragments),
..Default::default()
}
.cell()
}
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn get_server_runtime_entries( pub fn get_server_runtime_entries(
_ty: Value<ServerContextType>, _ty: Value<ServerContextType>,
......
...@@ -230,7 +230,9 @@ async fn apply_module_type( ...@@ -230,7 +230,9 @@ async fn apply_module_type(
} }
} }
_ => bail!( _ => bail!(
"Invalid module part for reexports only tree shaking mode" "Invalid module part \"{}\" for reexports only tree shaking \
mode",
part.to_string().await?
), ),
} }
} else if *module.get_exports().needs_facade().await? { } else if *module.get_exports().needs_facade().await? {
......
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