Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm: Not working with bun without node #688

Open
cethien opened this issue Apr 1, 2024 · 4 comments
Open

npm: Not working with bun without node #688

cethien opened this issue Apr 1, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@cethien
Copy link

cethien commented Apr 1, 2024

🔧 Summary

seems like the tool doesn't work without node. i have only bun for js on my system.
after lefthook install, every hooked git actions results in /usr/bin/env: ‘node’: No such file or directory

Lefthook version

1.6.7 599459e

Steps to reproduce

curl -fsSL https://bun.sh/install | bash
cd <repo>
bun add -D lefthook
<define any lefthook action, eg. commitlint>
lefthook install
git add . && git commit -m "hello"

Expected results

commitlint error

Actual results

/usr/bin/env: ‘node’: No such file or directory

Logs / Screenshots

+ '[' '' = 0 ']'
+ call_lefthook run prepare-commit-msg .git/COMMIT_EDITMSG message
++ git rev-parse --show-toplevel
+ dir=<userprofile>/source/posh-nv
++ uname
++ tr '[:upper:]' '[:lower:]'
+ osArch=mingw64_nt-10.0-22631
++ uname -m
++ sed s/aarch64/arm64/
+ cpuArch=x86_64
+ test -n ''
+ lefthook.exe -h
+ lefthook.bat -h
+ test -f <userprofile>/source/posh-nv/node_modules/lefthook/bin/index.js
+ <userprofile>source/posh-nv/node_modules/lefthook/bin/index.js run prepare-commit-msg .git/COMMIT_EDITMSG message     
/usr/bin/env: ‘node’: No such file or directory
@cethien cethien added the bug Something isn't working label Apr 1, 2024
@mrexox
Copy link
Member

mrexox commented Apr 2, 2024

Hey! Thank you for creating an issue. Do you have an idea of how an executable script could be run with either nodejs or bun? I can think of a statically built executable (probably with bun) but I have concerns. It would be great to know if there's a common solution for such cases. I will investigate

@cethien
Copy link
Author

cethien commented Apr 2, 2024

bun is intended as a node replacement, so just calling a script.js file should work fine.

It would be great to know if there's a common solution for such cases. I will investigate

i will check out some stuff and give a comment

@dalisoft
Copy link

@mrexox @cethien #705 maybe fixes this case as removes require of Node.js and #!/usr/bin/env node

@Blaquewithaq
Copy link

Blaquewithaq commented Apr 22, 2024

For those of you, that want to utilize this package with bun now, Ive figured out a quick patch solution until bun support has been officially added.

Add these to your package.json file and you'll be good to go.

"prepare:lefthook": "lefthook install && bun -e \"const fs=require('node:fs'); fs.writeFileSync('node_modules/lefthook/bin/index.js', fs.readFileSync('node_modules/lefthook/bin/index.js', 'utf8').replace(/^#!\\/usr\\/bin\\/env\\s+node/gm, '#!/usr/bin/env bun'))\"",
"postinstall": "bun prepare:lefthook"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants