@smoothbricks/nx-plugin 0.7.17 → 0.7.19

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 (199) hide show
  1. package/README.md +315 -114
  2. package/dist/.build-inputs.json +47 -38
  3. package/dist/built-output-packages.js +1 -1
  4. package/dist/bun-lock-scope.d.ts +128 -20
  5. package/dist/bun-lock-scope.d.ts.map +1 -1
  6. package/dist/bun-lock-scope.js +267 -44
  7. package/dist/cargo-closure-input.d.ts +8 -6
  8. package/dist/cargo-closure-input.d.ts.map +1 -1
  9. package/dist/cargo-closure-input.js +15 -12
  10. package/dist/cargo-source-hash.d.ts +26 -25
  11. package/dist/cargo-source-hash.d.ts.map +1 -1
  12. package/dist/cargo-source-hash.js +84 -105
  13. package/dist/cargo-toolchain-paths.d.ts +2 -2
  14. package/dist/cargo-toolchain-paths.js +2 -2
  15. package/dist/cargo-workspace.d.ts +20 -2
  16. package/dist/cargo-workspace.d.ts.map +1 -1
  17. package/dist/cargo-workspace.js +43 -22
  18. package/dist/ensure-built-receipt.d.ts +3 -2
  19. package/dist/ensure-built-receipt.d.ts.map +1 -1
  20. package/dist/ensure-built-receipt.js +3 -2
  21. package/dist/eslint-config-closure.d.ts +8 -3
  22. package/dist/eslint-config-closure.d.ts.map +1 -1
  23. package/dist/eslint-config-closure.js +24 -5
  24. package/dist/executors/bounded-exec/admission-queue.d.ts +3 -1
  25. package/dist/executors/bounded-exec/admission-queue.d.ts.map +1 -1
  26. package/dist/executors/bounded-exec/admission-queue.js +9 -10
  27. package/dist/executors/bounded-exec/awake-clock.d.ts +5 -0
  28. package/dist/executors/bounded-exec/awake-clock.d.ts.map +1 -0
  29. package/dist/executors/bounded-exec/awake-clock.js +22 -0
  30. package/dist/executors/bounded-exec/bounds.d.ts +19 -6
  31. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -1
  32. package/dist/executors/bounded-exec/bounds.js +22 -15
  33. package/dist/executors/bounded-exec/case-gate.d.ts +114 -0
  34. package/dist/executors/bounded-exec/case-gate.d.ts.map +1 -0
  35. package/dist/executors/bounded-exec/case-gate.js +342 -0
  36. package/dist/executors/bounded-exec/cpu-pool-thread.d.ts +1 -0
  37. package/dist/executors/bounded-exec/cpu-pool-thread.d.ts.map +1 -1
  38. package/dist/executors/bounded-exec/cpu-pool-thread.js +2 -2
  39. package/dist/executors/bounded-exec/cpu-pool.d.ts +28 -1
  40. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  41. package/dist/executors/bounded-exec/cpu-pool.js +102 -16
  42. package/dist/executors/bounded-exec/cpu-rise.d.ts +73 -0
  43. package/dist/executors/bounded-exec/cpu-rise.d.ts.map +1 -0
  44. package/dist/executors/bounded-exec/cpu-rise.js +111 -0
  45. package/dist/executors/bounded-exec/endpoint-life.d.ts +146 -0
  46. package/dist/executors/bounded-exec/endpoint-life.d.ts.map +1 -0
  47. package/dist/executors/bounded-exec/endpoint-life.js +228 -0
  48. package/dist/executors/bounded-exec/executor.d.ts +1 -1
  49. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  50. package/dist/executors/bounded-exec/executor.js +256 -86
  51. package/dist/executors/bounded-exec/gateway-lease.d.ts +1 -1
  52. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -1
  53. package/dist/executors/bounded-exec/gateway-lease.js +8 -1
  54. package/dist/executors/bounded-exec/go-run-summary.d.ts +51 -0
  55. package/dist/executors/bounded-exec/go-run-summary.d.ts.map +1 -0
  56. package/dist/executors/bounded-exec/go-run-summary.js +98 -0
  57. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +11 -3
  58. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  59. package/dist/executors/bounded-exec/hang-diagnostics.js +125 -47
  60. package/dist/executors/bounded-exec/lease-wait.d.ts +1 -0
  61. package/dist/executors/bounded-exec/lease-wait.d.ts.map +1 -1
  62. package/dist/executors/bounded-exec/lease-wait.js +1 -0
  63. package/dist/executors/bounded-exec/mbx-pool.d.ts +42 -7
  64. package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
  65. package/dist/executors/bounded-exec/mbx-pool.js +45 -8
  66. package/dist/executors/bounded-exec/mbx-reservations.d.ts +12 -6
  67. package/dist/executors/bounded-exec/mbx-reservations.d.ts.map +1 -1
  68. package/dist/executors/bounded-exec/mbx-reservations.js +190 -284
  69. package/dist/executors/bounded-exec/parent-grant.d.ts +2 -0
  70. package/dist/executors/bounded-exec/parent-grant.d.ts.map +1 -1
  71. package/dist/executors/bounded-exec/parent-grant.js +1 -0
  72. package/dist/executors/bounded-exec/pool-admission.d.ts +29 -3
  73. package/dist/executors/bounded-exec/pool-admission.d.ts.map +1 -1
  74. package/dist/executors/bounded-exec/pool-admission.js +47 -1
  75. package/dist/executors/bounded-exec/progress-channel.d.ts +38 -0
  76. package/dist/executors/bounded-exec/progress-channel.d.ts.map +1 -0
  77. package/dist/executors/bounded-exec/progress-channel.js +113 -0
  78. package/dist/executors/bounded-exec/progress.d.ts +5 -1
  79. package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
  80. package/dist/executors/bounded-exec/progress.js +31 -1
  81. package/dist/executors/bounded-exec/ram-temp.d.ts +24 -1
  82. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  83. package/dist/executors/bounded-exec/ram-temp.js +123 -16
  84. package/dist/executors/bounded-exec/reservation-connection.d.ts +90 -0
  85. package/dist/executors/bounded-exec/reservation-connection.d.ts.map +1 -0
  86. package/dist/executors/bounded-exec/reservation-connection.js +248 -0
  87. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
  88. package/dist/executors/bounded-exec/run-cpu-pool.js +3 -0
  89. package/dist/executors/bounded-exec/runner-sizing.d.ts +9 -5
  90. package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -1
  91. package/dist/executors/bounded-exec/runner-sizing.js +13 -9
  92. package/dist/executors/bounded-exec/schema.d.ts +7 -2
  93. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  94. package/dist/executors/bounded-exec/schema.js +17 -1
  95. package/dist/executors/bounded-exec/suite-minimum.d.ts +21 -0
  96. package/dist/executors/bounded-exec/suite-minimum.d.ts.map +1 -0
  97. package/dist/executors/bounded-exec/suite-minimum.js +85 -0
  98. package/dist/executors/bounded-exec/test-result-writer.d.ts +2 -0
  99. package/dist/executors/bounded-exec/test-result-writer.d.ts.map +1 -1
  100. package/dist/executors/bounded-exec/test-result-writer.js +1 -0
  101. package/dist/executors/bounded-exec/test-results.d.ts +5 -0
  102. package/dist/executors/bounded-exec/test-results.d.ts.map +1 -1
  103. package/dist/executors/bounded-exec/test-results.js +2 -2
  104. package/dist/executors/bounded-exec/verdict.d.ts +39 -10
  105. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  106. package/dist/executors/bounded-exec/verdict.js +60 -14
  107. package/dist/executors/cargo-zigbuild/executor.d.ts +10 -8
  108. package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -1
  109. package/dist/executors/cargo-zigbuild/executor.js +32 -19
  110. package/dist/index.d.ts.map +1 -1
  111. package/dist/index.js +294 -152
  112. package/dist/managed-files/ci-workflow.d.ts +4 -1
  113. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  114. package/dist/managed-files/ci-workflow.js +9 -14
  115. package/dist/managed-files/files.d.ts +3 -3
  116. package/dist/managed-files/files.js +3 -3
  117. package/dist/managed-files/generator.d.ts +5 -1
  118. package/dist/managed-files/generator.d.ts.map +1 -1
  119. package/dist/managed-files/generator.js +22 -7
  120. package/dist/managed-files/render-memo.d.ts +13 -0
  121. package/dist/managed-files/render-memo.d.ts.map +1 -0
  122. package/dist/managed-files/render-memo.js +94 -0
  123. package/dist/task-results.js +2 -1
  124. package/dist/test-program.d.ts +11 -6
  125. package/dist/test-program.d.ts.map +1 -1
  126. package/dist/test-program.js +39 -35
  127. package/dist/tool-bins.d.ts +12 -0
  128. package/dist/tool-bins.d.ts.map +1 -1
  129. package/dist/tool-bins.js +31 -6
  130. package/dist/typecheck-test-policy.d.ts +10 -1
  131. package/dist/typecheck-test-policy.d.ts.map +1 -1
  132. package/dist/typecheck-test-policy.js +40 -24
  133. package/dist/workspace-config-policy.d.ts.map +1 -1
  134. package/dist/workspace-config-policy.js +135 -42
  135. package/dist/workspace-index.d.ts +14 -1
  136. package/dist/workspace-index.d.ts.map +1 -1
  137. package/dist/workspace-index.js +36 -4
  138. package/executors.json +2 -0
  139. package/managed/raw/envrc +24 -0
  140. package/managed/raw/patches/nx@24.0.3.patch +1851 -221
  141. package/managed/raw/patches/ttsc@0.37.1.patch +1055 -0
  142. package/managed/raw/tooling/direnv/developer-links.ts +122 -14
  143. package/managed/raw/tooling/direnv/devenv.smoo.nix +20 -19
  144. package/managed/templates/github/actions/save-nix-devenv/action.yml +19 -1
  145. package/managed/templates/github/actions/setup-devenv/action.yml +2 -0
  146. package/package.json +68 -11
  147. package/runtime/nx-publish/.build-inputs.json +2 -2
  148. package/runtime/nx-publish/cache_adapter.js +293 -3
  149. package/runtime/nx-publish/nx_publish.js +36 -14
  150. package/src/built-output-packages.ts +1 -1
  151. package/src/bun-lock-scope.ts +293 -40
  152. package/src/cargo-closure-input.ts +20 -12
  153. package/src/cargo-source-hash.ts +119 -145
  154. package/src/cargo-toolchain-paths.ts +2 -2
  155. package/src/cargo-workspace.ts +59 -21
  156. package/src/ensure-built-receipt.ts +3 -2
  157. package/src/eslint-config-closure.ts +27 -6
  158. package/src/executors/bounded-exec/admission-queue.ts +11 -10
  159. package/src/executors/bounded-exec/awake-clock.ts +20 -0
  160. package/src/executors/bounded-exec/bounds.ts +41 -19
  161. package/src/executors/bounded-exec/case-gate.ts +365 -0
  162. package/src/executors/bounded-exec/cpu-pool-thread.ts +3 -3
  163. package/src/executors/bounded-exec/cpu-pool.ts +139 -12
  164. package/src/executors/bounded-exec/cpu-rise.ts +156 -0
  165. package/src/executors/bounded-exec/endpoint-life.ts +279 -0
  166. package/src/executors/bounded-exec/executor.ts +341 -123
  167. package/src/executors/bounded-exec/gateway-lease.ts +6 -0
  168. package/src/executors/bounded-exec/go-run-summary.ts +137 -0
  169. package/src/executors/bounded-exec/hang-diagnostics.ts +150 -50
  170. package/src/executors/bounded-exec/lease-wait.ts +1 -0
  171. package/src/executors/bounded-exec/mbx-pool.ts +57 -9
  172. package/src/executors/bounded-exec/mbx-reservations.ts +216 -183
  173. package/src/executors/bounded-exec/parent-grant.ts +3 -0
  174. package/src/executors/bounded-exec/pool-admission.ts +59 -2
  175. package/src/executors/bounded-exec/progress-channel.ts +129 -0
  176. package/src/executors/bounded-exec/progress.ts +39 -3
  177. package/src/executors/bounded-exec/ram-temp.ts +137 -17
  178. package/src/executors/bounded-exec/reservation-connection.ts +221 -0
  179. package/src/executors/bounded-exec/run-cpu-pool.ts +2 -0
  180. package/src/executors/bounded-exec/runner-sizing.ts +13 -8
  181. package/src/executors/bounded-exec/schema.json +1 -1
  182. package/src/executors/bounded-exec/schema.ts +21 -2
  183. package/src/executors/bounded-exec/suite-minimum.ts +81 -0
  184. package/src/executors/bounded-exec/test-result-writer.ts +3 -0
  185. package/src/executors/bounded-exec/test-results.ts +5 -0
  186. package/src/executors/bounded-exec/verdict.ts +83 -22
  187. package/src/executors/cargo-zigbuild/executor.ts +30 -19
  188. package/src/index.ts +357 -166
  189. package/src/managed-files/ci-workflow.ts +13 -17
  190. package/src/managed-files/files.ts +3 -3
  191. package/src/managed-files/generator.ts +21 -6
  192. package/src/managed-files/render-memo.ts +135 -0
  193. package/src/test-program.ts +36 -41
  194. package/src/tool-bins.ts +35 -6
  195. package/src/typecheck-test-policy.ts +49 -24
  196. package/src/workspace-config-policy.ts +161 -43
  197. package/src/workspace-index.ts +40 -5
  198. package/test-timings.json +157 -141
  199. package/managed/raw/patches/ttsc@0.36.3.patch +0 -1660
