1.6.1 • Published 5 years ago
nice-package-json v1.6.1
nice-package-json
An opinionated formatter for
package.jsonfiles
Usage
Print a formatted package.json file from the current working directory:
$ npx nice-package-jsonFormat and overwrite the package.json in the current working directory:
$ npx nice-package-json --writeOr format a file named something other than package.json:
$ npx nice-package-json --write pkg.jsonCompare with the current package.json file:
$ npx nice-package-json | diff package.json -Format each package.json in a Yarn-managed monorepo:
$ yarn add -DW nice-package-json # only run once
$ yarn workspaces run nice-package-json --writeProgrammatically
const nicePkg = require("nice-package-json");
const pkg = require("./package.json");
await fs.writeFile("package.json", nicePackageJson(pkg));Formatting
- 2-space indent
- Dependencies are always alphabetized
- Keys will be sorted into the following order:
nameprivateversiondescriptionkeywordsenginestypebrowsermainmodulesveltebinfileshomepagebugsrepositoryauthorcontributorslicensescriptsdependenciesdevDependenciesbundledDependenciesoptionalDependenciespeerDependenciespublishConfigconfigworkspaces- Everything else, sorted alphabetically (e.g.
eslintConfig,jest, etc.)
- Values of the following keys will be sorted alphabetically:
contributors(bynameor value)engines(by key)fileskeywordspublishConfig(by key)repository(by key)scripts(by key)