Repository navigation
fix: reuse the version resolution would dedupe onto for a changed range - #13779
Conversation
The importers fast update asked whether the locked version satisfies the new range and kept it when it did. Resolution asks a different question: preferredVersions makes it reuse the highest version of that alias already in the graph, which beats picking the highest published one. The two answers differ whenever some other importer or transitive dependency already holds a higher satisfying version, so widening a range through the fast path left the importer behind and kept a duplicate the resolver would have collapsed. Both stacks now pick the highest already-locked satisfying version, letting the shared epilogue prune whatever the move orphans. That also covers a range the locked version cannot satisfy at all but a present one can, which no longer falls back to the resolver. Bails kept for a candidate under peer-suffixed keys (the choice would be a guess) and for anything that is not plain semver. Closes #13778. Item 4 of #13696.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughFast importer updates in Rust and TypeScript now reuse the highest compatible non-peer version already in the lockfile. They update references, prune replaced entries, and fall back to resolution when no safe locked version exists. Tests cover reuse, deduplication, pruning, and resolution. ChangesLocked Version Reuse
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related issues
Possibly related PRs
Suggested labels: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. 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 fast lockfile update to reuse highest locked version on range changes
AI Description
Diagram
High-Level Assessment
Files changed (5)
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/package-manager/src/fast_update_importers.rs`:
- Line 66: Update the fast update flow around candidate.packages to borrow the
package map instead of cloning all package metadata. Preserve the empty-map
fallback without allocating or copying the full collection, while allowing
candidate.importers to be mutated through disjoint field access.
🪄 Autofix
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: 5727f271-ca44-4fbc-8a91-8c08c7405a5f
📒 Files selected for processing (5)
.changeset/locked-version-reuse.mdpnpm/crates/package-manager/src/fast_update_importers.rspnpm/crates/package-manager/src/fast_update_importers/tests.rspnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.tspnpm11/installing/deps-installer/test/install/lockedVersionReuse.ts
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Reviews (2): Last reviewed commit: "fix: exclude registry-qualified keys fro..." | Re-trigger Greptile |
Code Review by Qodo
1. Missing snapshot validation
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Micro-Benchmark ResultsLinux |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #13779 +/- ##
==========================================
+ Coverage 88.13% 88.16% +0.03%
==========================================
Files 623 623
Lines 101413 101523 +110
==========================================
+ Hits 89383 89511 +128
+ Misses 12030 12012 -18 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Integrated-Benchmark Report (Linux)Commit: Regular scenarios report direct and pnpr installs. The peer-heavy resolver scenario compares current Rust, main Rust, and TypeScript pnpm. Bencher consumes pacquet@HEAD and pnpr@HEAD. The tables below show mean ± σ; Bencher thresholds on the minimum latency, which is far less perturbed by shared-runner contention (noise only adds time). Scenario: Isolated linker: fresh restore, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.5943583070800003,
"stddev": 0.1559280493876055,
"median": 2.5467727250800003,
"user": 2.3949281399999998,
"system": 1.78828046,
"min": 2.40286920708,
"max": 2.8845650380800003,
"times": [
2.5270574280800004,
2.65778230108,
2.49123154208,
2.4597243520800003,
2.40286920708,
2.56648802208,
2.79949385408,
2.48452121608,
2.66985011008,
2.8845650380800003
]
},
{
"command": "pacquet@main",
"mean": 2.70703286688,
"stddev": 0.15464563869776807,
"median": 2.7467743765800003,
"user": 2.3868980399999997,
"system": 1.80588636,
"min": 2.5270360020800005,
"max": 2.9810523530800004,
"times": [
2.55551629608,
2.5669593820800003,
2.9810523530800004,
2.5326796880800004,
2.72706217808,
2.79383417208,
2.76648657508,
2.8427258020800004,
2.5270360020800005,
2.7769762200800003
]
},
{
"command": "pnpr@HEAD",
"mean": 1.5368504896800002,
"stddev": 0.10508635368629138,
"median": 1.5295848590799999,
"user": 1.45280894,
"system": 1.38629156,
"min": 1.40185695908,
"max": 1.73983603808,
"times": [
1.5306419650799998,
1.56285636808,
1.67574145508,
1.43362772708,
1.73983603808,
1.45569781308,
1.40185695908,
1.48769591708,
1.5285277530799999,
1.55202290108
]
},
{
"command": "pnpr@main",
"mean": 1.5519914188800001,
"stddev": 0.15974449041755545,
"median": 1.50965169658,
"user": 1.3972507399999998,
"system": 1.33891986,
"min": 1.39706239208,
"max": 1.85744889208,
"times": [
1.6779910740800001,
1.49456822608,
1.40104996508,
1.52473516708,
1.40913774708,
1.44290552108,
1.57066391408,
1.39706239208,
1.85744889208,
1.74435129008
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.27020800601999995,
"stddev": 0.012691491601364775,
"median": 0.26877020662,
"user": 0.23927298000000002,
"system": 0.53071012,
"min": 0.24819239862000003,
"max": 0.28711415862,
"times": [
0.28711415862,
0.27032286362,
0.28100440962,
0.27536233862,
0.26152848761999997,
0.25763568861999997,
0.24819239862000003,
0.26671656162,
0.26721754962,
0.28698560362
]
},
{
"command": "pacquet@main",
"mean": 0.32144103172,
"stddev": 0.01996771106185293,
"median": 0.31283904512000005,
"user": 0.29255628,
"system": 0.64262722,
"min": 0.30401365662,
"max": 0.36241991262,
"times": [
0.34353103062,
0.36241991262,
0.32925337062,
0.30702160562,
0.33269891762,
0.31637872162,
0.30569592362,
0.30401365662,
0.30929936862,
0.30409780962
]
},
{
"command": "pnpr@HEAD",
"mean": 0.34314308482,
"stddev": 0.05646020994928592,
"median": 0.32613357612000005,
"user": 0.29562237999999996,
"system": 0.64383152,
"min": 0.28785396562,
"max": 0.47538486862,
"times": [
0.32814789762,
0.30328720362,
0.31310390562,
0.30190459662,
0.28785396562,
0.32411925462,
0.39060118862,
0.37472035962,
0.47538486862,
0.33230760762
]
},
{
"command": "pnpr@main",
"mean": 0.34479653961999995,
"stddev": 0.0232714026193789,
"median": 0.35155384662,
"user": 0.2905865799999999,
"system": 0.64575602,
"min": 0.29645606862,
"max": 0.36698906062000003,
"times": [
0.35938135362,
0.36698906062000003,
0.34633631062,
0.33607343262,
0.34417641162,
0.36092993862,
0.35677138262,
0.36603097262,
0.31482046462,
0.29645606862
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.6642999664,
"stddev": 0.06920456220972428,
"median": 2.6762079743999996,
"user": 2.00797248,
"system": 1.57450344,
"min": 2.5800057619,
"max": 2.7581004289,
"times": [
2.7449133699,
2.7372724409,
2.7581004289,
2.6855364848999996,
2.6830343719,
2.6693815768999998,
2.6032732518999997,
2.5917418719,
2.5800057619,
2.5897401048999997
]
},
{
"command": "pacquet@main",
"mean": 2.5903235170000003,
"stddev": 0.026770175421694086,
"median": 2.5809057884,
"user": 1.73107678,
"system": 1.38570854,
"min": 2.5716532099,
"max": 2.6602847629,
"times": [
2.5943331429,
2.5994174559,
2.5775496198999996,
2.5842619569,
2.6602847629,
2.5716532099,
2.5958999338999997,
2.5751445699,
2.5723542649,
2.5723362529
]
},
{
"command": "pnpr@HEAD",
"mean": 1.6346251160999998,
"stddev": 0.16635328104976446,
"median": 1.6253905209000001,
"user": 1.2060152800000001,
"system": 1.1774724399999998,
"min": 1.4288936729000001,
"max": 1.8232203489000003,
"times": [
1.4968873979000001,
1.4694578089,
1.4682601009,
1.7873995859,
1.7019998039000002,
1.8097279419,
1.8232203489000003,
1.8116232619000001,
1.4288936729000001,
1.5487812379
]
},
{
"command": "pnpr@main",
"mean": 1.5739605634,
"stddev": 0.14401767917336092,
"median": 1.5271946489000001,
"user": 1.24524598,
"system": 1.17917464,
"min": 1.4365475469000002,
"max": 1.8607476829000003,
"times": [
1.8607476829000003,
1.4488374669000001,
1.7802883499000002,
1.4532954489,
1.4365475469000002,
1.5248555979,
1.5076127029000002,
1.5295336999000002,
1.6358098139000001,
1.5620773239
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.42020578942000003,
"stddev": 0.01964282189102156,
"median": 0.42153941862,
"user": 0.51849536,
"system": 0.6932561399999999,
"min": 0.39131605912,
"max": 0.44459040712000003,
"times": [
0.41185618212,
0.40575271112,
0.43367966912,
0.44234447912,
0.44459040712000003,
0.43122265512,
0.43627460412,
0.39590589212000005,
0.40911523512000003,
0.39131605912
]
},
{
"command": "pacquet@main",
"mean": 0.42202473372,
"stddev": 0.028454804434002653,
"median": 0.41659337712,
"user": 0.5072633599999999,
"system": 0.69604094,
"min": 0.37888995212000004,
"max": 0.46372728412,
"times": [
0.45424031512,
0.37888995212000004,
0.41105397212,
0.41136737612,
0.44335693712,
0.42181937812000003,
0.46372728412,
0.39250893812000004,
0.44497621812000004,
0.39830696612
]
},
{
"command": "pnpr@HEAD",
"mean": 0.29489233422,
"stddev": 0.005753530960841422,
"median": 0.29357379662000005,
"user": 0.18905645999999998,
"system": 0.49928014000000004,
"min": 0.28785044612,
"max": 0.30485386212000004,
"times": [
0.28785044612,
0.30333700512,
0.29152179512000004,
0.29611874812,
0.29056248612,
0.28929502612,
0.29388490812,
0.30485386212000004,
0.29823638012000003,
0.29326268512000003
]
},
{
"command": "pnpr@main",
"mean": 0.29001822922000003,
"stddev": 0.009803760151633296,
"median": 0.28691149612,
"user": 0.19494006,
"system": 0.5053653399999999,
"min": 0.28166391612,
"max": 0.31283198612,
"times": [
0.28570611612,
0.29181037612,
0.28174118812,
0.29870829612,
0.28166391612,
0.28178868812,
0.28471694012000004,
0.29309790912,
0.31283198612,
0.28811687612000003
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.7148885737400001,
"stddev": 0.009898711124147154,
"median": 1.71537581164,
"user": 0.79120278,
"system": 0.7551707400000001,
"min": 1.69469994914,
"max": 1.72920286314,
"times": [
1.71400009214,
1.72058417214,
1.72528996814,
1.71236757814,
1.70632365414,
1.69469994914,
1.7167515311400001,
1.71010154914,
1.72920286314,
1.71956438014
]
},
{
"command": "pacquet@main",
"mean": 1.70584104994,
"stddev": 0.009057116307962994,
"median": 1.7026659091400003,
"user": 0.75239088,
"system": 0.7613546400000001,
"min": 1.6968655321400001,
"max": 1.72722874614,
"times": [
1.71156187414,
1.6968655321400001,
1.69864782114,
1.71056814814,
1.70144707714,
1.69882458014,
1.7022255651400002,
1.72722874614,
1.70793490214,
1.70310625314
]
},
{
"command": "pnpr@HEAD",
"mean": 0.30349932784000005,
"stddev": 0.01516611530541227,
"median": 0.3003935106400001,
"user": 0.21518898000000003,
"system": 0.50111714,
"min": 0.28825627414000005,
"max": 0.33630796014000003,
"times": [
0.29679124514000005,
0.28998179414,
0.28825627414000005,
0.29550716914,
0.31480736014000005,
0.31334070514000006,
0.28840185414,
0.30399577614000006,
0.30760314014000006,
0.33630796014000003
]
},
{
"command": "pnpr@main",
"mean": 0.30255683204,
"stddev": 0.01935336163254721,
"median": 0.29699334114000003,
"user": 0.20934687999999996,
"system": 0.50720414,
"min": 0.28287541214000006,
"max": 0.33730195514000005,
"times": [
0.30879080314,
0.28287541214000006,
0.29602812814,
0.33730195514000005,
0.33482997914000007,
0.28439814314000006,
0.29080617214000004,
0.29795855414000005,
0.28973854414000005,
0.30284062914000004
]
}
]
}Scenario: Isolated linker: fresh resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.23570804310000004,
"stddev": 0.023209089973157612,
"median": 0.23864160970000003,
"user": 0.19137942000000002,
"system": 0.08644959999999999,
"min": 0.20328910320000002,
"max": 0.2703544412,
"times": [
0.2703544412,
0.2575107982,
0.2036968282,
0.21661045720000002,
0.23936572020000002,
0.20328910320000002,
0.22560910820000002,
0.25915365920000005,
0.24357281620000004,
0.23791749920000002
]
},
{
"command": "pacquet@main",
"mean": 0.24949721110909098,
"stddev": 0.020135974312519532,
"median": 0.24443721820000003,
"user": 0.2033938018181818,
"system": 0.08802660909090909,
"min": 0.22530400720000002,
"max": 0.29171003120000005,
"times": [
0.26452358620000005,
0.27379222420000005,
0.2524038242,
0.29171003120000005,
0.23831394620000002,
0.23768299320000003,
0.24443721820000003,
0.23951928920000004,
0.22775253120000002,
0.22530400720000002,
0.24902967120000002
]
},
{
"command": "pnpr@HEAD",
"mean": 0.09732249697777776,
"stddev": 0.004193486601002259,
"median": 0.0973877192,
"user": 0.02492510148148148,
"system": 0.014514648148148153,
"min": 0.0896384322,
"max": 0.1069723972,
"times": [
0.1013236542,
0.0976646102,
0.0972674132,
0.1069723972,
0.09931098320000001,
0.0986976982,
0.0998571142,
0.0960534792,
0.0946010162,
0.0918544352,
0.09592236520000001,
0.09820483420000001,
0.09659609520000001,
0.09575496920000001,
0.09387449120000001,
0.09043955520000001,
0.09104243420000001,
0.0973877192,
0.1022175542,
0.09986579920000001,
0.09423656420000001,
0.0896384322,
0.09473751820000001,
0.0992990002,
0.0974080412,
0.1032929652,
0.10418627920000001
]
},
{
"command": "pnpr@main",
"mean": 0.09289254012857143,
"stddev": 0.004537842609561565,
"median": 0.09331610370000001,
"user": 0.023055762857142857,
"system": 0.012261639285714287,
"min": 0.08657846820000001,
"max": 0.10625277120000001,
"times": [
0.0974149982,
0.0945115532,
0.0952680952,
0.0983896742,
0.10625277120000001,
0.0976401712,
0.09341807220000001,
0.0966371532,
0.0932141352,
0.0953044692,
0.0890400342,
0.0925233902,
0.09408337920000001,
0.0977163932,
0.08800490820000001,
0.08657846820000001,
0.0961723642,
0.0869142442,
0.08886461420000001,
0.0911837992,
0.09020774520000001,
0.09079143120000001,
0.08969252620000001,
0.08777639720000001,
0.09407681220000001,
0.0883259822,
0.0940242502,
0.0869632912
]
}
]
}Scenario: Isolated linker: peer-heavy resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.7734217936711111,
"stddev": 0.15549863225533042,
"median": 0.79376278556,
"user": 0.7079342377777776,
"system": 0.15813566,
"min": 0.55013017956,
"max": 0.99052204656,
"times": [
0.93749465456,
0.61803029856,
0.74197583356,
0.99052204656,
0.89332572056,
0.79376278556,
0.82596312256,
0.55013017956,
0.60959150156
]
},
{
"command": "pacquet@main",
"mean": 0.8188270115599999,
"stddev": 0.22185222518356287,
"median": 0.75323530056,
"user": 0.7602057933333334,
"system": 0.16102299333333334,
"min": 0.58921973956,
"max": 1.1644788955599998,
"times": [
0.67515351556,
1.1644788955599998,
0.75323530056,
0.60538765156,
0.99083103856,
0.9542852295600001,
0.59136066456,
1.0454910685599998,
0.58921973956
]
},
{
"command": "pnpm@HEAD",
"mean": 2.9053181477822227,
"stddev": 0.04802248800121166,
"median": 2.88797636756,
"user": 4.145830904444445,
"system": 0.3052351044444444,
"min": 2.87339002556,
"max": 3.02195692256,
"times": [
2.87441217556,
2.88797636756,
2.93631032556,
2.90127791756,
2.87813792156,
2.8772692595600002,
2.87339002556,
2.89713241456,
3.02195692256
]
}
]
}Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.5927868355,
"stddev": 0.16915721807176665,
"median": 4.5651184292,
"user": 1.9018699600000002,
"system": 1.40391748,
"min": 4.4240306142,
"max": 4.842317025200001,
"times": [
4.5774869632,
4.5597344692,
4.427354197200001,
4.5705023892000005,
4.468426256200001,
4.4338624082,
4.842317025200001,
4.8306983572,
4.4240306142,
4.793455675200001
]
},
{
"command": "pacquet@main",
"mean": 4.4967258529,
"stddev": 0.07669211320360513,
"median": 4.4868228297,
"user": 1.8461113599999996,
"system": 1.4616803799999998,
"min": 4.4062937492000005,
"max": 4.638091081200001,
"times": [
4.4831392892,
4.4280141432,
4.638091081200001,
4.5028030972,
4.4062937492000005,
4.4700474132000005,
4.4905063702,
4.6148615072000005,
4.4259663992,
4.5075354792
]
},
{
"command": "pnpr@HEAD",
"mean": 3.5810825091,
"stddev": 0.09262266985024249,
"median": 3.5789394157,
"user": 1.58009666,
"system": 1.4591895799999999,
"min": 3.4829225742,
"max": 3.7576176232,
"times": [
3.5528873632,
3.4832728772,
3.7576176232,
3.6376163602,
3.4898594272,
3.6756793491999997,
3.6049914682,
3.6096593852,
3.5163186632,
3.4829225742
]
},
{
"command": "pnpr@main",
"mean": 3.6408307823999997,
"stddev": 0.13322468024462636,
"median": 3.5868575191999996,
"user": 1.74816486,
"system": 1.5340825799999998,
"min": 3.5123794482,
"max": 3.8614850512,
"times": [
3.7774197332,
3.5123794482,
3.6499895812,
3.8275785812,
3.5349545922,
3.8614850512,
3.5481478442,
3.5226379542,
3.6127462832,
3.5609687552
]
}
]
} |
The candidate scan read a key's bare semver, so a version present only under a named-registry key (foo@work:1.2.0) counted as an ordinary candidate and would have been written back as a plain importer reference pointing at a key that does not exist. That semver pins a version only within its named registry, so such keys now take the same exit as peer-suffixed ones. pacquet was already safe here, since version_semver excludes registry-qualified versions by design; it gains the regression test. The Rust side also borrows the package map through disjoint field access instead of cloning every entry before the update begins.
|
Code review by qodo was updated up to the latest commit cb2b66c |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
|
| Project | pnpm's project |
| Branch | pr/13779 |
| Testbed | pnpr |
⚠️ WARNING: No Threshold found!Without a Threshold, no Alerts will ever be generated.
Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the--ci-only-thresholdsflag.
Click to view all benchmark results
| Benchmark | Latency | milliseconds (ms) |
|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot | 1,428.89 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 288.26 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 287.85 ms |
| isolated-linker.fresh-resolve.hot-cache.offline | 📈 view plot | 89.64 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 1,401.86 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr | 📈 view plot | 3,482.92 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 287.85 ms |
pnpm remove already skips resolution when the lockfile proves the outcome; its twin did not. `pnpm add <pkg>@<version>` re-resolved the whole graph even when the requested version was one the lockfile already held — promoting a transitive dependency to a direct one, or adding to a second workspace package what a first one already depends on. The rule is the one #13779 established: resolution reuses the already-locked version it would dedupe onto rather than fetching a higher one, because preferredVersions biases it toward what the graph already holds. The importers handler now records a brand-new importer edge at that version, under the group the manifest declares, alongside the whole-new-project entry #13803 added. It reuses that change's guards: a range several locked versions satisfy under `resolutionMode: time-based` or `lowest-direct` keeps the resolver, since those pick the low end and only for a run that leaves the manifest alone, and so does a plain range on a workspace project's name, which may resolve to a link instead. A lockfile carrying `time` keeps it too: `time` records a publish date per direct dependency and is only pruned on save, never extended, so a package promoted into that position would be missing the one a resolution records. `installSome` cannot edit the manifests in place the way `uninstallSome` does — the resolution path reads them to tell a new dependency from a re-added one, and reads them again to pick the range style it saves — so the edit is staged on copies, handed to the fast update and its freshness gates, and the context takes it only once the rewrite commits. The range a selector saves is computed with the resolver's own rule, extracted as `calcVersionRange` in `@pnpm/pkg-manifest.utils` alongside the `inferRangeSpecStyle` it needs. pacquet needed only the gate: `add` already pins the manifest before the install runs, so `may_fast_update_lockfile` admits `InstallSome` and `add` stops forcing `preferFrozenLockfile` off. `update` is also `InstallSome` and keeps its explicit opt-out, so it is unaffected. Its manifest pin still consults the registry packument; only the install-side resolution is skipped. The narrow cut is a plain registry specifier. A dist tag, an alias, a `workspace:`/`catalog:`/git/tarball specifier, `--save-peer`, a `catalogMode` other than `manual`, an overridden package, and a version nothing locked satisfies all keep the resolver. Closes #13798. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
pnpm remove already skips resolution when the lockfile proves the outcome; its twin did not. `pnpm add <pkg>@<version>` re-resolved the whole graph even when the requested version was one the lockfile already held — promoting a transitive dependency to a direct one, or adding to a second workspace package what a first one already depends on. The rule is the one #13779 established: resolution reuses the already-locked version it would dedupe onto rather than fetching a higher one, because preferredVersions biases it toward what the graph already holds. The importers handler now records a brand-new importer edge at that version, under the group the manifest declares, alongside the whole-new-project entry #13803 added. It reuses that change's guards: a range several locked versions satisfy under `resolutionMode: time-based` or `lowest-direct` keeps the resolver, since those pick the low end and only for a run that leaves the manifest alone, and so does a plain range on a workspace project's name, which may resolve to a link instead. A lockfile carrying `time` keeps it too: `time` records a publish date per direct dependency and is only pruned on save, never extended, so a package promoted into that position would be missing the one a resolution records. `installSome` cannot edit the manifests in place the way `uninstallSome` does — the resolution path reads them to tell a new dependency from a re-added one, and reads them again to pick the range style it saves — so the edit is staged on copies, handed to the fast update and its freshness gates, and the context takes it only once the rewrite commits. The range a selector saves is computed with the resolver's own rule, extracted as `calcVersionRange` in `@pnpm/pkg-manifest.utils` alongside the `inferRangeSpecStyle` it needs. pacquet needed only the gate: `add` already pins the manifest before the install runs, so `may_fast_update_lockfile` admits `InstallSome` and `add` stops forcing `preferFrozenLockfile` off. `update` is also `InstallSome` and keeps its explicit opt-out, so it is unaffected. Its manifest pin still consults the registry packument; only the install-side resolution is skipped. The narrow cut is a plain registry specifier. A dist tag, an alias, a `workspace:`/`catalog:`/git/tarball specifier, `--save-peer`, a `catalogMode` other than `manual`, an overridden package, and a version nothing locked satisfies all keep the resolver. Closes #13798. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
) pnpm remove already skips resolution when the lockfile proves the outcome; its twin did not. `pnpm add <pkg>@<version>` re-resolved the whole graph even when the requested version was one the lockfile already held — promoting a transitive dependency to a direct one, or adding to a second workspace package what a first one already depends on. The rule is the one #13779 established: resolution reuses the already-locked version it would dedupe onto rather than fetching a higher one, because preferredVersions biases it toward what the graph already holds. The importers handler now records a brand-new importer edge at that version, under the group the manifest declares, alongside the whole-new-project entry #13803 added. It reuses that change's guards: a range several locked versions satisfy under `resolutionMode: time-based` or `lowest-direct` keeps the resolver, since those pick the low end and only for a run that leaves the manifest alone, and so does a plain range on a workspace project's name, which may resolve to a link instead. A lockfile carrying `time` keeps it too: `time` records a publish date per direct dependency and is only pruned on save, never extended, so a package promoted into that position would be missing the one a resolution records. `installSome` cannot edit the manifests in place the way `uninstallSome` does — the resolution path reads them to tell a new dependency from a re-added one, and reads them again to pick the range style it saves — so the edit is staged on copies, handed to the fast update and its freshness gates, and the context takes it only once the rewrite commits. The range a selector saves is computed with the resolver's own rule, extracted as `calcVersionRange` in `@pnpm/pkg-manifest.utils` alongside the `inferRangeSpecStyle` it needs. pacquet needed only the gate: `add` already pins the manifest before the install runs, so `may_fast_update_lockfile` admits `InstallSome` and `add` stops forcing `preferFrozenLockfile` off. `update` is also `InstallSome` and keeps its explicit opt-out, so it is unaffected. Its manifest pin still consults the registry packument; only the install-side resolution is skipped. The narrow cut is a plain registry specifier. A dist tag, an alias, a `workspace:`/`catalog:`/git/tarball specifier, `--save-peer`, a `catalogMode` other than `manual`, an overridden package, and a version nothing locked satisfies all keep the resolver. Closes #13798.
Summary
Closes #13778. Item 4 of #13696.
Item 4 asked for a range change to reuse a version already in the lockfile instead of resolving. Establishing that the resolver actually behaves that way turned up a bug in the shipped fast path, and both turn out to be the same rule.
What resolution actually does (measured, not assumed — three probes against the real resolver):
[email protected], registry has1.3.0^1.1.01.1.0and1.2.0^1.1.0[email protected]present only as a transitive dep, importer locks100.0.0>=100.0.0100.0.0is prunedpreferredVersionsmakes the resolver dedupe onto what the graph already holds. The fast path asked a different question — "does the locked version satisfy?" — and kept it whenever it did. The third row is where that diverges: the fast path leaves the importer on100.0.0and keeps a duplicatefoothe resolver would have collapsed. That is #13778, present since the original fast-update work, not introduced here.The fix, in both stacks: pick the highest version of the alias already in the lockfile that satisfies the new range, and let the shared epilogue prune whatever the move orphans. That repairs the widening case and closes item 4 (a range only an already-present version satisfies) in one rule. Bails kept for a candidate that exists under peer-suffixed keys — choosing one would be a guess — and for anything that is not plain semver.
Tested at install level in TypeScript (all three rows, asserting zero
requestPackagecalls, plus a fall-back case where nothing present satisfies) and as unit tests in pacquet.Squash Commit Body
Checklist
already linked to it solves it.
pnpm/port, or the description notes what still needs porting.pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Written by an agent (Claude Code, claude-opus-5).
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit