Skip to content

Commit

Permalink
fix(hooks): change detection of husky 6 hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
jegli committed Jun 19, 2021
1 parent 88cf1ad commit f57c732
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"execa": "5.1.0",
"find-packages": "8.0.3",
"fs-extra": "10.0.0",
"glob": "7.1.7",
"husky": "6.0.0",
"jest": "26.6.3",
"license-checker": "25.0.1",
Expand Down
25 changes: 13 additions & 12 deletions src/hooks-installed.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { sync } from 'glob';
import { getFileData } from './get-file-data';
import { logMessages } from './log-messages';
import { getGitRoot } from './get-git-root';
Expand All @@ -11,23 +12,23 @@ export const isHookInstalled = async (pathName: string) => {
}
};

export const areAllHooksInstalled = async (gitRootDirectory: string) => {
const husky4HooksInstalled = await Promise.all([
isHookInstalled(`${gitRootDirectory}/.git/hooks/commit-msg`),
isHookInstalled(`${gitRootDirectory}/.git/hooks/pre-commit`),
]);
const husky6gitignorePath = `${gitRootDirectory}/${sync('**/.husky/.gitignore')}`;
const husky6HooksInstalled = await isHookInstalled(husky6gitignorePath);
return husky6HooksInstalled ||
husky4HooksInstalled.every((hookInstalled) => hookInstalled);
};

export const getHooksInstalledChecker = async () => {
const gitRootDirectory = await getGitRoot();
if (gitRootDirectory.error) {
return gitRootDirectory;
}
const husky4HooksInstalled = await Promise.all([
isHookInstalled(`${gitRootDirectory.text}/.git/hooks/commit-msg`),
isHookInstalled(`${gitRootDirectory.text}/.git/hooks/pre-commit`),
]);
const husky6HooksInstalled = await Promise.all([
isHookInstalled(`${gitRootDirectory.text}/.husky/commit-msg`),
isHookInstalled(`${gitRootDirectory.text}/.husky/pre-commit`),
]);
const areAllHooksInstalled =
husky4HooksInstalled.every((hookInstalled) => hookInstalled) ||
husky6HooksInstalled.every((hookInstalled) => hookInstalled);
return areAllHooksInstalled
return await areAllHooksInstalled(gitRootDirectory.text)
? { error: false, text: logMessages.success.gitHooksAreInstalled() }
: { error: true, text: logMessages.error.gitHooksNotInstalledError() };
};

0 comments on commit f57c732

Please sign in to comment.