# @arkweid/lefthook 中文文档

规范地址：https://npmcn.com/package/%40arkweid/lefthook/

版本：0\.7\.7
npm 元数据更新时间：2026-09-30T10:17:46.460Z
中文译文更新时间：2026-11-06T19:42:11.183Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40arkweid/lefthook
原文对照：https://npmcn.com/package/%40arkweid/lefthook/?lang=original
项目主页：https://github.com/evilmartians/lefthook#readme
源码仓库：https://github.com/evilmartians/lefthook

弃用说明：@arkweid/lefthook has been renamed to @evilmartians/lefthook, please upgrade to it\. You also can use @evilmartians/lefthook-installer

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：40.2 MB，12 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：0 个
- 首次发布：2019-04-17T15:56:49.581Z
- 最新版本发布：2021-10-02T17:41:07.577Z
- 近 30 天下载量：93825（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：31（近 12 个月 0 个）

## 中文简介

简单的钩子管理器

## 安装

```sh
npm install @arkweid/lefthook
```

也可以使用：`pnpm add @arkweid/lefthook`、`yarn add @arkweid/lefthook`、`bun add @arkweid/lefthook`

## README

![Build Status](https://api.travis-ci.org/evilmartians/lefthook.svg?branch=master)

# 左脚

> 最快的多块 外面的金钩经理

![](https://npmcn.com/package/%40arkweid/lefthook/logo_sign.svg "Lefthook logo")

快速而强大的Git悬钩管理器用于Node.js,Ruby或任何其他类型的项目.

-   **快点.** 它用"去"写,可以并行运行命令.
-   **权相相相.** 配置中的几行可以只检查已更改的文件 `pre-push` 钩.
-   **很简单.** 它是单一的无依赖二进制,可以在任何环境中工作.

📖 [阅读介绍文章](https://evilmartians.com/chronicles/lefthook-knock-your-teams-code-back-into-shape?utm_source=lefthook)

```yml
# On `git push` lefthook will run spelling and links check for all of the changed files
pre-push:
  parallel: true
  commands:
    spelling:
      files: git diff --name-only HEAD @{push}
      glob: "*.md"
      run: npx yaspeller {files}
    check-links:
      files: git diff --name-only HEAD @{push}
      glob: "*.md"
      run: npx markdown-link-check {files}
```

[![Sponsored by Evil Martians](https://evilmartians.com/badges/sponsored-by-evil-martians.svg)](https://evilmartians.com/?utm_source=lefthook)

## 使用量

选择您的环境 :

-   **[节点.js](https://npmcn.com/package/%40arkweid/lefthook/docs/node.md)**
-   **[鲁比](https://npmcn.com/package/%40arkweid/lefthook/docs/ruby.md)**
-   [其他环境](https://npmcn.com/package/%40arkweid/lefthook/docs/other.md)

然后,你可以找到所有左撇子的特性 [完整向导](https://npmcn.com/package/%40arkweid/lefthook/docs/full_guide.md) 并探索 [维基百科](https://github.com/evilmartians/lefthook/wiki)。 。 。 .

* * *

## 为什么是左撇子

-   ### **并行执行**
    

若欲更快相会. [示例](https://npmcn.com/package/%40arkweid/lefthook/docs/full_guide.md#parallel-execution)

```yml
pre-push:
  parallel: true
```

-   ### **文件的灵活列表**
    

如果你想要自己的名单. [自定义](https://npmcn.com/package/%40arkweid/lefthook/docs/full_guide.md#custom-file-list) 财务报告和审定财务报表 [预建](https://npmcn.com/package/%40arkweid/lefthook/docs/full_guide.md#select-specific-file-groups) 实例.

```yml
pre-commit:
  commands:
    frontend-linter:
      run: yarn eslint {staged_files}
    backend-linter:
      run: bundle exec rubocop --force-exclusion {all_files}
    frontend-style:
      files: git diff --name-only HEAD @{push}
      run: yarn stylelint {files}
```

-   ### **光标和正则表达式过滤器**
    

如果您想要过滤文件列表 .

```yml
pre-commit:
  commands:
    backend-linter:
      glob: "*.rb" # glob filter
      exclude: "application.rb|routes.rb" # regexp filter
      run: bundle exec rubocop --force-exclusion {all_files}
```

-   ### **在子目录中执行**
    

如果您要在相对路径中执行命令

```yml
pre-commit:
  commands:
    backend-linter:
      root: "api/" # Careful to have only trailing slash
      glob: "*.rb" # glob filter
      run: bundle exec rubocop {all_files}
```

-   ### **运行脚本**
    

如果单行命令不够,可以执行文件. [示例](https://npmcn.com/package/%40arkweid/lefthook/docs/full_guide.md#bash-script-example)。 。 。 .

```yml
commit-msg:
  scripts:
    "template_checker":
      runner: bash
```

-   ### **标记**
    

如果你想控制一组命令. [示例](https://npmcn.com/package/%40arkweid/lefthook/docs/full_guide.md#skipping-commands-by-tags)。 。 。 .

```yml
pre-push:
  commands:
    packages-audit:
      tags: frontend security
      run: yarn audit
    gems-audit:
      tags: backend security
      run: bundle audit
```

-   ### **支持嵌入器**
    

若入多克环境. [示例](https://npmcn.com/package/%40arkweid/lefthook/docs/full_guide.md#referencing-commands-from-lefthookyml)。 。 。 .

```yml
pre-commit:
  scripts:
    "good_job.js":
      runner: docker run -it --rm <container_id_or_name> {cmd}
```

-   ### **本地配置**
    

如果您是前端/后端的开发者, 并且想要跳过不必要的命令或将一些内容覆盖到 Docker 中 . [说明](https://npmcn.com/package/%40arkweid/lefthook/docs/full_guide.md#local-config)。 。 。 .

```yml
# lefthook-local.yml
pre-push:
  exclude_tags:
    - frontend
  commands:
    packages-audit:
      skip: true
```

-   ### **直接控制**
    

如果你想直接运行钩子组.

```bash
$ lefthook run pre-commit
```

-   ### **你的任务**
    

如果您想要直接运行特定的一组命令 .

```yml
fixer:
  commands:
    ruby-fixer:
      run: bundle exec rubocop --force-exclusion --safe-auto-correct {staged_files}
    js-fixer:
      run: yarn eslint --fix {staged_files}
```

```bash
$ lefthook run fixer
```

* * *

## 目录 :

### 指南

-   [节点.js](https://npmcn.com/package/%40arkweid/lefthook/docs/node.md)
-   [鲁比](https://npmcn.com/package/%40arkweid/lefthook/docs/ruby.md)
-   [其他环境](https://npmcn.com/package/%40arkweid/lefthook/docs/other.md)
-   [完整特性指南](https://npmcn.com/package/%40arkweid/lefthook/docs/full_guide.md)
-   [解决问题](https://github.com/evilmartians/lefthook/wiki/Troubleshooting)

### 从

-   [胡斯基](https://github.com/evilmartians/lefthook/wiki/Migration-from-husky)
-   [胡斯基和舞台剧](https://github.com/evilmartians/lefthook/wiki/Migration-from-husky-with-lint-staged)
-   [过度承诺](https://github.com/evilmartians/lefthook/wiki/Migration-from-overcommit)

### 实例

-   [简单脚本](https://github.com/evilmartians/lefthook/tree/master/examples/scripts)
-   [完整特性](https://github.com/evilmartians/lefthook/tree/master/examples/complete)

### 基准

-   [vs 过度承诺](https://github.com/evilmartians/lefthook/wiki/Benchmark-lefthook-vs-overcommit)
-   [vs 预承诺](https://github.com/evilmartians/lefthook/wiki/Benchmark-lefthook-vs-pre-commit)

### 比较清单

-   [vs 过度承诺 胡斯基 预承诺](https://github.com/evilmartians/lefthook/wiki/Comparison-with-other-solutions)

### 文章

-   [Lefthook:把你的团队代码恢复成形状](https://evilmartians.com/chronicles/lefthook-knock-your-teams-code-back-into-shape?utm_source=lefthook)
-   [左旋+水晶球](https://evilmartians.com/chronicles/lefthook-crystalball-and-git-magic?utm_source=lefthook)
-   [保持开放源码软件文件与文件编写、左翼和朋友的核对](https://evilmartians.com/chronicles/keeping-oss-documentation-in-check-with-docsify-lefthook-and-friends?utm_source=lefthook)

## 常见问题

### @arkweid/lefthook 是什么？

简单的钩子管理器注意：该包已被作者标记为弃用——@arkweid/lefthook has been renamed to @evilmartians/lefthook, please upgrade to it\. You also can use @evilmartians/lefthook-installer

### 如何安装 @arkweid/lefthook？

在项目目录运行 npm install @arkweid/lefthook，或使用 pnpm add / yarn add / bun add。它还提供命令行工具 lefthook，可以用 npx lefthook 直接运行。

### @arkweid/lefthook 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/arkweid\_\_lefthook 是否存在。

### @arkweid/lefthook 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @arkweid/lefthook 可以商用吗？

@arkweid/lefthook 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @arkweid/lefthook 的下载量有多少？

根据 npm 官方下载统计，@arkweid/lefthook 在 2026/10/07 – 2026/11/05 这 30 天内被下载 93,825 次，日均约 3,128 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @arkweid/lefthook 还在维护吗？

最新版本 0\.7\.7 发布于 2021/10/03（5 年前）；至今共发布 31 个版本，其中过去 12 个月发布了 0 个；首次发布于 2019/04/17。作者已将其标记为弃用，新项目建议寻找替代方案。

