@smoothbricks/nx-plugin 0.6.2 → 0.7.0

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 (177) hide show
  1. package/README.md +417 -171
  2. package/dist/.build-inputs.json +39 -28
  3. package/dist/bin/smoo-nx-go-test-build.d.ts +3 -0
  4. package/dist/bin/smoo-nx-go-test-build.d.ts.map +1 -0
  5. package/dist/bin/smoo-nx-go-test-build.js +79 -0
  6. package/dist/bin/smoo-nx-go-test-run.d.ts +3 -0
  7. package/dist/bin/smoo-nx-go-test-run.d.ts.map +1 -0
  8. package/dist/bin/smoo-nx-go-test-run.js +129 -0
  9. package/dist/bin/smoo-nx-publish.d.ts +3 -0
  10. package/dist/bin/smoo-nx-publish.d.ts.map +1 -0
  11. package/dist/bin/smoo-nx-publish.js +3 -0
  12. package/dist/bounded-test-policy.d.ts +1 -1
  13. package/dist/bounded-test-policy.d.ts.map +1 -1
  14. package/dist/bounded-test-policy.js +9 -8
  15. package/dist/cargo-retention-hook.d.ts +6 -2
  16. package/dist/cargo-retention-hook.d.ts.map +1 -1
  17. package/dist/cargo-retention-hook.js +13 -7
  18. package/dist/cargo-workspace.d.ts +10 -20
  19. package/dist/cargo-workspace.d.ts.map +1 -1
  20. package/dist/cargo-workspace.js +12 -22
  21. package/dist/cross-check-policy.d.ts +2 -2
  22. package/dist/cross-check-policy.js +2 -2
  23. package/dist/deploy-policy.d.ts +6 -0
  24. package/dist/deploy-policy.d.ts.map +1 -1
  25. package/dist/deploy-policy.js +11 -0
  26. package/dist/eslint-file-set.d.ts +4 -1
  27. package/dist/eslint-file-set.d.ts.map +1 -1
  28. package/dist/eslint-sources.d.ts +25 -0
  29. package/dist/eslint-sources.d.ts.map +1 -0
  30. package/dist/eslint-sources.js +99 -0
  31. package/dist/executors/all-verdicts/executor.d.ts +2 -1
  32. package/dist/executors/all-verdicts/executor.d.ts.map +1 -1
  33. package/dist/executors/all-verdicts/executor.js +48 -2
  34. package/dist/executors/all-verdicts/schema.d.ts +13 -0
  35. package/dist/executors/all-verdicts/schema.d.ts.map +1 -1
  36. package/dist/executors/all-verdicts/schema.js +7 -0
  37. package/dist/executors/bounded-exec/bounds.d.ts +57 -8
  38. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -1
  39. package/dist/executors/bounded-exec/bounds.js +100 -11
  40. package/dist/executors/bounded-exec/executor.d.ts +2 -1
  41. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  42. package/dist/executors/bounded-exec/executor.js +289 -34
  43. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +2 -0
  44. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  45. package/dist/executors/bounded-exec/hang-diagnostics.js +2 -2
  46. package/dist/executors/bounded-exec/mbx-pool.d.ts +56 -10
  47. package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
  48. package/dist/executors/bounded-exec/mbx-pool.js +145 -11
  49. package/dist/executors/bounded-exec/mbx-queue.d.ts +30 -0
  50. package/dist/executors/bounded-exec/mbx-queue.d.ts.map +1 -0
  51. package/dist/executors/bounded-exec/mbx-queue.js +229 -0
  52. package/dist/executors/bounded-exec/progress.d.ts +9 -2
  53. package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
  54. package/dist/executors/bounded-exec/progress.js +151 -25
  55. package/dist/executors/bounded-exec/runner-sizing.d.ts +40 -2
  56. package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -1
  57. package/dist/executors/bounded-exec/runner-sizing.js +55 -4
  58. package/dist/executors/bounded-exec/runtime-pin.js +1 -1
  59. package/dist/executors/bounded-exec/test-result-writer.d.ts +30 -0
  60. package/dist/executors/bounded-exec/test-result-writer.d.ts.map +1 -0
  61. package/dist/executors/bounded-exec/test-result-writer.js +126 -0
  62. package/dist/executors/bounded-exec/test-results.d.ts +33 -0
  63. package/dist/executors/bounded-exec/test-results.d.ts.map +1 -0
  64. package/dist/executors/bounded-exec/test-results.js +33 -0
  65. package/dist/executors/bounded-exec/verdict.d.ts +26 -2
  66. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  67. package/dist/executors/bounded-exec/verdict.js +108 -4
  68. package/dist/executors/wrangler-deploy/deploy-hash.d.ts +10 -0
  69. package/dist/executors/wrangler-deploy/deploy-hash.d.ts.map +1 -0
  70. package/dist/executors/wrangler-deploy/deploy-hash.js +14 -0
  71. package/dist/executors/wrangler-deploy/executor.d.ts +24 -0
  72. package/dist/executors/wrangler-deploy/executor.d.ts.map +1 -0
  73. package/dist/executors/wrangler-deploy/executor.js +43 -0
  74. package/dist/executors/wrangler-deploy/hasher.d.ts +27 -0
  75. package/dist/executors/wrangler-deploy/hasher.d.ts.map +1 -0
  76. package/dist/executors/wrangler-deploy/hasher.js +90 -0
  77. package/dist/executors/wrangler-deploy/schema.d.ts +5 -0
  78. package/dist/executors/wrangler-deploy/schema.d.ts.map +1 -0
  79. package/dist/go-tests.d.ts +30 -0
  80. package/dist/go-tests.d.ts.map +1 -0
  81. package/dist/go-tests.js +43 -0
  82. package/dist/index.d.ts +12 -4
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +338 -295
  85. package/dist/managed-files/files.d.ts.map +1 -1
  86. package/dist/managed-files/files.js +5 -0
  87. package/dist/nx-publish.d.ts +24 -0
  88. package/dist/nx-publish.d.ts.map +1 -0
  89. package/dist/nx-publish.js +150 -0
  90. package/dist/process-group.js +2 -2
  91. package/dist/runtime-input-policy.d.ts +17 -3
  92. package/dist/runtime-input-policy.d.ts.map +1 -1
  93. package/dist/runtime-input-policy.js +4 -4
  94. package/dist/test-timings.d.ts +23 -4
  95. package/dist/test-timings.d.ts.map +1 -1
  96. package/dist/test-timings.js +72 -12
  97. package/dist/tool-bins.d.ts +6 -8
  98. package/dist/tool-bins.d.ts.map +1 -1
  99. package/dist/tool-bins.js +7 -5
  100. package/dist/version-actions.cjs +10 -11
  101. package/dist/version-actions.d.cts.map +1 -1
  102. package/dist/workspace-config-policy.d.ts.map +1 -1
  103. package/dist/workspace-config-policy.js +17 -22
  104. package/dist/workspace-index.d.ts +7 -0
  105. package/dist/workspace-index.d.ts.map +1 -1
  106. package/dist/workspace-index.js +11 -0
  107. package/dist/workspace-manifest.js +3 -3
  108. package/executors.json +7 -6
  109. package/managed/raw/patches/nx@23.2.1.patch +118 -24
  110. package/managed/raw/patches/ttsc@0.34.1.patch +139 -0
  111. package/managed/raw/tooling/devenv +1 -2
  112. package/managed/raw/tooling/direnv/developer-links.ts +124 -51
  113. package/managed/raw/tooling/direnv/devenv.smoo.nix +34 -15
  114. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -10
  115. package/managed/raw/tooling/direnv/installed-bun-links.ts +7 -6
  116. package/managed/raw/tooling/direnv/setup-environment.ts +49 -24
  117. package/managed/raw/tooling/direnv/ttsc-env.sh +8 -6
  118. package/managed/raw/tooling/git-hooks/pinned-revisions-served.ts +252 -0
  119. package/managed/raw/tooling/git-hooks/pre-push.sh +34 -32
  120. package/managed/templates/github/actions/cache-node-modules/action.yml +1 -1
  121. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +12 -11
  122. package/package.json +277 -11
  123. package/runtime/nx-publish/.build-inputs.json +11 -0
  124. package/runtime/nx-publish/cache_adapter.js +45 -0
  125. package/runtime/nx-publish/nx_publish.js +60 -0
  126. package/runtime-input.sh +62 -26
  127. package/src/bin/smoo-nx-go-test-build.ts +83 -0
  128. package/src/bin/smoo-nx-go-test-run.ts +140 -0
  129. package/src/bin/smoo-nx-publish.ts +4 -0
  130. package/src/bounded-test-policy.ts +9 -8
  131. package/src/cargo-retention-hook.ts +16 -10
  132. package/src/cargo-workspace.ts +12 -24
  133. package/src/cross-check-policy.ts +2 -2
  134. package/src/deploy-policy.ts +11 -0
  135. package/src/eslint-file-set.ts +4 -1
  136. package/src/eslint-sources.ts +134 -0
  137. package/src/executors/all-verdicts/executor.ts +58 -3
  138. package/src/executors/all-verdicts/schema.json +4 -0
  139. package/src/executors/all-verdicts/schema.ts +14 -0
  140. package/src/executors/bounded-exec/bounds.ts +132 -15
  141. package/src/executors/bounded-exec/executor.ts +329 -34
  142. package/src/executors/bounded-exec/hang-diagnostics.ts +3 -2
  143. package/src/executors/bounded-exec/mbx-pool.ts +158 -17
  144. package/src/executors/bounded-exec/mbx-queue.ts +170 -0
  145. package/src/executors/bounded-exec/progress.ts +171 -18
  146. package/src/executors/bounded-exec/runner-sizing.ts +73 -7
  147. package/src/executors/bounded-exec/runtime-pin.ts +1 -1
  148. package/src/executors/bounded-exec/test-result-writer.ts +152 -0
  149. package/src/executors/bounded-exec/test-results.ts +39 -0
  150. package/src/executors/bounded-exec/verdict.ts +115 -5
  151. package/src/executors/wrangler-deploy/deploy-hash.ts +15 -0
  152. package/src/executors/wrangler-deploy/executor.ts +63 -0
  153. package/src/executors/wrangler-deploy/hasher.ts +111 -0
  154. package/src/executors/wrangler-deploy/schema.json +16 -0
  155. package/src/executors/wrangler-deploy/schema.ts +4 -0
  156. package/src/go-tests.ts +67 -0
  157. package/src/index.ts +368 -323
  158. package/src/managed-files/files.ts +5 -0
  159. package/src/nx-publish.ts +157 -0
  160. package/src/process-group.ts +2 -2
  161. package/src/runtime-input-policy.ts +4 -4
  162. package/src/test-timings.ts +72 -14
  163. package/src/tool-bins.ts +13 -9
  164. package/src/version-actions.cts +10 -11
  165. package/src/workspace-config-policy.ts +20 -29
  166. package/src/workspace-index.ts +12 -0
  167. package/src/workspace-manifest.ts +3 -3
  168. package/test-timings.json +131 -125
  169. package/dist/executors/clean-outputs/executor.d.ts +0 -26
  170. package/dist/executors/clean-outputs/executor.d.ts.map +0 -1
  171. package/dist/executors/clean-outputs/executor.js +0 -83
  172. package/dist/executors/clean-outputs/schema.d.ts +0 -4
  173. package/dist/executors/clean-outputs/schema.d.ts.map +0 -1
  174. package/src/executors/clean-outputs/executor.ts +0 -131
  175. package/src/executors/clean-outputs/schema.json +0 -15
  176. package/src/executors/clean-outputs/schema.ts +0 -3
  177. /package/dist/executors/{clean-outputs → wrangler-deploy}/schema.js +0 -0
