@zukhruf/git-hooks 0.8.20 → 0.8.22

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 (115) hide show
  1. package/README.md +275 -37
  2. package/dist/build.d.ts +1 -1
  3. package/dist/build.d.ts.map +1 -1
  4. package/dist/build.js +44 -46
  5. package/dist/build.js.map +1 -1
  6. package/dist/codegen.d.ts.map +1 -1
  7. package/dist/codegen.js +41 -8
  8. package/dist/codegen.js.map +1 -1
  9. package/dist/commit.d.ts +29 -10
  10. package/dist/commit.d.ts.map +1 -1
  11. package/dist/commit.js +244 -85
  12. package/dist/commit.js.map +1 -1
  13. package/dist/dependency-checks.d.ts.map +1 -1
  14. package/dist/dependency-checks.js +49 -44
  15. package/dist/dependency-checks.js.map +1 -1
  16. package/dist/dockerfile-installs.d.ts +7 -0
  17. package/dist/dockerfile-installs.d.ts.map +1 -0
  18. package/dist/dockerfile-installs.js +132 -0
  19. package/dist/dockerfile-installs.js.map +1 -0
  20. package/dist/format.d.ts.map +1 -1
  21. package/dist/format.js +33 -24
  22. package/dist/format.js.map +1 -1
  23. package/dist/git.d.ts +3 -0
  24. package/dist/git.d.ts.map +1 -0
  25. package/dist/git.js +20 -0
  26. package/dist/git.js.map +1 -0
  27. package/dist/index.d.ts +8 -3
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +3 -3
  30. package/dist/index.js.map +1 -1
  31. package/dist/lockfile-sync.d.ts +8 -0
  32. package/dist/lockfile-sync.d.ts.map +1 -0
  33. package/dist/lockfile-sync.js +82 -0
  34. package/dist/lockfile-sync.js.map +1 -0
  35. package/dist/no-numeric-pins.d.ts.map +1 -1
  36. package/dist/no-numeric-pins.js +12 -3
  37. package/dist/no-numeric-pins.js.map +1 -1
  38. package/dist/npm/lockfile.d.ts +18 -0
  39. package/dist/npm/lockfile.d.ts.map +1 -0
  40. package/dist/npm/lockfile.js +108 -0
  41. package/dist/npm/lockfile.js.map +1 -0
  42. package/dist/npmrc-policy.d.ts +7 -0
  43. package/dist/npmrc-policy.d.ts.map +1 -0
  44. package/dist/npmrc-policy.js +93 -0
  45. package/dist/npmrc-policy.js.map +1 -0
  46. package/dist/push.d.ts +14 -9
  47. package/dist/push.d.ts.map +1 -1
  48. package/dist/push.js +20 -93
  49. package/dist/push.js.map +1 -1
  50. package/dist/ref-update.d.ts +1 -1
  51. package/dist/ref-update.d.ts.map +1 -1
  52. package/dist/run/commit-msg.d.ts +9 -0
  53. package/dist/run/commit-msg.d.ts.map +1 -0
  54. package/dist/run/commit-msg.js +8 -0
  55. package/dist/run/commit-msg.js.map +1 -0
  56. package/dist/run/pre-commit.d.ts +14 -0
  57. package/dist/run/pre-commit.d.ts.map +1 -0
  58. package/dist/run/pre-commit.js +41 -0
  59. package/dist/run/pre-commit.js.map +1 -0
  60. package/dist/run/pre-push.d.ts +14 -0
  61. package/dist/run/pre-push.d.ts.map +1 -0
  62. package/dist/run/pre-push.js +27 -0
  63. package/dist/run/pre-push.js.map +1 -0
  64. package/dist/run/step-runner.d.ts +17 -0
  65. package/dist/run/step-runner.d.ts.map +1 -0
  66. package/dist/run/step-runner.js +27 -0
  67. package/dist/run/step-runner.js.map +1 -0
  68. package/dist/scripts/commit-msg.d.ts +1 -1
  69. package/dist/scripts/commit-msg.d.ts.map +1 -1
  70. package/dist/scripts/commit-msg.js +14 -19
  71. package/dist/scripts/commit-msg.js.map +1 -1
  72. package/dist/scripts/host.d.ts +10 -0
  73. package/dist/scripts/host.d.ts.map +1 -0
  74. package/dist/scripts/host.js +37 -0
  75. package/dist/scripts/host.js.map +1 -0
  76. package/dist/scripts/pre-commit.d.ts +1 -1
  77. package/dist/scripts/pre-commit.d.ts.map +1 -1
  78. package/dist/scripts/pre-commit.js +14 -17
  79. package/dist/scripts/pre-commit.js.map +1 -1
  80. package/dist/scripts/pre-push.d.ts +1 -1
  81. package/dist/scripts/pre-push.d.ts.map +1 -1
  82. package/dist/scripts/pre-push.js +16 -32
  83. package/dist/scripts/pre-push.js.map +1 -1
  84. package/dist/snapshot/drift.d.ts +0 -2
  85. package/dist/snapshot/drift.d.ts.map +1 -1
  86. package/dist/snapshot/drift.js +5 -57
  87. package/dist/snapshot/drift.js.map +1 -1
  88. package/dist/snapshot/installs.d.ts +1 -0
  89. package/dist/snapshot/installs.d.ts.map +1 -1
  90. package/dist/snapshot/installs.js +85 -29
  91. package/dist/snapshot/installs.js.map +1 -1
  92. package/dist/snapshot/snapshot.d.ts +21 -0
  93. package/dist/snapshot/snapshot.d.ts.map +1 -0
  94. package/dist/snapshot/snapshot.js +54 -0
  95. package/dist/snapshot/snapshot.js.map +1 -0
  96. package/dist/snapshot/snapshots.d.ts +30 -0
  97. package/dist/snapshot/snapshots.d.ts.map +1 -0
  98. package/dist/snapshot/snapshots.js +180 -0
  99. package/dist/snapshot/snapshots.js.map +1 -0
  100. package/dist/sync.d.ts.map +1 -1
  101. package/dist/sync.js +16 -16
  102. package/dist/sync.js.map +1 -1
  103. package/dist/testing.d.ts +23 -0
  104. package/dist/testing.d.ts.map +1 -0
  105. package/dist/testing.js +41 -0
  106. package/dist/testing.js.map +1 -0
  107. package/dist/tree.d.ts +24 -0
  108. package/dist/tree.d.ts.map +1 -0
  109. package/dist/tree.js +96 -0
  110. package/dist/tree.js.map +1 -0
  111. package/package.json +10 -4
  112. package/dist/snapshot/nx.d.ts +0 -7
  113. package/dist/snapshot/nx.d.ts.map +0 -1
  114. package/dist/snapshot/nx.js +0 -20
  115. package/dist/snapshot/nx.js.map +0 -1
@@ -0,0 +1,14 @@
1
+ import { Push } from '../push.ts';
2
+ import type { Step } from '../step.ts';
3
+ import { type HookRun, type StepsResult } from './step-runner.ts';
4
+ interface PrePushRun extends HookRun {
5
+ readonly toolEnvironment: NodeJS.ProcessEnv;
6
+ readonly remote: {
7
+ readonly name: string;
8
+ readonly url: string;
9
+ };
10
+ readonly input: string;
11
+ }
12
+ export declare function runPrePush({ root, hookEnvironment, toolEnvironment, print, remote, input }: PrePushRun, steps: readonly Step<Push>[]): Promise<StepsResult>;
13
+ export {};
14
+ //# sourceMappingURL=pre-push.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pre-push.d.ts","sourceRoot":"","sources":["../../src/run/pre-push.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,KAAK,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE9E,UAAU,UAAW,SAAQ,OAAO;IAElC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC,UAAU,CAAC;IAE5C,QAAQ,CAAC,MAAM,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IAEjE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAID,wBAAsB,UAAU,CAC9B,EAAE,IAAI,EAAE,eAAe,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,UAAU,EAC5E,KAAK,EAAE,SAAS,IAAI,CAAC,IAAI,CAAC,EAAE,GAC3B,OAAO,CAAC,WAAW,CAAC,CAmBtB"}
@@ -0,0 +1,27 @@
1
+ import { gitIn } from "../git.js";
2
+ import { Push } from "../push.js";
3
+ import { Snapshots } from "../snapshot/snapshots.js";
4
+ import { StepRunner } from "./step-runner.js";
5
+ // Runs the steps of a pre-push hook on the push. The snapshots that the steps
6
+ // open are deleted after the last step, also when a step fails or throws.
7
+ export async function runPrePush({ root, hookEnvironment, toolEnvironment, print, remote, input }, steps) {
8
+ const runner = new StepRunner(print);
9
+ await using snapshots = new Snapshots({
10
+ hook: 'pre-push',
11
+ root,
12
+ git: gitIn(root, hookEnvironment),
13
+ toolEnvironment,
14
+ notice: runner.notice,
15
+ clock: globalThis,
16
+ });
17
+ const push = await Push.read({
18
+ root,
19
+ environment: hookEnvironment,
20
+ snapshots,
21
+ remote,
22
+ input,
23
+ });
24
+ // Awaited here, so the snapshots stay open until the last step ends.
25
+ return await runner.run(push, steps);
26
+ }
27
+ //# sourceMappingURL=pre-push.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pre-push.js","sourceRoot":"","sources":["../../src/run/pre-push.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,OAAO,EAAgB,UAAU,EAAoB,MAAM,kBAAkB,CAAC;AAW9E,8EAA8E;AAC9E,0EAA0E;AAC1E,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,EAAE,IAAI,EAAE,eAAe,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAc,EAC5E,KAA4B;IAE5B,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IACrC,YAAY,SAAS,GAAG,IAAI,SAAS,CAAC;QACpC,IAAI,EAAE,UAAU;QAChB,IAAI;QACJ,GAAG,EAAE,KAAK,CAAC,IAAI,EAAE,eAAe,CAAC;QACjC,eAAe;QACf,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,KAAK,EAAE,UAAU;KAClB,CAAC,CAAC;IACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC;QAC3B,IAAI;QACJ,WAAW,EAAE,eAAe;QAC5B,SAAS;QACT,MAAM;QACN,KAAK;KACN,CAAC,CAAC;IACH,qEAAqE;IACrE,OAAO,MAAM,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { Outcome, Step } from '../step.ts';
2
+ export interface HookRun {
3
+ readonly root: string;
4
+ readonly hookEnvironment: NodeJS.ProcessEnv;
5
+ readonly print: (name: string, message: string) => void;
6
+ }
7
+ export interface StepsResult {
8
+ readonly kind: 'passed' | 'failed';
9
+ readonly outcomes: readonly Outcome[];
10
+ }
11
+ export declare class StepRunner {
12
+ #private;
13
+ constructor(print: (name: string, message: string) => void);
14
+ readonly notice: (message: string) => void;
15
+ run<Subject>(subject: Subject, steps: readonly Step<Subject>[]): Promise<StepsResult>;
16
+ }
17
+ //# sourceMappingURL=step-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"step-runner.d.ts","sourceRoot":"","sources":["../../src/run/step-runner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAGhD,MAAM,WAAW,OAAO;IAEtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC,UAAU,CAAC;IAE5C,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACzD;AAID,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAC;IACnC,QAAQ,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;CACvC;AAMD,qBAAa,UAAU;;gBAIT,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI;IAI1D,QAAQ,CAAC,MAAM,GAAI,SAAS,MAAM,KAAG,IAAI,CAEvC;IAEI,GAAG,CAAC,OAAO,EACf,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,SAAS,IAAI,CAAC,OAAO,CAAC,EAAE,GAC9B,OAAO,CAAC,WAAW,CAAC;CAWxB"}
@@ -0,0 +1,27 @@
1
+ // Runs the steps of a hook on one subject in order, and stops at the first
2
+ // fail. It prints the outcome of each step under the name of the step. A
3
+ // notice that the subject or its snapshots give while a step runs is printed
4
+ // under the name of that step too.
5
+ export class StepRunner {
6
+ #print;
7
+ #current = '';
8
+ constructor(print) {
9
+ this.#print = print;
10
+ }
11
+ notice = (message) => {
12
+ this.#print(this.#current, message);
13
+ };
14
+ async run(subject, steps) {
15
+ const outcomes = [];
16
+ for (const step of steps) {
17
+ this.#current = step.name;
18
+ const outcome = await step.run(subject);
19
+ outcomes.push(outcome);
20
+ this.#print(step.name, outcome.message);
21
+ if (outcome.kind === 'fail')
22
+ return { kind: 'failed', outcomes };
23
+ }
24
+ return { kind: 'passed', outcomes };
25
+ }
26
+ }
27
+ //# sourceMappingURL=step-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"step-runner.js","sourceRoot":"","sources":["../../src/run/step-runner.ts"],"names":[],"mappings":"AAmBA,2EAA2E;AAC3E,yEAAyE;AACzE,6EAA6E;AAC7E,mCAAmC;AACnC,MAAM,OAAO,UAAU;IACZ,MAAM,CAA0C;IACzD,QAAQ,GAAG,EAAE,CAAC;IAEd,YAAY,KAA8C;QACxD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAEQ,MAAM,GAAG,CAAC,OAAe,EAAQ,EAAE;QAC1C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC,CAAC;IAEF,KAAK,CAAC,GAAG,CACP,OAAgB,EAChB,KAA+B;QAE/B,MAAM,QAAQ,GAAc,EAAE,CAAC;QAC/B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC;YAC1B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACxC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACvB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;YACxC,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM;gBAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;QACnE,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;IACtC,CAAC;CACF"}
@@ -1,4 +1,4 @@
1
- import { CommitMessage } from '../commit-message.ts';
1
+ import type { CommitMessage } from '../commit-message.ts';
2
2
  import type { Step } from '../step.ts';
3
3
  export declare function commitMsg(steps: readonly Step<CommitMessage>[]): Promise<void>;
4
4
  //# sourceMappingURL=commit-msg.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"commit-msg.d.ts","sourceRoot":"","sources":["../../src/scripts/commit-msg.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAKvC,wBAAsB,SAAS,CAC7B,KAAK,EAAE,SAAS,IAAI,CAAC,aAAa,CAAC,EAAE,GACpC,OAAO,CAAC,IAAI,CAAC,CAaf"}
@@ -1,22 +1,17 @@
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.
1
+ import { runCommitMsg } from "../run/commit-msg.js";
2
+ import { Host } from "./host.js";
3
+ // What a repo's `.husky/commit-msg.ts` calls. Git gives the hook the file that
4
+ // holds the message as its argument.
6
5
  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
- }
6
+ const host = new Host();
7
+ const [file = ''] = host.arguments;
8
+ const { kind } = await runCommitMsg({
9
+ root: host.root,
10
+ hookEnvironment: host.hookEnvironment,
11
+ print: (name, message) => host.print(name, message),
12
+ file,
13
+ }, steps);
14
+ if (kind === 'failed')
15
+ host.stop('commit stopped by the commit-msg hook');
21
16
  }
22
17
  //# sourceMappingURL=commit-msg.js.map
@@ -1 +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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,CACN,CAAC;IACF,IAAI,IAAI,KAAK,QAAQ;QAAE,IAAI,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;AAC5E,CAAC"}
@@ -0,0 +1,10 @@
1
+ export declare class Host {
2
+ readonly root: string;
3
+ readonly arguments: string[];
4
+ readonly hookEnvironment: NodeJS.ProcessEnv;
5
+ toolEnvironment(): Promise<NodeJS.ProcessEnv>;
6
+ input(): Promise<string>;
7
+ print(name: string, message: string): void;
8
+ stop(reason: string): void;
9
+ }
10
+ //# sourceMappingURL=host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../src/scripts/host.ts"],"names":[],"mappings":"AAUA,qBAAa,IAAI;IACf,QAAQ,CAAC,IAAI,SAAiB;IAC9B,QAAQ,CAAC,SAAS,WAAyB;IAC3C,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC,UAAU,CAAsB;IAMjE,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC;IAK7C,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IAKxB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAO1C,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;CAI3B"}
@@ -0,0 +1,37 @@
1
+ import { text } from 'node:stream/consumers';
2
+ import { withoutRepoVariables } from "../repo-variables.js";
3
+ // The process of a hook: what git gives it, and where its outcomes go. This
4
+ // is the one module that reads the process: the current folder, the
5
+ // arguments, the standard input and the environment. Git runs a hook at the
6
+ // top of the working tree. The environment that git gives the hook is the
7
+ // hook environment: the git commands of the hook on the repo get it, so they
8
+ // read and write the index of the commit. A step never gets an environment.
9
+ export class Host {
10
+ root = process.cwd();
11
+ arguments = process.argv.slice(2);
12
+ hookEnvironment = { ...process.env };
13
+ // The environment of each tool: the hook environment without each variable
14
+ // that `git rev-parse --local-env-vars` lists, as git clears them when it
15
+ // runs a command in another repo (githooks(5)). A tool that runs git in a
16
+ // folder of its own then does not reach the repo of the hook.
17
+ toolEnvironment() {
18
+ return withoutRepoVariables(this.hookEnvironment);
19
+ }
20
+ // The standard input. Git gives one only to the pre-push hook.
21
+ input() {
22
+ return text(process.stdin);
23
+ }
24
+ // Prints a message of a step under its name, with its next lines indented.
25
+ print(name, message) {
26
+ const [first = '', ...rest] = message.split('\n');
27
+ console.error(`${name.padEnd(9)} ${first}`);
28
+ for (const line of rest)
29
+ console.error(`${' '.repeat(10)}${line}`);
30
+ }
31
+ // Stops the commit or the push: git reads the exit code of the hook.
32
+ stop(reason) {
33
+ console.error(`✖ ${reason}`);
34
+ process.exitCode = 1;
35
+ }
36
+ }
37
+ //# sourceMappingURL=host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.js","sourceRoot":"","sources":["../../src/scripts/host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAE7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,4EAA4E;AAC5E,oEAAoE;AACpE,4EAA4E;AAC5E,0EAA0E;AAC1E,6EAA6E;AAC7E,4EAA4E;AAC5E,MAAM,OAAO,IAAI;IACN,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IACrB,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAClC,eAAe,GAAsB,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAEjE,2EAA2E;IAC3E,0EAA0E;IAC1E,0EAA0E;IAC1E,8DAA8D;IAC9D,eAAe;QACb,OAAO,oBAAoB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACpD,CAAC;IAED,+DAA+D;IAC/D,KAAK;QACH,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED,2EAA2E;IAC3E,KAAK,CAAC,IAAY,EAAE,OAAe;QACjC,MAAM,CAAC,KAAK,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAClD,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC;QAC5C,KAAK,MAAM,IAAI,IAAI,IAAI;YAAE,OAAO,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC;IACrE,CAAC;IAED,qEAAqE;IACrE,IAAI,CAAC,MAAc;QACjB,OAAO,CAAC,KAAK,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC;QAC7B,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC;CACF"}
@@ -1,4 +1,4 @@
1
- import { Commit } from '../commit.ts';
1
+ import type { Commit } from '../commit.ts';
2
2
  import type { Step } from '../step.ts';
3
3
  export declare function preCommit(steps: readonly Step<Commit>[]): Promise<void>;
4
4
  //# sourceMappingURL=pre-commit.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pre-commit.d.ts","sourceRoot":"","sources":["../../src/scripts/pre-commit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAKvC,wBAAsB,SAAS,CAAC,KAAK,EAAE,SAAS,IAAI,CAAC,MAAM,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAa7E"}
1
+ {"version":3,"file":"pre-commit.d.ts","sourceRoot":"","sources":["../../src/scripts/pre-commit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAIvC,wBAAsB,SAAS,CAAC,KAAK,EAAE,SAAS,IAAI,CAAC,MAAM,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAc7E"}
@@ -1,20 +1,17 @@
1
- import { Commit } from "../commit.js";
2
- // What a repo's `.husky/pre-commit.ts` calls. Git runs the hook at the root of
3
- // the work tree, so the current folder is the repo. This is the one module
4
- // that prints and reads the environment, as a script may.
1
+ import { runPreCommit } from "../run/pre-commit.js";
2
+ import { Host } from "./host.js";
3
+ // What a repo's `.husky/pre-commit.ts` calls.
5
4
  export async function preCommit(steps) {
6
- const commit = new Commit(process.cwd(), process.env);
7
- for (const step of steps) {
8
- const outcome = await step.run(commit);
9
- const [first = '', ...rest] = outcome.message.split('\n');
10
- console.error(`${step.name.padEnd(9)} ${first}`);
11
- for (const line of rest)
12
- console.error(`${' '.repeat(10)}${line}`);
13
- if (outcome.kind === 'fail') {
14
- console.error('✖ commit stopped by the pre-commit hook');
15
- process.exitCode = 1;
16
- return;
17
- }
18
- }
5
+ const host = new Host();
6
+ const result = await runPreCommit({
7
+ root: host.root,
8
+ hookEnvironment: host.hookEnvironment,
9
+ toolEnvironment: await host.toolEnvironment(),
10
+ print: (name, message) => host.print(name, message),
11
+ }, steps);
12
+ if (result.kind === 'failed')
13
+ host.stop('commit stopped by the pre-commit hook');
14
+ if (result.kind === 'stopped')
15
+ host.stop(result.reason);
19
16
  }
20
17
  //# sourceMappingURL=pre-commit.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pre-commit.js","sourceRoot":"","sources":["../../src/scripts/pre-commit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,+EAA+E;AAC/E,2EAA2E;AAC3E,0DAA0D;AAC1D,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,KAA8B;IAC5D,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IACtD,KAAK,MAAM,IAAI,IA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EACD,KAAK,CACN,CAAC;IACF,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ;QAC1B,IAAI,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;IACrD,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS;QAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC1D,CAAC"}
@@ -1,4 +1,4 @@
1
- import { Push } from '../push.ts';
1
+ import type { Push } from '../push.ts';
2
2
  import type { Step } from '../step.ts';
3
3
  export declare function prePush(steps: readonly Step<Push>[]): Promise<void>;
4
4
  //# sourceMappingURL=pre-push.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pre-push.d.ts","sourceRoot":"","sources":["../../src/scripts/pre-push.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAOvC,wBAAsB,OAAO,CAAC,KAAK,EAAE,SAAS,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA0BzE"}
1
+ {"version":3,"file":"pre-push.d.ts","sourceRoot":"","sources":["../../src/scripts/pre-push.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAMvC,wBAAsB,OAAO,CAAC,KAAK,EAAE,SAAS,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAezE"}
@@ -1,36 +1,20 @@
1
- import { text } from 'node:stream/consumers';
2
- import { Push } from "../push.js";
3
- // What a repo's `.husky/pre-push.ts` calls. Git runs the hook at the root of
4
- // the work tree, with the name and the URL of the remote as arguments and one
5
- // ref update on each line of the standard input. This is the one module that
6
- // prints and reads the arguments, the input and the environment, as a script
7
- // may.
1
+ import { runPrePush } from "../run/pre-push.js";
2
+ import { Host } from "./host.js";
3
+ // What a repo's `.husky/pre-push.ts` calls. Git gives the hook the name and
4
+ // the URL of the remote as arguments, and one ref update on each line of the
5
+ // standard input.
8
6
  export async function prePush(steps) {
9
- let current = '';
10
- const print = (name, message) => {
11
- const [first = '', ...rest] = message.split('\n');
12
- console.error(`${name.padEnd(9)} ${first}`);
13
- for (const line of rest)
14
- console.error(`${' '.repeat(10)}${line}`);
15
- };
16
- const [name = '', url = ''] = process.argv.slice(2);
17
- const push = await Push.read({
18
- root: process.cwd(),
19
- environment: process.env,
7
+ const host = new Host();
8
+ const [name = '', url = ''] = host.arguments;
9
+ const { kind } = await runPrePush({
10
+ root: host.root,
11
+ hookEnvironment: host.hookEnvironment,
12
+ toolEnvironment: await host.toolEnvironment(),
13
+ print: (step, message) => host.print(step, message),
20
14
  remote: { name, url },
21
- input: await text(process.stdin),
22
- notice: (message) => print(current, message),
23
- clock: globalThis,
24
- });
25
- for (const step of steps) {
26
- current = step.name;
27
- const outcome = await step.run(push);
28
- print(step.name, outcome.message);
29
- if (outcome.kind === 'fail') {
30
- console.error('✖ push stopped by the pre-push hook');
31
- process.exitCode = 1;
32
- return;
33
- }
34
- }
15
+ input: await host.input(),
16
+ }, steps);
17
+ if (kind === 'failed')
18
+ host.stop('push stopped by the pre-push hook');
35
19
  }
36
20
  //# sourceMappingURL=pre-push.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pre-push.js","sourceRoot":"","sources":["../../src/scripts/pre-push.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAGlC,6EAA6E;AAC7E,8EAA8E;AAC9E,6EAA6E;AAC7E,6EAA6E;AAC7E,OAAO;AACP,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,KAA4B;IACxD,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,MAAM,KAAK,GAAG,C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CAAC;YACrD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;YACrB,OAAO;QACT,CAAC;IACH,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"pre-push.js","sourceRoot":"","sources":["../../src/scripts/pre-push.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,4EAA4E;AAC5E,6EAA6E;AAC7E,kBAAkB;AAClB,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,KAA4B;IACxD,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IACxB,MAAM,CAAC,IAAI,GAAG,EAAE,EAAE,GAAG,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC;IAC7C,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,UAAU,CAC/B;QACE,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,eAAe,EAAE,IAAI,CAAC,eAAe;QACrC,eAAe,EAAE,MAAM,IAAI,CAAC,eAAe,EAAE;QAC7C,KAAK,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC;QACnD,MAAM,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE;QACrB,KAAK,EAAE,MAAM,IAAI,CAAC,KAAK,EAAE;KAC1B,EACD,KAAK,CACN,CAAC;IACF,IAAI,IAAI,KAAK,QAAQ;QAAE,IAAI,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;AACxE,CAAC"}
@@ -1,4 +1,2 @@
1
1
  export declare function hasInstallDrift(lockfile: string, hiddenLockfile: string): Promise<boolean>;
2
- export declare function linkTargets(lockfile: string): Promise<string[]>;
3
- export declare function withInstallScripts(lockfile: string): Promise<string[]>;
4
2
  //# sourceMappingURL=drift.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"drift.d.ts","sourceRoot":"","sources":["../../src/snapshot/drift.ts"],"names":[],"mappings":"AAcA,wBAAsB,eAAe,CACnC,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,OAAO,CAAC,CAmBlB;AAsBD,wBAAsB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAQrE;AAsBD,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAQ5E"}
1
+ {"version":3,"file":"drift.d.ts","sourceRoot":"","sources":["../../src/snapshot/drift.ts"],"names":[],"mappings":"AASA,wBAAsB,eAAe,CACnC,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,OAAO,CAAC,CAoBlB"}
@@ -1,20 +1,22 @@
1
1
  import { readFile } from 'node:fs/promises';
2
+ import { Lockfile } from "../npm/lockfile.js";
2
3
  // Whether the installed packages differ from the lockfile of a commit. npm's
3
4
  // hidden lockfile, node_modules/.package-lock.json, lists what is installed.
4
5
  // Each difference in the third-party packages is drift: a missing package, a
5
6
  // different version, or an extra package, which would build here and fail in
6
7
  // CI. Links are not compared: a workspace link points into the snapshot.
7
8
  export async function hasInstallDrift(lockfile, hiddenLockfile) {
8
- const wanted = await packagesOf(lockfile);
9
- let installed;
9
+ const wanted = Lockfile.parse(await readFile(lockfile, 'utf8')).thirdParty();
10
+ let hidden;
10
11
  try {
11
- installed = await packagesOf(hiddenLockfile);
12
+ hidden = await readFile(hiddenLockfile, 'utf8');
12
13
  }
13
14
  catch (error) {
14
15
  if (Error.isError(error) && 'code' in error && error.code === 'ENOENT')
15
16
  return true;
16
17
  throw error;
17
18
  }
19
+ const installed = Lockfile.parse(hidden).thirdParty();
18
20
  for (const [path, entry] of wanted) {
19
21
  const have = installed.get(path);
20
22
  if (have === undefined) {
@@ -30,58 +32,4 @@ export async function hasInstallDrift(lockfile, hiddenLockfile) {
30
32
  return true;
31
33
  return false;
32
34
  }
33
- // The third-party packages of a lockfile: the entries in a node_modules
34
- // folder that are not links.
35
- async function packagesOf(path) {
36
- const entries = new Map();
37
- for (const [key, value] of await lockPackages(path)) {
38
- if (!key.includes('node_modules/'))
39
- continue;
40
- const entry = {
41
- version: field(value, 'version'),
42
- link: field(value, 'link') === true,
43
- optional: field(value, 'optional') === true,
44
- hasInstallScript: field(value, 'hasInstallScript') === true,
45
- };
46
- if (!entry.link)
47
- entries.set(key, entry);
48
- }
49
- return entries;
50
- }
51
- // The folders that the links of a lockfile point to, relative to the folder
52
- // of the lockfile: the workspace packages, and each folder that a `file:`
53
- // dependency names.
54
- export async function linkTargets(lockfile) {
55
- const targets = new Set();
56
- for (const [, value] of await lockPackages(lockfile)) {
57
- const resolved = field(value, 'resolved');
58
- if (field(value, 'link') === true && typeof resolved === 'string')
59
- targets.add(resolved);
60
- }
61
- return [...targets];
62
- }
63
- async function lockPackages(path) {
64
- const lockfile = JSON.parse(await readFile(path, 'utf8'));
65
- const packages = typeof lockfile === 'object' && lockfile !== null && 'packages' in lockfile
66
- ? lockfile.packages
67
- : undefined;
68
- if (typeof packages !== 'object' || packages === null)
69
- throw new TypeError(`${path} has no "packages"; npm 7 or later writes it`);
70
- return Object.entries(packages);
71
- }
72
- function field(value, name) {
73
- return typeof value === 'object' && value !== null && name in value
74
- ? Reflect.get(value, name)
75
- : undefined;
76
- }
77
- // The third-party packages that the lockfile marks with an install script.
78
- // The root and the workspace packages have the mark too, but their scripts
79
- // must not run in the state folder.
80
- export async function withInstallScripts(lockfile) {
81
- const names = new Set();
82
- for (const [key, entry] of await packagesOf(lockfile))
83
- if (entry.hasInstallScript)
84
- names.add(key.slice(key.lastIndexOf('node_modules/') + 'node_modules/'.length));
85
- return [...names];
86
- }
87
35
  //# sourceMappingURL=drift.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"drift.js","sourceRoot":"","sources":["../../src/snapshot/drift.ts"],"names":[],"mappings":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able;
1
2
  export declare function installFor(state: string, snapshot: string, environment: NodeJS.ProcessEnv, installing: () => void, clock: {
2
3
  readonly Date: {
3
4
  now(): number;
@@ -1 +1 @@
1
- {"version":3,"file":"installs.d.ts","sourceRoot":"","sources":["../../src/snapshot/installs.ts"],"names":[],"mappings":"AA+BA,wBAAsB,UAAU,CAC9B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,CAAC,UAAU,EAC9B,UAAU,EAAE,MAAM,IAAI,EACtB,KAAK,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE;QAAE,GAAG,IAAI,MAAM,CAAA;KAAE,CAAA;CAAE,GAC1C,OAAO,CAAC,MAAM,CAAC,CAgBjB"}
1
+ {"version":3,"file":"installs.d.ts","sourceRoot":"","sources":["../../src/snapshot/installs.ts"],"names":[],"mappings":"AAkCA,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CASvD;AAOD,wBAAsB,UAAU,CAC9B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,CAAC,UAAU,EAC9B,UAAU,EAAE,MAAM,IAAI,EACtB,KAAK,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE;QAAE,GAAG,IAAI,MAAM,CAAA;KAAE,CAAA;CAAE,GAC1C,OAAO,CAAC,MAAM,CAAC,CAcjB"}