简体   繁体   English

npm package 在预提交挂钩期间无法在自定义 bash 脚本中工作

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

I want to run lint-staged in my custom pre-commit hook.我想在我的自定义预提交挂钩中运行 lint-staged。
I have the.githooks in the root of my project.我的项目根目录中有 the.githooks。 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.在服务器内部,我调用了我的 node_modules 和 package.json 预提交挂钩,但是 lint-staged 没有抛出任何错误并且我的脚本已成功执行。 But I am sure that staged file has errors, because lint-staged throws error if I directly call it in my terminal.但我确定暂存文件有错误,因为如果我直接在终端中调用 lint-staged 会抛出错误。

.githooks/pre-commit .githooks/预提交

    #!/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 . Git 钩子应该在.git/hooks下,而不是.githooks

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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