Skip to content

Commit ec13855

Browse files
authored
v9 (#1333)
1 parent a5c36f5 commit ec13855

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+5274
-5669
lines changed

.commitlintrc.json

-3
This file was deleted.

.editorconfig

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root = true
2+
[*]
3+
end_of_line = lf
4+
indent_style = tab
5+
insert_final_newline = false

.eslintrc.json

-3
This file was deleted.

.gitattributes

-2
This file was deleted.

.github/README.md

+8-32
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,11 @@
66
77
Husky improves your commits and more 🐶 _woof!_
88

9-
# Install
10-
11-
```
12-
npm install husky -D
13-
```
14-
15-
# Usage
16-
17-
Edit `package.json > prepare` script and run it once:
18-
19-
```sh
20-
npm pkg set scripts.prepare="husky install"
21-
npm run prepare
22-
```
23-
24-
Add a hook:
25-
26-
```sh
27-
npx husky add .husky/pre-commit "npm test"
28-
git add .husky/pre-commit
29-
```
30-
31-
Make a commit:
32-
33-
```sh
34-
git commit -m "Keep calm and commit"
35-
# `npm test` will run every time you commit
36-
```
37-
38-
_For more use cases (project in sub-directory, custom directory, CI support, ...), see documentation._
39-
409
## Documentation
4110

4211
https://typicode.github.io/husky
4312

44-
**Important** Upgrading from v4 to v8 requires migrating previous config, please see the docs.
13+
**Important** Upgrading from v4 to v9 requires migrating previous config, please see the docs.
4514

4615
## Articles
4716

@@ -54,6 +23,13 @@ MIT
5423

5524
# Sponsors
5625

26+
<p align="center">
27+
<a href="./docs/sponsorkit/sponsors.svg">
28+
<img src='./docs/sponsorkit/sponsors.svg'/>
29+
</a>
30+
</p>
31+
32+
5733
## Companies
5834

5935
Does your company use husky? Ask your manager or marketing team if your company would be interested in supporting this project.

.github/workflows/deploy.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ jobs:
1919
fetch-depth: 0
2020
- uses: actions/setup-node@v3
2121
with:
22-
node-version: 16
22+
node-version: 20
2323
cache: npm
2424
- run: npm ci
2525
- name: Build
26-
run: npm run docs:build
26+
working-directory: ./docs
27+
run: npx vitepress build
2728
- uses: actions/configure-pages@v2
2829
- uses: actions/upload-pages-artifact@v1
2930
with:

.github/workflows/node.js.yml

+2-12
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,10 @@ permissions:
88
contents: read # to fetch code (actions/checkout)
99

1010
jobs:
11-
lint:
12-
runs-on: ubuntu-latest
13-
steps:
14-
- uses: actions/checkout@v3
15-
- uses: actions/setup-node@v3
16-
with:
17-
node-version: 20
18-
- run: npm ci --ignore-scripts
19-
- run: npm run lint
20-
2111
test:
2212
strategy:
2313
matrix:
24-
node-version: [16, 18, 20]
14+
node-version: [18, 20]
2515
os: [ubuntu-latest, macOS-latest, windows-latest]
2616
runs-on: ${{ matrix.os }}
2717
steps:
@@ -31,4 +21,4 @@ jobs:
3121
node-version: ${{ matrix.node-version }}
3222
- run: npm --version
3323
- run: npm ci --ignore-scripts
34-
- run: npm test
24+
- run: ./test.sh

.github/workflows/npm_publish.yml

+3-6
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ jobs:
1818
- uses: actions/checkout@v3
1919
- uses: actions/setup-node@v3
2020
with:
21-
node-version: 18
22-
- run: npm ci
23-
- run: npm test
21+
node-version: 20
22+
- run: ./test.sh
2423

2524
publish-npm:
2625
needs: build
@@ -31,9 +30,7 @@ jobs:
3130
- uses: actions/checkout@v3
3231
- uses: actions/setup-node@v3
3332
with:
34-
node-version: 18
35-
- run: npm ci
36-
- run: npm run build
33+
node-version: 20
3734
- run: npm publish --provenance --access public
3835
env:
3936
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
lib
21
node_modules
3-
husky-*.tgz
4-
tsconfig.tsbuildinfo
52
*.log
63
docs/.vitepress/cache
74
docs/.vitepress/dist
5+
docs/.env
6+
docs/sponsorkit/.cache.json
7+
docs/sponsorkit/sponsors.json
8+
docs/sponsorkit/sponsors.png

.husky/commit-msg

-4
This file was deleted.

.husky/pre-commit

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
#!/usr/bin/env sh
2-
. "$(dirname -- "$0")/_/husky.sh"
3-
4-
npm test
2+
./test.sh

.npmignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.*
2+
test*
3+
docs

.shellcheckrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
disable=SC1090,SC2164

CONTRIBUTING.md

-1
This file was deleted.

README.md

-37
Original file line numberDiff line numberDiff line change
@@ -1,38 +1 @@
1-
# husky
2-
3-
> Modern native Git hooks made easy
4-
5-
Husky improves your commits and more 🐶 *woof!*
6-
7-
# Install
8-
9-
```
10-
npm install husky --save-dev
11-
```
12-
13-
# Usage
14-
15-
Edit `package.json > prepare` script and run it once:
16-
17-
```sh
18-
npm pkg set scripts.prepare="husky install"
19-
npm run prepare
20-
```
21-
22-
Add a hook:
23-
24-
```sh
25-
npx husky add .husky/pre-commit "npm test"
26-
git add .husky/pre-commit
27-
```
28-
29-
Make a commit:
30-
31-
```sh
32-
git commit -m "Keep calm and commit"
33-
# `npm test` will run
34-
```
35-
36-
# Documentation
37-
381
https://typicode.github.io/husky

bin.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env node
2+
import f, { writeFileSync as w } from 'fs'
3+
import i from './index.js'
4+
5+
let a = process.argv[2]
6+
7+
if (a == 'init') {
8+
let p = process.env.npm_package_json
9+
let d = JSON.parse(f.readFileSync(p))
10+
d.scripts.prepare = 'husky'
11+
w('package.json', JSON.stringify(d, null, /\t/.test() ? '\t' : 2))
12+
process.stdout.write(i())
13+
w('.husky/pre-commit', process.env.npm_config_user_agent.split('/')[0] + ' test')
14+
process.exit()
15+
}
16+
17+
let d = c => console.error(`${c} command is deprecated`)
18+
if (['add', 'set', 'uninstall'].includes(a)) { d(a); process.exit(1) }
19+
if (a == 'install') d(a)
20+
21+
process.stdout.write(i(a == 'install' ? undefined : a))

docs/.vitepress/config.mts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { defineConfig } from 'vitepress'
2+
3+
// https://vitepress.dev/reference/site-config
4+
export default defineConfig({
5+
title: "Husky",
6+
description: "Git hooks made easy",
7+
base: '/husky/',
8+
themeConfig: {
9+
// outline: [2, 3],
10+
socialLinks: [
11+
{ icon: 'github', link: 'https://github.com/typicode/husky' },
12+
],
13+
carbonAds: {
14+
code: 'CWYDP53L',
15+
placement: 'typicodegithubio',
16+
},
17+
sidebar: [
18+
{ text: 'Introduction', link: '/' },
19+
{ text: 'Get Started', link: '/get-started' },
20+
{ text: 'How To', link: '/how-to' },
21+
{ text: 'Troubleshoot', link: '/troubleshoot' },
22+
{ text: 'Migrate from v4', link: '/migrate-from-v4' },
23+
],
24+
}
25+
})

docs/.vitepress/config.ts

-45
This file was deleted.

docs/get-started.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Get started
2+
3+
## Install
4+
5+
::: code-group
6+
7+
```shell [npm]
8+
npm install --save-dev husky
9+
```
10+
11+
```shell [pnpm]
12+
pnpm add --save-dev husky
13+
```
14+
15+
```shell [yarn]
16+
yarn add --dev husky
17+
# Add pinst ONLY if your package is not private
18+
yarn add --dev pinst
19+
```
20+
21+
```shell [bun]
22+
bun add --dev husky
23+
```
24+
25+
:::
26+
27+
## `husky init` (recommended)
28+
29+
The `init` command simplifies setting up husky in a project. It creates a `pre-commit` script in `.husky/` and updates the `prepare` script in `package.json`. Modifications can be made later to suit your workflow.
30+
31+
::: code-group
32+
33+
```shell [npm]
34+
npx husky init
35+
```
36+
37+
```shell [pnpm]
38+
pnpm exec husky init
39+
```
40+
41+
```shell [yarn]
42+
# Due to specific caveats and differences with other package managers,
43+
# refer to the How To section.
44+
```
45+
46+
```shell [bun]
47+
bunx husky init
48+
```
49+
50+
:::
51+
52+
53+
## Try it
54+
55+
Congratulations! You've successfully set up your first Git hook with just one command 🎉. Let's test it:
56+
57+
```shell
58+
git commit -m "Keep calm and commit"
59+
# test script will run every time you commit
60+
```
61+
62+
_For manual setup and more information, see the [How To](how-to) section._
63+

0 commit comments

Comments
 (0)