bun-git-hooks 0.2.8 → 0.2.9
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/cli.js +17 -12
- package/dist/config.d.ts +0 -1
- package/dist/git-hooks.d.ts +3 -1
- package/dist/index.js +17 -13
- package/dist/types.d.ts +4 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -604,7 +604,7 @@ class CAC extends EventEmitter {
|
|
|
604
604
|
}
|
|
605
605
|
}
|
|
606
606
|
// package.json
|
|
607
|
-
var version = "0.2.
|
|
607
|
+
var version = "0.2.9";
|
|
608
608
|
|
|
609
609
|
// src/git-hooks.ts
|
|
610
610
|
import fs from "fs";
|
|
@@ -787,14 +787,18 @@ async function loadConfig({
|
|
|
787
787
|
var defaultConfigDir = resolve(process2.cwd(), "config");
|
|
788
788
|
var defaultGeneratedDir = resolve(process2.cwd(), "src/generated");
|
|
789
789
|
|
|
790
|
-
//
|
|
791
|
-
var
|
|
790
|
+
// git-hooks.config.ts
|
|
791
|
+
var config = {
|
|
792
|
+
"pre-commit": "bun run lint && bun run test",
|
|
792
793
|
verbose: true
|
|
793
794
|
};
|
|
794
|
-
var
|
|
795
|
+
var git_hooks_config_default = config;
|
|
796
|
+
|
|
797
|
+
// src/config.ts
|
|
798
|
+
var config2 = await loadConfig({
|
|
795
799
|
name: "git-hooks",
|
|
796
800
|
cwd: process3.cwd(),
|
|
797
|
-
defaultConfig
|
|
801
|
+
defaultConfig: git_hooks_config_default
|
|
798
802
|
});
|
|
799
803
|
|
|
800
804
|
// src/git-hooks.ts
|
|
@@ -871,19 +875,20 @@ function getGitProjectRoot(directory = process4.cwd()) {
|
|
|
871
875
|
}
|
|
872
876
|
return getGitProjectRoot(parentDir);
|
|
873
877
|
}
|
|
874
|
-
function setHooksFromConfig(projectRootPath = process4.cwd(), options
|
|
875
|
-
if (!
|
|
878
|
+
function setHooksFromConfig(projectRootPath = process4.cwd(), options) {
|
|
879
|
+
if (!config2 || Object.keys(config2).length === 0)
|
|
876
880
|
throw new Error("[ERROR] Config was not found! Please add `.git-hooks.config.{ts,js,mjs,cjs,mts,cts,json}` or `git-hooks.config.{ts,js,mjs,cjs,mts,cts,json}` or the `git-hooks` entry in package.json.\r\nCheck README for details");
|
|
877
|
-
const
|
|
881
|
+
const configFile = options?.configFile ? options.configFile : config2;
|
|
882
|
+
const hookKeys = Object.keys(configFile).filter((key) => key !== "preserveUnused" && key !== "verbose");
|
|
878
883
|
const isValidConfig = hookKeys.every((key) => VALID_GIT_HOOKS.includes(key));
|
|
879
884
|
if (!isValidConfig)
|
|
880
885
|
throw new Error("[ERROR] Config was not in correct format. Please check git hooks or options name");
|
|
881
|
-
const preserveUnused = Array.isArray(
|
|
886
|
+
const preserveUnused = Array.isArray(configFile.preserveUnused) ? configFile.preserveUnused : configFile.preserveUnused ? VALID_GIT_HOOKS : [];
|
|
882
887
|
for (const hook of VALID_GIT_HOOKS) {
|
|
883
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
884
|
-
if (!
|
|
888
|
+
if (Object.prototype.hasOwnProperty.call(configFile, hook)) {
|
|
889
|
+
if (!configFile[hook])
|
|
885
890
|
throw new Error(`[ERROR] Command for ${hook} is not set`);
|
|
886
|
-
_setHook(hook,
|
|
891
|
+
_setHook(hook, configFile[hook], projectRootPath);
|
|
887
892
|
} else if (!preserveUnused.includes(hook)) {
|
|
888
893
|
_removeHook(hook, projectRootPath);
|
|
889
894
|
}
|
package/dist/config.d.ts
CHANGED
package/dist/git-hooks.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { SetHooksFromConfigOptions } from './types';
|
|
2
|
+
|
|
1
3
|
export declare const VALID_GIT_HOOKS: Array<
|
|
2
4
|
'applypatch-msg' |
|
|
3
5
|
'pre-applypatch' |
|
|
@@ -33,7 +35,7 @@ export declare const PREPEND_SCRIPT: unknown;
|
|
|
33
35
|
export declare function getGitProjectRoot(directory: string): string | undefined;
|
|
34
36
|
export declare function checkBunGitHooksInDependencies(projectRootPath: string): boolean;
|
|
35
37
|
declare function _getPackageJson(projectPath): void;
|
|
36
|
-
export declare function setHooksFromConfig(projectRootPath: string, options?:
|
|
38
|
+
export declare function setHooksFromConfig(projectRootPath: string, options?: SetHooksFromConfigOptions): void;
|
|
37
39
|
declare function _setHook(hook: string, command: string, projectRoot: string): void;
|
|
38
40
|
export declare function removeHooks(projectRoot: string, verbose): void;
|
|
39
41
|
declare function _removeHook(hook: string, projectRoot, verbose): void;
|
package/dist/index.js
CHANGED
|
@@ -519,14 +519,18 @@ async function loadConfig({
|
|
|
519
519
|
var defaultConfigDir = B(j.cwd(), "config");
|
|
520
520
|
var defaultGeneratedDir = B(j.cwd(), "src/generated");
|
|
521
521
|
|
|
522
|
-
//
|
|
523
|
-
var
|
|
522
|
+
// git-hooks.config.ts
|
|
523
|
+
var config = {
|
|
524
|
+
"pre-commit": "bun run lint && bun run test",
|
|
524
525
|
verbose: true
|
|
525
526
|
};
|
|
526
|
-
var
|
|
527
|
+
var git_hooks_config_default = config;
|
|
528
|
+
|
|
529
|
+
// src/config.ts
|
|
530
|
+
var config2 = await loadConfig({
|
|
527
531
|
name: "git-hooks",
|
|
528
532
|
cwd: j.cwd(),
|
|
529
|
-
defaultConfig
|
|
533
|
+
defaultConfig: git_hooks_config_default
|
|
530
534
|
});
|
|
531
535
|
// src/git-hooks.ts
|
|
532
536
|
var { default: fs} = (() => ({}));
|
|
@@ -647,19 +651,20 @@ function _getPackageJson(projectPath = j.cwd()) {
|
|
|
647
651
|
const packageJsonDataRaw = fs.readFileSync(targetPackageJson, { encoding: "utf-8" });
|
|
648
652
|
return { packageJsonContent: JSON.parse(packageJsonDataRaw), packageJsonPath: targetPackageJson };
|
|
649
653
|
}
|
|
650
|
-
function setHooksFromConfig(projectRootPath = j.cwd(), options
|
|
651
|
-
if (!
|
|
654
|
+
function setHooksFromConfig(projectRootPath = j.cwd(), options) {
|
|
655
|
+
if (!config2 || Object.keys(config2).length === 0)
|
|
652
656
|
throw new Error("[ERROR] Config was not found! Please add `.git-hooks.config.{ts,js,mjs,cjs,mts,cts,json}` or `git-hooks.config.{ts,js,mjs,cjs,mts,cts,json}` or the `git-hooks` entry in package.json.\r\nCheck README for details");
|
|
653
|
-
const
|
|
657
|
+
const configFile = options?.configFile ? options.configFile : config2;
|
|
658
|
+
const hookKeys = Object.keys(configFile).filter((key) => key !== "preserveUnused" && key !== "verbose");
|
|
654
659
|
const isValidConfig = hookKeys.every((key) => VALID_GIT_HOOKS.includes(key));
|
|
655
660
|
if (!isValidConfig)
|
|
656
661
|
throw new Error("[ERROR] Config was not in correct format. Please check git hooks or options name");
|
|
657
|
-
const preserveUnused = Array.isArray(
|
|
662
|
+
const preserveUnused = Array.isArray(configFile.preserveUnused) ? configFile.preserveUnused : configFile.preserveUnused ? VALID_GIT_HOOKS : [];
|
|
658
663
|
for (const hook of VALID_GIT_HOOKS) {
|
|
659
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
660
|
-
if (!
|
|
664
|
+
if (Object.prototype.hasOwnProperty.call(configFile, hook)) {
|
|
665
|
+
if (!configFile[hook])
|
|
661
666
|
throw new Error(`[ERROR] Command for ${hook} is not set`);
|
|
662
|
-
_setHook(hook,
|
|
667
|
+
_setHook(hook, configFile[hook], projectRootPath);
|
|
663
668
|
} else if (!preserveUnused.includes(hook)) {
|
|
664
669
|
_removeHook(hook, projectRootPath);
|
|
665
670
|
}
|
|
@@ -696,8 +701,7 @@ export {
|
|
|
696
701
|
removeHooks,
|
|
697
702
|
getProjectRootDirectoryFromNodeModules,
|
|
698
703
|
getGitProjectRoot,
|
|
699
|
-
|
|
700
|
-
config,
|
|
704
|
+
config2 as config,
|
|
701
705
|
checkBunGitHooksInDependencies,
|
|
702
706
|
VALID_OPTIONS,
|
|
703
707
|
VALID_GIT_HOOKS,
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED