lockfile-sync-check
A command-line tool to check if your package manager's lockfile is in sync with the latest changes in your Git repository.
Features
- Supports multiple package managers (npm, yarn, pnpm)
- Optional automatic dependency installation
- Easy integration with Git hooks
Installation
npm install -D lockfile-sync-check
# or
yarn add -D lockfile-sync-check
# or
pnpm add -D lockfile-sync-check
Usage
lockfile-sync-check [package-manager] [--install]
Options
package-manager: Optional. Specify the package manager to use ("npm", "yarn", or "pnpm"). If not provided, defaultpnpm.--install: Optional. Automatically install dependencies if the lockfile is out of sync.
Example
# Check if lockfile is in sync, using default package manager (pnpm)
lockfile-sync-check
# Check using specific package manager
lockfile-sync-check npm
# Check and auto-install if out of sync
lockfile-sync-check npm --install
Git Hook Integration
Using simple-git-hooks
- Install simple-git-hooks:
npm install -D simple-git-hooks
# or
yarn add -D simple-git-hooks
# or
pnpm add -D simple-git-hooks
- Add configuration to your package.json:
{
"simple-git-hooks": {
"post-merge": "lockfile-sync-check --install",
"post-rewrite": "lockfile-sync-check --install"
}
}
- Initialize git hooks:
npx simple-git-hooks
Using Husky
- Install Husky:
npm install -D husky
# or
yarn add -D husky
# or
pnpm add -D husky
- Initialize Husky:
npx husky install
- Add hooks:
npx husky add .husky/post-merge "lockfile-sync-check --install"
npx husky add .husky/post-rewrite "lockfile-sync-check --install"
Manual Setup
Alternatively, you can manually add the script to your .git/hooks/post-merge or .git/hooks/post-rewrite: