@smoothbricks/nx-plugin 0.7.17 → 0.7.18

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 (102) hide show
  1. package/README.md +204 -64
  2. package/dist/.build-inputs.json +24 -21
  3. package/dist/bun-lock-scope.d.ts +128 -20
  4. package/dist/bun-lock-scope.d.ts.map +1 -1
  5. package/dist/bun-lock-scope.js +267 -44
  6. package/dist/cargo-closure-input.d.ts +8 -6
  7. package/dist/cargo-closure-input.d.ts.map +1 -1
  8. package/dist/cargo-closure-input.js +14 -11
  9. package/dist/cargo-source-hash.d.ts +23 -4
  10. package/dist/cargo-source-hash.d.ts.map +1 -1
  11. package/dist/cargo-source-hash.js +80 -14
  12. package/dist/cargo-workspace.d.ts +20 -2
  13. package/dist/cargo-workspace.d.ts.map +1 -1
  14. package/dist/cargo-workspace.js +42 -22
  15. package/dist/ensure-built-receipt.d.ts +3 -2
  16. package/dist/ensure-built-receipt.d.ts.map +1 -1
  17. package/dist/ensure-built-receipt.js +3 -2
  18. package/dist/eslint-config-closure.d.ts +8 -3
  19. package/dist/eslint-config-closure.d.ts.map +1 -1
  20. package/dist/eslint-config-closure.js +24 -5
  21. package/dist/executors/bounded-exec/bounds.d.ts +12 -1
  22. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -1
  23. package/dist/executors/bounded-exec/bounds.js +8 -4
  24. package/dist/executors/bounded-exec/cpu-rise.d.ts +73 -0
  25. package/dist/executors/bounded-exec/cpu-rise.d.ts.map +1 -0
  26. package/dist/executors/bounded-exec/cpu-rise.js +111 -0
  27. package/dist/executors/bounded-exec/executor.d.ts +1 -1
  28. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  29. package/dist/executors/bounded-exec/executor.js +54 -22
  30. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +8 -0
  31. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  32. package/dist/executors/bounded-exec/hang-diagnostics.js +66 -6
  33. package/dist/executors/bounded-exec/mbx-pool.d.ts +16 -2
  34. package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
  35. package/dist/executors/bounded-exec/mbx-pool.js +18 -2
  36. package/dist/executors/bounded-exec/mbx-reservations.d.ts +5 -2
  37. package/dist/executors/bounded-exec/mbx-reservations.d.ts.map +1 -1
  38. package/dist/executors/bounded-exec/mbx-reservations.js +5 -3
  39. package/dist/executors/bounded-exec/progress-channel.d.ts +38 -0
  40. package/dist/executors/bounded-exec/progress-channel.d.ts.map +1 -0
  41. package/dist/executors/bounded-exec/progress-channel.js +113 -0
  42. package/dist/executors/bounded-exec/progress.d.ts +2 -1
  43. package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
  44. package/dist/executors/bounded-exec/ram-temp.d.ts +24 -1
  45. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  46. package/dist/executors/bounded-exec/ram-temp.js +123 -16
  47. package/dist/executors/bounded-exec/schema.d.ts +5 -0
  48. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  49. package/dist/executors/bounded-exec/schema.js +17 -1
  50. package/dist/executors/bounded-exec/verdict.d.ts +13 -6
  51. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  52. package/dist/executors/bounded-exec/verdict.js +34 -9
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +199 -89
  55. package/dist/managed-files/generator.d.ts +5 -1
  56. package/dist/managed-files/generator.d.ts.map +1 -1
  57. package/dist/managed-files/generator.js +22 -7
  58. package/dist/managed-files/render-memo.d.ts +13 -0
  59. package/dist/managed-files/render-memo.d.ts.map +1 -0
  60. package/dist/managed-files/render-memo.js +94 -0
  61. package/dist/test-program.d.ts +11 -6
  62. package/dist/test-program.d.ts.map +1 -1
  63. package/dist/test-program.js +39 -35
  64. package/dist/tool-bins.d.ts +12 -0
  65. package/dist/tool-bins.d.ts.map +1 -1
  66. package/dist/tool-bins.js +31 -6
  67. package/dist/typecheck-test-policy.d.ts +10 -1
  68. package/dist/typecheck-test-policy.d.ts.map +1 -1
  69. package/dist/typecheck-test-policy.js +40 -24
  70. package/dist/workspace-index.d.ts +14 -1
  71. package/dist/workspace-index.d.ts.map +1 -1
  72. package/dist/workspace-index.js +36 -4
  73. package/managed/raw/patches/nx@24.0.3.patch +703 -119
  74. package/managed/raw/tooling/direnv/developer-links.ts +17 -3
  75. package/managed/templates/github/actions/save-nix-devenv/action.yml +19 -1
  76. package/managed/templates/github/actions/setup-devenv/action.yml +2 -0
  77. package/package.json +3 -2
  78. package/src/bun-lock-scope.ts +293 -40
  79. package/src/cargo-closure-input.ts +19 -11
  80. package/src/cargo-source-hash.ts +103 -13
  81. package/src/cargo-workspace.ts +59 -20
  82. package/src/ensure-built-receipt.ts +3 -2
  83. package/src/eslint-config-closure.ts +27 -6
  84. package/src/executors/bounded-exec/bounds.ts +13 -4
  85. package/src/executors/bounded-exec/cpu-rise.ts +156 -0
  86. package/src/executors/bounded-exec/executor.ts +65 -21
  87. package/src/executors/bounded-exec/hang-diagnostics.ts +88 -6
  88. package/src/executors/bounded-exec/mbx-pool.ts +24 -3
  89. package/src/executors/bounded-exec/mbx-reservations.ts +7 -5
  90. package/src/executors/bounded-exec/progress-channel.ts +129 -0
  91. package/src/executors/bounded-exec/progress.ts +2 -1
  92. package/src/executors/bounded-exec/ram-temp.ts +137 -17
  93. package/src/executors/bounded-exec/schema.ts +19 -0
  94. package/src/executors/bounded-exec/verdict.ts +44 -16
  95. package/src/index.ts +255 -98
  96. package/src/managed-files/generator.ts +21 -6
  97. package/src/managed-files/render-memo.ts +135 -0
  98. package/src/test-program.ts +36 -41
  99. package/src/tool-bins.ts +35 -6
  100. package/src/typecheck-test-policy.ts +49 -24
  101. package/src/workspace-index.ts +40 -5
  102. package/test-timings.json +6 -0
