@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
@@ -1,25 +1,41 @@
1
1
  import { execFile } from 'node:child_process';
2
- import { hash } from 'node:crypto';
3
- import { existsSync } from 'node:fs';
4
- import { copyFile, cp, mkdir, readFile, readdir, rm, stat, utimes, writeFile, } from 'node:fs/promises';
2
+ import { hash, randomUUID } from 'node:crypto';
3
+ import { existsSync, mkdirSync, rmSync } from 'node:fs';
4
+ import { cp, mkdir, readFile, readdir, rm, stat, utimes, writeFile, } from 'node:fs/promises';
5
5
  import { basename, isAbsolute, join, normalize, sep } from 'node:path';
6
6
  import { promisify } from 'node:util';
7
- import { linkTargets, withInstallScripts } from "./drift.js";
7
+ import { FileLock } from '@zukhruf/fs';
8
+ import { Lockfile } from "../npm/lockfile.js";
8
9
  import { workspaceFolders } from "./workspaces.js";
9
10
  const execFileAsync = promisify(execFile);
10
11
  // The installs that the hook keeps: the ones that it used last.
11
12
  const kept = 2;
12
13
  // Written last, so a folder without it is an install that did not end.
13
14
  const marker = 'installed';
15
+ // One locked file in it for each snapshot that links to the install.
16
+ const leases = 'leases';
17
+ // Marks the install at `folder` as in use until the lease is disposed. The
18
+ // kernel holds the lock of the lease file, so a hook that dies lets it go.
19
+ // Take it under the lock of the installs, so no prune runs between the
20
+ // install and the lease.
21
+ export function leaseInstall(folder) {
22
+ mkdirSync(join(folder, leases), { recursive: true });
23
+ const path = join(folder, leases, `${randomUUID()}.lock`);
24
+ const lease = new DisposableStack();
25
+ const lock = lease.use(FileLock.open(path));
26
+ if (!lock.tryLock())
27
+ throw new Error(`another process holds the new lease ${path}`);
28
+ lease.defer(() => rmSync(path, { force: true }));
29
+ return lease;
30
+ }
14
31
  // An install of the lockfile of the snapshot in a folder of the state folder,
15
- // named by the hash of the lockfile. A second push with the same lockfile
16
- // uses the same install, with the linked folders of the snapshot. `installing`
17
- // runs before a new install, because a full install takes some time.
32
+ // named by the hash of the lockfile and the .npmrc. A second snapshot with the
33
+ // same two files uses the same install, with the linked folders of the
34
+ // snapshot. `installing` runs before a new install, because a full install
35
+ // takes some time. npm gets `environment`: the tool environment.
18
36
  export async function installFor(state, snapshot, environment, installing, clock) {
19
- const lockfile = await readFile(join(snapshot, 'package-lock.json'));
20
- const lockfileHash = hash('sha256', lockfile);
21
37
  const installs = join(state, 'installs');
22
- const folder = join(installs, lockfileHash.slice(0, 16));
38
+ const folder = join(installs, (await installKey(snapshot)).slice(0, 16));
23
39
  if (existsSync(join(folder, marker))) {
24
40
  const now = new Date(clock.Date.now());
25
41
  await utimes(join(folder, marker), now, now);
@@ -33,6 +49,22 @@ export async function installFor(state, snapshot, environment, installing, clock
33
49
  await prune(installs);
34
50
  return folder;
35
51
  }
52
+ // The sha256 of the lockfile and the .npmrc, with a NUL between them: a
53
+ // lockfile is JSON, which holds no NUL, so no two pairs of files give the
54
+ // same bytes. A snapshot without .npmrc hashes it as empty.
55
+ async function installKey(snapshot) {
56
+ const lockfile = await readFile(join(snapshot, 'package-lock.json'));
57
+ let npmrc;
58
+ try {
59
+ npmrc = await readFile(join(snapshot, '.npmrc'));
60
+ }
61
+ catch (error) {
62
+ if (!Error.isError(error) || !('code' in error) || error.code !== 'ENOENT')
63
+ throw error;
64
+ npmrc = Buffer.alloc(0);
65
+ }
66
+ return hash('sha256', Buffer.concat([lockfile, Buffer.from([0]), npmrc]));
67
+ }
36
68
  // `npm ci --ignore-scripts`, and then `npm rebuild` with only the
37
69
  // third-party packages that have install scripts, such as esbuild. The
38
70
  // scripts of the repo and of its workspace packages, such as `prepare`,
@@ -40,38 +72,46 @@ export async function installFor(state, snapshot, environment, installing, clock
40
72
  // names, `npm rebuild` runs them too. npm 12 runs only the dependency
41
73
  // scripts that `allowScripts` in the copied package.json approves.
42
74
  async function install(snapshot, folder, environment) {
43
- await mkdir(folder, { recursive: true });
44
- for (const file of ['package.json', 'package-lock.json', '.npmrc'])
45
- if (existsSync(join(snapshot, file)))
46
- await copyFile(join(snapshot, file), join(folder, file));
47
- for (const workspace of await workspaceFolders(snapshot)) {
48
- await mkdir(join(folder, workspace), { recursive: true });
49
- await copyFile(join(snapshot, workspace, 'package.json'), join(folder, workspace, 'package.json'));
50
- }
51
- await copyLinkedFolders(snapshot, folder);
75
+ // The full tree of the commit, as a clean checkout has it: each file that
76
+ // npm reads, such as the patch files of `patchedDependencies`, a
77
+ // `.npm-extension.mjs`, the workspace manifests and the folders of `file:`
78
+ // dependencies. A link keeps its text, so it points into the install.
79
+ await cp(snapshot, folder, {
80
+ recursive: true,
81
+ verbatimSymlinks: true,
82
+ filter: (source) => !['.git', 'node_modules'].includes(basename(source)),
83
+ });
52
84
  await npm(folder, environment, 'ci', '--ignore-scripts', '--no-audit', '--no-fund');
53
- const names = await withInstallScripts(join(folder, 'package-lock.json'));
85
+ const names = Lockfile.parse(await readFile(join(folder, 'package-lock.json'), 'utf8')).withInstallScripts();
54
86
  if (names.length > 0)
55
87
  await npm(folder, environment, 'rebuild', ...names);
56
88
  await writeFile(join(folder, marker), '');
57
89
  }
58
90
  // Copies each folder of the snapshot that a `file:` dependency links to into
59
- // the install. A package of the install that depends on it resolves it from
60
- // its real path in the install, so a link from the snapshot does not reach it.
61
- // The lockfile, which names the install, does not change when the files of the
62
- // folder change, so each snapshot copies the folder again. The copy keeps the
63
- // node_modules that npm installed in the folder. A folder in node_modules is
64
- // npm's, and a folder outside the repo is not in the snapshot: neither is
65
- // copied.
91
+ // the install that the snapshot uses again. A package of the install that
92
+ // depends on it resolves it from its real path in the install, so a link from
93
+ // the snapshot does not reach it. The lockfile, which names the install, does
94
+ // not change when the files of the folder change, so each snapshot copies the
95
+ // folder again. The copy keeps the node_modules that npm installed in the
96
+ // folder. A folder in node_modules is npm's, a folder outside the repo is not
97
+ // in the snapshot, and a workspace package links to its folder in the
98
+ // snapshot: none of them is copied. A folder that the lockfile names and the
99
+ // commit does not have, such as a workspace that .gitignore names, is not
100
+ // copied either (#4193).
66
101
  async function copyLinkedFolders(snapshot, folder) {
67
102
  const workspaces = new Set((await workspaceFolders(snapshot)).map(normalize));
68
- for (const target of await linkTargets(join(snapshot, 'package-lock.json'))) {
103
+ const lockfile = Lockfile.parse(await readFile(join(snapshot, 'package-lock.json'), 'utf8'));
104
+ for (const target of lockfile.linkTargets()) {
69
105
  const path = normalize(target);
70
106
  if (workspaces.has(path) ||
71
107
  path.startsWith('..') ||
72
108
  isAbsolute(path) ||
73
109
  path.split(sep).includes('node_modules'))
74
110
  continue;
111
+ // The copy first empties the folder of the install, so the source is
112
+ // checked before.
113
+ if (!existsSync(join(snapshot, path)))
114
+ continue;
75
115
  const destination = join(folder, path);
76
116
  await mkdir(destination, { recursive: true });
77
117
  for (const name of await readdir(destination))
@@ -108,7 +148,23 @@ async function prune(installs) {
108
148
  })));
109
149
  used.sort((left, right) => right.at - left.at);
110
150
  for (const [index, { name, at }] of used.entries())
111
- if (index >= kept || at < 0)
151
+ if ((index >= kept || at < 0) && !(await isLeased(join(installs, name))))
112
152
  await rm(join(installs, name), { recursive: true, force: true });
113
153
  }
154
+ // Whether a live snapshot links to the install. Only an install that the
155
+ // prune would delete is checked: the install that this process uses is the
156
+ // one it used last, which the prune keeps. That matters, because reading a
157
+ // lease file that this process holds would drop its lock (FileLock).
158
+ async function isLeased(folder) {
159
+ let names;
160
+ try {
161
+ names = await readdir(join(folder, leases));
162
+ }
163
+ catch (error) {
164
+ if (Error.isError(error) && 'code' in error && error.code === 'ENOENT')
165
+ return false;
166
+ throw error;
167
+ }
168
+ return names.some((name) => FileLock.check(join(folder, leases, name)) === 'locked');
169
+ }
114
170
  //# sourceMappingURL=installs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"installs.js","sourceRoot":"","sources":["../../src/snapshot/installs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EACL,QAAQ,EACR,EAAE,EACF,KAAK,EACL,QAAQ,EACR,OAAO,EACP,EAAE,EACF,IAAI,EACJ,MAAM,EACN,SAAS,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAC7D,O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EAAE,IAAI,CAAC,CAAC,KAAK,QAAQ,CAClE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { Clone } from './snapshots.ts';
2
+ export interface ProcessResult {
3
+ readonly status: number | null;
4
+ readonly stdout: string;
5
+ readonly stderr: string;
6
+ }
7
+ export interface RunOptions {
8
+ readonly env?: Readonly<Record<string, string>>;
9
+ }
10
+ export declare class Snapshot {
11
+ #private;
12
+ readonly folder: string;
13
+ constructor(clone: Clone);
14
+ run(command: string, args: readonly string[], options?: RunOptions): Promise<ProcessResult>;
15
+ }
16
+ export declare class PackagedSnapshot extends Snapshot {
17
+ readonly nxCacheDirectory: string;
18
+ constructor(clone: Clone);
19
+ bin(name: string, args: readonly string[], options?: RunOptions): Promise<ProcessResult>;
20
+ }
21
+ //# sourceMappingURL=snapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../src/snapshot/snapshot.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAI5C,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAGD,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACjD;AAKD,qBAAa,QAAQ;;IACnB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAGZ,KAAK,EAAE,KAAK;IAWlB,GAAG,CACP,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,OAAO,GAAE,UAAe,GACvB,OAAO,CAAC,aAAa,CAAC;CAmB1B;AAID,qBAAa,gBAAiB,SAAQ,QAAQ;IAE5C,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;gBAEtB,KAAK,EAAE,KAAK;IAOxB,GAAG,CACD,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,OAAO,GAAE,UAAe,GACvB,OAAO,CAAC,aAAa,CAAC;CAW1B"}
@@ -0,0 +1,54 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { join } from 'node:path';
3
+ import { text } from 'node:stream/consumers';
4
+ // A commit checked out in a temporary folder, where a step runs its tools.
5
+ // Git there sees a clean checkout of the commit. Each command gets the tool
6
+ // environment, with NX_DAEMON=false and the nx cache of the state folder.
7
+ export class Snapshot {
8
+ folder;
9
+ #environment;
10
+ constructor(clone) {
11
+ this.folder = clone.folder;
12
+ this.#environment = clone.environment;
13
+ }
14
+ // Runs a command from the PATH, or a file at an absolute path, in the
15
+ // snapshot. An exit code other than 0 is a result, not an error. A command
16
+ // that cannot start throws the error of Node. No shell runs, except on
17
+ // Windows for a .cmd file and for a command from the PATH, which can be a
18
+ // .cmd file such as npm: Node starts a .cmd file only through a shell. The
19
+ // arguments then get no quotes.
20
+ async run(command, args, options = {}) {
21
+ const child = spawn(command, args, {
22
+ cwd: this.folder,
23
+ env: { ...this.#environment, ...options.env },
24
+ stdio: ['ignore', 'pipe', 'pipe'],
25
+ shell: process.platform === 'win32' &&
26
+ (command.endsWith('.cmd') || !/[\\/]/.test(command)),
27
+ });
28
+ const [stdout, stderr, status] = await Promise.all([
29
+ text(child.stdout),
30
+ text(child.stderr),
31
+ new Promise((resolve, reject) => {
32
+ child.once('error', reject);
33
+ child.once('close', resolve);
34
+ }),
35
+ ]);
36
+ return { status, stdout, stderr };
37
+ }
38
+ }
39
+ // A snapshot with a node_modules: the packages of the commit's own lockfile,
40
+ // and each workspace package from its folder in the snapshot.
41
+ export class PackagedSnapshot extends Snapshot {
42
+ // The nx cache of the state folder, where nx writes the summary of its run.
43
+ nxCacheDirectory;
44
+ constructor(clone) {
45
+ super(clone);
46
+ this.nxCacheDirectory = clone.nxCacheDirectory;
47
+ }
48
+ // Runs `node_modules/.bin/<name>` of the snapshot, as `run` does. On
49
+ // Windows, npm writes `<name>.cmd` there.
50
+ bin(name, args, options = {}) {
51
+ return this.run(join(this.folder, 'node_modules/.bin', process.platform === 'win32' ? `${name}.cmd` : name), args, options);
52
+ }
53
+ }
54
+ //# sourceMappingURL=snapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../../src/snapshot/snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAiB7C,2EAA2E;AAC3E,4EAA4E;AAC5E,0EAA0E;AAC1E,MAAM,OAAO,QAAQ;IACV,MAAM,CAAS;IACf,YAAY,CAAoB;IAEzC,YAAY,KAAY;QACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,WAAW,CAAC;IACxC,CAAC;IAED,sEAAsE;IACtE,2EAA2E;IAC3E,uEAAuE;IACvE,0EAA0E;IAC1E,2EAA2E;IAC3E,gCAAgC;IAChC,KAAK,CAAC,GAAG,CACP,OAAe,EACf,IAAuB,EACvB,UAAsB,EAAE;QAExB,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE;YACjC,GAAG,EAAE,IAAI,CAAC,MAAM;YAChB,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,YAAY,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE;YAC7C,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;YACjC,KAAK,EACH,OAAO,CAAC,QAAQ,KAAK,OAAO;gBAC5B,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACvD,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACjD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;YAClB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;YAClB,IAAI,OAAO,CAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBAC7C,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;gBAC5B,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC/B,CAAC,CAAC;SACH,CAAC,CAAC;QACH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IACpC,CAAC;CACF;AAED,6EAA6E;AAC7E,8DAA8D;AAC9D,MAAM,OAAO,gBAAiB,SAAQ,QAAQ;IAC5C,4EAA4E;IACnE,gBAAgB,CAAS;IAElC,YAAY,KAAY;QACtB,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC,gBAAgB,CAAC;IACjD,CAAC;IAED,qEAAqE;IACrE,0CAA0C;IAC1C,GAAG,CACD,IAAY,EACZ,IAAuB,EACvB,UAAsB,EAAE;QAExB,OAAO,IAAI,CAAC,GAAG,CACb,IAAI,CACF,IAAI,CAAC,MAAM,EACX,mBAAmB,EACnB,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,CACpD,EACD,IAAI,EACJ,OAAO,CACR,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,30 @@
1
+ import { type WallClock } from '@zukhruf/async';
2
+ import { type Git } from '../git.ts';
3
+ export declare class MissingLockfileError extends Error {
4
+ constructor(commit: string);
5
+ }
6
+ export interface Clone {
7
+ readonly folder: string;
8
+ readonly environment: NodeJS.ProcessEnv;
9
+ readonly nxCacheDirectory: string;
10
+ }
11
+ export type HookKind = 'pre-commit' | 'pre-push';
12
+ interface SnapshotsOptions {
13
+ readonly hook: HookKind;
14
+ readonly root: string;
15
+ readonly git: Git;
16
+ readonly toolEnvironment: NodeJS.ProcessEnv;
17
+ readonly notice: (message: string) => void;
18
+ readonly clock: WallClock;
19
+ }
20
+ export declare function stateFolder(git: Git): Promise<string>;
21
+ export declare class Snapshots implements AsyncDisposable {
22
+ #private;
23
+ readonly toolEnvironment: NodeJS.ProcessEnv;
24
+ constructor({ hook, root, git, toolEnvironment, notice, clock, }: SnapshotsOptions);
25
+ open(commit: string, name: string, packages: boolean): Promise<Clone>;
26
+ openPrivate(commit: string, name: string): Promise<Clone & AsyncDisposable>;
27
+ [Symbol.asyncDispose](): Promise<void>;
28
+ }
29
+ export {};
30
+ //# sourceMappingURL=snapshots.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshots.d.ts","sourceRoot":"","sources":["../../src/snapshot/snapshots.ts"],"names":[],"mappings":"AAIA,OAAO,EAAS,KAAK,SAAS,EAAQ,MAAM,gBAAgB,CAAC;AAG7D,OAAO,EAAE,KAAK,GAAG,EAAS,MAAM,WAAW,CAAC;AAK5C,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,MAAM,EAAE,MAAM;CAI3B;AAGD,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,UAAU,CAAC;IACxC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;CACnC;AAmBD,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAG,UAAU,CAAC;AAEjD,UAAU,gBAAgB;IACxB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAExB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAElB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC,UAAU,CAAC;IAE5C,QAAQ,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAG3C,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;CAC3B;AAKD,wBAAsB,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAS3D;AAOD,qBAAa,SAAU,YAAW,eAAe;;IAC/C,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC,UAAU,CAAC;gBAWhC,EACV,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,eAAe,EACf,MAAM,EACN,KAAK,GACN,EAAE,gBAAgB;IAWb,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC;IAmBrE,WAAW,CACf,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,KAAK,GAAG,eAAe,CAAC;IAe7B,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;CAoH7C"}
@@ -0,0 +1,180 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { mkdir } from 'node:fs/promises';
3
+ import { join } from 'node:path';
4
+ import { Latch, poll } from '@zukhruf/async';
5
+ import { FileLock, TemporaryFiles } from '@zukhruf/fs';
6
+ import { gitIn } from "../git.js";
7
+ import { hasInstallDrift } from "./drift.js";
8
+ import { installFor, leaseInstall } from "./installs.js";
9
+ import { linkPackages } from "./packages.js";
10
+ export class MissingLockfileError extends Error {
11
+ constructor(commit) {
12
+ super(`${commit} has no package-lock.json`);
13
+ this.name = 'MissingLockfileError';
14
+ }
15
+ }
16
+ // The folder `git-hooks` in the common git folder of the repo, where both
17
+ // hooks keep the installs, the locks and the nx caches. Linked worktrees use
18
+ // the same one.
19
+ export async function stateFolder(git) {
20
+ const state = join((await git('rev-parse', '--path-format=absolute', '--git-common-dir')).trim(), 'git-hooks');
21
+ await mkdir(state, { recursive: true });
22
+ return state;
23
+ }
24
+ // The snapshots of one run of a hook: one clone of the repo for each commit,
25
+ // made at the first ask. The clone shares the objects of the repo
26
+ // (`git clone --shared`), so git copies none, and git commands in it see a
27
+ // clean checkout of the commit. A later ask for packages links a node_modules into the same clone. Disposing
28
+ // deletes each clone and lets each lock go.
29
+ export class Snapshots {
30
+ toolEnvironment;
31
+ #hook;
32
+ #root;
33
+ #git;
34
+ #notice;
35
+ #clock;
36
+ #stack = new AsyncDisposableStack();
37
+ #opened = new Map();
38
+ // The build lock, taken at the first open of a pre-push snapshot.
39
+ #holdBuildLock = memoized(() => this.#acquireBuildLock());
40
+ constructor({ hook, root, git, toolEnvironment, notice, clock, }) {
41
+ this.toolEnvironment = toolEnvironment;
42
+ this.#hook = hook;
43
+ this.#root = root;
44
+ this.#git = git;
45
+ this.#notice = notice;
46
+ this.#clock = clock;
47
+ }
48
+ // The clone of `commit`, with a node_modules when `packages` is true.
49
+ // `name` names the commit in a notice or an error.
50
+ async open(commit, name, packages) {
51
+ if (this.#hook === 'pre-push') {
52
+ await this.#holdBuildLock();
53
+ await this.#evictOtherThan(commit);
54
+ }
55
+ const opened = this.#opened.get(commit) ?? this.#start(commit);
56
+ const clone = await settled(opened.clone);
57
+ if (packages) {
58
+ opened.packages ??= outcomeOf(() => this.#link(clone, name, opened.resources));
59
+ await settled(opened.packages);
60
+ }
61
+ return clone;
62
+ }
63
+ // A clone of `commit` with packages that no other caller shares: a step
64
+ // that writes files writes them there, so the steps that read the shared
65
+ // snapshot never see them. Disposing it deletes the clone.
66
+ async openPrivate(commit, name) {
67
+ const resources = new AsyncDisposableStack();
68
+ try {
69
+ const clone = await this.#clone(commit, resources);
70
+ await this.#link(clone, name, resources);
71
+ return {
72
+ ...clone,
73
+ [Symbol.asyncDispose]: () => resources.disposeAsync(),
74
+ };
75
+ }
76
+ catch (error) {
77
+ await resources.disposeAsync();
78
+ throw error;
79
+ }
80
+ }
81
+ async [Symbol.asyncDispose]() {
82
+ for (const opened of this.#opened.values())
83
+ await opened.resources.disposeAsync();
84
+ this.#opened.clear();
85
+ await this.#stack.disposeAsync();
86
+ }
87
+ #start(commit) {
88
+ const resources = new AsyncDisposableStack();
89
+ const opened = {
90
+ clone: outcomeOf(() => this.#clone(commit, resources)),
91
+ packages: undefined,
92
+ resources,
93
+ };
94
+ this.#opened.set(commit, opened);
95
+ return opened;
96
+ }
97
+ // A push with many heads builds one head after another: the clone of an
98
+ // earlier head goes before the next one is made, as one build at a time
99
+ // used one folder at a time.
100
+ async #evictOtherThan(commit) {
101
+ for (const [other, opened] of this.#opened)
102
+ if (other !== commit) {
103
+ this.#opened.delete(other);
104
+ await opened.resources.disposeAsync();
105
+ }
106
+ }
107
+ async #acquireBuildLock() {
108
+ const lock = await acquire(join(await stateFolder(this.#git), 'build.lock'), () => this.#notice('waiting for another pre-push build in this repo'), this.#clock);
109
+ this.#stack.use(lock);
110
+ }
111
+ async #clone(commit, resources) {
112
+ const cache = join(await stateFolder(this.#git), this.#hook === 'pre-push' ? 'nx' : 'nx-pre-commit');
113
+ const temporary = resources.use(await new TemporaryFiles().directory('git-hooks-snapshot-'));
114
+ const folder = join(temporary.path, 'tree');
115
+ await gitIn(temporary.path, this.toolEnvironment)('clone', '--shared', '--no-checkout', '--quiet', this.#root, folder);
116
+ await gitIn(folder, this.toolEnvironment)('checkout', '--detach', '--quiet', commit);
117
+ return {
118
+ folder,
119
+ nxCacheDirectory: cache,
120
+ environment: {
121
+ ...this.toolEnvironment,
122
+ NX_DAEMON: 'false',
123
+ NX_CACHE_DIRECTORY: cache,
124
+ NX_WORKSPACE_DATA_DIRECTORY: join(cache, 'workspace-data'),
125
+ },
126
+ };
127
+ }
128
+ // Uses the packages that the repo installed when they match the lockfile
129
+ // of the commit, and else an install of that lockfile in the state folder.
130
+ // The install, its prune and the lease on it happen under one lock, so a
131
+ // hook never deletes an install that a snapshot of another hook links to.
132
+ async #link(clone, name, resources) {
133
+ const lockfile = join(clone.folder, 'package-lock.json');
134
+ if (!existsSync(lockfile))
135
+ throw new MissingLockfileError(name);
136
+ if (!(await hasInstallDrift(lockfile, join(this.#root, 'node_modules/.package-lock.json'))))
137
+ return linkPackages(this.#root, clone.folder);
138
+ const state = await stateFolder(this.#git);
139
+ let installed;
140
+ {
141
+ using _ = await acquire(join(state, 'installs.lock'), () => this.#notice(`${name}: waiting for an install of another hook`), this.#clock);
142
+ installed = await installFor(state, clone.folder, this.toolEnvironment, () => this.#notice(`${name}: the installed packages differ from package-lock.json; installing it with npm ci (first time for this lockfile)`), this.#clock);
143
+ resources.use(leaseInstall(installed));
144
+ }
145
+ await linkPackages(installed, clone.folder);
146
+ }
147
+ }
148
+ // Takes the lock on the file at `path`, and waits while another process
149
+ // holds it.
150
+ async function acquire(path, waiting, clock) {
151
+ const lock = FileLock.open(path);
152
+ if (!lock.tryLock()) {
153
+ waiting();
154
+ await poll(async () => (lock.tryLock() ? true : undefined), {
155
+ interval: 200,
156
+ clock,
157
+ signal: undefined,
158
+ });
159
+ }
160
+ return lock;
161
+ }
162
+ // `work`, run at the first call; each later call waits for the same outcome.
163
+ function memoized(work) {
164
+ let outcome;
165
+ return () => settled((outcome ??= outcomeOf(work)));
166
+ }
167
+ // The outcome of `work`: it starts now, and each caller waits for the same
168
+ // outcome.
169
+ function outcomeOf(work) {
170
+ const outcome = new Latch();
171
+ void Promise.allSettled([Promise.try(work)]).then(([result]) => outcome.open(result));
172
+ return outcome;
173
+ }
174
+ async function settled(outcome) {
175
+ const result = await outcome.wait();
176
+ if (result.status === 'rejected')
177
+ throw result.reason;
178
+ return result.value;
179
+ }
180
+ //# sourceMappingURL=snapshots.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshots.js","sourceRoot":"","sources":["../../src/snapshot/snapshots.ts"],"names":[],"mappings":"AAAA,OAAO,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AAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,KAAK,UAAU,OAAO,CAAI,OAAmB;IAC3C,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;IACpC,IAAI,MAAM,CAAC,MAAM,KAAK,UAAU;QAAE,MAAM,MAAM,CAAC,MAAM,CAAC;IACtD,OAAO,MAAM,CAAC,KAAK,CAAC;AACtB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,KAAK,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAU/C,qBAAa,IAAK,SAAQ,IAAI,CAAC,MAAM,CAAC;;IACpC,QAAQ,CAAC,IAAI,UAAU;gBAGX,EACV,KAA6B,GAC9B,GAAE;QAAE,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;KAAO;IAK/B,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAmB5C"}
1
+ {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,KAAK,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAQ/C,qBAAa,IAAK,SAAQ,IAAI,CAAC,MAAM,CAAC;;IACpC,QAAQ,CAAC,IAAI,UAAU;gBAGX,EACV,KAA6B,GAC9B,GAAE;QAAE,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;KAAO;IAK/B,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAuB5C"}
package/dist/sync.js CHANGED
@@ -1,13 +1,10 @@
1
- import { matchesGlob } from 'node:path';
2
1
  import { Step } from "./step.js";
3
- // Runs `nx sync`, then stages the files that it wrote. `sync.applyChanges`
4
- // in nx.json applies only in an interactive terminal, so a commit from a GUI
5
- // client or an agent shell would miss the synced files.
6
- //
7
- // A file counts as synced when it changed during the run and matches `stage`:
8
- // the file names that the repo's sync generators write. Any other change
9
- // during the run, or a file that was already modified before it, belongs to
10
- // another session that edits the same working tree.
2
+ // Runs `nx sync` on the staged commit, then stages the files that it wrote
3
+ // there and that match `stage`: the file names that the repo's sync
4
+ // generators write. `sync.applyChanges` in nx.json applies only in an
5
+ // interactive terminal, so a commit from a GUI client or an agent shell would
6
+ // miss the synced files. nx syncs the staged tree, not the working tree, so a
7
+ // file that another session edits is judged as the commit holds it.
11
8
  export class Sync extends Step {
12
9
  name = 'sync';
13
10
  #globs;
@@ -16,9 +13,13 @@ export class Sync extends Step {
16
13
  this.#globs = stage;
17
14
  }
18
15
  async run(commit) {
19
- const before = new Set(await commit.modified());
16
+ let generated;
20
17
  try {
21
- await commit.nx('sync');
18
+ generated = await commit.generate(this.#globs, async (snapshot) => {
19
+ const { status, stdout, stderr } = await snapshot.bin('nx', ['sync']);
20
+ if (status !== 0)
21
+ throw new Error(`nx sync exited with ${status}:\n${`${stdout}${stderr}`.trimEnd()}`);
22
+ });
22
23
  }
23
24
  catch (error) {
24
25
  // A failed sync is the step's outcome: the author reads nx's reason, not
@@ -27,12 +28,11 @@ export class Sync extends Step {
27
28
  throw error;
28
29
  return this.fail(error.message.trimEnd());
29
30
  }
30
- const synced = (await commit.modified()).filter((path) => !before.has(path) &&
31
- this.#globs.some((glob) => matchesGlob(path, glob)));
32
- if (synced.length === 0)
31
+ if (generated.kind === 'not-staged')
32
+ return this.fail(generated.reason);
33
+ if (generated.entries.length === 0)
33
34
  return this.pass('nx sync wrote nothing to stage');
34
- await commit.stage(synced);
35
- return this.pass(`staged what nx sync wrote: ${synced.join(', ')}`);
35
+ return this.pass(`staged what nx sync wrote: ${generated.entries.map(({ path }) => path).join(', ')}`);
36
36
  }
37
37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C,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,yEAAyE;YACzE,6BAA6B;YAC7B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;gBAAE,MAAM,KAAK,CAAC;YACvC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5C,CAAC;QACD,IAAI,SAAS,CAAC,IAAI,KAAK,YAAY;YAAE,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACxE,IAAI,SAAS,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;YAChC,OAAO,IAAI,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC,IAAI,CACd,8BAA8B,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACrF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,23 @@
1
+ import type { CommitMessage } from './commit-message.ts';
2
+ import type { Commit } from './commit.ts';
3
+ import type { Push } from './push.ts';
4
+ import type { Outcome, Step } from './step.ts';
5
+ export declare function preCommit({ root, environment }: {
6
+ root: string;
7
+ environment: NodeJS.ProcessEnv;
8
+ }, steps: readonly Step<Commit>[]): Promise<readonly Outcome[]>;
9
+ export declare function prePush({ root, environment, remote, input, }: {
10
+ root: string;
11
+ environment: NodeJS.ProcessEnv;
12
+ remote: {
13
+ name: string;
14
+ url: string;
15
+ };
16
+ input: string;
17
+ }, steps: readonly Step<Push>[]): Promise<readonly Outcome[]>;
18
+ export declare function commitMsg({ root, environment, file, }: {
19
+ root: string;
20
+ environment: NodeJS.ProcessEnv;
21
+ file: string;
22
+ }, steps: readonly Step<CommitMessage>[]): Promise<readonly Outcome[]>;
23
+ //# sourceMappingURL=testing.d.ts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