Skip to content
This repository was archived by the owner on May 14, 2026. It is now read-only.

feat(lockfile): support npm-alias dependencies in snapshots#258

Merged
zkochan merged 2 commits into
mainfrom
feat/snapshot-alias-deps
Apr 24, 2026
Merged

feat(lockfile): support npm-alias dependencies in snapshots#258
zkochan merged 2 commits into
mainfrom
feat/snapshot-alias-deps

Conversation

@zkochan

@zkochan zkochan commented Apr 24, 2026

Copy link
Copy Markdown
Member

Summary

  • Pacquet's snapshot-dep value type PkgVerPeer only parsed bare semver (with optional peer suffix), so lockfiles containing npm-alias references like string-width-cjs: string-width@4.2.3 failed to load with Failed to parse version.
  • Introduce SnapshotDepRefPlain(PkgVerPeer) or Alias(PkgNameVerPeer) — mirroring pnpm's refToRelative alias detection (ref starts with @, or first @ precedes any ( and :).
  • Thread the new type through SnapshotEntry, build_snapshot, and create_symlink_layout: alias entries now use the entry key as the link name under node_modules/ and the aliased target for the virtual-store directory lookup.

Test plan

  • cargo test -p pacquet-lockfile — 42 passing, includes 10 new snapshot_dep_ref cases (plain / alias / scoped alias / alias-with-peer-suffix parsing, resolve semantics, display roundtrip, YAML deserialize, looks_like_alias rules).
  • Repro install against the failing lockfile (@isaacs/cliui@8.0.2) — pacquet install --frozen-lockfile now succeeds and produces the correct symlinks:
    • string-width-cjs -> .pnpm/string-width@4.2.3/node_modules/string-width
    • strip-ansi-cjs -> .pnpm/strip-ansi@6.0.1/node_modules/strip-ansi
    • wrap-ansi-cjs -> .pnpm/wrap-ansi@7.0.0/node_modules/wrap-ansi
  • Full cargo build clean.

zkochan added 2 commits April 24, 2026 05:45
Snapshot dependency values can be either a plain version (e.g. `5.1.2`)
or an npm-alias reference (e.g. `string-width-cjs: string-width@4.2.3`,
produced by `"string-width-cjs": "npm:string-width@^4.2.0"` in a
consumer's package.json). Parsing the alias form as `PkgVerPeer` failed
because it is not a bare semver.

Introduce `SnapshotDepRef` — `Plain(PkgVerPeer)` or `Alias(PkgNameVerPeer)`
— mirroring pnpm's `refToRelative` alias detection, and thread it through
the snapshot → virtual-store symlink path: alias entries use the entry
key as the link name under `node_modules/` and the aliased target for
the virtual-store lookup.
@codecov

codecov Bot commented Apr 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.88525% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.93%. Comparing base (4220053) to head (0dba1db).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/lockfile/src/snapshot_dep_ref.rs 92.85% 8 Missing ⚠️
...rates/package-manager/src/create_symlink_layout.rs 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #258      +/-   ##
==========================================
+ Coverage   89.88%   89.93%   +0.05%     
==========================================
  Files          57       58       +1     
  Lines        4358     4471     +113     
==========================================
+ Hits         3917     4021     +104     
- Misses        441      450       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI 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.

Pull request overview

Adds first-class support for npm-alias dependency references in lockfile snapshot dependency maps so pnpm-style entries like string-width-cjs: string-width@4.2.3 can be parsed and correctly materialized into node_modules/ symlinks.

Changes:

  • Introduce SnapshotDepRef (Plain(PkgVerPeer) | Alias(PkgNameVerPeer)) with pnpm-like alias detection and serde/string parsing.
  • Update lockfile snapshot schema (SnapshotEntry.dependencies / optional_dependencies) to use SnapshotDepRef.
  • Update snapshot building and symlink layout creation so alias keys determine node_modules link names while the aliased target determines the virtual-store lookup.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/package-manager/src/create_symlink_layout.rs Materialize aliased deps by linking node_modules/<alias> to the target package directory in the virtual store.
crates/package-manager/src/build_snapshot.rs Emit snapshot dependencies as SnapshotDepRef::Plain(...) when building lockfile snapshots from resolved deps.
crates/lockfile/src/snapshot_entry.rs Change snapshot dependency value type to SnapshotDepRef for parsing/serialization support.
crates/lockfile/src/snapshot_dep_ref.rs New type + parsing/serde + tests for plain vs alias snapshot dependency references.
crates/lockfile/src/lib.rs Wire the new module and re-export SnapshotDepRef.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

Copy link
Copy Markdown

Micro-Benchmark Results

Linux

group                          main                                   pr
-----                          ----                                   --
tarball/download_dependency    1.00     19.0±0.55ms   228.4 KB/sec    1.09    20.6±13.89ms   210.1 KB/sec

@zkochan zkochan merged commit badb479 into main Apr 24, 2026
16 of 19 checks passed
@zkochan zkochan deleted the feat/snapshot-alias-deps branch April 24, 2026 04:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants