I'm trying to run an npm script inside a post-merge Git hook, but the npm script isn't working. The hook is being triggered on a git pull.
Here is what my post-merge file looks like:
#!/bin/sh
/home/jt/nvm/versions/node/v18.12.0/bin/npm run build --prefix /home/jt/project/frontend
touch /home/jt/project/backend/backend/wsgi.py
The post-merge file is correctly located in the hooks directory within the .git directory:
23:44 ~/project/.git/hooks (hosting)$ tree
.
├── applypatch-msg.sample
├── commit-msg.sample
├── fsmonitor-watchman.sample
├── post-merge
├── post-update.sample
├── pre-applypatch.sample
├── pre-commit.sample
├── pre-merge-commit.sample
├── pre-push.sample
├── pre-rebase.sample
├── pre-receive.sample
├── prepare-commit-msg.sample
└── update.sample
0 directories, 13 files
23:44 ~/project/.git/hooks (hosting)$
When I run the npn run build command in a shell script, it runs perfectly.
23:38 ~/project (hosting)$ nano test.sh
23:38 ~/project (hosting)$ ls
LICENSE README.md backend frontend test.sh
23:38 ~/project (hosting)$ source test.sh
> frontend@0.0.0 build
> vite build
vite v3.2.5 building for production...
✓ 241 modules transformed.
../backend/static/assets/react.35ef61ed.svg 4.03 KiB
../backend/static/assets/map-pin-icon-default.2555d711.svg 0.22 KiB
../backend/static/assets/map-pin-icon-selected.0e940bf1.svg 0.23 KiB
../backend/static/assets/map-pin-icon-home.bc73a24c.svg 0.23 KiB
../backend/static/assets/bg_image.90202fe6.png 1671.34 KiB
../backend/static/index.html 1.00 KiB
../backend/static/assets/index.a062f1f9.css 192.35 KiB / gzip: 27.36 KiB
../backend/static/assets/index.fd1f092a.js 263.23 KiB / gzip: 87.69 KiB
../backend/static/assets/index.fd1f092a.js.map 1010.80 KiB
23:39 ~/project (hosting)$
Why is the npm run build script not working inside the git post-merge hook?