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 CHANGED
@@ -604,7 +604,7 @@ class CAC extends EventEmitter {
604
604
  }
605
605
  }
606
606
  // package.json
607
- var version = "0.2.8";
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
- // src/config.ts
791
- var defaultConfig = {
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 config = await loadConfig({
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 (!config || Object.keys(config).length === 0)
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 hookKeys = Object.keys(config).filter((key) => key !== "preserveUnused" && key !== "verbose");
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(config.preserveUnused) ? config.preserveUnused : config.preserveUnused ? VALID_GIT_HOOKS : [];
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(config, hook)) {
884
- if (!config[hook])
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, config[hook], projectRootPath);
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
@@ -1,4 +1,3 @@
1
1
  import type { GitHooksConfig } from './types';
2
2
 
3
- export declare const defaultConfig: GitHooksConfig;
4
3
  export declare const config: GitHooksConfig;
@@ -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?: { configFile?: , string }): void;
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
- // src/config.ts
523
- var defaultConfig = {
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 config = await loadConfig({
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 (!config || Object.keys(config).length === 0)
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 hookKeys = Object.keys(config).filter((key) => key !== "preserveUnused" && key !== "verbose");
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(config.preserveUnused) ? config.preserveUnused : config.preserveUnused ? VALID_GIT_HOOKS : [];
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(config, hook)) {
660
- if (!config[hook])
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, config[hook], projectRootPath);
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
- defaultConfig,
700
- config,
704
+ config2 as config,
701
705
  checkBunGitHooksInDependencies,
702
706
  VALID_OPTIONS,
703
707
  VALID_GIT_HOOKS,
package/dist/types.d.ts CHANGED
@@ -40,4 +40,8 @@ export type GitHooksConfig = {
40
40
  } & {
41
41
  preserveUnused?: boolean | typeof VALID_GIT_HOOKS[number][]
42
42
  verbose?: boolean
43
+ }
44
+
45
+ export interface SetHooksFromConfigOptions {
46
+ configFile?: GitHooksConfig
43
47
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-git-hooks",
3
3
  "type": "module",
4
- "version": "0.2.8",
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",