diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_remove_pnpm10/snapshots/command_remove_pnpm10.global.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_remove_pnpm10/snapshots/command_remove_pnpm10.global.md index a6089a0c92..5a3d4c5072 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_remove_pnpm10/snapshots/command_remove_pnpm10.global.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_remove_pnpm10/snapshots/command_remove_pnpm10.global.md @@ -116,10 +116,10 @@ Packages: -2 -- dependencies: -- testnpm2 1.0.1 +- testnpm2 devDependencies: -- test-vite-plus-install 1.0.0 +- test-vite-plus-install Done in using pnpm ``` diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_remove_pnpm10/snapshots/command_remove_pnpm10.local.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_remove_pnpm10/snapshots/command_remove_pnpm10.local.md index ca09982902..2283f86949 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_remove_pnpm10/snapshots/command_remove_pnpm10.local.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_remove_pnpm10/snapshots/command_remove_pnpm10.local.md @@ -112,10 +112,10 @@ Packages: -2 -- dependencies: -- testnpm2 1.0.1 +- testnpm2 devDependencies: -- test-vite-plus-install 1.0.0 +- test-vite-plus-install Done in using pnpm ``` diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_remove_pnpm11/snapshots/command_remove_pnpm11.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_remove_pnpm11/snapshots/command_remove_pnpm11.md index aaf526bf84..be515b4d3f 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_remove_pnpm11/snapshots/command_remove_pnpm11.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_remove_pnpm11/snapshots/command_remove_pnpm11.md @@ -116,10 +116,10 @@ Packages: -2 -- dependencies: -- testnpm2 1.0.1 +- testnpm2 devDependencies: -- test-vite-plus-install 1.0.0 +- test-vite-plus-install Done in using pnpm ``` diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_update_pnpm10/snapshots/command_update_pnpm10.global.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_update_pnpm10/snapshots/command_update_pnpm10.global.md index fda81d8fb5..ffc46aac1c 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_update_pnpm10/snapshots/command_update_pnpm10.global.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_update_pnpm10/snapshots/command_update_pnpm10.global.md @@ -189,8 +189,8 @@ Packages: -2 -- optionalDependencies: -- test-vite-plus-package-optional 1.0.0 -- testnpm2 1.0.0 +- test-vite-plus-package-optional +- testnpm2 Done in using pnpm ``` diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_update_pnpm10/snapshots/command_update_pnpm10.local.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_update_pnpm10/snapshots/command_update_pnpm10.local.md index 3d37055500..ea57f581d1 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_update_pnpm10/snapshots/command_update_pnpm10.local.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_update_pnpm10/snapshots/command_update_pnpm10.local.md @@ -185,8 +185,8 @@ Packages: -2 -- optionalDependencies: -- test-vite-plus-package-optional 1.0.0 -- testnpm2 1.0.0 +- test-vite-plus-package-optional +- testnpm2 Done in using pnpm ``` diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_update_pnpm11/snapshots/command_update_pnpm11.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_update_pnpm11/snapshots/command_update_pnpm11.md index 7eed3730e5..af2231ad83 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_update_pnpm11/snapshots/command_update_pnpm11.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_update_pnpm11/snapshots/command_update_pnpm11.md @@ -189,7 +189,7 @@ Done in using pnpm - optionalDependencies: -- testnpm2 1.0.0 +- testnpm2 testnpm2 1.0.1 Done in using pnpm diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/redact.rs b/crates/vp_cli_snapshots/tests/cli_snapshots/redact.rs index 1301e2dc33..fcce014b60 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/redact.rs +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/redact.rs @@ -207,6 +207,19 @@ static PNPM_STORE_INFO_RE: LazyLock = LazyLock::new(|| { ) .unwrap() }); +// pnpm reads a removed package's manifest concurrently with unlinking the +// package, so its removal summary may omit the version. Strip that version +// within dependency sections of pnpm output; keep names and added versions. +static PNPM_DEPENDENCY_SECTION_RE: LazyLock = LazyLock::new(|| { + regex::Regex::new( + r"(?m)^(?:dependencies|devDependencies|optionalDependencies):\n(?:[^\n]+\n?)*", + ) + .unwrap() +}); +static PNPM_REMOVED_VERSION_RE: LazyLock = LazyLock::new(|| { + regex::Regex::new(r"(?m)^(- \S+) \d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$") + .unwrap() +}); // Stack frames under file:// URLs carry line:column offsets of the bundled // chunk that produced them, which shift with every build of the bundle (and // the chunk hash in the frame path shifts with content); the error message @@ -580,6 +593,14 @@ pub fn redact_output( output = PNPM_PROGRESS_RE.replace_all(&output, "").into_owned(); output = PNPM_STORE_INFO_RE.replace_all(&output, "").into_owned(); + if output.contains("Done in using pnpm ") { + output = PNPM_DEPENDENCY_SECTION_RE + .replace_all(&output, |caps: ®ex::Captures| { + PNPM_REMOVED_VERSION_RE.replace_all(&caps[0], "${1}").into_owned() + }) + .into_owned(); + } + // Pin racy blank-line layout last, after every rule above that strips // whole lines (banner box, stack frames, progress rows) has run, so the // newlines those strips leave behind collapse the same way whether or not diff --git a/crates/vp_cli_snapshots/tests/redact_unit.rs b/crates/vp_cli_snapshots/tests/redact_unit.rs index 5c264e6756..7a20411af9 100644 --- a/crates/vp_cli_snapshots/tests/redact_unit.rs +++ b/crates/vp_cli_snapshots/tests/redact_unit.rs @@ -153,6 +153,48 @@ fn strips_pnpm_store_location_diagnostics() { ); } +#[test] +fn normalizes_pnpm_removed_dependency_versions() { + // pnpm can report a removal with or without the package version, depending + // on whether its manifest read finishes before the package is unlinked. + for section in ["dependencies", "devDependencies", "optionalDependencies"] { + for version in [" 1.0.0", "", " 1.0.0-beta.1+build.2"] { + let input = format!( + "Packages: -2\n--\n\n{section}:\n- testnpm2{version}\n- @scope/pkg{version}\n\nDone in 1s using pnpm 10.18.0\n" + ); + let expected = format!( + "Packages: -2\n--\n\n{section}:\n- testnpm2\n- @scope/pkg\n\nDone in using pnpm \n" + ); + assert_eq!(redact_output(input, &[], true), expected); + } + } +} + +#[test] +fn preserves_pnpm_added_versions_and_text_outside_dependency_sections() { + let input = concat!( + "- outside 2.0.0\n\n", + "optionalDependencies:\n", + "- testnpm2 1.0.0\n", + " testnpm2 1.0.1\n", + " @scope/pkg 2.0.0 (3.0.0 is available)\n\n", + "- after-section 3.0.0\n", + "\"testnpm2\": \"1.0.1\"\n\n", + "Done in 1s using pnpm 10.18.0\n", + ) + .to_owned(); + let expected = input + .replace("- testnpm2 1.0.0", "- testnpm2") + .replace("1s using pnpm 10.18.0", " using pnpm "); + assert_eq!(redact_output(input, &[], true), expected); +} + +#[test] +fn preserves_dependency_versions_without_pnpm_output() { + let input = "optionalDependencies:\n- testnpm2 1.0.0\n".to_owned(); + assert_eq!(redact_output(input.clone(), &[], true), input); +} + #[test] fn masks_current_vite_plus_version_in_upgrade_check_output() { let input = concat!(