Skip to content

Commit f4c4807

Browse files
committed
chore: release v0.2.9
1 parent 849264f commit f4c4807

File tree

6 files changed

+233
-229
lines changed

6 files changed

+233
-229
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

2+
## v0.2.8...v0.2.8
3+
4+
[compare changes](https://github.com/stacksjs/bun-git-hooks/compare/v0.2.8...v0.2.8)
5+
26
## v0.2.7...main
37

48
[compare changes](https://github.com/stacksjs/bun-git-hooks/compare/v0.2.7...main)

bun.lock

Lines changed: 215 additions & 215 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bun-git-hooks",
33
"type": "module",
4-
"version": "0.2.8",
4+
"version": "0.2.9",
55
"description": "A modern, zero dependency tool for managing git hooks in Bun projects.",
66
"author": "Chris Breuer <[email protected]>",
77
"license": "MIT",

src/config.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import type { GitHooksConfig } from './types'
22
import process from 'node:process'
33
import { loadConfig } from 'bunfig'
4+
import defaultConfig from '../git-hooks.config.ts'
45

5-
export const defaultConfig: GitHooksConfig = {
6-
// 'pre-commit': 'echo "pre-commit"',
7-
verbose: true,
8-
}
9-
10-
// @ts-expect-error dtsx issue
116
// eslint-disable-next-line antfu/no-top-level-await
127
export const config: GitHooksConfig = await loadConfig({
138
name: 'git-hooks',

src/git-hooks.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'node:fs'
22
import path from 'node:path'
33
import process from 'node:process'
44
import { config } from './config'
5-
5+
import type { SetHooksFromConfigOptions } from './types'
66
export const VALID_GIT_HOOKS = [
77
'applypatch-msg',
88
'pre-applypatch',
@@ -190,25 +190,26 @@ function _getPackageJson(projectPath = process.cwd()) {
190190
* Parses the config and sets git hooks
191191
* @param {string} projectRootPath
192192
*/
193-
export function setHooksFromConfig(projectRootPath: string = process.cwd(), options?: { configFile?: string } = {}): void {
193+
export function setHooksFromConfig(projectRootPath: string = process.cwd(), options?: SetHooksFromConfigOptions): void {
194194
if (!config || Object.keys(config).length === 0)
195195
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')
196196

197+
const configFile = options?.configFile ? options.configFile : config
197198
// Only validate hook names that aren't options
198-
const hookKeys = Object.keys(config).filter(key => key !== 'preserveUnused' && key !== 'verbose')
199+
const hookKeys = Object.keys(configFile).filter(key => key !== 'preserveUnused' && key !== 'verbose')
199200
const isValidConfig = hookKeys.every(key => VALID_GIT_HOOKS.includes(key as typeof VALID_GIT_HOOKS[number]))
200201

201202
if (!isValidConfig)
202203
throw new Error('[ERROR] Config was not in correct format. Please check git hooks or options name')
203204

204-
const preserveUnused = Array.isArray(config.preserveUnused) ? config.preserveUnused : config.preserveUnused ? VALID_GIT_HOOKS : []
205+
const preserveUnused = Array.isArray(configFile.preserveUnused) ? configFile.preserveUnused : configFile.preserveUnused ? VALID_GIT_HOOKS : []
205206

206207
for (const hook of VALID_GIT_HOOKS) {
207-
if (Object.prototype.hasOwnProperty.call(config, hook)) {
208-
if (!config[hook])
208+
if (Object.prototype.hasOwnProperty.call(configFile, hook)) {
209+
if (!configFile[hook])
209210
throw new Error(`[ERROR] Command for ${hook} is not set`)
210211

211-
_setHook(hook, config[hook], projectRootPath)
212+
_setHook(hook, configFile[hook], projectRootPath)
212213
}
213214
else if (!preserveUnused.includes(hook)) {
214215
_removeHook(hook, projectRootPath)

src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ export type GitHooksConfig = {
4444
preserveUnused?: boolean | typeof VALID_GIT_HOOKS[number][]
4545
verbose?: boolean
4646
}
47+
48+
export interface SetHooksFromConfigOptions {
49+
configFile?: GitHooksConfig
50+
}

0 commit comments

Comments
 (0)