bun-git-hooks 0.2.8 → 0.2.10

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
Binary file
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;
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -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.10",
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",
@@ -44,13 +44,13 @@
44
44
  "files": ["README.md", "dist"],
45
45
  "scripts": {
46
46
  "build": "bun build.ts && bun run compile",
47
- "compile": "bun build ./bin/cli.ts --compile --minify --outfile bin/git-hooks",
47
+ "compile": "bun build ./bin/cli.ts --compile --minify --outfile dist/cli.js",
48
48
  "compile:all": "bun run compile:linux-x64 && bun run compile:linux-arm64 && bun run compile:windows-x64 && bun run compile:darwin-x64 && bun run compile:darwin-arm64",
49
- "compile:linux-x64": "bun build ./bin/cli.ts --compile --minify --target=bun-linux-x64 --outfile bin/git-hooks-linux-x64",
50
- "compile:linux-arm64": "bun build ./bin/cli.ts --compile --minify --target=bun-linux-arm64 --outfile bin/git-hooks-linux-arm64",
51
- "compile:windows-x64": "bun build ./bin/cli.ts --compile --minify --target=bun-windows-x64 --outfile bin/git-hooks-windows-x64.exe",
52
- "compile:darwin-x64": "bun build ./bin/cli.ts --compile --minify --target=bun-darwin-x64 --outfile bin/git-hooks-darwin-x64",
53
- "compile:darwin-arm64": "bun build ./bin/cli.ts --compile --minify --target=bun-darwin-arm64 --outfile bin/git-hooks-darwin-arm64",
49
+ "compile:linux-x64": "bun build ./bin/cli.ts --compile --minify --target=bun-linux-x64 --outfile dist/git-hooks-linux-x64",
50
+ "compile:linux-arm64": "bun build ./bin/cli.ts --compile --minify --target=bun-linux-arm64 --outfile dist/git-hooks-linux-arm64",
51
+ "compile:windows-x64": "bun build ./bin/cli.ts --compile --minify --target=bun-windows-x64 --outfile dist/git-hooks-windows-x64.exe",
52
+ "compile:darwin-x64": "bun build ./bin/cli.ts --compile --minify --target=bun-darwin-x64 --outfile dist/git-hooks-darwin-x64",
53
+ "compile:darwin-arm64": "bun build ./bin/cli.ts --compile --minify --target=bun-darwin-arm64 --outfile dist/git-hooks-darwin-arm64",
54
54
  "postinstall": "bun ./scripts/postinstall.ts",
55
55
  "uninstall": "bun ./scripts/uninstall.ts",
56
56
  "lint": "bunx --bun eslint .",
@@ -66,11 +66,11 @@
66
66
  "typecheck": "bun --bun tsc --noEmit",
67
67
  "zip": "bun run zip:all",
68
68
  "zip:all": "bun run zip:linux-x64 && bun run zip:linux-arm64 && bun run zip:windows-x64 && bun run zip:darwin-x64 && bun run zip:darwin-arm64",
69
- "zip:linux-x64": "zip -j bin/git-hooks-linux-x64.zip bin/git-hooks-linux-x64",
70
- "zip:linux-arm64": "zip -j bin/git-hooks-linux-arm64.zip bin/git-hooks-linux-arm64",
71
- "zip:windows-x64": "zip -j bin/git-hooks-windows-x64.zip bin/git-hooks-windows-x64.exe",
72
- "zip:darwin-x64": "zip -j bin/git-hooks-darwin-x64.zip bin/git-hooks-darwin-x64",
73
- "zip:darwin-arm64": "zip -j bin/git-hooks-darwin-arm64.zip bin/git-hooks-darwin-arm64"
69
+ "zip:linux-x64": "zip -j dist/git-hooks-linux-x64.zip dist/git-hooks-linux-x64",
70
+ "zip:linux-arm64": "zip -j dist/git-hooks-linux-arm64.zip dist/git-hooks-linux-arm64",
71
+ "zip:windows-x64": "zip -j dist/git-hooks-windows-x64.zip dist/git-hooks-windows-x64.exe",
72
+ "zip:darwin-x64": "zip -j dist/git-hooks-darwin-x64.zip dist/git-hooks-darwin-x64",
73
+ "zip:darwin-arm64": "zip -j dist/git-hooks-darwin-arm64.zip dist/git-hooks-darwin-arm64"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@iconify-json/carbon": "^1.2.8",