Skip to content

Commit d748eb6

Browse files
committed
v9.1.0
1 parent da40de3 commit d748eb6

17 files changed

+321
-258
lines changed

bin.mjs renamed to bin.js

+2-2
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,7 +15,7 @@ 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

docs/.vitepress/config.mts

+5-8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ 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
],
1617
carbonAds: {
1718
code: 'CWYDP53L',
@@ -26,14 +27,10 @@ export default defineConfig({
2627
],
2728
nav: [
2829
{
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-
}
30+
text: 'Changelog',
31+
link: 'https://github.com/typicode/husky/releases/tag/v9.0.1'
32+
},
33+
{ text: 'Sponsor', link: 'https://github.com/sponsors/typicode' }
3734
]
3835
},
3936
locales: {

docs/get-started.md

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

62+
## A few words
63+
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 hooks 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:
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+
See also [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 and can be globally disabled if wished. They can be made opt-in as well.
81+
6282
_For manual setup and more information, see the [How To](how-to) section._
6383

docs/index.md

+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

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 - DEPRECATED: '~/.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 renamed to index.d.ts

File renamed without changes.

index.mjs renamed to 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 - DEPRECATED `#!/usr/bin/env sh` and `. "$(dirname -- "$0")/_/husky.sh"` lines in hooks are deprecated, you can remove them safely 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 renamed to 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)