Repository navigation
Fix/13556 exclude links lockfile relative - #13561
Ayush442842q wants to merge 2 commits into
Conversation
…to satisfy clippy/dylint
📝 WalkthroughWalkthroughThe resolver now anchors relative ChangesRelative link remapping
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
Possibly related PRs
Suggested labels: Suggested reviewers: ✨ Finishing Touches 💡 1⚔️ Resolve merge conflicts 💡
🧪 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 relative workspace link remapping with excludeLinksFromLockfile
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
.changeset/fix-exclude-links-lockfile-relative-path.md (1)
5-5: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDescribe the observable fix, not the resolver implementation.
Keep the workspace-internal remapping bug in the note. Remove the explanation about resolving targets against
project_dirand containment checks.Proposed wording
-Fixed an issue where `excludeLinksFromLockfile` incorrectly remaps workspace-internal `link:` dependencies by resolving relative link targets against the importer's `project_dir` before performing the subdirectory containment check. +Fixed an issue where `excludeLinksFromLockfile` incorrectly remaps workspace-internal `link:` dependencies.Based on learnings, “Changesets should describe the user-visible behavior that the change affects.”
🤖 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 @.changeset/fix-exclude-links-lockfile-relative-path.md at line 5, Update the changeset note to describe only the observable fix: workspace-internal link dependencies are no longer incorrectly remapped by excludeLinksFromLockfile. Remove implementation details about project_dir resolution and subdirectory containment checks.Source: Learnings
🤖 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.
Inline comments:
In `@pnpm/crates/resolving-deps-resolver/src/resolve_peers/tests.rs`:
- Around line 2274-2282: Add a test case in the resolve peers tests covering
remap_link_node_id when ResolvePeersOptions.project_dir is None, using a
relative link target and asserting it resolves from the importer directory
rather than as-is. Alternatively, explicitly document existing coverage that
preserves this behavior, while keeping the current project_dir-provided case
unchanged.
---
Nitpick comments:
In @.changeset/fix-exclude-links-lockfile-relative-path.md:
- Line 5: Update the changeset note to describe only the observable fix:
workspace-internal link dependencies are no longer incorrectly remapped by
excludeLinksFromLockfile. Remove implementation details about project_dir
resolution and subdirectory containment checks.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 86daf4e8-2b5c-4bca-b606-481642e50849
📒 Files selected for processing (3)
.changeset/fix-exclude-links-lockfile-relative-path.mdpnpm/crates/resolving-deps-resolver/src/resolve_peers.rspnpm/crates/resolving-deps-resolver/src/resolve_peers/tests.rs
Confidence Score: 4/5The workspace-level peer-resolution path still misclassifies relative internal links and should be fixed before merging. The new conversion depends on Files Needing Attention: pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs, pnpm/crates/resolving-deps-resolver/src/resolve_peers/tests.rs Reviews (1): Last reviewed commit: "test(resolving-deps-resolver): fix singl..." | Re-trigger Greptile |
Code Review by Qodo
Context used✅ Compliance rules (platform):
24 rules 1. Workspace misses project_dir
|
| let absolute_target = if link_target.is_absolute() { | ||
| std::borrow::Cow::Borrowed(link_target) | ||
| } else if let Some(project_dir) = &opts.project_dir { | ||
| std::borrow::Cow::Owned(project_dir.join(link_target)) | ||
| } else { | ||
| std::borrow::Cow::Borrowed(link_target) | ||
| }; | ||
| if pacquet_fs::is_subdir(lockfile_dir, &absolute_target) { |
There was a problem hiding this comment.
2. Workspace misses project_dir 🐞 Bug ≡ Correctness
remap_link_node_id only resolves relative link: targets against opts.project_dir, but the workspace multi-importer path leaves project_dir unset and never swaps it per importer, so workspace-internal relative targets can still be misclassified as external and remapped when exclude_links_from_lockfile is enabled.
Agent Prompt
### Issue description
`remap_link_node_id()` now relies on `ResolvePeersOptions.project_dir` to resolve relative `link:` targets before the `is_subdir(lockfile_dir, ...)` containment check. However, `resolve_peers_workspace()` (multi-importer workspace resolver) initializes `ResolvePeersOptions` with `project_dir: None` and only swaps `modules_dir` per importer, so `remap_link_node_id()` falls back to the old behavior in this main workspace path.
### Issue Context
- Single-importer resolution (`resolve_importer`) sets `project_dir: Some(...)`, so the fix applies there.
- Workspace resolution (`resolve_workspace` → `resolve_peers_workspace`) sets `project_dir: None` and does not override it in the per-importer loop.
- The new unit test calls `remap_link_node_id()` directly with `project_dir: Some(...)`, so it doesn’t exercise the workspace driver behavior.
### Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs[648-701]
- pnpm/crates/resolving-deps-resolver/src/resolve_workspace.rs[371-384]
- pnpm/crates/resolving-deps-resolver/src/resolve_peers/tests.rs[2266-2370]
### Suggested fix
1. In `resolve_peers_workspace()`:
- Before building `root_parents` and before each importer’s `build_importer_parents_from(...)` / walk, set `walker.opts.project_dir = Some(importer.root_dir.clone())` (save/restore if needed, similar to the existing `modules_dir` swapping).
2. Add an integration-ish unit test that exercises the workspace driver behavior (or extend the existing test) to ensure a relative internal `link:` target does **not** get remapped when running through the `resolve_peers_workspace` importer loop.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Code review by qodo was updated up to the latest commit 5c97d51 |
Summary
This PR fixes a bug in
pacquet(the Rust CLI) where workspace-internallink:dependencies were incorrectly remapped whenexcludeLinksFromLockfilewas enabled.The issue occurred because the resolver checked whether a link target was inside the workspace by calling
pacquet_fs::is_subdirusing a relative target directory (e.g.../lib), which failed to match the absolutelockfile_dircoordinate system. We now resolve relative target directories against the importer'sproject_dirprior to checking containment.Closes #13556.
Squash Commit Body
The function
remap_link_node_idinpacquet-resolving-deps-resolverchecks if a link target directory is insidelockfile_dirusingpacquet_fs::is_subdir. However,is_subdiris purely lexical and does not resolve relative paths against a base. For workspacelink:dependencies, targets are emitted relative to the importer'sproject_dirrather thanlockfile_dir(e.g.,../libinstead of/ws/packages/lib). Because of this difference in coordinate systems, the check would fail and the internal link was incorrectly remapped.To fix this, we resolve the relative link target path against
project_dirbefore passing it tois_subdir. Ifproject_diris missing (e.g., in unit tests) or the target path is absolute, it falls back to the original target.Closes #13556.
Checklist
already linked to it solves it.
pnpm/port, or the description notes what still needs porting.(Note: This fix is Rust-only;
excludeLinksFromLockfilehas no counterpart in the TypeScript CLI.)pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
Bug Fixes
Tests