1- use std:: { collections:: HashSet , env:: current_dir, path:: PathBuf } ;
1+ use std:: { collections:: HashSet , env:: current_dir, path:: PathBuf , usize } ;
22
33use anyhow:: Result ;
44use 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