fixpack is a command-line interface (CLI) tool designed to enforce a consistent structure and content within `package.json` files. It automates the reordering of top-level keys, alphabetically sorts `dependencies` and `devDependencies`, and ensures a newline at the end of the file. The tool also provides configurable warnings for missing recommended fields (e.g., `description`, `author`, `license`) and errors for missing required fields (e.g., `name`, `version`). A key differentiator is its ability to tolerate malformed JSON using the `alce` library, making it robust against minor syntax errors. The current stable version is 4.0.0, though the project's update cadence appears irregular, with previous major updates and patch fixes spanning several years. It supports extensive configuration via `.fixpackrc` files and CLI arguments, and can be integrated into CI/CD pipelines using its `--dryRun` flag to check for compliance without modifying files.
npm install fixpackVerified import paths — ran on the pinned version, not inferred.
Demonstrates global installation and execution of fixpack, including its use in a post-install hook and a dry run for CI checks.
Create a `.fixpackrc` file in your project root or home directory, or pass configuration options directly as CLI arguments (e.g., `fixpack --indent 2`).
Always commit your `package.json` to version control before running `fixpack`, or use the `--dryRun` flag first to preview changes. For critical environments, consider piping the output of `fixpack` to a temporary file before overwriting.
Ensure all fields listed in your `required` configuration are present in `package.json`. Adjust the `required` array in your `.fixpackrc` if certain fields are not strictly necessary for your project.
When integrating into CI, explicitly check for exit code `0` for success if the goal is to ensure an already fixed `package.json`. If using `--dryRun` as a check, an exit code of `1` indicates a non-compliant file.
Only use `fixpack --wipe` if you understand its implications and intend to immediately follow up with `npm update --save && npm update --save-dev` or similar commands to reinstall specific version ranges. Avoid using it generally.
Ensure you are running `fixpack` from the root directory of your project, or a subdirectory where a `package.json` can be found in a parent directory.
Install `fixpack` globally using `npm i -g fixpack` or `yarn global add fixpack`. If it's already installed globally, check your shell's PATH configuration to ensure the npm global bin directory is included.
If running interactively, this means your `package.json` was fixed. If in CI and `--dryRun` was used, it means the `package.json` was not compliant. Review the output for warnings/errors and ensure your `package.json` meets the configured requirements. Run `fixpack` without `--dryRun` to apply changes.