Skip to content

Commit 61aa167

Browse files
committed
refactor(vite_install): use is_yarn_berry for yarn version checks
1 parent 9345ea0 commit 61aa167

15 files changed

Lines changed: 40 additions & 36 deletions

File tree

crates/vite_install/src/commands/approve_builds.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ impl PackageManager {
204204
}
205205
PackageManagerType::Yarn => {
206206
// Yarn 1 (Classic) runs lifecycle scripts by default; Berry (2+) blocks them.
207-
if self.version.starts_with("1.") {
207+
let is_berry = self.is_yarn_berry();
208+
if !is_berry {
208209
output::warn(
209210
"yarn (v1) runs lifecycle scripts by default. To restrict them, set \
210211
`ignore-scripts=true` in .npmrc and rebuild approved packages with \

crates/vite_install/src/commands/audit.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,8 @@ impl PackageManager {
9393
}
9494
}
9595
PackageManagerType::Yarn => {
96-
let is_yarn1 = self.version.starts_with("1.");
97-
98-
if is_yarn1 {
96+
let is_berry = self.is_yarn_berry();
97+
if !is_berry {
9998
if options.fix {
10099
output::warn("yarn v1 audit does not support --fix");
101100
return None;

crates/vite_install/src/commands/cache.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,17 @@ impl PackageManager {
9191
}
9292
PackageManagerType::Yarn => {
9393
bin_name = "yarn".into();
94-
let is_yarn1 = self.version.starts_with("1.");
9594

9695
match options.subcommand {
9796
"dir" | "path" => {
98-
if is_yarn1 {
99-
args.push("cache".into());
100-
args.push("dir".into());
101-
} else {
97+
let is_berry = self.is_yarn_berry();
98+
if is_berry {
10299
args.push("config".into());
103100
args.push("get".into());
104101
args.push("cacheFolder".into());
102+
} else {
103+
args.push("cache".into());
104+
args.push("dir".into());
105105
}
106106
}
107107
"clean" => {

crates/vite_install/src/commands/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ impl PackageManager {
8686
PackageManagerType::Yarn => {
8787
args.push("config".into());
8888

89-
let is_yarn1 = self.version.starts_with("1.");
89+
let is_berry = self.is_yarn_berry();
9090

9191
// yarn@2+ uses 'unset' instead of 'delete', and no subcommand for 'list'
92-
if options.subcommand == "delete" && !is_yarn1 {
92+
if options.subcommand == "delete" && is_berry {
9393
args.push("unset".into());
94-
} else if options.subcommand == "list" && !is_yarn1 {
94+
} else if options.subcommand == "list" && is_berry {
9595
// yarn@2+: 'yarn config' with no subcommand lists all
9696
// Don't add 'list'
9797
} else {
@@ -112,7 +112,7 @@ impl PackageManager {
112112

113113
// Handle --location parameter
114114
if let Some(location) = options.location {
115-
if is_yarn1 {
115+
if !is_berry {
116116
// yarn@1: use --global for global location
117117
if location == "global" {
118118
args.push("--global".into());

crates/vite_install/src/commands/dist_tag.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ impl PackageManager {
5656
}
5757
PackageManagerType::Yarn => {
5858
bin_name = "yarn".into();
59-
let is_yarn1 = self.version.starts_with("1.");
59+
let is_berry = self.is_yarn_berry();
6060

61-
if is_yarn1 {
61+
if is_berry {
62+
args.push("npm".into());
6263
args.push("tag".into());
6364
} else {
64-
args.push("npm".into());
6565
args.push("tag".into());
6666
}
6767
}

crates/vite_install/src/commands/dlx.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ impl PackageManager {
4545
PackageManagerType::Pnpm => self.resolve_pnpm_dlx(options, envs),
4646
PackageManagerType::Npm => self.resolve_npm_dlx(options, envs),
4747
PackageManagerType::Yarn => {
48-
if self.version.starts_with("1.") {
48+
let is_berry = self.is_yarn_berry();
49+
50+
if !is_berry {
4951
// Yarn 1.x doesn't have dlx, fall back to npx
5052
self.resolve_npx_fallback(options, envs)
5153
} else {

crates/vite_install/src/commands/list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl PackageManager {
5454
options: &ListCommandOptions,
5555
) -> Option<ResolveCommandResult> {
5656
// yarn@2+ does not support list command
57-
if self.client == PackageManagerType::Yarn && !self.version.starts_with("1.") {
57+
if self.client == PackageManagerType::Yarn && self.is_yarn_berry() {
5858
output::warn("yarn@2+ does not support 'list' command");
5959
return None;
6060
}

crates/vite_install/src/commands/login.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ impl PackageManager {
4646
}
4747
PackageManagerType::Yarn => {
4848
bin_name = "yarn".into();
49-
let is_yarn1 = self.version.starts_with("1.");
49+
let is_berry = self.is_yarn_berry();
5050

51-
if is_yarn1 {
51+
if !is_berry {
5252
args.push("login".into());
5353
} else {
5454
args.push("npm".into());

crates/vite_install/src/commands/logout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ impl PackageManager {
4646
}
4747
PackageManagerType::Yarn => {
4848
bin_name = "yarn".into();
49-
let is_yarn1 = self.version.starts_with("1.");
49+
let is_berry = self.is_yarn_berry();
5050

51-
if is_yarn1 {
51+
if !is_berry {
5252
args.push("logout".into());
5353
} else {
5454
args.push("npm".into());

crates/vite_install/src/commands/outdated.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,10 @@ impl PackageManager {
157157
}
158158
PackageManagerType::Yarn => {
159159
bin_name = "yarn".into();
160+
let is_berry = self.is_yarn_berry();
160161

161162
// Check if yarn@2+ (uses upgrade-interactive)
162-
if self.version.starts_with("1.") {
163+
if !is_berry {
163164
// yarn@1
164165
args.push("outdated".into());
165166

0 commit comments

Comments
 (0)