Skip to content

Commit 651e9d4

Browse files
authored
fix(cli): ensure install_deps runs in correct project directory (#18019)
1 parent b1e8dc9 commit 651e9d4

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

crates/taro_init/src/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl Project {
153153
init_git(&self.project_name, project_path_str.as_str())?;
154154
let auto_install = self.auto_install.unwrap_or(true);
155155
if auto_install {
156-
install_deps(&self.npm, || self.call_success()).await?;
156+
install_deps(&self.npm, project_path_str.as_str(), || self.call_success()).await?;
157157
} else {
158158
self.call_success();
159159
}

crates/taro_init/src/utils.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ where
128128
}
129129
}
130130

131-
pub async fn install_deps<F>(npm: &NpmType, cb: F) -> anyhow::Result<()>
131+
pub async fn install_deps<F>(npm: &NpmType, project_path: &str, cb: F) -> anyhow::Result<()>
132132
where
133133
F: FnOnce(),
134134
{
@@ -139,6 +139,10 @@ where
139139
"执行安装项目依赖 {}, 需要一会儿...",
140140
style(command.to_owned() + " install").cyan().bold()
141141
);
142+
143+
// 确保在项目目录中执行
144+
env::set_current_dir(project_path)?;
145+
142146
let output = execute_command(command, &["install"]).await;
143147
match output {
144148
result::Result::Ok(_) => {

0 commit comments

Comments
 (0)