Skip to content

Commit 5ce6c62

Browse files
committed
refactor(spawn): tighten powershell rewrite review points
- Compare `.bin` / `node_modules` path components case-insensitively, matching the existing case-insensitive `.cmd`/`.bat` check and npm's de-facto lowercase naming (robust to symlinks/mounts) - Condense the scope-check comment to one line to match the repo style - Narrow `#[expect(clippy::disallowed_types)]` from the whole test module to just the two helpers that actually bridge std paths
1 parent 9b5cad2 commit 5ce6c62

1 file changed

Lines changed: 8 additions & 17 deletions

File tree

crates/vite_task/src/session/execute/powershell.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,13 @@ fn rewrite_with_host(
6565
return None;
6666
}
6767

68-
// Only rewrite shims under `node_modules/.bin` — the triplet
69-
// (`.cmd` / `.ps1` / POSIX) is a known-safe shape produced by npm /
70-
// pnpm / yarn. Any other `.cmd` / `.bat` on PATH (Windows system tools,
71-
// user-installed tools) is left alone to avoid unintended side effects.
68+
// Limit to npm/pnpm/yarn `node_modules/.bin` shims; leave system tools alone.
7269
let mut parents = program_path.as_path().components().rev();
7370
parents.next()?; // shim filename
74-
if parents.next()?.as_os_str() != ".bin" {
71+
if !parents.next()?.as_os_str().eq_ignore_ascii_case(".bin") {
7572
return None;
7673
}
77-
if parents.next()?.as_os_str() != "node_modules" {
74+
if !parents.next()?.as_os_str().eq_ignore_ascii_case("node_modules") {
7875
return None;
7976
}
8077

@@ -104,28 +101,22 @@ fn rewrite_with_host(
104101
}
105102

106103
#[cfg(test)]
107-
#[expect(
108-
clippy::disallowed_types,
109-
reason = "test fixtures bridge tempdir's std paths into AbsolutePath"
110-
)]
111104
mod tests {
112-
use std::{
113-
fs,
114-
path::{Path, PathBuf},
115-
sync::Arc,
116-
};
105+
use std::{fs, sync::Arc};
117106

118107
use tempfile::tempdir;
119108
use vite_path::{AbsolutePath, AbsolutePathBuf};
120109
use vite_str::Str;
121110

122111
use super::rewrite_with_host;
123112

124-
fn abs_path(buf: PathBuf) -> Arc<AbsolutePath> {
113+
#[expect(clippy::disallowed_types, reason = "tempdir bridges std PathBuf into AbsolutePath")]
114+
fn abs_path(buf: std::path::PathBuf) -> Arc<AbsolutePath> {
125115
Arc::<AbsolutePath>::from(AbsolutePathBuf::new(buf).unwrap())
126116
}
127117

128-
fn bin_dir(root: &Path) -> PathBuf {
118+
#[expect(clippy::disallowed_types, reason = "tempdir hands out std Path for the test root")]
119+
fn bin_dir(root: &std::path::Path) -> std::path::PathBuf {
129120
let bin = root.join("node_modules").join(".bin");
130121
fs::create_dir_all(&bin).unwrap();
131122
bin

0 commit comments

Comments
 (0)