@@ -211,6 +211,11 @@ const managedFiles: ManagedFileDescriptor[] = [
211
211
  target: 'tooling/git-hooks/pre-push.sh',
212
212
  executable: true,
213
213
  },
214
+ {
215
+ kind: 'raw',
216
+ source: 'tooling/git-hooks/pinned-revisions-served.ts',
217
+ target: 'tooling/git-hooks/pinned-revisions-served.ts',
218
+ },
214
219
  {
215
220
  kind: 'raw',
216
221
  source: 'tooling/git-reword-commit',
@@ -0,0 +1,157 @@
1
+ // Accepted-task publication for declared gates (specs/cowshed/05_gateway.md, "Publication").
2
+ // Capture each successful Nx invocation before another overwrites run.json; publish the captured lists only after
3
+ // the entire gate passes. Ordinary shed clients remain read-only.
4
+
5
+ import { spawn } from 'node:child_process';
6
+ import { readFileSync } from 'node:fs';
7
+ import { isAbsolute, join } from 'node:path';
8
+ import { fileURLToPath } from 'node:url';
9
+
10
+ const USAGE = 'usage: smoo-nx-publish hashes RUN_JSON SINCE_EPOCH | publish CHECKOUT HASHES_JSON\n';
11
+
12
+ /** A task hash as the gateway's cache route takes it (05_gateway.md). */
13
+ const TASK_HASH = /^[A-Za-z0-9_-]{1,128}$/;
14
+
15
+ // One cached producer copies the unchanged canonical cowshed scripts outside the TypeScript output tree.
16
+ const PUBLISH_ASSETS = fileURLToPath(new URL('../runtime/nx-publish/', import.meta.url));
17
+
18
+ /** A refusal says why: a malformed summary or hash list is never guessed at. */
19
+ export type HashList =
20
+ | { readonly kind: 'hashes'; readonly hashes: readonly string[] }
21
+ | { readonly kind: 'refused'; readonly why: string };
22
+
23
+ const refusal = (why: string): HashList => ({ kind: 'refused', why });
24
+
25
+ function errorMessage(error: unknown): string {
26
+ return error instanceof Error ? error.message : String(error);
27
+ }
28
+
29
+ export function isRecord(value: unknown): value is Record<string, unknown> {
30
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
31
+ }
32
+
33
+ function isTaskHash(value: unknown): value is string {
34
+ return typeof value === 'string' && TASK_HASH.test(value);
35
+ }
36
+
37
+ /**
38
+ * Why a run summary's `run` is not of the invocation that began at `since` (epoch milliseconds), or undefined when it
39
+ * is. A summary Nx began before the gate is an earlier invocation's: its tasks are not the gate's.
40
+ */
41
+ export function staleSummary(run: Record<string, unknown>, since: number): string | undefined {
42
+ const started = run.startTime;
43
+ const startedAt = typeof started === 'string' ? Date.parse(started) : Number.NaN;
44
+ if (Number.isNaN(startedAt)) return `the run summary has no start time: ${JSON.stringify(started)}`;
45
+ if (startedAt >= since) return undefined;
46
+ return `the run summary is of an invocation that began at ${started}, before this gate began at ${new Date(since).toISOString()}`;
47
+ }
48
+
49
+ /**
50
+ * The distinct hashes of the run's succeeded tasks (status 0), in run order, from a summary Nx began at or after
51
+ * `since` (epoch milliseconds). Every task must be well formed, failed or not.
52
+ */
53
+ export function succeededHashes(since: number, summaryJson: string): HashList {
54
+ let summary: unknown;
55
+ try {
56
+ summary = JSON.parse(summaryJson);
57
+ } catch (error) {
58
+ return refusal(`the run summary is not JSON: ${errorMessage(error)}`);
59
+ }
60
+ if (!isRecord(summary) || !isRecord(summary.run) || !Array.isArray(summary.tasks)) {
61
+ return refusal('the run summary has no run object or no tasks array');
62
+ }
63
+ const stale = staleSummary(summary.run, since);
64
+ if (stale !== undefined) return refusal(stale);
65
+ const tasks: readonly unknown[] = summary.tasks;
66
+ const hashes = new Set<string>();
67
+ for (const task of tasks) {
68
+ if (!isRecord(task) || typeof task.status !== 'number') {
69
+ return refusal(`the run summary has a task without a numeric status: ${JSON.stringify(task)}`);
70
+ }
71
+ if (!isTaskHash(task.hash)) {
72
+ return refusal(`the run summary has an invalid task hash: ${JSON.stringify(task.hash)}`);
73
+ }
74
+ if (task.status === 0) hashes.add(task.hash);
75
+ }
76
+ return { kind: 'hashes', hashes: [...hashes] };
77
+ }
78
+
79
+ /** The hash list 'hashes' printed: a JSON array of distinct, well-formed task hashes. 'publish' checks it before spawning. */
80
+ export function hashList(text: string): HashList {
81
+ let value: unknown;
82
+ try {
83
+ value = JSON.parse(text);
84
+ } catch (error) {
85
+ return refusal(`the hash list is not JSON: ${errorMessage(error)}`);
86
+ }
87
+ if (!Array.isArray(value) || !value.every(isTaskHash)) {
88
+ return refusal('the hash list is not a JSON array of valid task hashes');
89
+ }
90
+ if (new Set(value).size !== value.length) return refusal('the hash list repeats a task hash');
91
+ return { kind: 'hashes', hashes: value };
92
+ }
93
+
94
+ /** cache_adapter.js first: it defines the cache nx_publish.js calls. Both go to 'node -' as one program. */
95
+ function bridgeProgram(): string {
96
+ const adapter = readFileSync(join(PUBLISH_ASSETS, 'cache_adapter.js'), 'utf8');
97
+ const publisher = readFileSync(join(PUBLISH_ASSETS, 'nx_publish.js'), 'utf8');
98
+ return `${adapter}\n${publisher}`;
99
+ }
100
+
101
+ /** Runs the bridge as 'node - ARGS' with the program on stdin. Its stderr is ours; its stdout comes back. */
102
+ function runBridge(args: readonly string[]): Promise<{ readonly status: number; readonly stdout: string }> {
103
+ // Read before spawning: a read that threw after the spawn would leave node waiting on a stdin that never closes.
104
+ const program = bridgeProgram();
105
+ // eslint-disable-next-line deadline/no-unbounded-wait -- WHY unbounded: the accepted-result archive command lasts as long as its work; node close/error settles this wait, and the operator's interrupt or the enclosing cowshed job or test-runner lifecycle ends a hung one (05_gateway.md, "Deadlines", "Enforcement")
106
+ return new Promise((resolve, reject) => {
107
+ const child = spawn('node', ['-', ...args], { stdio: ['pipe', 'pipe', 'inherit'] });
108
+ let stdout = '';
109
+ child.stdout.setEncoding('utf8');
110
+ child.stdout.on('data', (chunk: string) => {
111
+ stdout += chunk;
112
+ });
113
+ child.on('error', reject);
114
+ child.on('close', (status, signal) => {
115
+ if (status === null) reject(new Error(`node ended by signal ${String(signal)}`));
116
+ else resolve({ status, stdout });
117
+ });
118
+ child.stdin.on('error', reject);
119
+ child.stdin.end(program);
120
+ });
121
+ }
122
+
123
+ function fail(why: string): number {
124
+ process.stderr.write(`smoo-nx-publish: ${why}\n`);
125
+ return 1;
126
+ }
127
+
128
+ async function main(argv: readonly string[]): Promise<number> {
129
+ const [verb, first, second] = argv;
130
+ if (verb === 'hashes' && argv.length === 3 && first !== undefined && second !== undefined) {
131
+ const since = Number(second);
132
+ if (!Number.isInteger(since)) return fail(`SINCE must be whole epoch seconds, not ${second}`);
133
+ const result = succeededHashes(since * 1000, readFileSync(first, 'utf8'));
134
+ if (result.kind === 'refused') return fail(result.why);
135
+ process.stdout.write(`${JSON.stringify(result.hashes)}\n`);
136
+ return 0;
137
+ }
138
+ if (verb === 'publish' && argv.length === 3 && first !== undefined && second !== undefined) {
139
+ if (!isAbsolute(first)) return fail(`the checkout must be an absolute path, not ${first}`);
140
+ const list = hashList(readFileSync(second, 'utf8'));
141
+ if (list.kind === 'refused') return fail(list.why);
142
+ const bridge = await runBridge([first, JSON.stringify(list.hashes)]);
143
+ process.stdout.write(bridge.stdout);
144
+ return bridge.status;
145
+ }
146
+ process.stderr.write(USAGE);
147
+ return 64;
148
+ }
149
+
150
+ /** Run the packaged publisher, returning a failure status and diagnostic for operational refusals. */
151
+ export async function runNxPublish(argv: readonly string[]): Promise<number> {
152
+ try {
153
+ return await main(argv);
154
+ } catch (error) {
155
+ return fail(errorMessage(error));
156
+ }
157
+ }
@@ -173,8 +173,8 @@ export function killProcessGroupNow(pgid: number, patience: Patience): boolean {
173
173
  * Waits `ms` of host time without blocking this thread, so that the event loop serves everything else meanwhile and
174
174
  * reaps the group's leader. Two waits, and whichever ends first ends the pause: a timer, which keeps the process alive
175
175
  * while it waits, and `Atomics.waitAsync`, which does not (a process with nothing else pending exits under it, as
176
- * measured on Node 26 and Bun 1.4.3) but is not a timer. A timer alone is its caller's clock, and a test that fakes the
177
- * clock stops it for good, while what a kill waits for is the kernel.
176
+ * measured on Node 26 and Bun 1.4.3 and 1.4.4) but is not a timer. A timer alone is its caller's clock, and a test
177
+ * that fakes the clock stops it for good, while what a kill waits for is the kernel.
178
178
  */
179
179
  function pause(ms: number): Promise<void> {
180
180
  return new Promise((resolve) => {
@@ -107,7 +107,7 @@ function closingBracket(text: string, from: number, open: string, close: string)
107
107
  * The shell tokens of `script`. A command substitution is part of its word, and the programs it runs are appended to
108
108
  * `nested`; quoting is removed from the words, which are only inspected, never run.
109
109
  */
110
- function shellTokens(script: string, nested: string[]): Token[] {
110
+ export function shellTokens(script: string, nested: string[]): Token[] {
111
111
  const tokens: Token[] = [];
112
112
  let word: string | undefined;
113
113
  const flush = (): void => {
@@ -376,9 +376,9 @@ function absentAsUndefined<T>(read: () => T): T | undefined {
376
376
 
377
377
  /**
378
378
  * The report of every failure runtime-input.sh retained under `root` at or after `sinceMs`, oldest first, each headed
379
- * by its path. Nx 23.2.1 names a failed runtime input only as `invalid utf-8 sequence of 1 bytes from index N` and
380
- * drops the input's stderr, so a headless run prints these after Nx fails: they name the command, its exit status and
381
- * its stderr. A record without a report (its evidence could not be written) is named as such.
379
+ * by its path. Nx names a failed runtime input's tasks and their runtime inputs (`Could not hash …`), not which one
380
+ * failed or why, and drops the input's stderr, so a headless run prints these after Nx fails: they name the command,
381
+ * its exit status and its stderr. A record without a report (its evidence could not be written) is named as such.
382
382
  */
383
383
  export function runtimeInputFailureReports(root: string, sinceMs: number): string[] {
384
384
  const directory = join(root, RUNTIME_INPUT_FAILURES);
@@ -1,9 +1,10 @@
1
+ import type { Stats } from 'node:fs';
1
2
  import { readdir, readFile, stat } from 'node:fs/promises';
2
3
  import { join, posix } from 'node:path';
3
4
  import { parse as parseToml } from 'smol-toml';
4
5
  import typia, { type IValidation } from 'typia';
5
6
 
6
- import { shellWord } from './runtime-input.js';
7
+ import { runtimeInput, shellWord } from './runtime-input.js';
7
8
  import { isRecord } from './type-guards.js';
8
9
 
9
10
  /**
@@ -187,10 +188,11 @@ const validateBunfigDiscovery = typia.createValidate<BunfigDiscovery>();
187
188
  * Bun's test discovery for `args` in `cwd`, replayed without running a test: files named `*.test.*`, `*_test.*`,
188
189
  * `*.spec.*` or `*_spec.*` with a JavaScript extension, in any letter case, under bunfig's `test.root`, outside
189
190
  * `node_modules` and hidden directories. A symlink counts as its target, a directory entered and a file matched, and a
190
- * link to nothing as a file; the link's own name is the one the name rules see. `--path-ignore-patterns` globs match
191
- * the cwd-relative path as written and replace bunfig's `pathIgnorePatterns` when given; `--config=` names another
192
- * bunfig; `.gitignore` plays no part. These are the rules of Bun 1.4: `test-timings.test.ts` compares them with the
193
- * files `bun test --update-timings` writes for a fixture, so a Bun release that changes them fails there.
191
+ * link to nothing is skipped; any other link it cannot resolve refuses the replay. The link's own name is the one the
192
+ * name rules see. `--path-ignore-patterns` globs match the cwd-relative path as written and replace bunfig's
193
+ * `pathIgnorePatterns` when given; `--config=` names another bunfig; `.gitignore` plays no part. These are the rules
194
+ * of Bun 1.4.4: `test-timings.test.ts` compares them with the files `bun test --update-timings` writes for a fixture,
195
+ * so a Bun release that changes them fails there.
194
196
  */
195
197
  export async function timingsCoverage(
196
198
  workspaceRoot: string,
@@ -210,7 +212,12 @@ export async function timingsCoverage(
210
212
  cliIgnores.length > 0 ? cliIgnores : typeof bunfigIgnores === 'string' ? [bunfigIgnores] : bunfigIgnores;
211
213
  const root = posix.normalize(bunfig.test?.root ?? '.');
212
214
  const files: string[] = [];
213
- await collectTestFiles(cwd, root === '.' ? '' : root.replace(/\/$/, ''), ignores, files);
215
+ try {
216
+ await collectTestFiles(cwd, root === '.' ? '' : root.replace(/\/$/, ''), ignores, files);
217
+ } catch (error) {
218
+ if (!(error instanceof Error && 'code' in error)) throw error;
219
+ return { ok: false, error: `cannot replay Bun's discovery under ${posix.join(suite.cwd, root)}: ${error.message}` };
220
+ }
214
221
  files.sort();
215
222
  const timed = new Set<string>();
216
223
  for (const manifest of manifests) {
@@ -221,6 +228,50 @@ export async function timingsCoverage(
221
228
  return { ok: true, coverage: { manifests, files, untimed: files.filter((file) => !timed.has(file)) } };
222
229
  }
223
230
 
231
+ /**
232
+ * What the shard-timings check reads, as Nx inputs: its timing manifests and its bunfig as files, and the names Bun's
233
+ * discovery would find as {@link bunTestFileNamesInput}. Files alone cannot key the last: discovery finds gitignored
234
+ * files too, and Nx hashes no ignored file.
235
+ */
236
+ export function timingsSuiteInputs(suite: Pick<TimingsShardedSuite, 'cwd' | 'args'>): (string | { runtime: string })[] {
237
+ const inCwd = (file: string) => `{workspaceRoot}/${posix.join(suite.cwd, file)}`;
238
+ return [
239
+ ...flagValues(suite.args, '--timings').map(inCwd),
240
+ inCwd(flagValues(suite.args, '--config').at(-1) ?? 'bunfig.toml'),
241
+ bunTestFileNamesInput(suite.cwd),
242
+ ];
243
+ }
244
+
245
+ /**
246
+ * The names of the files under `cwd` (workspace-relative) Bun's discovery could run, sorted, as a runtime input. It is a
247
+ * superset of {@link timingsCoverage}'s rules (any extension, the whole tree whatever bunfig's `test.root`, no ignore
248
+ * glob), so every file discovery would find changes the value, and a name discovery skips costs at most a cache miss.
249
+ * Like Bun, it skips `node_modules` and hidden directories, follows symlinks (each directory once, by its real path),
250
+ * skips a link to nothing, and reads no `.gitignore`. It walks with Bun, which every workspace declares.
251
+ */
252
+ export function bunTestFileNamesInput(cwd: string): { runtime: string } {
253
+ return runtimeInput(`bun -e ${shellWord(LIST_TEST_FILE_NAMES)} ${shellWord(cwd)}`);
254
+ }
255
+
256
+ const LIST_TEST_FILE_NAMES = [
257
+ 'const { readdirSync, realpathSync, statSync } = require("node:fs");',
258
+ 'const names = []; const seen = new Set();',
259
+ 'const walk = (dir) => {',
260
+ ' const real = realpathSync(dir); if (seen.has(real)) return; seen.add(real);',
261
+ ' for (const entry of readdirSync(dir, { withFileTypes: true })) {',
262
+ ' const path = dir === "." ? entry.name : dir + "/" + entry.name; const name = entry.name.toLowerCase();',
263
+ ' let directory = entry.isDirectory();',
264
+ ' if (entry.isSymbolicLink()) {',
265
+ ' try { directory = statSync(path).isDirectory(); }',
266
+ ' catch (error) { if (error?.code !== "ENOENT") throw error; continue; }',
267
+ ' }',
268
+ ' if (directory) { if (!name.startsWith(".") && name !== "node_modules") walk(path); }',
269
+ ' else if (/[._](test|spec)[.]/.test(name)) names.push(path);',
270
+ ' }',
271
+ '};',
272
+ 'process.chdir(process.argv[1]); walk("."); names.sort(); for (const name of names) console.log(name);',
273
+ ].join(' ');
274
+
224
275
  /**
225
276
  * The failure an untimed file earns: every such file, and the one command that refreshes the manifest. `cwd` is the
226
277
  * suite's workspace-relative directory, so the operator can find the files from the repository root.
@@ -242,17 +293,14 @@ async function collectTestFiles(cwd: string, dir: string, ignores: readonly stri
242
293
  const path = dir === '' ? entry.name : `${dir}/${entry.name}`;
243
294
  // Bun matches every name in lower case, and its ignore globs see the path as written.
244
295
  const name = entry.name.toLowerCase();
245
- // Bun follows a symlink to what it points at and takes one that points at nothing for a file.
246
- const resolved = entry.isSymbolicLink() ? await stat(join(cwd, path)).catch(() => null) : entry;
247
- if (resolved?.isDirectory()) {
296
+ // Bun follows a symlink to what it points at and skips one that points at nothing.
297
+ const resolved = entry.isSymbolicLink() ? await statUnlessMissing(join(cwd, path)) : entry;
298
+ if (resolved === null) continue;
299
+ if (resolved.isDirectory()) {
248
300
  if (!name.startsWith('.') && name !== 'node_modules') {
249
301
  await collectTestFiles(cwd, path, ignores, files);
250
302
  }
251
- } else if (
252
- (resolved === null || resolved.isFile()) &&
253
- TEST_FILE.test(name) &&
254
- !ignores.some((glob) => posix.matchesGlob(path, glob))
255
- ) {
303
+ } else if (resolved.isFile() && TEST_FILE.test(name) && !ignores.some((glob) => posix.matchesGlob(path, glob))) {
256
304
  files.push(path);
257
305
  }
258
306
  }
@@ -297,6 +345,16 @@ async function readTimingManifest(
297
345
  return { ok: true, files: validated.data.files };
298
346
  }
299
347
 
348
+ /** What a symlink at `path` leads to, or null when it leads nowhere; any other failure to resolve it is thrown. */
349
+ async function statUnlessMissing(path: string): Promise<Stats | null> {
350
+ try {
351
+ return await stat(path);
352
+ } catch (error) {
353
+ if (error instanceof Error && 'code' in error && error.code === 'ENOENT') return null;
354
+ throw error;
355
+ }
356
+ }
357
+
300
358
  async function readOptionalFile(path: string): Promise<string | null> {
301
359
  try {
302
360
  return await readFile(path, 'utf-8');
package/src/tool-bins.ts CHANGED
@@ -23,18 +23,16 @@ function toolCommand(cwd: string, tool: string, file: string): string {
23
23
  return `${posix.join(posix.relative(cwd, '.'), PLUGIN_LINK)}/../${tool}/${file}`;
24
24
  }
25
25
 
26
- /** The tool packages whose executables inferred commands run. */
27
- const NATIVE_TOOL_PACKAGES = ['build-inputs', 'cargo-retain', 'nextest-extract'] as const;
26
+ /** The tool packages whose native artifacts inferred commands consume. */
27
+ const NATIVE_TOOL_PACKAGES = ['build-inputs', 'cargo-retain', 'nextest-extract', 'cowshed'] as const;
28
28
 
29
29
  export type NativeToolPackage = (typeof NATIVE_TOOL_PACKAGES)[number];
30
30
 
31
31
  type TargetDependency = NonNullable<TargetConfiguration['dependsOn']>[number];
32
32
 
33
33
  /**
34
- * The tool packages' executables as the inferring host runs them. Every scriptc package ships each platform's
35
- * executable under `dist/bin/<platform>/`, so an installed tool package already carries this host's. A tool package
36
- * that is a project of the workspace being inferred (a checkout of the repository that builds it) has only what its
37
- * `scriptc-<arch>-<family>` target last wrote, so a command running it depends on that target.
34
+ * Native tools as the inferring host consumes them. Installed packages already ship their artifacts; a workspace
35
+ * package needs its declared producer. Scriptc tools use the host platform target, cowshed its napi-native addon.
38
36
  */
39
37
  export interface NativeTools {
40
38
  /** The host's directory under a tool package's `dist/bin`. */
@@ -101,8 +99,14 @@ export function nativeToolCommand(
101
99
  return toolCommand(cwd, tool, `dist/bin/${tools.platform}/${bin}`);
102
100
  }
103
101
 
104
- /** The task that builds `tool`'s executables for this host, when this workspace builds them. */
105
- export function nativeToolDependsOn(tools: NativeTools | null, tool: NativeToolPackage): TargetDependency[] {
102
+ /** The task producing a tool artifact, only when this workspace owns its package. */
103
+ export function nativeToolDependsOn(
104
+ tools: NativeTools | null,
105
+ tool: NativeToolPackage,
106
+ target?: string,
107
+ ): TargetDependency[] {
106
108
  const project = tools?.projects.get(tool);
107
- return project === undefined || tools === null ? [] : [{ projects: [project], target: tools.target }];
109
+ return project === undefined || tools === null
110
+ ? []
111
+ : [{ projects: [project], target: target ?? (tool === 'cowshed' ? 'napi-native' : tools.target) }];
108
112
  }
@@ -34,19 +34,18 @@ const PUBLISHED_DEPENDENCY_FIELDS = ['dependencies', 'peerDependencies', 'option
34
34
  const afterAllProjectsVersioned: AfterAllProjectsVersioned = async (cwd, options) => {
35
35
  const result = await nxJsVersionActions.afterAllProjectsVersioned(cwd, options);
36
36
 
37
- // Temporary Bun workaround. Delete this hook together with the CLI lockfile
38
- // sync/validation code once supported Bun versions fix all three issues:
39
- // - https://github.com/oven-sh/bun/issues/18906
40
- // - https://github.com/oven-sh/bun/issues/20477
41
- // - https://github.com/oven-sh/bun/issues/20829
42
- //
43
37
  // After ANY version bump (release or prepare-next), bun.lock workspace versions
44
- // must match package.json exactly — including unpublished -next. Day-to-day CI
45
- // and frozen installs require that invariant.
38
+ // must match package.json exactly, unpublished -next included, and
39
+ // `smoo monorepo validate` refuses a lock that does not. The Bun bugs this hook
40
+ // began as a workaround for are closed (oven-sh/bun#18906, #20477, #20829):
41
+ // measured on Bun 1.4.4, `bun install --lockfile-only`, the lock update Nx runs
42
+ // after versioning, writes a bumped package.json version into bun.lock. But
43
+ // `bun install --frozen-lockfile` still accepts an entry the manifest moved
44
+ // past, so the release commit's lock is made exact here whatever ran before.
46
45
  //
47
- // Publish-time pack rewrites (-next → last stable tag) happen only in
48
- // `smoo release publish` around `bun pm pack`, never here. Doing publish-mode
49
- // rewrite on prepare-next is what left lock at 0.x.y while package.json said
46
+ // Publish-time pins (-next → last stable tag) go only into the packed manifest
47
+ // of `smoo release publish`, never into bun.lock. Rewriting the lock that way
48
+ // on prepare-next is what left it at 0.x.y while package.json said
50
49
  // 0.x.y-next.0 and blew up monorepo validate / packed-package-manifest.
51
50
  const updated = syncBunLockfileVersionsToPackageJson(cwd);
52
51
  if (updated === 0) {
@@ -84,7 +84,11 @@ export function isTestRunnerTargetName(name: string): boolean {
84
84
 
85
85
  const nxJsTypescriptPlugin = '@nx/js/typescript';
86
86
  const smoothBricksNxPlugin = '@smoothbricks/nx-plugin';
87
- const cleanOutputsExecutor = '@smoothbricks/nx-plugin:clean-outputs';
87
+ /**
88
+ * The executor of the retired `clean` target, which deleted declared outputs file by file. Build state is removed whole
89
+ * instead (cowshed rm, mbx gc), so a `targetDefaults.clean` naming it is refused and removed.
90
+ */
91
+ const retiredCleanOutputsExecutor = '@smoothbricks/nx-plugin:clean-outputs';
88
92
  const ciWorkflowNamedInput = ['{workspaceRoot}/.github/workflows/ci.yml'];
89
93
  const inferredTestTypecheckTarget = 'typecheck-tests';
90
94
  /**
@@ -138,6 +142,12 @@ export function checkWorkspaceConfig(nxJson: Record<string, unknown>): NxPolicyI
138
142
  'Per-project inference selects current library or build outputs before test typechecking.',
139
143
  });
140
144
  }
145
+ if (isRetiredCleanTargetDefault(targetDefaults, targetName)) {
146
+ issues.push({
147
+ path: 'nx.json',
148
+ message: `targetDefaults.clean names the retired ${retiredCleanOutputsExecutor}; run smoo monorepo update to remove it`,
149
+ });
150
+ }
141
151
  }
142
152
  }
143
153
 
@@ -149,9 +159,6 @@ export function checkWorkspaceConfig(nxJson: Record<string, unknown>): NxPolicyI
149
159
 
150
160
  validateLintTargetDefault(nxJson, 'nx.json', issues);
151
161
 
152
- // Clean target default
153
- validateCleanTargetDefault(nxJson, 'nx.json', issues);
154
-
155
162
  // Named input defaults
156
163
  validateNamedInputDefaults(nxJson, 'nx.json', issues);
157
164
 
@@ -203,7 +210,6 @@ export function applyWorkspaceConfig(nxJson: Record<string, unknown>): boolean {
203
210
  changed = applyBuildTargetDefault(nxJson) || changed;
204
211
  changed = applyTestTargetDefault(nxJson) || changed;
205
212
  changed = applyLintTargetDefault(nxJson) || changed;
206
- changed = applyCleanTargetDefault(nxJson) || changed;
207
213
  changed = applyNamedInputDefaults(nxJson) || changed;
208
214
  const plugins = validatePlugins(nxJson.plugins === undefined ? [] : nxJson.plugins);
209
215
  if (plugins.success) {
@@ -322,21 +328,6 @@ function validateBuildTargetDefault(
322
328
  }
323
329
  }
324
330
 
325
- function validateCleanTargetDefault(
326
- nxJson: Record<string, unknown>,
327
- nxJsonPath: string,
328
- issues: NxPolicyIssue[],
329
- ): void {
330
- const targetDefaults = recordProperty(nxJson, 'targetDefaults');
331
- const clean = targetDefaults ? recordProperty(targetDefaults, 'clean') : null;
332
- if (!clean || clean.executor !== cleanOutputsExecutor) {
333
- issues.push({ path: nxJsonPath, message: `targetDefaults.clean.executor must be ${cleanOutputsExecutor}` });
334
- }
335
- if (clean?.cache !== false) {
336
- issues.push({ path: nxJsonPath, message: 'targetDefaults.clean.cache must be false' });
337
- }
338
- }
339
-
340
331
  function validateNamedInputDefaults(
341
332
  nxJson: Record<string, unknown>,
342
333
  nxJsonPath: string,
@@ -471,14 +462,6 @@ function applyLintTargetDefault(nxJson: Record<string, unknown>): boolean {
471
462
  return changed;
472
463
  }
473
464
 
474
- function applyCleanTargetDefault(nxJson: Record<string, unknown>): boolean {
475
- const targetDefaults = getOrCreateRecord(nxJson, 'targetDefaults');
476
- const clean = getOrCreateRecord(targetDefaults, 'clean');
477
- let changed = setStringProperty(clean, 'executor', cleanOutputsExecutor);
478
- changed = setBooleanProperty(clean, 'cache', false) || changed;
479
- return changed;
480
- }
481
-
482
465
  function applyNamedInputDefaults(nxJson: Record<string, unknown>): boolean {
483
466
  const namedInputs = getOrCreateRecord(nxJson, 'namedInputs');
484
467
  let changed = false;
@@ -516,7 +499,11 @@ function removeDisallowedTargetDefaults(nxJson: Record<string, unknown>): boolea
516
499
  }
517
500
  let changed = false;
518
501
  for (const targetName of Object.keys(targetDefaults)) {
519
- if (targetName.includes(':') || targetName === inferredTestTypecheckTarget) {
502
+ if (
503
+ targetName.includes(':') ||
504
+ targetName === inferredTestTypecheckTarget ||
505
+ isRetiredCleanTargetDefault(targetDefaults, targetName)
506
+ ) {
520
507
  delete targetDefaults[targetName];
521
508
  changed = true;
522
509
  }
@@ -524,6 +511,10 @@ function removeDisallowedTargetDefaults(nxJson: Record<string, unknown>): boolea
524
511
  return changed;
525
512
  }
526
513
 
514
+ function isRetiredCleanTargetDefault(targetDefaults: Record<string, unknown>, targetName: string): boolean {
515
+ return targetName === 'clean' && recordProperty(targetDefaults, 'clean')?.executor === retiredCleanOutputsExecutor;
516
+ }
517
+
527
518
  function isPreciseProductionNamedInput(production: unknown[]): boolean {
528
519
  let hasPositiveProjectInput = false;
529
520
  for (const input of production) {
@@ -1,3 +1,5 @@
1
+ import native from 'nx/src/native/index.js';
2
+ import { workspaceDataDirectoryForWorkspace } from 'nx/src/utils/cache-directory.js';
1
3
  import { globWithWorkspaceContext, globWithWorkspaceContextSync } from 'nx/src/utils/workspace-context.js';
2
4
  import { workspaceRoot as daemonWorkspaceRoot } from 'nx/src/utils/workspace-root.js';
3
5
 
@@ -16,3 +18,13 @@ export async function globIndexedFiles(workspaceRoot: string, globs: string[]):
16
18
  ? globWithWorkspaceContext(workspaceRoot, globs)
17
19
  : globWithWorkspaceContextSync(workspaceRoot, globs);
18
20
  }
21
+
22
+ /**
23
+ * Like {@link globIndexedFiles}, read from the filesystem now: a new native context, the same walk and the same ignore
24
+ * rules, never the table of this process or of the daemon. A table only learns of a write when a watcher event reaches
25
+ * it, so one the watcher missed leaves a deleted file listed and an added one unlisted until that process ends. What
26
+ * runs on the files as they are asks here; what describes a graph asks {@link globIndexedFiles}.
27
+ */
28
+ export function freshIndexedFiles(workspaceRoot: string, globs: string[]): string[] {
29
+ return new native.WorkspaceContext(workspaceRoot, workspaceDataDirectoryForWorkspace(workspaceRoot)).glob(globs);
30
+ }
@@ -414,9 +414,9 @@ export function catalogName(value: string): string | null {
414
414
  /**
415
415
  * Where Bun reads a root manifest's catalogs: from the object form of `workspaces` once it holds `catalog` or
416
416
  * `catalogs`, and then from nowhere else; otherwise from the manifest's own top-level `catalog` and `catalogs`.
417
- * Measured with `bun install` 1.4.3: beside a `workspaces.catalog`, a top-level `catalog` entry is not in the catalog
418
- * and a top-level `catalogs` name is "no catalog named"; beside a `workspaces` object without either, the top level
419
- * resolves.
417
+ * Measured with `bun install` 1.4.3 and 1.4.4: beside a `workspaces.catalog`, a top-level `catalog` entry is not in
418
+ * the catalog and a top-level `catalogs` name is "no catalog named"; beside a `workspaces` object without either, the
419
+ * top level resolves.
420
420
  */
421
421
  function catalogHolder(root: PackageJson): { holder: PackageCatalogs; path: string } {
422
422
  const workspaces = root.workspaces;