bun-git-hooks 0.2.17 → 0.2.18
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/dist/bin/cli.js +16 -2
- package/dist/index.js +28 -14
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -2085,7 +2085,7 @@ class CAC extends EventEmitter {
|
|
|
2085
2085
|
}
|
|
2086
2086
|
}
|
|
2087
2087
|
// package.json
|
|
2088
|
-
var version = "0.2.
|
|
2088
|
+
var version = "0.2.18";
|
|
2089
2089
|
|
|
2090
2090
|
// src/git-hooks.ts
|
|
2091
2091
|
import fs from "fs";
|
|
@@ -3690,6 +3690,20 @@ function isObject22(item) {
|
|
|
3690
3690
|
var log = new Logger2("bunfig", {
|
|
3691
3691
|
showTags: true
|
|
3692
3692
|
});
|
|
3693
|
+
async function config22(nameOrOptions = { defaultConfig: {} }) {
|
|
3694
|
+
if (typeof nameOrOptions === "string") {
|
|
3695
|
+
const { cwd } = await import("process");
|
|
3696
|
+
return await loadConfig32({
|
|
3697
|
+
name: nameOrOptions,
|
|
3698
|
+
cwd: cwd(),
|
|
3699
|
+
generatedDir: "./generated",
|
|
3700
|
+
configDir: "./config",
|
|
3701
|
+
defaultConfig: {},
|
|
3702
|
+
checkEnv: true
|
|
3703
|
+
});
|
|
3704
|
+
}
|
|
3705
|
+
return await loadConfig32(nameOrOptions);
|
|
3706
|
+
}
|
|
3693
3707
|
async function tryLoadConfig22(configPath, defaultConfig22) {
|
|
3694
3708
|
if (!existsSync3(configPath))
|
|
3695
3709
|
return null;
|
|
@@ -3844,7 +3858,7 @@ var config3 = {
|
|
|
3844
3858
|
var git_hooks_config_default = config3;
|
|
3845
3859
|
|
|
3846
3860
|
// src/config.ts
|
|
3847
|
-
var config4 = await
|
|
3861
|
+
var config4 = await config22({
|
|
3848
3862
|
name: "git-hooks",
|
|
3849
3863
|
cwd: process9.cwd(),
|
|
3850
3864
|
defaultConfig: git_hooks_config_default
|
package/dist/index.js
CHANGED
|
@@ -1615,6 +1615,20 @@ function isObject2(item) {
|
|
|
1615
1615
|
var log = new Logger("bunfig", {
|
|
1616
1616
|
showTags: true
|
|
1617
1617
|
});
|
|
1618
|
+
async function config2(nameOrOptions = { defaultConfig: {} }) {
|
|
1619
|
+
if (typeof nameOrOptions === "string") {
|
|
1620
|
+
const { cwd } = await import("process");
|
|
1621
|
+
return await loadConfig3({
|
|
1622
|
+
name: nameOrOptions,
|
|
1623
|
+
cwd: cwd(),
|
|
1624
|
+
generatedDir: "./generated",
|
|
1625
|
+
configDir: "./config",
|
|
1626
|
+
defaultConfig: {},
|
|
1627
|
+
checkEnv: true
|
|
1628
|
+
});
|
|
1629
|
+
}
|
|
1630
|
+
return await loadConfig3(nameOrOptions);
|
|
1631
|
+
}
|
|
1618
1632
|
async function tryLoadConfig2(configPath, defaultConfig2) {
|
|
1619
1633
|
if (!existsSync3(configPath))
|
|
1620
1634
|
return null;
|
|
@@ -1754,7 +1768,7 @@ var defaultConfigDir2 = resolve3(process8.cwd(), "config");
|
|
|
1754
1768
|
var defaultGeneratedDir2 = resolve3(process8.cwd(), "src/generated");
|
|
1755
1769
|
|
|
1756
1770
|
// git-hooks.config.ts
|
|
1757
|
-
var
|
|
1771
|
+
var config3 = {
|
|
1758
1772
|
"pre-commit": {
|
|
1759
1773
|
"staged-lint": {
|
|
1760
1774
|
"**/*.{js,ts}": [
|
|
@@ -1766,10 +1780,10 @@ var config2 = {
|
|
|
1766
1780
|
"commit-msg": "bunx gitlint .git/COMMIT_EDITMSG",
|
|
1767
1781
|
verbose: true
|
|
1768
1782
|
};
|
|
1769
|
-
var git_hooks_config_default =
|
|
1783
|
+
var git_hooks_config_default = config3;
|
|
1770
1784
|
|
|
1771
1785
|
// src/config.ts
|
|
1772
|
-
var
|
|
1786
|
+
var config5 = await config2({
|
|
1773
1787
|
name: "git-hooks",
|
|
1774
1788
|
cwd: process6.cwd(),
|
|
1775
1789
|
defaultConfig: git_hooks_config_default
|
|
@@ -2023,7 +2037,7 @@ async function loadConfig22() {
|
|
|
2023
2037
|
return defaultConfig2;
|
|
2024
2038
|
}
|
|
2025
2039
|
}
|
|
2026
|
-
var
|
|
2040
|
+
var config6 = await loadConfig22();
|
|
2027
2041
|
function isBrowserProcess2() {
|
|
2028
2042
|
if (process32.env.NODE_ENV === "test" || process32.env.BUN_ENV === "test") {
|
|
2029
2043
|
return false;
|
|
@@ -2157,7 +2171,7 @@ class Logger2 {
|
|
|
2157
2171
|
activeProgressBar = null;
|
|
2158
2172
|
constructor(name, options = {}) {
|
|
2159
2173
|
this.name = name;
|
|
2160
|
-
this.config = { ...
|
|
2174
|
+
this.config = { ...config6 };
|
|
2161
2175
|
this.options = this.normalizeOptions(options);
|
|
2162
2176
|
this.formatter = this.options.formatter || new JsonFormatter2;
|
|
2163
2177
|
this.enabled = options.enabled ?? true;
|
|
@@ -2213,7 +2227,7 @@ class Logger2 {
|
|
|
2213
2227
|
const defaultOptions = {
|
|
2214
2228
|
format: "json",
|
|
2215
2229
|
level: "info",
|
|
2216
|
-
logDirectory:
|
|
2230
|
+
logDirectory: config6.logDirectory,
|
|
2217
2231
|
rotation: undefined,
|
|
2218
2232
|
timestamp: undefined,
|
|
2219
2233
|
fingersCrossed: {},
|
|
@@ -3367,9 +3381,9 @@ function _getPackageJson(projectPath = process11.cwd()) {
|
|
|
3367
3381
|
return { packageJsonContent: JSON.parse(packageJsonDataRaw), packageJsonPath: targetPackageJson };
|
|
3368
3382
|
}
|
|
3369
3383
|
function setHooksFromConfig(projectRootPath = process11.cwd(), options) {
|
|
3370
|
-
if (!
|
|
3384
|
+
if (!config5 || Object.keys(config5).length === 0)
|
|
3371
3385
|
throw new Error("[ERROR] Config was not found! Please add `.git-hooks.config.{ts,js,mjs,cjs,json}` or `git-hooks.config.{ts,js,mjs,cjs,json}` or the `git-hooks` entry in package.json.\r\nCheck README for details");
|
|
3372
|
-
const configFile = options?.configFile || { ...
|
|
3386
|
+
const configFile = options?.configFile || { ...config5 };
|
|
3373
3387
|
_validateStagedLintConfig(configFile);
|
|
3374
3388
|
const hookKeys = Object.keys(configFile).filter((key) => !VALID_OPTIONS.includes(key));
|
|
3375
3389
|
const isValidConfig = hookKeys.every((key) => VALID_GIT_HOOKS.includes(key));
|
|
@@ -3393,7 +3407,7 @@ async function getStagedFiles(projectRoot = process11.cwd()) {
|
|
|
3393
3407
|
const { stdout } = await execAsync("git diff --cached --name-only --diff-filter=ACMR", { cwd: projectRoot });
|
|
3394
3408
|
const files = stdout.trim().split(`
|
|
3395
3409
|
`).filter(Boolean);
|
|
3396
|
-
if (
|
|
3410
|
+
if (config5.verbose && files.length > 0) {
|
|
3397
3411
|
console.info("[INFO] Staged files found:", files);
|
|
3398
3412
|
}
|
|
3399
3413
|
return files;
|
|
@@ -3530,7 +3544,7 @@ function _removeHook(hook, projectRoot = process11.cwd(), verbose = false) {
|
|
|
3530
3544
|
}
|
|
3531
3545
|
async function runStagedLint(hook) {
|
|
3532
3546
|
const projectRoot = process11.cwd();
|
|
3533
|
-
const configFile =
|
|
3547
|
+
const configFile = config5;
|
|
3534
3548
|
if (!configFile) {
|
|
3535
3549
|
console.error(`[ERROR] No configuration found`);
|
|
3536
3550
|
return false;
|
|
@@ -3550,10 +3564,10 @@ async function runStagedLint(hook) {
|
|
|
3550
3564
|
console.error(`[ERROR] No staged lint configuration found for hook ${hook}`);
|
|
3551
3565
|
return false;
|
|
3552
3566
|
}
|
|
3553
|
-
function _validateStagedLintConfig(
|
|
3567
|
+
function _validateStagedLintConfig(config4) {
|
|
3554
3568
|
for (const hook of VALID_GIT_HOOKS) {
|
|
3555
|
-
if (hook !== "pre-commit" &&
|
|
3556
|
-
const hookConfig =
|
|
3569
|
+
if (hook !== "pre-commit" && config4[hook] && typeof config4[hook] === "object") {
|
|
3570
|
+
const hookConfig = config4[hook];
|
|
3557
3571
|
if (hookConfig["stagedLint"] || hookConfig["staged-lint"]) {
|
|
3558
3572
|
throw new Error(`staged-lint is only allowed in pre-commit hook. Found in ${hook} hook.`);
|
|
3559
3573
|
}
|
|
@@ -3566,7 +3580,7 @@ export {
|
|
|
3566
3580
|
removeHooks,
|
|
3567
3581
|
getProjectRootDirectoryFromNodeModules,
|
|
3568
3582
|
getGitProjectRoot,
|
|
3569
|
-
|
|
3583
|
+
config5 as config,
|
|
3570
3584
|
checkBunGitHooksInDependencies,
|
|
3571
3585
|
VALID_OPTIONS,
|
|
3572
3586
|
VALID_GIT_HOOKS,
|
package/package.json
CHANGED