简体   繁体   中英

npm package not working in custom bash script during pre-commit hook

I want to run lint-staged in my custom pre-commit hook.
I have the.githooks in the root of my project. I symlink them and hooks work, they get invoked correctly. Then server folder is also at the same level. And inside server I have my node_modules and package.json pre-commit hook get invoked, but lint-staged doesn't throw any error and my script is successfully executed. But I am sure that staged file has errors, because lint-staged throws error if I directly call it in my terminal.

.githooks/pre-commit

    #!/bin/bash
    script_path=$(readlink -f "$0")
    hooks_dir=$(dirname "$script_path")
    root_dir=$(dirname "$hooks_dir")
    echo "Running pre-commit"
    cd "${root_dir}/server" && npx lint-staged

Git hooks should be under .git/hooks , not .githooks .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM