【问题标题】:Run NPM script ONLY when a JS file is staged仅在暂存 JS 文件时运行 NPM 脚本
【发布时间】:2017-04-24 09:47:37
【问题描述】:

有没有办法仅在暂存 JS 文件时运行 NPM 脚本?具体来说,在pre-commit git 钩子之后(使用Husky)。我的package.json 中有以下脚本:

"scripts": {
    ...
    "test": "jest",
    "precommit": "npm test",
    ...
},

如果有 JS 文件暂存,我希望能够只运行 jest。我怎样才能做到这一点?

【问题讨论】:

    标签: javascript node.js git npm pre-commit-hook


    【解决方案1】:

    你见过吗?

    https://github.com/okonet/lint-staged

    你可以这样配置:

    "lint-staged": { "*.js": "eslint" } 添加到package.json

    【讨论】:

    • 我已经尝试过了。不幸的是,它不适用于我想要的输出。这将运行任何 npm 脚本,但不会因输出失败而中断。它只是继续提交。
    • 更具体地说:npm run test-no-commit-on-test-fail
    猜你喜欢
    • 2016-01-03
    • 1970-01-01
    • 2023-01-27
    • 1970-01-01
    • 2021-08-25
    • 2021-11-22
    • 2017-04-30
    • 1970-01-01
    • 2015-05-15
    相关资源
    最近更新 更多