Skip to content

fix(manifest): preserve package.yaml comments and key order - #15148

Merged
zkochan merged 3 commits into
mainfrom
fix-2008
Sep 20, 2026
Merged

zkochan merged 3 commits into
mainfrom
fix-2008

Conversation

@zkochan

@zkochan zkochan commented Sep 19, 2026 •

Copy link
Copy Markdown
Member

Summary

Preserve comments and existing key order when commands update package.yaml. Existing keys stay in place and new keys are appended to their mapping. Closes #2008.

The workspace YAML writer already preserves comments and ordering, and JSON5 already preserves comments. This fixes the remaining package YAML writer in pnpm v11. The Rust CLI reads package.yaml but does not write it, so it does not contain this bug.

Squash Commit Body

Patch the existing package.yaml document using the shared YAML document
synchronizer and write it atomically. Preserve existing key order and scalar
aliases, and reject malformed YAML without overwriting it.

Allow the synchronizer to retain null values and empty maps for package
metadata while keeping its configuration-pruning defaults. Match scalar YAML
keys to their JSON property names so custom metadata keeps numeric and
boolean keys. Keep reader-specific null-key conversion explicit and retain
comments when replacing scalar metadata such as timestamps and binary values. Reconcile shorter
sequences and replaced collection aliases without retaining stale values.

Validate through both project-manifest reader entry points, direct writer
regressions, synchronizer tests, and the existing workspace writer suite.
The new writer regression tests fail against the original implementation.

Closes pnpm/pnpm#2008.

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • New features are implemented only in the Rust pnpm v12 CLI. Bug fixes
    are implemented in every affected version.
  • 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.

Validation: 191 tests pass across the document synchronizer, project manifest reader and writer, and workspace manifest writer. Package compilation/lint and repository metadata validation pass.


Written by an agent (Codex, GPT-6).

Summary by CodeRabbit

  • New Features

    • pnpm now preserves comments and existing key order in package.yaml files when updating manifests.
    • Newly added keys are appended without disrupting the existing structure.
    • Empty values, aliases, metadata, and legacy YAML formatting are retained where applicable.
    • Invalid YAML is detected without overwriting the existing manifest.
  • Documentation

    • Added guidance for manifest preservation, key ordering, value retention, key appending, and cleanup behavior.

@coderabbitai

coderabbitai Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: pnpm/pnpm/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: c0c7d780-e7fe-40a9-b66e-0cfc67b11bf8

📥 Commits

Reviewing files that changed from the base of the PR and between 616b043 and 8f92912.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (9)
  • .changeset/preserve-package-yaml.md
  • pnpm11/workspace/project-manifest-reader/test/index.ts
  • pnpm11/workspace/project-manifest-writer/package.json
  • pnpm11/workspace/project-manifest-writer/src/index.ts
  • pnpm11/workspace/project-manifest-writer/test/index.ts
  • pnpm11/workspace/project-manifest-writer/tsconfig.json
  • pnpm11/yaml/document-sync/README.md
  • pnpm11/yaml/document-sync/src/patchDocument.ts
  • pnpm11/yaml/document-sync/test/patchDocument.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The change updates YAML manifest writing to patch existing documents instead of serializing them from scratch. It preserves comments, key order, aliases, nulls, and empty collections, reports parse errors, and adds regression coverage.

Changes

Package YAML preservation

Layer / File(s) Summary
YAML document patching contract
pnpm11/yaml/document-sync/src/patchDocument.ts, pnpm11/yaml/document-sync/test/patchDocument.test.ts, pnpm11/yaml/document-sync/README.md
The patcher supports key-order preservation, custom scalar-key conversion, and optional retention of null and empty values. Tests cover aliases, sequences, scalar keys, comments, and recursive updates.
Manifest writer integration
pnpm11/workspace/project-manifest-writer/src/index.ts, pnpm11/workspace/project-manifest-writer/package.json, pnpm11/workspace/project-manifest-writer/tsconfig.json, pnpm11/workspace/project-manifest-writer/test/index.ts, .changeset/preserve-package-yaml.md
The writer reads and patches existing YAML, reports parse errors as ERR_PNPM_YAML_PARSE, creates missing directories, and writes atomically. Tests cover preservation, invalid YAML, and new directories.
Reader and rewrite validation
pnpm11/workspace/project-manifest-reader/test/index.ts
Reader tests cover directory and exact-file manifest updates while preserving comments, dependency order, and metadata comments.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Low

Sequence Diagram(s)

