Repository navigation
feat(pacquet): port the catalogMode auto-cataloging half (saveCatalogName / catalog writes) - #12202
Conversation
Implements the auto-cataloging half of pnpm's `catalogMode` (the gate was ported in #11706): under `catalogMode: strict`/`prefer` (or `--save-catalog[-name]`), `add`/`update` write `catalog:`/`catalog:<name>` to `package.json`, insert the entry into `pnpm-workspace.yaml`, and record the resolved snapshot in `pnpm-lock.yaml`'s `catalogs:`. - config: add `saveCatalogName`; move `save-catalog-name` out of the parity NOT_PORTED list - new crate `pacquet-workspace-manifest-writer`: format-preserving (comment/blank-line/key-order/quote-style) catalog write-back, byte-for-byte with pnpm, on top of yamlpatch/yamlpath/yaml_serde - lockfile: add `catalogs:` snapshot (CatalogSnapshots/ResolvedCatalogEntry) - catalog_mode: `decide_catalog` per-dep decision (gate + auto-catalog) - add: parse `pkg@version`; `--save-catalog`/`--save-catalog-name` flags - update: route the catalog gate through the decision core, handling `--latest` on catalog deps Closes #12196
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (4)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
📝 WalkthroughWalkthroughThis PR adds catalog-aware add/update behavior, introduces a format-preserving workspace manifest writer crate, adds lockfile catalog snapshot schema and generation, wires CLI/config ChangesAuto-Cataloging Feature Delivery
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI
participant AddCmd as AddCommand
participant CatalogMode
participant WorkspaceWriter
participant Install
participant LockfileBuilder
User->>CLI: run add command with save catalog name
CLI->>AddCmd: pass package and catalog options
AddCmd->>CatalogMode: decide_catalog using current spec and mode
alt catalog decision is Catalog
CatalogMode-->>AddCmd: manifest specifier and updated catalog entry
AddCmd->>WorkspaceWriter: update_workspace_manifest with updated catalogs
WorkspaceWriter-->>AddCmd: workspace manifest updated
else catalog decision is KeepDirect
CatalogMode-->>AddCmd: keep direct specifier
end
AddCmd->>Install: run install with reconciled manifest specifier
Install->>LockfileBuilder: convert graph to lockfile with catalogs
LockfileBuilder-->>Install: lockfile includes catalog snapshots
Install-->>User: command completes with manifest and lockfile updates
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Micro-Benchmark ResultsLinux |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #12202 +/- ##
==========================================
+ Coverage 87.75% 87.94% +0.19%
==========================================
Files 272 277 +5
Lines 31244 32014 +770
==========================================
+ Hits 27419 28156 +737
- Misses 3825 3858 +33 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Review Summary by QodoPort pnpm's catalogMode auto-cataloging feature with format-preserving workspace manifest writer
WalkthroughsDescription• **Auto-cataloging feature**: Ports pnpm's catalogMode auto-cataloging half (PR #12196), enabling add/update commands to write catalog: specifiers to package.json and record resolved entries in pnpm-workspace.yaml under catalogMode: strict/prefer • **New crate pacquet-workspace-manifest-writer**: Format-preserving catalog write-back to pnpm-workspace.yaml that preserves comments, blank lines, key order, and quote styles byte-for-byte with pnpm, using yamlpatch, yamlpath, and yaml_serde • **Catalog decision core**: Refactors check_catalog_mode() → decide_catalog() returning CatalogDecision enum that unifies gate (strict-error/prefer-warn) with auto-cataloging (write catalog:, record entry), supporting named catalogs and --save-catalog-name parameter • **Lockfile snapshots**: Adds top-level catalogs: field to lockfile schema with CatalogSnapshots type, positioned between settings and overrides, recording resolved specifier + version for every catalog: direct dependency • **CLI flags**: Adds --save-catalog and --save-catalog-name= flags to add command with proper precedence handling • **Config parity**: Adds save_catalog_name config field and Scalar::Undefined variant to model pnpm's undefined default • **Comprehensive test coverage**: 17 byte-for-byte format-preservation tests, decision core tests for strict/prefer/manual modes and named catalogs, 4 end-to-end integration tests ported from pnpm, plus 20+ test fixture updates across lockfile and dependency graph modules • **Update command integration**: Handles --latest on catalog: dependencies by bumping catalog entry while preserving manifest reference Diagramflowchart LR
A["add/update commands"] -->|parse pkg@version| B["decide_catalog()"]
B -->|CatalogDecision| C["write catalog: to manifest"]
C -->|CatalogEntry| D["update_workspace_manifest()"]
D -->|format-preserving| E["pnpm-workspace.yaml"]
B -->|resolved entry| F["build_catalog_snapshots()"]
F -->|CatalogSnapshots| G["lockfile catalogs: field"]
H["--save-catalog-name flag"] -->|save_catalog_name| B
File Changes1. pacquet/crates/workspace-manifest-writer/src/edit.rs
|
Integrated-Benchmark Report (Linux)Each scenario has pacquet rows (direct install) and pnpr rows (the same client through the pnpr install accelerator), so pnpr@HEAD vs pacquet@HEAD is the pnpr-vs-direct ratio. Cold-store scenarios wipe the client store between runs (warm server); hot-store scenarios keep it warm. The pacquet@HEAD rows feed the pacquet Bencher testbed; the pnpr@HEAD rows feed the pnpr testbed. Scenario: Isolated linker: fresh restore, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.7680403042199995,
"stddev": 0.052578159680087375,
"median": 4.75621358962,
"user": 2.4665458800000004,
"system": 3.64222252,
"min": 4.72390893312,
"max": 4.9089908081199995,
"times": [
4.72390893312,
4.77177438012,
4.74338607012,
4.9089908081199995,
4.7679967441199995,
4.734731755119999,
4.75319070712,
4.75923647212,
4.737883582119999,
4.77930359012
]
},
{
"command": "pacquet@main",
"mean": 4.8130351648200005,
"stddev": 0.086650383305607,
"median": 4.78625339062,
"user": 2.48478128,
"system": 3.66802372,
"min": 4.7145910101199995,
"max": 4.9695092891199995,
"times": [
4.9695092891199995,
4.78731036712,
4.78519641412,
4.8159679961199995,
4.7145910101199995,
4.77934932012,
4.7503954861199995,
4.96914954612,
4.7909855411199995,
4.76789667812
]
},
{
"command": "pnpr@HEAD",
"mean": 2.0011039576200003,
"stddev": 0.05467012199564364,
"median": 2.00208303462,
"user": 2.6431634799999997,
"system": 3.21138532,
"min": 1.9222081181200001,
"max": 2.07752071212,
"times": [
1.95232564612,
1.9686152431200001,
2.00195593712,
2.07752071212,
1.9222081181200001,
2.03867606312,
2.00221013212,
1.93899158512,
2.03883950812,
2.0696966311200002
]
},
{
"command": "pnpr@main",
"mean": 1.9998140405200004,
"stddev": 0.038639401971641826,
"median": 1.99921397012,
"user": 2.66219488,
"system": 3.20869862,
"min": 1.95183720112,
"max": 2.0592481901200004,
"times": [
1.98140993512,
1.95183720112,
1.95257451412,
2.0592481901200004,
2.0336755661200003,
2.02659872212,
2.01518588512,
1.9608264151199999,
2.0335419211200003,
1.98324205512
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.6686195677999999,
"stddev": 0.019129641047707334,
"median": 0.6664182424,
"user": 0.36586872,
"system": 1.3151213399999997,
"min": 0.6528438019,
"max": 0.7190480059000001,
"times": [
0.7190480059000001,
0.6707711579000001,
0.6715297109,
0.6667370639,
0.6582872019,
0.6705052289000001,
0.6532616659,
0.6660994209000001,
0.6571124199,
0.6528438019
]
},
{
"command": "pacquet@main",
"mean": 0.6619351950000001,
"stddev": 0.0158805585011663,
"median": 0.6563715689,
"user": 0.36776361999999996,
"system": 1.30260014,
"min": 0.6486042379,
"max": 0.6991363059,
"times": [
0.6806933159,
0.6616856389,
0.6519270279,
0.6551432959,
0.6575998419,
0.6515896359000001,
0.6991363059,
0.6599979659,
0.6486042379,
0.6529746839
]
},
{
"command": "pnpr@HEAD",
"mean": 0.6591688075,
"stddev": 0.01210588884501222,
"median": 0.6586978284,
"user": 0.35912301999999996,
"system": 1.3103610399999996,
"min": 0.6406108369,
"max": 0.6831699029,
"times": [
0.6831699029,
0.6487899719,
0.6673361189,
0.6673464049000001,
0.6473700439000001,
0.6584001469,
0.6627073359000001,
0.6569618029000001,
0.6589955099,
0.6406108369
]
},
{
"command": "pnpr@main",
"mean": 0.7362840445,
"stddev": 0.07213191660308178,
"median": 0.7315829714,
"user": 0.36759432,
"system": 1.30522714,
"min": 0.6449843709,
"max": 0.8491470669000001,
"times": [
0.8160015589,
0.7182902549,
0.7006085709000001,
0.6449843709,
0.8045268139,
0.7448756879,
0.6557776659,
0.7673449529,
0.6612835019000001,
0.8491470669000001
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.141736881120001,
"stddev": 0.023404362486616,
"median": 2.14000341772,
"user": 3.48246332,
"system": 2.92708102,
"min": 2.1027211447200003,
"max": 2.1771030807200002,
"times": [
2.1771030807200002,
2.1288799807200003,
2.12698993072,
2.14709290072,
2.12412889072,
2.15073748972,
2.17639844472,
2.15040301372,
2.1027211447200003,
2.1329139347200003
]
},
{
"command": "pacquet@main",
"mean": 2.1403875072200003,
"stddev": 0.030448887216400405,
"median": 2.1356357037200002,
"user": 3.4749988200000006,
"system": 2.9526051199999994,
"min": 2.07298526472,
"max": 2.1849355217200004,
"times": [
2.13373376572,
2.13147279372,
2.1375376417200003,
2.1849355217200004,
2.13330073872,
2.12987565272,
2.16607678072,
2.1695000227200003,
2.1444568897200003,
2.07298526472
]
},
{
"command": "pnpr@HEAD",
"mean": 2.15281814102,
"stddev": 0.027215589234277707,
"median": 2.14152409722,
"user": 3.4708352200000006,
"system": 2.9470470200000003,
"min": 2.1191422657200003,
"max": 2.1919022307200002,
"times": [
2.13201206372,
2.13684556772,
2.14620262672,
2.1191422657200003,
2.1259517957200003,
2.1799187037200003,
2.18283593272,
2.1356426867200002,
2.1777275367200004,
2.1919022307200002
]
},
{
"command": "pnpr@main",
"mean": 2.1457841192200005,
"stddev": 0.021435452627310066,
"median": 2.13897602722,
"user": 3.480977120000001,
"system": 2.95379492,
"min": 2.11895364572,
"max": 2.1877019797200004,
"times": [
2.1306028557200003,
2.14175505172,
2.14502592072,
2.1361970027200003,
2.1877019797200004,
2.13540616072,
2.1770719667200003,
2.15285300272,
2.13227360572,
2.11895364572
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.2828524669799999,
"stddev": 0.01407517751512622,
"median": 1.2819556539799999,
"user": 1.37457816,
"system": 1.7074852799999998,
"min": 1.26245342998,
"max": 1.30893089198,
"times": [
1.29282487198,
1.29607918298,
1.26514652498,
1.27483975398,
1.28426553898,
1.26245342998,
1.28544645798,
1.30893089198,
1.27889224798,
1.27964576898
]
},
{
"command": "pacquet@main",
"mean": 1.3098036067800003,
"stddev": 0.04283395742756858,
"median": 1.2981991049800001,
"user": 1.3766088599999997,
"system": 1.7233899799999999,
"min": 1.25750172198,
"max": 1.40138559998,
"times": [
1.25750172198,
1.27074478498,
1.31086291998,
1.28880876598,
1.40138559998,
1.3585619209800002,
1.2888694949800001,
1.32490264898,
1.3056006339800001,
1.2907975759800001
]
},
{
"command": "pnpr@HEAD",
"mean": 1.30311941648,
"stddev": 0.03334995493933743,
"median": 1.29286528948,
"user": 1.38246976,
"system": 1.72747368,
"min": 1.27681678898,
"max": 1.39026184898,
"times": [
1.27804431398,
1.31898723598,
1.29589881698,
1.28983176198,
1.39026184898,
1.28859126498,
1.28322129698,
1.27681678898,
1.30362097098,
1.30591986498
]
},
{
"command": "pnpr@main",
"mean": 1.2890680544800002,
"stddev": 0.018704038399288116,
"median": 1.29065977848,
"user": 1.3871077600000001,
"system": 1.7053245799999999,
"min": 1.25607568098,
"max": 1.31962738998,
"times": [
1.28246678998,
1.31962738998,
1.29676046598,
1.27113746198,
1.2926905449800001,
1.29324022098,
1.28862901198,
1.25607568098,
1.3123501099800001,
1.27770286798
]
}
]
} |
|
| Branch | pr/12202 |
| Testbed | pacquet |
🚨 1 Alert
| Benchmark | Measure Units | View | Benchmark Result (Result Δ%) | Upper Boundary (Limit %) |
|---|---|---|---|---|
| isolated-linker.fresh-restore.cold-cache.cold-store | Latency seconds (s) | 📈 plot 🚷 threshold 🚨 alert (🔔) | 4.77 s(+59.66%)Baseline: 2.99 s | 3.58 s (133.05%) |
Click to view all benchmark results
| Benchmark | Latency | Benchmark Result milliseconds (ms) (Result Δ%) | Upper Boundary milliseconds (ms) (Limit %) |
|---|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot 🚷 view threshold | 2,141.74 ms(-6.08%)Baseline: 2,280.29 ms | 2,736.35 ms (78.27%) |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot 🚷 view threshold | 1,282.85 ms(-10.11%)Baseline: 1,427.07 ms | 1,712.48 ms (74.91%) |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot 🚷 view threshold 🚨 view alert (🔔) | 4,768.04 ms(+59.66%)Baseline: 2,986.35 ms | 3,583.61 ms (133.05%) |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot 🚷 view threshold | 668.62 ms(-0.40%)Baseline: 671.33 ms | 805.59 ms (83.00%) |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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 `@pacquet/crates/cli/tests/catalog.rs`:
- Around line 163-186: In test update_latest_named_catalog_bumps_the_entry add a
lockfile assertion: after run_ok(..., ["update", "--latest", "--lockfile-only",
FOO]) read the lockfile (e.g. via read(&workspace, "pnpm-lock.yaml") or the
project’s lockfile name) and assert it no longer contains the old catalog pin
like format!("'{FOO}': 1.0.0") (mirror the existing workspace_yaml assertion
style); this ensures the lockfile snapshot in
update_latest_named_catalog_bumps_the_entry is verified alongside dep_spec(...)
and pnpm-workspace.yaml checks.
In `@pacquet/crates/package-manager/src/update.rs`:
- Around line 475-483: The current block always writes updated_catalogs to disk
(calling update_workspace_manifest) even when the CLI was invoked with
--no-save; update the condition that guards the write to also check the
save/no-save flag used by the command (e.g., require save == true or !no_save)
so that the write only occurs when saving is allowed. Concretely, modify the if
that references updated_catalogs and workspace_dir_for_catalogs to also require
the save flag, or thread the save boolean into this scope and skip calling
update_workspace_manifest(&workspace_dir, &updated_catalogs) when saving is
disabled.
In `@pacquet/crates/workspace-manifest-writer/src/edit.rs`:
- Around line 401-405: The traversal in locate() hard-codes a two-space indent
step (base_indent += 2) which breaks manifests using a different child
indentation; change locate and the loop that compares
structural_indent(all[idx].content) to compute an indent_step dynamically and
use that instead of 2. Specifically, when you find a matching segment (in the
for (depth, segment) loop and the subsequent advance at lines 423-425),
determine the child indent by scanning nearby entries (e.g., the next index in
the lo..hi range or the first entry whose structural_indent is greater than
current base_indent) to calculate indent_step = child_indent - base_indent,
validate it's >0, then set base_indent += indent_step; replace any other
hard-coded +2 advances with this computed indent_step so mapping traversal and
insert expect calls (e.g., where catalog mapping is later looked up) work for
non-2-space indents.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: c059694d-a952-4a6e-b77f-280048285d7d
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (30)
Cargo.tomlpacquet/crates/cli/src/cli_args/add.rspacquet/crates/cli/src/cli_args/dlx.rspacquet/crates/cli/tests/catalog.rspacquet/crates/config/src/lib.rspacquet/crates/config/src/pnpm_default_parity.rspacquet/crates/lockfile/src/catalog_snapshots.rspacquet/crates/lockfile/src/lib.rspacquet/crates/lockfile/src/save_lockfile/tests.rspacquet/crates/package-manager/Cargo.tomlpacquet/crates/package-manager/src/add.rspacquet/crates/package-manager/src/catalog_mode.rspacquet/crates/package-manager/src/catalog_mode/tests.rspacquet/crates/package-manager/src/current_lockfile.rspacquet/crates/package-manager/src/current_lockfile/tests.rspacquet/crates/package-manager/src/dependencies_graph_to_lockfile.rspacquet/crates/package-manager/src/dependencies_graph_to_lockfile/tests.rspacquet/crates/package-manager/src/hoisted_dep_graph/tests.rspacquet/crates/package-manager/src/install_package_from_registry/tests.rspacquet/crates/package-manager/src/install_with_fresh_lockfile.rspacquet/crates/package-manager/src/update.rspacquet/crates/real-hoist/src/tests.rspacquet/crates/resolving-deps-resolver/src/lockfile_reuse/tests.rspacquet/crates/workspace-manifest-writer/Cargo.tomlpacquet/crates/workspace-manifest-writer/src/edit.rspacquet/crates/workspace-manifest-writer/src/lib.rspacquet/crates/workspace-manifest-writer/src/model.rspacquet/crates/workspace-manifest-writer/src/render.rspacquet/crates/workspace-manifest-writer/src/tests.rspacquet/plans/TEST_PORTING.md
- update: gate the `pnpm-workspace.yaml` write on `save` so `--no-save` persists nothing to disk, matching pnpm's `if (opts.save !== false)` - workspace-manifest-writer: detect each block's child indent dynamically instead of assuming two spaces - tests: assert the lockfile `catalogs:` snapshot in the named-catalog `update --latest` e2e test; add `--no-save` and four-space-indent cases
What
Ports the auto-cataloging half of pnpm's
catalogModeto pacquet, closing #12196. PR #11706 ported the mismatch gate; this adds the write side: undercatalogMode: strict/prefer(or--save-catalog[-name]),add/updatewritecatalog:/catalog:<name>intopackage.json, insert the entry intopnpm-workspace.yaml, and record the resolved snapshot inpnpm-lock.yaml'scatalogs:.How
saveCatalogName; movesave-catalog-nameout of the parityNOT_PORTEDlist (newScalar::Undefinedfor pnpm'sundefineddefault).pacquet-workspace-manifest-writer— format-preserving catalog write-back topnpm-workspace.yaml: preserves comments, blank lines, key order, and quote styles byte-for-byte with pnpm. Ports pnpm'saddCatalogs/reorderRecursive/detectKeyLayout/propagateBlankLinesToNewPairs, layered onyamlpatch+yamlpath+yaml_serde(new deps; MIT/Apache-2.0, license-clean fordeny.toml).catalogs:snapshot (CatalogSnapshots/ResolvedCatalogEntry), positioned betweensettingsandoverridesper pnpm'ssortLockfileKeys.dependencies_graph_to_lockfileportsgetCatalogSnapshots.check_catalog_mode→decide_catalog, returning a per-depCatalogDecisionthat unifies the gate (strict-error / prefer-warn) with auto-cataloging (writecatalog:, record the entry), folding insaveCatalogName, named-catalog resolution, and re-add handling.pkg@version; new--save-catalog/--save-catalog-name=<name>flags; writes the workspace YAML before install so resolution + the lockfile snapshot see the merged catalogs.--lateston acatalog:<name>dependency (keeps the manifest reference, bumps the catalog entry).Tests
package-manager::catalog_mode::tests(strict/prefer/manual, named catalogs,--save-catalog-name, runtime skip).workspace-manifest-writer::tests— 17 byte-for-byte cases (comment/blank-line/quote-style/sorted-insert/named-catalog/scoped-key preservation).crates/cli/tests/catalog.rs), ported frominstalling/deps-installer/test/catalogs.ts:adding with catalogMode: strict/prefer will add to or use from catalogre-adding existing catalog dependency preserves catalog specifier(catalogMode: strictcreates invalidpnpm-workspace.yaml#10176)adding mismatched version with catalogMode: strict will errorupdate --latest works on named catalog dependency with catalogMode=preferTEST_PORTING.mdupdated. Fullpre-push-rust.sh(fmt/doc/dylint/taplo) + workspace clippy + typos pass; builds--locked.Notes / deferred
cleanupUnusedCatalogs(theremovePackagesFromWorkspaceCataloghalf of the writer) is not ported.update --latestof acatalog:dep is unchanged (catalog handling is gated oncatalogMode != manual, matching pre-existing pacquet behavior); the strict/prefer paths match pnpm.Per pacquet convention, this pacquet-only change does not include a changeset.
Written by an agent (Claude Code, claude-opus-4-8).
Summary by CodeRabbit
New Features
--save-catalogand--save-catalog-nametopacquet addupdate --latesthonors catalog stateTests
Documentation