bun-git-hooks 0.2.7 → 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/{bin/cli.js → cli.js} +17 -24
- package/dist/config.d.ts +0 -1
- package/dist/git-hooks.d.ts +3 -1
- package/dist/index.js +17 -24
- package/dist/types.d.ts +4 -0
- package/package.json +7 -7
- package/dist/bin/config.d.ts +0 -4
- package/dist/bin/git-hooks.d.ts +0 -50
- package/dist/bin/index.d.ts +0 -3
- package/dist/bin/types.d.ts +0 -43
|
@@ -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,16 +787,19 @@ 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
|
-
console.log("config", process3.cwd());
|
|
800
803
|
|
|
801
804
|
// src/git-hooks.ts
|
|
802
805
|
var VALID_GIT_HOOKS = [
|
|
@@ -872,27 +875,21 @@ function getGitProjectRoot(directory = process4.cwd()) {
|
|
|
872
875
|
}
|
|
873
876
|
return getGitProjectRoot(parentDir);
|
|
874
877
|
}
|
|
875
|
-
function setHooksFromConfig(projectRootPath = process4.cwd(), options
|
|
876
|
-
if (!
|
|
878
|
+
function setHooksFromConfig(projectRootPath = process4.cwd(), options) {
|
|
879
|
+
if (!config2 || Object.keys(config2).length === 0)
|
|
877
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");
|
|
878
|
-
|
|
879
|
-
const hookKeys = Object.keys(
|
|
880
|
-
console.log("hookKeys", hookKeys);
|
|
881
|
+
const configFile = options?.configFile ? options.configFile : config2;
|
|
882
|
+
const hookKeys = Object.keys(configFile).filter((key) => key !== "preserveUnused" && key !== "verbose");
|
|
881
883
|
const isValidConfig = hookKeys.every((key) => VALID_GIT_HOOKS.includes(key));
|
|
882
|
-
console.log("isValidConfig", isValidConfig);
|
|
883
884
|
if (!isValidConfig)
|
|
884
885
|
throw new Error("[ERROR] Config was not in correct format. Please check git hooks or options name");
|
|
885
|
-
const preserveUnused = Array.isArray(
|
|
886
|
+
const preserveUnused = Array.isArray(configFile.preserveUnused) ? configFile.preserveUnused : configFile.preserveUnused ? VALID_GIT_HOOKS : [];
|
|
886
887
|
for (const hook of VALID_GIT_HOOKS) {
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
console.log("hook in config");
|
|
890
|
-
if (!config[hook])
|
|
888
|
+
if (Object.prototype.hasOwnProperty.call(configFile, hook)) {
|
|
889
|
+
if (!configFile[hook])
|
|
891
890
|
throw new Error(`[ERROR] Command for ${hook} is not set`);
|
|
892
|
-
|
|
893
|
-
_setHook(hook, config[hook], projectRootPath);
|
|
891
|
+
_setHook(hook, configFile[hook], projectRootPath);
|
|
894
892
|
} else if (!preserveUnused.includes(hook)) {
|
|
895
|
-
console.log("Remove hook", hook);
|
|
896
893
|
_removeHook(hook, projectRootPath);
|
|
897
894
|
}
|
|
898
895
|
}
|
|
@@ -906,12 +903,9 @@ function _setHook(hook, command, projectRoot = process4.cwd()) {
|
|
|
906
903
|
const hookCommand = PREPEND_SCRIPT + command;
|
|
907
904
|
const hookDirectory = path.join(gitRoot, "hooks");
|
|
908
905
|
const hookPath = path.normalize(path.join(hookDirectory, hook));
|
|
909
|
-
console.log("hook", { hookPath, hookCommand, hookDirectory });
|
|
910
906
|
if (!fs.existsSync(hookDirectory)) {
|
|
911
|
-
console.log("hook folder not exists");
|
|
912
907
|
fs.mkdirSync(hookDirectory, { recursive: true });
|
|
913
908
|
}
|
|
914
|
-
console.log("Create/Write hook");
|
|
915
909
|
fs.writeFileSync(hookPath, hookCommand, { mode: 493 });
|
|
916
910
|
}
|
|
917
911
|
function removeHooks(projectRoot = process4.cwd(), verbose = false) {
|
|
@@ -940,7 +934,6 @@ cli.command("[configPath]", "Install git hooks, optionally from specified config
|
|
|
940
934
|
console.log("[DEBUG] Config path:", configPath || "using default");
|
|
941
935
|
console.log("[DEBUG] Working directory:", process5.cwd());
|
|
942
936
|
}
|
|
943
|
-
console.log("setHooksFromConfig", { configFile: configPath });
|
|
944
937
|
setHooksFromConfig(process5.cwd(), { configFile: configPath });
|
|
945
938
|
console.log("[INFO] Successfully set all git hooks");
|
|
946
939
|
} catch (err) {
|
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,16 +519,19 @@ 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
|
-
console.log("config", j.cwd());
|
|
532
535
|
// src/git-hooks.ts
|
|
533
536
|
var { default: fs} = (() => ({}));
|
|
534
537
|
init_process();
|
|
@@ -648,27 +651,21 @@ function _getPackageJson(projectPath = j.cwd()) {
|
|
|
648
651
|
const packageJsonDataRaw = fs.readFileSync(targetPackageJson, { encoding: "utf-8" });
|
|
649
652
|
return { packageJsonContent: JSON.parse(packageJsonDataRaw), packageJsonPath: targetPackageJson };
|
|
650
653
|
}
|
|
651
|
-
function setHooksFromConfig(projectRootPath = j.cwd(), options
|
|
652
|
-
if (!
|
|
654
|
+
function setHooksFromConfig(projectRootPath = j.cwd(), options) {
|
|
655
|
+
if (!config2 || Object.keys(config2).length === 0)
|
|
653
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");
|
|
654
|
-
|
|
655
|
-
const hookKeys = Object.keys(
|
|
656
|
-
console.log("hookKeys", hookKeys);
|
|
657
|
+
const configFile = options?.configFile ? options.configFile : config2;
|
|
658
|
+
const hookKeys = Object.keys(configFile).filter((key) => key !== "preserveUnused" && key !== "verbose");
|
|
657
659
|
const isValidConfig = hookKeys.every((key) => VALID_GIT_HOOKS.includes(key));
|
|
658
|
-
console.log("isValidConfig", isValidConfig);
|
|
659
660
|
if (!isValidConfig)
|
|
660
661
|
throw new Error("[ERROR] Config was not in correct format. Please check git hooks or options name");
|
|
661
|
-
const preserveUnused = Array.isArray(
|
|
662
|
+
const preserveUnused = Array.isArray(configFile.preserveUnused) ? configFile.preserveUnused : configFile.preserveUnused ? VALID_GIT_HOOKS : [];
|
|
662
663
|
for (const hook of VALID_GIT_HOOKS) {
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
console.log("hook in config");
|
|
666
|
-
if (!config[hook])
|
|
664
|
+
if (Object.prototype.hasOwnProperty.call(configFile, hook)) {
|
|
665
|
+
if (!configFile[hook])
|
|
667
666
|
throw new Error(`[ERROR] Command for ${hook} is not set`);
|
|
668
|
-
|
|
669
|
-
_setHook(hook, config[hook], projectRootPath);
|
|
667
|
+
_setHook(hook, configFile[hook], projectRootPath);
|
|
670
668
|
} else if (!preserveUnused.includes(hook)) {
|
|
671
|
-
console.log("Remove hook", hook);
|
|
672
669
|
_removeHook(hook, projectRootPath);
|
|
673
670
|
}
|
|
674
671
|
}
|
|
@@ -682,12 +679,9 @@ function _setHook(hook, command, projectRoot = j.cwd()) {
|
|
|
682
679
|
const hookCommand = PREPEND_SCRIPT + command;
|
|
683
680
|
const hookDirectory = q2.join(gitRoot, "hooks");
|
|
684
681
|
const hookPath = q2.normalize(q2.join(hookDirectory, hook));
|
|
685
|
-
console.log("hook", { hookPath, hookCommand, hookDirectory });
|
|
686
682
|
if (!fs.existsSync(hookDirectory)) {
|
|
687
|
-
console.log("hook folder not exists");
|
|
688
683
|
fs.mkdirSync(hookDirectory, { recursive: true });
|
|
689
684
|
}
|
|
690
|
-
console.log("Create/Write hook");
|
|
691
685
|
fs.writeFileSync(hookPath, hookCommand, { mode: 493 });
|
|
692
686
|
}
|
|
693
687
|
function removeHooks(projectRoot = j.cwd(), verbose = false) {
|
|
@@ -707,8 +701,7 @@ export {
|
|
|
707
701
|
removeHooks,
|
|
708
702
|
getProjectRootDirectoryFromNodeModules,
|
|
709
703
|
getGitProjectRoot,
|
|
710
|
-
|
|
711
|
-
config,
|
|
704
|
+
config2 as config,
|
|
712
705
|
checkBunGitHooksInDependencies,
|
|
713
706
|
VALID_OPTIONS,
|
|
714
707
|
VALID_GIT_HOOKS,
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bun-git-hooks",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.9",
|
|
5
5
|
"description": "A modern, zero dependency tool for managing git hooks in Bun projects.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"module": "./dist/index.js",
|
|
39
39
|
"types": "./dist/index.d.ts",
|
|
40
40
|
"bin": {
|
|
41
|
-
"git-hooks": "./dist/
|
|
42
|
-
"bun-git-hooks": "./dist/
|
|
41
|
+
"git-hooks": "./dist/cli.js",
|
|
42
|
+
"bun-git-hooks": "./dist/cli.js"
|
|
43
43
|
},
|
|
44
44
|
"files": ["README.md", "dist"],
|
|
45
45
|
"scripts": {
|
|
@@ -74,10 +74,10 @@
|
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@iconify-json/carbon": "^1.2.8",
|
|
77
|
-
"@shikijs/vitepress-twoslash": "^3.2.
|
|
77
|
+
"@shikijs/vitepress-twoslash": "^3.2.2",
|
|
78
78
|
"@stacksjs/eslint-config": "^4.10.2-beta.3",
|
|
79
|
-
"@types/bun": "^1.2.
|
|
80
|
-
"@types/node": "^22.
|
|
79
|
+
"@types/bun": "^1.2.9",
|
|
80
|
+
"@types/node": "^22.14.0",
|
|
81
81
|
"@vite-pwa/vitepress": "^1.0.0",
|
|
82
82
|
"bumpp": "^10.1.0",
|
|
83
83
|
"bun-plugin-dtsx": "^0.21.9",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"cac": "^6.7.14",
|
|
86
86
|
"changelogen": "^0.6.1",
|
|
87
87
|
"lint-staged": "^15.5.0",
|
|
88
|
-
"typescript": "^5.8.
|
|
88
|
+
"typescript": "^5.8.3",
|
|
89
89
|
"unocss": "^66.0.0",
|
|
90
90
|
"unplugin-icons": "^22.1.0",
|
|
91
91
|
"unplugin-vue-components": "^28.4.1",
|
package/dist/bin/config.d.ts
DELETED
package/dist/bin/git-hooks.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
export declare const VALID_GIT_HOOKS: Array<
|
|
2
|
-
'applypatch-msg' |
|
|
3
|
-
'pre-applypatch' |
|
|
4
|
-
'post-applypatch' |
|
|
5
|
-
'pre-commit' |
|
|
6
|
-
'pre-merge-commit' |
|
|
7
|
-
'prepare-commit-msg' |
|
|
8
|
-
'commit-msg' |
|
|
9
|
-
'post-commit' |
|
|
10
|
-
'pre-rebase' |
|
|
11
|
-
'post-checkout' |
|
|
12
|
-
'post-merge' |
|
|
13
|
-
'pre-push' |
|
|
14
|
-
'pre-receive' |
|
|
15
|
-
'update' |
|
|
16
|
-
'proc-receive' |
|
|
17
|
-
'post-receive' |
|
|
18
|
-
'post-update' |
|
|
19
|
-
'reference-transaction' |
|
|
20
|
-
'push-to-checkout' |
|
|
21
|
-
'pre-auto-gc' |
|
|
22
|
-
'post-rewrite' |
|
|
23
|
-
'sendemail-validate' |
|
|
24
|
-
'fsmonitor-watchman' |
|
|
25
|
-
'p4-changelist' |
|
|
26
|
-
'p4-prepare-changelist' |
|
|
27
|
-
'p4-post-changelist' |
|
|
28
|
-
'p4-pre-submit' |
|
|
29
|
-
'post-index-change'
|
|
30
|
-
>;
|
|
31
|
-
export declare const VALID_OPTIONS: Array<'preserveUnused'>;
|
|
32
|
-
export declare const PREPEND_SCRIPT: unknown;
|
|
33
|
-
export declare function getGitProjectRoot(directory: string): string | undefined;
|
|
34
|
-
export declare function checkBunGitHooksInDependencies(projectRootPath: string): boolean;
|
|
35
|
-
declare function _getPackageJson(projectPath): void;
|
|
36
|
-
export declare function setHooksFromConfig(projectRootPath: string, options?: { configFile?: , string }): void;
|
|
37
|
-
declare function _setHook(hook: string, command: string, projectRoot: string): void;
|
|
38
|
-
export declare function removeHooks(projectRoot: string, verbose): void;
|
|
39
|
-
declare function _removeHook(hook: string, projectRoot, verbose): void;
|
|
40
|
-
declare function _validateHooks(config: Record<string, string>): void;
|
|
41
|
-
declare const gitHooks: {
|
|
42
|
-
PREPEND_SCRIPT: typeof PREPEND_SCRIPT
|
|
43
|
-
setHooksFromConfig: typeof setHooksFromConfig
|
|
44
|
-
removeHooks: typeof removeHooks
|
|
45
|
-
checkBunGitHooksInDependencies: typeof checkBunGitHooksInDependencies
|
|
46
|
-
getProjectRootDirectoryFromNodeModules: typeof getProjectRootDirectoryFromNodeModules
|
|
47
|
-
getGitProjectRoot: typeof getGitProjectRoot
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export default gitHooks;
|
package/dist/bin/index.d.ts
DELETED
package/dist/bin/types.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { Buffer } from 'node:buffer';
|
|
2
|
-
|
|
3
|
-
export declare interface RawImageData<T> {
|
|
4
|
-
width: number
|
|
5
|
-
height: number
|
|
6
|
-
data: T
|
|
7
|
-
}
|
|
8
|
-
export declare interface BufferRet {
|
|
9
|
-
data: Buffer | Uint8ClampedArray
|
|
10
|
-
width: number
|
|
11
|
-
height: number
|
|
12
|
-
exifBuffer?: ArrayBuffer
|
|
13
|
-
comments?: string[]
|
|
14
|
-
}
|
|
15
|
-
export declare type UintArrRet = ImageData & {
|
|
16
|
-
exifBuffer?: ArrayBuffer
|
|
17
|
-
comments?: string[]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface ImageData {
|
|
21
|
-
width: number
|
|
22
|
-
height: number
|
|
23
|
-
data: Uint8ClampedArray | Buffer
|
|
24
|
-
colorSpace?: 'srgb'
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type BufferLike = Buffer | Uint8Array | ArrayLike<number> | Iterable<number> | ArrayBuffer
|
|
28
|
-
|
|
29
|
-
export interface DecoderOptions {
|
|
30
|
-
useTArray: boolean
|
|
31
|
-
colorTransform?: boolean
|
|
32
|
-
formatAsRGBA?: boolean
|
|
33
|
-
tolerantDecoding?: boolean
|
|
34
|
-
maxResolutionInMP?: number
|
|
35
|
-
maxMemoryUsageInMB?: number
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export type GitHooksConfig = {
|
|
39
|
-
[K in typeof VALID_GIT_HOOKS[number]]?: string
|
|
40
|
-
} & {
|
|
41
|
-
preserveUnused?: boolean | typeof VALID_GIT_HOOKS[number][]
|
|
42
|
-
verbose?: boolean
|
|
43
|
-
}
|