@howells/husky 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/bin/detect.mjs +18 -31
- package/bin/howells-husky.mjs +6 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,6 +23,8 @@ In `package.json`:
|
|
|
23
23
|
}
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
+
Standard external lint-staged configuration files are supported as an alternative to the inline `package.json` entry. Use one when path-aware or computed commands are needed.
|
|
27
|
+
|
|
26
28
|
That's it. On `pnpm install`, the hooks are installed automatically.
|
|
27
29
|
|
|
28
30
|
## What it does
|
|
@@ -61,7 +63,7 @@ Your `package.json` must have:
|
|
|
61
63
|
- a `"prepush"` script appropriate to the repository, or both:
|
|
62
64
|
- a `"typecheck"` script (e.g. `tsc --noEmit` or `turbo run typecheck`)
|
|
63
65
|
- a `"lint"` script (e.g. `howells-lint` or `turbo run lint`)
|
|
64
|
-
-
|
|
66
|
+
- inline or standard external lint-staged configuration appropriate to the project
|
|
65
67
|
|
|
66
68
|
## Why a package?
|
|
67
69
|
|
package/bin/detect.mjs
CHANGED
|
@@ -5,40 +5,27 @@
|
|
|
5
5
|
* around behaviour that is unit-testable in isolation.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
// `howells-fix` is the current canonical @howells/lint fixer; `howells-ox-fix`
|
|
9
|
-
// and `howells-format` are earlier names still in use by repos mid-migration.
|
|
10
|
-
// Accept all three so a correct lint-staged config never draws a false warning.
|
|
11
|
-
export const lintStagedFormatterCommands = [
|
|
12
|
-
"howells-fix",
|
|
13
|
-
"howells-ox-fix",
|
|
14
|
-
"howells-format",
|
|
15
|
-
];
|
|
16
|
-
|
|
17
8
|
export const recommendedLintStagedCommand = "howells-fix";
|
|
18
9
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
10
|
+
// Standard configuration names supported by lint-staged. Package-level files
|
|
11
|
+
// in a monorepo are discovered by lint-staged itself; the installer only needs
|
|
12
|
+
// to recognise the root configuration it is responsible for validating.
|
|
13
|
+
export const lintStagedConfigFileNames = [
|
|
14
|
+
".lintstagedrc",
|
|
15
|
+
".lintstagedrc.json",
|
|
16
|
+
".lintstagedrc.yaml",
|
|
17
|
+
".lintstagedrc.yml",
|
|
18
|
+
".lintstagedrc.js",
|
|
19
|
+
".lintstagedrc.mjs",
|
|
20
|
+
".lintstagedrc.cjs",
|
|
21
|
+
"lint-staged.config.js",
|
|
22
|
+
"lint-staged.config.mjs",
|
|
23
|
+
"lint-staged.config.cjs",
|
|
24
|
+
"lint-staged.config.ts",
|
|
25
|
+
];
|
|
34
26
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
*/
|
|
38
|
-
export function usesSupportedFormatter(command) {
|
|
39
|
-
return lintStagedFormatterCommands.some((formatter) =>
|
|
40
|
-
command.includes(formatter)
|
|
41
|
-
);
|
|
27
|
+
export function findLintStagedConfigFile(exists) {
|
|
28
|
+
return lintStagedConfigFileNames.find((file) => exists(file));
|
|
42
29
|
}
|
|
43
30
|
|
|
44
31
|
/**
|
package/bin/howells-husky.mjs
CHANGED
|
@@ -27,10 +27,9 @@ import path from "node:path";
|
|
|
27
27
|
|
|
28
28
|
import {
|
|
29
29
|
fallbackFailed,
|
|
30
|
-
|
|
30
|
+
findLintStagedConfigFile,
|
|
31
31
|
recommendedLintStagedCommand,
|
|
32
32
|
shouldUseNpxFallback,
|
|
33
|
-
usesSupportedFormatter,
|
|
34
33
|
} from "./detect.mjs";
|
|
35
34
|
|
|
36
35
|
const scriptDir = import.meta.dirname;
|
|
@@ -117,31 +116,19 @@ for (const hook of hooks) {
|
|
|
117
116
|
const packageJsonPath = path.join(projectRoot, "package.json");
|
|
118
117
|
if (existsSync(packageJsonPath)) {
|
|
119
118
|
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
119
|
+
const externalLintStagedConfig = findLintStagedConfigFile((file) =>
|
|
120
|
+
existsSync(path.join(projectRoot, file))
|
|
121
|
+
);
|
|
120
122
|
|
|
121
|
-
if (!packageJson["lint-staged"]) {
|
|
123
|
+
if (!packageJson["lint-staged"] && !externalLintStagedConfig) {
|
|
122
124
|
console.warn(
|
|
123
|
-
|
|
125
|
+
"[@howells/husky] Warning: no inline or external lint-staged config found."
|
|
124
126
|
);
|
|
125
127
|
console.warn(
|
|
126
128
|
` Add: "lint-staged": { "*.{js,ts,jsx,tsx,json,jsonc,css}": "${recommendedLintStagedCommand}" }`
|
|
127
129
|
);
|
|
128
130
|
}
|
|
129
131
|
|
|
130
|
-
// Check that the lint-staged command uses a supported Howells formatter.
|
|
131
|
-
const lsConfig = packageJson["lint-staged"];
|
|
132
|
-
if (lsConfig) {
|
|
133
|
-
const commands = lintStagedCommandValues(lsConfig);
|
|
134
|
-
const usesHowells = commands.some(usesSupportedFormatter);
|
|
135
|
-
if (!usesHowells) {
|
|
136
|
-
console.warn(
|
|
137
|
-
"[@howells/husky] Warning: lint-staged should use a supported Howells formatter."
|
|
138
|
-
);
|
|
139
|
-
console.warn(
|
|
140
|
-
` Expected: "*.{js,ts,jsx,tsx,json,jsonc,css}": "${recommendedLintStagedCommand}"`
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
132
|
// Projects can own an appropriately scoped pre-push gate. Older projects
|
|
146
133
|
// retain the package's typecheck + lint fallback until they add one.
|
|
147
134
|
const scripts = packageJson.scripts || {};
|