Skip to content

Commit e0994a4

Browse files
authored
v9.1.0 (#1467)
1 parent da40de3 commit e0994a4

19 files changed

+327
-271
lines changed

β€Ž.github/workflows/node.js.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ jobs:
1111
test:
1212
strategy:
1313
matrix:
14-
node-version: [18, 20]
14+
node-version: [18, 20, 22]
1515
os: [ubuntu-latest, macOS-latest, windows-latest]
1616
runs-on: ${{ matrix.os }}
1717
steps:
18-
- uses: actions/checkout@v3
19-
- uses: actions/setup-node@v3
18+
- uses: actions/checkout@v4
19+
- uses: actions/setup-node@v4
2020
with:
2121
node-version: ${{ matrix.node-version }}
2222
- run: npm --version

β€Ž.github/workflows/npm_publish.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v4
18-
- uses: actions/setup-node@v3
18+
- uses: actions/setup-node@v4
1919
with:
2020
node-version: 20
2121
- run: ./test.sh
@@ -27,7 +27,7 @@ jobs:
2727
id-token: write
2828
steps:
2929
- uses: actions/checkout@v4
30-
- uses: actions/setup-node@v3
30+
- uses: actions/setup-node@v4
3131
with:
3232
node-version: 20
3333
registry-url: 'https://registry.npmjs.org'

β€Žbin.mjs β€Žbin.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22
import f, { writeFileSync as w } from 'fs'
3-
import i from './index.mjs'
3+
import i from './index.js'
44

55
let p, a, n, s, o, d
66

@@ -15,11 +15,11 @@ if (a == 'init') {
1515
w(n, JSON.stringify(o, 0, /\t/.test(s) ? '\t' : 2) + '\n')
1616
p.stdout.write(i())
1717
try { f.mkdirSync('.husky') } catch {}
18-
w('.husky/pre-commit', p.env.npm_config_user_agent.split('/')[0] + ' test\n')
18+
w('.husky/pre-commit', p.env.npm_config_user_agent?.split('/')[0] ?? 'npm' + ' test\n')
1919
p.exit()
2020
}
2121

22-
d = c => console.error(`${c} command is deprecated`)
22+
d = c => console.error(`${c} command is DEPRECATED`)
2323
if (['add', 'set', 'uninstall'].includes(a)) { d(a); p.exit(1) }
2424
if (a == 'install') d(a)
2525

β€Ždocs/.vitepress/config.mts

+6-13
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ export default defineConfig({
1212
// outline: [2, 3],
1313
socialLinks: [
1414
{ icon: 'github', link: 'https://github.com/typicode/husky' },
15+
{ icon: 'twitter', link: 'https://x.com/typicode' }
1516
],
16-
carbonAds: {
17-
code: 'CWYDP53L',
18-
placement: 'typicodegithubio',
19-
},
17+
// carbonAds: {
18+
// code: 'CWYDP53L',
19+
// placement: 'typicodegithubio',
20+
// },
2021
sidebar: [
2122
{ text: 'Introduction', link: '/' },
2223
{ text: 'Get Started', link: '/get-started' },
@@ -25,15 +26,7 @@ export default defineConfig({
2526
{ text: 'Migrate from v4', link: '/migrate-from-v4' },
2627
],
2728
nav: [
28-
{
29-
text: 'v9.0.1',
30-
items: [
31-
{
32-
text: 'Changelog',
33-
link: 'https://github.com/typicode/husky/releases/tag/v9.0.1'
34-
}
35-
]
36-
}
29+
{ text: 'Sponsor', link: 'https://github.com/sponsors/typicode' }
3730
]
3831
},
3932
locales: {

β€Ždocs/get-started.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,22 @@ git commit -m "Keep calm and commit"
5959
# test script will run every time you commit
6060
```
6161

62-
_For manual setup and more information, see the [How To](how-to) section._
62+
## A few words...
6363

64+
### Scripting
65+
66+
While most of the time, you'll just run a few `npm run` or `npx` commands in your hooks, you can also script them using POSIX shell for custom workflows.
67+
68+
For example, here's how you can lint your staged files on each commit with only two lines of shell code and no external dependency:
69+
70+
```shell
71+
# .husky/pre-commit
72+
prettier $(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g') --write --ignore-unknown
73+
git update-index --again
74+
```
75+
76+
_This is a basic but workinkg example, check [lint-staged](https://github.com/lint-staged/lint-staged) if you need more._
77+
78+
### Disabling hooks
79+
80+
Husky doesn't force Git hooks. It can be globally disabled (`HUSKY=0`) or be opt-in if wanted. See the [How To](how-to) section for manual setup and more information.

β€Ždocs/index.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ And more:
2626
- Adheres to Git's native hook organization
2727
- Aligns with [npm](https://docs.npmjs.com/cli/v10/using-npm/scripts#best-practices) best practices using `prepare` script
2828
- Opt-in/opt-out options
29+
- Can be globally disabled
2930
- User-friendly error messages
3031

3132
## Sponsors
@@ -60,7 +61,7 @@ Support this project by becoming a sponsor [here](https://github.com/sponsors/ty
6061

6162
## Used by
6263

63-
Husky is used in [**over 1.3M projects**](https://github.com/typicode/husky/network/dependents?package_id=UGFja2FnZS0xODQzNTgwNg%3D%3D) on GitHub, including:
64+
Husky is used in [**over 1.5M projects**](https://github.com/typicode/husky/network/dependents?package_id=UGFja2FnZS0xODQzNTgwNg%3D%3D) on GitHub, including:
6465

6566
- [vercel/next.js](https://github.com/vercel/next.js)
6667
- [vercel/hyper](https://github.com/vercel/hyper)

β€Ždocs/migrate-from-v4.md

+3-10
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ If you were calling locally installed binaries, **you need to run them via your
3535
```
3636

3737
```shell [.husky/pre-commit (v9)]
38-
# ...
39-
npx --no jest
40-
# or
41-
yarn jest
38+
jest
4239
```
4340

4441
:::
@@ -56,10 +53,7 @@ yarn jest
5653
```
5754

5855
```shell [.husky/commit-msg (v9)]
59-
# ...
60-
npx --no -- commitlint --edit $1
61-
# or
62-
yarn commitlint --edit $1
56+
commitlint --edit $1
6357
```
6458

6559
:::
@@ -68,5 +62,4 @@ Other environment variables changes:
6862

6963
- `HUSKY_SKIP_HOOKS` is replaced by `HUSKY`.
7064
- `HUSKY_SKIP_INSTALL` is replaced by `HUSKY`.
71-
- `HUSKY_GIT_PARAMS` is removed. Instead Git parameters should be used directly in scripts (e.g. `$1`).
72-
- `PATH` for locally installed tools is not automatically set anymore. You'll need to use your package manager to run them.
65+
- `HUSKY_GIT_PARAMS` is removed. Instead Git parameters should be used directly in scripts (e.g. `$1`).

β€Ždocs/sponsorkit/sponsors.svg

+250-212
Loading

β€Žhusky

+19-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
#!/usr/bin/env sh
2+
# shellcheck disable=SC1090
23
[ "$HUSKY" = "2" ] && set -x
3-
h="${0##*/}"
4-
s="${0%/*/*}/$h"
4+
n=$(basename "$0")
5+
s=$(dirname "$(dirname "$0")")/$n
56

67
[ ! -f "$s" ] && exit 0
78

8-
for f in "${XDG_CONFIG_HOME:-$HOME/.config}/husky/init.sh" "$HOME/.huskyrc"; do
9-
# shellcheck disable=SC1090
10-
[ -f "$f" ] && . "$f"
11-
done
9+
if [ -f "$HOME/.huskyrc" ]; then
10+
echo "husky - '~/.huskyrc' is DEPRECATED, please move your code to ~/.config/husky/init.sh"
11+
fi
12+
i="${XDG_CONFIG_HOME:-$HOME/.config}/husky/init.sh"
13+
[ -f "$i" ] && . "$i"
1214

1315
[ "${HUSKY-}" = "0" ] && exit 0
1416

15-
sh -e "$s" "$@"
16-
c=$?
17-
18-
[ $c != 0 ] && echo "husky - $h script failed (code $c)"
19-
[ $c = 127 ] && echo "husky - command not found in PATH=$PATH"
20-
exit $c
17+
c=0
18+
h() {
19+
[ $c = 0 ] && return
20+
[ $c != 0 ] && echo "husky - $n script failed (code $c)"
21+
[ $c = 127 ] && echo "husky - command not found in PATH=$PATH"
22+
exit 1
23+
}
24+
trap 'c=$?; h' EXIT
25+
set -e
26+
PATH=node_modules/.bin:$PATH
27+
. "$s"

β€Žindex.d.mts β€Žindex.d.ts

File renamed without changes.

β€Žindex.mjs β€Žindex.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ export default (d = '.husky') => {
1818
w(_('.gitignore'), '*')
1919
f.copyFileSync(new URL('husky', import.meta.url), _('h'))
2020
l.forEach(h => w(_(h), `#!/usr/bin/env sh\n. "\${0%/*}/h"`, { mode: 0o755 }))
21-
w(_('husky.sh'), '')
21+
w(_('husky.sh'), 'echo "husky - `#!/usr/bin/env sh` and `. "$(dirname -- "$0")/_/husky.sh"` lines in hooks are DEPRECATED and won\'t be supported in v10. You can remove these two lines for even simpler scripts"')
2222
return ''
2323
}

β€Žpackage.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "husky",
33
"version": "9.0.11",
4+
"type": "module",
45
"description": "Modern native Git hooks",
56
"keywords": [
67
"git",
@@ -15,9 +16,9 @@
1516
"license": "MIT",
1617
"author": "typicode",
1718
"bin": {
18-
"husky": "bin.mjs"
19+
"husky": "bin.js"
1920
},
20-
"exports": "./index.mjs",
21+
"exports": "./index.js",
2122
"engines": {
2223
"node": ">=18"
2324
}

β€Žtea.yaml

-6
This file was deleted.

β€Žtest.sh

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ sh test/3_from-sub-dir.sh
88
sh test/4_not-git-dir.sh
99
sh test/5_git_command_not_found.sh
1010
sh test/6_command_not_found.sh
11-
sh test/7_set_u.sh
12-
sh test/8_husky_0.sh
13-
sh test/9_init.sh
14-
sh test/10_time.sh
11+
sh test/7_node_modules_path.sh
12+
sh test/8_set_u.sh
13+
sh test/9_husky_0.sh
14+
sh test/10_init.sh
15+
sh test/11_time.sh
File renamed without changes.

β€Žtest/10_time.sh β€Žtest/11_time.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ install
66
npx --no-install husky
77

88
git add package.json
9-
echo "echo pre-commit" >.husky/pre-commit
9+
echo "echo pre-commit" > .husky/pre-commit
1010
time git commit -m foo

β€Žtest/7_node_modules_path.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
. test/functions.sh
3+
setup
4+
install
5+
6+
npx --no-install husky
7+
8+
# Test pre-commit
9+
git add package.json
10+
echo 'echo "$PATH" | grep -q "node_modules/.bin"' > .husky/pre-commit
11+
expect 0 "git commit -m foo"
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
Β (0)