11#!/usr/bin/env bun
2+
3+ import { mkdir , symlink } from 'node:fs/promises'
4+ import { dirname , join } from 'node:path'
25import process from 'node:process'
36import { checkBunGitHooksInDependencies , getProjectRootDirectoryFromNodeModules , setHooksFromConfig } from '../src/git-hooks'
47
58/**
69 * Creates the pre-commit from command in config by default
710 */
8- function postinstall ( ) {
11+ async function postinstall ( ) {
912 let projectDirectory
1013
1114 /* 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() {
1922 projectDirectory = process . cwd ( )
2023 }
2124
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+
2241 if ( checkBunGitHooksInDependencies ( projectDirectory ) ) {
2342 try {
2443 setHooksFromConfig ( projectDirectory )
0 commit comments