Skip to content

Commit 046ecc4

Browse files
committed
Add depth flag to NFT CLI
1 parent 43d4532 commit 046ecc4

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

turbopack/crates/turbopack-nft/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ pub struct Arguments {
3131

3232
#[clap(long)]
3333
pub show_issues: bool,
34+
35+
#[clap(long)]
36+
pub depth: Option<usize>,
3437
}
3538

3639
#[global_allocator]
@@ -95,6 +98,7 @@ async fn main_inner(args: Arguments) -> Result<()> {
9598
args.entry.into(),
9699
args.graph,
97100
args.show_issues,
101+
args.depth,
98102
)
99103
.await?;
100104
Ok(Default::default())

turbopack/crates/turbopack-nft/src/nft.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{collections::HashSet, env::current_dir, path::PathBuf};
1+
use std::{collections::HashSet, env::current_dir, path::PathBuf, usize};
22

33
use anyhow::Result;
44
use turbo_rcstr::{RcStr, rcstr};
@@ -28,8 +28,9 @@ pub async fn node_file_trace(
2828
input: RcStr,
2929
graph: bool,
3030
show_issues: bool,
31+
max_depth: Option<usize>,
3132
) -> Result<()> {
32-
let op = node_file_trace_operation(project_root.clone(), input.clone(), graph);
33+
let op = node_file_trace_operation(project_root.clone(), input.clone(), graph, max_depth);
3334
let result = op.resolve_strongly_consistent().await?;
3435

3536
if show_issues {
@@ -58,6 +59,7 @@ async fn node_file_trace_operation(
5859
project_root: RcStr,
5960
input: RcStr,
6061
graph: bool,
62+
max_depth: Option<usize>,
6163
) -> Result<Vc<Vec<RcStr>>> {
6264
let workspace_fs: Vc<Box<dyn FileSystem>> = Vc::upcast(DiskFileSystem::new(
6365
rcstr!("workspace"),
@@ -98,7 +100,7 @@ async fn node_file_trace_operation(
98100
..Default::default()
99101
}
100102
.cell(),
101-
Layer::new(rcstr!("test")),
103+
Layer::new(rcstr!("externals-tracing")),
102104
);
103105
let module = module_asset_context
104106
.process(Vc::upcast(source), ReferenceType::Undefined)
@@ -107,7 +109,7 @@ async fn node_file_trace_operation(
107109
let asset = TracedAsset::new(module).to_resolved().await?;
108110

109111
Ok(Vc::cell(if graph {
110-
to_graph(ResolvedVc::upcast(asset)).await?
112+
to_graph(ResolvedVc::upcast(asset), max_depth.unwrap_or(usize::MAX)).await?
111113
} else {
112114
to_list(ResolvedVc::upcast(asset)).await?
113115
}))
@@ -126,7 +128,7 @@ async fn to_list(asset: ResolvedVc<Box<dyn OutputAsset>>) -> Result<Vec<RcStr>>
126128
Ok(assets)
127129
}
128130

129-
async fn to_graph(asset: ResolvedVc<Box<dyn OutputAsset>>) -> Result<Vec<RcStr>> {
131+
async fn to_graph(asset: ResolvedVc<Box<dyn OutputAsset>>, max_depth: usize) -> Result<Vec<RcStr>> {
130132
let mut visited = HashSet::new();
131133
let mut queue = Vec::new();
132134
queue.push((0, asset));
@@ -142,12 +144,19 @@ async fn to_graph(asset: ResolvedVc<Box<dyn OutputAsset>>) -> Result<Vec<RcStr>>
142144
for &asset in references.iter().rev() {
143145
queue.push((depth + 1, asset));
144146
}
145-
result.push(format!("{}{}", indent, asset.path().to_string().await?).into());
147+
if depth <= max_depth {
148+
result.push(format!("{}{}", indent, asset.path().to_string().await?).into());
149+
}
146150
} else if references.is_empty() {
147-
result.push(format!("{}{} *", indent, asset.path().to_string().await?).into());
148-
} else {
151+
if depth <= max_depth {
152+
result.push(format!("{}{} *", indent, asset.path().to_string().await?).into());
153+
}
154+
} else if depth <= max_depth {
149155
result.push(format!("{}{} *...", indent, asset.path().to_string().await?).into());
150156
}
151157
}
158+
result.push("".into());
159+
result.push("* : revisited".into());
160+
result.push("*... : revisited and references were already printed".into());
152161
Ok(result)
153162
}

0 commit comments

Comments
 (0)