Pre-commit hook bug on NPM when using VCS tools

Hi,

 

I try to add a pre-commit hook in my project to execute my linter before committing. Here si my pre-commit file, wich is located in "physically" located in .githooks/ folder with a symlink in .git/hooks.

#!/bin/sh

pass=true
RED='\033[1;31m'
GREEN='\033[0;32m'
NC='\033[0m'

echo "Running Linters:"

# Run tslint and get the output and return code
tslint=$(npm run lint)
ret_code=$?

# If it didn't pass, announce it failed and print the output
if [ $ret_code != 0 ]; then
printf "\n${RED}tslint failed:${NC}"
echo "$tslint\n"
pass=false
else
printf "${GREEN}tslint passed.${NC}\n"
fi

# Run stylelint and get the output and return code
stylelint=$(npm run stylelint)
ret_code=$?

if [ $ret_code != 0 ]; then
printf "${RED}stylelint failed:${NC}"
echo "$stylelint\n"
pass=false
else
printf "${GREEN}stylelint passed.${NC}\n"
fi

# If there were no failures, it is good to commit
if $pass; then
exit 0
fi

exit 1

 

When I commit in command line, it works as expected, when I use the Webstorm VCS, I got this error :


If somebody know how to fix that.

Thanks in advance
Takeshi

 

 

4 comments

Looks like `npm` is not on your $PATH when running script from the IDE. What OS are you on? Can you check if the issue persist if you start the IDE from terminal?

0

I, thanks alot for the response, I'm working on a mac 10.13.5.

I tried to open Webstorm from the terminal and the pre-commit hook works, thanks.
Do you know how i can make it works even if I launch Webstorm from the icon ? 

0

on MacOSX the environment variables differ between GUI applications and within the terminal. Terminal environment is only available to applications started from terminal.
To solve this problem, WebStorm tries to load terminal environment by executing the following command on startup:

<your shell> -l -i -c '/Applications/webstorm.app/bin/printenv.py'

Seems this command can't retrieve all needed stuff in your case - thus the issue.

Some links you may find useful: http://apple.stackexchange.com/questions/106355/setting-the-system-wide-path-environment-variable-in-mavericks, http://apple.stackexchange.com/questions/51677/how-to-set-path-for-finder-launched-applications.. The problem is that the way to define system-wide environment variables on Mac changes from one version to another (even minor system updates may break your environment)

0

Please sign in to leave a comment.