@@ -20,6 +20,8 @@ use vite_task_graph::display::TaskDisplay;
2020use vite_task_plan:: { ExecutionGraph , ExecutionItemKind } ;
2121use vite_workspace:: find_workspace_root;
2222
23+ const PREFIX_BIN_PLACEHOLDER : & str = "__PLAN_SNAPSHOT_PREFIX_BIN__" ;
24+
2325/// Local parser wrapper for `BuiltInCommand`
2426#[ derive( Parser ) ]
2527#[ command( name = "vt" ) ]
@@ -141,6 +143,26 @@ fn assert_identifier_like(kind: &str, value: &str) {
141143 ) ;
142144}
143145
146+ #[ expect(
147+ clippy:: disallowed_types,
148+ reason = "Path required for fixture file replacement; String required by std::fs APIs"
149+ ) ]
150+ fn replace_prefix_bin_placeholder ( stage_path : & AbsolutePath , prefix_bin_dir : & std:: path:: Path ) {
151+ let package_json = stage_path. join ( "package.json" ) ;
152+ let contents = match std:: fs:: read_to_string ( package_json. as_path ( ) ) {
153+ Ok ( contents) => contents,
154+ Err ( err) if err. kind ( ) == std:: io:: ErrorKind :: NotFound => return ,
155+ Err ( err) => panic ! ( "failed to read {}: {err}" , package_json. as_path( ) . display( ) ) ,
156+ } ;
157+ if !contents. contains ( PREFIX_BIN_PLACEHOLDER ) {
158+ return ;
159+ }
160+
161+ let prefix_bin = prefix_bin_dir. to_str ( ) . unwrap ( ) . cow_replace ( '\\' , "/" ) ;
162+ let updated = contents. as_str ( ) . cow_replace ( PREFIX_BIN_PLACEHOLDER , prefix_bin. as_ref ( ) ) ;
163+ std:: fs:: write ( package_json. as_path ( ) , updated. as_ref ( ) ) . unwrap ( ) ;
164+ }
165+
144166#[ expect(
145167 clippy:: disallowed_types,
146168 reason = "Path required for fixture handling; String required by std::fs::read and toml::from_slice"
@@ -186,15 +208,18 @@ fn run_case_inner(
186208 let stage_path = tmpdir. join ( fixture_name) ;
187209 copy_dir ( fixture_path, & stage_path) . unwrap ( ) ;
188210
211+ let manifest_dir = std:: path:: PathBuf :: from ( std:: env:: var_os ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ) ;
212+ let prefix_bin_dir = manifest_dir. join ( "tests/plan_snapshots/prefix-bin" ) ;
213+ replace_prefix_bin_placeholder ( & stage_path, & prefix_bin_dir) ;
214+
189215 let ( workspace_root, _cwd) = find_workspace_root ( & stage_path) . unwrap ( ) ;
190216
191217 assert_eq ! (
192218 & stage_path, & * workspace_root. path,
193219 "folder '{fixture_name}' should be a workspace root"
194220 ) ;
195221
196- let fake_bin_dir = std:: path:: PathBuf :: from ( std:: env:: var_os ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) )
197- . join ( "tests/plan_snapshots/fake-bin" ) ;
222+ let fake_bin_dir = manifest_dir. join ( "tests/plan_snapshots/fake-bin" ) ;
198223 let combined_path =
199224 Arc :: < OsStr > :: from ( std:: ffi:: OsString :: from ( fake_bin_dir. to_str ( ) . unwrap ( ) ) ) ;
200225
0 commit comments