Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 <duration> using pnpm <version>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <duration> using pnpm <version>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <duration> using pnpm <version>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <duration> using pnpm <version>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <duration> using pnpm <version>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Done in <duration> using pnpm <version>
-

optionalDependencies:
- testnpm2 1.0.0
- testnpm2
testnpm2 1.0.1

Done in <duration> using pnpm <version>
Expand Down
21 changes: 21 additions & 0 deletions crates/vp_cli_snapshots/tests/cli_snapshots/redact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ static PNPM_STORE_INFO_RE: LazyLock<regex::Regex> = 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<regex::Regex> = LazyLock::new(|| {
regex::Regex::new(
r"(?m)^(?:dependencies|devDependencies|optionalDependencies):\n(?:[^\n]+\n?)*",
)
.unwrap()
});
static PNPM_REMOVED_VERSION_RE: LazyLock<regex::Regex> = 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
Expand Down Expand Up @@ -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 <duration> using pnpm <version>") {
output = PNPM_DEPENDENCY_SECTION_RE
.replace_all(&output, |caps: &regex::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
Expand Down
42 changes: 42 additions & 0 deletions crates/vp_cli_snapshots/tests/redact_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <duration> using pnpm <version>\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", "<duration> using pnpm <version>");
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!(
Expand Down
Loading