Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@ifanrx/hghusky

Package Overview
Dependencies
Maintainers
3
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ifanrx/hghusky

The Mercurial version of husky

latest
npmnpm
Version
1.0.3
Version published
Maintainers
3
Created
Source

hghusky

The Mercurial version of husky.

Usage

大体参考:https://typicode.github.io/husky

安装:

pnpm add --save-dev @ifanrx/hghusky

初始化(或更新版本时使用,会覆盖更新 .hghusky/_/):

pnpm husky init

将以下 script 加入到你所在项目的根目录 package.json 中:

{
  "scripts": {
    "prepare": "husky"
  }
}

每次执行 pnpm install 就会检测是否初始化(若没有则进行初始化),并自动将 .hghusky 目录下的 hook 文件配置到 .hg/hgrc 中。

根据项目需要在 .hghusky 目录下创建 hooks 同名文件,已默认创建 pretxncommit 文件,按需开启 lint 功能。

注意:.hghusky/_/ 不需要提交到代码库(会自动添加到 .hgignore 文件)。

lint-staged

根据项目的需要,可以启用 lint-staged。其优点在于可以仅处理本次提交的文件,而不是处理所有文件。配置与原始版 lint-staged 大致相同。以下是一个示例:

package.json 中进行配置:

{
  "scripts": {
    "lint-staged": "lint-staged"
  },
  "lint-staged": {
    "**/*.{js,vue}": ["eslint --cache --fix", "pnpm dts"],
    "**/*.{css,vue}": "stylelint --cache --fix",
    "**/*.{json,d.ts,md}": "prettier --write"
  }
}

执行:

pnpm lint-staged

需要留意的是,该匹配仅限于 package.json 所在目录及其子目录,不会扩展至外层目录。 。

当执行命令以数组形式提供时,会按顺序逐个执行。

配合 turbo 食用

lint-staged 配合 turbo 食用效果更佳,首先已在项目自带的 pretxncommit 文件中默认添加以下命令,取消注释即可:

# TODO: 如需使用 lint-staged,添加以下两行
pnpm lint-staged
FORCE_COLOR=1 pnpm turbo run lint-staged

然后在根目录下的 turbo.json 添加以下:

{
  "$schema": "https://turbo.build/schema.json",
  "pipeline": {
    "lint-staged": {
      "inputs": ["**/*.{js,md,json,vue}", "!{node_modules,dist}/**"]
    }
  }
}

然后在各个分包中根据情况在 package.json 中添加上述 lint-staged 配置:

{
  "script": {
    "lint-staged": "lint-staged"
  },
  "lint-staged": {
    "**/*.{js,vue}": ["eslint --cache --fix", "pnpm dts", "hg commit"],
    "**/*.{css,vue}": "stylelint --cache --fix",
    "**/*.{json,d.ts,md}": "prettier --write"
  }
}

注意:"hg commit" 并不是必须的。

lint-staged 阶段,一些工具,例如 eslint --fix,会对代码进行格式化或修复,并且这些更改将自动被包含在当前的提交中。

然而,如果在此阶段有些命令(如执行 pnpm dts)导致了当前提交之外的文件被修改,例如在 types 目录下更新了类型声明文件,那么这就需要通过额外执行 hg commit 命令来将这些附加的修改也提交上去。

绕过执行

目前有两种方式可以绕过当前提交执行 husky

  • HUSKY=0 hg ...

  • hg commit -m "chore: [skip-lint] xxx"

FAQs

Package last updated on 15 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts