From 3c66f3380667552af40a53a4698e95cf78e8a69d Mon Sep 17 00:00:00 2001 From: Vlad Holubiev Date: Mon, 7 Mar 2022 18:12:26 +0100 Subject: [PATCH] chore: migrate to husky v7 --- .gitignore | 1 + .husky/_/husky.sh | 31 +++++++++++++++++++++++++++++++ .husky/post-commit | 3 +++ .husky/pre-commit | 3 +++ package.json | 10 ++-------- 5 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 .husky/_/husky.sh create mode 100755 .husky/post-commit create mode 100755 .husky/pre-commit diff --git a/.gitignore b/.gitignore index 09baa77f..b5a14b39 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ yarn.lock *.log .DS_Store globalConfig.json +!.husky/_/husky.sh diff --git a/.husky/_/husky.sh b/.husky/_/husky.sh new file mode 100644 index 00000000..6809ccca --- /dev/null +++ b/.husky/_/husky.sh @@ -0,0 +1,31 @@ +#!/bin/sh +if [ -z "$husky_skip_init" ]; then + debug () { + if [ "$HUSKY_DEBUG" = "1" ]; then + echo "husky (debug) - $1" + fi + } + + readonly hook_name="$(basename "$0")" + debug "starting $hook_name..." + + if [ "$HUSKY" = "0" ]; then + debug "HUSKY env variable is set to 0, skipping hook" + exit 0 + fi + + if [ -f ~/.huskyrc ]; then + debug "sourcing ~/.huskyrc" + . ~/.huskyrc + fi + + export readonly husky_skip_init=1 + sh -e "$0" "$@" + exitCode="$?" + + if [ $exitCode != 0 ]; then + echo "husky - $hook_name hook exited with code $exitCode (error)" + fi + + exit $exitCode +fi diff --git a/.husky/post-commit b/.husky/post-commit new file mode 100755 index 00000000..749d9277 --- /dev/null +++ b/.husky/post-commit @@ -0,0 +1,3 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" +git update-index --again diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 00000000..7b0aca40 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,3 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" +yarn lint-staged diff --git a/package.json b/package.json index 847a5dbf..cedf5a0b 100644 --- a/package.json +++ b/package.json @@ -22,12 +22,6 @@ "test": "jest", "test:repl": "MONGO_MEMORY_SERVER_FILE=jest-mongodb-config-repl.js jest" }, - "husky": { - "hooks": { - "pre-commit": "lint-staged", - "post-commit": "git update-index --again" - } - }, "lint-staged": { "*.{html,md,yml}": [ "prettier --write", @@ -50,8 +44,8 @@ "devDependencies": { "@shelf/eslint-config": "1.5.0", "@shelf/prettier-config": "1.0.0", - "eslint": "8.10.0", - "husky": "4.3.8", + "eslint": "7.32.0", + "husky": "7.0.4", "jest": "27.5.1", "lint-staged": "12.3.5", "mongodb": "4.2.2",