diff --git a/.commitlintrc b/.commitlintrc.json
similarity index 100%
rename from .commitlintrc
rename to .commitlintrc.json
diff --git a/.eslintrc b/.eslintrc.json
similarity index 100%
rename from .eslintrc
rename to .eslintrc.json
diff --git a/.github/ISSUE_TEMPLATE/issue.md b/.github/ISSUE_TEMPLATE/issue.md
index dd33e06fa..35d7ae6a6 100644
--- a/.github/ISSUE_TEMPLATE/issue.md
+++ b/.github/ISSUE_TEMPLATE/issue.md
@@ -8,11 +8,11 @@ assignees: ''
---
**Troubleshoot**
-Before creating an issue, please check:
+- [ ] Before creating an issue, please check:
https://typicode.github.io/husky/#/?id=troubleshoot
If you're migrating from husky 4, see:
-https://typicode.github.io/husky/#/?id=migrate-from-v4-to-v5
+https://typicode.github.io/husky/#/?id=migrate-from-v4-to-v7
**Context**
Please describe your issue and provide some context:
diff --git a/.github/README.md b/.github/README.md
new file mode 100644
index 000000000..63615beb8
--- /dev/null
+++ b/.github/README.md
@@ -0,0 +1,78 @@
+# husky
+
+[](https://opencollective.com/husky) [](https://www.npmjs.org/package/husky) [](https://github.com/typicode/husky/actions)
+
+> Modern native Git hooks made easy
+
+Husky improves your commits and more 🐶 _woof!_
+
+# Install
+
+```
+npm install husky -D
+```
+
+# Usage
+
+Edit `package.json > prepare` script and run it once:
+
+```sh
+npm pkg set scripts.prepare="husky install"
+npm run prepare
+```
+
+Add a hook:
+
+```sh
+npx husky add .husky/pre-commit "npm test"
+git add .husky/pre-commit
+```
+
+Make a commit:
+
+```sh
+git commit -m "Keep calm and commit"
+# `npm test` will run every time you commit
+```
+
+_For more use cases (project in sub-directory, custom directory, CI support, ...), see documentation._
+
+## Documentation
+
+https://typicode.github.io/husky
+
+**Important** Upgrading from v4 to v7 requires migrating previous config, please see the docs.
+
+## Articles
+
+- [Why husky has dropped conventional JS config](https://blog.typicode.com/husky-git-hooks-javascript-config/)
+- [Why husky doesn't autoinstall anymore](https://blog.typicode.com/husky-git-hooks-autoinstall/)
+
+## License
+
+MIT
+
+# Sponsors
+
+## Companies
+
+Does your company use husky? Ask your manager or marketing team if your company would be interested in supporting this project.
+
+
+
+
+
+
+
+
+
+
+
+
+## Individuals
+
+Find husky helpful? Become a backer and show your appreciation with a monthly donation on [Open Collective](https://opencollective.com/husky). You can also tip with a one-time donation.
+
+
+
+GitHub sponsors can be viewed on my [profile](https://github.com/typicode). All past and current Open Collective sponsors can be viewed on [here](https://opencollective.com/husky).
diff --git a/.github/stale.yml b/.github/stale.yml
new file mode 100644
index 000000000..ee4424bc7
--- /dev/null
+++ b/.github/stale.yml
@@ -0,0 +1,17 @@
+# Number of days of inactivity before an issue becomes stale
+daysUntilStale: 90
+# Number of days of inactivity before a stale issue is closed
+daysUntilClose: 7
+# Issues with these labels will never be considered stale
+exemptLabels:
+ - pinned
+ - security
+# Label to use when marking an issue as stale
+staleLabel: wontfix
+# Comment to post when marking an issue as stale. Set to `false` to disable
+markComment: >
+ This issue has been automatically marked as stale because it has not had
+ recent activity. It will be closed if no further activity occurs. Thank you
+ for your contributions.
+# Comment to post when closing a stale issue. Set to `false` to disable
+closeComment: false
diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml
index 4fc6f8a2e..6a8f1beed 100644
--- a/.github/workflows/node.js.yml
+++ b/.github/workflows/node.js.yml
@@ -1,4 +1,3 @@
-# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
@@ -7,20 +6,33 @@ on: [push]
jobs:
build:
- name: Test on node ${{ matrix.node_version }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
-
strategy:
matrix:
- node-version: [10.x, 14.x]
- os: [ubuntu-latest, windows-latest, macOS-latest]
-
+ node-version: [14, 16, 18]
+ os: [ubuntu-latest, macOS-latest]
steps:
- - uses: actions/checkout@v2
- - name: Use Node.js ${{ matrix.node-version }}
- uses: actions/setup-node@v1
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- - run: npm ci
- - run: npm run postinstall --if-present
+ - run: npm --version
+ - run: npm ci --ignore-scripts
+ - run: npm test
+ # Node 14 comes with npm 6 which has issues on Windows
+ # Skipping tests on Windows with Node 14
+ build-windows:
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ node-version: [16, 18]
+ os: [windows-latest]
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
+ with:
+ node-version: ${{ matrix.node-version }}
+ - run: npm --version
+ - run: npm ci --ignore-scripts
+ - run: npm test
diff --git a/.github/workflows/npm_publish.yml b/.github/workflows/npm_publish.yml
new file mode 100644
index 000000000..65288a7eb
--- /dev/null
+++ b/.github/workflows/npm_publish.yml
@@ -0,0 +1,33 @@
+# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
+
+name: Node.js Package
+
+on:
+ release:
+ types: [created]
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
+ with:
+ node-version: 16
+ - run: npm ci --ignore-scripts
+ - run: npm test
+
+ publish-npm:
+ needs: build
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
+ with:
+ node-version: 16
+ registry-url: https://registry.npmjs.org/
+ - run: npm ci --ignore-scripts
+ - run: npm run build
+ - run: npm publish
+ env:
+ NODE_AUTH_TOKEN: ${{secrets.npm_token}}
diff --git a/.gitignore b/.gitignore
index 437ca9ff5..53b54be18 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@ lib
node_modules
husky-*.tgz
tsconfig.tsbuildinfo
+*.log
diff --git a/.husky/.gitignore b/.husky/.gitignore
deleted file mode 100644
index 31354ec13..000000000
--- a/.husky/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-_
diff --git a/.husky/commit-msg b/.husky/commit-msg
index 567ff71f0..b56767669 100755
--- a/.husky/commit-msg
+++ b/.husky/commit-msg
@@ -1,6 +1,4 @@
-#!/bin/sh
+#!/usr/bin/env sh
+. "$(dirname -- "$0")/_/husky.sh"
-# shellcheck source=./_/husky.sh
-. "$(dirname "$0")/_/husky.sh"
-
-npx --no-install commitlint --edit "$1"
+npx --no -- commitlint --edit "$1"
diff --git a/.husky/pre-commit b/.husky/pre-commit
index 7d0a96b9c..610c2a54f 100755
--- a/.husky/pre-commit
+++ b/.husky/pre-commit
@@ -1,6 +1,4 @@
-#!/bin/sh
-
-# shellcheck source=./_/husky.sh
-. "$(dirname "$0")/_/husky.sh"
+#!/usr/bin/env sh
+. "$(dirname -- "$0")/_/husky.sh"
npm test
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index c4b1f9f6e..44eeaf9ad 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,2 +1 @@
-By contributing, you agree to release your modifications under the MIT
-license (see the file LICENSE-MIT).
+By contributing, you agree to release your modifications under the MIT license (see the file LICENSE-MIT).
diff --git a/LICENSE b/LICENSE
index d814a08c0..049c9dc4e 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1 +1,21 @@
-License Zero Parity 7.0.0 (see LICENSE-PARITY file) and MIT (contributions, see LICENSE-MIT file) with exception License Zero Patron 1.0.0 (see LICENSE-PATRON file)
+MIT License
+
+Copyright (c) 2021 typicode
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/LICENSE-MIT b/LICENSE-MIT
deleted file mode 100644
index 81f990d60..000000000
--- a/LICENSE-MIT
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2020
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
diff --git a/LICENSE-PARITY b/LICENSE-PARITY
deleted file mode 100644
index 8478ede80..000000000
--- a/LICENSE-PARITY
+++ /dev/null
@@ -1,71 +0,0 @@
-# The Parity Public License 7.0.0
-
-Contributor: Typicode
-
-Source Code: https://github.com/typicode/husky
-
-## Purpose
-
-This license allows you to use and share this software for free, but you have to share software that builds on it alike.
-
-## Agreement
-
-In order to receive this license, you have to agree to its rules. Those rules are both obligations under that agreement and conditions to your license. Don't do anything with this software that triggers a rule you can't or won't follow.
-
-## Notices
-
-Make sure everyone who gets a copy of any part of this software from you, with or without changes, also gets the text of this license and the contributor and source code lines above.
-
-## Copyleft
-
-[Contribute](#contribute) software you develop, operate, or analyze with this software, including changes or additions to this software. When in doubt, [contribute](#contribute).
-
-## Prototypes
-
-You don't have to [contribute](#contribute) any change, addition, or other software that meets all these criteria:
-
-1. You don't use it for more than thirty days.
-
-2. You don't share it outside the team developing it, other than for non-production user testing.
-
-3. You don't develop, operate, or analyze other software with it for anyone outside the team developing it.
-
-## Reverse Engineering
-
-You may use this software to operate and analyze software you can't [contribute](#contribute) in order to develop alternatives you can and do [contribute](#contribute).
-
-## Contribute
-
-To [contribute](#contribute) software:
-
-1. Publish all source code for the software in the preferred form for making changes through a freely accessible distribution system widely used for similar source code so the contributor and others can find and copy it.
-
-2. Make sure every part of the source code is available under this license or another license that allows everything this license does, such as [the Blue Oak Model License 1.0.0](https://blueoakcouncil.org/license/1.0.0), [the Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.html), [the MIT license](https://spdx.org/licenses/MIT.html), or [the two-clause BSD license](https://spdx.org/licenses/BSD-2-Clause.html).
-
-3. Take these steps within thirty days.
-
-4. Note that this license does _not_ allow you to change the license terms for this software. You must follow [Notices](#notices).
-
-## Excuse
-
-You're excused for unknowingly breaking [Copyleft](#copyleft) if you [contribute](#contribute) as required, or stop doing anything requiring this license, within thirty days of learning you broke the rule. You're excused for unknowingly breaking [Notices](#notices) if you take all practical steps to comply within thirty days of learning you broke the rule.
-
-## Defense
-
-Don't make any legal claim against anyone accusing this software, with or without changes, alone or with other technology, of infringing any patent.
-
-## Copyright
-
-The contributor licenses you to do everything with this software that would otherwise infringe their copyright in it.
-
-## Patent
-
-The contributor licenses you to do everything with this software that would otherwise infringe any patents they can license or become able to license.
-
-## Reliability
-
-The contributor can't revoke this license.
-
-## No Liability
-
-***As far as the law allows, this software comes as is, without any warranty or condition, and the contributor won't be liable to anyone for any damages related to this software or this license, under any kind of legal claim.***
diff --git a/LICENSE-PATRON b/LICENSE-PATRON
deleted file mode 100644
index 6d995c59f..000000000
--- a/LICENSE-PATRON
+++ /dev/null
@@ -1,63 +0,0 @@
-# Patron License 1.0.0
-
-Payment Platforms:
-- https://github.com/sponsors/typicode
-- https://opencollective.com/husky
-- https://www.patreon.com/typicode
-
-Participating Contributors:
-- Typicode
-
-## Purpose
-
-This license gives everyone patronizing contributors to this software permission to ignore any noncommercial or copyleft rules of its free public license, while continuing to protect contributors from liability.
-
-## Acceptance
-
-In order to agree to these terms and receive a license, you must qualify under [Patrons](#patrons). The rules of these terms are both obligations under your agreement and conditions to your license. That agreement and your license continue only while you qualify as a patron. You must not do anything with this software that triggers a rule that you cannot or will not follow.
-
-## Patrons
-
-To accept these terms, you must be enrolled to make regular payments through any of the payment platforms pages listed above, in amounts qualifying you for a tier that includes a "patron license" or otherwise identifies a license under these terms as a reward.
-
-## Scope
-
-Except under [Seat](#seat) and [Applications](#applications), you may not sublicense or transfer any agreement or license under these terms to anyone else.
-
-## Seat
-
-If a legal entity, rather than an individual, accepts these terms, the entity may sublicense one individual employee or independent contractor at any given time. If the employee or contractor breaks any rule of these terms, the entity will stand directly responsible.
-
-## Applications
-
-If you combine this software with other software in a larger application, you may sublicense this software as part of your larger application, and allow further sublicensing in turn, under these rules:
-
-1. Your larger application must have significant additional content or functionality beyond that of this software, and end users must license your larger application primarily for that added content or functionality.
-
-2. You may not sublicense anyone to break any rule of the public license for this software for any changes of their own or any software besides your larger application.
-
-3. You may build, and sublicense for, as many larger applications as you like.
-
-## Copyright
-
-Each contributor licenses you to do everything with this software that would otherwise infringe that contributor's copyright in it.
-
-## Notices
-
-You must ensure that everyone who gets a copy of any part of this software from you, with or without changes, also gets the texts of both this license and the free public license for this software.
-
-## Excuse
-
-If anyone notifies you in writing that you have not complied with [Notices](#notices), you can keep your agreement and your license by taking all practical steps to comply within 30 days after the notice. If you do not do so, your agreement under these terms ends immediately, and your license ends with it.
-
-## Patent
-
-Each contributor licenses you to do everything with this software that would otherwise infringe any patent claims they can license or become able to license.
-
-## Reliability
-
-No contributor can revoke this license, but your license may end if you break any rule of these terms.
-
-## No Liability
-
-***As far as the law allows, this software comes as is, without any warranty or condition, and no contributor will be liable to anyone for any damages related to this software or this license, under any kind of legal claim.***
diff --git a/README.md b/README.md
index 048c42076..adfd3773f 100644
--- a/README.md
+++ b/README.md
@@ -1,90 +1,38 @@
# husky
-[](https://opencollective.com/husky) [](https://www.npmjs.org/package/husky) [](https://github.com/typicode/husky/actions)
-
-> Git hooks made easy
+> Modern native Git hooks made easy
Husky improves your commits and more 🐶 *woof!*
-- [**Documentation v5 (recommended for Open Source and Sponsors)**](https://typicode.github.io/husky)
-- [Documentation v4](https://github.com/typicode/husky/tree/master)
-
-__👋 [Read husky 5 announcement and see what's new](https://dev.to/typicode/what-s-new-in-husky-5-32g5)__
-
-__Note: husky 5 is a major version with breaking changes. Upgrading from v4 to v5 requires additional steps, please see the docs.__
-
----
-
-You're viewing documentation for husky v5, which is free to use in Open Source projects ❤️ and in early access for Sponsors 🎁.
-
-To use this new version at work, you can become a sponsor on [GitHub Sponsors](https://github.com/sponsors/typicode) or [Open Collective](https://opencollective.com/husky) (monthly or yearly donations are supported).
-
-If you can't sponsor Husky, that's okay, [husky v4](https://github.com/typicode/husky/tree/master) is free to use in any project. During the early access, v4 will continue to receive maintainance updates.
+# Install
-After the early access, husky v5 will be MIT again.
+```
+npm install husky --save-dev
+```
----
+# Usage
-# Sponsors
+Edit `package.json > prepare` script and run it once:
-## Companies
+```sh
+npm pkg set scripts.prepare="husky install"
+npm run prepare
+```
-
+Add a hook:
-
-
-
-
-
-
-
-
-
-
+```sh
+npx husky add .husky/pre-commit "npm test"
+git add .husky/pre-commit
+```
-## Individuals
+Make a commit:
-Find Husky helpful? Become a backer and show your appreciation with a monthly donation on [Open Collective](https://opencollective.com/husky). You can also tip with a one-time donation.
+```sh
+git commit -m "Keep calm and commit"
+# `npm test` will run
+```
-[](https://opencollective.com/husky/backer/0/website)
-[](https://opencollective.com/husky/backer/1/website)
-[](https://opencollective.com/husky/backer/2/website)
-[](https://opencollective.com/husky/backer/3/website)
-[](https://opencollective.com/husky/backer/4/website)
-[](https://opencollective.com/husky/backer/5/website)
-[](https://opencollective.com/husky/backer/6/website)
-[](https://opencollective.com/husky/backer/7/website)
-[](https://opencollective.com/husky/backer/8/website)
-[](https://opencollective.com/husky/backer/9/website)
-[](https://opencollective.com/husky/backer/10/website)
-[](https://opencollective.com/husky/backer/11/website)
-[](https://opencollective.com/husky/backer/12/website)
-[](https://opencollective.com/husky/backer/13/website)
-[](https://opencollective.com/husky/backer/14/website)
-[](https://opencollective.com/husky/backer/15/website)
-[](https://opencollective.com/husky/backer/16/website)
-[](https://opencollective.com/husky/backer/17/website)
-[](https://opencollective.com/husky/backer/18/website)
-[](https://opencollective.com/husky/backer/19/website)
-[](https://opencollective.com/husky/backer/20/website)
-[](https://opencollective.com/husky/backer/21/website)
-[](https://opencollective.com/husky/backer/22/website)
-[](https://opencollective.com/husky/backer/23/website)
-[](https://opencollective.com/husky/backer/24/website)
-[](https://opencollective.com/husky/backer/25/website)
-[](https://opencollective.com/husky/backer/26/website)
-[](https://opencollective.com/husky/backer/27/website)
-[](https://opencollective.com/husky/backer/28/website)
-[](https://opencollective.com/husky/backer/29/website)
-[](https://opencollective.com/husky/backer/30/website)
-[](https://opencollective.com/husky/backer/31/website)
-[](https://opencollective.com/husky/backer/32/website)
-[](https://opencollective.com/husky/backer/33/website)
-[](https://opencollective.com/husky/backer/34/website)
-[](https://opencollective.com/husky/backer/35/website)
-[](https://opencollective.com/husky/backer/36/website)
-[](https://opencollective.com/husky/backer/37/website)
-[](https://opencollective.com/husky/backer/38/website)
-[](https://opencollective.com/husky/backer/39/website)
+# Documentation
-GitHub sponsors can be viewed on my [profile](https://github.com/typicode). All past and current Open Collective sponsors can be viewed on [Husky's Open Collective](https://opencollective.com/husky).
+https://typicode.github.io/husky
diff --git a/docs/README.md b/docs/README.md
index 6e50bb34d..3848d5ff6 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -1,44 +1,84 @@
[](https://opencollective.com/husky) [](https://www.npmjs.org/package/husky) [](https://github.com/typicode/husky/actions)
-> Git hooks made easy
+> Modern native git hooks made easy
Husky improves your commits and more 🐶 _woof!_
-You can use it to **lint your commit messages**, **run tests**, **lint code**, etc... when you commit or push. Husky supports [all](https://git-scm.com/docs/githooks) Git hooks.
-
-# Announcement
-
-**👋 [Read husky 5 announcement and see what's new](https://dev.to/typicode/what-s-new-in-husky-5-32g5)**
-
-?> You're viewing documentation for husky v5, which is free to use in Open Source projects ❤️ and in early access for Sponsors 🎁. To use this new version at work, you can become a sponsor on [GitHub Sponsors](https://github.com/sponsors/typicode) or [Open Collective](https://opencollective.com/husky).
If you can't sponsor Husky, that's okay, [husky v4](https://github.com/typicode/husky/tree/master) is free to use in any project.
+You can use it to **lint your commit messages**, **run tests**, **lint code**, etc... when you commit or push. Husky supports [all Git hooks](https://git-scm.com/docs/githooks).
# Features
-- Zero dependencies
-- Lightweight (`~0.02MB` vs `~1MB` for husky 4)
-- Fast (`~0.01s` vs `~0.5s` for husky 4)
-- Supports macOS, Linux and Windows
+- Zero dependencies and lightweight (`6 kB`)
+- Powered by modern new Git feature (`core.hooksPath`)
+- Follows [npm](https://docs.npmjs.com/cli/v8/using-npm/scripts#best-practices) and [Yarn](https://yarnpkg.com/advanced/lifecycle-scripts#a-note-about-postinstall) best practices regarding autoinstall
+- User-friendly messages
+- Optional install
+- __Like husky 4, supports__
+ - macOS, Linux and Windows
+ - Git GUIs
+ - Custom directories
+ - Monorepos
+
+# Used by
+
+Husky is used by these awesome projects:
+
+- [webpack/webpack](https://github.com/webpack/webpack)
+- [angular/angular](https://github.com/angular/angular)
+- [angular/angular-cli](https://github.com/angular/angular-cli)
+- [angular/components](https://github.com/angular/components)
+- [vercel/hyper](https://github.com/vercel/hyper)
+- [blitz-js/blitz](https://github.com/blitz-js/blitz)
+- [facebook/docusaurus](https://github.com/facebook/docusaurus)
+- [typescript-eslint/typescript-eslint](https://github.com/typescript-eslint/typescript-eslint)
+- [11ty/eleventy](https://github.com/11ty/eleventy)
+- [stylelint/stylelint](https://github.com/stylelint/stylelint)
+- [rollup/rollup](https://github.com/rollup/rollup)
+- [tauri-apps/tauri](https://github.com/tauri-apps/tauri)
+- [NativeScript/NativeScript](https://github.com/NativeScript/NativeScript)
+- [formatjs/formatjs](https://github.com/formatjs/formatjs)
+- [react-bootstrap/react-bootstrap](https://github.com/react-bootstrap/react-bootstrap)
+- [react-dnd/react-dnd](https://github.com/react-dnd/react-dnd)
+- [react-grid-layout/react-grid-layout](https://github.com/react-grid-layout/react-grid-layout)
+- [snabbdom/snabbdom](https://github.com/snabbdom/snabbdom)
+- [logaretm/vee-validate](https://github.com/logaretm/vee-validate)
+- [zenorocha/clipboard.js](https://github.com/zenorocha/clipboard.js)
+- [NodeBB/NodeBB](https://github.com/NodeBB/NodeBB)
+- [ant-design/ant-design](https://github.com/ant-design/ant-design)
+- And [__more__](https://github.com/typicode/husky/network/dependents?package_id=UGFja2FnZS0xODQzNTgwNg%3D%3D)
+
+## Articles
+
+- [Why husky has dropped conventional JS config](https://blog.typicode.com/husky-git-hooks-javascript-config/)
+- [Why husky doesn't autoinstall anymore](https://blog.typicode.com/husky-git-hooks-autoinstall/)
# Usage
-Already using husky? See [Migrate from 4 to 5](/?id=migrate-from-v4-to-v5).
+Already using husky? See [Migrate from 4 to 8](/?id=migrate-from-v4-to-v8).
## Automatic (recommended)
+`husky-init` is a one-time command to quickly initialize a project with husky.
+
```shell
-npm install husky --save-dev && npx husky init
+npx husky-init && npm install # npm
+npx husky-init && yarn # Yarn 1
+yarn dlx husky-init --yarn2 && yarn # Yarn 2+
+pnpm dlx husky-init && pnpm install # pnpm
```
-The command above will setup husky, modify `package.json` and create a sample `pre-commit` hook that you can edit. By default, it will run `npm test` when you commit.
+It will setup husky, modify `package.json` and create a sample `pre-commit` hook that you can edit. By default, it will run `npm test` when you commit.
To add another hook use `husky add`.
For example:
```shell
-npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
+npx husky add .husky/commit-msg 'npx --no -- commitlint --edit "$1"'
```
+_For Windows users, if you see the help message when running `npx husky add ...`, try `node node_modules/husky/lib/bin add ...` instead. This isn't an issue with husky code._
+
## Manual
### Install
@@ -57,6 +97,12 @@ npx husky install
3. To automatically have Git hooks enabled after install, edit `package.json`
+```shell
+npm pkg set scripts.prepare="husky install"
+```
+
+You should have:
+
```js
// package.json
{
@@ -66,14 +112,15 @@ npx husky install
}
```
-!> **Yarn v2 doesn't support `prepare` lifecycle script, so husky needs to be installed differently (this doesn't apply to yarn v1 though). See [Yarn v2 install](/?id=yarn-v2).**
+!> **Yarn 2+ doesn't support `prepare` lifecycle script, so husky needs to be installed differently (this doesn't apply to Yarn 1 though). See [Yarn 2+ install](/?id=yarn-2).**
-### Add a hook
+### Create a hook
-To add a hook, use `husky add [cmd]` (don't forget to run `husky install` before).
+To add a command to a hook or create a new one, use `husky add [cmd]` (don't forget to run `husky install` before).
```shell
npx husky add .husky/pre-commit "npm test"
+git add .husky/pre-commit
```
Try to make a commit
@@ -86,13 +133,15 @@ If `npm test` command fails, your commit will be automatically aborted.
!> **Using Yarn to run commands? There's an issue on Windows with Git Bash, see [Yarn on Windows](/?id=yarn-on-windows).**
+_For Windows users, if you see the help message when running `npx husky add ...`, try `node node_modules/.bin/husky add ...` instead. This isn't an issue with husky code and is fixed in recent versions of npm 8._
+
### Uninstall
```shell
-npm uninstall husky
+npm uninstall husky && git config --unset core.hooksPath
```
-## Yarn v2
+## Yarn 2
### Install
@@ -100,7 +149,7 @@ npm uninstall husky
```shell
yarn add husky --dev
-yarn add pinst --dev # if your package is not private
+yarn add pinst --dev # ONLY if your package is not private
```
2. Enable Git hooks
@@ -114,7 +163,7 @@ yarn husky install
```js
// package.json
{
- "private": true,
+ "private": true, // ← your package is private, you only need postinstall
"scripts": {
"postinstall": "husky install"
}
@@ -126,11 +175,11 @@ yarn husky install
```js
// package.json
{
- "private": false,
+ "private": false, // ← your package is public
"scripts": {
"postinstall": "husky install",
- "prepublishOnly": "pinst --disable",
- "postpublish": "pinst --enable"
+ "prepack": "pinst --disable",
+ "postpack": "pinst --enable"
}
}
```
@@ -198,9 +247,50 @@ For Git commands that don't have a `--no-verify` option, you can use `HUSKY` env
HUSKY=0 git push # yolo!
```
-## Disable hooks in CI
+## Disable husky in CI/Docker/Prod
+
+There's no right or wrong way to disable husky in CI/Docker/Prod context and is highly __dependent on your use-case__.
+
+### With npm
+
+If you want to prevent husky from installing completely
+
+```shell
+npm ci --omit=dev --ignore-scripts
+```
+
+Alternatively, you can specifically disable `prepare` script with
-You can set `HUSKY` environment variable to `0` in your CI config file, to disable all hooks.
+```shell
+npm pkg delete scripts.prepare
+npm ci --omit=dev
+```
+
+### With a custom script
+
+You can create a custom JS script and conditionally require husky and install hooks.
+
+```json
+"prepare": "node ./prepare.js"
+```
+
+```js
+// prepare.js
+const isCi = process.env.CI !== undefined
+if (!isCi) {
+ require('husky').install()
+}
+```
+
+Or make `prepare` script fail silently if husky is not installed:
+
+```json
+"prepare": "node -e \"try { require('husky').install() } catch (e) {if (e.code !== 'MODULE_NOT_FOUND') throw e}\""
+```
+
+### With env variables
+
+You can set `HUSKY` environment variable to `0` in your CI config file, to disable hooks installation.
Alternatively, most Continuous Integration Servers set a `CI` environment variable. You can use it in your hooks to detect if it's running in a CI.
@@ -210,7 +300,9 @@ Alternatively, most Continuous Integration Servers set a `CI` environment variab
[ -n "$CI" ] && exit 0
```
-You can also use [is-ci](https://github.com/watson/is-ci) in your `prepare` script to conditionnally install husky
+### With is-ci
+
+You can also use [is-ci](https://github.com/watson/is-ci) in your `prepare` script to conditionally install husky
```shell
npm install is-ci --save-dev
@@ -245,8 +337,8 @@ git config gitflow.path.hooks .husky
**Note:**
-- If you are configuring git-flow _after_ you have installed Husky, the git-flow setup process will correctly suggest the .husky directory.
-- If you have set a [custom directory](/?id=custom-directory) for Husky you need to specify that (ex. `git config gitflow.path.hooks .config/husky`)
+- If you are configuring git-flow _after_ you have installed husky, the git-flow setup process will correctly suggest the .husky directory.
+- If you have set a [custom directory](/?id=custom-directory) for husky you need to specify that (ex. `git config gitflow.path.hooks .config/husky`)
To **revert** the git-flow hooks directory back to its default you need to reset the config to point to the default Git hooks directory.
@@ -283,11 +375,16 @@ export NVM_DIR="$HOME/.nvm"
## Hooks not running
-Ensure that you don't have a typo in your filename. For example, `precommit` or `pre-commit.sh` are invalid names. See Git hooks [documentation](https://git-scm.com/docs/githooks) for valid names.
+1. Ensure that you don't have a typo in your filename. For example, `precommit` or `pre-commit.sh` are invalid names. See Git hooks [documentation](https://git-scm.com/docs/githooks) for valid names.
+1. Check that `git config core.hooksPath` returns `.husky` (or your custom hooks directory).
+1. Verify that hook files are executable. This is automatically set when using `husky add` command but you can run `chmod +x .husky/` to fix that.
+1. Check that your version of Git is greater than `2.9`.
-Verify hooks permissions, they should be executable. This is automatically set when using `husky add` command but you can run `chmod +x .husky/` to fix that.
+## .git/hooks/ not working after uninstall
-Check that your version of Git is greater than `2.9`.
+If after uninstalling `husky`, hooks in `.git/hooks/` aren't working. Run `git config --unset core.hooksPath`.
+
+Note: this was done automatically by `npm <7` when uninstalling husky, however `preuninstall` is now unsupported.
## Yarn on Windows
@@ -309,36 +406,27 @@ fi
2. Source it in in places where Yarn is used to run commands:
```shell
-#!/bin/sh
-. "$(dirname "$0")/_/husky.sh"
-. "$(dirname "$0")/common.sh"
+#!/usr/bin/env sh
+. "$(dirname -- "$0")/_/husky.sh"
+. "$(dirname -- "$0")/common.sh"
yarn ...
```
-# Free for Open Source, early access for Sponsors
-
-How it works?
-
-- If you have an Open Source project, you're free to install or upgrade husky to v5 ❤️
-- If you have a commercial project and are a Sponsor, you can start using v5 today at work 🎁
-
-To acquire a proprietary-use license, simply go to [GitHub Sponsors](https://github.com/sponsors/typicode) or [Open Collective](https://opencollective.com/husky).
-
# Breaking changes
Environment variables:
-- `HUSKY_SKIP_HOOKS` becomes `HUSKY`.
-- `HUSKY_SKIP_INSTALL` is removed.
+- `HUSKY_SKIP_HOOKS` is replaced by `HUSKY`.
+- `HUSKY_SKIP_INSTALL` is replaced by `HUSKY`.
- `HUSKY_GIT_PARAMS` is removed. Instead Git parameters should be used directly in scripts (e.g. `$1`).
- `PATH` for locally installed tools is not automatically set anymore. You'll need to use your package manager to run them.
-# Migrate from v4 to v5
+# Migrate from v4 to v8
-## husky-4-to-5 CLI
+## husky-4-to-8 CLI
-See [husky-4-to-5](https://github.com/typicode/husky-4-to-5) CLI to quickly migrate from v4 to v5.
+See [husky-4-to-8](https://github.com/typicode/husky-4-to-8) CLI to quickly migrate from v4 to v8.
## Package scripts
@@ -354,7 +442,7 @@ If you were calling `package.json` scripts using `npm` or `yarn`, **you can simp
```
```shell
-# .husky/pre-commit (v5)
+# .husky/pre-commit (v8)
# ...
npm test
npm run foo
@@ -374,9 +462,10 @@ If you were calling directly locally installed binaries, **you need to run them
```
```shell
-# .husky/pre-commit (v5)
+# .husky/pre-commit (v8)
# ...
-npx --no-install jest
+npx --no jest
+# or
yarn jest
```
@@ -394,9 +483,9 @@ Previous `HUSKY_GIT_PARAMS` environment variable is replaced by native params `$
```
```shell
-# .husky/commit-msg (v5)
+# .husky/commit-msg (v8)
# ...
-npx --no-install commitlint --edit $1
+npx --no -- commitlint --edit $1
# or
yarn commitlint --edit $1
```
@@ -405,70 +494,27 @@ yarn commitlint --edit $1
## Companies
-
-
-Does your company use Husky? Ask your manager or marketing team if your company would be interested in supporting this project.
+Does your company use husky? Ask your manager or marketing team if your company would be interested in supporting this project.
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
## Individuals
-Find Husky helpful? Become a backer and show your appreciation with a monthly donation on [Open Collective](https://opencollective.com/husky). You can also tip with a one-time donation.
-
-[](https://opencollective.com/husky/backer/0/website)
-[](https://opencollective.com/husky/backer/1/website)
-[](https://opencollective.com/husky/backer/2/website)
-[](https://opencollective.com/husky/backer/3/website)
-[](https://opencollective.com/husky/backer/4/website)
-[](https://opencollective.com/husky/backer/5/website)
-[](https://opencollective.com/husky/backer/6/website)
-[](https://opencollective.com/husky/backer/7/website)
-[](https://opencollective.com/husky/backer/8/website)
-[](https://opencollective.com/husky/backer/9/website)
-[](https://opencollective.com/husky/backer/10/website)
-[](https://opencollective.com/husky/backer/11/website)
-[](https://opencollective.com/husky/backer/12/website)
-[](https://opencollective.com/husky/backer/13/website)
-[](https://opencollective.com/husky/backer/14/website)
-[](https://opencollective.com/husky/backer/15/website)
-[](https://opencollective.com/husky/backer/16/website)
-[](https://opencollective.com/husky/backer/17/website)
-[](https://opencollective.com/husky/backer/18/website)
-[](https://opencollective.com/husky/backer/19/website)
-[](https://opencollective.com/husky/backer/20/website)
-[](https://opencollective.com/husky/backer/21/website)
-[](https://opencollective.com/husky/backer/22/website)
-[](https://opencollective.com/husky/backer/23/website)
-[](https://opencollective.com/husky/backer/24/website)
-[](https://opencollective.com/husky/backer/25/website)
-[](https://opencollective.com/husky/backer/26/website)
-[](https://opencollective.com/husky/backer/27/website)
-[](https://opencollective.com/husky/backer/28/website)
-[](https://opencollective.com/husky/backer/29/website)
-[](https://opencollective.com/husky/backer/30/website)
-[](https://opencollective.com/husky/backer/31/website)
-[](https://opencollective.com/husky/backer/32/website)
-[](https://opencollective.com/husky/backer/33/website)
-[](https://opencollective.com/husky/backer/34/website)
-[](https://opencollective.com/husky/backer/35/website)
-[](https://opencollective.com/husky/backer/36/website)
-[](https://opencollective.com/husky/backer/37/website)
-[](https://opencollective.com/husky/backer/38/website)
-[](https://opencollective.com/husky/backer/39/website)
-
-GitHub sponsors can be viewed on my [profile](https://github.com/typicode). All past and current Open Collective sponsors can be viewed on [Husky's Open Collective](https://opencollective.com/husky).
+Find husky helpful? Become a backer and show your appreciation with a monthly donation on [Open Collective](https://opencollective.com/husky). You can also tip with a one-time donation.
-# License
+
-[License Zero Parity 7.0.0](https://paritylicense.com/versions/7.0.0.html) and MIT (contributions) with exception [License Zero Patron 1.0.0](https://patronlicense.com/versions/1.0.0).
+GitHub sponsors can be viewed on my [profile](https://github.com/typicode). All past and current Open Collective sponsors can be viewed on [here](https://opencollective.com/husky).
+
+# License
-👉 See the [announcement](/?id=announcement) for more details.
+MIT
diff --git a/docs/index.html b/docs/index.html
index d81064a61..8e371023f 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -4,7 +4,7 @@
Husky - Git hooks
-
+
+