@howells/husky 0.1.1 → 0.1.2

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.
Files changed (2) hide show
  1. package/bin/howells-husky.mjs +33 -15
  2. package/package.json +13 -5
@@ -16,15 +16,28 @@
16
16
  */
17
17
 
18
18
  import { spawnSync } from "node:child_process";
19
- import { copyFileSync, existsSync, mkdirSync, readFileSync, chmodSync } from "node:fs";
19
+ import {
20
+ copyFileSync,
21
+ existsSync,
22
+ mkdirSync,
23
+ readFileSync,
24
+ chmodSync,
25
+ } from "node:fs";
20
26
  import { dirname, join, resolve } from "node:path";
21
27
  import { fileURLToPath } from "node:url";
22
28
 
23
- const __dirname = dirname(fileURLToPath(import.meta.url));
29
+ const __dirname = import.meta.dirname;
24
30
  const packageRoot = resolve(__dirname, "..");
25
31
  const projectRoot = process.cwd();
26
- const lintStagedFormatterCommands = ["howells-format", "howells-ox-fix"];
27
- const recommendedLintStagedCommand = "howells-ox-fix";
32
+ // `howells-fix` is the current canonical @howells/lint fixer; `howells-ox-fix`
33
+ // and `howells-format` are earlier names still in use by repos mid-migration.
34
+ // Accept all three so a correct lint-staged config never draws a false warning.
35
+ const lintStagedFormatterCommands = [
36
+ "howells-fix",
37
+ "howells-ox-fix",
38
+ "howells-format",
39
+ ];
40
+ const recommendedLintStagedCommand = "howells-fix";
28
41
 
29
42
  function lintStagedCommandValues(config) {
30
43
  return Object.values(config).flatMap((value) => {
@@ -39,7 +52,9 @@ function lintStagedCommandValues(config) {
39
52
  }
40
53
 
41
54
  function usesSupportedFormatter(command) {
42
- return lintStagedFormatterCommands.some((formatter) => command.includes(formatter));
55
+ return lintStagedFormatterCommands.some((formatter) =>
56
+ command.includes(formatter)
57
+ );
43
58
  }
44
59
 
45
60
  // Skip in CI environments — hooks aren't needed there
@@ -56,19 +71,22 @@ if (!existsSync(join(projectRoot, ".git"))) {
56
71
  const huskyBin = resolve(packageRoot, "node_modules", ".bin", "husky");
57
72
  const huskyResult = spawnSync(huskyBin, [], {
58
73
  cwd: projectRoot,
59
- stdio: "inherit",
60
74
  env: process.env,
75
+ stdio: "inherit",
61
76
  });
62
77
 
63
78
  if (huskyResult.error) {
64
79
  // Fallback: try resolving husky from the project's node_modules
65
80
  const fallbackResult = spawnSync("npx", ["husky"], {
66
81
  cwd: projectRoot,
67
- stdio: "inherit",
68
82
  env: process.env,
83
+ stdio: "inherit",
69
84
  });
70
85
 
71
- if (fallbackResult.error || (fallbackResult.status !== null && fallbackResult.status !== 0)) {
86
+ if (
87
+ fallbackResult.error ||
88
+ (fallbackResult.status !== null && fallbackResult.status !== 0)
89
+ ) {
72
90
  console.error("[@howells/husky] Failed to initialise husky");
73
91
  process.exit(1);
74
92
  }
@@ -93,14 +111,14 @@ for (const hook of hooks) {
93
111
  // Step 3: Validate lint-staged config
94
112
  const packageJsonPath = join(projectRoot, "package.json");
95
113
  if (existsSync(packageJsonPath)) {
96
- const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
114
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
97
115
 
98
116
  if (!packageJson["lint-staged"]) {
99
117
  console.warn(
100
- '[@howells/husky] Warning: no "lint-staged" config found in package.json.',
118
+ '[@howells/husky] Warning: no "lint-staged" config found in package.json.'
101
119
  );
102
120
  console.warn(
103
- ` Add: "lint-staged": { "*.{js,ts,jsx,tsx,json,jsonc,css}": "${recommendedLintStagedCommand}" }`,
121
+ ` Add: "lint-staged": { "*.{js,ts,jsx,tsx,json,jsonc,css}": "${recommendedLintStagedCommand}" }`
104
122
  );
105
123
  }
106
124
 
@@ -111,10 +129,10 @@ if (existsSync(packageJsonPath)) {
111
129
  const usesHowells = commands.some(usesSupportedFormatter);
112
130
  if (!usesHowells) {
113
131
  console.warn(
114
- "[@howells/husky] Warning: lint-staged should use a supported Howells formatter.",
132
+ "[@howells/husky] Warning: lint-staged should use a supported Howells formatter."
115
133
  );
116
134
  console.warn(
117
- ` Expected: "*.{js,ts,jsx,tsx,json,jsonc,css}": "${recommendedLintStagedCommand}"`,
135
+ ` Expected: "*.{js,ts,jsx,tsx,json,jsonc,css}": "${recommendedLintStagedCommand}"`
118
136
  );
119
137
  }
120
138
  }
@@ -123,12 +141,12 @@ if (existsSync(packageJsonPath)) {
123
141
  const scripts = packageJson.scripts || {};
124
142
  if (!scripts.typecheck) {
125
143
  console.warn(
126
- '[@howells/husky] Warning: no "typecheck" script found. Pre-push hook requires it.',
144
+ '[@howells/husky] Warning: no "typecheck" script found. Pre-push hook requires it.'
127
145
  );
128
146
  }
129
147
  if (!scripts.lint) {
130
148
  console.warn(
131
- '[@howells/husky] Warning: no "lint" script found. Pre-push hook requires it.',
149
+ '[@howells/husky] Warning: no "lint" script found. Pre-push hook requires it.'
132
150
  );
133
151
  }
134
152
  }
package/package.json CHANGED
@@ -1,21 +1,29 @@
1
1
  {
2
2
  "name": "@howells/husky",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Standardised git hooks for Howells projects. Immutable pre-commit and pre-push configuration.",
5
5
  "license": "MIT",
6
+ "bin": {
7
+ "howells-husky": "bin/howells-husky.mjs"
8
+ },
6
9
  "files": [
7
10
  "bin/*.mjs",
8
11
  "hooks/*",
9
12
  "README.md"
10
13
  ],
11
- "bin": {
12
- "howells-husky": "bin/howells-husky.mjs"
14
+ "exports": {
15
+ "./package.json": "./package.json"
16
+ },
17
+ "scripts": {
18
+ "lint": "howells-ox-check --config=oxlint.config.ts package.json bin hooks README.md oxlint.config.ts oxfmt.config.ts",
19
+ "lint:fix": "howells-ox-fix --config=oxlint.config.ts package.json bin hooks README.md oxlint.config.ts oxfmt.config.ts",
20
+ "format": "howells-oxfmt --write package.json bin hooks README.md oxlint.config.ts oxfmt.config.ts README.md"
13
21
  },
14
22
  "dependencies": {
15
23
  "husky": "^9.1.7",
16
24
  "lint-staged": "^16.4.0"
17
25
  },
18
- "exports": {
19
- "./package.json": "./package.json"
26
+ "devDependencies": {
27
+ "@howells/lint": "^0.2.1"
20
28
  }
21
29
  }