TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

A Prettier package.json Prettier Plugin

A plugin created by Megabyte Labs

A Prettier plugin that formats the package.json file by leveraging the prettier-package-json CLI library

Table of Contents


The prettier-package-json CLI tool is easily the best package.json formatter available. However, despite its name, it is not a Prettier plugin. This project brings all of the great prettier-package-json features to Prettier as a plugin. It sorts in an opinionated style and also has some nifty features that other formatters do not have like:

  • Sorting in an opinionated manner (common elements at the top of the file and everything else sorted alphabetically afterwards)
  • Sorting scripts while keeping pre and post commands together
  • Removing redundant or unnecessary fields in favor of more compact syntax
  • More information available on the prettier-package-json page


If you are simply including this library in your project, all you need is a recent version of Node.js. Node.js >14.18.0 is sometimes required and is the only version range we actively support. Albeit, it is highly probable that lower versions will work as well depending on the requirements that this project imports.

Developer Requirements

The following versions of Node.js and Python are required for development:

Other versions may work, but only the above versions are supported. Most development dependencies are installed automatically by our Taskfile.yml set-up (even Node.js and Python). Run bash to install Bodega (an improved fork of go-task) and run the initialization sequence. The taskfiles will automatically install dependencies as they are needed, based on what development tasks you are running. For more information, check out the or simply run:

npm run help

npm run help will ensure Bodega is installed and then open an interactive dialog where you can explore and learn about various developer commands.

Usage / Installation

Prettier plugins are automatically registered if their package name begins with @prettier/plugin-, prettier-plugin-, or @<scope>/prettier-plugin-. Since this package begins with prettier-plugin-, all you have to do is install it via:

npm install --save-dev prettier-plugin-package-perfection

That is it! You are good to go. Prettier should automatically pick up on the plugin.

Shared Configuration

With Prettier, you can create a shared configuration that you can share across all your projects. To do this, you first have to find or create an NPM package that will house your configuration. Then, you have to set the .prettier key in package.json equal to the name of your shared configuration NPM package.

You can find an example shared configuration NPM package here (check out the src/main.ts file to see the magic). All the configuration does is export a typical configuration with module.exports. This opens the door for dynamically configuring your project's configuration and keeping things DRY.

Example Configuration

Specifically including this Prettier plugin in your configuration might look something like this:

  "bracketSpacing": true,
  "printWidth": 120,
  "quoteProps": "as-needed",
  "requirePragma": false,
  "semi": false,
  "singleQuote": true,
  "tabWidth": 2,
  "trailingComma": "none",
  "useTabs": false,
  "goTemplateBracketSpacing": true,
  "overrides": [
      "files": ["*.go.html"],
      "options": {
        "parser": "go-template"
      "files": ["*.yml"],
      "options": {
        "printWidth": 160
  "plugins": [


Contributions, issues, and feature requests are welcome! Feel free to check the issues page. If you would like to contribute, please take a look at the contributing guide.


Dear Awesome Person,

I create open source projects out of love. Although I have a job, shelter, and as much fast food as I can handle, it would still be pretty cool to be appreciated by the community for something I have spent a lot of time and money on. Please consider sponsoring me! Who knows? Maybe I will be able to quit my job and publish open source full time.


Brian Zalewski

Open Collective sponsors GitHub sponsors Patreon


Below you will find a list of services we leverage that offer special incentives for signing up for their services through our special links:

MailChimp DigitalOcean Referral Badge


Copyright © 2020-2021 Megabyte LLC. This project is MIT licensed.

Package Sidebar


npm i prettier-plugin-package-perfection

Weekly Downloads






Unpacked Size

25.9 kB

Total Files


Last publish


  • professormanhattan