Unverified Commit 34647db2 authored by Andrew Imm's avatar Andrew Imm Committed by GitHub

Turbopack: add webpack loader names to traces (#87230)

When examining the long trace this morning, it wasn't immediately clear
what was running in the shell-out to Node.
This doesn't fully fix the issue, but it makes it clearer which webpack
loader is running, similar to how the PostCSS loader lists the name of
the css file it's parsing.

In this trace, the next config contains:
```
  turbopack: {
    rules: {
      "**/*.{js,jsx,ts,tsx}": {
        loaders: ["./loader_test.js"],
      },
    },
  },
```

And the trace renders as:

<img width="995" height="553" alt="Screenshot 2025-12-15 at 11 22 39 PM"
src="https://github.com/user-attachments/assets/b0936e2e-f9d5-45fc-8a1c-2f98b1aa38b6"
/>
parent 299e1ff3
...@@ -67,3 +67,18 @@ impl TaskInput for ResolvedWebpackLoaderItem { ...@@ -67,3 +67,18 @@ impl TaskInput for ResolvedWebpackLoaderItem {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
#[turbo_tasks::value(shared, transparent)] #[turbo_tasks::value(shared, transparent)]
pub struct WebpackLoaderItems(pub Vec<WebpackLoaderItem>); pub struct WebpackLoaderItems(pub Vec<WebpackLoaderItem>);
impl std::fmt::Display for WebpackLoaderItems {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut iter = self.0.iter();
if let Some(first) = iter.next() {
write!(f, "{}", first.loader)?;
for remaining in iter {
write!(f, ", {}", remaining.loader)?;
}
}
Ok(())
}
}
...@@ -8,9 +8,10 @@ use futures::try_join; ...@@ -8,9 +8,10 @@ use futures::try_join;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::{Map as JsonMap, Value as JsonValue, json}; use serde_json::{Map as JsonMap, Value as JsonValue, json};
use serde_with::serde_as; use serde_with::serde_as;
use tracing::Instrument;
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ use turbo_tasks::{
Completion, OperationVc, ResolvedVc, TaskInput, TryJoinIterExt, ValueToString, Vc, Completion, OperationVc, ReadRef, ResolvedVc, TaskInput, TryJoinIterExt, ValueToString, Vc,
trace::TraceRawVcs, trace::TraceRawVcs,
}; };
use turbo_tasks_env::ProcessEnv; use turbo_tasks_env::ProcessEnv;
...@@ -196,7 +197,14 @@ impl WebpackLoadersProcessedAsset { ...@@ -196,7 +197,14 @@ impl WebpackLoadersProcessedAsset {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn process(&self) -> Result<Vc<ProcessWebpackLoadersResult>> { async fn process(&self) -> Result<Vc<ProcessWebpackLoadersResult>> {
let transform = self.transform.await?; let transform = self.transform.await?;
let loaders = transform.loaders.await?;
let webpack_span = tracing::info_span!(
"webpack loader",
name = display(ReadRef::<WebpackLoaderItems>::as_raw_ref(&loaders))
);
async {
let ExecutionContext { let ExecutionContext {
project_path, project_path,
chunking_context, chunking_context,
...@@ -208,7 +216,8 @@ impl WebpackLoadersProcessedAsset { ...@@ -208,7 +216,8 @@ impl WebpackLoadersProcessedAsset {
}; };
let FileContent::Content(file_content) = &*file.await? else { let FileContent::Content(file_content) = &*file.await? else {
return Ok(ProcessWebpackLoadersResult { return Ok(ProcessWebpackLoadersResult {
content: AssetContent::File(FileContent::NotFound.resolved_cell()).resolved_cell(), content: AssetContent::File(FileContent::NotFound.resolved_cell())
.resolved_cell(),
assets: Vec::new(), assets: Vec::new(),
source_map: FileContent::NotFound.resolved_cell(), source_map: FileContent::NotFound.resolved_cell(),
} }
...@@ -251,7 +260,6 @@ impl WebpackLoadersProcessedAsset { ...@@ -251,7 +260,6 @@ impl WebpackLoadersProcessedAsset {
resource_fs_path, project_path resource_fs_path, project_path
)); ));
}; };
let loaders = transform.loaders.await?;
let config_value = evaluate_webpack_loader(WebpackLoaderContext { let config_value = evaluate_webpack_loader(WebpackLoaderContext {
entries, entries,
cwd: project_path.clone(), cwd: project_path.clone(),
...@@ -275,14 +283,17 @@ impl WebpackLoadersProcessedAsset { ...@@ -275,14 +283,17 @@ impl WebpackLoadersProcessedAsset {
let Some(val) = &*config_value else { let Some(val) = &*config_value else {
// An error happened, which has already been converted into an issue. // An error happened, which has already been converted into an issue.
return Ok(ProcessWebpackLoadersResult { return Ok(ProcessWebpackLoadersResult {
content: AssetContent::File(FileContent::NotFound.resolved_cell()).resolved_cell(), content: AssetContent::File(FileContent::NotFound.resolved_cell())
.resolved_cell(),
assets: Vec::new(), assets: Vec::new(),
source_map: FileContent::NotFound.resolved_cell(), source_map: FileContent::NotFound.resolved_cell(),
} }
.cell()); .cell());
}; };
let processed: WebpackLoadersProcessingResult = parse_json_with_source_context(val) let processed: WebpackLoadersProcessingResult = parse_json_with_source_context(val)
.context("Unable to deserializate response from webpack loaders transform operation")?; .context(
"Unable to deserializate response from webpack loaders transform operation",
)?;
// handle SourceMap // handle SourceMap
let source_map = if !transform.source_maps { let source_map = if !transform.source_maps {
...@@ -292,7 +303,8 @@ impl WebpackLoadersProcessedAsset { ...@@ -292,7 +303,8 @@ impl WebpackLoadersProcessedAsset {
.map .map
.map(|source_map| Rope::from(source_map.into_owned())) .map(|source_map| Rope::from(source_map.into_owned()))
}; };
let source_map = resolve_source_map_sources(source_map.as_ref(), &resource_fs_path).await?; let source_map =
resolve_source_map_sources(source_map.as_ref(), &resource_fs_path).await?;
let file = match processed.source { let file = match processed.source {
Either::Left(str) => File::from(str), Either::Left(str) => File::from(str),
...@@ -313,6 +325,9 @@ impl WebpackLoadersProcessedAsset { ...@@ -313,6 +325,9 @@ impl WebpackLoadersProcessedAsset {
} }
.cell()) .cell())
} }
.instrument(webpack_span)
.await
}
} }
#[turbo_tasks::function] #[turbo_tasks::function]
......
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