1
1
#!/usr/bin/env bun
2
+
3
+ import { mkdir , symlink } from 'node:fs/promises'
4
+ import { dirname , join } from 'node:path'
2
5
import process from 'node:process'
3
6
import { checkBunGitHooksInDependencies , getProjectRootDirectoryFromNodeModules , setHooksFromConfig } from '../src/git-hooks'
4
7
5
8
/**
6
9
* Creates the pre-commit from command in config by default
7
10
*/
8
- function postinstall ( ) {
11
+ async function postinstall ( ) {
9
12
let projectDirectory
10
13
11
14
/* When script is run after install, the process.cwd() would be like <project_folder>/node_modules/simple-git-hooks
@@ -19,6 +22,22 @@ function postinstall() {
19
22
projectDirectory = process . cwd ( )
20
23
}
21
24
25
+ // Link the binary
26
+ const binDir = join ( projectDirectory , 'node_modules' , '.bin' )
27
+ await mkdir ( binDir , { recursive : true } )
28
+
29
+ const sourcePath = join ( process . cwd ( ) , 'dist' , 'bin' , 'cli.js' )
30
+ const targetPath = join ( binDir , 'bun-git-hooks' )
31
+
32
+ try {
33
+ await symlink ( sourcePath , targetPath , 'file' )
34
+ }
35
+ catch ( err ) {
36
+ if ( ( err as NodeJS . ErrnoException ) . code !== 'EEXIST' ) {
37
+ console . error ( `[ERROR] Failed to link binary: ${ err } ` )
38
+ }
39
+ }
40
+
22
41
if ( checkBunGitHooksInDependencies ( projectDirectory ) ) {
23
42
try {
24
43
setHooksFromConfig ( projectDirectory )
0 commit comments