Skip to content

Commit 2060317

Browse files
committed
show message instead of automatically remove deprecated code
1 parent f6cc410 commit 2060317

File tree

6 files changed

+15
-34
lines changed

6 files changed

+15
-34
lines changed

husky

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env sh
2-
# shellcheck disable=SC1090
32
[ "$HUSKY" = "2" ] && set -x
43
n=$(basename "$0")
54
s=$(dirname "$(dirname "$0")")/$n
@@ -14,14 +13,10 @@ i="${XDG_CONFIG_HOME:-$HOME/.config}/husky/init.sh"
1413

1514
[ "${HUSKY-}" = "0" ] && exit 0
1615

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"
16+
export PATH=node_modules/.bin:$PATH
17+
sh -e "$s" "$@"
18+
c=$?
19+
20+
[ $c != 0 ] && echo "husky - $n script failed (code $c)"
21+
[ $c = 127 ] && echo "husky - command not found in PATH=$PATH"
22+
exit $c

index.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import f, { readdir, writeFileSync as w } from 'fs'
33
import p from 'path'
44

55
let l = [ 'pre-commit', 'prepare-commit-msg', 'commit-msg', 'post-commit', 'applypatch-msg', 'pre-applypatch', 'post-applypatch', 'pre-rebase', 'post-rewrite', 'post-checkout', 'post-merge', 'pre-push', 'pre-auto-gc' ],
6-
re = /^(#!\/usr\/bin\/env sh|\. "\$\(dirname -- "\$0"\)\/_\/husky\.sh")\r?\n/gm
6+
msg = `echo "husky - DEPRECATED\n\nPlease remove the following lines from your hook scripts:\n\n#!/usr/bin/env sh\n. \\"\\$(dirname -- \\"\\$0\\")/_/husky.sh\\"\n\nThey WILL FAIL in v10.0.0\n"`
77

88
export default (d = '.husky') => {
99
if (process.env.HUSKY === '0') return 'HUSKY=0 skip install'
@@ -16,18 +16,10 @@ export default (d = '.husky') => {
1616
if (s) return '' + e
1717

1818
f.rmSync(_('husky.sh'), { force: true })
19-
l.forEach(h => {
20-
let hp = p.join(d, h)
21-
if (!f.existsSync(hp)) return
22-
let prev = f.readFileSync(hp, 'utf8')
23-
let next = prev.replace(re, '')
24-
if (prev !== next) console.log(`husky - removed deprecated code from ${hp}`)
25-
f.writeFileSync(hp, next)
26-
})
27-
2819
f.mkdirSync(_(), { recursive: true })
2920
w(_('.gitignore'), '*')
3021
f.copyFileSync(new URL('husky', import.meta.url), _('h'))
3122
l.forEach(h => w(_(h), `#!/usr/bin/env sh\n. "\$(dirname "\$0")/h"`, { mode: 0o755 }))
23+
w(_('husky.sh'), msg)
3224
return ''
3325
}

test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ sh test/8_set_u.sh
1313
sh test/9_husky_0.sh
1414
sh test/10_init.sh
1515
sh test/11_time.sh
16-
sh test/12_rm_deprecated.sh
16+
sh test/12_deprecated.sh

test/12_rm_deprecated.sh test/12_deprecated.sh

+2-9
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,10 @@ install
55

66
npx --no-install husky
77

8+
git add package.json
89
cat > .husky/pre-commit <<'EOL'
9-
# foo
1010
#!/usr/bin/env sh
1111
. "$(dirname -- "$0")/_/husky.sh"
12-
# bar
1312
EOL
1413

15-
cat > expected <<'EOL'
16-
# foo
17-
# bar
18-
EOL
19-
20-
npx --no-install husky
21-
expect 0 "diff .husky/pre-commit expected"
14+
expect 0 "git commit -m foo"

test/7_node_modules_path.sh

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

88
# Test pre-commit
99
git add package.json
10-
echo 'echo "$PATH" | grep -q "node_modules/.bin"' > .husky/pre-commit
10+
# Should not fail when running hook
11+
echo 'echo "$PATH" | grep "node_modules/.bin"' > .husky/pre-commit
1112
expect 0 "git commit -m foo"

test/8_set_u.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ npx --no-install husky
77
expect_hooksPath_to_be ".husky/_"
88

99
git add package.json
10-
echo "echo \"pre-commit\"" >.husky/pre-commit
10+
echo "echo \"pre-commit\"" > .husky/pre-commit
1111

1212
# Should not fail if set -u is used
1313
mkdir -p config/husky

0 commit comments

Comments
 (0)