使用 npm test && np --no-cleanup --yolo --no-publish --any-branch 发布代码时报错误

    1. ? Select semver increment or specify new version patch 0.0.10
    2. Git
    3. Bumping version using npm
    4. v0.0.10
    5. Pushing tags
    6. Command failed with exit code 1: npm version 0.0.10
    7. npm ERR! code 1
    8. npm ERR! Command failed: git commit -m 0.0.10
    9. npm ERR! nvm is not compatible with the "npm_config_prefix" environment variable: currently set to "/Users/xxx/.nvm/versions/node/v14.17.6"
    10. npm ERR! Run `unset npm_config_prefix` to unset it.
    11. npm ERR! > running pre-commit hook: lint-staged && npm run lint
    12. npm ERR! lint-staged requires at least version 12.13.0 of Node, please upgrade
    13. npm ERR!
    14. npm ERR! pre-commit hook failed (add --no-verify to bypass)
    15. npm ERR!
    16. npm ERR! A complete log of this run can be found in:
    17. npm ERR! /Users/xxx/.npm/_logs/2021-09-29T11_30_41_453Z-debug.log
    18. v0.0.10
    19. npm ERR! code ELIFECYCLE
    20. npm ERR! errno 1

    解决方案,

    执行 unset npm_config_prefix 这个没效果

    通过参考实践以下的文档,尝试了使用各个方案暂时没效果

    • 方案一:想通过修改 np 代码,在执行 npm version patch 时添加 —no-verify 参数,执行仍然报错
      • const args = [‘version’, input, ‘—no-verify’]; // 新增参数
      • pre-commit hook failed (add —no-verify to bypass)
    • 方案二:想通过添加 lint-staged 的 ignore 配置来处理,结果 ignore参数已经废弃
      • “lint-staged”: {

    “*.{js,jsx,less,md,json}”: [
    “prettier —write”
    ],
    “ignore”: [“node_modules”, “dist”, “package-lock.json”, “package.json”]
    },

    经过查询文档,lint-staged 使用 yorkie 来实现 git hooks的钩子 pre-commit,而 yorkie 是 husky 的 fork,已有三年未更新了,所以决定改为 husky 方案实现 git 的钩子

    文档 husky

    以下方法也许可以 HUSKY=0 git push # yolo!

    安装

    1. npx husky-init && npm install
    2. npm set-script prepare "husky install"
    3. // 添加 scripts "prepare": "husky install"
    4. // 添加钩子
    5. npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
    6. npx husky add .husky/pre-commit "npm test"

    参考: