Skip to content

Commit d6e4e73

Browse files
committed
chore: wip
1 parent 644f2e2 commit d6e4e73

File tree

6 files changed

+41
-24
lines changed

6 files changed

+41
-24
lines changed

build.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ await Bun.build({
66
outdir: './dist',
77
plugins: [dts()],
88
})
9+
10+
await Bun.build({
11+
entrypoints: ['bin/cli.ts'],
12+
target: 'bun',
13+
outdir: './dist',
14+
plugins: [dts()],
15+
})

bun.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"@vite-pwa/vitepress": "^0.5.3",
1212
"bumpp": "^10.0.3",
1313
"bun-plugin-dtsx": "^0.21.9",
14-
"bunfig": "^0.6.0",
14+
"bunfig": "^0.7.0",
1515
"changelogen": "^0.5.7",
1616
"lint-staged": "^15.4.3",
1717
"typescript": "^5.7.3",
@@ -665,7 +665,7 @@
665665

666666
"bundle-name": ["bundle-name@4.1.0", "", { "dependencies": { "run-applescript": "^7.0.0" } }, "sha512-tjwM5exMg6BGRI+kNmTntNsvdZS1X8BFYS6tnJ2hdH0kVxM6/eVZ2xy+FqStSWvYmtfFMDLIxurorHwDKfDz5Q=="],
667667

668-
"bunfig": ["bunfig@0.6.0", "", {}, "sha512-Oq1E2yRPyNdlYVYiQManFAUCfLdwOHr7mV7ut5SO9C1TeoitLVBoBvLx1ikngDVpdWY0ZS0OTb1526Rs5bF1Qw=="],
668+
"bunfig": ["bunfig@0.7.0", "", {}, "sha512-q9F/r97pSepONQOnvvtU3WZ3kt+bhZYLbQsI2JnhqQVGuv3M/rP661QuK7fCDVmaGM5BOnd1H9qCBa4l2Y1fnA=="],
669669

670670
"c12": ["c12@2.0.2", "", { "dependencies": { "chokidar": "^4.0.3", "confbox": "^0.1.8", "defu": "^6.1.4", "dotenv": "^16.4.7", "giget": "^1.2.4", "jiti": "^2.4.2", "mlly": "^1.7.4", "ohash": "^1.1.4", "pathe": "^2.0.2", "perfect-debounce": "^1.0.0", "pkg-types": "^1.3.1", "rc9": "^2.1.2" }, "peerDependencies": { "magicast": "^0.3.5" }, "optionalPeers": ["magicast"] }, "sha512-NkvlL5CHZt9kPswJYDCUYtTaMt7JOfcpsnNncfj7sWsc13x6Wz+GiTpBtqZOojFlzyTHui8+OAfR6praV6PYaQ=="],
671671

git-hooks.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { GitHooksConfig } from "./src/types";
2+
3+
const config: GitHooksConfig = {
4+
// 'pre-commit': 'bun run lint && bun run test',
5+
};
6+
7+
export default config

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"@vite-pwa/vitepress": "^0.5.3",
7474
"bumpp": "^10.0.3",
7575
"bun-plugin-dtsx": "^0.21.9",
76-
"bunfig": "^0.6.0",
76+
"bunfig": "^0.7.0",
7777
"changelogen": "^0.5.7",
7878
"lint-staged": "^15.4.3",
7979
"typescript": "^5.7.3",

src/git-hooks.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,19 @@ fi
5656
* @return {string | undefined} .git folder path or undefined if it was not found
5757
*/
5858
export function getGitProjectRoot(directory: string = process.cwd()): string | undefined {
59-
let start: string | string[] = directory
60-
61-
if (typeof start === 'string') {
62-
if (start[start.length - 1] !== path.sep) {
63-
start += path.sep
64-
}
65-
66-
start = path.normalize(start)
67-
start = start.split(path.sep)
59+
// If the directory itself ends with .git, return it normalized
60+
if (directory.endsWith('.git')) {
61+
return path.normalize(directory)
6862
}
6963

70-
if (!start.length)
71-
return undefined
64+
let start = path.normalize(directory)
7265

73-
start.pop()
66+
// Stop if we've reached the root directory
67+
if (!start || start === path.sep || start === '.') {
68+
return undefined
69+
}
7470

75-
const dir = start.join(path.sep)
76-
const fullPath = path.join(dir, '.git')
71+
const fullPath = path.join(start, '.git')
7772

7873
if (fs.existsSync(fullPath)) {
7974
if (!fs.lstatSync(fullPath).isDirectory()) {
@@ -98,7 +93,15 @@ export function getGitProjectRoot(directory: string = process.cwd()): string | u
9893
return path.normalize(fullPath)
9994
}
10095

101-
return getGitProjectRoot(start.join(path.sep))
96+
// Move up one directory
97+
const parentDir = path.dirname(start)
98+
99+
// If we're already at the root, stop
100+
if (parentDir === start) {
101+
return undefined
102+
}
103+
104+
return getGitProjectRoot(parentDir)
102105
}
103106

104107
/**

test/bun-git-hooks.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe('bun-git-hooks', () => {
4444
`var/my-project/node_modules/.bin/bun-git-hooks`,
4545
),
4646
).toBe('var/my-project')
47+
4748
expect(
4849
gitHooks.getProjectRootDirectoryFromNodeModules(
4950
`var/my-project/node_modules/.bin/bun-git-hooks`,
@@ -53,11 +54,12 @@ describe('bun-git-hooks', () => {
5354
})
5455

5556
describe('getGitProjectRoot', () => {
56-
const gitProjectRoot = path.normalize(path.join(__dirname, '.git'))
57-
const currentPath = path.normalize(path.join(__dirname))
58-
const currentFilePath = path.normalize(path.join(__filename))
57+
const gitProjectRoot = path.normalize(path.join(__dirname, '..', '.git'))
58+
const currentPath = path.normalize(path.join(__dirname, '..'))
59+
const currentFilePath = path.normalize(path.join(__filename, '..'))
5960

6061
it('works from .git directory itself', () => {
62+
console.log('gitHooks.getGitProjectRoot(gitProjectRoot)', gitHooks.getGitProjectRoot(gitProjectRoot))
6163
expect(gitHooks.getGitProjectRoot(gitProjectRoot)).toBe(gitProjectRoot)
6264
})
6365

@@ -294,9 +296,7 @@ describe('bun-git-hooks', () => {
294296
it('creates git hooks if configuration is correct from package.json', () => {
295297
createGitHooksFolder(PROJECT_WITH_CONF_IN_PACKAGE_JSON)
296298

297-
gitHooks.setHooksFromConfig(PROJECT_WITH_CONF_IN_PACKAGE_JSON, {
298-
configFile: 'git-hooks.js',
299-
})
299+
gitHooks.setHooksFromConfig(PROJECT_WITH_CONF_IN_PACKAGE_JSON)
300300
const installedHooks = getInstalledGitHooks(
301301
path.normalize(
302302
path.join(PROJECT_WITH_CONF_IN_PACKAGE_JSON, '.git', 'hooks'),

0 commit comments

Comments
 (0)