# npm `package.json` formatting This RFC ```bash= # New subcommand in `npm pkg` to format `package.json` based on config values npm pkg format # Set config value to make commands auto format package.json npm config set pkg-format-auto=true # The following commands will format `package.json` based on the config values npm install foo npm pkg set foo="bar npm init --yes ``` ### Configs Goal for initial implementation is to have these defaults mirror current behavior. - `pkg-format-auto` - controls whether commands that update package.json will also format it - defaults to `false` (`true`|`false`) - `pkg-format-indent-type` - defaults to `spaces` (`spaces`|`tabs`) - Related to: https://github.com/npm/rfcs/issues/420 - `pkg-format-indent-size` - defaults to `2` - `pkg-format-sort-dependencies` - defaults to `alpha` (`alpha`|`reverse-alpha`|`false`) - `pkg-format-sort-dev-dependencies` - defaults to `alpha` (`alpha`|`reverse-alpha`|`false`) - `pkg-format-sort-peer-dependencies` - defaults to `alpha` (`alpha`|`reverse-alpha`|`false`) - `pkg-format-sort-optional-dependencies` - defaults to `alpha` (`alpha`|`reverse-alpha`|`false`) - `pkg-format-sort-bundled-dependencies` - defaults to `alpha` (`alpha`|`reverse-alpha`|`false`) - `pkg-format-keys-start` - list of top level keys that will always be moved to the start of `package.json` - defaults to `name,description,version,author` - `pkg-format-keys-end` - list of top level keys that will always be moved to the end of `package.json` - defaults to `dependencies,scripts,workspaces` - `pkg-format-keys-sort` - defaults to `false` (`alpha`|`reverse-alpha`|`false`) ### Future Major Versions Depending on user feedback and how prescriptive we want to be, I think ### Actions - [ ] find what commands update `package.json`