Skip to content

Commit fe24e82

Browse files
committed
wip
1 parent 8d6893f commit fe24e82

2 files changed

Lines changed: 24 additions & 17 deletions

File tree

crates/vite_global_cli/src/commands/env/clean.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,18 @@ async fn remove_dir_all_if_exists(path: &Path) -> Result<bool, Error> {
110110
}
111111

112112
async fn run_corepack_cache_clean(cwd: &AbsolutePathBuf) -> Result<bool, Error> {
113-
if corepack_cache_clean_would_auto_install(cwd).await? {
113+
let corepack_path = match resolve_corepack_from_path(cwd) {
114+
Some(path) => path,
115+
None => return Ok(false),
116+
};
117+
118+
if corepack_cache_clean_would_auto_install(cwd, &corepack_path).await? {
114119
return Ok(false);
115120
}
116121

117-
let result = tokio::process::Command::new("corepack")
122+
let result = tokio::process::Command::new(corepack_path.as_path())
118123
.args(["cache", "clean"])
124+
.current_dir(cwd.as_path())
119125
.env_remove(env_vars::VP_TOOL_RECURSION)
120126
.output()
121127
.await;
@@ -128,12 +134,10 @@ async fn run_corepack_cache_clean(cwd: &AbsolutePathBuf) -> Result<bool, Error>
128134
}
129135
}
130136

131-
async fn corepack_cache_clean_would_auto_install(cwd: &AbsolutePathBuf) -> Result<bool, Error> {
132-
let corepack_path = match resolve_corepack_from_path(cwd) {
133-
Some(path) => path,
134-
None => return Ok(false),
135-
};
136-
137+
async fn corepack_cache_clean_would_auto_install(
138+
cwd: &AbsolutePathBuf,
139+
corepack_path: &AbsolutePath,
140+
) -> Result<bool, Error> {
137141
let bin_dir = config::get_bin_dir()?;
138142
if corepack_path.parent() != Some(&bin_dir) {
139143
return Ok(false);

packages/cli/snap-tests-global/command-env-clean/setup-env-clean.mjs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ fs.mkdirSync(path.join('home', 'package_manager', 'npm', '11.0.0', 'npm', 'bin')
1717
});
1818
fs.mkdirSync('fake-bin', { recursive: true });
1919

20-
fs.writeFileSync(
21-
path.join('fake-bin', 'corepack'),
22-
'#!/bin/sh\nmkdir -p "$VP_HOME"\ntouch "$VP_HOME/corepack-cleaned"\n',
23-
{ mode: 0o755 },
24-
);
25-
fs.writeFileSync(
26-
path.join('fake-bin', 'corepack.cmd'),
27-
'@echo off\r\nif not exist "%VP_HOME%" mkdir "%VP_HOME%"\r\ntype nul > "%VP_HOME%\\corepack-cleaned"\r\n',
28-
);
20+
if (process.platform === 'win32') {
21+
fs.writeFileSync(
22+
path.join('fake-bin', 'corepack.cmd'),
23+
'@echo off\r\nif not exist "%VP_HOME%" mkdir "%VP_HOME%"\r\ntype nul > "%VP_HOME%\\corepack-cleaned"\r\n',
24+
);
25+
} else {
26+
fs.writeFileSync(
27+
path.join('fake-bin', 'corepack'),
28+
'#!/bin/sh\nmkdir -p "$VP_HOME"\ntouch "$VP_HOME/corepack-cleaned"\n',
29+
{ mode: 0o755 },
30+
);
31+
}
2932
fs.writeFileSync(path.join('home', 'config.json'), '{"defaultNodeVersion":"24.11.0"}\n');

0 commit comments

Comments
 (0)