sequenceDiagram
  participant ProjectManifestWriter
  participant Filesystem
  participant YAMLDocument
  ProjectManifestWriter->>Filesystem: read package.yaml
  Filesystem-->>ProjectManifestWriter: YAML source or missing-file error
  ProjectManifestWriter->>YAMLDocument: parse and patch manifest
  YAMLDocument-->>ProjectManifestWriter: preserved YAML document
  ProjectManifestWriter->>Filesystem: atomically write package.yaml
Loading

Assessment Against Linked Issues

Objective Addressed Explanation
Preserve comments and existing key order in package.yaml during manifest updates [#2008] ✅
Append new mapping keys while updating dependencies and other manifest fields [#2008] ✅
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

pnpm11/workspace/project-manifest-reader/test/index.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

pnpm11/workspace/project-manifest-writer/package.json

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

pnpm11/workspace/project-manifest-writer/src/index.ts

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

  • 3 others

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.

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: 8f92912697a4

Regular scenarios report direct and pnpr installs. The peer-heavy resolver scenario compares current Rust, main Rust, and TypeScript pnpm; the linked-workspace scenario compares current Rust against main Rust. 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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.369 ± 0.190 2.229 2.770 1.67 ± 0.20
pacquet@main 2.374 ± 0.147 2.211 2.586 1.68 ± 0.18
pnpr@HEAD 1.414 ± 0.124 1.294 1.604 1.00
pnpr@main 1.482 ± 0.148 1.311 1.667 1.05 ± 0.14
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.36869001962,
      "stddev": 0.18983130893459155,
      "median": 2.25504860972,
      "user": 1.1935287999999997,
      "system": 1.44021772,
      "min": 2.22946694422,
      "max": 2.76980878522
    },
    {
      "command": "pacquet@main",
      "mean": 2.37444435142,
      "stddev": 0.14701911313370547,
      "median": 2.31005557772,
      "user": 1.1541917000000002,
      "system": 1.32017092,
      "min": 2.21140639322,
      "max": 2.58612598522
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.41439272452,
      "stddev": 0.12394378008828173,
      "median": 1.35507157622,
      "user": 1.0608556,
      "system": 1.22041432,
      "min": 1.2940508862200002,
      "max": 1.6036778202200002
    },
    {
      "command": "pnpr@main",
      "mean": 1.48219426642,
      "stddev": 0.14771507387720154,
      "median": 1.4724579557200002,
      "user": 1.0734762000000002,
      "system": 1.2281190199999998,
      "min": 1.3112740762200001,
      "max": 1.6667435752200002
    }
  ]
}

Scenario: Isolated linker: fresh restore, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 202.4 ± 5.8 194.2 211.7 1.00 ± 0.06
pacquet@main 202.3 ± 11.5 184.7 220.1 1.00
pnpr@HEAD 229.1 ± 6.3 220.9 238.9 1.13 ± 0.07
pnpr@main 244.1 ± 53.4 198.8 339.6 1.21 ± 0.27
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.20241858862,
      "stddev": 0.005778092560231348,
      "median": 0.20230725232000002,
      "user": 0.22271663999999997,
      "system": 0.50156022,
      "min": 0.19415247582,
      "max": 0.21167758082000002
    },
    {
      "command": "pacquet@main",
      "mean": 0.20233182452000004,
      "stddev": 0.01149702769172483,
      "median": 0.20442934982,
      "user": 0.20543543999999997,
      "system": 0.51021202,
      "min": 0.18468458882,
      "max": 0.22008783282
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.22905743142,
      "stddev": 0.00632775418426991,
      "median": 0.22963425182000002,
      "user": 0.22229804,
      "system": 0.5259156199999999,
      "min": 0.22088477882000002,
      "max": 0.23893045182
    },
    {
      "command": "pnpr@main",
      "mean": 0.24414571782000002,
      "stddev": 0.053414067669716785,
      "median": 0.22111437682,
      "user": 0.2607892399999999,
      "system": 0.54776462,
      "min": 0.19878439682000001,
      "max": 0.33960949682
    }
  ]
}

