fix(core): preserve comments in catalog YAML updates#35733
fix(core): preserve comments in catalog YAML updates#35733polygraph-snapshot-app[bot] wants to merge 5 commits into
Conversation
|
View your CI Pipeline Execution ↗ for commit 3c9d3a3
☁️ Nx Cloud last updated this comment at |
✅ Deploy Preview for nx-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for nx-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
The catalog manager update path used @zkochan/js-yaml's load/dump, which parses YAML to plain JS objects and serializes back without comments, anchors, or formatting. As a result, `nx migrate` and `nx release version` wiped user-authored content from pnpm-workspace.yaml and .yarnrc.yml whenever a catalog-referenced package was bumped. Switch updateCatalogVersions in both nx and devkit catalog managers (pnpm and yarn variants) to the eemeli/yaml Document API. Walk paths alias-aware so configs using YAML anchors keep working, and seed null placeholders inline so empty `catalog:` skeletons (sometimes carrying only comments) can still be populated without dropping their comments.
Both pnpm-manager and yarn-manager in each of `nx` and `@nx/devkit` contained the same alias-aware YAML helpers, the same read helpers, and a near-identical `updateCatalogVersions` body that differed only by the config filename. Move them into a per-package `manager-utils.ts` and let each manager's methods delegate. Each manager file drops ~180 lines. The duplication between nx and devkit remains, intentionally: the @nx/devkit peerDep range covers nx versions that don't expose these helpers via devkit-internals. The devkit copy can be replaced with a re-export from nx once the lowest supported version ships the helpers.
The new yaml-based catalog updater emits unquoted scalars (`react: 18.2.0`) where the previous `@zkochan/js-yaml` `dump` path emitted forced double-quoted scalars (`react: "18.2.0"`). Both are semantically identical YAML, but the e2e assertions in misc.test.ts were hard-coded against the quoted form. Drop the quotes from the expected substrings.
6e54e78 to
3c9d3a3
Compare
… [Self-Healing CI Rerun]
There was a problem hiding this comment.
Nx Cloud has identified a flaky task in your failed CI:
🔂 Since the failure was identified as flaky, we triggered a CI rerun by adding an empty commit to this branch.
🎓 Learn more about Self-Healing CI on nx.dev
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub. |
|
Warning Review the following alerts detected in dependencies. According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.
|
Current Behavior
When
nx migrate(ornx release version) bumps a package that's referenced viacatalog:inpnpm-workspace.yamlor.yarnrc.yml, all comments, YAML anchors, and formatting in the file are wiped out. The catalog manager update path used@zkochan/js-yaml'sload/dump, which parses YAML to plain JS objects and serializes back without preserving any non-data tokens.Expected Behavior
User-authored comments, anchors, and formatting survive a catalog version bump. Only the targeted version entry changes; everything else in the file is byte-stable.
Implementation Details
updateCatalogVersionsin both thenxand@nx/devkitcatalog managers (pnpm + yarn variants) now uses theyamlpackage'sDocumentAPI, which is designed for comment-preserving round-trips. The walk is alias-aware so configs using YAML anchors keep working, and null placeholders (catalog:with no value, optionally carrying comments) are seeded inline so empty skeletons can still be populated without dropping their comments.yamlis added as a direct dependency of@nx/devkit(it was already a runtime dep ofnx).View session information ↗