Skip to content

Commit 6d2f774

Browse files
authored
fix(pm): disable Yarn update notifications (#2651)
`vp install` can show Yarn upgrade notices even though Vite+ manages the selected version. The resolver sets `YARN_DISABLE_SELF_UPDATE_CHECK=true` for Yarn Classic and `YARN_ENABLE_TIPS=false` for Yarn `4` and later. This also hides daily tips. The telemetry setting stays unchanged. Yarn `2` and `3` receive neither setting because they reject these options. Terminal tests cover Yarn `1.22.22`, `2.4.2`, `3.8.7`, and `4.12.0`.
1 parent 2c0ff62 commit 6d2f774

9 files changed

Lines changed: 241 additions & 4 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
disable-self-update-check false
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
enableTelemetry: true
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "yarn-update-notifier",
3+
"version": "1.0.0",
4+
"private": true,
5+
"packageManager": "yarn@1.22.22"
6+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[[case]]
2+
name = "yarn1_update_notifier"
3+
vp = "global"
4+
env = { NODE_OPTIONS = "--no-deprecation" }
5+
comment = "Managed Yarn Classic disables self-update checks even when the project enables them."
6+
steps = [
7+
["vp", "pm", "config", "get", "disable-self-update-check"],
8+
["vp", "install"],
9+
]
10+
11+
[[case]]
12+
name = "yarn2_update_notifier_compatibility"
13+
vp = "global"
14+
comment = "Yarn 2 commands work without unsupported update settings."
15+
steps = [
16+
{ argv = ["vpt", "json-edit", "package.json", "packageManager", "yarn@2.4.2"], snapshot = false },
17+
["vp", "pm", "config", "get", "enableTelemetry"],
18+
["vp", "install"],
19+
]
20+
21+
[[case]]
22+
name = "yarn3_update_notifier_compatibility"
23+
vp = "global"
24+
comment = "Yarn 3 commands work without unsupported update settings."
25+
steps = [
26+
{ argv = ["vpt", "json-edit", "package.json", "packageManager", "yarn@3.8.7"], snapshot = false },
27+
["vp", "pm", "config", "get", "enableTelemetry"],
28+
["vp", "install"],
29+
]
30+
31+
[[case]]
32+
name = "yarn4_update_notifier"
33+
vp = "global"
34+
comment = "Managed Yarn 4 disables daily tips, including version notices, without changing telemetry."
35+
steps = [
36+
{ argv = ["vpt", "json-edit", "package.json", "packageManager", "yarn@4.12.0"], snapshot = false },
37+
{ argv = ["vpt", "write-file", ".yarnrc.yml", "enableTelemetry: true\nenableTips: true\n"], snapshot = false },
38+
["vp", "pm", "config", "get", "enableTips"],
39+
["vp", "pm", "config", "get", "enableTelemetry"],
40+
["vp", "install"],
41+
]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# yarn1_update_notifier
2+
3+
Managed Yarn Classic disables self-update checks even when the project enables them.
4+
5+
## `vp pm config get disable-self-update-check`
6+
7+
```
8+
true
9+
```
10+
11+
## `vp install`
12+
13+
```
14+
VITE+ - The Unified Toolchain for the Web
15+
16+
yarn install <version>
17+
info No lockfile found.
18+
[1/4] Resolving packages...
19+
[2/4] Fetching packages...
20+
[3/4] Linking dependencies...
21+
[4/4] Building fresh packages...
22+
23+
success Saved lockfile.
24+
25+
Done in <duration>.
26+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# yarn2_update_notifier_compatibility
2+
3+
Yarn 2 commands work without unsupported update settings.
4+
5+
## `vpt json-edit package.json packageManager yarn@2.4.2`
6+
7+
8+
## `vp pm config get enableTelemetry`
9+
10+
```
11+
true
12+
```
13+
14+
## `vp install`
15+
16+
```
17+
VITE+ - The Unified Toolchain for the Web
18+
19+
➤ YN0000: ┌ Resolution step
20+
➤ YN0000: └ Completed
21+
➤ YN0000: ┌ Fetch step
22+
➤ YN0000: └ Completed
23+
➤ YN0000: ┌ Link step
24+
➤ YN0000: └ Completed
25+
➤ YN0000: Done in <duration> <duration>
26+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# yarn3_update_notifier_compatibility
2+
3+
Yarn 3 commands work without unsupported update settings.
4+
5+
## `vpt json-edit package.json packageManager yarn@3.8.7`
6+
7+
8+
## `vp pm config get enableTelemetry`
9+
10+
```
11+
true
12+
```
13+
14+
## `vp install`
15+
16+
```
17+
VITE+ - The Unified Toolchain for the Web
18+
19+
➤ YN0000: ┌ Resolution step
20+
➤ YN0000: └ Completed
21+
➤ YN0000: ┌ Fetch step
22+
➤ YN0000: └ Completed
23+
➤ YN0000: ┌ Link step
24+
➤ YN0000: └ Completed
25+
➤ YN0000: Done in <duration> <duration>
26+
```
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# yarn4_update_notifier
2+
3+
Managed Yarn 4 disables daily tips, including version notices, without changing telemetry.
4+
5+
## `vpt json-edit package.json packageManager yarn@4.12.0`
6+
7+
8+
## `vpt write-file .yarnrc.yml 'enableTelemetry: true
9+
enableTips: true
10+
'`
11+
12+
13+
## `vp pm config get enableTips`
14+
15+
```
16+
false
17+
```
18+
19+
## `vp pm config get enableTelemetry`
20+
21+
```
22+
true
23+
```
24+
25+
## `vp install`
26+
27+
```
28+
VITE+ - The Unified Toolchain for the Web
29+
30+
➤ YN0000: · Yarn <version>
31+
➤ YN0000: ┌ Resolution step
32+
➤ YN0000: └ Completed
33+
➤ YN0000: ┌ Fetch step
34+
➤ YN0000: └ Completed
35+
➤ YN0000: ┌ Link step
36+
➤ YN0000: └ Completed
37+
➤ YN0000: · Done in <duration> <duration>
38+
```

crates/vp_pm_cli/src/resolution/resolve.rs

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,28 @@ where
6060
command
6161
.env
6262
.insert("PATH".to_string(), vp_shared::format_path_prepended(manager.get_bin_prefix()));
63-
if manager.client == PackageManagerType::Pnpm {
64-
// Vite+ manages pnpm, so its self-update notification is not useful here.
65-
command.env.insert("PNPM_CONFIG_UPDATE_NOTIFIER".to_string(), "false".to_string());
63+
match manager.client {
64+
PackageManagerType::Pnpm => {
65+
// Vite+ manages pnpm, so its self-update notification is not useful here.
66+
command.env.insert("PNPM_CONFIG_UPDATE_NOTIFIER".to_string(), "false".to_string());
67+
}
68+
PackageManagerType::Yarn if command.program == "yarn" => {
69+
match parse_version(manager)?.major {
70+
0 | 1 => {
71+
command.env.insert(
72+
"YARN_DISABLE_SELF_UPDATE_CHECK".to_string(),
73+
"true".to_string(),
74+
);
75+
}
76+
4.. => {
77+
// Yarn 4 includes version notices in its daily tips.
78+
command.env.insert("YARN_ENABLE_TIPS".to_string(), "false".to_string());
79+
}
80+
// Yarn 2 and 3 reject these settings and have no version notices.
81+
_ => {}
82+
}
83+
}
84+
_ => {}
6685
}
6786
}
6887

@@ -80,7 +99,7 @@ fn parse_version(manager: &PackageManager) -> Result<Version, Error> {
8099
#[cfg(test)]
81100
mod tests {
82101
use super::*;
83-
use crate::resolution::{ApproveBuildsArgs, InstallArgs};
102+
use crate::resolution::{ApproveBuildsArgs, DlxArgs, InstallArgs};
84103

85104
fn package_manager(client: PackageManagerType, version: &str) -> PackageManager {
86105
let workspace_root = vt_path::current_dir().unwrap();
@@ -127,6 +146,59 @@ mod tests {
127146
));
128147
}
129148

149+
#[test]
150+
fn yarn_update_settings_match_the_major_version() {
151+
for (client, version, classic, tips) in [
152+
(PackageManagerType::Yarn, "1.22.22", Some("true"), None),
153+
(PackageManagerType::Yarn, "2.4.2", None, None),
154+
(PackageManagerType::Yarn, "3.8.7", None, None),
155+
(PackageManagerType::Yarn, "4.0.0", None, Some("false")),
156+
(PackageManagerType::Yarn, "4.12.0", None, Some("false")),
157+
(PackageManagerType::Npm, "11.13.0", None, None),
158+
(PackageManagerType::Pnpm, "12.3.4", None, None),
159+
(PackageManagerType::Bun, "1.0.0", None, None),
160+
] {
161+
let manager = package_manager(client, version);
162+
let resolution = resolve_for_manager(&manager, InstallArgs::default()).unwrap();
163+
let CommandResolution::Run(command) = resolution.outcome else {
164+
panic!("expected install command");
165+
};
166+
167+
assert_eq!(
168+
command.env.get("YARN_DISABLE_SELF_UPDATE_CHECK").map(String::as_str),
169+
classic,
170+
"{client}@{version}"
171+
);
172+
assert_eq!(
173+
command.env.get("YARN_ENABLE_TIPS").map(String::as_str),
174+
tips,
175+
"{client}@{version}"
176+
);
177+
assert!(!command.env.contains_key("YARN_ENABLE_TELEMETRY"));
178+
}
179+
}
180+
181+
#[test]
182+
fn yarn_classic_npx_fallback_uses_only_npm_update_settings() {
183+
let manager = package_manager(PackageManagerType::Yarn, "1.22.22");
184+
let resolution = resolve_for_manager(
185+
&manager,
186+
DlxArgs { args: vec!["create-vue".to_string()], ..Default::default() },
187+
)
188+
.unwrap();
189+
let CommandResolution::Run(command) = resolution.outcome else {
190+
panic!("expected npx command");
191+
};
192+
193+
assert_eq!(command.program, "npx");
194+
assert_eq!(
195+
command.env.get("npm_config_update_notifier").map(String::as_str),
196+
Some("false")
197+
);
198+
assert!(!command.env.contains_key("YARN_DISABLE_SELF_UPDATE_CHECK"));
199+
assert!(!command.env.contains_key("YARN_ENABLE_TIPS"));
200+
}
201+
130202
#[test]
131203
fn only_npm_installs_disable_npm_update_notifications() {
132204
for (client, version, expected) in [

0 commit comments

Comments
 (0)