What is fixpack?
The fixpack npm package is a tool designed to format and sort the fields in a package.json file according to a predefined order. This helps maintain consistency and readability in the package.json file.
What are fixpack's main functionalities?
Sort and Format package.json
This feature allows you to sort and format the fields in your package.json file. By running the fixpack function and passing the path to your package.json file, it will reorder the fields according to a predefined order and format them for better readability.
const fixpack = require('fixpack');
fixpack('./path/to/package.json');
Custom Configuration
This feature allows you to customize the order in which the fields in your package.json file are sorted. By providing an options object with a custom order array, you can define your own field order.
const fixpack = require('fixpack');
const options = { order: ['name', 'version', 'description', 'main', 'scripts', 'dependencies', 'devDependencies'] };
fixpack('./path/to/package.json', options);
Other packages similar to fixpack
sort-package-json
The sort-package-json package is similar to fixpack in that it also sorts the fields in a package.json file. It provides a default order but also allows for custom sorting orders. Compared to fixpack, sort-package-json is more focused on sorting and does not include formatting capabilities.
npm-package-json-lint
The npm-package-json-lint package is a linter for package.json files. It helps enforce a consistent style and structure by checking for common issues and enforcing rules. While it does not sort or format the fields like fixpack, it provides a broader range of linting capabilities to ensure the quality of the package.json file.
fixpack
A package.json file scrubber for the truly insane.
It will re-write your package.json file as follows:
- name first
- description second
- version third
- author fourth
- all other keys in alphabetical order
- dependencies and devDependencies sorted alphabetically
- newline at the end of the file
It will warn you if any of these are missing:
- description
- author
- repository
- keywords
- main
- bugs
- homepage
- license
Maintain current indentation, End of Line, and Final New Line, or set them to your configured value
(see configuration).
Oh, and it will tolerate improperly quoted and comma'd JSON thanks to ALCE.
Oh, and can do same if you pass it a bower.json
file or whatnot.
Oh, and it will exit with 0
when already fixed or with 1
otherwise (so combined with --dryRun
flag it can be used as CI check)
Usage
- install it globally
npm i -g fixpack
- run it in the same directory as your package.json, that's it.
fixpack
What you might do if you're clever
npm i cool_package --save && fixpack
Configuration
It's configurable. You can create a .fixpackrc
file in your project or anywhere up the tree to your $HOME
directory. Or overwrite options via CLI arguments.
Uses the rc module to do this. So you can pass all these as CLI args too.
The available options and their defaults shown below:
{
sortToTop: [
'name',
'description',
'version',
'author'
],
required: [
'name',
'version'
],
warn: [
'description',
'author',
'repository',
'keywords',
'main',
'bugs',
'homepage',
'license'
],
requiredOnPrivate: [],
warnOnPrivate: ['name', 'version', 'description', 'main'],
sortedSubItems: [
'dependencies',
'devDependencies',
'jshintConfig',
'scripts',
'keywords'
],
quiet: false,
files: ['package.json'],
dryRun: false,
wipe: false,
indent: null,
newLine: null,
finalNewLine: null
}
Changelog
- 3.0.6 - Fix
false
removal issue. - 3.0.5 - Fix coloration of warnings
- 3.0.4 - OS specific EOL
- 3.0.3 - updates to remove NSP warnings in deps.
- 2.3.0 - add
wipe
option that sets all dep versions to *
for easier bulk updating. - 2.2.0 - add
optionalDependencies
to auto sorted - 2.1.0 - switched to standard style. Add
peerDependencies
to default sorted keys. - 2.0.1 - don't error on missing bower file by default.
- 2.0.0 - configurable via
.fixpackrc
file using rc module. - x.x.x - unknown miscellaneous madness and poor version tracking
- 0.0.2 diff - EOF newline
- 0.0.1 - initial release
Credits
This embarrassing display of insanity,
type-A-ness, and OCD brought to you by @HenrikJoreteg.
License
MIT