The missing npm wrapper for Gitleaks
Gitleaks - is a fast, lightweight secret scanner for git repositories.
This library is just a thin wrapper which automatically downloads the correct gitleaks binary for your platform on install and exposes it as a CLI command.
Installation
Typically installed as a dev dependency:
Local (project)
npm install --save-dev @b12k/gitleaks
Recent npm versions require approving dependency install scripts. Approve this package so its postinstall script can download the gitleaks binary:
npm approve-scripts @b12k/gitleaks
pnpm add -D --allow-build=@b12k/gitleaks @b12k/gitleaks
pnpm 11 requires the --allow-build flag so this package's postinstall script can download the gitleaks binary.
yarn add --dev @b12k/gitleaks
Global
npm install -g --allow-scripts=@b12k/gitleaks @b12k/gitleaks
Global npm installs cannot use npm approve-scripts; use --allow-scripts instead.
pnpm add -g --allow-build=@b12k/gitleaks @b12k/gitleaks
pnpm 11 requires the --allow-build flag during global install as well.
yarn global add @b12k/gitleaks
The postinstall script downloads the gitleaks binary for your platform from the official GitHub release.
If you already installed with npm or pnpm and the build was blocked, approve and rebuild it:
npm approve-scripts @b12k/gitleaks
npm rebuild @b12k/gitleaks
pnpm approve-builds @b12k/gitleaks
pnpm rebuild @b12k/gitleaks
Usage
See the gitleaks documentation for the full list of commands and flags.
Local install
npx gitleaks <command>
pnpm exec gitleaks <command>
yarn gitleaks <command>
Global install
gitleaks <command>
package.json script
{ "scripts": { "secrets": "gitleaks <command>" } }
Troubleshooting
If the binary fails to install, re-run with --foreground-scripts to see the postinstall output:
npm install --save-dev @b12k/gitleaks --foreground-scripts
pnpm add -D --allow-build=@b12k/gitleaks @b12k/gitleaks --foreground-scripts
yarn add --dev @b12k/gitleaks --foreground-scripts
Supported platforms
- Linux — x64, arm64
- macOS — x64, arm64
- Windows — x64, arm64
Version
The npm package version mirrors the gitleaks release version.
To install a different gitleaks release, define it in .gitleaks-version as v1.2.3 or 1.2.3 before installing the package.
If you add or change .gitleaks-version after installing, run:
gitleaks-install