From eb54845768e9d38cd81a98204511de665e8dda6b Mon Sep 17 00:00:00 2001 From: typicode Date: Thu, 18 Jul 2024 14:25:45 +0200 Subject: [PATCH] automatically rm deprecated code --- docs/sponsorkit/sponsors.svg | 266 ++++++++++++++++++----------------- index.js | 15 +- test.sh | 1 + test/10_init.sh | 0 test/12_rm_deprecated.sh | 21 +++ test/1_default.sh | 2 +- test/6_command_not_found.sh | 2 +- test/8_set_u.sh | 0 test/9_husky_0.sh | 0 9 files changed, 171 insertions(+), 136 deletions(-) mode change 100644 => 100755 test/10_init.sh create mode 100755 test/12_rm_deprecated.sh mode change 100644 => 100755 test/8_set_u.sh mode change 100644 => 100755 test/9_husky_0.sh diff --git a/docs/sponsorkit/sponsors.svg b/docs/sponsorkit/sponsors.svg index 3d5338282..3c5c7563b 100644 --- a/docs/sponsorkit/sponsors.svg +++ b/docs/sponsorkit/sponsors.svg @@ -16,61 +16,57 @@ text { } Gold Sponsors - Zuplo - - - - Microsoft - + Zuplo + Silver Sponsors Kong Bronze Sponsors - risedotcom - + risedotcom + - Storyblok - + Storyblok + - Better Stack - + Better Stack + + + + Route4Me + Sponsors - Ehren - + Ehren + - Erik Gross - + Erik Gross + - Cased - + Cased + - Dustin - + Dustin + - Extremely - - - - Jamie - + Extremely + - Comarch - + Comarch + - Mercury - + Mercury + - Ray Foss - + Ray Foss + Backers @@ -176,7 +172,7 @@ text { - + @@ -308,264 +304,270 @@ text { + + + - + - + - + - + + + - - - - + + - + - + - + - + - + - + - + - + - + - + - + - + + + + - + - + - + - + - + - + - + - + - - - - + + + - - - + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - + + + - - - + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - + + + - - - + + + + - + - + - + - + - + - + - + - + - + - + diff --git a/index.js b/index.js index 73f55d39a..29966479f 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,9 @@ import c from 'child_process' -import f, { writeFileSync as w } from 'fs' +import f, { readdir, writeFileSync as w } from 'fs' import p from 'path' -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' ] +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' ], + re = /^(#!\/usr\/bin\/env sh|\. "\$\(dirname -- "\$0"\)\/_\/husky\.sh")\r?\n/gm export default (d = '.husky') => { if (process.env.HUSKY === '0') return 'HUSKY=0 skip install' @@ -14,6 +15,16 @@ export default (d = '.husky') => { if (s == null) return 'git command not found' if (s) return '' + e + f.rmSync(_('husky.sh'), { force: true }) + l.forEach(h => { + let hp = p.join(d, h) + if (!f.existsSync(hp)) return + let prev = f.readFileSync(hp, 'utf8') + let next = prev.replace(re, '') + if (prev !== next) console.log(`husky - removed deprecated code from ${hp}`) + f.writeFileSync(hp, next) + }) + f.mkdirSync(_(), { recursive: true }) w(_('.gitignore'), '*') f.copyFileSync(new URL('husky', import.meta.url), _('h')) diff --git a/test.sh b/test.sh index 4153af277..3ca0a5eaf 100755 --- a/test.sh +++ b/test.sh @@ -13,3 +13,4 @@ sh test/8_set_u.sh sh test/9_husky_0.sh sh test/10_init.sh sh test/11_time.sh +sh test/12_rm_deprecated.sh \ No newline at end of file diff --git a/test/10_init.sh b/test/10_init.sh old mode 100644 new mode 100755 diff --git a/test/12_rm_deprecated.sh b/test/12_rm_deprecated.sh new file mode 100755 index 000000000..7f6755cdb --- /dev/null +++ b/test/12_rm_deprecated.sh @@ -0,0 +1,21 @@ +#!/bin/sh +. test/functions.sh +setup +install + +npx --no-install husky + +cat > .husky/pre-commit <<'EOL' +# foo +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" +# bar +EOL + +cat > expected <<'EOL' +# foo +# bar +EOL + +npx --no-install husky +expect 0 "diff .husky/pre-commit expected" \ No newline at end of file diff --git a/test/1_default.sh b/test/1_default.sh index ac0162b8d..93b6bdafa 100755 --- a/test/1_default.sh +++ b/test/1_default.sh @@ -10,5 +10,5 @@ expect_hooksPath_to_be ".husky/_" # Test pre-commit git add package.json -echo "echo \"pre-commit\" && exit 1" >.husky/pre-commit +echo "echo \"pre-commit\" && exit 1" > .husky/pre-commit expect 1 "git commit -m foo" diff --git a/test/6_command_not_found.sh b/test/6_command_not_found.sh index 99f78bd84..2c0f99203 100755 --- a/test/6_command_not_found.sh +++ b/test/6_command_not_found.sh @@ -10,5 +10,5 @@ expect_hooksPath_to_be ".husky/_" # Test pre-commit with 127 exit code git add package.json -echo "exit 127" >.husky/pre-commit +echo "exit 127" > .husky/pre-commit expect 1 "git commit -m foo" diff --git a/test/8_set_u.sh b/test/8_set_u.sh old mode 100644 new mode 100755 diff --git a/test/9_husky_0.sh b/test/9_husky_0.sh old mode 100644 new mode 100755