An opinionated package.json formatter plugin for Prettier (v0.22.1, released 2024-03-14). It sorts top-level keys in a custom order, alphabetizes scripts (with pre/post script grouping), engines, files, and dependencies. Provides presets 'npm' and 'npm-plus' via `packageSortOrderPreset`. Requires Prettier ^3.0.3. Unlike prettier-plugin-packagejson, it offers more opinionated sorting and supports custom sort order via `packageSortOrder`.
npm install prettier-plugin-pkgVerified import paths — ran on the pinned version, not inferred.
Shows installation, configuration with plugins array and sort preset, and example formatting of package.json.
Upgrade Prettier to ^3.0.3 (or higher).
Check script ordering after upgrade; may need to adjust script names if custom ordering changed.
Use ESM import syntax or rely on Prettier plugin resolution; avoid require('prettier-plugin-pkg').Use packageSortOrder to explicitly place custom keys or set packageIgnoreSort for specific keys.
Run `npm install --save-dev prettier prettier-plugin-pkg` and ensure both are in devDependencies.
Upgrade Prettier to 3.x. Check that plugin is installed and listed in plugins array.
Update prettier-plugin-pkg to v0.21.0+ with `npm install prettier-plugin-pkg@latest`.
Remove direct require; use only via Prettier configuration.