Unverified Commit a12283e5 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: mode to disable tracing (#83683)

This means that the default is `TracingMode::Bundling` which has no tracing.

This is what you want for most normal bundler use cases, and what we want for our execution contexts for the Node.js loader runners.

This should help with #83613
parent 743d7a17
...@@ -28,7 +28,7 @@ use turbopack_core::{ ...@@ -28,7 +28,7 @@ use turbopack_core::{
module_graph::export_usage::OptionExportUsageInfo, module_graph::export_usage::OptionExportUsageInfo,
resolve::{parse::Request, pattern::Pattern}, resolve::{parse::Request, pattern::Pattern},
}; };
use turbopack_ecmascript::{TypeofWindow, chunk::EcmascriptChunkType}; use turbopack_ecmascript::{AnalyzeMode, TypeofWindow, chunk::EcmascriptChunkType};
use turbopack_node::{ use turbopack_node::{
execution_context::ExecutionContext, execution_context::ExecutionContext,
transforms::postcss::{PostCssConfigLocation, PostCssTransformOptions}, transforms::postcss::{PostCssConfigLocation, PostCssTransformOptions},
...@@ -337,6 +337,14 @@ pub async fn get_client_module_options_context( ...@@ -337,6 +337,14 @@ pub async fn get_client_module_options_context(
enable_postcss_transform, enable_postcss_transform,
side_effect_free_packages: next_config.optimize_package_imports().owned().await?, side_effect_free_packages: next_config.optimize_package_imports().owned().await?,
keep_last_successful_parse: next_mode.is_development(), keep_last_successful_parse: next_mode.is_development(),
analyze_mode: if next_mode.is_development() {
AnalyzeMode::CodeGeneration
} else {
// Technically, this doesn't need to tracing for the client context. But this will
// result in more cache hits for the analysis for modules which are loaded for both ssr
// and client
AnalyzeMode::CodeGenerationAndTracing
},
..Default::default() ..Default::default()
}; };
......
...@@ -27,7 +27,7 @@ use turbopack_core::{ ...@@ -27,7 +27,7 @@ use turbopack_core::{
target::CompileTarget, target::CompileTarget,
}; };
use turbopack_ecmascript::{ use turbopack_ecmascript::{
TypeofWindow, chunk::EcmascriptChunkType, references::esm::UrlRewriteBehavior, AnalyzeMode, TypeofWindow, chunk::EcmascriptChunkType, 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,
...@@ -592,6 +592,11 @@ pub async fn get_server_module_options_context( ...@@ -592,6 +592,11 @@ pub async fn get_server_module_options_context(
}, },
tree_shaking_mode: tree_shaking_mode_for_user_code, tree_shaking_mode: tree_shaking_mode_for_user_code,
side_effect_free_packages: next_config.optimize_package_imports().owned().await?, side_effect_free_packages: next_config.optimize_package_imports().owned().await?,
analyze_mode: if next_mode.is_development() {
AnalyzeMode::CodeGeneration
} else {
AnalyzeMode::CodeGenerationAndTracing
},
enable_externals_tracing: if next_mode.is_production() { enable_externals_tracing: if next_mode.is_production() {
Some( Some(
ExternalsTracingOptions { ExternalsTracingOptions {
......
...@@ -17,11 +17,14 @@ use turbopack_core::{ ...@@ -17,11 +17,14 @@ use turbopack_core::{
environment::{Environment, ExecutionEnvironment, NodeJsEnvironment, NodeJsVersion}, environment::{Environment, ExecutionEnvironment, NodeJsEnvironment, NodeJsVersion},
target::CompileTarget, target::CompileTarget,
}; };
use turbopack_ecmascript::analyzer::{ use turbopack_ecmascript::{
graph::{EvalContext, VarGraph, VarMeta, create_graph}, AnalyzeMode,
imports::ImportAttributes, analyzer::{
linker::link, graph::{EvalContext, VarGraph, VarMeta, create_graph},
test_utils::{early_visitor, visitor}, imports::ImportAttributes,
linker::link,
test_utils::{early_visitor, visitor},
},
}; };
pub fn benchmark(c: &mut Criterion) { pub fn benchmark(c: &mut Criterion) {
...@@ -62,7 +65,11 @@ pub fn benchmark(c: &mut Criterion) { ...@@ -62,7 +65,11 @@ pub fn benchmark(c: &mut Criterion) {
None, None,
None, None,
); );
let var_graph = create_graph(&program, &eval_context, false); let var_graph = create_graph(
&program,
&eval_context,
AnalyzeMode::CodeGenerationAndTracing,
);
let input = BenchInput { let input = BenchInput {
program, program,
...@@ -88,7 +95,13 @@ struct BenchInput { ...@@ -88,7 +95,13 @@ struct BenchInput {
} }
fn bench_create_graph(b: &mut Bencher, input: &BenchInput) { fn bench_create_graph(b: &mut Bencher, input: &BenchInput) {
b.iter(|| create_graph(&input.program, &input.eval_context, false)); b.iter(|| {
create_graph(
&input.program,
&input.eval_context,
AnalyzeMode::CodeGenerationAndTracing,
)
});
} }
fn bench_link(b: &mut Bencher, input: &BenchInput) { fn bench_link(b: &mut Bencher, input: &BenchInput) {
......
...@@ -50,7 +50,7 @@ pub fn benchmark(c: &mut Criterion) { ...@@ -50,7 +50,7 @@ pub fn benchmark(c: &mut Criterion) {
.resolved_cell(); .resolved_cell();
let mut cases = vec![]; let mut cases = vec![];
for (file, is_tracing) in [ for (file, analyze_mode) in [
(r#"packages-bundle.js"#, false), (r#"packages-bundle.js"#, false),
(r#"packages-bundle.js"#, true), (r#"packages-bundle.js"#, true),
(r#"app-page-turbo.runtime.prod.js"#, false), (r#"app-page-turbo.runtime.prod.js"#, false),
...@@ -68,7 +68,11 @@ pub fn benchmark(c: &mut Criterion) { ...@@ -68,7 +68,11 @@ pub fn benchmark(c: &mut Criterion) {
EcmascriptInputTransforms::empty().to_resolved().await?, EcmascriptInputTransforms::empty().to_resolved().await?,
EcmascriptOptions { EcmascriptOptions {
tree_shaking_mode: Some(TreeShakingMode::ReexportsOnly), tree_shaking_mode: Some(TreeShakingMode::ReexportsOnly),
is_tracing, analyze_mode: if analyze_mode {
turbopack_ecmascript::AnalyzeMode::Tracing
} else {
turbopack_ecmascript::AnalyzeMode::CodeGenerationAndTracing
},
..Default::default() ..Default::default()
} }
.resolved_cell(), .resolved_cell(),
...@@ -80,7 +84,7 @@ pub fn benchmark(c: &mut Criterion) { ...@@ -80,7 +84,7 @@ pub fn benchmark(c: &mut Criterion) {
cases.push(( cases.push((
file.rsplit("/").next().unwrap(), file.rsplit("/").next().unwrap(),
if is_tracing { "tracing" } else { "full" }, if analyze_mode { "tracing" } else { "full" },
module, module,
)); ));
} }
......
...@@ -29,7 +29,7 @@ use super::{ ...@@ -29,7 +29,7 @@ use super::{
is_unresolved_id, is_unresolved_id,
}; };
use crate::{ use crate::{
SpecifiedModuleType, AnalyzeMode, SpecifiedModuleType,
analyzer::{WellKnownObjectKind, is_unresolved}, analyzer::{WellKnownObjectKind, is_unresolved},
references::constant_value::parse_single_expr_lit, references::constant_value::parse_single_expr_lit,
utils::{AstPathRange, unparen}, utils::{AstPathRange, unparen},
...@@ -330,7 +330,11 @@ impl VarGraph { ...@@ -330,7 +330,11 @@ impl VarGraph {
/// You should use same [Mark] for this function and /// You should use same [Mark] for this function and
/// [swc_ecma_transforms_base::resolver::resolver_with_mark] /// [swc_ecma_transforms_base::resolver::resolver_with_mark]
pub fn create_graph(m: &Program, eval_context: &EvalContext, is_tracing: bool) -> VarGraph { pub fn create_graph(
m: &Program,
eval_context: &EvalContext,
analyze_mode: AnalyzeMode,
) -> VarGraph {
let mut graph = VarGraph { let mut graph = VarGraph {
values: Default::default(), values: Default::default(),
free_var_ids: Default::default(), free_var_ids: Default::default(),
...@@ -339,7 +343,7 @@ pub fn create_graph(m: &Program, eval_context: &EvalContext, is_tracing: bool) - ...@@ -339,7 +343,7 @@ pub fn create_graph(m: &Program, eval_context: &EvalContext, is_tracing: bool) -
m.visit_with_ast_path( m.visit_with_ast_path(
&mut Analyzer { &mut Analyzer {
is_tracing, analyze_mode,
data: &mut graph, data: &mut graph,
state: analyzer_state::AnalyzerState::new(), state: analyzer_state::AnalyzerState::new(),
eval_context, eval_context,
...@@ -860,7 +864,7 @@ pub fn as_parent_path_skip( ...@@ -860,7 +864,7 @@ pub fn as_parent_path_skip(
} }
struct Analyzer<'a> { struct Analyzer<'a> {
is_tracing: bool, analyze_mode: AnalyzeMode,
data: &'a mut VarGraph, data: &'a mut VarGraph,
state: analyzer_state::AnalyzerState, state: analyzer_state::AnalyzerState,
...@@ -1467,7 +1471,7 @@ impl Analyzer<'_> { ...@@ -1467,7 +1471,7 @@ impl Analyzer<'_> {
member_expr: &'ast MemberExpr, member_expr: &'ast MemberExpr,
ast_path: &AstNodePath<AstParentNodeRef<'r>>, ast_path: &AstNodePath<AstParentNodeRef<'r>>,
) { ) {
if self.is_tracing { if !self.analyze_mode.is_code_gen() {
return; return;
} }
...@@ -1501,7 +1505,7 @@ impl Analyzer<'_> { ...@@ -1501,7 +1505,7 @@ impl Analyzer<'_> {
start_ast_path, start_ast_path,
} => { } => {
self.effects = prev_effects; self.effects = prev_effects;
if !self.is_tracing { if self.analyze_mode.is_code_gen() {
self.effects.push(Effect::Unreachable { start_ast_path }); self.effects.push(Effect::Unreachable { start_ast_path });
} }
always_returns = true; always_returns = true;
...@@ -2229,7 +2233,7 @@ impl VisitAstPath for Analyzer<'_> { ...@@ -2229,7 +2233,7 @@ impl VisitAstPath for Analyzer<'_> {
} }
// If this identifier is free, produce an effect so we can potentially replace it later. // If this identifier is free, produce an effect so we can potentially replace it later.
if !self.is_tracing if self.analyze_mode.is_code_gen()
&& let JsValue::FreeVar(var) = self.eval_context.eval_ident(ident) && let JsValue::FreeVar(var) = self.eval_context.eval_ident(ident)
{ {
// TODO(lukesandberg): we should consider filtering effects here, e.g. there is no // TODO(lukesandberg): we should consider filtering effects here, e.g. there is no
...@@ -2267,7 +2271,7 @@ impl VisitAstPath for Analyzer<'_> { ...@@ -2267,7 +2271,7 @@ impl VisitAstPath for Analyzer<'_> {
return; return;
} }
if !self.is_tracing { if self.analyze_mode.is_code_gen() {
// Otherwise 'this' is free // Otherwise 'this' is free
self.add_effect(Effect::FreeVar { self.add_effect(Effect::FreeVar {
var: atom!("this"), var: atom!("this"),
...@@ -2282,7 +2286,7 @@ impl VisitAstPath for Analyzer<'_> { ...@@ -2282,7 +2286,7 @@ impl VisitAstPath for Analyzer<'_> {
expr: &'ast MetaPropExpr, expr: &'ast MetaPropExpr,
ast_path: &mut AstNodePath<AstParentNodeRef<'r>>, ast_path: &mut AstNodePath<AstParentNodeRef<'r>>,
) { ) {
if !self.is_tracing && expr.kind == MetaPropKind::ImportMeta { if self.analyze_mode.is_code_gen() && expr.kind == MetaPropKind::ImportMeta {
// MetaPropExpr also covers `new.target`. Only consider `import.meta` // MetaPropExpr also covers `new.target`. Only consider `import.meta`
// an effect. // an effect.
self.add_effect(Effect::ImportMeta { self.add_effect(Effect::ImportMeta {
...@@ -2533,7 +2537,7 @@ impl VisitAstPath for Analyzer<'_> { ...@@ -2533,7 +2537,7 @@ impl VisitAstPath for Analyzer<'_> {
n: &'ast UnaryExpr, n: &'ast UnaryExpr,
ast_path: &mut swc_core::ecma::visit::AstNodePath<'r>, ast_path: &mut swc_core::ecma::visit::AstNodePath<'r>,
) { ) {
if n.op == UnaryOp::TypeOf && !self.is_tracing { if n.op == UnaryOp::TypeOf && self.analyze_mode.is_code_gen() {
let arg_value = Box::new(self.eval_context.eval(&n.arg)); let arg_value = Box::new(self.eval_context.eval(&n.arg));
self.add_effect(Effect::TypeOf { self.add_effect(Effect::TypeOf {
......
...@@ -3813,9 +3813,12 @@ mod tests { ...@@ -3813,9 +3813,12 @@ mod tests {
graph::{ConditionalKind, Effect, EffectArg, EvalContext, VarGraph, create_graph}, graph::{ConditionalKind, Effect, EffectArg, EvalContext, VarGraph, create_graph},
linker::link, linker::link,
}; };
use crate::analyzer::{ use crate::{
graph::{AssignmentScopes, VarMeta}, AnalyzeMode,
imports::ImportAttributes, analyzer::{
graph::{AssignmentScopes, VarMeta},
imports::ImportAttributes,
},
}; };
#[fixture("tests/analyzer/graph/**/input.js")] #[fixture("tests/analyzer/graph/**/input.js")]
...@@ -3857,7 +3860,8 @@ mod tests { ...@@ -3857,7 +3860,8 @@ mod tests {
None, None,
); );
let mut var_graph = create_graph(&m, &eval_context, false); let mut var_graph =
create_graph(&m, &eval_context, AnalyzeMode::CodeGenerationAndTracing);
let var_cache = Default::default(); let var_cache = Default::default();
let mut named_values = var_graph let mut named_values = var_graph
......
...@@ -173,6 +173,48 @@ pub enum TreeShakingMode { ...@@ -173,6 +173,48 @@ pub enum TreeShakingMode {
ReexportsOnly, ReexportsOnly,
} }
#[derive(
PartialOrd,
Ord,
PartialEq,
Eq,
Hash,
Debug,
Clone,
Copy,
Default,
Serialize,
Deserialize,
TaskInput,
TraceRawVcs,
NonLocalValue,
)]
pub enum AnalyzeMode {
/// For bundling only, no tracing of referenced files.
#[default]
CodeGeneration,
/// For bundling and tracing of referenced files.
CodeGenerationAndTracing,
/// For tracing of referenced files only, no bundling (i.e. no codegen).
Tracing,
}
impl AnalyzeMode {
pub fn is_tracing(self) -> bool {
match self {
AnalyzeMode::Tracing | AnalyzeMode::CodeGenerationAndTracing => true,
AnalyzeMode::CodeGeneration => false,
}
}
pub fn is_code_gen(self) -> bool {
match self {
AnalyzeMode::CodeGeneration | AnalyzeMode::CodeGenerationAndTracing => true,
AnalyzeMode::Tracing => false,
}
}
}
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
pub struct OptionTreeShaking(pub Option<TreeShakingMode>); pub struct OptionTreeShaking(pub Option<TreeShakingMode>);
...@@ -222,7 +264,7 @@ pub struct EcmascriptOptions { ...@@ -222,7 +264,7 @@ pub struct EcmascriptOptions {
pub keep_last_successful_parse: bool, pub keep_last_successful_parse: bool,
/// Whether the modules in this context are never chunked/codegen-ed, but only used for /// Whether the modules in this context are never chunked/codegen-ed, but only used for
/// tracing. /// tracing.
pub is_tracing: bool, pub analyze_mode: AnalyzeMode,
// TODO this should just be handled via CompileTimeInfo FreeVarReferences, but then it // TODO this should just be handled via CompileTimeInfo FreeVarReferences, but then it
// (currently) wouldn't be possible to have different replacement values in user code vs // (currently) wouldn't be possible to have different replacement values in user code vs
// node_modules. // node_modules.
......
...@@ -84,7 +84,7 @@ impl Display for CachedExternalType { ...@@ -84,7 +84,7 @@ impl Display for CachedExternalType {
pub struct CachedExternalModule { pub struct CachedExternalModule {
request: RcStr, request: RcStr,
external_type: CachedExternalType, external_type: CachedExternalType,
tracing_mode: CachedExternalTracingMode, analyze_mode: CachedExternalTracingMode,
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
...@@ -93,12 +93,12 @@ impl CachedExternalModule { ...@@ -93,12 +93,12 @@ impl CachedExternalModule {
pub fn new( pub fn new(
request: RcStr, request: RcStr,
external_type: CachedExternalType, external_type: CachedExternalType,
tracing_mode: CachedExternalTracingMode, analyze_mode: CachedExternalTracingMode,
) -> Vc<Self> { ) -> Vc<Self> {
Self::cell(CachedExternalModule { Self::cell(CachedExternalModule {
request, request,
external_type, external_type,
tracing_mode, analyze_mode,
}) })
} }
...@@ -226,7 +226,7 @@ impl Module for CachedExternalModule { ...@@ -226,7 +226,7 @@ impl Module for CachedExternalModule {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(&self) -> Result<Vc<ModuleReferences>> { async fn references(&self) -> Result<Vc<ModuleReferences>> {
Ok(match &self.tracing_mode { Ok(match &self.analyze_mode {
CachedExternalTracingMode::Untraced => ModuleReferences::empty(), CachedExternalTracingMode::Untraced => ModuleReferences::empty(),
CachedExternalTracingMode::Traced { CachedExternalTracingMode::Traced {
externals_context, externals_context,
......
...@@ -6,6 +6,7 @@ use turbo_tasks::{ResolvedVc, TransientInstance, TryJoinIterExt, ValueToString, ...@@ -6,6 +6,7 @@ use turbo_tasks::{ResolvedVc, TransientInstance, TryJoinIterExt, ValueToString,
use turbo_tasks_fs::{DiskFileSystem, FileSystem}; use turbo_tasks_fs::{DiskFileSystem, FileSystem};
use turbopack::{ use turbopack::{
ModuleAssetContext, ModuleAssetContext,
ecmascript::AnalyzeMode,
module_options::{ module_options::{
CssOptionsContext, EcmascriptOptionsContext, ModuleOptionsContext, CssOptionsContext, EcmascriptOptionsContext, ModuleOptionsContext,
TypescriptTransformOptions, TypescriptTransformOptions,
...@@ -95,7 +96,7 @@ async fn node_file_trace_operation( ...@@ -95,7 +96,7 @@ async fn node_file_trace_operation(
// Environment is not passed in order to avoid downleveling JS / CSS for // Environment is not passed in order to avoid downleveling JS / CSS for
// node-file-trace. // node-file-trace.
environment: None, environment: None,
is_tracing: true, analyze_mode: AnalyzeMode::Tracing,
..Default::default() ..Default::default()
} }
.cell(), .cell(),
......
...@@ -20,7 +20,9 @@ use turbo_tasks_fs::{ ...@@ -20,7 +20,9 @@ use turbo_tasks_fs::{
use turbo_unix_path::sys_to_unix; use turbo_unix_path::sys_to_unix;
use turbopack::{ use turbopack::{
ModuleAssetContext, ModuleAssetContext,
ecmascript::{EcmascriptInputTransform, TreeShakingMode, chunk::EcmascriptChunkType}, ecmascript::{
AnalyzeMode, EcmascriptInputTransform, TreeShakingMode, chunk::EcmascriptChunkType,
},
module_options::{ module_options::{
EcmascriptOptionsContext, JsxTransformOptions, ModuleOptionsContext, ModuleRule, EcmascriptOptionsContext, JsxTransformOptions, ModuleOptionsContext, ModuleRule,
ModuleRuleEffect, RuleCondition, TypescriptTransformOptions, ModuleRuleEffect, RuleCondition, TypescriptTransformOptions,
...@@ -356,12 +358,14 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> { ...@@ -356,12 +358,14 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> {
ModuleOptionsContext { ModuleOptionsContext {
environment: Some(env), environment: Some(env),
tree_shaking_mode: options.tree_shaking_mode, tree_shaking_mode: options.tree_shaking_mode,
analyze_mode: AnalyzeMode::CodeGenerationAndTracing,
..Default::default() ..Default::default()
} }
.resolved_cell(), .resolved_cell(),
)], )],
module_rules: vec![module_rules], module_rules: vec![module_rules],
tree_shaking_mode: options.tree_shaking_mode, tree_shaking_mode: options.tree_shaking_mode,
analyze_mode: AnalyzeMode::CodeGenerationAndTracing,
..Default::default() ..Default::default()
} }
.into(), .into(),
......
...@@ -33,7 +33,9 @@ use turbo_tasks::{ ...@@ -33,7 +33,9 @@ use turbo_tasks::{
use turbo_tasks_backend::TurboTasksBackend; use turbo_tasks_backend::TurboTasksBackend;
use turbo_tasks_fs::{DiskFileSystem, FileSystem}; use turbo_tasks_fs::{DiskFileSystem, FileSystem};
use turbopack::{ use turbopack::{
ModuleAssetContext, emit_with_completion_operation, ModuleAssetContext,
ecmascript::AnalyzeMode,
emit_with_completion_operation,
module_options::{ module_options::{
CssOptionsContext, EcmascriptOptionsContext, ModuleOptionsContext, CssOptionsContext, EcmascriptOptionsContext, ModuleOptionsContext,
TypescriptTransformOptions, TypescriptTransformOptions,
...@@ -373,7 +375,7 @@ async fn node_file_trace_operation( ...@@ -373,7 +375,7 @@ async fn node_file_trace_operation(
// Environment is not passed in order to avoid downleveling JS / CSS for // Environment is not passed in order to avoid downleveling JS / CSS for
// node-file-trace. // node-file-trace.
environment: None, environment: None,
is_tracing: true, analyze_mode: AnalyzeMode::Tracing,
..Default::default() ..Default::default()
} }
.cell(), .cell(),
......
...@@ -15,6 +15,7 @@ use turbo_tasks_backend::TurboTasksBackend; ...@@ -15,6 +15,7 @@ use turbo_tasks_backend::TurboTasksBackend;
use turbo_tasks_fs::{DiskFileSystem, FileSystem}; use turbo_tasks_fs::{DiskFileSystem, FileSystem};
use turbopack::{ use turbopack::{
ModuleAssetContext, ModuleAssetContext,
ecmascript::AnalyzeMode,
module_options::{ module_options::{
CssOptionsContext, EcmascriptOptionsContext, ModuleOptionsContext, CssOptionsContext, EcmascriptOptionsContext, ModuleOptionsContext,
TypescriptTransformOptions, TypescriptTransformOptions,
...@@ -210,7 +211,7 @@ async fn node_file_trace_operation(package_root: RcStr, input: RcStr) -> Result< ...@@ -210,7 +211,7 @@ async fn node_file_trace_operation(package_root: RcStr, input: RcStr) -> Result<
// Environment is not passed in order to avoid downleveling JS / CSS for // Environment is not passed in order to avoid downleveling JS / CSS for
// node-file-trace. // node-file-trace.
environment: None, environment: None,
is_tracing: true, analyze_mode: AnalyzeMode::Tracing,
..Default::default() ..Default::default()
} }
.cell(), .cell(),
......
...@@ -56,6 +56,7 @@ use turbopack_core::{ ...@@ -56,6 +56,7 @@ use turbopack_core::{
pub use turbopack_css as css; pub use turbopack_css as css;
pub use turbopack_ecmascript as ecmascript; pub use turbopack_ecmascript as ecmascript;
use turbopack_ecmascript::{ use turbopack_ecmascript::{
AnalyzeMode,
inlined_bytes_module::InlinedBytesJsModule, inlined_bytes_module::InlinedBytesJsModule,
references::external_module::{ references::external_module::{
CachedExternalModule, CachedExternalTracingMode, CachedExternalType, CachedExternalModule, CachedExternalTracingMode, CachedExternalType,
...@@ -719,7 +720,7 @@ pub async fn externals_tracing_module_context( ...@@ -719,7 +720,7 @@ pub async fn externals_tracing_module_context(
// Environment is not passed in order to avoid downleveling JS / CSS for // Environment is not passed in order to avoid downleveling JS / CSS for
// node-file-trace. // node-file-trace.
environment: None, environment: None,
is_tracing: true, analyze_mode: AnalyzeMode::Tracing,
..Default::default() ..Default::default()
} }
.cell(), .cell(),
...@@ -824,7 +825,7 @@ impl AssetContext for ModuleAssetContext { ...@@ -824,7 +825,7 @@ impl AssetContext for ModuleAssetContext {
} }
ResolveResultItem::External { name, ty, traced } => { ResolveResultItem::External { name, ty, traced } => {
let replacement = if replace_externals { let replacement = if replace_externals {
let tracing_mode = if traced == ExternalTraced::Traced let analyze_mode = if traced == ExternalTraced::Traced
&& let Some(options) = &self && let Some(options) = &self
.module_options_context() .module_options_context()
.await? .await?
...@@ -850,7 +851,7 @@ impl AssetContext for ModuleAssetContext { ...@@ -850,7 +851,7 @@ impl AssetContext for ModuleAssetContext {
CachedExternalTracingMode::Untraced CachedExternalTracingMode::Untraced
}; };
replace_external(&name, ty, import_externals, tracing_mode).await? replace_external(&name, ty, import_externals, analyze_mode).await?
} else { } else {
None None
}; };
...@@ -1003,7 +1004,7 @@ pub async fn replace_external( ...@@ -1003,7 +1004,7 @@ pub async fn replace_external(
name: &RcStr, name: &RcStr,
ty: ExternalType, ty: ExternalType,
import_externals: bool, import_externals: bool,
tracing_mode: CachedExternalTracingMode, analyze_mode: CachedExternalTracingMode,
) -> Result<Option<ModuleResolveResultItem>> { ) -> Result<Option<ModuleResolveResultItem>> {
let external_type = match ty { let external_type = match ty {
ExternalType::CommonJs => CachedExternalType::CommonJs, ExternalType::CommonJs => CachedExternalType::CommonJs,
...@@ -1022,7 +1023,7 @@ pub async fn replace_external( ...@@ -1022,7 +1023,7 @@ pub async fn replace_external(
} }
}; };
let module = CachedExternalModule::new(name.clone(), external_type, tracing_mode) let module = CachedExternalModule::new(name.clone(), external_type, analyze_mode)
.to_resolved() .to_resolved()
.await?; .await?;
......
...@@ -227,7 +227,7 @@ impl ModuleOptions { ...@@ -227,7 +227,7 @@ impl ModuleOptions {
execution_context, execution_context,
tree_shaking_mode, tree_shaking_mode,
keep_last_successful_parse, keep_last_successful_parse,
is_tracing, analyze_mode,
.. ..
} = *module_options_context.await?; } = *module_options_context.await?;
...@@ -280,7 +280,7 @@ impl ModuleOptions { ...@@ -280,7 +280,7 @@ impl ModuleOptions {
ignore_dynamic_requests, ignore_dynamic_requests,
extract_source_map: matches!(ecmascript_source_maps, SourceMapsType::Full), extract_source_map: matches!(ecmascript_source_maps, SourceMapsType::Full),
keep_last_successful_parse, keep_last_successful_parse,
is_tracing, analyze_mode,
enable_typeof_window_inlining, enable_typeof_window_inlining,
..Default::default() ..Default::default()
}; };
......
...@@ -9,7 +9,9 @@ use turbopack_core::{ ...@@ -9,7 +9,9 @@ use turbopack_core::{
chunk::SourceMapsType, compile_time_info::CompileTimeInfo, condition::ContextCondition, chunk::SourceMapsType, compile_time_info::CompileTimeInfo, condition::ContextCondition,
environment::Environment, resolve::options::ImportMapping, environment::Environment, resolve::options::ImportMapping,
}; };
use turbopack_ecmascript::{TreeShakingMode, TypeofWindow, references::esm::UrlRewriteBehavior}; use turbopack_ecmascript::{
AnalyzeMode, TreeShakingMode, TypeofWindow, references::esm::UrlRewriteBehavior,
};
pub use turbopack_mdx::MdxTransformOptions; pub use turbopack_mdx::MdxTransformOptions;
use turbopack_node::{ use turbopack_node::{
execution_context::ExecutionContext, execution_context::ExecutionContext,
...@@ -207,7 +209,7 @@ pub struct ModuleOptionsContext { ...@@ -207,7 +209,7 @@ pub struct ModuleOptionsContext {
/// Whether the modules in this context are never chunked/codegen-ed, but only used for /// Whether the modules in this context are never chunked/codegen-ed, but only used for
/// tracing. /// tracing.
pub is_tracing: bool, pub analyze_mode: AnalyzeMode,
pub placeholder_for_future_extensions: (), pub placeholder_for_future_extensions: (),
} }
......
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