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 {
}
#[turbo_tasks::function]
pub fn tree_shaking_mode_for_user_code(
self: Vc<Self>,
is_development: bool,
) -> Vc<OptionTreeShaking> {
Vc::cell(Some(if is_development {
TreeShakingMode::ReexportsOnly
} else {
TreeShakingMode::ModuleFragments
}))
pub fn tree_shaking_mode_for_user_code(&self, is_development: bool) -> Vc<OptionTreeShaking> {
let tree_shaking = self
.experimental
.turbo
.as_ref()
.and_then(|v| v.tree_shaking);
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]
......
......@@ -23,7 +23,7 @@ use turbopack_core::{
environment::{Environment, ExecutionEnvironment, NodeJsEnvironment, RuntimeVersions},
free_var_references,
};
use turbopack_ecmascript::{references::esm::UrlRewriteBehavior, TreeShakingMode};
use turbopack_ecmascript::references::esm::UrlRewriteBehavior;
use turbopack_ecmascript_plugins::transform::directives::{
client::ClientDirectiveTransformer, client_disallowed::ClientDisallowedDirectiveTransformer,
};
......@@ -898,20 +898,6 @@ pub async fn get_server_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]
pub fn get_server_runtime_entries(
_ty: Value<ServerContextType>,
......
......@@ -230,7 +230,9 @@ async fn apply_module_type(
}
}
_ => 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? {
......
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