Repository navigation
fix(cli): render clean/purge Removing paths relative to cwd on Windows - #13046
Conversation
`pnpm clean` / `pnpm purge` built its `Removing <path>` lines by stripping the raw `current_dir()` from targets that are anchored on the symlink-canonicalized `--dir`. On Windows those two representations diverge (casing, 8.3 short names, junctions), so the prefix strip found no common base and leaked the full absolute path into the output, failing the Windows `clean` integration tests on main. Derive the relative path against the canonicalized working directory via `pathdiff::diff_paths` (which mirrors Node's `path.relative`, including walk-ups), so the base shares the targets' representation. The workspace test now builds its expected `Removing pkg/node_modules` text with the platform separator instead of a hard-coded `/`.
📝 WalkthroughWalkthroughThe filesystem crate adds shared platform-aware relative path computation. The clean command uses it for canonicalized removal output, symlink target generation delegates to it, and workspace cleanup tests construct platform-correct expected paths. ChangesRelative path handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoFix clean/purge “Removing …” paths to be cwd-relative on Windows
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Confidence Score: 5/5The change is a narrowly-scoped Windows path display fix with no impact on package installation or filesystem state; the refactored The extraction of No files require special attention. Reviews (2): Last reviewed commit: "refactor(fs): extract root-guarded relat..." | Re-trigger Greptile |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pnpm/crates/cli/src/cli_args/clean.rs (1)
198-203: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winCache the canonicalized CWD for the clean operation.
print_removingperformscurrent_dir()anddunce::canonicalizefor every emitted path. Workspace cleanup can invoke this repeatedly, adding unnecessary filesystem work to the output path hot path. Compute the base once inclean_builtinand pass it into this helper.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pnpm/crates/cli/src/cli_args/clean.rs` around lines 198 - 203, Update clean_builtin to compute the canonicalized current working directory once per clean operation, then pass that base path into print_removing. Remove the current_dir and canonicalize calls from print_removing while preserving its relative-path fallback and “.” handling.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pnpm/crates/cli/src/cli_args/clean.rs`:
- Around line 198-203: Update clean_builtin to compute the canonicalized current
working directory once per clean operation, then pass that base path into
print_removing. Remove the current_dir and canonicalize calls from
print_removing while preserving its relative-path fallback and “.” handling.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 719461f5-a66d-4190-88fb-f453a3aa87a9
📒 Files selected for processing (2)
pnpm/crates/cli/src/cli_args/clean.rspnpm/crates/cli/tests/clean.rs
Code Review by Qodo
Context used✅ Compliance rules (platform):
18 rules 1. Empty cwd fallback leaks paths
|
Micro-Benchmark ResultsLinux |
PR Code Suggestions ✨Latest suggestions up to 3c81b50 Warning
Previous suggestions✅ Suggestions up to commit 5f1d1a6
|
||||||||||||||||||
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #13046 +/- ##
=======================================
Coverage 85.53% 85.53%
=======================================
Files 497 498 +1
Lines 79544 79541 -3
=======================================
- Hits 68038 68037 -1
+ Misses 11506 11504 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…clean Address PR review feedback on the clean/purge Windows path fix: - Hoist the `current_dir()` + `dunce::canonicalize` out of `print_removing` into `clean_builtin`, so the cwd is canonicalized once per command instead of once per removed path. - Replace the bare `pathdiff::diff_paths` call with a shared `pacquet_fs::relative_path`, extracted from `symlink_dir`'s `relative_target_inner`. It carries the Windows `same_path_root` guard, so a target on a different drive/UNC share renders as the absolute path (matching Node's `path.relative`) instead of a re-anchored garbage path. `symlink_dir` now delegates to the same helper rather than duplicating it. - Move the canonicalization rationale from the `print_removing` rustdoc into an implementation `//` comment at the cwd computation.
|
Thanks for the reviews. Follow-up commit 3c81b50 addresses the automated feedback:
Written by an agent (Claude Code, claude-opus-4-8). |
|
Code review by qodo was updated up to the latest commit 3c81b50 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pnpm/crates/cli/src/cli_args/clean.rs (1)
100-105: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider preserving the uncanonicalized directory on failure.
Currently, if
dunce::canonicalizefails (for example, due to missing read permissions on an ancestor directory), it drops the validcurrent_dirand falls back to an empty path, which disables relative path formatting entirely. Falling back to the uncanonicalized current directory is slightly more resilient.♻️ Proposed refactor
// Windows the raw `current_dir()` can differ (casing, 8.3 short names, // junctions) and defeat the relative-path computation. - let cwd = std::env::current_dir().and_then(dunce::canonicalize).unwrap_or_default(); + let cwd = std::env::current_dir() + .map(|d| dunce::canonicalize(&d).unwrap_or(d)) + .unwrap_or_default(); // `pnpm clean` resolves the modules dir relative to each project🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pnpm/crates/cli/src/cli_args/clean.rs` around lines 100 - 105, Update the cwd initialization near the `dunce::canonicalize` call to preserve the successfully retrieved uncanonicalized `current_dir` when canonicalization fails, instead of falling back directly to an empty path. Keep the empty-path fallback only for failure to obtain the current directory.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pnpm/crates/cli/src/cli_args/clean.rs`:
- Around line 100-105: Update the cwd initialization near the
`dunce::canonicalize` call to preserve the successfully retrieved
uncanonicalized `current_dir` when canonicalization fails, instead of falling
back directly to an empty path. Keep the empty-path fallback only for failure to
obtain the current directory.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 029ce116-dd6a-4eb9-afe3-554067db1888
📒 Files selected for processing (4)
pnpm/crates/cli/src/cli_args/clean.rspnpm/crates/fs/src/lib.rspnpm/crates/fs/src/relative_path.rspnpm/crates/fs/src/symlink_dir.rs
Summary
The
Rust CI / Test / windowsjob started failing onmain(run 29437828132) in the newly addedclean/purgecommand tests (pnpm/crates/cli/tests/clean.rs), which had never run on Windows before.pnpm clean/pnpm purgebuilt itsRemoving <path>lines by strippingstd::env::current_dir()from targets that are anchored on the symlink-canonicalized--dir(dispatch runsdunce::canonicalize). On Windows those two representations diverge (casing, 8.3 short names, junctions), so the prefix strip found no common base and leaked the full absolute path (C:\Users\...\workspace\node_modules) instead of the relativenode_modules.The fix derives the relative path against the canonicalized working directory, so the base shares the targets' representation. The
clean_works_in_a_workspacetest now builds its expectedRemoving pkg/node_modulestext with the platform separator instead of a hard-coded/.This is a
pacquet-only fix: the TypeScript CLI already usespath.relative(process.cwd(), p)and does not canonicalize its dir, so it never had this bug.Follow-up (addressing review feedback)
cleanrun and threaded intoprint_removing, instead of once per removed path.pacquet_fs::relative_path, extracted fromsymlink_dir's existing root-guarded diff. It carries the Windowssame_path_rootguard, so a target on a different drive / UNC share renders as the absolute path (matching Node'spath.relative) rather than a re-anchored garbage path;symlink_dirdelegates to the same helper instead of duplicating it.Squash Commit Body
Checklist
pnpm/port, or the description notes what still needs porting.Written by an agent (Claude Code, claude-opus-4-8).