package/src/index.ts CHANGED
@@ -26,7 +26,22 @@ import { parse as parseToml } from 'smol-toml';
26
26
  import { BOUNDED_TEST_IDLE_TIMEOUT_MS, BOUNDED_TEST_KILL_AFTER_MS } from './bounded-test-policy.js';
27
27
  import { refuseOverlappingOutputs } from './build-state-output-policy.js';
28
28
  import { builtOutputLockfileDependencies, builtOutputLockfileNodes } from './built-output-packages.js';
29
- import { bunLockDependencies, bunLockInput, bunLockNode } from './bun-lock-scope.js';
29
+ import {
30
+ BUN_LOCK_SCOPE_NAMED_INPUT,
31
+ bunLoadInput,
32
+ bunLoadScopes,
33
+ bunLockDependencies,
34
+ bunLockInput,
35
+ bunLockNode,
36
+ bunLockRuntimeNode,
37
+ bunScopeInput,
38
+ bunVersionAliasDependencies,
39
+ manifestsAbove,
40
+ type PackageLoad,
41
+ refuseUndeclaredImports,
42
+ specifierPackage,
43
+ typescriptLoads,
44
+ } from './bun-lock-scope.js';
30
45
  import {
31
46
  CARGO_CLOSURE_INPUT,
32
47
  CARGO_LOCK_NODE_PREFIX,
@@ -34,7 +49,7 @@ import {
34
49
  cargoClosureInputs,
35
50
  cargoLockNode,
36
51
  cargoLockNodeName,
37
- indexedCargoManifests,
52
+ indexedCargoSources,
38
53
  isCargoLockInput,
39
54
  resolveCargoClosureSource,
40
55
  } from './cargo-closure-input.js';
@@ -49,6 +64,7 @@ import {
49
64
  type CargoCrossTestTarget,
50
65
  type CargoInputsCache,
51
66
  cargoPackageTestInputs,
67
+ cargoProducerOutputInputs,
52
68
  cargoTestGroupTargetName,
53
69
  cargoTestPackageTargetName,
54
70
  createCargoInputsCache,
@@ -85,8 +101,10 @@ import {
85
101
  type AllVerdictsOptions,
86
102
  ESLINT_SOURCES_TOKEN,
87
103
  } from './executors/all-verdicts/schema.js';
104
+ import { runsAsCargoLeaf } from './executors/bounded-exec/mbx-pool.js';
88
105
  import { closeRunReservations, serveRunReservations } from './executors/bounded-exec/mbx-reservations.js';
89
106
  import { closeRunCpuPool, serveRunCpuPool } from './executors/bounded-exec/run-cpu-pool.js';
107
+ import { boundedCommand } from './executors/bounded-exec/schema.js';
90
108
  import { ffiPathProblem } from './executors/scriptc-native/ffi-paths.js';
91
109
  import type { ScriptcNativeFfi } from './executors/scriptc-native/schema.js';
92
110
  import { hashVersionlessCrateManifests } from './manifest-hash.js';
@@ -106,7 +124,13 @@ import {
106
124
  timingsSuiteInputs,
107
125
  } from './test-timings.js';
108
126
  import { assertUpstreamBasePrecondition } from './test-walk-policy.js';
109
- import { type NativeTools, nativeToolCommand, nativeToolDependsOn, resolveNativeTools } from './tool-bins.js';
127
+ import {
128
+ type NativeTools,
129
+ nativeToolCommand,
130
+ nativeToolDependsOn,
131
+ pluginBuildDependsOn,
132
+ resolveNativeTools,
133
+ } from './tool-bins.js';
110
134
  import { typecheckRoute } from './typecheck-route.js';
111
135
  import {
112
136
  isBuildOutputTargetName,
@@ -231,13 +255,46 @@ const NODE_MODULES_SEGMENT = /(?:^|\/)node_modules(?:\/|$)/;
231
255
  * which is the silence above. The ancestors this cannot name as a fileset are
232
256
  * the two kinds Nx has no fileset for; see {@link configChainInput}.
233
257
  */
234
- function typescriptConfigChainInputs(configPaths: readonly string[], workspaceRoot: string): string[] {
235
- const inputs = new Set([WORKSPACE_TSCONFIG_BASE_INPUT]);
258
+ function typescriptConfigChainInputs(configPaths: readonly string[], workspaceRoot: string): TypescriptConfigChain {
259
+ const chain: TypescriptConfigChainParts = {
260
+ inputs: new Set([WORKSPACE_TSCONFIG_BASE_INPUT]),
261
+ extendsLoads: [],
262
+ transformLoads: [],
263
+ };
236
264
  const walked = new Set<string>();
237
265
  for (const configPath of configPaths) {
238
- addTypescriptConfigAncestors(configPath, workspaceRoot, inputs, walked);
266
+ addTypescriptConfigAncestors(configPath, workspaceRoot, chain, walked);
267
+ }
268
+ return { inputs: [...chain.inputs], extendsLoads: chain.extendsLoads, transformLoads: chain.transformLoads };
269
+ }
270
+
271
+ /** What a project's TypeScript configs make its tasks read: the config files, and the packages they load by name. */
272
+ interface TypescriptConfigChain {
273
+ /** Every workspace config of the chains, as an input. */
274
+ readonly inputs: string[];
275
+ /** Each installed config the chains extend, by the package holding it and the directory of the config naming it. */
276
+ readonly extendsLoads: readonly PackageLoad[];
277
+ /** Each transform plugin a workspace config of the chains names (`compilerOptions.plugins[].transform`), which ttsc loads. */
278
+ readonly transformLoads: readonly PackageLoad[];
279
+ }
280
+
281
+ interface TypescriptConfigChainParts {
282
+ readonly inputs: Set<string>;
283
+ readonly extendsLoads: PackageLoad[];
284
+ readonly transformLoads: PackageLoad[];
285
+ }
286
+
287
+ /** The bare transform plugin specifiers one config names (`compilerOptions.plugins[].transform`). */
288
+ function typescriptTransforms(configPath: string): string[] {
289
+ const config: unknown = readJsonFile(configPath, { expectComments: true });
290
+ if (!isRecord(config) || !isRecord(config.compilerOptions) || !Array.isArray(config.compilerOptions.plugins)) {
291
+ return [];
239
292
  }
240
- return [...inputs];
293
+ return config.compilerOptions.plugins.flatMap((plugin: unknown) =>
294
+ isRecord(plugin) && typeof plugin.transform === 'string' && /^[@\w]/u.test(plugin.transform)
295
+ ? [plugin.transform]
296
+ : [],
297
+ );
241
298
  }
242
299
 
243
300
  /**
@@ -245,24 +302,32 @@ function typescriptConfigChainInputs(configPaths: readonly string[], workspaceRo
245
302
  * `extends` cycle.
246
303
  *
247
304
  * The walk stops at an ancestor Nx cannot hash, because everything reachable
248
- * from an installed config is installed too: the lockfile pins that whole
249
- * subtree, and parsing it could only invent failures for a dependency's own
250
- * chain.
305
+ * from an installed config is installed too: the package holding it is
306
+ * recorded as a load of the extending config's directory, and the lock scope
307
+ * that declares it there keys that whole subtree. Parsing it could only
308
+ * invent failures for a dependency's own chain.
251
309
  */
252
310
  function addTypescriptConfigAncestors(
253
311
  configPath: string,
254
312
  workspaceRoot: string,
255
- inputs: Set<string>,
313
+ chain: TypescriptConfigChainParts,
256
314
  walked: Set<string>,
257
315
  ): void {
258
316
  if (walked.has(configPath)) return;
259
317
  walked.add(configPath);
318
+ const directory = relative(workspaceRoot, dirname(configPath)).replaceAll('\\', '/') || '.';
319
+ for (const transform of typescriptTransforms(configPath)) {
320
+ chain.transformLoads.push({ directory, name: specifierPackage(transform) });
321
+ }
260
322
  for (const specifier of typescriptConfigExtends(configPath)) {
261
323
  const ancestor = resolveTypescriptConfigExtends(specifier, configPath);
262
324
  const input = configChainInput(ancestor, configPath, workspaceRoot);
263
- if (input === null) continue;
264
- inputs.add(input);
265
- addTypescriptConfigAncestors(ancestor.path, workspaceRoot, inputs, walked);
325
+ if (input === null) {
326
+ if (ancestor.installed) chain.extendsLoads.push({ directory, name: specifierPackage(specifier) });
327
+ continue;
328
+ }
329
+ chain.inputs.add(input);
330
+ addTypescriptConfigAncestors(ancestor.path, workspaceRoot, chain, walked);
266
331
  }
267
332
  }
268
333
 
@@ -426,6 +491,8 @@ interface EslintWorkspace {
426
491
  readonly sources: ReadonlySet<string>;
427
492
  /** The workspace modules the root configs load, transitively, workspace-relative and sorted; the configs excluded. */
428
493
  readonly configImports: readonly string[];
494
+ /** The lock scopes of the installed packages those modules load by name, each where its module loads it; sorted. */
495
+ readonly configScopes: readonly string[];
429
496
  }
430
497
 
431
498
  /**
@@ -445,15 +512,18 @@ interface EslintWorkspace {
445
512
  * The configs key every lint target with exactly the workspace files they
446
513
  * load (eslint-config-closure.ts): a glob over the directory holding a
447
514
  * config's rule modules keyed every file beside them, and one test fixture
448
- * there re-keyed 44 lint targets in one land.
515
+ * there re-keyed 44 lint targets in one land. The packages they load by name
516
+ * key it by the lock scope declaring each where it loads (bun-lock-scope.ts).
449
517
  */
450
518
  async function eslintWorkspace(workspaceRoot: string): Promise<EslintWorkspace | null> {
451
519
  const configs = ESLINT_CONFIG_FILES.filter((name) => existsSync(join(workspaceRoot, name)));
452
520
  if (configs.length === 0) return null;
453
521
  const indexed = new Set(await globIndexedFiles(workspaceRoot, [ESLINT_SOURCES_GLOB, '**/*.json']));
522
+ const closure = eslintConfigClosure(workspaceRoot, configs, indexed);
454
523
  return {
455
524
  sources: new Set([...indexed].filter((path) => !path.endsWith('.json'))),
456
- configImports: eslintConfigClosure(workspaceRoot, configs, indexed),
525
+ configImports: closure.files,
526
+ configScopes: bunLoadScopes(workspaceRoot, closure.packageLoads),
457
527
  };
458
528
  }
459
529
 
@@ -851,18 +921,21 @@ function createCargoWasmTarget(
851
921
  * create its parent, so the build consumes what the `mkdir` produced. Outside
852
922
  * Nx there is no task hash, and a build no task names is refused here rather
853
923
  * than by every runner.
924
+ *
925
+ * `inputs` is the workspace's Cargo union; the build also runs the nextest helper (`record`).
854
926
  */
855
927
  function createCargoTestBuildTarget(
856
928
  projectRoot: string,
857
929
  toolConfig: string,
858
930
  nativeTools: NativeTools | null,
931
+ inputs: NonNullable<TargetConfiguration['inputs']>,
859
932
  ): TargetConfiguration {
860
- const helper = nativeToolCommand(nativeTools, projectRoot, 'nextest-extract', 'smoo-nx-nextest-binaries');
933
+ const helper = nativeToolCommand(nativeTools, projectRoot, 'nextest-extract', NEXTEST_HELPER_BIN);
861
934
  return {
862
935
  executor: 'nx:run-commands',
863
936
  metadata: CARGO_PRODUCER_METADATA,
864
937
  cache: true,
865
- inputs: CARGO_INPUTS,
938
+ inputs: [...inputs, ...nextestHelperInputs(nativeTools)],
866
939
  outputs: [
867
940
  `{projectRoot}/${NEXTEST_BINARIES_METADATA}`,
868
941
  `{projectRoot}/${NEXTEST_CARGO_METADATA}`,
@@ -892,6 +965,21 @@ function nextestBinariesBuild(toolConfig: string): string {
892
965
  return cargoFrozen(`${NEXTEST_BINARIES_BUILD_ARGS.join(' ')} ${toolConfig}`);
893
966
  }
894
967
 
968
+ /** The nextest helper the test build and every runner run (`record`, `ensure`, `target-dir`). */
969
+ const NEXTEST_HELPER_BIN = 'smoo-nx-nextest-binaries';
970
+
971
+ /**
972
+ * The helper's bytes, for a target that runs it, where this workspace builds it: the producer edge orders the build and
973
+ * this input keys what the target runs. An installed helper is its package's, keyed as the package.
974
+ */
975
+ function nextestHelperInputs(
976
+ nativeTools: NativeTools | null,
977
+ ): { dependentTasksOutputFiles: string; transitive: false }[] {
978
+ return nativeTools !== null && nativeToolDependsOn(nativeTools, 'nextest-extract').length > 0
979
+ ? [{ dependentTasksOutputFiles: `**/dist/bin/${nativeTools.platform}/${NEXTEST_HELPER_BIN}`, transitive: false }]
980
+ : [];
981
+ }
982
+
895
983
  /**
896
984
  * One foreign triple's test archive, and the target that EXECUTES it.
897
985
  *
@@ -1306,12 +1394,14 @@ export const postTasksExecution: PostTasksExecution<ProducerReceiptsOptions> = a
1306
1394
  export const createDependencies: CreateDependencies = (options, context) => [
1307
1395
  ...bunLockDependencies(context),
1308
1396
  ...builtOutputLockfileDependencies(options, context),
1397
+ ...bunVersionAliasDependencies(context.externalNodes ?? {}),
1309
1398
  ];
1310
1399
 
1311
1400
  /** Nx invokes this only after merging inferred/declarative targets and every plugin's project dependencies. */
1312
1401
  export const createMetadata: CreateMetadata = (graph, _options, context) => {
1313
1402
  refuseOverlappingOutputs(graph, context.workspaceRoot);
1314
1403
  refuseBuildTestDependencies(graph, context.workspaceRoot);
1404
+ refuseUndeclaredImports(graph);
1315
1405
  return {};
1316
1406
  };
1317
1407
 
@@ -1678,20 +1768,40 @@ async function createProjectTargets(
1678
1768
  [...(hasLibTsconfig ? [libTsconfigPath] : []), ...(hasTestTsconfig ? [testTsconfigPath] : [])],
1679
1769
  workspaceRoot,
1680
1770
  );
1771
+ // The packages a TypeScript task loads by name beyond its sources' imports, each keyed by the lock scope that
1772
+ // declares it where it loads (bun-lock-scope.ts): the project's own node keys its own declarations, and a root
1773
+ // declaration is named by itself, so no task is keyed on root tooling it never loads. A check reads the @types and
1774
+ // tslib TypeScript finds by ancestry and the installed configs its chain extends. The emit also runs ttsc from the
1775
+ // root's node_modules/.bin, and ttsc loads the TypeScript API from the project and each transform plugin its
1776
+ // configs name.
1777
+ const manifests = manifestsAbove(workspaceRoot, projectRoot);
1778
+ const rootManifests = manifests.filter((manifest) => manifest.root === '.');
1779
+ const checkScopes = [
1780
+ ...bunLoadInput(manifests, typescriptLoads(manifests)).externalDependencies,
1781
+ ...bunLoadScopes(workspaceRoot, typescriptConfigChain.extendsLoads),
1782
+ ];
1783
+ const checkScopeInput = bunScopeInput(projectRoot, checkScopes);
1784
+ const emitScopeInput = bunScopeInput(
1785
+ projectRoot,
1786
+ checkScopes,
1787
+ bunLoadInput(manifests, ['typescript']).externalDependencies,
1788
+ bunLoadInput(rootManifests, ['ttsc', '@typescript/native']).externalDependencies,
1789
+ bunLoadScopes(workspaceRoot, typescriptConfigChain.transformLoads),
1790
+ );
1681
1791
  const toolchainInputs = [
1682
1792
  ...RELEASE_REWRITTEN_WORKSPACE_INPUTS,
1683
- bunLockInput(projectRoot),
1793
+ emitScopeInput,
1684
1794
  ...TYPESCRIPT_PATCH_INPUTS,
1685
- ...typescriptConfigChain,
1795
+ ...typescriptConfigChain.inputs,
1686
1796
  ];
1687
1797
  const checkInputs =
1688
1798
  versionless === null
1689
1799
  ? toolchainInputs
1690
1800
  : [
1691
1801
  ...TYPESCRIPT_PATCH_INPUTS,
1692
- ...typescriptConfigChain,
1802
+ ...typescriptConfigChain.inputs,
1693
1803
  ...VERSIONLESS_TOOLCHAIN_MANIFEST_INPUTS,
1694
- bunLockInput(projectRoot),
1804
+ checkScopeInput,
1695
1805
  ];
1696
1806
  const selfProduction = versionless === null ? 'production' : VERSIONLESS_PRODUCTION_INPUT;
1697
1807
  const selfDefault = versionless === null ? 'default' : VERSIONLESS_DEFAULT_INPUT;
@@ -1895,32 +2005,37 @@ async function createProjectTargets(
1895
2005
  memberDir: plan.package.dir,
1896
2006
  cache: cargoWorkspace.inputsCache,
1897
2007
  cargo: cargoWorkspace.closureSource.cargo,
2008
+ sources: cargoWorkspace.closureSource.sources,
1898
2009
  }),
1899
2010
  ),
1900
2011
  )
1901
2012
  ).flat(),
1902
2013
  ),
1903
2014
  ];
1904
- // Generated crate sources (wire codecs, vocabularies, fixtures) are
1905
- // gitignored and invisible to nx's file hasher; they reach these targets
1906
- // as the outputs of the targets a repository adds to `dependsOn`. Hashing
1907
- // those outputs here means a repository never has to restate `inputs` to
1908
- // add them - and a restated `inputs` REPLACES this union with the root
1909
- // project's `default`, which owns no crate file, so the test build then
1910
- // cache-hits against edited crates while every per-crate test reruns on
1911
- // the stale binary. That verdict is wrong, not merely slow.
2015
+ // Generated crate sources (wire codecs, vocabularies, fixtures) and
2016
+ // compiled-in files are often gitignored and invisible to nx's file
2017
+ // hasher; they reach these targets as the outputs of the targets a
2018
+ // repository adds to `dependsOn`. Hashing those outputs here means a
2019
+ // repository never has to restate `inputs` to add them - and a restated
2020
+ // `inputs` REPLACES this union with the root project's `default`, which
2021
+ // owns no crate file, so the test build then cache-hits against edited
2022
+ // crates while every per-crate test reruns on the stale binary. Only the
2023
+ // outputs under the union's own file sets are hashed
2024
+ // (`cargoProducerOutputInputs`): a compile reads nothing else, and a
2025
+ // producer's TypeScript output outside every crate keys no Rust build.
2026
+ const closureInputs = workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS;
1912
2027
  const workspaceCargoInputs: TargetConfiguration['inputs'] = [
1913
- ...(workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS),
1914
- { dependentTasksOutputFiles: '**/*', transitive: false },
2028
+ ...closureInputs,
2029
+ ...cargoProducerOutputInputs(closureInputs, cargoWorkspaceRoot),
1915
2030
  ];
2031
+ // The build's `cargo nextest list` loads the repository's nextest config and
2032
+ // refuses an invalid one, so that file keys the build as well as every run.
1916
2033
  targets[CARGO_TEST_BUILD_TARGET] = createCargoTestBuildTarget(
1917
2034
  cargoWorkspaceRoot,
1918
2035
  nextestToolConfigArg(cargoWorkspaceRoot),
1919
2036
  nativeTools,
2037
+ [...workspaceCargoInputs, `{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`],
1920
2038
  );
1921
- // The build's `cargo nextest list` loads the repository's nextest config and
1922
- // refuses an invalid one, so that file keys the build as well as every run.
1923
- targets[CARGO_TEST_BUILD_TARGET].inputs = [...workspaceCargoInputs, `{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`];
1924
2039
  // One archive per declared foreign triple, from the same inputs and the
1925
2040
  // same repository nextest config, whose `archive.include` decides what an
1926
2041
  // archive CONTAINS: it is the workspace's test binaries for another
@@ -2215,38 +2330,6 @@ async function createProjectTargets(
2215
2330
  ];
2216
2331
  }
2217
2332
 
2218
- const napiDebug = targets['napi-debug'];
2219
- if (napiDebug && cargoWorkspace) {
2220
- // A crate whose project also builds the debug cdylib runs its tests after
2221
- // that build: the tests dlopen what `napi-debug` writes into `target/debug`,
2222
- // and a test binary run in place loads it from this tree.
2223
- const runners = [
2224
- ...cargoPackagePlans.flatMap((plan) => plan.pieces.map((piece) => piece.targetName)),
2225
- // The root owns the serial groups' runners, so they take its build as its pieces do.
2226
- ...(ownsCargoWorkspaceTargets
2227
- ? cargoWorkspace.serialGroups.map((group) => cargoTestGroupTargetName(group.group))
2228
- : []),
2229
- ];
2230
- for (const name of runners) {
2231
- const target = targets[name];
2232
- if (target && !hasCargoTargetDependency(target.dependsOn ?? [], 'napi-debug')) {
2233
- target.dependsOn = [...(target.dependsOn ?? []), 'napi-debug'];
2234
- }
2235
- }
2236
- } else if (napiDebug) {
2237
- const cargoTest = targets[CARGO_TEST_TARGET];
2238
- if (
2239
- cargoTest?.options &&
2240
- typeof cargoTest.options.command === 'string' &&
2241
- cargoTest.options.command.startsWith('cargo ')
2242
- ) {
2243
- const dependsOn = cargoTest.dependsOn ?? [];
2244
- if (!dependsOn.includes('napi-debug')) {
2245
- cargoTest.dependsOn = [...dependsOn, 'napi-debug'];
2246
- }
2247
- }
2248
- }
2249
-
2250
2333
  // The inferring host's own platform binaries join the aggregate `build`;
2251
2334
  // publish still owns foreign platforms.
2252
2335
  const hostPlatformBinaries = hostPlatformTargetNames(
@@ -2412,6 +2495,15 @@ async function createProjectTargets(
2412
2495
  inputs: lintProgramInputs,
2413
2496
  eslintFileSet,
2414
2497
  } = projectLintCommands(projectRoot, workspaceRoot, eslint);
2498
+ // The lint tools run from the root's node_modules/.bin, and ESLint loads the packages its configs name.
2499
+ const runsEslint = eslintFileSet !== null;
2500
+ const lintScopes = [
2501
+ ...bunLoadInput(rootManifests, [
2502
+ ...(runsEslint ? ['eslint'] : []),
2503
+ ...(lintCommands.some((command) => command.startsWith('biome ')) ? ['@biomejs/biome'] : []),
2504
+ ]).externalDependencies,
2505
+ ...(runsEslint ? (eslint?.configScopes ?? []) : []),
2506
+ ];
2415
2507
  // Every lint tool reaches its own verdict in one run: run-commands would end the
2416
2508
  // other tools once one fails, and their findings would surface a run later.
2417
2509
  if (validationTargets.length > 0 || lintCommands.length > 0) {
@@ -2431,6 +2523,7 @@ async function createProjectTargets(
2431
2523
  `{projectRoot}/${name}`,
2432
2524
  ]),
2433
2525
  ...(eslint?.configImports ?? []).map((path) => `{workspaceRoot}/${path}`),
2526
+ ...(lintScopes.length > 0 ? [bunScopeInput(projectRoot, lintScopes)] : []),
2434
2527
  ],
2435
2528
  ...(lintCommands.length > 0
2436
2529
  ? {
@@ -2458,8 +2551,12 @@ async function createProjectTargets(
2458
2551
  }
2459
2552
  }
2460
2553
 
2461
- // Runtime observers need the local addon, not the package aggregate (which can deliberately build only JS).
2462
- // Declarations retain these prerequisites and output inputs with Nx's ordinary "..." merge token.
2554
+ // bounded-exec's admission observer loads cowshed's process-lineage entry, and through it the addon, only while a
2555
+ // Cargo leaf waits for mbx admission (specs/cowshed/11_shell.md, "Cargo test-runner boundaries"; mbx-queue.ts). Such
2556
+ // a target runs after the local producers so the observer finds them. Its reading only decides whether that wait is
2557
+ // credited against the idle bound, so the producers' bytes key no target (README, "Bounded exec key"): a command that
2558
+ // reads them keys them itself. A command named in either the declaration or the inference counts.
2559
+ // Declarations retain these prerequisites with Nx's ordinary "..." merge token.
2463
2560
  // The canonical release-check instead judges prebuilt shipping artifacts and must remain dependency-free.
2464
2561
  const observerProducers = [...nativeToolDependsOn(nativeTools, 'cowshed'), ...lineageProducer];
2465
2562
  if (observerProducers.length > 0) {
@@ -2472,15 +2569,67 @@ async function createProjectTargets(
2472
2569
  if (targets[name]?.executor !== undefined && targets[name]?.executor !== executor) {
2473
2570
  targets[name] = {};
2474
2571
  }
2572
+ const runs = [...targetOptionSets(declared), ...targetOptionSets(targets[name])];
2573
+ if (!runs.some((options) => runsAsCargoLeaf(boundedCommandLine(options) ?? ''))) continue;
2475
2574
  targets[name] ??= {};
2476
2575
  const target = targets[name];
2477
2576
  target.dependsOn = [...(target.dependsOn ?? []), ...observerProducers];
2577
+ }
2578
+ }
2579
+
2580
+ // The package's addon loader reads napi-debug's dev-profile addon when NAPI_DEBUG_ADDON=1 (createNapiTestTarget), so
2581
+ // a target whose run sets it, in its declaration or its inference, runs after that build and keys the addon it writes.
2582
+ if (targets['napi-debug'] !== undefined) {
2583
+ for (const name of new Set([...Object.keys(targets), ...Object.keys(declaredTargets)])) {
2584
+ const declared = declaredTargets[name];
2585
+ const runs = [...targetOptionSets(declared), ...targetOptionSets(targets[name])];
2586
+ if (!runs.some((options) => isRecord(options.env) && options.env.NAPI_DEBUG_ADDON === '1')) continue;
2587
+ const executor =
2588
+ isRecord(declared) && declared.executor !== undefined ? declared.executor : targets[name]?.executor;
2589
+ // Nx discards an incompatible executor's inferred configuration; only the addon prerequisite belongs below it.
2590
+ if (targets[name]?.executor !== undefined && targets[name]?.executor !== executor) {
2591
+ targets[name] = {};
2592
+ }
2593
+ targets[name] ??= {};
2594
+ const target = targets[name];
2595
+ const named = [
2596
+ ...(target.dependsOn ?? []),
2597
+ ...(isRecord(declared) && Array.isArray(declared.dependsOn) ? declared.dependsOn : []),
2598
+ ];
2599
+ if (!named.includes('napi-debug')) {
2600
+ target.dependsOn = [...(target.dependsOn ?? []), 'napi-debug'];
2601
+ }
2478
2602
  const inputs =
2479
2603
  target.inputs ?? (isRecord(declared) && Array.isArray(declared.inputs) ? [] : ['default', '^production']);
2480
- target.inputs = [
2481
- ...inputs,
2482
- { dependentTasksOutputFiles: '**/*.node', transitive: true },
2483
- { dependentTasksOutputFiles: '**/dist/lineage/**/*.js', transitive: true },
2604
+ target.inputs = [...inputs, { dependentTasksOutputFiles: '**/*.node', transitive: false }];
2605
+ }
2606
+ }
2607
+
2608
+ // A plugin executor is a file the workspace plugin's own build writes, so a target that starts before that build
2609
+ // ends loads the dist a previous build left: one without the executors the plugin gained since (a Linux CLI
2610
+ // target failed "Could not resolve ./dist/executors/cargo-zigbuild/executor.js" in a checkout restored from a
2611
+ // cache that predated it). Every such target of every project but the plugin takes the one edge, so no executor
2612
+ // needs its own: the executors that build the plugin (the bootstrap ones) take none, the plugin's own targets
2613
+ // are ordered by its own graph, and release-check stays dependency-free (specs/cowshed/06_cli.md,
2614
+ // `release-check`). Declarations that replace `dependsOn` keep it with Nx's "..." token.
2615
+ if (packageJson.name !== '@smoothbricks/nx-plugin') {
2616
+ for (const name of new Set([...Object.keys(targets), ...Object.keys(declaredTargets)])) {
2617
+ if (name === 'release-check') continue;
2618
+ const declared = declaredTargets[name];
2619
+ const executor =
2620
+ isRecord(declared) && declared.executor !== undefined ? declared.executor : targets[name]?.executor;
2621
+ const edge = pluginBuildDependsOn(nativeTools, executor);
2622
+ if (edge.length === 0) continue;
2623
+ // Nx discards an incompatible executor's inferred configuration; only the edge belongs below it.
2624
+ if (targets[name]?.executor !== undefined && targets[name]?.executor !== executor) {
2625
+ targets[name] = {};
2626
+ }
2627
+ targets[name] ??= {};
2628
+ const target = targets[name];
2629
+ const present = new Set((target.dependsOn ?? []).map((dependency) => JSON.stringify(dependency)));
2630
+ target.dependsOn = [
2631
+ ...(target.dependsOn ?? []),
2632
+ ...edge.filter((dependency) => !present.has(JSON.stringify(dependency))),
2484
2633
  ];
2485
2634
  }
2486
2635
  }
@@ -2504,6 +2653,7 @@ async function createProjectTargets(
2504
2653
  // its configuration hash, so defining it everywhere would invalidate every
2505
2654
  // task in the repository to serve projects that can never reference it.
2506
2655
  const namedInputs: Record<string, NonNullable<TargetConfiguration['inputs']>> = {
2656
+ [BUN_LOCK_SCOPE_NAMED_INPUT]: [bunLockInput(projectRoot)],
2507
2657
  ...(versionless === null
2508
2658
  ? {}
2509
2659
  : {
@@ -2590,7 +2740,8 @@ async function lockScopeNodes(
2590
2740
  }
2591
2741
  }
2592
2742
  const own = bunLockNode(projectRoot);
2593
- const nodes: Record<string, ProjectGraphExternalNode> = { [own.name]: own };
2743
+ const runtime = bunLockRuntimeNode(projectRoot);
2744
+ const nodes: Record<string, ProjectGraphExternalNode> = { [own.name]: own, [runtime.name]: runtime };
2594
2745
  for (const node of await Promise.all(
2595
2746
  [...directories].map((directory) => cargoLockNode(directory, cargoSourcesUnder(directory, cargoWorkspaces))),
2596
2747
  )) {
@@ -2959,6 +3110,28 @@ function createNapiTargets(
2959
3110
  return targets;
2960
3111
  }
2961
3112
 
3113
+ /** A target's own options and each of its configurations' options, as one declaration or inference states them. */
3114
+ function targetOptionSets(target: unknown): Record<string, unknown>[] {
3115
+ if (!isRecord(target)) return [];
3116
+ const configurations = isRecord(target.configurations) ? Object.values(target.configurations) : [];
3117
+ return [target.options, ...configurations].filter(isRecord);
3118
+ }
3119
+
3120
+ /** The command line a bounded-exec run with `options` starts (`boundedCommand`), or null when they name no command. */
3121
+ function boundedCommandLine(options: Record<string, unknown>): string | null {
3122
+ const { command, args } = options;
3123
+ if (typeof command !== 'string') return null;
3124
+ return boundedCommand({
3125
+ command,
3126
+ args:
3127
+ typeof args === 'string'
3128
+ ? args
3129
+ : Array.isArray(args)
3130
+ ? args.filter((arg): arg is string => typeof arg === 'string')
3131
+ : undefined,
3132
+ });
3133
+ }
3134
+
2962
3135
  function createNapiTestTarget(projectRoot: string, hasDedicatedBunfig: boolean): TargetConfiguration {
2963
3136
  const configFlag = hasDedicatedBunfig ? ' --config=../bunfig.napi-test.toml' : ' --config=../bunfig.toml';
2964
3137
  return {
@@ -3217,14 +3390,14 @@ async function resolveCargoWorkspaces(
3217
3390
  if (found.length === 0) return [];
3218
3391
  // Started only once every workspace listed cleanly, so a listing that throws
3219
3392
  // leaves no Cargo process behind.
3220
- const indexedManifests = indexedCargoManifests(workspaceRoot);
3393
+ const indexedSources = indexedCargoSources(workspaceRoot);
3221
3394
  return Promise.all(
3222
3395
  found.map(async (workspace) => ({
3223
3396
  ...workspace,
3224
3397
  closureSource: await resolveCargoClosureSource(
3225
3398
  posix.join(workspace.projectRoot, 'Cargo.toml'),
3226
3399
  workspaceRoot,
3227
- indexedManifests,
3400
+ indexedSources,
3228
3401
  workspace.inputsCache.compiledInFiles,
3229
3402
  ),
3230
3403
  })),
@@ -3374,6 +3547,7 @@ async function cargoTestRunnerInputs(
3374
3547
  memberDir,
3375
3548
  cache: workspace.inputsCache,
3376
3549
  cargo: workspace.closureSource.cargo,
3550
+ sources: workspace.closureSource.sources,
3377
3551
  }),
3378
3552
  ),
3379
3553
  );
@@ -3424,7 +3598,7 @@ const NEXTEST_BINARIES_FIXTURE_TIMEOUT_MS = 3_600_000;
3424
3598
  * from the run's, and names the crates loudly when mbx had to compile (smoo-nx-nextest-binaries).
3425
3599
  */
3426
3600
  function nextestRunnerFixture(workspace: CargoWorkspace, nativeTools: NativeTools | null): string {
3427
- const helper = nativeToolCommand(nativeTools, workspace.projectRoot, 'nextest-extract', 'smoo-nx-nextest-binaries');
3601
+ const helper = nativeToolCommand(nativeTools, workspace.projectRoot, 'nextest-extract', NEXTEST_HELPER_BIN);
3428
3602
  return `${helper} ensure ${NEXTEST_BINARIES_METADATA} ${NEXTEST_BUILD_KEY} -- ${nextestBinariesBuild(nextestToolConfigArg(workspace.projectRoot))}`;
3429
3603
  }
3430
3604
 
@@ -3442,7 +3616,7 @@ function nextestRunnerCommand(
3442
3616
  ): string {
3443
3617
  const toolConfig = nextestToolConfigArg(workspace.projectRoot);
3444
3618
  // Relative to the runner's cwd, so the hashed command is the same in every checkout.
3445
- const helper = nativeToolCommand(nativeTools, workspace.projectRoot, 'nextest-extract', 'smoo-nx-nextest-binaries');
3619
+ const helper = nativeToolCommand(nativeTools, workspace.projectRoot, 'nextest-extract', NEXTEST_HELPER_BIN);
3446
3620
  const reuseBuild =
3447
3621
  `--binaries-metadata ${NEXTEST_BINARIES_METADATA} --cargo-metadata ${NEXTEST_CARGO_METADATA} ` +
3448
3622
  `--target-dir-remap "$(${helper} target-dir)"`;
@@ -3462,7 +3636,8 @@ function cargoTestRunnerTarget(
3462
3636
  return {
3463
3637
  executor: '@smoothbricks/nx-plugin:bounded-exec',
3464
3638
  cache: true,
3465
- inputs,
3639
+ // The command (`target-dir`) and the fixture (`ensure`) run the nextest helper.
3640
+ inputs: [...inputs, ...nextestHelperInputs(nativeTools)],
3466
3641
  dependsOn: [build, ...nativeToolDependsOn(nativeTools, 'nextest-extract')],
3467
3642
  options: {
3468
3643
  command: nextestRunnerCommand(
@@ -3500,7 +3675,7 @@ function cargoTestGroupTarget(
3500
3675
  return {
3501
3676
  executor: '@smoothbricks/nx-plugin:bounded-exec',
3502
3677
  cache: true,
3503
- inputs: [...inputs, fileHashInput(PLUGIN_NEXTEST_CODE_BOUND)],
3678
+ inputs: [...inputs, fileHashInput(PLUGIN_NEXTEST_CODE_BOUND), ...nextestHelperInputs(nativeTools)],
3504
3679
  dependsOn: [CARGO_TEST_BUILD_TARGET, ...nativeToolDependsOn(nativeTools, 'nextest-extract')],
3505
3680
  options: {
3506
3681
  command: nextestRunnerCommand('run', workspace, nativeTools, group.filter, ' --no-fail-fast --no-tests=fail'),
@@ -3513,21 +3688,3 @@ function cargoTestGroupTarget(
3513
3688
  },
3514
3689
  };
3515
3690
  }
3516
-
3517
- function hasCargoTargetDependency(
3518
- dependencies: readonly CargoTargetDependency[],
3519
- expected: CargoTargetDependency,
3520
- ): boolean {
3521
- if (typeof expected === 'string') {
3522
- return dependencies.includes(expected);
3523
- }
3524
- return dependencies.some(
3525
- (dependency) =>
3526
- typeof dependency !== 'string' &&
3527
- dependency.target === expected.target &&
3528
- Array.isArray(dependency.projects) &&
3529
- Array.isArray(expected.projects) &&
3530
- dependency.projects.length === expected.projects.length &&
3531
- dependency.projects.every((project, index) => project === expected.projects?.[index]),
3532
- );
3533
- }
@@ -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(