From accbea420df7c60b97cdde153fee716a521a2451 Mon Sep 17 00:00:00 2001 From: Mike Hardy Date: Mon, 5 Apr 2021 09:42:43 -0500 Subject: [PATCH] chore: add husky and hook build/format/lint checks to pre-commit This enforces the same checks locally that will execute in CI With this, everyone should have a clean / consistent dev environment, and it will be clear to contributors if they submit code that is not valid typescript Additionally, after doing the build it adds the dist/index.js output to the commit list so contributors can't forget to commit it --- .husky/.gitignore | 1 + .husky/pre-commit | 3 +++ package.json | 6 ++++-- yarn.lock | 5 +++++ 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .husky/.gitignore create mode 100755 .husky/pre-commit diff --git a/.husky/.gitignore b/.husky/.gitignore new file mode 100644 index 00000000..31354ec1 --- /dev/null +++ b/.husky/.gitignore @@ -0,0 +1 @@ +_ diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 00000000..33feda64 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,3 @@ +#!/bin/sh +yarn build && git add dist/index.js +yarn format-check diff --git a/package.json b/package.json index 9a8e396d..1a379aef 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "build": "ncc build src/index.ts --license LICENSES.txt", "format": "prettier --write '**/*.ts'", - "format-check": "prettier --check '**/*.ts'" + "format-check": "prettier --check '**/*.ts'", + "prepare": "husky install" }, "dependencies": { "@actions/core": "1.2.6", @@ -15,6 +16,7 @@ "devDependencies": { "@vercel/ncc": "0.27.0", "prettier": "2.2.1", - "typescript": "4.1.5" + "typescript": "4.1.5", + "husky": "6.0.0" } } diff --git a/yarn.lock b/yarn.lock index efbe399a..e53b1b64 100644 --- a/yarn.lock +++ b/yarn.lock @@ -126,6 +126,11 @@ deprecation@^2.0.0, deprecation@^2.3.1: resolved "https://registry.yarnpkg.com/deprecation/-/deprecation-2.3.1.tgz#6368cbdb40abf3373b525ac87e4a260c3a700919" integrity sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ== +husky@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/husky/-/husky-6.0.0.tgz#810f11869adf51604c32ea577edbc377d7f9319e" + integrity sha512-SQS2gDTB7tBN486QSoKPKQItZw97BMOd+Kdb6ghfpBc0yXyzrddI0oDV5MkDAbuB4X2mO3/nj60TRMcYxwzZeQ== + is-plain-object@^4.0.0: version "4.1.1" resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-4.1.1.tgz#1a14d6452cbd50790edc7fdaa0aed5a40a35ebb5"