@arkweid/lefthook

中文文档
0.7.7发布于 2021/10/03MITCommonJS零依赖近 30 天下载 9.4万

Simple git hooks manager

此软件包已被标记为弃用

@arkweid/lefthook has been renamed to @evilmartians/lefthook, please upgrade to it. You also can use @evilmartians/lefthook-installer

原始使用文档
文档目录19 节
  1. Usage
  2. Why Lefthook
  3. Parallel execution
  4. Flexible list of files
  5. Glob and regexp filters
  6. Execute in sub-directory
  7. Run scripts
  8. Tags
  9. Support Docker
  10. Local config
  11. Direct control
  12. Your own tasks
  13. Table of contents:
  14. Guides
  15. Migrate from
  16. Examples
  17. Benchmarks
  18. Comparison list
  19. Articles

Build Status

Lefthook

The fastest polyglot Git hooks manager out there

Fast and powerful Git hooks manager for Node.js, Ruby or any other type of projects.

  • Fast. It is written in Go. Can run commands in parallel.
  • Powerful. With a few lines in the config you can check only the changed files on pre-push hook.
  • Simple. It is single dependency-free binary which can work in any environment.

📖 Read the introduction post

# 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

Usage

Choose your environment:

Then you can find all Lefthook features in the full guide and explore wiki.


Why Lefthook

  • Parallel execution

If you want more speed. Example

pre-push:
  parallel: true
  • Flexible list of files

If you want your own list. Custom and prebuilt examples.

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}
  • Glob and regexp filters

If you want to filter list of files.

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

If you want to execute the commands in a relative path

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

If oneline commands are not enough, you can execute files. Example.

commit-msg:
  scripts:
    "template_checker":
      runner: bash
  • Tags

If you want to control a group of commands. Example.

pre-push:
  commands:
    packages-audit:
      tags: frontend security
      run: yarn audit
    gems-audit:
      tags: backend security
      run: bundle audit
  • Support Docker

If you are in the Docker environment. Example.

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

If you a frontend/backend developer and want to skip unnecessary commands or override something into Docker. Description.

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

If you want to run hooks group directly.

$ lefthook run pre-commit
  • Your own tasks

If you want to run specific group of commands directly.

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

Table of contents:

Guides

Migrate from

Examples

Benchmarks

Comparison list

Articles

版本与发布记录

@arkweid/lefthook 共发布 31 个版本,首次发布于 2019/04/17;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.7.7latest2021/10/035 年前
0.7.62021/06/025 年前
0.7.52021/05/155 年前
0.7.42021/04/305 年前
0.7.32021/04/235 年前
0.7.22020/05/196 年前

关于 @arkweid/lefthook 的常见问题

@arkweid/lefthook 是什么?

Simple git hooks manager注意:该包已被作者标记为弃用——@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。作者已将其标记为弃用,新项目建议寻找替代方案。