Unverified Commit 4fba975c authored by Alexander Lyon's avatar Alexander Lyon Committed by GitHub

set up options / hooks to enable turbotrace (#72306)

Adds tracing settings to the various contexts that are used for nft

There are cases where we need to know whether tracing is useful, this PR sets up that state ahead of the next one(s) which actually take advantage of them.

Closes PACK-3377
parent 2484e93d
...@@ -73,6 +73,7 @@ use crate::{ ...@@ -73,6 +73,7 @@ use crate::{
}, },
font::create_font_manifest, font::create_font_manifest,
loadable_manifest::create_react_loadable_manifest, loadable_manifest::create_react_loadable_manifest,
nft_json::NftJsonAsset,
paths::{ paths::{
all_paths_in_root, all_server_paths, get_js_paths_from_root, get_paths_from_root, all_paths_in_root, all_server_paths, get_js_paths_from_root, get_paths_from_root,
get_wasm_paths_from_root, paths_to_bindings, wasm_paths_to_bindings, get_wasm_paths_from_root, paths_to_bindings, wasm_paths_to_bindings,
...@@ -1140,29 +1141,34 @@ impl AppEndpoint { ...@@ -1140,29 +1141,34 @@ impl AppEndpoint {
let app_entry_chunks_ref = app_entry_chunks.await?; let app_entry_chunks_ref = app_entry_chunks.await?;
server_assets.extend(app_entry_chunks_ref.iter().copied()); server_assets.extend(app_entry_chunks_ref.iter().copied());
if let (Some(client_references), Some(client_references_chunks)) = // these references are important for turbotrace
(client_references, client_references_chunks) let client_reference_manifest =
{ if let (Some(client_references), Some(client_references_chunks)) =
let entry_manifest = ClientReferenceManifest::build_output( (client_references, client_references_chunks)
node_root, {
client_relative_path, let entry_manifest = ClientReferenceManifest::build_output(
app_entry.original_name.clone(), node_root,
client_references, client_relative_path,
client_references_chunks, app_entry.original_name.clone(),
*app_entry_chunks, client_references,
Value::new(*app_entry_chunks_availability), client_references_chunks,
client_chunking_context, *app_entry_chunks,
ssr_chunking_context, Value::new(*app_entry_chunks_availability),
this.app_project.project().next_config(), client_chunking_context,
runtime, ssr_chunking_context,
) this.app_project.project().next_config(),
.to_resolved() runtime,
.await?; )
server_assets.insert(entry_manifest); .to_resolved()
if runtime == NextRuntime::Edge { .await?;
middleware_assets.push(entry_manifest); server_assets.insert(entry_manifest);
} if runtime == NextRuntime::Edge {
} middleware_assets.push(entry_manifest);
}
Some(entry_manifest)
} else {
None
};
let client_assets = OutputAssets::new(client_assets.iter().map(|asset| **asset).collect()); let client_assets = OutputAssets::new(client_assets.iter().map(|asset| **asset).collect());
...@@ -1348,6 +1354,26 @@ impl AppEndpoint { ...@@ -1348,6 +1354,26 @@ impl AppEndpoint {
); );
server_assets.extend(loadable_manifest_output.await?.iter().copied()); server_assets.extend(loadable_manifest_output.await?.iter().copied());
if this
.app_project
.project()
.next_mode()
.await?
.is_production()
{
server_assets.insert(ResolvedVc::upcast(
NftJsonAsset::new(
*rsc_chunk,
this.app_project.project().output_fs(),
this.app_project.project().project_fs(),
this.app_project.project().client_fs(),
client_reference_manifest.iter().map(|m| **m).collect(),
)
.to_resolved()
.await?,
));
}
AppEndpointOutput::NodeJs { AppEndpointOutput::NodeJs {
rsc_chunk, rsc_chunk,
server_assets: Vc::cell(server_assets.iter().cloned().collect::<Vec<_>>()), server_assets: Vc::cell(server_assets.iter().cloned().collect::<Vec<_>>()),
......
...@@ -524,6 +524,11 @@ pub async fn get_server_module_options_context( ...@@ -524,6 +524,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().await?.clone_value(), side_effect_free_packages: next_config.optimize_package_imports().await?.clone_value(),
enable_externals_tracing: if next_mode.is_production() {
Some(project_path)
} else {
None
},
..Default::default() ..Default::default()
}; };
...@@ -965,7 +970,8 @@ pub async fn get_server_chunking_context_with_client_assets( ...@@ -965,7 +970,8 @@ pub async fn get_server_chunking_context_with_client_assets(
} else { } else {
MinifyType::NoMinify MinifyType::NoMinify
}) })
.module_id_strategy(module_id_strategy); .module_id_strategy(module_id_strategy)
.file_tracing(next_mode.is_production());
if next_mode.is_development() { if next_mode.is_development() {
builder = builder.use_file_source_map_uris(); builder = builder.use_file_source_map_uris();
...@@ -1000,7 +1006,8 @@ pub async fn get_server_chunking_context( ...@@ -1000,7 +1006,8 @@ pub async fn get_server_chunking_context(
} else { } else {
MinifyType::NoMinify MinifyType::NoMinify
}) })
.module_id_strategy(module_id_strategy); .module_id_strategy(module_id_strategy)
.file_tracing(next_mode.is_production());
if next_mode.is_development() { if next_mode.is_development() {
builder = builder.use_file_source_map_uris() builder = builder.use_file_source_map_uris()
......
...@@ -48,6 +48,11 @@ impl BrowserChunkingContextBuilder { ...@@ -48,6 +48,11 @@ impl BrowserChunkingContextBuilder {
self self
} }
pub fn tracing(mut self, enable_tracing: bool) -> Self {
self.chunking_context.enable_tracing = enable_tracing;
self
}
pub fn asset_base_path(mut self, asset_base_path: Vc<Option<RcStr>>) -> Self { pub fn asset_base_path(mut self, asset_base_path: Vc<Option<RcStr>>) -> Self {
self.chunking_context.asset_base_path = asset_base_path; self.chunking_context.asset_base_path = asset_base_path;
self self
...@@ -128,6 +133,8 @@ pub struct BrowserChunkingContext { ...@@ -128,6 +133,8 @@ pub struct BrowserChunkingContext {
asset_base_path: Vc<Option<RcStr>>, asset_base_path: Vc<Option<RcStr>>,
/// Enable HMR for this chunking /// Enable HMR for this chunking
enable_hot_module_replacement: bool, enable_hot_module_replacement: bool,
/// Enable tracing for this chunking
enable_tracing: bool,
/// The environment chunks will be evaluated in. /// The environment chunks will be evaluated in.
environment: Vc<Environment>, environment: Vc<Environment>,
/// The kind of runtime to include in the output. /// The kind of runtime to include in the output.
...@@ -164,6 +171,7 @@ impl BrowserChunkingContext { ...@@ -164,6 +171,7 @@ impl BrowserChunkingContext {
chunk_base_path: Default::default(), chunk_base_path: Default::default(),
asset_base_path: Default::default(), asset_base_path: Default::default(),
enable_hot_module_replacement: false, enable_hot_module_replacement: false,
enable_tracing: false,
environment, environment,
runtime_type, runtime_type,
minify_type: MinifyType::NoMinify, minify_type: MinifyType::NoMinify,
...@@ -363,6 +371,11 @@ impl ChunkingContext for BrowserChunkingContext { ...@@ -363,6 +371,11 @@ impl ChunkingContext for BrowserChunkingContext {
Vc::cell(self.should_use_file_source_map_uris) Vc::cell(self.should_use_file_source_map_uris)
} }
#[turbo_tasks::function]
fn is_tracing_enabled(&self) -> Vc<bool> {
Vc::cell(self.enable_tracing)
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn chunk_group( async fn chunk_group(
self: Vc<Self>, self: Vc<Self>,
......
...@@ -84,6 +84,10 @@ pub trait ChunkingContext { ...@@ -84,6 +84,10 @@ pub trait ChunkingContext {
Vc::cell(false) Vc::cell(false)
} }
fn is_tracing_enabled(self: Vc<Self>) -> Vc<bool> {
Vc::cell(false)
}
fn async_loader_chunk_item( fn async_loader_chunk_item(
&self, &self,
module: Vc<Box<dyn ChunkableModule>>, module: Vc<Box<dyn ChunkableModule>>,
......
...@@ -44,6 +44,11 @@ impl NodeJsChunkingContextBuilder { ...@@ -44,6 +44,11 @@ impl NodeJsChunkingContextBuilder {
self self
} }
pub fn file_tracing(mut self, enable_tracing: bool) -> Self {
self.chunking_context.enable_file_tracing = enable_tracing;
self
}
pub fn runtime_type(mut self, runtime_type: RuntimeType) -> Self { pub fn runtime_type(mut self, runtime_type: RuntimeType) -> Self {
self.chunking_context.runtime_type = runtime_type; self.chunking_context.runtime_type = runtime_type;
self self
...@@ -91,6 +96,8 @@ pub struct NodeJsChunkingContext { ...@@ -91,6 +96,8 @@ pub struct NodeJsChunkingContext {
environment: Vc<Environment>, environment: Vc<Environment>,
/// The kind of runtime to include in the output. /// The kind of runtime to include in the output.
runtime_type: RuntimeType, runtime_type: RuntimeType,
/// Enable tracing for this chunking
enable_file_tracing: bool,
/// Whether to minify resulting chunks /// Whether to minify resulting chunks
minify_type: MinifyType, minify_type: MinifyType,
/// Whether to use manifest chunks for lazy compilation /// Whether to use manifest chunks for lazy compilation
...@@ -120,6 +127,7 @@ impl NodeJsChunkingContext { ...@@ -120,6 +127,7 @@ impl NodeJsChunkingContext {
chunk_root_path, chunk_root_path,
asset_root_path, asset_root_path,
asset_prefix: Default::default(), asset_prefix: Default::default(),
enable_file_tracing: false,
environment, environment,
runtime_type, runtime_type,
minify_type: MinifyType::NoMinify, minify_type: MinifyType::NoMinify,
...@@ -201,6 +209,11 @@ impl ChunkingContext for NodeJsChunkingContext { ...@@ -201,6 +209,11 @@ impl ChunkingContext for NodeJsChunkingContext {
self.environment self.environment
} }
#[turbo_tasks::function]
fn is_tracing_enabled(&self) -> Vc<bool> {
Vc::cell(self.enable_file_tracing)
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn asset_url(self: Vc<Self>, ident: Vc<AssetIdent>) -> Result<Vc<RcStr>> { async fn asset_url(self: Vc<Self>, ident: Vc<AssetIdent>) -> Result<Vc<RcStr>> {
let this = self.await?; let this = self.await?;
......
...@@ -319,6 +319,9 @@ pub struct ModuleAssetContext { ...@@ -319,6 +319,9 @@ pub struct ModuleAssetContext {
pub resolve_options_context: Vc<ResolveOptionsContext>, pub resolve_options_context: Vc<ResolveOptionsContext>,
pub layer: Vc<RcStr>, pub layer: Vc<RcStr>,
transition: Option<ResolvedVc<Box<dyn Transition>>>, transition: Option<ResolvedVc<Box<dyn Transition>>>,
/// Whether to replace external resolutions with CachedExternalModules. Used with
/// ModuleOptionsContext.enable_externals_tracing to handle transitive external dependencies.
replace_externals: bool,
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
...@@ -338,6 +341,7 @@ impl ModuleAssetContext { ...@@ -338,6 +341,7 @@ impl ModuleAssetContext {
resolve_options_context, resolve_options_context,
transition: None, transition: None,
layer, layer,
replace_externals: true,
}) })
} }
...@@ -357,6 +361,26 @@ impl ModuleAssetContext { ...@@ -357,6 +361,26 @@ impl ModuleAssetContext {
resolve_options_context, resolve_options_context,
layer, layer,
transition: Some(transition), transition: Some(transition),
replace_externals: true,
})
}
#[turbo_tasks::function]
fn new_without_replace_externals(
transitions: Vc<TransitionOptions>,
compile_time_info: Vc<CompileTimeInfo>,
module_options_context: Vc<ModuleOptionsContext>,
resolve_options_context: Vc<ResolveOptionsContext>,
layer: Vc<RcStr>,
) -> Vc<Self> {
Self::cell(ModuleAssetContext {
transitions,
compile_time_info,
module_options_context,
resolve_options_context,
transition: None,
layer,
replace_externals: false,
}) })
} }
......
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use turbo_tasks::{trace::TraceRawVcs, FxIndexMap, RcStr, ResolvedVc, ValueDefault, Vc}; use turbo_tasks::{trace::TraceRawVcs, FxIndexMap, RcStr, ResolvedVc, ValueDefault, Vc};
use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{ use turbopack_core::{
chunk::MinifyType, condition::ContextCondition, environment::Environment, chunk::MinifyType, condition::ContextCondition, environment::Environment,
resolve::options::ImportMapping, resolve::options::ImportMapping,
...@@ -124,6 +125,13 @@ pub struct ModuleOptionsContext { ...@@ -124,6 +125,13 @@ pub struct ModuleOptionsContext {
pub side_effect_free_packages: Vec<RcStr>, pub side_effect_free_packages: Vec<RcStr>,
pub tree_shaking_mode: Option<TreeShakingMode>, pub tree_shaking_mode: Option<TreeShakingMode>,
/// Generate (non-emitted) output assets for static assets and externals, to facilitate
/// generating a list of all non-bundled files that will be required at runtime.
///
/// The filepath is the directory from which the bundled files will require the externals at
/// runtime.
pub enable_externals_tracing: Option<Vc<FileSystemPath>>,
/// Custom rules to be applied after all default rules. /// Custom rules to be applied after all default rules.
pub module_rules: Vec<ModuleRule>, pub module_rules: Vec<ModuleRule>,
/// A list of rules to use a different module option context for certain /// A list of rules to use a different module option context for certain
......
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