From a8e91a670071bd1a609bd31383bdfb830bd6b3ff Mon Sep 17 00:00:00 2001 From: Lee Chiang Fong Date: Mon, 20 May 2024 14:49:28 +0800 Subject: [PATCH] chore: upgrade husky setup for v9 Remove boilerplate from hook files. Move husky install from postinstall to prepare, to match husky init. Use husky's suggested script to avoid errors for npm installs without devDependencies. --- .husky/install.mjs | 6 ++++++ .husky/pre-commit | 3 --- .husky/pre-push | 3 --- package-lock.json | 1 - package.json | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) create mode 100644 .husky/install.mjs diff --git a/.husky/install.mjs b/.husky/install.mjs new file mode 100644 index 0000000..ba8e33d --- /dev/null +++ b/.husky/install.mjs @@ -0,0 +1,6 @@ +// Skip Husky install in production and CI +if (process.env.NODE_ENV === 'production' || process.env.CI === 'true') { + process.exit(0) +} +const husky = (await import('husky')).default +console.log(husky()) diff --git a/.husky/pre-commit b/.husky/pre-commit index 36af219..2312dc5 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1 @@ -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - npx lint-staged diff --git a/.husky/pre-push b/.husky/pre-push index 0473f6c..a21a749 100755 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1,4 +1 @@ -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - npx commitlint --from origin/main --to HEAD --verbose diff --git a/package-lock.json b/package-lock.json index 4bf7730..4c6c6a2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,6 @@ "": { "name": "@opengovsg/mockpass", "version": "4.2.0", - "hasInstallScript": true, "license": "MIT", "dependencies": { "base-64": "^1.0.0", diff --git a/package.json b/package.json index 4088d3c..7c3d336 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "cz": "git-cz", "lint": "eslint lib", "lint-fix": "eslint --fix lib", - "postinstall": "husky install", + "prepare": "node .husky/install.mjs", "prepublishOnly": "pinst --disable", "postpublish": "pinst --enable" },