Scenario: Isolated linker: repeat install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 6.8 ± 0.5 5.7 9.0 1.08 ± 0.11
pacquet@main 6.9 ± 0.5 6.0 10.1 1.10 ± 0.10
pnpr@HEAD 6.8 ± 0.6 5.7 10.5 1.08 ± 0.12
pnpr@main 6.3 ± 0.4 5.5 7.8 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.006770801961333337,
      "stddev": 0.0005198379121281596,
      "median": 0.006691171940000001,
      "user": 0.004395038666666668,
      "system": 0.0027936038400000014,
      "min": 0.00571596494,
      "max": 0.00900841894
    },
    {
      "command": "pacquet@main",
      "mean": 0.006909314626015835,
      "stddev": 0.00047576907888126027,
      "median": 0.00685699394,
      "user": 0.004541125963060688,
      "system": 0.002833058258575199,
      "min": 0.00602105994,
      "max": 0.01009499594
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.006811331354168932,
      "stddev": 0.0005958813017129346,
      "median": 0.0067586389400000006,
      "user": 0.004262743923705721,
      "system": 0.0029809932425068123,
      "min": 0.0056520949400000004,
      "max": 0.010523434940000001
    },
    {
      "command": "pnpr@main",
      "mean": 0.006284961115438601,
      "stddev": 0.00040894350751829545,
      "median": 0.00624226694,
      "user": 0.0040907918295739355,
      "system": 0.0025699695238095245,
      "min": 0.005497392940000001,
      "max": 0.00777075594
    }
  ]
}

Scenario: Isolated linker: repeat install, cold cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 7.3 ± 0.7 6.0 10.0 1.00
pacquet@main 7.7 ± 0.3 6.7 9.2 1.05 ± 0.11
pnpr@HEAD 7.6 ± 0.4 6.8 10.3 1.05 ± 0.11
pnpr@main 7.7 ± 0.4 6.8 9.1 1.06 ± 0.11
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.007295028713890675,
      "stddev": 0.0006946764093173708,
      "median": 0.007208566820000001,
      "user": 0.004367640900321545,
      "system": 0.0033779566559485504,
      "min": 0.006001330820000001,
      "max": 0.00997356582
    },
    {
      "command": "pacquet@main",
      "mean": 0.007656991667682116,
      "stddev": 0.00033362166537598,
      "median": 0.007648632320000001,
      "user": 0.004707341854304635,
      "system": 0.0034054909933774824,
      "min": 0.0066561808200000004,
      "max": 0.00915013082
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.007642122775555561,
      "stddev": 0.0003990717644713038,
      "median": 0.007615831820000001,
      "user": 0.004797980317460313,
      "system": 0.00329583949206349,
      "min": 0.00676721882,
      "max": 0.01025312982
    },
    {
      "command": "pnpr@main",
      "mean": 0.00773689801471947,
      "stddev": 0.00039115223666574394,
      "median": 0.007691874820000001,
      "user": 0.004859994587458746,
      "system": 0.0033389236963696396,
      "min": 0.006773189820000001,
      "max": 0.00914806582
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.507 ± 0.048 2.471 2.624 1.67 ± 0.15
pacquet@main 2.512 ± 0.062 2.444 2.658 1.68 ± 0.15
pnpr@HEAD 1.497 ± 0.131 1.360 1.770 1.00
pnpr@main 1.538 ± 0.147 1.362 1.769 1.03 ± 0.13
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.50688655684,
      "stddev": 0.04849439796095294,
      "median": 2.48569062604,
      "user": 1.8665023600000001,
      "system": 1.61326872,
      "min": 2.4705221915399997,
      "max": 2.62355258654
    },
    {
      "command": "pacquet@main",
      "mean": 2.51186996184,
      "stddev": 0.0621258538818043,
      "median": 2.48848555404,
      "user": 1.8216680599999997,
      "system": 1.63382942,
      "min": 2.44442127754,
      "max": 2.65788024254
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.4967675047400002,
      "stddev": 0.1308782433748418,
      "median": 1.4576862025400001,
      "user": 1.01902756,
      "system": 1.25641552,
      "min": 1.35951172254,
      "max": 1.77043741654
    },
    {
      "command": "pnpr@main",
      "mean": 1.53788029894,
      "stddev": 0.1470822897654109,
      "median": 1.4870592475400002,
      "user": 1.07543406,
      "system": 1.29546492,
      "min": 1.36232069854,
      "max": 1.7691082605400001
    }
  ]
}

