Skip to content

Commit e0229ff

Browse files
committed
refactor(plan): extract powershell prefix flags to const
Address review feedback on #345: - Extract the 5 fixed PowerShell prefix flags to a `const POWERSHELL_PREFIX` - Build `new_args` via iterator chain instead of manual Vec pushes - Drop the no-op `let _ = (&program_path, &args);` on non-Windows
1 parent e660c41 commit e0229ff

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

crates/vite_task_plan/src/powershell.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ pub fn rewrite_cmd_shim_to_powershell(
3535

3636
#[cfg(not(windows))]
3737
{
38-
let _ = (&program_path, &args);
3938
(program_path, args)
4039
}
4140
}
@@ -47,6 +46,12 @@ mod imp {
4746
use vite_path::{AbsolutePath, AbsolutePathBuf};
4847
use vite_str::Str;
4948

49+
/// Fixed arguments prepended before the `.ps1` path. `-NoProfile`/`-NoLogo`
50+
/// skip user profile loading; `-ExecutionPolicy Bypass` allows running the
51+
/// unsigned shims that npm/pnpm install into `node_modules/.bin`.
52+
const POWERSHELL_PREFIX: &[&str] =
53+
&["-NoProfile", "-NoLogo", "-ExecutionPolicy", "Bypass", "-File"];
54+
5055
/// Cached location of the PowerShell host used to run `.ps1` shims. Prefers
5156
/// cross-platform `pwsh.exe` when present, falling back to the Windows
5257
/// built-in `powershell.exe`. `None` means no host was found in PATH.
@@ -89,16 +94,15 @@ mod imp {
8994
ps1_str,
9095
);
9196

92-
let mut new_args: Vec<Str> = Vec::with_capacity(6 + args.len());
93-
new_args.push(Str::from("-NoProfile"));
94-
new_args.push(Str::from("-NoLogo"));
95-
new_args.push(Str::from("-ExecutionPolicy"));
96-
new_args.push(Str::from("Bypass"));
97-
new_args.push(Str::from("-File"));
98-
new_args.push(Str::from(ps1_str));
99-
new_args.extend(args.iter().cloned());
97+
let new_args: Arc<[Str]> = POWERSHELL_PREFIX
98+
.iter()
99+
.copied()
100+
.map(Str::from)
101+
.chain(std::iter::once(Str::from(ps1_str)))
102+
.chain(args.iter().cloned())
103+
.collect();
100104

101-
(Arc::clone(host), Arc::<[Str]>::from(new_args))
105+
(Arc::clone(host), new_args)
102106
}
103107
}
104108

0 commit comments

Comments
 (0)