mirror of https://github.com/typicode/husky.git
v9.1.0 (#1467)
This commit is contained in:
parent
da40de3edd
commit
e0994a4f60
|
@ -11,12 +11,12 @@ jobs:
|
||||||
test:
|
test:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [18, 20]
|
node-version: [18, 20, 22]
|
||||||
os: [ubuntu-latest, macOS-latest, windows-latest]
|
os: [ubuntu-latest, macOS-latest, windows-latest]
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node-version }}
|
node-version: ${{ matrix.node-version }}
|
||||||
- run: npm --version
|
- run: npm --version
|
||||||
|
|
|
@ -15,7 +15,7 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 20
|
||||||
- run: ./test.sh
|
- run: ./test.sh
|
||||||
|
@ -27,7 +27,7 @@ jobs:
|
||||||
id-token: write
|
id-token: write
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 20
|
||||||
registry-url: 'https://registry.npmjs.org'
|
registry-url: 'https://registry.npmjs.org'
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
import f, { writeFileSync as w } from 'fs'
|
import f, { writeFileSync as w } from 'fs'
|
||||||
import i from './index.mjs'
|
import i from './index.js'
|
||||||
|
|
||||||
let p, a, n, s, o, d
|
let p, a, n, s, o, d
|
||||||
|
|
||||||
|
@ -15,11 +15,11 @@ if (a == 'init') {
|
||||||
w(n, JSON.stringify(o, 0, /\t/.test(s) ? '\t' : 2) + '\n')
|
w(n, JSON.stringify(o, 0, /\t/.test(s) ? '\t' : 2) + '\n')
|
||||||
p.stdout.write(i())
|
p.stdout.write(i())
|
||||||
try { f.mkdirSync('.husky') } catch {}
|
try { f.mkdirSync('.husky') } catch {}
|
||||||
w('.husky/pre-commit', p.env.npm_config_user_agent.split('/')[0] + ' test\n')
|
w('.husky/pre-commit', p.env.npm_config_user_agent?.split('/')[0] ?? 'npm' + ' test\n')
|
||||||
p.exit()
|
p.exit()
|
||||||
}
|
}
|
||||||
|
|
||||||
d = c => console.error(`${c} command is deprecated`)
|
d = c => console.error(`${c} command is DEPRECATED`)
|
||||||
if (['add', 'set', 'uninstall'].includes(a)) { d(a); p.exit(1) }
|
if (['add', 'set', 'uninstall'].includes(a)) { d(a); p.exit(1) }
|
||||||
if (a == 'install') d(a)
|
if (a == 'install') d(a)
|
||||||
|
|
|
@ -12,11 +12,12 @@ export default defineConfig({
|
||||||
// outline: [2, 3],
|
// outline: [2, 3],
|
||||||
socialLinks: [
|
socialLinks: [
|
||||||
{ icon: 'github', link: 'https://github.com/typicode/husky' },
|
{ icon: 'github', link: 'https://github.com/typicode/husky' },
|
||||||
|
{ icon: 'twitter', link: 'https://x.com/typicode' }
|
||||||
],
|
],
|
||||||
carbonAds: {
|
// carbonAds: {
|
||||||
code: 'CWYDP53L',
|
// code: 'CWYDP53L',
|
||||||
placement: 'typicodegithubio',
|
// placement: 'typicodegithubio',
|
||||||
},
|
// },
|
||||||
sidebar: [
|
sidebar: [
|
||||||
{ text: 'Introduction', link: '/' },
|
{ text: 'Introduction', link: '/' },
|
||||||
{ text: 'Get Started', link: '/get-started' },
|
{ text: 'Get Started', link: '/get-started' },
|
||||||
|
@ -25,15 +26,7 @@ export default defineConfig({
|
||||||
{ text: 'Migrate from v4', link: '/migrate-from-v4' },
|
{ text: 'Migrate from v4', link: '/migrate-from-v4' },
|
||||||
],
|
],
|
||||||
nav: [
|
nav: [
|
||||||
{
|
{ text: 'Sponsor', link: 'https://github.com/sponsors/typicode' }
|
||||||
text: 'v9.0.1',
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
text: 'Changelog',
|
|
||||||
link: 'https://github.com/typicode/husky/releases/tag/v9.0.1'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
locales: {
|
locales: {
|
||||||
|
|
|
@ -59,5 +59,22 @@ git commit -m "Keep calm and commit"
|
||||||
# test script will run every time you commit
|
# test script will run every time you commit
|
||||||
```
|
```
|
||||||
|
|
||||||
_For manual setup and more information, see the [How To](how-to) section._
|
## A few words...
|
||||||
|
|
||||||
|
### Scripting
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
# .husky/pre-commit
|
||||||
|
prettier $(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g') --write --ignore-unknown
|
||||||
|
git update-index --again
|
||||||
|
```
|
||||||
|
|
||||||
|
_This is a basic but workinkg example, check [lint-staged](https://github.com/lint-staged/lint-staged) if you need more._
|
||||||
|
|
||||||
|
### Disabling hooks
|
||||||
|
|
||||||
|
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.
|
|
@ -26,6 +26,7 @@ And more:
|
||||||
- Adheres to Git's native hook organization
|
- Adheres to Git's native hook organization
|
||||||
- Aligns with [npm](https://docs.npmjs.com/cli/v10/using-npm/scripts#best-practices) best practices using `prepare` script
|
- Aligns with [npm](https://docs.npmjs.com/cli/v10/using-npm/scripts#best-practices) best practices using `prepare` script
|
||||||
- Opt-in/opt-out options
|
- Opt-in/opt-out options
|
||||||
|
- Can be globally disabled
|
||||||
- User-friendly error messages
|
- User-friendly error messages
|
||||||
|
|
||||||
## Sponsors
|
## Sponsors
|
||||||
|
@ -60,7 +61,7 @@ Support this project by becoming a sponsor [here](https://github.com/sponsors/ty
|
||||||
|
|
||||||
## Used by
|
## Used by
|
||||||
|
|
||||||
Husky is used in [**over 1.3M projects**](https://github.com/typicode/husky/network/dependents?package_id=UGFja2FnZS0xODQzNTgwNg%3D%3D) on GitHub, including:
|
Husky is used in [**over 1.5M projects**](https://github.com/typicode/husky/network/dependents?package_id=UGFja2FnZS0xODQzNTgwNg%3D%3D) on GitHub, including:
|
||||||
|
|
||||||
- [vercel/next.js](https://github.com/vercel/next.js)
|
- [vercel/next.js](https://github.com/vercel/next.js)
|
||||||
- [vercel/hyper](https://github.com/vercel/hyper)
|
- [vercel/hyper](https://github.com/vercel/hyper)
|
||||||
|
|
|
@ -35,10 +35,7 @@ If you were calling locally installed binaries, **you need to run them via your
|
||||||
```
|
```
|
||||||
|
|
||||||
```shell [.husky/pre-commit (v9)]
|
```shell [.husky/pre-commit (v9)]
|
||||||
# ...
|
jest
|
||||||
npx --no jest
|
|
||||||
# or
|
|
||||||
yarn jest
|
|
||||||
```
|
```
|
||||||
|
|
||||||
:::
|
:::
|
||||||
|
@ -56,10 +53,7 @@ yarn jest
|
||||||
```
|
```
|
||||||
|
|
||||||
```shell [.husky/commit-msg (v9)]
|
```shell [.husky/commit-msg (v9)]
|
||||||
# ...
|
commitlint --edit $1
|
||||||
npx --no -- commitlint --edit $1
|
|
||||||
# or
|
|
||||||
yarn commitlint --edit $1
|
|
||||||
```
|
```
|
||||||
|
|
||||||
:::
|
:::
|
||||||
|
@ -68,5 +62,4 @@ Other environment variables changes:
|
||||||
|
|
||||||
- `HUSKY_SKIP_HOOKS` is replaced by `HUSKY`.
|
- `HUSKY_SKIP_HOOKS` is replaced by `HUSKY`.
|
||||||
- `HUSKY_SKIP_INSTALL` 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`).
|
- `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.
|
|
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 508 KiB After Width: | Height: | Size: 532 KiB |
31
husky
31
husky
|
@ -1,20 +1,27 @@
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
|
# shellcheck disable=SC1090
|
||||||
[ "$HUSKY" = "2" ] && set -x
|
[ "$HUSKY" = "2" ] && set -x
|
||||||
h="${0##*/}"
|
n=$(basename "$0")
|
||||||
s="${0%/*/*}/$h"
|
s=$(dirname "$(dirname "$0")")/$n
|
||||||
|
|
||||||
[ ! -f "$s" ] && exit 0
|
[ ! -f "$s" ] && exit 0
|
||||||
|
|
||||||
for f in "${XDG_CONFIG_HOME:-$HOME/.config}/husky/init.sh" "$HOME/.huskyrc"; do
|
if [ -f "$HOME/.huskyrc" ]; then
|
||||||
# shellcheck disable=SC1090
|
echo "husky - '~/.huskyrc' is DEPRECATED, please move your code to ~/.config/husky/init.sh"
|
||||||
[ -f "$f" ] && . "$f"
|
fi
|
||||||
done
|
i="${XDG_CONFIG_HOME:-$HOME/.config}/husky/init.sh"
|
||||||
|
[ -f "$i" ] && . "$i"
|
||||||
|
|
||||||
[ "${HUSKY-}" = "0" ] && exit 0
|
[ "${HUSKY-}" = "0" ] && exit 0
|
||||||
|
|
||||||
sh -e "$s" "$@"
|
c=0
|
||||||
c=$?
|
h() {
|
||||||
|
[ $c = 0 ] && return
|
||||||
[ $c != 0 ] && echo "husky - $h script failed (code $c)"
|
[ $c != 0 ] && echo "husky - $n script failed (code $c)"
|
||||||
[ $c = 127 ] && echo "husky - command not found in PATH=$PATH"
|
[ $c = 127 ] && echo "husky - command not found in PATH=$PATH"
|
||||||
exit $c
|
exit 1
|
||||||
|
}
|
||||||
|
trap 'c=$?; h' EXIT
|
||||||
|
set -e
|
||||||
|
PATH=node_modules/.bin:$PATH
|
||||||
|
. "$s"
|
|
@ -18,6 +18,6 @@ export default (d = '.husky') => {
|
||||||
w(_('.gitignore'), '*')
|
w(_('.gitignore'), '*')
|
||||||
f.copyFileSync(new URL('husky', import.meta.url), _('h'))
|
f.copyFileSync(new URL('husky', import.meta.url), _('h'))
|
||||||
l.forEach(h => w(_(h), `#!/usr/bin/env sh\n. "\${0%/*}/h"`, { mode: 0o755 }))
|
l.forEach(h => w(_(h), `#!/usr/bin/env sh\n. "\${0%/*}/h"`, { mode: 0o755 }))
|
||||||
w(_('husky.sh'), '')
|
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"')
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "husky",
|
"name": "husky",
|
||||||
"version": "9.0.11",
|
"version": "9.0.11",
|
||||||
|
"type": "module",
|
||||||
"description": "Modern native Git hooks",
|
"description": "Modern native Git hooks",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"git",
|
"git",
|
||||||
|
@ -15,9 +16,9 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"author": "typicode",
|
"author": "typicode",
|
||||||
"bin": {
|
"bin": {
|
||||||
"husky": "bin.mjs"
|
"husky": "bin.js"
|
||||||
},
|
},
|
||||||
"exports": "./index.mjs",
|
"exports": "./index.js",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
|
|
6
tea.yaml
6
tea.yaml
|
@ -1,6 +0,0 @@
|
||||||
# https://tea.xyz/what-is-this-file
|
|
||||||
---
|
|
||||||
version: 1.0.0
|
|
||||||
codeOwners:
|
|
||||||
- '0xeB520938F9A236E6ff1D001551f9731F97a38023'
|
|
||||||
quorum: 1
|
|
9
test.sh
9
test.sh
|
@ -8,7 +8,8 @@ sh test/3_from-sub-dir.sh
|
||||||
sh test/4_not-git-dir.sh
|
sh test/4_not-git-dir.sh
|
||||||
sh test/5_git_command_not_found.sh
|
sh test/5_git_command_not_found.sh
|
||||||
sh test/6_command_not_found.sh
|
sh test/6_command_not_found.sh
|
||||||
sh test/7_set_u.sh
|
sh test/7_node_modules_path.sh
|
||||||
sh test/8_husky_0.sh
|
sh test/8_set_u.sh
|
||||||
sh test/9_init.sh
|
sh test/9_husky_0.sh
|
||||||
sh test/10_time.sh
|
sh test/10_init.sh
|
||||||
|
sh test/11_time.sh
|
||||||
|
|
|
@ -6,5 +6,5 @@ install
|
||||||
npx --no-install husky
|
npx --no-install husky
|
||||||
|
|
||||||
git add package.json
|
git add package.json
|
||||||
echo "echo pre-commit" >.husky/pre-commit
|
echo "echo pre-commit" > .husky/pre-commit
|
||||||
time git commit -m foo
|
time git commit -m foo
|
|
@ -0,0 +1,11 @@
|
||||||
|
#!/bin/sh
|
||||||
|
. test/functions.sh
|
||||||
|
setup
|
||||||
|
install
|
||||||
|
|
||||||
|
npx --no-install husky
|
||||||
|
|
||||||
|
# Test pre-commit
|
||||||
|
git add package.json
|
||||||
|
echo 'echo "$PATH" | grep -q "node_modules/.bin"' > .husky/pre-commit
|
||||||
|
expect 0 "git commit -m foo"
|
Loading…
Reference in New Issue