forked from webpro-nl/knip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
34 lines (26 loc) · 1.12 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { readFileSync } from 'fs';
import { _getDependenciesFromScripts } from '../../binaries/index.js';
import { timerify } from '../../util/Performance.js';
import { hasDependency } from '../../util/plugin.js';
import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
// https://typicode.github.io/husky
// https://git-scm.com/docs/githooks
export const NAME = 'husky';
/** @public */
export const ENABLERS = ['husky'];
export const isEnabled: IsPluginEnabledCallback = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
// TODO More hooks exists, but is it worth adding all of them?
export const CONFIG_FILE_PATTERNS = [
'.husky/commit-msg',
'.husky/pre-{applypatch,commit,merge-commit,push,rebase,receive}',
'.husky/post-{checkout,commit,merge,rewrite}',
];
const findHuskyDependencies: GenericPluginCallback = async (configFilePath, { cwd, manifest }) => {
const script = readFileSync(configFilePath);
return _getDependenciesFromScripts(String(script), {
cwd,
manifest,
knownGlobalsOnly: true,
});
};
export const findDependencies = timerify(findHuskyDependencies);