@b12k/gitleaks 0.0.0-v.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bogdan Kolesnyk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # The missing npm wrapper for [Gitleaks](https://github.com/gitleaks/gitleaks)
2
+
3
+ [Gitleaks](https://github.com/gitleaks/gitleaks) - is a fast, lightweight secret scanner for git repositories.
4
+
5
+ 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.
6
+
7
+ ## Installation
8
+
9
+ Typically installed as a dev dependency:
10
+
11
+ **Local (project)**
12
+
13
+ ```bash
14
+ npm install --save-dev @b12k/gitleaks
15
+ ```
16
+
17
+ ```bash
18
+ pnpm add -D --allow-build=@b12k/gitleaks @b12k/gitleaks
19
+ ```
20
+
21
+ pnpm 11 requires the `--allow-build` flag so this package's postinstall script can download the gitleaks binary.
22
+
23
+ ```bash
24
+ yarn add --dev @b12k/gitleaks
25
+ ```
26
+
27
+ **Global**
28
+
29
+ ```bash
30
+ npm install -g @b12k/gitleaks
31
+ ```
32
+
33
+ ```bash
34
+ pnpm add -g --allow-build=@b12k/gitleaks @b12k/gitleaks
35
+ ```
36
+
37
+ pnpm 11 requires the `--allow-build` flag during global install as well.
38
+
39
+ ```bash
40
+ yarn global add @b12k/gitleaks
41
+ ```
42
+
43
+ The postinstall script downloads the gitleaks binary for your platform from the official GitHub release.
44
+
45
+ If you already installed with pnpm 11 and the build was blocked, approve and rebuild it:
46
+
47
+ ```bash
48
+ pnpm approve-builds @b12k/gitleaks
49
+ pnpm rebuild @b12k/gitleaks
50
+ ```
51
+
52
+ ## Usage
53
+
54
+ See the [gitleaks documentation](https://github.com/gitleaks/gitleaks) for the full list of commands and flags.
55
+
56
+ **Local install**
57
+
58
+ ```bash
59
+ npx gitleaks <command>
60
+ ```
61
+
62
+ ```bash
63
+ pnpm exec gitleaks <command>
64
+ ```
65
+
66
+ ```bash
67
+ yarn gitleaks <command>
68
+ ```
69
+
70
+ **Global install**
71
+
72
+ ```bash
73
+ gitleaks <command>
74
+ ```
75
+
76
+ **`package.json` script**
77
+
78
+ ```json
79
+ { "scripts": { "secrets": "gitleaks <command>" } }
80
+ ```
81
+
82
+ ## Troubleshooting
83
+
84
+ If the binary fails to install, re-run with `--foreground-scripts` to see the postinstall output:
85
+
86
+ ```bash
87
+ npm install --save-dev @b12k/gitleaks --foreground-scripts
88
+ ```
89
+
90
+ ```bash
91
+ pnpm add -D --allow-build=@b12k/gitleaks @b12k/gitleaks --foreground-scripts
92
+ ```
93
+
94
+ ```bash
95
+ yarn add --dev @b12k/gitleaks --foreground-scripts
96
+ ```
97
+
98
+ ## Supported platforms
99
+
100
+ - Linux — x64, arm64
101
+ - macOS — x64, arm64
102
+ - Windows — x64, arm64
103
+
104
+ ## Version
105
+
106
+ The npm package version mirrors the gitleaks release version.
107
+
108
+ To install a different gitleaks release, define it in `.gitleaks-version` as `v1.2.3` or `1.2.3` before installing the package.
package/dist/cli.js ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from "node:child_process";
3
+ import { access } from "node:fs/promises";
4
+ import update_notifier from "update-notifier";
5
+ import { binaryPath, name as external_config_js_name, version } from "./config.js";
6
+ import { logError } from "./log.js";
7
+ function setErrorExitCode(errorName, metaInfo) {
8
+ try {
9
+ logError(errorName, metaInfo);
10
+ } catch {
11
+ process.exitCode = 1;
12
+ }
13
+ }
14
+ update_notifier({
15
+ pkg: {
16
+ name: external_config_js_name,
17
+ version: version
18
+ },
19
+ shouldNotifyInNpmScript: true,
20
+ updateCheckInterval: 86400000
21
+ }).notify({
22
+ defer: false
23
+ });
24
+ let canSpawn = true;
25
+ try {
26
+ await access(binaryPath);
27
+ } catch {
28
+ setErrorExitCode('binaryNotFound');
29
+ canSpawn = false;
30
+ }
31
+ if (canSpawn) {
32
+ const childProcess = spawn(binaryPath, process.argv.slice(2), {
33
+ stdio: 'inherit'
34
+ });
35
+ childProcess.on('error', (error)=>{
36
+ setErrorExitCode('executionFailed', error.message);
37
+ });
38
+ childProcess.on('exit', (code, signal)=>{
39
+ if (signal) return void process.kill(process.pid, signal);
40
+ process.exitCode = code ?? 1;
41
+ });
42
+ }
package/dist/config.js ADDED
@@ -0,0 +1,48 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import node_path from "node:path";
3
+ import package_0 from "../package.json" with {
4
+ type: "json"
5
+ };
6
+ const platform = 'win32' === process.platform ? 'windows' : process.platform;
7
+ const isWindows = 'windows' === platform;
8
+ const { arch: architecture } = process;
9
+ const { name: config_name, version: version } = package_0;
10
+ const [defaultVersion = ''] = version.split('-');
11
+ const versionFileName = '.gitleaks-version';
12
+ const versionFilePath = node_path.join(process.env['INIT_CWD'] ?? process.cwd(), versionFileName);
13
+ let versionOverride;
14
+ try {
15
+ const fileContents = await readFile(versionFilePath, 'utf8');
16
+ versionOverride = fileContents.trim().replace(/^v/, '');
17
+ } catch (error) {
18
+ if ('ENOENT' !== error.code) {
19
+ const message = Error.isError(error) ? error.message : 'Unknown error.';
20
+ throw new Error(`Failed to read ${versionFileName}: ${message}`, {
21
+ cause: error
22
+ });
23
+ }
24
+ versionOverride = '';
25
+ }
26
+ const libraryVersion = versionOverride || defaultVersion;
27
+ const currentDirectory = import.meta.dirname;
28
+ const libraryName = 'gitleaks';
29
+ const binaryExtension = isWindows ? '.exe' : '';
30
+ const binaryFileName = `${libraryName}${binaryExtension}`;
31
+ const binaryPath = node_path.join(currentDirectory, binaryFileName);
32
+ const archiveExtension = isWindows ? '.zip' : '.tar.gz';
33
+ const archiveFileName = `${libraryName}_${libraryVersion}_${platform}_${architecture}${archiveExtension}`;
34
+ const checksumsFileName = `${libraryName}_${libraryVersion}_checksums.txt`;
35
+ const gitLeaksGithubUrl = `https://github.com/gitleaks/gitleaks/releases/download/v${libraryVersion}`;
36
+ const archiveGithubUrl = `${gitLeaksGithubUrl}/${archiveFileName}`;
37
+ const checksumsGithubUrl = `${gitLeaksGithubUrl}/${checksumsFileName}`;
38
+ const archivePath = node_path.join(currentDirectory, archiveFileName);
39
+ const supportedPlatforms = [
40
+ 'darwin',
41
+ 'windows',
42
+ 'linux'
43
+ ];
44
+ const supportedArchitectures = [
45
+ 'x64',
46
+ 'arm64'
47
+ ];
48
+ export { architecture, archiveFileName, archiveGithubUrl, archivePath, binaryPath, checksumsGithubUrl, config_name as name, currentDirectory, libraryName, libraryVersion, platform, supportedArchitectures, supportedPlatforms, version };
package/dist/errors.js ADDED
@@ -0,0 +1,27 @@
1
+ const ERRORS_BY_KEY = {
2
+ binaryNotFound: {
3
+ instruction: 'Try re-installing the library.',
4
+ message: 'Binary not found.'
5
+ },
6
+ executionFailed: {
7
+ instruction: 'Try re-installing the library.',
8
+ message: 'Failed to execute the binary.'
9
+ },
10
+ installationFailed: {
11
+ instruction: '',
12
+ message: 'Failed to install the binary.'
13
+ },
14
+ unsupportedArchitecture: {
15
+ instruction: 'Supported architectures are x64 and arm64.',
16
+ message: 'Unsupported architecture.'
17
+ },
18
+ unsupportedArchiveFormat: {
19
+ instruction: 'Supported archive formats are .zip and .tar.gz.',
20
+ message: 'Unsupported archive format.'
21
+ },
22
+ unsupportedPlatform: {
23
+ instruction: 'Supported platforms are darwin, windows and linux.',
24
+ message: 'Unsupported platform.'
25
+ }
26
+ };
27
+ export { ERRORS_BY_KEY };
@@ -0,0 +1,14 @@
1
+ import extract_zip from "extract-zip";
2
+ import { extract } from "tar";
3
+ import { logError } from "./log.js";
4
+ async function extractArchive(archivePath, targetDirectoryPath) {
5
+ if (archivePath.endsWith('.zip')) return void await extract_zip(archivePath, {
6
+ dir: targetDirectoryPath
7
+ });
8
+ if (archivePath.endsWith('.tar.gz')) return void await extract({
9
+ cwd: targetDirectoryPath,
10
+ file: archivePath
11
+ });
12
+ logError('unsupportedArchiveFormat', archivePath);
13
+ }
14
+ export { extractArchive };
package/dist/log.js ADDED
@@ -0,0 +1,19 @@
1
+ import boxen from "boxen";
2
+ import { libraryName } from "./config.js";
3
+ import { ERRORS_BY_KEY } from "./errors.js";
4
+ function log(message, options) {
5
+ console.log(boxen(message, options));
6
+ }
7
+ const errorPrefix = `[${libraryName}]`;
8
+ function logError(errorName, metaInfo) {
9
+ const error = ERRORS_BY_KEY[errorName];
10
+ let logMessage = error.message;
11
+ if (error.instruction) logMessage += `\n\n${error.instruction}`;
12
+ if (metaInfo) logMessage += `\n\n${metaInfo}`;
13
+ log(logMessage, {
14
+ borderColor: 'red',
15
+ title: errorPrefix
16
+ });
17
+ throw new Error(`${errorPrefix} ${error.message}`);
18
+ }
19
+ export { log, logError };
@@ -0,0 +1,73 @@
1
+ import { createHash } from "node:crypto";
2
+ import { createWriteStream } from "node:fs";
3
+ import { readFile, rm } from "node:fs/promises";
4
+ import { Readable } from "node:stream";
5
+ import { pipeline } from "node:stream/promises";
6
+ import { architecture, archiveFileName, archiveGithubUrl, archivePath, binaryPath, checksumsGithubUrl, currentDirectory, libraryName, platform, supportedArchitectures, supportedPlatforms } from "./config.js";
7
+ import { extractArchive } from "./extract-archive.js";
8
+ import { log, logError } from "./log.js";
9
+ const DOWNLOAD_TIMEOUT_MS = 300000;
10
+ if (!supportedPlatforms.includes(platform)) logError('unsupportedPlatform');
11
+ if (!supportedArchitectures.includes(architecture)) logError('unsupportedArchitecture');
12
+ async function createFetchResponse(url) {
13
+ const response = await fetch(url, {
14
+ signal: AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS)
15
+ });
16
+ if (!response.ok) throw new Error(String(response.status));
17
+ return response;
18
+ }
19
+ async function downloadArchive() {
20
+ log(archiveGithubUrl, {
21
+ borderColor: 'green',
22
+ title: `${libraryName}:download`
23
+ });
24
+ const response = await createFetchResponse(archiveGithubUrl);
25
+ if (!response.body) throw new Error('Archive download returned no body.');
26
+ log(archivePath, {
27
+ borderColor: 'green',
28
+ title: `${libraryName}:save`
29
+ });
30
+ await pipeline(Readable.fromWeb(response.body), createWriteStream(archivePath));
31
+ }
32
+ async function ensureArchiveChecksum() {
33
+ log(checksumsGithubUrl, {
34
+ borderColor: 'green',
35
+ title: `${libraryName}:verify`
36
+ });
37
+ const response = await createFetchResponse(checksumsGithubUrl);
38
+ const checksums = await response.text();
39
+ const checksum = checksums.split('\n').find((line)=>line.endsWith(` ${archiveFileName}`))?.split(/\s+/, 1)[0];
40
+ if (!checksum) throw new Error(`Checksum not found for ${archiveFileName}.`);
41
+ const archive = await readFile(archivePath);
42
+ const actualChecksum = createHash('sha256').update(archive).digest('hex');
43
+ if (actualChecksum !== checksum) throw new Error(`Checksum mismatch for ${archiveFileName}.`);
44
+ }
45
+ async function install() {
46
+ await downloadArchive();
47
+ await ensureArchiveChecksum();
48
+ log(currentDirectory, {
49
+ borderColor: 'green',
50
+ title: `${libraryName}:extract`
51
+ });
52
+ await extractArchive(archivePath, currentDirectory);
53
+ log(binaryPath, {
54
+ borderColor: 'green',
55
+ title: `${libraryName}:installed`
56
+ });
57
+ }
58
+ async function installWithCleanup() {
59
+ try {
60
+ await install();
61
+ } finally{
62
+ await rm(archivePath, {
63
+ force: true
64
+ });
65
+ }
66
+ }
67
+ try {
68
+ await installWithCleanup();
69
+ } catch (error) {
70
+ let message = 'Unknown error.';
71
+ if (Error.isError(error)) message = error.message;
72
+ logError('installationFailed', message);
73
+ }
package/package.json ADDED
@@ -0,0 +1,102 @@
1
+ {
2
+ "name": "@b12k/gitleaks",
3
+ "version": "0.0.0-v.1",
4
+ "description": "The missing NPM wrapper for Gitleaks",
5
+ "keywords": [
6
+ "api-keys",
7
+ "cli",
8
+ "data-loss-prevention",
9
+ "devsecops",
10
+ "dlp",
11
+ "files",
12
+ "git",
13
+ "gitleaks",
14
+ "npm",
15
+ "passwords",
16
+ "secret",
17
+ "secrets",
18
+ "security",
19
+ "security-tools",
20
+ "stdin",
21
+ "tokens",
22
+ "wrapper"
23
+ ],
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/b12k/gitleaks.git"
27
+ },
28
+ "license": "MIT",
29
+ "author": "Bogdan Kolesnyk",
30
+ "type": "module",
31
+ "bin": {
32
+ "gitleaks": "dist/cli.js"
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "scripts"
37
+ ],
38
+ "scripts": {
39
+ "build": "rslib",
40
+ "check": "run-p -l check:*",
41
+ "check:format": "prettier . --check",
42
+ "check:package-json": "sort-package-json --check",
43
+ "check:scripts": "eslint . --cache",
44
+ "check:types": "tsc --noEmit",
45
+ "deps:check": "ncu -e 1 -c 7",
46
+ "deps:update": "ncu -du --doctorTest \"pnpm deps:update:doctor\" -c 7",
47
+ "deps:update:doctor": "run-p -l check:types check:scripts build",
48
+ "dev": "rslib --watch",
49
+ "fix": "run-p -l fix:*",
50
+ "fix:format": "prettier . --write",
51
+ "fix:package-json": "sort-package-json",
52
+ "fix:scripts": "eslint . --fix --cache",
53
+ "ga:notify": "tsx .github/notify.ts",
54
+ "ga:update-gitleaks": "tsx .github/update-gitleaks.ts",
55
+ "husky:commit-msg": "commitlint",
56
+ "husky:pre-commit": "lint-staged",
57
+ "husky:pre-push": "branch-name-lint",
58
+ "postinstall": "node scripts/postinstall.js",
59
+ "prepack": "run-p check build",
60
+ "prepare": "husky",
61
+ "release": "release-it --preRelease=v"
62
+ },
63
+ "dependencies": {
64
+ "boxen": "8.0.1",
65
+ "extract-zip": "2.0.1",
66
+ "tar": "7.5.19",
67
+ "update-notifier": "7.3.1"
68
+ },
69
+ "devDependencies": {
70
+ "@b12k/branch-name-lint": "1.3.0",
71
+ "@commitlint/config-conventional": "21.1.0",
72
+ "@eslint/js": "10.0.1",
73
+ "@release-it/conventional-changelog": "11.0.1",
74
+ "@rslib/core": "0.23.1",
75
+ "@types/node": "26.0.1",
76
+ "@types/semver": "7.7.1",
77
+ "@types/update-notifier": "6.0.8",
78
+ "commitlint": "21.1.0",
79
+ "eslint": "10.6.0",
80
+ "eslint-config-airbnb-extended": "3.1.0",
81
+ "eslint-config-prettier": "10.1.8",
82
+ "eslint-plugin-perfectionist": "5.9.1",
83
+ "eslint-plugin-unicorn": "70.0.0",
84
+ "husky": "9.1.7",
85
+ "lint-staged": "17.0.8",
86
+ "npm-check-updates": "22.2.9",
87
+ "npm-run-all2": "9.0.2",
88
+ "prettier": "3.9.1",
89
+ "release-it": "20.2.1",
90
+ "semver": "7.8.5",
91
+ "sort-package-json": "4.0.0",
92
+ "tsx": "4.22.4",
93
+ "typescript": "6.0.3"
94
+ },
95
+ "packageManager": "pnpm@11.10.0",
96
+ "engines": {
97
+ "node": ">=24"
98
+ },
99
+ "publishConfig": {
100
+ "access": "public"
101
+ }
102
+ }
@@ -0,0 +1,6 @@
1
+ import path from 'node:path';
2
+
3
+ const directory = import.meta.dirname;
4
+ // eslint-disable-next-line n/no-process-exit
5
+ if (!directory.includes('node_modules')) process.exit(0);
6
+ await import(path.join(directory, '../dist/postinstall.js'));