Skip to content

Fix/13556 exclude links lockfile relative - #13561

Closed
Ayush442842q wants to merge 2 commits into
pnpm:mainfrom
Ayush442842q:fix/13556-exclude-links-lockfile-relative
Closed

Ayush442842q wants to merge 2 commits into
pnpm:mainfrom
Ayush442842q:fix/13556-exclude-links-lockfile-relative

Conversation

@Ayush442842q

@Ayush442842q Ayush442842q commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR fixes a bug in pacquet (the Rust CLI) where workspace-internal link: dependencies were incorrectly remapped when excludeLinksFromLockfile was enabled.

The issue occurred because the resolver checked whether a link target was inside the workspace by calling pacquet_fs::is_subdir using a relative target directory (e.g. ../lib), which failed to match the absolute lockfile_dir coordinate system. We now resolve relative target directories against the importer's project_dir prior to checking containment.

Closes #13556.

Squash Commit Body

The function remap_link_node_id in pacquet-resolving-deps-resolver checks if a link target directory is inside lockfile_dir using pacquet_fs::is_subdir. However, is_subdir is purely lexical and does not resolve relative paths against a base. For workspace link: dependencies, targets are emitted relative to the importer's project_dir rather than lockfile_dir (e.g., ../lib instead 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_dir before passing it to is_subdir. If project_dir is missing (e.g., in unit tests) or the target path is absolute, it falls back to the original target.

Closes #13556.

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting.
    (Note: This fix is Rust-only; excludeLinksFromLockfile has no counterpart in the TypeScript CLI.)
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests.
  • Updated the documentation if needed.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed workspace-internal relative link dependencies being incorrectly remapped in lockfiles.
    • Improved handling of relative and absolute link targets, ensuring only links outside the workspace are remapped.
    • Preserved expected behavior when link exclusion is disabled.
  • Tests

    • Added coverage for internal, external, relative, and absolute link targets.

@Ayush442842q
Ayush442842q requested a review from zkochan as a code owner August 1, 2026 15:30
@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The resolver now anchors relative link: targets to project_dir before lockfile containment checks. Tests cover internal and external relative or absolute targets, plus disabled link exclusion.

Changes

Relative link remapping

Layer / File(s) Summary
Resolver containment behavior
pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs
remap_link_node_id resolves relative targets against project_dir before checking lockfile containment.
Remapping coverage and release note
pnpm/crates/resolving-deps-resolver/src/resolve_peers/tests.rs, .changeset/fix-exclude-links-lockfile-relative-path.md
Tests cover internal and external relative or absolute targets and disabled exclusion. The changeset documents the patch.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • pnpm/pnpm issue 13556 — Directly tracks the relative-path containment bug fixed here.

Possibly related PRs

  • pnpm/pnpm#13551 — Both changes modify remap_link_node_id for importer-relative link: paths and containment validation.

Suggested labels: product: pacquet

Suggested reviewers: zkochan

✨ Finishing Touches 💡 1
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch fix/13556-exclude-links-lockfile-relative
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Fix relative workspace link remapping with excludeLinksFromLockfile

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Resolve relative link: targets against the importer project_dir before workspace containment
 checks.
• Prevent workspace-internal links from being incorrectly remapped when excludeLinksFromLockfile
 is enabled.
• Add unit coverage for relative/absolute and in-/out-of-workspace containment cases.
Diagram

