Skip to content

fix: keep // comment keys with the field below them in package.json - #73

Merged
dsherret merged 1 commit into
mainfrom
fix/package-json-comment-keys
Oct 1, 2026
Merged

dsherret merged 1 commit into
mainfrom
fix/package-json-comment-keys

Conversation

@dsherret

@dsherret dsherret commented Oct 1, 2026

Copy link
Copy Markdown
Member

Closes #72

With packageJson.applyConventions, a top level key starting with // ("//", "// node", ...) was treated as an unknown field and sorted to the end of the file, away from the field it was written to describe.

Such a key now travels with the field written below it, the same way a real comment does:

  • several comment keys above one field keep the order they were written in
  • a comment key with no field below it stays at the end
  • comments and blank lines written above a comment key still move with it

Not changed here:

  • comment keys inside the sections that get sorted alphabetically (engines, bin, the dependency sections) are still sorted as ordinary names
  • a comment key always binds downwards, so one written after the field it describes moves with the next field instead

@dsherret
dsherret merged commit 17418d9 into main Oct 1, 2026
2 checks passed
@dsherret

dsherret commented Oct 1, 2026

Copy link
Copy Markdown
Member Author

This only did top level. Doing a new pr for nested sections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

applyConventions shouldn't move "//..." keys, those are comments

1 participant