Skip to content

Commit d5bbaa3

Browse files
authored
fix(pm): disable pnpm update notifications (#2649)
`vp install` can show pnpm's update notice even though Vite+ manages the selected pnpm version. The shared package-manager resolver now sets `PNPM_CONFIG_UPDATE_NOTIFIER=false` for pnpm commands. The tests cover pnpm `11.25.0` and `12.3.4`, including projects that set `updateNotifier: true`. Before this change: <img width="731" alt="pnpm upgrade notification shown during vp install" src="https://github.com/user-attachments/assets/8f197217-bbd9-48b4-9c43-7a232fd1e450" />
1 parent d1b8cee commit d5bbaa3

6 files changed

Lines changed: 103 additions & 1 deletion

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "pnpm-update-notifier",
3+
"version": "1.0.0",
4+
"private": true,
5+
"packageManager": "pnpm@11.25.0",
6+
"scripts": {
7+
"postinstall": "node -e \"console.log('PNPM_CONFIG_UPDATE_NOTIFIER=' + process.env.PNPM_CONFIG_UPDATE_NOTIFIER)\""
8+
}
9+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
updateNotifier: true
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[[case]]
2+
name = "pnpm11_update_notifier"
3+
vp = "global"
4+
comment = "Managed pnpm 11 commands disable update notifications even when the project enables them."
5+
steps = [
6+
["vp", "pm", "config", "get", "updateNotifier"],
7+
["vp", "install"],
8+
]
9+
10+
[[case]]
11+
name = "pnpm12_update_notifier"
12+
vp = "global"
13+
comment = "Managed pnpm 12 commands disable update notifications even when the project enables them."
14+
steps = [
15+
{ argv = ["vpt", "json-edit", "package.json", "packageManager", "pnpm@12.3.4"], snapshot = false },
16+
["vp", "pm", "config", "get", "updateNotifier"],
17+
["vp", "install"],
18+
]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# pnpm11_update_notifier
2+
3+
Managed pnpm 11 commands disable update notifications even when the project enables them.
4+
5+
## `vp pm config get updateNotifier`
6+
7+
```
8+
false
9+
```
10+
11+
## `vp install`
12+
13+
```
14+
VITE+ - The Unified Toolchain for the Web
15+
16+
Already up to date
17+
. postinstall$ node -e "console.log('PNPM_CONFIG_UPDATE_NOTIFIER=' + process.env.PNPM_CONFIG_UPDATE_NOTIFIER)"
18+
│ PNPM_CONFIG_UPDATE_NOTIFIER=false
19+
└─ Done in <duration>
20+
21+
Done in <duration> using pnpm <version>
22+
```
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# pnpm12_update_notifier
2+
3+
Managed pnpm 12 commands disable update notifications even when the project enables them.
4+
5+
## `vpt json-edit package.json packageManager pnpm@12.3.4`
6+
7+
8+
## `vp pm config get updateNotifier`
9+
10+
```
11+
false
12+
```
13+
14+
## `vp install`
15+
16+
```
17+
VITE+ - The Unified Toolchain for the Web
18+
19+
. postinstall$ node -e "console.log('PNPM_CONFIG_UPDATE_NOTIFIER=' + process.env.PNPM_CONFIG_UPDATE_NOTIFIER)"
20+
│ PNPM_CONFIG_UPDATE_NOTIFIER=false
21+
└─ Done in <duration>
22+
Already up to date
23+
24+
Done in <duration> using pnpm <version>
25+
```

crates/vp_pm_cli/src/resolution/resolve.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ 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());
66+
}
6367
}
6468

6569
Ok(resolution)
@@ -76,7 +80,7 @@ fn parse_version(manager: &PackageManager) -> Result<Version, Error> {
7680
#[cfg(test)]
7781
mod tests {
7882
use super::*;
79-
use crate::resolution::ApproveBuildsArgs;
83+
use crate::resolution::{ApproveBuildsArgs, InstallArgs};
8084

8185
fn package_manager(client: PackageManagerType, version: &str) -> PackageManager {
8286
let workspace_root = vt_path::current_dir().unwrap();
@@ -122,4 +126,27 @@ mod tests {
122126
} if version == "latest"
123127
));
124128
}
129+
130+
#[test]
131+
fn only_pnpm_installs_disable_update_notifications() {
132+
for (client, version, expected) in [
133+
(PackageManagerType::Pnpm, "11.25.0", Some("false")),
134+
(PackageManagerType::Pnpm, "12.3.4", Some("false")),
135+
(PackageManagerType::Npm, "11.0.0", None),
136+
(PackageManagerType::Yarn, "4.0.0", None),
137+
(PackageManagerType::Bun, "1.0.0", None),
138+
] {
139+
let manager = package_manager(client, version);
140+
let resolution = resolve_for_manager(&manager, InstallArgs::default()).unwrap();
141+
let CommandResolution::Run(command) = resolution.outcome else {
142+
panic!("expected install command");
143+
};
144+
145+
assert_eq!(
146+
command.env.get("PNPM_CONFIG_UPDATE_NOTIFIER").map(String::as_str),
147+
expected,
148+
"{client}@{version}"
149+
);
150+
}
151+
}
125152
}

0 commit comments

Comments
 (0)