@@ -119,7 +119,10 @@ export interface CiWorkflowDefinitionOptions extends DeployStepSecretConfig {
119
119
  deploy: boolean;
120
120
  browserTests: boolean;
121
121
  e2eDeployment: boolean;
122
- /** The first entry is the branch whose pushes deploy the staging stage. */
122
+ /**
123
+ * The first entry is the branch whose pushes queue behind a running CI run instead of canceling it, and, with
124
+ * deploy, deploy the staging stage.
125
+ */
123
126
  pushBranches: NonEmptyArray<string>;
124
127
  /** Default ubuntu-latest when omitted. */
125
128
  runsOn?: string | string[];
@@ -297,22 +300,12 @@ permissions:
297
300
  ${options.deploy ? ' deployments: write\n' : ''} statuses: write
298
301
 
299
302
  concurrency:
300
- ${
301
- options.deploy
302
- ? ` # One in-flight run per pull request, and per ref for pushes. Pushes to the
303
- # staging push branch queue behind a running workflow instead of canceling it,
304
- # so a newer push never cancels the deploy job mid-flight. Pull requests and
305
- # other branches keep canceling superseded runs.
306
- group: ${CI_CONCURRENCY_GROUP}
307
- cancel-in-progress: \${{ github.ref != ${stagingRefLiteral(options)} }}`
308
- : ` # This workflow validates and never deploys, so there is no in-flight
309
- # deployment for a newer push to protect: every pull request, and every ref
310
- # for pushes, cancels its superseded runs. Queuing them instead serializes
311
- # the staging branch, and a burst of pushes then reports the newest commit
312
- # one full run per queued push late.
303
+ # One in-flight run per pull request, and per ref for pushes. Pushes to the first
304
+ # push branch queue behind a running workflow instead of canceling it, so every
305
+ # push there ends in a finished run and a newer push never cancels a deploy job
306
+ # mid-flight. Pull requests and other branches keep canceling superseded runs.
313
307
  group: ${CI_CONCURRENCY_GROUP}
314
- cancel-in-progress: true`
315
- }
308
+ cancel-in-progress: \${{ github.ref != ${stagingRefLiteral(options)} }}
316
309
 
317
310
  defaults:
318
311
  run:
@@ -1194,7 +1187,10 @@ export const SAME_REPO_GATE_FOLDED = [
1194
1187
  ' }}',
1195
1188
  ];
1196
1189
 
1197
- /** The first push branch is the one whose pushes deploy the staging stage. */
1190
+ /**
1191
+ * The first push branch is the one whose pushes queue behind a running CI run, and, with deploy, deploy the staging
1192
+ * stage.
1193
+ */
1198
1194
  function stagingPushBranch(options: CiWorkflowDefinitionOptions): string {
1199
1195
  return options.pushBranches[0];
1200
1196
  }
@@ -72,9 +72,9 @@ export interface ManagedFileContext {
72
72
 
73
73
  /** Temporary upstream compiler repairs distributed to smoo-managed Bun workspaces. */
74
74
  export const managedTtscPatch = {
75
- version: '0.36.3',
76
- key: 'ttsc@0.36.3',
77
- path: 'patches/ttsc@0.36.3.patch',
75
+ version: '0.37.1',
76
+ key: 'ttsc@0.37.1',
77
+ path: 'patches/ttsc@0.37.1.patch',
78
78
  } as const;
79
79
 
80
80
  /** Maintained Nx 24.0.3 repairs, applied as an ordinary Bun patchedDependency over the registry release. */
@@ -1,10 +1,12 @@
1
+ import { createHash } from 'node:crypto';
1
2
  import { createProjectGraphAsync, getProjects, joinPathFragments, readJson, type Tree } from 'nx/src/devkit-exports.js';
2
- import { renderTypecheckTestFiles } from '../typecheck-test-policy.js';
3
+ import { renderTypecheckTestFiles, treeSourceListing } from '../typecheck-test-policy.js';
3
4
  import type { PackageJson } from '../workspace-manifest.js';
4
5
  import { deriveManagedFileContext, type WorkspaceProjects } from './context.js';
5
6
  import { type ManagedFileContext, renderManagedFiles } from './files.js';
6
7
  import { formatManagedContent } from './managed-format.js';
7
8
  import { inspectManagedPaths } from './paths.js';
9
+ import { renderedOnChange } from './render-memo.js';
8
10
  import { assertNoManagedConflicts, type FileResult, type ManagedPathInfo, stageManagedFiles } from './tree.js';
9
11
 
10
12
  /**
@@ -33,16 +35,29 @@ export async function generateManagedFiles(
33
35
  );
34
36
  }
35
37
 
36
- /** Shared rendering boundary; stage only after every consumer formatter has succeeded. */
38
+ /**
39
+ * Shared rendering boundary; stage only after every consumer formatter has succeeded. The render is a function of the
40
+ * context, the workspace's source listing and what it reads through the Tree, so it runs again only when one of those
41
+ * changed (`renderedOnChange`); staging always compares against the Tree as it is.
42
+ */
37
43
  export async function generateManagedFilesForContext(
38
44
  tree: Tree,
39
45
  context: ManagedFileContext,
40
46
  pathInfo?: ReadonlyMap<string, ManagedPathInfo>,
41
47
  ): Promise<FileResult[]> {
42
- const files = [...renderManagedFiles(context), ...renderTypecheckTestFiles(tree)];
43
- for (const file of files) {
44
- if (file.content !== null) file.content = await formatManagedContent(tree.root, file.target, file.content);
45
- }
48
+ const listing = treeSourceListing(tree);
49
+ const key = createHash('sha256')
50
+ .update(JSON.stringify(context))
51
+ .update('\0')
52
+ .update(listing.join('\0'))
53
+ .digest('hex');
54
+ const files = await renderedOnChange(tree, key, async (reading) => {
55
+ const rendered = [...renderManagedFiles(context), ...renderTypecheckTestFiles(reading, listing)];
56
+ for (const file of rendered) {
57
+ if (file.content !== null) file.content = await formatManagedContent(reading.root, file.target, file.content);
58
+ }
59
+ return rendered;
60
+ });
46
61
  const paths =
47
62
  pathInfo ??
48
63
  inspectManagedPaths(
@@ -0,0 +1,135 @@
1
+ import { createHash } from 'node:crypto';
2
+ import type { FileChange, Tree } from 'nx/src/devkit-exports.js';
3
+ import type { ManagedFile } from './tree.js';
4
+
5
+ /** What a render can ask a Tree. */
6
+ type Question = 'read' | 'exists' | 'isFile' | 'children';
7
+
8
+ /** One question a render asked, and the answer it got: a digest of the bytes for a read. */
9
+ interface Answer {
10
+ readonly question: Question;
11
+ readonly path: string;
12
+ readonly value: string;
13
+ }
14
+
15
+ /** A render's result, and every answer it was computed from. */
16
+ interface Render {
17
+ readonly key: string;
18
+ readonly answers: readonly Answer[];
19
+ readonly files: readonly ManagedFile[];
20
+ }
21
+
22
+ /** The last render of each workspace root. Replaced by the next render of that root; never expired by time. */
23
+ const renders = new Map<string, Render>();
24
+
25
+ function readValue(bytes: Buffer | null): string {
26
+ return bytes === null ? 'absent' : createHash('sha256').update(bytes).digest('base64');
27
+ }
28
+
29
+ function answerOf(tree: Tree, question: Question, path: string): string {
30
+ switch (question) {
31
+ case 'read':
32
+ return readValue(tree.read(path));
33
+ case 'exists':
34
+ return String(tree.exists(path));
35
+ case 'isFile':
36
+ return String(tree.isFile(path));
37
+ case 'children':
38
+ return JSON.stringify(tree.children(path));
39
+ }
40
+ }
41
+
42
+ /**
43
+ * A Tree that answers from another and keeps every answer it gave. A render that reads the workspace only through
44
+ * it is a function of those answers and of what its caller keys it on. It refuses every write: a render reads the
45
+ * Tree, and staging alone writes it.
46
+ */
47
+ class AnsweringTree implements Tree {
48
+ readonly answers = new Map<string, Answer>();
49
+
50
+ constructor(private readonly tree: Tree) {}
51
+
52
+ get root(): string {
53
+ return this.tree.root;
54
+ }
55
+
56
+ read(filePath: string): Buffer | null;
57
+ read(filePath: string, encoding: BufferEncoding): string | null;
58
+ read(filePath: string, encoding?: BufferEncoding): Buffer | string | null {
59
+ const bytes = this.tree.read(filePath);
60
+ this.keep('read', filePath, readValue(bytes));
61
+ return bytes === null || encoding === undefined ? bytes : bytes.toString(encoding);
62
+ }
63
+
64
+ exists(filePath: string): boolean {
65
+ return this.keep('exists', filePath, String(this.tree.exists(filePath))) === 'true';
66
+ }
67
+
68
+ isFile(filePath: string): boolean {
69
+ return this.keep('isFile', filePath, String(this.tree.isFile(filePath))) === 'true';
70
+ }
71
+
72
+ children(dirPath: string): string[] {
73
+ const children = this.tree.children(dirPath);
74
+ this.keep('children', dirPath, JSON.stringify(children));
75
+ return children;
76
+ }
77
+
78
+ listChanges(): FileChange[] {
79
+ return this.tree.listChanges();
80
+ }
81
+
82
+ write(filePath: string): never {
83
+ throw readOnly(filePath);
84
+ }
85
+
86
+ delete(filePath: string): never {
87
+ throw readOnly(filePath);
88
+ }
89
+
90
+ rename(from: string): never {
91
+ throw readOnly(from);
92
+ }
93
+
94
+ changePermissions(filePath: string): never {
95
+ throw readOnly(filePath);
96
+ }
97
+
98
+ private keep(question: Question, path: string, value: string): string {
99
+ this.answers.set(`${question}\0${path}`, { question, path, value });
100
+ return value;
101
+ }
102
+ }
103
+
104
+ function readOnly(path: string): Error {
105
+ return new Error(`${path}: a managed-files render reads the Tree; only staging writes it`);
106
+ }
107
+
108
+ /**
109
+ * The files `render` gives for `tree`, rendered again only when one of its inputs changed: `key`, which names what the
110
+ * render reads beside the Tree (the context, the source listing), or an answer the Tree gave it. Checking the answers
111
+ * reads each file the last render read, once; the render itself (policy, JSON edits, formatter runs) is skipped.
112
+ *
113
+ * A Tree with pending edits is rendered and nothing is kept: no later Tree shows those edits as they are here.
114
+ * The formatters' own configuration is not an answer: Prettier and Biome read it from disk, and Prettier keeps it for
115
+ * the life of the process, so a daemon already formats with what it first read.
116
+ */
117
+ export async function renderedOnChange(
118
+ tree: Tree,
119
+ key: string,
120
+ render: (tree: Tree) => Promise<ManagedFile[]>,
121
+ ): Promise<readonly ManagedFile[]> {
122
+ if (tree.listChanges().length > 0) return render(tree);
123
+ const last = renders.get(tree.root);
124
+ if (
125
+ last !== undefined &&
126
+ last.key === key &&
127
+ last.answers.every(({ question, path, value }) => answerOf(tree, question, path) === value)
128
+ ) {
129
+ return last.files;
130
+ }
131
+ const answering = new AnsweringTree(tree);
132
+ const files = await render(answering);
133
+ renders.set(tree.root, { key, answers: [...answering.answers.values()], files });
134
+ return files;
135
+ }
@@ -1,5 +1,4 @@
1
1
  import { posix } from 'node:path';
2
- import type { Tree } from 'nx/src/devkit-exports.js';
3
2
  import { isNonSourceDirectory } from './source-directories.js';
4
3
 
5
4
  /**
@@ -20,9 +19,6 @@ export interface TestProgram {
20
19
  readonly readConfig: (path: string) => Record<string, unknown> | null;
21
20
  }
22
21
 
23
- /** A directory listing the walker can use: an Nx `Tree`, or the disk behind a small adapter. */
24
- export type ProjectTree = Pick<Tree, 'children' | 'isFile'>;
25
-
26
22
  /** Why a test program typechecks none of what it exists to typecheck. */
27
23
  export type TestProgramFault =
28
24
  | { readonly kind: 'no-tests' }
@@ -49,51 +45,50 @@ const PACKAGE_CONVENTION_ROOT = 'src';
49
45
  const TESTS_DIRECTORY = '__tests__';
50
46
 
51
47
  /**
52
- * The TypeScript sources of a project, project-relative and sorted.
48
+ * The files {@link typeScriptSourcesByProject} lists from: the TypeScript sources, and the manifests that make a
49
+ * directory a project of its own.
50
+ */
51
+ export const SOURCE_LISTING_GLOBS = ['**/*.{ts,tsx,mts,cts}', '**/{package,project}.json'];
52
+
53
+ /**
54
+ * The TypeScript sources of each of `projectRoots`, project-relative and sorted, from one listing of the workspace's
55
+ * files (workspace-relative; a file that is neither a source nor a manifest is passed over). One pass over the listing
56
+ * answers every project: no directory is listed and no file is probed.
53
57
  *
54
58
  * A directory below the project that is a project of its own (its own manifest or Nx project file) is not part of
55
59
  * this one: its files are its own tests, found by its own policy pass, and folding them in would count them twice.
56
60
  * A directory that merely carries a tsconfig is not that: in a monorepo of Bun programs such a file routes the
57
61
  * directory's files to the parent's program (a `tests/tsconfig.json` extending `../tsconfig.test.json`), and
58
- * nothing typechecks the directory but that program.
62
+ * nothing typechecks the directory but that program. Nothing beneath a build-output or dot directory is a source
63
+ * ({@link isNonSourceDirectory}).
59
64
  */
60
- export function listTypeScriptSources(tree: ProjectTree, projectRoot: string): string[] {
61
- const files: string[] = [];
62
- const walk = (directory: string): void => {
63
- for (const name of childrenOf(tree, directory)) {
64
- const path = posix.join(directory, name);
65
- if (tree.isFile(path)) {
66
- if (TYPESCRIPT_SOURCE.test(name)) files.push(posix.relative(projectRoot, path));
67
- } else if (!isNonSourceDirectory(name) && !isNestedProject(tree, path)) {
68
- walk(path);
69
- }
70
- }
71
- };
72
- walk(projectRoot);
73
- return files.sort();
74
- }
75
-
76
- /** A directory with its own manifest or Nx project file is a project, and its files are that project's. */
77
- function isNestedProject(tree: ProjectTree, directory: string): boolean {
78
- return childrenOf(tree, directory).some(
79
- (name) => PROJECT_FILE.test(name) && tree.isFile(posix.join(directory, name)),
80
- );
65
+ export function typeScriptSourcesByProject(
66
+ files: Iterable<string>,
67
+ projectRoots: Iterable<string>,
68
+ ): ReadonlyMap<string, readonly string[]> {
69
+ const sources = new Map<string, string[]>();
70
+ for (const root of projectRoots) sources.set(root === '' ? '.' : root, []);
71
+ const owners = new Set(sources.keys());
72
+ const listed: string[] = [];
73
+ for (const file of files) {
74
+ const name = posix.basename(file);
75
+ if (PROJECT_FILE.test(name)) owners.add(posix.dirname(file));
76
+ if (TYPESCRIPT_SOURCE.test(name)) listed.push(file);
77
+ }
78
+ for (const file of listed) {
79
+ const owner = ownerOf(file, owners);
80
+ if (owner === null) continue;
81
+ sources.get(owner)?.push(owner === '.' ? file : file.slice(owner.length + 1));
82
+ }
83
+ for (const list of sources.values()) list.sort();
84
+ return sources;
81
85
  }
82
86
 
83
- /** A dangling link (a collected build out-link) is neither a file nor a directory; anything else is a real fault. */
84
- function childrenOf(tree: ProjectTree, directory: string): string[] {
85
- try {
86
- return tree.children(directory);
87
- } catch (error) {
88
- // ELOOP is a link cycle: there is nothing beneath it to list.
89
- if (
90
- error instanceof Error &&
91
- 'code' in error &&
92
- (error.code === 'ENOENT' || error.code === 'ENOTDIR' || error.code === 'ELOOP')
93
- ) {
94
- return [];
95
- }
96
- throw error;
87
+ /** The nearest directory holding a file that is a project, or null when a build-output or dot directory comes first. */
88
+ function ownerOf(file: string, owners: ReadonlySet<string>): string | null {
89
+ for (let directory = posix.dirname(file); ; directory = posix.dirname(directory)) {
90
+ if (owners.has(directory)) return directory;
91
+ if (directory === '.' || isNonSourceDirectory(posix.basename(directory))) return null;
97
92
  }
98
93
  }
99
94
 
package/src/tool-bins.ts CHANGED
@@ -41,6 +41,11 @@ export interface NativeTools {
41
41
  readonly target: string;
42
42
  /** Each tool package that is a project of this workspace, to its project name. */
43
43
  readonly projects: ReadonlyMap<NativeToolPackage, string>;
44
+ /**
45
+ * The Nx project of the plugin itself, when this workspace owns it: the executors it ships are files its own
46
+ * build writes. An installed plugin ships them built, so a consumer has none.
47
+ */
48
+ readonly plugin: string | undefined;
44
49
  }
45
50
 
46
51
  /**
@@ -54,6 +59,7 @@ export async function resolveNativeTools(
54
59
  target: string,
55
60
  ): Promise<NativeTools> {
56
61
  const projects = new Map<NativeToolPackage, string>();
62
+ let pluginProject: string | undefined;
57
63
  const plugin = await realpath(join(workspaceRoot, PLUGIN_LINK)).catch((error: unknown) => {
58
64
  // A workspace whose install has not linked the plugin yet has no tool package of its own either.
59
65
  if (error instanceof Error && 'code' in error && error.code === 'ENOENT') return null;
@@ -61,16 +67,21 @@ export async function resolveNativeTools(
61
67
  });
62
68
  if (plugin !== null) {
63
69
  const root = await realpath(workspaceRoot);
64
- for (const tool of NATIVE_TOOL_PACKAGES) {
65
- const manifest = relative(root, join(dirname(plugin), tool, 'package.json')).replaceAll('\\', '/');
66
- if (!projectManifests.includes(manifest)) continue;
70
+ const owned = async (directory: string, package_: string): Promise<string | undefined> => {
71
+ const manifest = relative(root, join(directory, 'package.json')).replaceAll('\\', '/');
72
+ if (!projectManifests.includes(manifest)) return undefined;
67
73
  const parsed: unknown = JSON.parse(await readFile(join(root, manifest), 'utf8'));
68
74
  const name = projectName(parsed);
69
- if (name === undefined) throw new Error(`${manifest}: a tool package names its Nx project in name or nx.name`);
70
- projects.set(tool, name);
75
+ if (name === undefined) throw new Error(`${manifest}: ${package_} names its Nx project in name or nx.name`);
76
+ return name;
77
+ };
78
+ pluginProject = await owned(plugin, 'the plugin package');
79
+ for (const tool of NATIVE_TOOL_PACKAGES) {
80
+ const name = await owned(join(dirname(plugin), tool), 'a tool package');
81
+ if (name !== undefined) projects.set(tool, name);
71
82
  }
72
83
  }
73
- return { platform, target, projects };
84
+ return { platform, target, projects, plugin: pluginProject };
74
85
  }
75
86
 
76
87
  function projectName(manifest: unknown): string | undefined {
@@ -110,3 +121,21 @@ export function nativeToolDependsOn(
110
121
  ? []
111
122
  : [{ projects: [project], target: target ?? (tool === 'cowshed' ? 'napi-native' : tools.target) }];
112
123
  }
124
+
125
+ /** The plugin executors its own build runs: they load from a dist an earlier build left, so none can wait for it. */
126
+ const BOOTSTRAP_EXECUTORS: ReadonlySet<string> = new Set([
127
+ '@smoothbricks/nx-plugin:typescript-emit',
128
+ '@smoothbricks/nx-plugin:scriptc-native',
129
+ ]);
130
+
131
+ /**
132
+ * The task that leaves the plugin's executors built, for a target whose `executor` is one of them, only when this
133
+ * workspace owns the plugin's package (an installed plugin ships its executors built). The executor is a file the
134
+ * plugin's own build writes, so a target that starts before that build ends loads the dist a previous build left, which
135
+ * lacks an executor the plugin gained since, or none at all.
136
+ */
137
+ export function pluginBuildDependsOn(tools: NativeTools | null, executor: unknown): TargetDependency[] {
138
+ if (tools?.plugin === undefined || typeof executor !== 'string') return [];
139
+ if (!executor.startsWith('@smoothbricks/nx-plugin:') || BOOTSTRAP_EXECUTORS.has(executor)) return [];
140
+ return [{ projects: [tools.plugin], target: 'build' }];
141
+ }
@@ -1,21 +1,23 @@
1
- import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
1
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
2
2
  import { dirname, join, posix, relative } from 'node:path';
3
3
  import type { Tree } from 'nx/src/devkit-exports.js';
4
4
  import { getProjects, parseJson, readJson, readProjectConfiguration } from 'nx/src/devkit-exports.js';
5
+ import { globWithWorkspaceContextSync } from 'nx/src/utils/workspace-context.js';
5
6
  import typia from 'typia';
6
7
  import { editJsonText } from './managed-files/json-edit.js';
7
8
  import { formatJsonWithBiome, jsonFileText } from './managed-files/managed-format.js';
8
9
  import type { ManagedFile } from './managed-files/tree.js';
9
10
  import {
10
11
  includeGlobsFor,
11
- listTypeScriptSources,
12
- type ProjectTree,
12
+ SOURCE_LISTING_GLOBS,
13
13
  type TestProgram,
14
14
  type TestProgramFault,
15
15
  testProgramFault,
16
+ typeScriptSourcesByProject,
16
17
  } from './test-program.js';
17
18
  import { isRecord } from './type-guards.js';
18
19
  import type { NxPolicyIssue } from './workspace-config-policy.js';
20
+ import { freshIndexedFiles } from './workspace-index.js';
19
21
  import { workspacePackagePatterns } from './workspace-manifest.js';
20
22
 
21
23
  export type TestRunner = 'bun' | 'vitest';
@@ -261,8 +263,13 @@ export function removeTsconfigTestReference(projectTsconfig: Record<string, unkn
261
263
  */
262
264
  export function checkTypecheckTestPolicyTree(tree: Tree): NxPolicyIssue[] {
263
265
  const issues: NxPolicyIssue[] = [];
266
+ const projects = getProjects(tree);
267
+ const sources = typeScriptSourcesByProject(
268
+ treeSourceListing(tree),
269
+ [...projects.values()].map((project) => project.root),
270
+ );
264
271
 
265
- for (const [projectName, config] of getProjects(tree)) {
272
+ for (const [projectName, config] of projects) {
266
273
  const pkgPath = `${config.root}/package.json`;
267
274
  if (!tree.exists(pkgPath)) continue;
268
275
  if (config.root === '.' || config.root === '') continue;
@@ -289,7 +296,7 @@ export function checkTypecheckTestPolicyTree(tree: Tree): NxPolicyIssue[] {
289
296
  // Check tsconfig.test.json contents
290
297
  const tsconfigTest = readJson<Record<string, unknown>>(tree, tsconfigTestPath);
291
298
  issues.push(...checkTypecheckTestConfig(tsconfigTest, config.root));
292
- const fault = testProgramFault(treeProgram(tree, config.root), tsconfigTest);
299
+ const fault = testProgramFault(treeProgram(tree, config.root, sources), tsconfigTest);
293
300
  if (fault !== null) {
294
301
  issues.push({ path: tsconfigTestPath, message: testProgramFaultMessage(config.root, testRunners, fault) });
295
302
  }
@@ -308,12 +315,18 @@ export function checkTypecheckTestPolicyTree(tree: Tree): NxPolicyIssue[] {
308
315
  /**
309
316
  * Render test typechecking policy from the caller's Tree. The managed generator
310
317
  * owns staging, permission checks, and flushing together with its other files.
318
+ * `listing` is {@link treeSourceListing} of the same Tree: the caller holds it, as the render's memo is keyed on it.
311
319
  */
312
- export function renderTypecheckTestFiles(tree: Tree): ManagedFile[] {
320
+ export function renderTypecheckTestFiles(tree: Tree, listing: readonly string[]): ManagedFile[] {
313
321
  const files: ManagedFile[] = [];
314
322
  const workspacePackages = collectWorkspacePackagesTree(tree);
323
+ const projects = getProjects(tree);
324
+ const sources = typeScriptSourcesByProject(
325
+ listing,
326
+ [...projects.values()].map((project) => project.root),
327
+ );
315
328
 
316
- for (const [projectName, config] of getProjects(tree)) {
329
+ for (const [projectName, config] of projects) {
317
330
  const pkgPath = `${config.root}/package.json`;
318
331
  if (!tree.exists(pkgPath)) continue;
319
332
  if (config.root === '.' || config.root === '') continue;
@@ -341,7 +354,7 @@ export function renderTypecheckTestFiles(tree: Tree): ManagedFile[] {
341
354
  // Collect reference paths
342
355
  const referencePaths = collectReferencePathsTree(tree, config.root, pkg, workspacePackages);
343
356
 
344
- const program = treeProgram(tree, config.root);
357
+ const program = treeProgram(tree, config.root, sources);
345
358
  applyTypecheckTestDefaults(tsconfigTest, {
346
359
  testRunners,
347
360
  testExtends,
@@ -397,28 +410,34 @@ function renderTsconfig(tree: Tree, target: string, after: Record<string, unknow
397
410
  return { target, content: edited === current ? current : formatJsonWithBiome(path, edited) };
398
411
  }
399
412
 
400
- function treeProgram(tree: Tree, projectRoot: string): TestProgram {
413
+ /**
414
+ * The files a Tree's source listing reads, workspace-relative and sorted: Nx's workspace file index for the Tree's
415
+ * root, with the Tree's pending edits over it, as devkit's own `getProjects` lists project files. The index applies
416
+ * .gitignore and .nxignore, so the listing is what the commit holds, the same in every checkout, and never build
417
+ * output one disk happens to carry; it is read from memory, so no directory is listed and no file probed. A path a
418
+ * pending edit writes is listed whatever its name: the listing passes over what is neither a source nor a manifest.
419
+ */
420
+ export function treeSourceListing(tree: Tree): string[] {
421
+ const files = new Set(globWithWorkspaceContextSync(tree.root, SOURCE_LISTING_GLOBS));
422
+ for (const change of tree.listChanges()) {
423
+ if (change.type === 'DELETE') files.delete(change.path);
424
+ else files.add(change.path);
425
+ }
426
+ return [...files].sort();
427
+ }
428
+
429
+ function treeProgram(tree: Tree, projectRoot: string, sources: ReadonlyMap<string, readonly string[]>): TestProgram {
401
430
  return {
402
431
  projectRoot,
403
- files: listTypeScriptSources(tree, projectRoot),
432
+ files: sources.get(projectRoot) ?? [],
404
433
  readConfig: (path) => (tree.exists(path) ? readJson<Record<string, unknown>>(tree, path) : null),
405
434
  };
406
435
  }
407
436
 
408
- function diskProgram(root: string, projectRoot: string): TestProgram {
409
- const disk: ProjectTree = {
410
- children: (directory) => readdirSync(join(root, directory)),
411
- isFile: (path) => {
412
- try {
413
- return statSync(join(root, path)).isFile();
414
- } catch {
415
- return false;
416
- }
417
- },
418
- };
437
+ function diskProgram(root: string, projectRoot: string, sources: ReadonlyMap<string, readonly string[]>): TestProgram {
419
438
  return {
420
439
  projectRoot,
421
- files: listTypeScriptSources(disk, projectRoot),
440
+ files: sources.get(projectRoot) ?? [],
422
441
  readConfig: (path) => readJsonObject(join(root, path)),
423
442
  };
424
443
  }
@@ -450,7 +469,13 @@ function testProgramFaultMessage(
450
469
  export function checkTypecheckTestPolicy(root: string): NxPolicyIssue[] {
451
470
  const issues: NxPolicyIssue[] = [];
452
471
  const workspaceNames = getWorkspacePackageNames(root);
453
- for (const packageJsonPath of listWorkspacePackageJsonPaths(root)) {
472
+ const packageJsonPaths = listWorkspacePackageJsonPaths(root);
473
+ // Files as they are on disk now, through the same ignore rules as the Tree listing.
474
+ const sources = typeScriptSourcesByProject(
475
+ freshIndexedFiles(root, SOURCE_LISTING_GLOBS),
476
+ packageJsonPaths.map((path) => relative(root, dirname(path))),
477
+ );
478
+ for (const packageJsonPath of packageJsonPaths) {
454
479
  const pkg = readJsonObject(packageJsonPath);
455
480
  if (!pkg) {
456
481
  continue;
@@ -483,7 +508,7 @@ export function checkTypecheckTestPolicy(root: string): NxPolicyIssue[] {
483
508
  if (tsconfig) {
484
509
  const absoluteIssues = checkTypecheckTestConfig(tsconfig, join(root, packagePath));
485
510
  issues.push(...absoluteIssues);
486
- const program = diskProgram(root, packagePath);
511
+ const program = diskProgram(root, packagePath, sources);
487
512
  const fault = testProgramFault(program, tsconfig);
488
513
  if (fault !== null) {
489
514
  issues.push({ path: tsconfigTestPath, message: testProgramFaultMessage(packagePath, testRunners, fault) });