@3-/prettier-pnp v0.3.1
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
prettierwith 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 withprettier-plugin-, then you can omit this part.Example:
npx prettier-pnp --pn curly index.js--quietPrevent 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.jsPrettier-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 theplugin-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.jsThe 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.jsonAnd 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