feat(lockfile): support npm-alias dependencies in snapshots#258
Conversation
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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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 useSnapshotDepRef. - Update snapshot building and symlink layout creation so alias keys determine
node_moduleslink 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.
Micro-Benchmark ResultsLinux |
Summary
PkgVerPeeronly parsed bare semver (with optional peer suffix), so lockfiles containing npm-alias references likestring-width-cjs: string-width@4.2.3failed to load withFailed to parse version.SnapshotDepRef—Plain(PkgVerPeer)orAlias(PkgNameVerPeer)— mirroring pnpm'srefToRelativealias detection (ref starts with@, or first@precedes any(and:).SnapshotEntry,build_snapshot, andcreate_symlink_layout: alias entries now use the entry key as the link name undernode_modules/and the aliased target for the virtual-store directory lookup.Test plan
cargo test -p pacquet-lockfile— 42 passing, includes 10 newsnapshot_dep_refcases (plain / alias / scoped alias / alias-with-peer-suffix parsing, resolve semantics, display roundtrip, YAML deserialize,looks_like_aliasrules).@isaacs/cliui@8.0.2) —pacquet install --frozen-lockfilenow succeeds and produces the correct symlinks:string-width-cjs -> .pnpm/string-width@4.2.3/node_modules/string-widthstrip-ansi-cjs -> .pnpm/strip-ansi@6.0.1/node_modules/strip-ansiwrap-ansi-cjs -> .pnpm/wrap-ansi@7.0.0/node_modules/wrap-ansicargo buildclean.