-
Notifications
You must be signed in to change notification settings - Fork 3k
Format package.json with Prettier after npm install
#17973
Comments
We already take a lot of care to make sure package.json is sorted consistently, and that the existing indentation scheme is preserved. If you want a specific format beyond that for your package.json, you'll have to do it yourself. We're unlikely to go back to forcing the file to one particular format after so many folks wanting us to preserve things. |
I understand that, but Prettier does nothing to sorting and ordering. You can just pass the string of JSON, after the whole normalization and validation, and before passing it to writeFile. |
When I contribute to projects that use prettier and apply it to json, when I run |
Not a problem with Prettier, it respects ordering.
We could do the same with Prettier: Detect the indentation scheme to set npm should respect the project's Prettier config, or else use defaults tweaked to preserve indentation. The current forced formatting in package.json has terrible legibility; single item arrays are expanded to cover 3 lines! Most would say the carefully considered Prettier format, which has consensus, looks better. Prettier is fast becoming the standard for formatting .js, .graphql, .md, and more. If this must be a wontfix, at least can we have an npm script to hook on so that tidying up after npm can be automated? E.g. {
"scripts": {
"postpackageformat": "prettier --write package.json"
}
} |
@jaydenseric good point! I'm tired about that. |
It would be nice if |
I'm opening this issue because:
What's the feature?
Format package.json with Prettier
What problem is the feature intended to solve?
git diffs would be more pretty. The whole problem is that when
npm install
it formats it, then when update it from the editor which, of course uses some integration plugins (eslint + prettier), it is changed again, then commit. After that in next turn, for example just run some npm install or update the deps with some tool, the package.json again is formated, then commit and there is needless diff.Probably, workaround is to run prettier formatting on
precommit
onpackage.json
, but it again won't be good.Is the absence of this feature blocking you or your team? If so, how?
No
Is this feature similar to an existing feature in another tool?
No
Is this a feature you're prepared to implement, with support from the npm CLI team?
Yes, probably. I believe it is in
normalize-package-data
?The text was updated successfully, but these errors were encountered: