@zukhruf/git-hooks 0.8.0 → 0.8.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @zukhruf/git-hooks
2
2
 
3
- Git hooks written in TypeScript. A pre-commit hook runs steps in order against the staged commit. The steps check the staged copy of each file with Prettier and change nothing, run `nx sync` and stage only the files that sync wrote, and build generated files when nx says that their projects are affected. A pre-push hook runs steps in order against the push. Its build step builds each pushed commit in a snapshot, never the working tree. A repo adds a step of its own as a class.
3
+ Git hooks written in TypeScript. A pre-commit hook runs steps in order against the staged commit. The steps check the staged copy of each file with Prettier and change nothing, run `nx sync` and stage only the files that sync wrote, and build generated files when nx says that their projects are affected. A pre-push hook runs steps in order against the push. Its build step builds each pushed commit in a snapshot, never the working tree. A commit-msg hook runs steps in order against the message of the commit. Its scope step stops a subject that nx release reads with the wrong scope. A repo adds a step of its own as a class.
4
4
 
5
5
  The words in these documents have one meaning each. See the glossary in [CONTEXT.md](./CONTEXT.md).
6
6
 
@@ -286,3 +286,59 @@ export class AffectedTest extends Step<Push> {
286
286
  ```
287
287
 
288
288
  Use the `base` and the `head` of each update, not `--base=origin/main --head=HEAD`. That pair checks the branch that is checked out, and a push can send other refs.
289
+
290
+ ## Install the commit-msg hook
291
+
292
+ Git runs the commit-msg hook after you write the message, before git makes the commit. Write the hook in `.husky/commit-msg.ts`:
293
+
294
+ ```ts
295
+ #!/usr/bin/env node
296
+ import { NxReleaseScope, commitMsg } from '@zukhruf/git-hooks';
297
+
298
+ await commitMsg([new NxReleaseScope()]);
299
+ ```
300
+
301
+ Make it executable, and commit a link to it, as for the pre-commit hook:
302
+
303
+ ```sh
304
+ chmod +x .husky/commit-msg.ts
305
+ ln -s commit-msg.ts .husky/commit-msg
306
+ ```
307
+
308
+ When `package.json` has no `"type": "module"`, name the file `commit-msg.mts`, and link to that name. The `prepare` script in [Install the hook](#install-the-hook) tells git where the hooks are.
309
+
310
+ Git gives the hook the file that holds the message. `commitMsg` reads it into a `CommitMessage`, without the comment lines of the editor. It runs the steps in order and prints the outcome of each step. At the first fail, the commit stops.
311
+
312
+ ## Keep the scope that nx release reads
313
+
314
+ `NxReleaseScope` stops a commit when nx release reads its subject with another scope than the first parenthesis. The parser of nx takes the scope up to the last `): ` of the subject. Thus `fix(fs): the lock (3da0916, #3840): reads it` gets the scope `fs): the lock (3da0916, #3840`, not `fs`. A scope that names no project gives the commit to no project. A scope piece that starts with `#` stops `nx release version` with `Invalid glob pattern`. A `!` before the first `: ` is lost too, so a breaking change ships as a patch.
315
+
316
+ ```text
317
+ scope nx release reads the scope of this subject as "fs): the lock (3da0916, #3840", not "fs":
318
+ its parser takes the scope up to the last "): " of the subject.
319
+ A scope that names no project gives the commit to no project, and a
320
+ scope piece that starts with "#" stops `nx release version`.
321
+ Write "; " after a parenthesis in the subject, as "(#3840); ", or move
322
+ the parenthesis to the body.
323
+ ✖ commit stopped by the commit-msg hook
324
+ ```
325
+
326
+ The step asks the parser of the repo's own nx, so it judges the subject as `nx release` of the repo does. It needs `nx` in the repo. The subject is the first paragraph of the message, with its lines joined by spaces, as `git log --format=%s` gives it. The body is not checked. A merge commit and a release commit, such as `chore(release): publish 0.7.0`, pass.
327
+
328
+ ## Add a commit-msg step of your own
329
+
330
+ A commit-msg step is a subclass of `Step<CommitMessage>`. `CommitMessage` has the `text` of the message without comment lines, and its `subject`:
331
+
332
+ ```ts
333
+ import { type CommitMessage, Step } from '@zukhruf/git-hooks';
334
+
335
+ export class NoTrailers extends Step<CommitMessage> {
336
+ readonly name = 'trailers';
337
+
338
+ async run(message: CommitMessage) {
339
+ return /^Co-Authored-By:/im.test(message.text)
340
+ ? this.fail('remove the Co-Authored-By trailer')
341
+ : this.pass();
342
+ }
343
+ }
344
+ ```
@@ -0,0 +1,7 @@
1
+ export declare class CommitMessage {
2
+ readonly text: string;
3
+ readonly subject: string;
4
+ private constructor();
5
+ static read(root: string, environment: NodeJS.ProcessEnv, file: string): Promise<CommitMessage>;
6
+ }
7
+ //# sourceMappingURL=commit-message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit-message.d.ts","sourceRoot":"","sources":["../src/commit-message.ts"],"names":[],"mappings":"AASA,qBAAa,aAAa;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAGtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,OAAO;WAKM,IAAI,CACf,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,CAAC,UAAU,EAC9B,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,aAAa,CAAC;CAS1B"}
@@ -0,0 +1,27 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { promisify } from 'node:util';
4
+ const execFileAsync = promisify(execFile);
5
+ // The message of the commit that git is about to make, as the commit-msg hook
6
+ // gets it in a file. Git gives the hook the text before its cleanup, so the
7
+ // comment lines of the editor are still in it; the text here has none.
8
+ export class CommitMessage {
9
+ text;
10
+ // The subject as `git log --format=%s` gives it, and as nx release reads
11
+ // it: the first paragraph, with its lines joined by spaces.
12
+ subject;
13
+ constructor(text) {
14
+ this.text = text;
15
+ this.subject = (text.split('\n\n')[0] ?? '').split('\n').join(' ');
16
+ }
17
+ static async read(root, environment, file) {
18
+ const git = execFileAsync('git', ['stripspace', '--strip-comments'], {
19
+ cwd: root,
20
+ env: environment,
21
+ encoding: 'utf8',
22
+ });
23
+ git.child.stdin?.end(await readFile(file, 'utf8'));
24
+ return new CommitMessage((await git).stdout);
25
+ }
26
+ }
27
+ //# sourceMappingURL=commit-message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit-message.js","sourceRoot":"","sources":["../src/commit-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAE1C,8EAA8E;AAC9E,4EAA4E;AAC5E,uEAAuE;AACvE,MAAM,OAAO,aAAa;IACf,IAAI,CAAS;IACtB,yEAAyE;IACzE,4DAA4D;IACnD,OAAO,CAAS;IAEzB,YAAoB,IAAY;QAC9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrE,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,IAAI,CACf,IAAY,EACZ,WAA8B,EAC9B,IAAY;QAEZ,MAAM,GAAG,GAAG,aAAa,CAAC,KAAK,EAAE,CAAC,YAAY,EAAE,kBAAkB,CAAC,EAAE;YACnE,GAAG,EAAE,IAAI;YACT,GAAG,EAAE,WAAW;YAChB,QAAQ,EAAE,MAAM;SACjB,CAAC,CAAC;QACH,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QACnD,OAAO,IAAI,aAAa,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;IAC/C,CAAC;CACF"}
package/dist/index.d.ts CHANGED
@@ -1,11 +1,14 @@
1
1
  export { Build } from './build.ts';
2
2
  export { Codegen } from './codegen.ts';
3
3
  export { Commit } from './commit.ts';
4
+ export { CommitMessage } from './commit-message.ts';
4
5
  export { DependencyChecks } from './dependency-checks.ts';
5
6
  export { Format } from './format.ts';
6
7
  export { NoNumericPins } from './no-numeric-pins.ts';
8
+ export { NxReleaseScope } from './nx-release-scope.ts';
7
9
  export { Push } from './push.ts';
8
10
  export type { RefUpdate } from './ref-update.ts';
11
+ export { commitMsg } from './scripts/commit-msg.ts';
9
12
  export { preCommit } from './scripts/pre-commit.ts';
10
13
  export { prePush } from './scripts/pre-push.ts';
11
14
  export { type Outcome, Step } from './step.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,KAAK,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,KAAK,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -1,10 +1,13 @@
1
1
  export { Build } from "./build.js";
2
2
  export { Codegen } from "./codegen.js";
3
3
  export { Commit } from "./commit.js";
4
+ export { CommitMessage } from "./commit-message.js";
4
5
  export { DependencyChecks } from "./dependency-checks.js";
5
6
  export { Format } from "./format.js";
6
7
  export { NoNumericPins } from "./no-numeric-pins.js";
8
+ export { NxReleaseScope } from "./nx-release-scope.js";
7
9
  export { Push } from "./push.js";
10
+ export { commitMsg } from "./scripts/commit-msg.js";
8
11
  export { preCommit } from "./scripts/pre-commit.js";
9
12
  export { prePush } from "./scripts/pre-push.js";
10
13
  export { Step } from "./step.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAgB,IAAI,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAgB,IAAI,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { CommitMessage } from './commit-message.ts';
2
+ import { type Outcome, Step } from './step.ts';
3
+ export declare class NxReleaseScope extends Step<CommitMessage> {
4
+ readonly name = "scope";
5
+ run(message: CommitMessage): Promise<Outcome>;
6
+ }
7
+ //# sourceMappingURL=nx-release-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nx-release-scope.d.ts","sourceRoot":"","sources":["../src/nx-release-scope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,KAAK,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAY/C,qBAAa,cAAe,SAAQ,IAAI,CAAC,aAAa,CAAC;IACrD,QAAQ,CAAC,IAAI,WAAW;IAElB,GAAG,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC;CAiCpD"}
@@ -0,0 +1,41 @@
1
+ import { Step } from "./step.js";
2
+ // A conventional-commit header whose scope is its first parenthesis: the
3
+ // scope holds no parenthesis.
4
+ const HEADER = /^(?<type>[^\s():!]+)(?:\s*\((?<scope>[^()]*)\))?(?<breaking>!)?: (?<description>.+)$/u;
5
+ // Stops a commit whose subject nx release reads with another scope than its
6
+ // first parenthesis. The parser of nx takes the scope up to the last "): " of
7
+ // the subject, so `fix(a): b (c, #1): d` gets the scope `a): b (c, #1`, and a
8
+ // `!` before the first ": " is lost. The step asks the repo's own nx, so it
9
+ // judges the subject as the nx release of the repo will.
10
+ export class NxReleaseScope extends Step {
11
+ name = 'scope';
12
+ async run(message) {
13
+ const { parseConventionalCommitsMessage } = await import('nx/src/command-line/release/utils/git');
14
+ // nx gives the type __INVALID__ to a subject that is no conventional
15
+ // header, such as that of a merge commit.
16
+ const nx = parseConventionalCommitsMessage(message.subject) ?? {
17
+ type: '__INVALID__',
18
+ scope: '',
19
+ breaking: false,
20
+ };
21
+ const header = HEADER.exec(message.subject)?.groups;
22
+ const scope = header?.['scope'] ?? '';
23
+ const breaking = header?.['breaking'] !== undefined;
24
+ if (nx.type === (header?.['type'] ?? '__INVALID__') &&
25
+ nx.scope === scope &&
26
+ nx.breaking === breaking)
27
+ return this.pass('nx release reads the scope as written');
28
+ return this.fail([
29
+ `nx release reads the scope of this subject as ${JSON.stringify(nx.scope)}${header === undefined ? '' : `, not ${JSON.stringify(scope)}`}:`,
30
+ ' its parser takes the scope up to the last "): " of the subject.',
31
+ ...(breaking && !nx.breaking
32
+ ? [' It also loses the "!", so a breaking change ships as a patch.']
33
+ : []),
34
+ 'A scope that names no project gives the commit to no project, and a',
35
+ 'scope piece that starts with "#" stops `nx release version`.',
36
+ 'Write "; " after a parenthesis in the subject, as "(#3840); ", or move',
37
+ 'the parenthesis to the body.',
38
+ ].join('\n'));
39
+ }
40
+ }
41
+ //# sourceMappingURL=nx-release-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nx-release-scope.js","sourceRoot":"","sources":["../src/nx-release-scope.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,IAAI,EAAE,MAAM,WAAW,CAAC;AAE/C,yEAAyE;AACzE,8BAA8B;AAC9B,MAAM,MAAM,GACV,uFAAuF,CAAC;AAE1F,4EAA4E;AAC5E,8EAA8E;AAC9E,8EAA8E;AAC9E,4EAA4E;AAC5E,yDAAyD;AACzD,MAAM,OAAO,cAAe,SAAQ,IAAmB;IAC5C,IAAI,GAAG,OAAO,CAAC;IAExB,KAAK,CAAC,GAAG,CAAC,OAAsB;QAC9B,MAAM,EAAE,+BAA+B,EAAE,GACvC,MAAM,MAAM,CAAC,uCAAuC,CAAC,CAAC;QACxD,qEAAqE;QACrE,0CAA0C;QAC1C,MAAM,EAAE,GAAG,+BAA+B,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI;YAC7D,IAAI,EAAE,aAAa;YACnB,KAAK,EAAE,EAAE;YACT,QAAQ,EAAE,KAAK;SAChB,CAAC;QACF,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QACpD,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QACtC,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,UAAU,CAAC,KAAK,SAAS,CAAC;QACpD,IACE,EAAE,CAAC,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,IAAI,aAAa,CAAC;YAC/C,EAAE,CAAC,KAAK,KAAK,KAAK;YAClB,EAAE,CAAC,QAAQ,KAAK,QAAQ;YAExB,OAAO,IAAI,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;QAC5D,OAAO,IAAI,CAAC,IAAI,CACd;YACE,iDAAiD,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,GAAG;YAC3I,mEAAmE;YACnE,GAAG,CAAC,QAAQ,IAAI,CAAC,EAAE,CAAC,QAAQ;gBAC1B,CAAC,CAAC,CAAC,iEAAiE,CAAC;gBACrE,CAAC,CAAC,EAAE,CAAC;YACP,qEAAqE;YACrE,8DAA8D;YAC9D,wEAAwE;YACxE,8BAA8B;SAC/B,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ import { CommitMessage } from '../commit-message.ts';
2
+ import type { Step } from '../step.ts';
3
+ export declare function commitMsg(steps: readonly Step<CommitMessage>[]): Promise<void>;
4
+ //# sourceMappingURL=commit-msg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit-msg.d.ts","sourceRoot":"","sources":["../../src/scripts/commit-msg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAMvC,wBAAsB,SAAS,CAC7B,KAAK,EAAE,SAAS,IAAI,CAAC,aAAa,CAAC,EAAE,GACpC,OAAO,CAAC,IAAI,CAAC,CAcf"}
@@ -0,0 +1,22 @@
1
+ import { CommitMessage } from "../commit-message.js";
2
+ // What a repo's `.husky/commit-msg.ts` calls. Git runs the hook at the root of
3
+ // the work tree, with the file that holds the message as its argument. This is
4
+ // the one module that prints and reads the arguments and the environment, as
5
+ // a script may.
6
+ export async function commitMsg(steps) {
7
+ const [file = ''] = process.argv.slice(2);
8
+ const message = await CommitMessage.read(process.cwd(), process.env, file);
9
+ for (const step of steps) {
10
+ const outcome = await step.run(message);
11
+ const [first = '', ...rest] = outcome.message.split('\n');
12
+ console.error(`${step.name.padEnd(9)} ${first}`);
13
+ for (const line of rest)
14
+ console.error(`${' '.repeat(10)}${line}`);
15
+ if (outcome.kind === 'fail') {
16
+ console.error('✖ commit stopped by the commit-msg hook');
17
+ process.exitCode = 1;
18
+ return;
19
+ }
20
+ }
21
+ }
22
+ //# sourceMappingURL=commit-msg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit-msg.js","sourceRoot":"","sources":["../../src/scripts/commit-msg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,+EAA+E;AAC/E,+EAA+E;AAC/E,6EAA6E;AAC7E,gBAAgB;AAChB,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,KAAqC;IAErC,MAAM,CAAC,IAAI,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC1C,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC3E,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACxC,MAAM,CAAC,KAAK,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC1D,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC;QACjD,KAAK,MAAM,IAAI,IAAI,IAAI;YAAE,OAAO,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC;QACnE,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;YACzD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;YACrB,OAAO;QACT,CAAC;IACH,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zukhruf/git-hooks",
3
- "version": "0.8.0",
4
- "description": "Git hooks in TypeScript. Pre-commit checks staged files with Prettier, runs nx sync and stages only what it wrote, and builds affected generated files. Pre-push builds each pushed commit in a snapshot, not the working tree. A repo adds a step as a class.",
3
+ "version": "0.8.1",
4
+ "description": "Git hooks in TypeScript, a class per step. Pre-commit checks staged files with Prettier, stages only what nx sync wrote, and builds generated files. Commit-msg stops a subject whose scope nx release misreads. Pre-push builds pushed commits in snapshots.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -17,6 +17,7 @@
17
17
  "hooks",
18
18
  "pre-commit",
19
19
  "pre-push",
20
+ "commit-msg",
20
21
  "build",
21
22
  "snapshot",
22
23
  "prettier",
@@ -46,8 +47,8 @@
46
47
  "access": "public"
47
48
  },
48
49
  "dependencies": {
49
- "@zukhruf/async": "^0.8.0",
50
- "@zukhruf/fs": "^0.8.0"
50
+ "@zukhruf/async": "^0.8.1",
51
+ "@zukhruf/fs": "^0.8.1"
51
52
  },
52
53
  "peerDependencies": {
53
54
  "eslint": "^9.30.0 || ^10.0.0",
@@ -63,7 +64,7 @@
63
64
  }
64
65
  },
65
66
  "devDependencies": {
66
- "@zukhruf/testing": "^0.8.0",
67
+ "@zukhruf/testing": "^0.8.1",
67
68
  "eslint": "^10.12.0",
68
69
  "jsonc-eslint-parser": "^3.3.0",
69
70
  "prettier": "^3.9.9"