From 1e1b289189f4c23b25b8c51d07c1a9ea4700f878 Mon Sep 17 00:00:00 2001 From: typicode Date: Sat, 5 Dec 2020 12:18:59 +0100 Subject: [PATCH] update error message --- README.md | 2 +- package.json | 13 ++----------- src/installer/bin.ts | 15 ++++++++------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 4d5e53317..5ab90643a 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Husky can prevent bad `git commit`, `git push` and more 🐶 _woof!_ **Announcement: Husky v5 has been published, to view v5 docs click [here](https://typicode.github.io/husky).** -**Note for npm 7 users** Currently `INIT_CWD` environment variable is missing in npm v7 and is required for Husky v4 to auto-install (https://github.com/npm/cli/issues/2033). To manually install husky v4, run `npx --no-install husky install .` or upgrade to husky v5. +**Note for npm v7 users** Currently `INIT_CWD` environment variable is missing in npm v7 and is required for Husky v4 to auto-install (https://github.com/npm/cli/issues/2033). To manually install husky v4, run `INIT_CWD="$(pwd)" npm install husky --save-dev` or upgrade to [husky v5](https://typicode.github.io/husky/#/). ## Install diff --git a/package.json b/package.json index 3f07b4740..301bbf4c2 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,6 @@ "version": "4.3.3", "description": "Prevents bad commit or push (git hooks, pre-commit/precommit, pre-push/prepush, post-merge/postmerge and all that stuff...)", "bin": { - "husky": "./husky.js", "husky-run": "./bin/run.js", "husky-upgrade": "./lib/upgrader/bin.js" }, @@ -93,16 +92,8 @@ "^.+\\.tsx?$": "ts-jest" }, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", - "testPathIgnorePatterns": [ - "node_modules", - "__env__.ts" - ], - "moduleFileExtensions": [ - "ts", - "js", - "json", - "node" - ] + "testPathIgnorePatterns": ["node_modules", "__env__.ts"], + "moduleFileExtensions": ["ts", "js", "json", "node"] }, "collective": { "type": "opencollective", diff --git a/src/installer/bin.ts b/src/installer/bin.ts index ec50a64d5..9ff1d4867 100644 --- a/src/installer/bin.ts +++ b/src/installer/bin.ts @@ -43,7 +43,12 @@ function getInitCwdEnv(): string { if (INIT_CWD === undefined) { const { name, version } = whichPMRuns() throw new Error( - `INIT_CWD is not set, please check that your package manager supports it (${name} ${version})` + `INIT_CWD is not set, please check that your package manager supports it (${name} ${version}) + +Alternatively, you could set it manually: +INIT_CWD="$(pwd)" npm install husky --save-dev + +Or upgrade to husky v5` ) } @@ -84,12 +89,8 @@ function run(): void { checkGitVersion() } - let cwd = process.argv[3] - if (cwd === undefined) { - cwd = getInitCwdEnv() - } - - const userPkgDir = getUserPkgDir(cwd) + const INIT_CWD = getInitCwdEnv() + const userPkgDir = getUserPkgDir(INIT_CWD) checkGitDirEnv() const { absoluteGitCommonDir, relativeUserPkgDir } = getDirs(userPkgDir)