Scenario: Isolated linker: fresh install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 344.1 ± 10.9 326.5 358.1 1.29 ± 0.05
pacquet@main 440.2 ± 91.5 337.6 542.4 1.65 ± 0.35
pnpr@HEAD 272.2 ± 7.1 260.9 283.6 1.02 ± 0.04
pnpr@main 266.7 ± 6.1 256.5 278.9 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.34411359354000004,
      "stddev": 0.010871678411893747,
      "median": 0.34767532274,
      "user": 0.5377269,
      "system": 0.7932444799999999,
      "min": 0.32653425224,
      "max": 0.35812149424
    },
    {
      "command": "pacquet@main",
      "mean": 0.44021397883999996,
      "stddev": 0.09146269671315817,
      "median": 0.43497251774,
      "user": 0.7020040999999999,
      "system": 0.9789711799999999,
      "min": 0.33756338824,
      "max": 0.54241422024
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.27217601044,
      "stddev": 0.0070995064290767535,
      "median": 0.27416757424000004,
      "user": 0.2167189,
      "system": 0.5259965799999999,
      "min": 0.26088601524,
      "max": 0.28360902324
    },
    {
      "command": "pnpr@main",
      "mean": 0.26666603894,
      "stddev": 0.006133082714928078,
      "median": 0.26560338874,
      "user": 0.20159,
      "system": 0.52988098,
      "min": 0.25653456724,
      "max": 0.27887332624
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + hot store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.638 ± 0.101 1.549 1.814 5.68 ± 0.38
pacquet@main 1.575 ± 0.011 1.563 1.600 5.46 ± 0.15
pnpr@HEAD 0.289 ± 0.008 0.277 0.302 1.00
pnpr@main 0.297 ± 0.008 0.280 0.307 1.03 ± 0.04
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.6384782190200002,
      "stddev": 0.10103782197202699,
      "median": 1.5930473859199998,
      "user": 0.99702448,
      "system": 1.1593236999999998,
      "min": 1.54882929392,
      "max": 1.81359401892
    },
    {
      "command": "pacquet@main",
      "mean": 1.57485341282,
      "stddev": 0.011366735023192456,
      "median": 1.5733071779199999,
      "user": 0.8183077799999999,
      "system": 1.0935064,
      "min": 1.56283506692,
      "max": 1.59989814492
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.28850343172000004,
      "stddev": 0.007712712465890957,
      "median": 0.28802321492000005,
      "user": 0.24460498,
      "system": 0.5593308,
      "min": 0.27702122692000003,
      "max": 0.30248548292000005
    },
    {
      "command": "pnpr@main",
      "mean": 0.29697855912,
      "stddev": 0.008035554217126624,
      "median": 0.29736123942000003,
      "user": 0.24989277999999998,
      "system": 0.5951793000000001,
      "min": 0.27962603792,
      "max": 0.30666192792
    }
  ]
}

Scenario: Isolated linker: fresh resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 202.7 ± 12.4 178.3 229.1 2.29 ± 0.15
pacquet@main 195.7 ± 17.7 175.3 227.4 2.21 ± 0.20
pnpr@HEAD 88.6 ± 1.9 86.2 92.9 1.00
pnpr@main 89.7 ± 2.3 85.2 95.0 1.01 ± 0.03
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.20270055585076924,
      "stddev": 0.012428264418264029,
      "median": 0.20286019262000002,
      "user": 0.20016929384615384,
      "system": 0.06493051538461539,
      "min": 0.17825714062000003,
      "max": 0.22909090762000003
    },
    {
      "command": "pacquet@main",
      "mean": 0.19566449176285716,
      "stddev": 0.017670109132623648,
      "median": 0.19156153662000003,
      "user": 0.1896453542857143,
      "system": 0.06700947142857143,
      "min": 0.17528762162000003,
      "max": 0.22741012562000001
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.08863484318250002,
      "stddev": 0.001915657983577578,
      "median": 0.08828680712,
      "user": 0.02915879624999999,
      "system": 0.016041153124999995,
      "min": 0.08622644762000001,
      "max": 0.09288287162
    },
    {
      "command": "pnpr@main",
      "mean": 0.08970672787806451,
      "stddev": 0.002308456273112459,
      "median": 0.08962164462,
      "user": 0.03334584967741934,
      "system": 0.01213932258064516,
      "min": 0.08515394562,
      "max": 0.09501277562
    }
  ]
}

Scenario: Isolated linker: peer-heavy resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 663.5 ± 62.8 570.2 730.0 1.03 ± 0.14
pacquet@main 641.5 ± 59.0 565.3 739.6 1.00
pnpm@HEAD 3068.3 ± 102.1 2914.2 3207.7 4.78 ± 0.47
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.6635216444622222,
      "stddev": 0.06279312335526703,
      "median": 0.6845582482400001,
      "user": 0.6776358644444443,
      "system": 0.13444761777777778,
      "min": 0.5702120232400001,
      "max": 0.73002295124
    },
    {
      "command": "pacquet@main",
      "mean": 0.641510641017778,
      "stddev": 0.05902413865057817,
      "median": 0.6384769092400001,
      "user": 0.65813742,
      "system": 0.14656717333333333,
      "min": 0.5653062482400001,
      "max": 0.7396076572400001
    },
    {
      "command": "pnpm@HEAD",
      "mean": 3.068282827351111,
      "stddev": 0.10208385668545127,
      "median": 3.05710869924,
      "user": 4.844855864444444,
      "system": 0.21851650666666664,
      "min": 2.9142274682400005,
      "max": 3.2076696892400003
    }
  ]
}

