Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(husky): remove no longer needed npm exec since 9.1.1 #1760

Merged
merged 2 commits into from
Jul 22, 2024

Conversation

dependabot[bot]
Copy link
Contributor

@dependabot dependabot bot commented on behalf of github Jul 22, 2024

Bumps husky from 9.0.11 to 9.1.1.

Release notes

Sourced from husky's releases.

v9.1.1

Super saiyan god dog! It's over 9.0.0!

What's new

You can now run package commands directly, no need for npx or equivalents. It makes writing hooks more intuitive and is also slightly faster 🐺⚡️

# .husky/pre-commit
- npx jest
+ jest # ~0.2s faster

A new recipe has been added to the docs. Lint staged files without external dependencies (inspired by Prettier docs). Feel free to modify it.

# .husky/pre-commit
prettier $(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g') --write --ignore-unknown
git update-index --again

For more advanced use cases, see lint-staged.

Fixes

  • bunx husky init command
  • Workaround for some hooks implementation on Windows

Deprecations

  • #!/usr/bin/env sh and . "$(dirname -- "$0")/_/husky.sh" are deprecated. husky command will automatically remove them, no action required.
  • If you're having code in ~/.huskyrc please move it to .config/husky/init.sh

Support for these will be removed in v10.

Friendly reminder

If Git hooks don't fit your workflow, you can disable Husky globally. Just add export HUSKY=0 to .config/husky/init.sh.

I've seen some confusion about this on X, so just a heads-up!

Sponsoring

Husky is downloaded over 45M times per month and used by ~1.5M projects. If your company wants to sponsor, you can do so here: GitHub Sponsors.

... (truncated)

Commits

Dependabot compatibility score

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options

You can trigger Dependabot actions by commenting on this PR:

  • @dependabot rebase will rebase this PR
  • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
  • @dependabot merge will merge this PR after your CI passes on it
  • @dependabot squash and merge will squash and merge this PR after your CI passes on it
  • @dependabot cancel merge will cancel a previously requested merge and block automerging
  • @dependabot reopen will reopen this PR if it is closed
  • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
  • @dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency
  • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
  • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
  • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)

@dependabot dependabot bot added dependencies Pull requests that update a dependency file javascript Pull requests that update Javascript code labels Jul 22, 2024
@github-actions github-actions bot enabled auto-merge (squash) July 22, 2024 02:16
Copy link
Contributor

Diff between husky 9.0.11 and 9.1.1
diff --git a/husky b/husky
index v9.0.11..v9.1.1 100644
--- a/husky
+++ b/husky
@@ -1,20 +1,27 @@
 #!/usr/bin/env sh
+# shellcheck disable=SC1090
 [ "$HUSKY" = "2" ] && set -x
-h="${0##*/}"
-s="${0%/*/*}/$h"
+n=$(basename "$0")
+s=$(dirname "$(dirname "$0")")/$n
 
 [ ! -f "$s" ] && exit 0
 
-for f in "${XDG_CONFIG_HOME:-$HOME/.config}/husky/init.sh" "$HOME/.huskyrc"; do
-	# shellcheck disable=SC1090
-	[ -f "$f" ] && . "$f"
-done
+if [ -f "$HOME/.huskyrc" ]; then
+	echo "husky - '~/.huskyrc' is DEPRECATED, please move your code to ~/.config/husky/init.sh"
+fi
+i="${XDG_CONFIG_HOME:-$HOME/.config}/husky/init.sh"
+[ -f "$i" ] && . "$i"
 
\ No newline at end of file
 [ "${HUSKY-}" = "0" ] && exit 0
 
