About package.json formatter
Format package.json with the conventional key order and sorted dependencies, so diffs stay small and files are consistent across a team.
Why order helps
- Key information such as name, version and scripts is easy to find.
- Sorted dependencies make merge conflicts less likely.
- Consistent formatting reduces noise in reviews.
A worked example
A file where scripts comes first and the dependencies are in random order is rewritten with name, version and description at the top, then scripts, then dependencies sorted alphabetically. Sorted keys mean that two developers adding packages rarely cause merge conflicts.
Fields worth checking
- engines to state the supported Node version.
- files to control what gets published.
- private: true to stop an app from being published by mistake.
Indentation
npm writes package.json with two spaces. Using the same style avoids noisy changes in version control when npm updates the file.