Scenario: Isolated linker: linked-workspace resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 164.7 ± 2.6 161.9 170.3 1.00 ± 0.02
pacquet@main 164.4 ± 2.6 160.1 169.2 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.16465647618444443,
      "stddev": 0.002622318345479618,
      "median": 0.16419561224,
      "user": 0.12099098888888887,
      "system": 0.08172850000000002,
      "min": 0.16189096274,
      "max": 0.17029340973999998
    },
    {
      "command": "pacquet@main",
      "mean": 0.16444999662235296,
      "stddev": 0.002586029983730155,
      "median": 0.16481406574,
      "user": 0.12866830588235295,
      "system": 0.07230052941176472,
      "min": 0.16007212074,
      "max": 0.16916633174
    }
  ]
}

Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.350 ± 0.081 4.266 4.477 1.28 ± 0.05
pacquet@main 4.328 ± 0.090 4.252 4.546 1.27 ± 0.05
pnpr@HEAD 3.398 ± 0.103 3.336 3.660 1.00
pnpr@main 3.413 ± 0.072 3.350 3.542 1.00 ± 0.04
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.349856300240001,
      "stddev": 0.08087643386711221,
      "median": 4.32532096094,
      "user": 1.3578508999999999,
      "system": 1.54739998,
      "min": 4.2663639274400005,
      "max": 4.4768779824400005
    },
    {
      "command": "pacquet@main",
      "mean": 4.32796915984,
      "stddev": 0.08992596908683341,
      "median": 4.2885464324400004,
      "user": 1.2791587,
      "system": 1.42100598,
      "min": 4.2519258434400005,
      "max": 4.545693052440001
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.3984518176399994,
      "stddev": 0.10305656506034204,
      "median": 3.3614051924399995,
      "user": 1.2516816999999998,
      "system": 1.3101940799999998,
      "min": 3.33588188844,
      "max": 3.66020650244
    },
    {
      "command": "pnpr@main",
      "mean": 3.4128684396399995,
      "stddev": 0.07199247185777188,
      "median": 3.38834802844,
      "user": 1.2778076,
      "system": 1.41111248,
      "min": 3.34990509844,
      "max": 3.54174544144
    }
  ]
}

Scenario: GVS linker: fresh restore, hot cache + hot store

