0.3.0 • Published 7 months ago

prettier-pnp v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

prettier-pnp

Prettier-pnp is utility for running Prettier with plugins, without installing them manually.

Why?

Sometimes you need to format some files, but you don't want to create a package.json, install Prettier and plugins for it. Also Prettier can't load plugins installed globally (it tries to import() them, but Node.js doesn't support import from NODE_PATH).

This may be useful for CI environments, where you need to quickly check the formatting of files.

How?

Prettier-pnp works like a proxy for prettier cli. All arguments passed to prettier-pnp will be forwarded directly to prettier. Prettier-pnp adds only three new args:

  • --pnp <plugin name> or --pnp <plugin name>@<version>

    Runs prettier with plugin named <plugin name> (or <plugin name>@<version> if the version was specified).

    Example:

    npx prettier-pnp --pnp prettier-plugin-curly index.js
  • --pn <short plugin name> or --pn <short plugin name>@<version>

    Shorthand for --pnp. If plugin name starts with prettier-plugin-, then you can omit this part.

    Example:

    npx prettier-pnp --pn curly index.js
  • --quiet

    Prevent any extra output (e.g plugin installation progress). Only the output of Prettier will be printed.

Prettier-pnp includes Prettier as dependency. Also, all requested plugins are stored in the internal storage (plugin-store folder inside the installed prettier-pnp). So, when you run:

npx prettier-pnp --pn my-plugin index.js

Prettier-pnp tries to install prettier-plugin-my-plugin as a regular NPM package. Then it resolves the absolute path to the plugin and passes it to the Prettier.

After you uninstall prettier-pnp, all plugins will also be uninstalled, because they are stored inside the plugin-store

Let's assume that you have installed prettier-pnp globally to /home/user/node_modules. After

npx prettier-pnp --pn my-plugin --single-quote index.js

The folder structure will look like this:

/home/user/node_modules
 📂 prettier-pnp
 ├─   package.json
 ├─ 📁 dist
 └─ 📂 plugin-store
    ├─   package.json
    └─ 📂 node_modules
       └─ 📂 prettier-plugin-my-plugin
          ├─   index.js
          └─   package.json

And the Prettier will be executed with the following arguments:

prettier --plugin /home/user/node_modules/prettier-pnp/plugin-store/node_modules/prettier-plugin-my-plugin/index.js --single-quote index.js

License

MIT License © 2023 auvred

0.3.0

7 months ago

0.2.1

8 months ago

0.2.0

9 months ago

0.1.2

9 months ago

0.1.1

9 months ago

0.1.0

9 months ago