graph TD
  A["ResolvePeersOptions"] --> B["remap_link_node_id"] --> C["Make target absolute"] --> D{"Inside lockfile_dir?"}
  D -->|"yes"| E["Return None (no remap)"]
  D -->|"no"| F["Return NodeId link:<rel modules path>"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Canonicalize paths before containment check
  • ➕ Correctly accounts for symlinks and filesystem reality, not just lexical .. segments
  • ➕ Potentially avoids subtle edge cases when paths contain redundant segments
  • ➖ Requires filesystem I/O; can fail in tests/virtualized scenarios and adds latency
  • ➖ Behavior may vary across platforms and symlink setups, reducing determinism
2. Move relative-target normalization into pacquet_fs::is_subdir (or a helper)
  • ➕ Centralizes path coordinate-system handling for all containment checks
  • ➕ Reduces chance of future call sites repeating the same mistake
  • ➖ API change / broader refactor; needs audit of existing call sites and semantics
  • ➖ Harder to pick the correct base dir generically (project_dir vs lockfile_dir vs cwd)

Recommendation: The PR’s approach (join relative targets to the importer’s project_dir only when needed) is the best tradeoff: it fixes the coordinate-system bug without introducing I/O or changing global path-containment semantics. Consider a follow-up helper for “containment with base dir” if this pattern appears elsewhere.

Files changed (3) +120 / -2

Bug fix (1) +8 / -1
resolve_peers.rsResolve relative link targets against project_dir in remap_link_node_id +8/-1

Resolve relative link targets against project_dir in remap_link_node_id

• Updates 'remap_link_node_id' to convert relative 'link:' target directories into an absolute path by joining with 'opts.project_dir' before calling 'pacquet_fs::is_subdir'. This prevents workspace-internal links from being misclassified as external when the lockfile and link target paths use different coordinate bases.

pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs

Tests (1) +107 / -1
tests.rsAdd containment tests for remap_link_node_id +107/-1

Add containment tests for remap_link_node_id

• Imports 'remap_link_node_id' and adds a unit test covering relative/absolute link targets both inside and outside 'lockfile_dir', plus the behavior when 'exclude_links_from_lockfile' is disabled.

pnpm/crates/resolving-deps-resolver/src/resolve_peers/tests.rs

Documentation (1) +5 / -0
fix-exclude-links-lockfile-relative-path.mdAdd patch changeset describing the link-remap fix +5/-0

Add patch changeset describing the link-remap fix

• Adds a 'pacquet' patch changeset documenting the bug fix for 'excludeLinksFromLockfile' and workspace-internal 'link:' dependencies.

.changeset/fix-exclude-links-lockfile-relative-path.md

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
.changeset/fix-exclude-links-lockfile-relative-path.md (1)

5-5: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Describe the observable fix, not the resolver implementation.

Keep the workspace-internal remapping bug in the note. Remove the explanation about resolving targets against project_dir and 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

📥 Commits

Reviewing files that changed from the base of the PR and between fa8d383 and 5c97d51.

📒 Files selected for processing (3)
  • .changeset/fix-exclude-links-lockfile-relative-path.md
  • pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs
  • pnpm/crates/resolving-deps-resolver/src/resolve_peers/tests.rs

@greptile-apps

greptile-apps Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

The workspace-level peer-resolution path still misclassifies relative internal links and should be fixed before merging.

The new conversion depends on opts.project_dir, but resolve_peers_workspace leaves that field unset while processing importer-relative workspace links, so the containment comparison remains between incompatible path coordinate systems.

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

@qodo-code-review

qodo-code-review Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (1) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 24 rules

Grey Divider


Action required

1. Workspace misses project_dir 🐞 Bug ≡ Correctness ⭐ New
Description
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.
Code

pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs[R3870-3877]

+    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) {
Relevance

●●● Strong

Team has accepted prior fixes around project_dir-relative link/specifier handling in this resolver
area (e.g. accepted review in PR #13343).

PR-#13343

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The PR change makes relative-target containment depend on opts.project_dir, but the workspace
resolver path explicitly sets project_dir: None and only swaps modules_dir per importer, so the
new resolution branch is never taken in that path; the added unit test only validates the
project_dir: Some(...) case.

pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs[3855-3884]
pnpm/crates/resolving-deps-resolver/src/resolve_workspace.rs[371-384]
pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs[675-700]
pnpm/crates/resolving-deps-resolver/src/resolve_peers/tests.rs[2266-2282]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### 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



Remediation recommended

2. Win-absolute misclassified on POSIX 🐞 Bug ⛨ Security
Description
On POSIX, Windows-drive/UNC absolute strings (e.g. C:\foo or \\server\share) are not
Path::is_absolute(), so remap_link_node_id now joins them to project_dir, causing
is_subdir(lockfile_dir, ...) to incorrectly treat them as workspace-internal and skip remapping.
This undermines exclude_links_from_lockfile for cross-platform lockfiles/configs and can
reintroduce machine-specific link node IDs / unstable peer-suffix behavior for those entries.
Code

pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs[R3870-3877]

+    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) {
Relevance

●●● Strong

Team previously accepted mixed POSIX/Win absolute link: path fix; likely accept similar
Windows-drive detection here.

PR-#12430

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new code resolves any non-absolute directory against project_dir, and is_subdir performs a
lexical normalization + prefix check; therefore a POSIX-joined path like /ws/.../C:\foo will start
with /ws and be treated as inside the workspace, even though the original target is
Windows-absolute. The repo already contains explicit Windows-drive detection helpers, and a similar
mixed-flavor absolute-path issue was previously fixed in the TypeScript implementation.

pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs[3855-3884]
pnpm/crates/fs/src/is_subdir.rs[5-17]
pnpm/crates/cli/src/cli_args/global.rs[672-678]
PR-#12430

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`remap_link_node_id()` uses `Path::is_absolute()` to decide whether to resolve a `link:` target against `project_dir`. On POSIX, Windows-style absolute paths like `C:\foo` or `\\server\share\foo` are **not** considered absolute by `std::path`, so they get incorrectly joined to `project_dir`, making `pacquet_fs::is_subdir(lockfile_dir, ...)` think the target is inside the workspace.

### Issue Context
This is a cross-platform path-flavor bug: POSIX pacquet processing a Windows-flavored `link:` directory string (e.g. from a lockfile or config authored on Windows).

### Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs[3869-3877]

### Suggested fix
1. Before the `project_dir.join(link_target)` branch, add a host-independent detection for Windows-absolute path strings (drive-letter `^[A-Za-z]:` and UNC `^\\\\` / possibly `^//`).
2. If the directory string matches Windows-absolute, treat it as “absolute-like”: do **not** join against `project_dir` (keep it as `Borrowed(link_target)`), so the subdir check correctly treats it as outside `lockfile_dir` on POSIX and performs the remap.
3. Add a regression test (likely `#[cfg(not(windows))]`) that sets `directory` to `"C:\\external"` (and optionally a UNC example) and asserts the function returns `Some(NodeId::leaf("link:..."))` when `exclude_links_from_lockfile` is enabled.

(There are already similar Windows-drive detectors in the repo; consider factoring a shared helper if appropriate.)

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

3. Changeset missing pnpm entry 📘 Rule violation § Compliance ⭐ New
Description
The new changeset lists only pacquet and omits the required pnpm package entry. This can cause
the pnpm release workflow to miss the intended version bump/release note association.
Code

.changeset/fix-exclude-links-lockfile-relative-path.md[R1-3]

+---
+"pacquet": patch
+---
Relevance

● Weak

Similar “add pnpm entry to pacquet-only changeset” suggestions were repeatedly rejected/merged
anyway (e.g. PRs #13549, #13545).

PR-#13549
PR-#13545

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713436 requires that newly added/modified changeset files include an explicit
pnpm entry with a correct bump type. The added changeset front-matter includes only `"pacquet":
patch, so pnpm` is missing.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/fix-exclude-links-lockfile-relative-path.md[1-3]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The changeset front-matter omits a `pnpm` entry, but the compliance checklist requires every changeset to explicitly include `pnpm` with a valid bump type (`patch`/`minor`/`major`).

## Issue Context
This PR adds `.changeset/fix-exclude-links-lockfile-relative-path.md` with only a `pacquet` bump.

## Fix Focus Areas
- .changeset/fix-exclude-links-lockfile-relative-path.md[1-3]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ  1 issues published inline · 2 in summary

To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Previous review results

Review updated until commit 5c97d51 ⚖️ Balanced

Results up to commit 5c97d51 ⚖️ Balanced


🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Remediation recommended
1. Win-absolute misclassified on POSIX 🐞 Bug ⛨ Security
Description
On POSIX, Windows-drive/UNC absolute strings (e.g. C:\foo or \\server\share) are not
Path::is_absolute(), so remap_link_node_id now joins them to project_dir, causing
is_subdir(lockfile_dir, ...) to incorrectly treat them as workspace-internal and skip remapping.
This undermines exclude_links_from_lockfile for cross-platform lockfiles/configs and can
reintroduce machine-specific link node IDs / unstable peer-suffix behavior for those entries.
Code

pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs[R3870-3877]

+    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) {
Relevance

●●● Strong

Team previously accepted mixed POSIX/Win absolute link: path fix; likely accept similar
Windows-drive detection here.

PR-#12430

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new code resolves any non-absolute directory against project_dir, and is_subdir performs a
lexical normalization + prefix check; therefore a POSIX-joined path like /ws/.../C:\foo will start
with /ws and be treated as inside the workspace, even though the original target is
Windows-absolute. The repo already contains explicit Windows-drive detection helpers, and a similar
mixed-flavor absolute-path issue was previously fixed in the TypeScript implementation.

pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs[3855-3884]
pnpm/crates/fs/src/is_subdir.rs[5-17]
pnpm/crates/cli/src/cli_args/global.rs[672-678]
PR-#12430

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`remap_link_node_id()` uses `Path::is_absolute()` to decide whether to resolve a `link:` target against `project_dir`. On POSIX, Windows-style absolute paths like `C:\foo` or `\\server\share\foo` are **not** considered absolute by `std::path`, so they get incorrectly joined to `project_dir`, making `pacquet_fs::is_subdir(lockfile_dir, ...)` think the target is inside the workspace.

### Issue Context
This is a cross-platform path-flavor bug: POSIX pacquet processing a Windows-flavored `link:` directory string (e.g. from a lockfile or config authored on Windows).

### Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/resolve_peers.rs[3869-3877]

### Suggested fix
1. Before the `project_dir.join(link_target)` branch, add a host-independent detection for Windows-absolute path strings (drive-letter `^[A-Za-z]:` and UNC `^\\\\` / possibly `^//`).
2. If the directory string matches Windows-absolute, treat it as “absolute-like”: do **not** join against `project_dir` (keep it as `Borrowed(link_target)`), so the subdir check correctly treats it as outside `lockfile_dir` on POSIX and performs the remap.
3. Add a regression test (likely `#[cfg(not(windows))]`) that sets `directory` to `"C:\\external"` (and optionally a UNC example) and asserts the function returns `Some(NodeId::leaf("link:..."))` when `exclude_links_from_lockfile` is enabled.

(There are already similar Windows-drive detectors in the repo; consider factoring a shared helper if appropriate.)

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Qodo Logo

Comment on lines +3870 to +3877
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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

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

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 5c97d51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

excludeLinksFromLockfile remaps workspace-internal link: deps because the containment check compares a relative path

1 participant