Skip to content

从 v4 迁移

¥Migrate from v4

如果你使用 npmyarn 调用 package.json 脚本,你可以简单地将命令从配置文件复制到相应的钩子:

¥If you were calling package.json scripts using npm or yarn, you can simply copy your commands from your config file to the corresponding hook:

Husky v4

json
// package.json
{
  "hooks": {
    "pre-commit": "npm test && npm run foo"
  }
}

Husky v9

shell
# .husky/pre-commit
# Note that you can now have commands on multiple lines
npm test // [!code hl]
npm run foo // [!code hl]

如果你调用本地安装的二进制文件,你现在需要通过包管理器运行它们:

¥If you were calling locally installed binaries, you need to run them via your package manager now:

js
{
  "hooks": {
    "pre-commit": "jest"
  }
}
shell
jest

HUSKY_GIT_PARAMS 环境变量现在被原生参数 $1$2 等替换。

¥HUSKY_GIT_PARAMS environment variable is replaced now by native params $1, $2, etc.

js
{
  "hooks": {
    "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
  }
}
shell
commitlint --edit $1

其他环境变量更改:

¥Other environment variables changes:

  • HUSKY_SKIP_HOOKSHUSKY 替换。

    ¥HUSKY_SKIP_HOOKS is replaced by HUSKY.

  • HUSKY_SKIP_INSTALLHUSKY 替换。

    ¥HUSKY_SKIP_INSTALL is replaced by HUSKY.

  • HUSKY_GIT_PARAMS 已被删除。相反,应该直接在脚本中使用 Git 参数(例如 $1)。

    ¥HUSKY_GIT_PARAMS is removed. Instead Git parameters should be used directly in scripts (e.g. $1).