-sh -e "$s" "$@"
-c=$?
-
-[ $c != 0 ] && echo "husky - $h script failed (code $c)"
-[ $c = 127 ] && echo "husky - command not found in PATH=$PATH"
-exit $c
+c=0
+h() {
+	[ $c = 0 ] && return
+	[ $c != 0 ] && echo "husky - $n script failed (code $c)"
+	[ $c = 127 ] && echo "husky - command not found in PATH=$PATH"
+	exit 1
+}
+trap 'c=$?; h' EXIT
+set -e
+PATH=node_modules/.bin:$PATH
+. "$s"
\ No newline at end of file
diff --git a/package.json b/package.json
index v9.0.11..v9.1.1 100644
--- a/package.json
+++ b/package.json
@@ -1,5 +1,6 @@
 {
 	"name": "husky",
-	"version": "9.0.11",
+	"version": "9.1.1",
+	"type": "module",
 	"description": "Modern native Git hooks",
 	"keywords": [
@@ -16,7 +17,7 @@
 	"author": "typicode",
 	"bin": {
-		"husky": "bin.mjs"
+		"husky": "bin.js"
 	},
-	"exports": "./index.mjs",
+	"exports": "./index.js",
 	"engines": {
 		"node": ">=18"
diff --git a/bin.mjs b/bin.mjs
deleted file mode 100755
index v9.0.11..v9.1.1 
--- a/bin.mjs
+++ b/bin.mjs
@@ -1,26 +0,0 @@
-#!/usr/bin/env node
-import f, { writeFileSync as w } from 'fs'
-import i from './index.mjs'
-
-let p, a, n, s, o, d
-
-p = process
-a = p.argv[2]
-
-if (a == 'init') {
-	n = 'package.json'
-	s = f.readFileSync(n)
-	o = JSON.parse(s)
-	;(o.scripts ||= {}).prepare = 'husky'
-	w(n, JSON.stringify(o, 0, /\t/.test(s) ? '\t' : 2) + '\n')
-	p.stdout.write(i())
-	try { f.mkdirSync('.husky') } catch {}
-	w('.husky/pre-commit', p.env.npm_config_user_agent.split('/')[0] + ' test\n')
-	p.exit()
-}
-
-d = c => console.error(`${c} command is deprecated`)
-if (['add', 'set', 'uninstall'].includes(a)) { d(a); p.exit(1) }
-if (a == 'install') d(a)
-
-p.stdout.write(i(a == 'install' ? undefined : a))
\ No newline at end of file
diff --git a/index.mjs b/index.mjs
deleted file mode 100644
index v9.0.11..v9.1.1 
--- a/index.mjs
+++ b/index.mjs
@@ -1,23 +0,0 @@
-import c from 'child_process'
-import f, { 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' ]
-
-export default (d = '.husky') => {
-	if (process.env.HUSKY === '0') return 'HUSKY=0 skip install'
-	if (d.includes('..')) return '.. not allowed'
-	if (!f.existsSync('.git')) return `.git can't be found`
-
-	let _ = (x = '') => p.join(d, '_', x)
-	let { status: s, stderr: e } = c.spawnSync('git', ['config', 'core.hooksPath', `${d}/_`])
-	if (s == null) return 'git command not found'
-	if (s) return '' + e
-
-	f.mkdirSync(_(), { recursive: true })
-	w(_('.gitignore'), '*')
-	f.copyFileSync(new URL('husky', import.meta.url), _('h'))
-	l.forEach(h => w(_(h), `#!/usr/bin/env sh\n. "\${0%/*}/h"`, { mode: 0o755 }))
-	w(_('husky.sh'), '')
-	return ''
-}
\ No newline at end of file
diff --git a/index.d.mts b/index.d.mts
deleted file mode 100644
index v9.0.11..v9.1.1 
--- a/index.d.mts
+++ b/index.d.mts
@@ -1,1 +0,0 @@
-export default function (dir?: string): string;
\ No newline at end of file
diff --git a/bin.js b/bin.js
new file mode 100755
index v9.0.11..v9.1.1 
--- a/bin.js
+++ b/bin.js
@@ -0,0 +1,26 @@
+#!/usr/bin/env node
+import f, { writeFileSync as w } from 'fs'
+import i from './index.js'
+
+let p, a, n, s, o, d
+
+p = process
+a = p.argv[2]
+
+if (a == 'init') {
+	n = 'package.json'
+	s = f.readFileSync(n)
+	o = JSON.parse(s)
+	;(o.scripts ||= {}).prepare = 'husky'
+	w(n, JSON.stringify(o, 0, /\t/.test(s) ? '\t' : 2) + '\n')
+	p.stdout.write(i())
+	try { f.mkdirSync('.husky') } catch {}
+	w('.husky/pre-commit', p.env.npm_config_user_agent?.split('/')[0] ?? 'npm' + ' test\n')
+	p.exit()
+}
+
+d = c => console.error(`${c} command is DEPRECATED`)
+if (['add', 'set', 'uninstall'].includes(a)) { d(a); p.exit(1) }
+if (a == 'install') d(a)
+
+p.stdout.write(i(a == 'install' ? undefined : a))
\ No newline at end of file
diff --git a/index.js b/index.js
new file mode 100644
index v9.0.11..v9.1.1 
--- a/index.js
+++ b/index.js
@@ -0,0 +1,33 @@
+import c from 'child_process'
+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' ],
+	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'
+	if (d.includes('..')) return '.. not allowed'
+	if (!f.existsSync('.git')) return `.git can't be found`
+
+	let _ = (x = '') => p.join(d, '_', x)
+	let { status: s, stderr: e } = c.spawnSync('git', ['config', 'core.hooksPath', `${d}/_`])
+	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'))
+	l.forEach(h => w(_(h), `#!/usr/bin/env sh\n. "\$(dirname "\$0")/h"`, { mode: 0o755 }))
+	return ''
+}
\ No newline at end of file
diff --git a/index.d.ts b/index.d.ts
new file mode 100644
index v9.0.11..v9.1.1 
--- a/index.d.ts
+++ b/index.d.ts
@@ -0,0 +1,1 @@
+export default function (dir?: string): string;
\ No newline at end of file
Size Files
3.5 KB → 4.1 KB (+599 B 🟡) 7 → 7 (±0 🟢)
Command details
npm diff [email protected] [email protected] --diff-unified=2

See also the npm diff document.

Reported by ybiquitous/[email protected] (Node.js 22.5.1 and npm 10.8.2)

@dependabot dependabot bot force-pushed the dependabot/npm_and_yarn/husky-9.1.1 branch 2 times, most recently from 32cb939 to f784682 Compare July 22, 2024 02:30
@ybiquitous
Copy link
Owner

@dependabot rebase

@ybiquitous ybiquitous disabled auto-merge July 22, 2024 02:35
Bumps [husky](https://github.com/typicode/husky) from 9.0.11 to 9.1.1.
- [Release notes](https://github.com/typicode/husky/releases)
- [Commits](typicode/husky@v9.0.11...v9.1.1)

---
updated-dependencies:
- dependency-name: husky
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
@dependabot dependabot bot force-pushed the dependabot/npm_and_yarn/husky-9.1.1 branch from f784682 to 337180e Compare July 22, 2024 02:35
@github-actions github-actions bot enabled auto-merge (squash) July 22, 2024 02:35
@ybiquitous ybiquitous disabled auto-merge July 22, 2024 02:55
@ybiquitous ybiquitous changed the title build(deps): bump husky from 9.0.11 to 9.1.1 feat(husky): remove no longer needed npm exec since 9.1.1 Jul 22, 2024
@ybiquitous ybiquitous merged commit 2d0af12 into main Jul 22, 2024
6 of 7 checks passed
@ybiquitous ybiquitous deleted the dependabot/npm_and_yarn/husky-9.1.1 branch July 22, 2024 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file javascript Pull requests that update Javascript code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant