Skip to content

Commit 0958327

Browse files
committed
refactor(shell): model cwd-changing commands
1 parent 455b93b commit 0958327

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

crates/vite_shell/src/lib.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,30 @@ fn pipeline_to_command(pipeline: &Pipeline) -> Option<(TaskParsedCommand, Range<
135135
Some((TaskParsedCommand { envs, program: unquote(program)?, args }, range))
136136
}
137137

138+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
139+
enum CwdChangingCommand {
140+
Cd,
141+
Chdir,
142+
Dot,
143+
Source,
144+
Eval,
145+
}
146+
147+
impl CwdChangingCommand {
148+
fn from_name(command_name: &str) -> Option<Self> {
149+
Some(match command_name {
150+
"cd" => Self::Cd,
151+
"chdir" => Self::Chdir,
152+
"." => Self::Dot,
153+
"source" => Self::Source,
154+
"eval" => Self::Eval,
155+
_ => return None,
156+
})
157+
}
158+
}
159+
138160
fn command_name_may_change_cwd(command_name: &str) -> bool {
139-
matches!(command_name, "cd" | "chdir" | "." | "source" | "eval")
161+
CwdChangingCommand::from_name(command_name).is_some()
140162
}
141163

142164
fn wrapper_command_may_change_cwd(suffix: Option<&CommandSuffix>) -> bool {

0 commit comments

Comments
 (0)