Same install as the isolated fresh-restore hot/hot scenario, into the shared virtual store, the layout pnpm 12 installs into by default. Scenarios run on separate machines, so compare main and branch within each table.

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 122.0 ± 6.6 113.8 140.1 1.03 ± 0.10
pacquet@main 117.9 ± 9.4 107.4 138.6 1.00
pnpr@HEAD 127.1 ± 4.6 119.4 136.7 1.08 ± 0.09
pnpr@main 125.8 ± 5.3 118.1 136.5 1.07 ± 0.10
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.12195874518545455,
      "stddev": 0.006596150318277158,
      "median": 0.11971963314,
      "user": 0.1554903690909091,
      "system": 0.14618057272727272,
      "min": 0.11378638364,
      "max": 0.14011957264
    },
    {
      "command": "pacquet@main",
      "mean": 0.11790029918545457,
      "stddev": 0.009401752042506215,
      "median": 0.11563691264,
      "user": 0.14220473272727274,
      "system": 0.13948102727272726,
      "min": 0.10741635564,
      "max": 0.13857652764
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.12707700116380952,
      "stddev": 0.004646848192839891,
      "median": 0.12629461064,
      "user": 0.14789834095238097,
      "system": 0.13645120476190475,
      "min": 0.11943941464,
      "max": 0.13673202464
    },
    {
      "command": "pnpr@main",
      "mean": 0.12582600469,
      "stddev": 0.005292985188729804,
      "median": 0.12516072964,
      "user": 0.14390556000000002,
      "system": 0.1383719,
      "min": 0.11810068864,
      "max": 0.13646706564
    }
  ]
}

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/15148
Testbedpacquet
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
gvs-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
113.79 ms
(+12.64%)Baseline: 101.02 ms
121.22 ms
(93.87%)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
🚷 view threshold
2,470.52 ms
(+1.75%)Baseline: 2,428.04 ms
2,913.65 ms
(84.79%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
1,548.83 ms
(+1.08%)Baseline: 1,532.25 ms
1,838.70 ms
(84.24%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
326.53 ms
(-2.65%)Baseline: 335.44 ms
402.53 ms
(81.12%)
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
178.26 ms
(-1.70%)Baseline: 181.34 ms
217.61 ms
(81.92%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
2,229.47 ms
(-0.30%)Baseline: 2,236.07 ms
2,683.28 ms
(83.09%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
4,266.36 ms
(-0.52%)Baseline: 4,288.78 ms
5,146.54 ms
(82.90%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
194.15 ms
(-2.18%)Baseline: 198.48 ms
238.17 ms
(81.52%)
isolated-linker.linked-workspace-resolve.hot-cache.offline📈 view plot
🚷 view threshold
161.89 ms
(-3.14%)Baseline: 167.14 ms
200.57 ms
(80.72%)
isolated-linker.peer-heavy-resolve.hot-cache.offline📈 view plot
🚷 view threshold
570.21 ms
(+9.46%)Baseline: 520.95 ms
625.14 ms
(91.21%)
isolated-linker.repeat-install.cold-cache.hot-store📈 view plot
🚷 view threshold
6.00 ms
(-1.05%)Baseline: 6.06 ms
7.28 ms
(82.46%)
isolated-linker.repeat-install.hot-cache.hot-store📈 view plot
🚷 view threshold
5.72 ms
(-6.19%)Baseline: 6.09 ms
7.31 ms
(78.18%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/15148
Testbedpnpr

⚠️ 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-thresholds flag.

Click to view all benchmark results
BenchmarkLatencymilliseconds (ms)
gvs-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
119.44 ms
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,359.51 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
277.02 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
260.89 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
86.23 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,294.05 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
3,335.88 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
220.88 ms
isolated-linker.repeat-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
6.77 ms
isolated-linker.repeat-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
5.65 ms
🐰 View full continuous benchmarking report in Bencher

@zkochan

zkochan commented Sep 19, 2026 •

Copy link
Copy Markdown
Member Author

Investigated the initial Bencher alert for isolated-linker.repeat-install.cold-cache.hot-store. The compared base (616b043f5f) and this PR have identical Rust sources, Cargo dependencies, and toolchain configuration.

The first run measured 12.4 ± 2.0 ms for the PR and 8.8 ± 2.3 ms for the base. Rerunning that scenario without code changes measured 6.8 ± 0.6 ms and 6.5 ± 0.3 ms respectively. The replacement Bencher report passes. This supports timing variance as the cause of the initial alert.

On 5f01786792, the GVS restore scenario also triggered the historical-baseline threshold. Its same-run means were 133.5 ms for the PR and 134.0 ms for main, so the PR did not regress that comparison. A targeted rerun measured 118.5 ms and 116.8 ms respectively and the replacement Bencher report passed.

For 8f92912697, three different historical-baseline alerts appeared. Targeted reruns without code changes cleared all three: fresh-install minimum 436.3 → 326.5 ms, resolver minimum 239.3 → 178.3 ms, and repeat-install minimum 10.4 → 5.7 ms (the repeat case needed a second rerun). In the final repeat run the means were 6.8 ms for the PR and 6.9 ms for main. Main remains 616b043f5f, and the Rust sources, Cargo dependencies, toolchain, and benchmark fixtures are identical across the comparison. The final Bencher report passes.


Written by an agent (Codex, GPT-6).

@zkochan
zkochan marked this pull request as ready for review September 20, 2026 00:22
@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Preserve package.yaml comments and key order

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Preserve package.yaml comments, aliases, and existing key order during manifest updates.
• Append new keys while retaining nulls, empty collections, and scalar metadata keys.
• Reject malformed YAML and atomically write validated document patches.
Diagram

sequenceDiagram
  actor Cmd as Manifest command
  participant Reader as Manifest reader
  participant Writer as YAML writer
  participant Parser as YAML parser
  participant Sync as Document sync
  participant File as package.yaml
  Cmd->>Reader: Load manifest
  Reader->>File: Read YAML
  File-->>Reader: Manifest data
  Cmd->>Reader: Save changes
  Reader->>Writer: Write manifest
  Writer->>File: Read source text
  Writer->>Parser: Parse document
  alt Invalid YAML
    Parser-->>Writer: Parse errors
    Writer-->>Cmd: Reject update
  else Valid YAML
    Parser-->>Writer: YAML document
    Writer->>Sync: Patch preserving metadata
    Sync-->>Writer: Patched document
    Writer->>File: Atomic replacement
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Writer-specific YAML patching
  • ➕ Could tailor behavior exclusively to package manifests.
  • ➕ Would avoid expanding the shared synchronizer API.
  • ➖ Duplicates AST reconciliation logic already used by workspace YAML.
  • ➖ Increases maintenance risk for aliases, comments, sequences, and scalar keys.
  • ➖ Could diverge from workspace manifest behavior.
2. Parse and fully reserialize YAML
  • ➕ Simpler implementation with fewer AST edge cases.
  • ➕ Produces deterministic output from manifest data.
  • ➖ Loses comments, formatting choices, aliases, and existing key order.
  • ➖ Directly conflicts with the issue requirements.

Recommendation: Use the shared document synchronizer as implemented. Extending it with opt-in preservation and pruning controls keeps configuration defaults unchanged, aligns package and workspace YAML behavior, and centralizes difficult AST reconciliation logic.

Files changed (10) +231 / -28

Bug fix (2) +51 / -24
index.tsPatch existing package YAML documents atomically +25/-7

Patch existing package YAML documents atomically

• Reads and parses existing 'package.yaml' content, rejects malformed YAML, and applies manifest changes through the shared document synchronizer. Preserves key order and scalar aliases, retains empty metadata values, and writes the result atomically.

pnpm11/workspace/project-manifest-writer/src/index.ts

patchDocument.tsExtend YAML synchronization for manifest preservation +26/-17

Extend YAML synchronization for manifest preservation

• Adds opt-in existing-key ordering and empty-value retention while preserving configuration-oriented defaults. Correctly matches scalar mapping keys, retains nullable sequence values, removes stale trailing items, and replaces changed collection aliases.

pnpm11/yaml/document-sync/src/patchDocument.ts

Tests (3) +144 / -1
index.tsVerify preservation through both manifest reader APIs +23/-1

Verify preservation through both manifest reader APIs

• Exercises directory-based and exact-file manifest readers when updating YAML dependencies. Confirms comments and dependency order survive updates, additions, and removals.

pnpm11/workspace/project-manifest-reader/test/index.ts

index.tsCover package YAML preservation and failure behavior +84/-0

Cover package YAML preservation and failure behavior

• Adds regressions for comments, key order, removals, aliases, scalar keys, nulls, and empty collections. Also verifies malformed YAML remains untouched and missing directories are created.

pnpm11/workspace/project-manifest-writer/test/index.ts

patchDocument.test.tsTest manifest synchronization edge cases +37/-0

Test manifest synchronization edge cases

• Covers recursive key-order preservation, disabled pruning, shortened complex sequences, replaced collection aliases, and numeric, boolean, or null mapping keys. Confirms source formatting and comments remain attached where expected.

pnpm11/yaml/document-sync/test/patchDocument.test.ts

Documentation (2) +19 / -0
preserve-package-yaml.mdAdd patch release notes for package YAML preservation +7/-0

Add patch release notes for package YAML preservation

• Declares patch releases for pnpm, the project manifest writer, and the YAML document synchronizer. Documents preserved comments, existing key order, and append-only placement for new keys.

.changeset/preserve-package-yaml.md

README.mdDocument manifest-oriented synchronization options +12/-0

Document manifest-oriented synchronization options

• Explains how package manifests can preserve existing key order and scalar aliases while retaining null values and empty maps. Clarifies default ordering and pruning behavior.

pnpm11/yaml/document-sync/README.md

Other (3) +17 / -3
pnpm-lock.yamlUpdate manifest writer dependency resolution +8/-2

Update manifest writer dependency resolution

• Adds the shared pnpm error and YAML document synchronization packages to the writer importer. Replaces 'write-yaml-file' with the 'yaml' parser dependency.

pnpm-lock.yaml

package.jsonAdopt document synchronization dependencies +3/-1

Adopt document synchronization dependencies

• Adds pnpm error handling and the shared YAML document synchronizer. Replaces the full-file YAML serializer with the AST-capable 'yaml' package.

pnpm11/workspace/project-manifest-writer/package.json

tsconfig.jsonReference new writer workspace dependencies +6/-0

Reference new writer workspace dependencies

• Adds TypeScript project references for the pnpm error and YAML document synchronization packages.

pnpm11/workspace/project-manifest-writer/tsconfig.json

@greptile-apps

greptile-apps Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; no actionable new defect or outstanding prior finding remains.

Reviews (2) · Last reviewed commit: "fix(yaml): preserve legacy manifest scal..."

@qodo-code-review

qodo-code-review Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Informational

1. Release readers cannot identify the tool ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
Preserve comments and existing key order... uses an imperative with an implied subject instead of
naming pnpm as the actor. Because this is the release note for three packages, readers must infer
which tool performs the manifest update from repository context.
Code

.changeset/preserve-package-yaml.md[7]

+Preserve comments and existing key order when updating `package.yaml`. New keys are appended to their mapping [pnpm/pnpm#2008](https://github.com/pnpm/pnpm/issues/2008).
Relevance

● Weak

A closely matching explicit-subject changeset finding was rejected; subjectless release-note
openings are tolerated.

PR-#14700

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Compliance rule 3058332 requires an explicit subject when the actor matters. The added changeset
describes the behavior with the subjectless imperative Preserve, even though naming pnpm is
necessary to identify the acting tool.

Rule 3058332: Use plain, direct, and quantifiable language in changeset entries
.changeset/preserve-package-yaml.md[7-7]

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 uses an imperative sentence with an implied subject, so it does not explicitly identify the tool responsible for the observable behavior.

## Fix Focus Areas
- .changeset/preserve-package-yaml.md[7-7]

## Recommended Fix
Rewrite the entry in active voice with `pnpm` as the explicit subject, for example: `pnpm now preserves comments and existing key order when updating package.yaml.` Keep the new-key behavior as the separate second sentence.

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


Grey Divider

Context sources
✅ Compliance rules (platform): 53 rules
✅ Skills: review-code
✅ Cross-repo context — repo relationships
  Explored: repo: pnpm/update (sha: fcaa952e)
Review mode: ⚖️ Balanced: This localized runtime change alters shared YAML synchronization and package manifest writing semantics, with real compatibility and data-preservation risk, but not enough independent logic to justify extended review.

Grey Divider

Tip of the day
💡 Did you know, you can turn on the rule miner and Qodo learns your standards from review history

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@zkochan

zkochan commented Sep 20, 2026

Copy link
Copy Markdown
Member Author

Addressed Qodo's release-note wording suggestion in 8f92912: the entry now starts with “pnpm now preserves comments and existing key order”.


Written by an agent (Codex, GPT-6).

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 8f92912

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@zkochan

zkochan commented Sep 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

Please review the current head, 8f92912. The in-progress summary still names 5f01786.


Written by an agent (Codex, GPT-6).

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Sep 20, 2026
@coderabbitai

coderabbitai Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

@zkochan I will review the current head, 8f92912697a47bc476e3eeb3185ebb8b9e4816b2. I will use this commit as the review target. The in-progress summary reference to 5f01786792 is stale.

⚠️ Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@zkochan
zkochan merged commit 23458f8 into main Sep 20, 2026
124 checks passed
@zkochan
zkochan deleted the fix-2008 branch September 20, 2026 09:05
zkochan added a commit that referenced this pull request Sep 20, 2026
Read and save package.yaml through PackageManifest, preserving comments and
existing mapping order while retaining the atomic-write and no-op-save paths.
Use manifest discovery for pkg, version, set-script, and link.

Extract the workspace writer's scalar alias support into a shared YAML utility.
Batch edits by YAML path and detach collection aliases when either side changes.
Reject invalid roots and colliding keys. Validate the edited document against
the requested value before replacing it. Publish new manifests atomically while
retaining normal creation permissions and existing-file permissions.

Keep the Rust test runner's isolated npmrc in commands spawned by test helpers,
preventing developer registry settings from leaking into fixture installs.

Follow-up to #15148. Related to #2008.
u9g pushed a commit to u9g/pnpm that referenced this pull request Sep 25, 2026
Patch the existing package.yaml document using the shared YAML document
synchronizer and write it atomically. Preserve existing key order and scalar
aliases, and reject malformed YAML without overwriting it.

Allow the synchronizer to retain null values and empty maps for package
metadata while keeping its configuration-pruning defaults. Match scalar YAML
keys to their JSON property names so custom metadata keeps numeric and
boolean keys. Keep reader-specific null-key conversion explicit and retain
comments when replacing scalar metadata such as timestamps and binary values. Reconcile shorter
sequences and replaced collection aliases without retaining stale values.

Validate through both project-manifest reader entry points, direct writer
regressions, synchronizer tests, and the existing workspace writer suite.
The new writer regression tests fail against the original implementation.

Closes pnpm#2008.
u9g pushed a commit to u9g/pnpm that referenced this pull request Sep 25, 2026
Read and save package.yaml through PackageManifest, preserving comments and
existing mapping order while retaining the atomic-write and no-op-save paths.
Use manifest discovery for pkg, version, set-script, and link.

Extract the workspace writer's scalar alias support into a shared YAML utility.
Batch edits by YAML path and detach collection aliases when either side changes.
Reject invalid roots and colliding keys. Validate the edited document against
the requested value before replacing it. Publish new manifests atomically while
retaining normal creation permissions and existing-file permissions.

Keep the Rust test runner's isolated npmrc in commands spawned by test helpers,
preventing developer registry settings from leaking into fixture installs.

Follow-up to pnpm#15148. Related to pnpm#2008.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pnpm@11 reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Request: Preserve comments and key orders in package.yaml/pnpm-workspace.yaml when run 'pnpm install --save', 'pnpm update --latest', etc.

1 participant