@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/dist/index.js CHANGED
@@ -10,19 +10,21 @@ import { parse as parseToml } from 'smol-toml';
10
10
  import { BOUNDED_TEST_IDLE_TIMEOUT_MS, BOUNDED_TEST_KILL_AFTER_MS } from './bounded-test-policy.js';
11
11
  import { refuseOverlappingOutputs } from './build-state-output-policy.js';
12
12
  import { builtOutputLockfileDependencies, builtOutputLockfileNodes } from './built-output-packages.js';
13
- import { bunLockDependencies, bunLockInput, bunLockNode } from './bun-lock-scope.js';
14
- import { CARGO_CLOSURE_INPUT, CARGO_LOCK_NODE_PREFIX, cargoClosureInputs, cargoLockNode, cargoLockNodeName, indexedCargoManifests, isCargoLockInput, resolveCargoClosureSource, } from './cargo-closure-input.js';
13
+ import { BUN_LOCK_SCOPE_NAMED_INPUT, bunLoadInput, bunLoadScopes, bunLockDependencies, bunLockInput, bunLockNode, bunLockRuntimeNode, bunScopeInput, bunVersionAliasDependencies, manifestsAbove, refuseUndeclaredImports, specifierPackage, typescriptLoads, } from './bun-lock-scope.js';
14
+ import { CARGO_CLOSURE_INPUT, CARGO_LOCK_NODE_PREFIX, cargoClosureInputs, cargoLockNode, cargoLockNodeName, indexedCargoSources, isCargoLockInput, resolveCargoClosureSource, } from './cargo-closure-input.js';
15
15
  import { CARGO_PRODUCER_METADATA, postTasksExecution as postCargoRetention } from './cargo-retention-hook.js';
16
16
  import { CARGO_TOOLCHAIN_NAMED_INPUT, cargoRuntimeInput, cargoToolchainInputs } from './cargo-toolchain-policy.js';
17
- import { attributeCargoWorkspacePackages, CARGO_TEST_BUILD_TARGET, CARGO_TEST_EXCEPTIONS_SUFFIX, CARGO_TEST_TARGET, cargoPackageTestInputs, cargoTestGroupTargetName, cargoTestPackageTargetName, createCargoInputsCache, EXTERNAL_RUST_CRATES_INPUT, exceptionalTestFilter, listCargoCrossTestTargets, listCargoWorkspacePackages, NEXTEST_REPO_CONFIG_PATH, nextestToolConfigArg, PLUGIN_NEXTEST_CONFIG_PATH, requireExternalRustCratesInput, serialTestGroups, } from './cargo-workspace.js';
17
+ import { attributeCargoWorkspacePackages, CARGO_TEST_BUILD_TARGET, CARGO_TEST_EXCEPTIONS_SUFFIX, CARGO_TEST_TARGET, cargoPackageTestInputs, cargoProducerOutputInputs, cargoTestGroupTargetName, cargoTestPackageTargetName, createCargoInputsCache, EXTERNAL_RUST_CRATES_INPUT, exceptionalTestFilter, listCargoCrossTestTargets, listCargoWorkspacePackages, NEXTEST_REPO_CONFIG_PATH, nextestToolConfigArg, PLUGIN_NEXTEST_CONFIG_PATH, requireExternalRustCratesInput, serialTestGroups, } from './cargo-workspace.js';
18
18
  import { compileEnvironment } from './compile-environment.js';
19
19
  import { CARGO_CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET, CARGO_FETCH_COMMAND, CARGO_FETCH_TARGET, CARGO_LINT_CLIPPY_COMMAND, cargoCrossTestArchiveFile, cargoCrossTestArchiveTargetName, cargoCrossTestTargetName, cargoFrozen, runsFrozenCargo, } from './cross-check-policy.js';
20
20
  import { directDependencyManifests } from './dependency-manifests.js';
21
21
  import { eslintConfigClosure } from './eslint-config-closure.js';
22
22
  import { ESLINT_SOURCES_GLOB, eslintSources } from './eslint-sources.js';
23
23
  import { ALL_VERDICTS_EXECUTOR, ESLINT_SOURCES_TOKEN, } from './executors/all-verdicts/schema.js';
24
+ import { runsAsCargoLeaf } from './executors/bounded-exec/mbx-pool.js';
24
25
  import { closeRunReservations, serveRunReservations } from './executors/bounded-exec/mbx-reservations.js';
25
26
  import { closeRunCpuPool, serveRunCpuPool } from './executors/bounded-exec/run-cpu-pool.js';
27
+ import { boundedCommand } from './executors/bounded-exec/schema.js';
26
28
  import { ffiPathProblem } from './executors/scriptc-native/ffi-paths.js';
27
29
  import { hashVersionlessCrateManifests } from './manifest-hash.js';
28
30
  import { NEXTEST_TIMINGS_PATH, namedTestsFilter, readNextestTimings, timedShardMembers } from './nextest-timings.js';
@@ -32,7 +34,7 @@ import { inferredTaskKind, refuseBuildTestDependencies } from './task-graph-poli
32
34
  import { postTasksExecution as postTaskResults, preTasksExecution as preTaskResults } from './task-results.js';
33
35
  import { SHARD_TIMINGS_EXECUTOR, SHARD_TIMINGS_TARGET, timingsShardedSuite, timingsSuiteInputs, } from './test-timings.js';
34
36
  import { assertUpstreamBasePrecondition } from './test-walk-policy.js';
35
- import { nativeToolCommand, nativeToolDependsOn, resolveNativeTools } from './tool-bins.js';
37
+ import { nativeToolCommand, nativeToolDependsOn, pluginBuildDependsOn, resolveNativeTools, } from './tool-bins.js';
36
38
  import { typecheckRoute } from './typecheck-route.js';
37
39
  import { isBuildOutputTargetName, isTestNamespaceTargetName, isTestRunnerTargetName, RELEASE_CONFIGURATION, } from './workspace-config-policy.js';
38
40
  import { globIndexedFiles } from './workspace-index.js';
@@ -139,33 +141,55 @@ const NODE_MODULES_SEGMENT = /(?:^|\/)node_modules(?:\/|$)/;
139
141
  * the two kinds Nx has no fileset for; see {@link configChainInput}.
140
142
  */
141
143
  function typescriptConfigChainInputs(configPaths, workspaceRoot) {
142
- const inputs = new Set([WORKSPACE_TSCONFIG_BASE_INPUT]);
144
+ const chain = {
145
+ inputs: new Set([WORKSPACE_TSCONFIG_BASE_INPUT]),
146
+ extendsLoads: [],
147
+ transformLoads: [],
148
+ };
143
149
  const walked = new Set();
144
150
  for (const configPath of configPaths) {
145
- addTypescriptConfigAncestors(configPath, workspaceRoot, inputs, walked);
151
+ addTypescriptConfigAncestors(configPath, workspaceRoot, chain, walked);
152
+ }
153
+ return { inputs: [...chain.inputs], extendsLoads: chain.extendsLoads, transformLoads: chain.transformLoads };
154
+ }
155
+ /** The bare transform plugin specifiers one config names (`compilerOptions.plugins[].transform`). */
156
+ function typescriptTransforms(configPath) {
157
+ const config = readJsonFile(configPath, { expectComments: true });
158
+ if (!isRecord(config) || !isRecord(config.compilerOptions) || !Array.isArray(config.compilerOptions.plugins)) {
159
+ return [];
146
160
  }
147
- return [...inputs];
161
+ return config.compilerOptions.plugins.flatMap((plugin) => isRecord(plugin) && typeof plugin.transform === 'string' && /^[@\w]/u.test(plugin.transform)
162
+ ? [plugin.transform]
163
+ : []);
148
164
  }
149
165
  /**
150
166
  * One config's ancestors; `walked` both dedupes shared bases and breaks an
151
167
  * `extends` cycle.
152
168
  *
153
169
  * The walk stops at an ancestor Nx cannot hash, because everything reachable
154
- * from an installed config is installed too: the lockfile pins that whole
155
- * subtree, and parsing it could only invent failures for a dependency's own
156
- * chain.
170
+ * from an installed config is installed too: the package holding it is
171
+ * recorded as a load of the extending config's directory, and the lock scope
172
+ * that declares it there keys that whole subtree. Parsing it could only
173
+ * invent failures for a dependency's own chain.
157
174
  */
158
- function addTypescriptConfigAncestors(configPath, workspaceRoot, inputs, walked) {
175
+ function addTypescriptConfigAncestors(configPath, workspaceRoot, chain, walked) {
159
176
  if (walked.has(configPath))
160
177
  return;
161
178
  walked.add(configPath);
179
+ const directory = relative(workspaceRoot, dirname(configPath)).replaceAll('\\', '/') || '.';
180
+ for (const transform of typescriptTransforms(configPath)) {
181
+ chain.transformLoads.push({ directory, name: specifierPackage(transform) });
182
+ }
162
183
  for (const specifier of typescriptConfigExtends(configPath)) {
163
184
  const ancestor = resolveTypescriptConfigExtends(specifier, configPath);
164
185
  const input = configChainInput(ancestor, configPath, workspaceRoot);
165
- if (input === null)
186
+ if (input === null) {
187
+ if (ancestor.installed)
188
+ chain.extendsLoads.push({ directory, name: specifierPackage(specifier) });
166
189
  continue;
167
- inputs.add(input);
168
- addTypescriptConfigAncestors(ancestor.path, workspaceRoot, inputs, walked);
190
+ }
191
+ chain.inputs.add(input);
192
+ addTypescriptConfigAncestors(ancestor.path, workspaceRoot, chain, walked);
169
193
  }
170
194
  }
171
195
  /** What one config extends: a single specifier, or the ordered list TypeScript 5.0 added. */
@@ -319,16 +343,19 @@ const ESLINT_CONFIG_FILES = [
319
343
  * The configs key every lint target with exactly the workspace files they
320
344
  * load (eslint-config-closure.ts): a glob over the directory holding a
321
345
  * config's rule modules keyed every file beside them, and one test fixture
322
- * there re-keyed 44 lint targets in one land.
346
+ * there re-keyed 44 lint targets in one land. The packages they load by name
347
+ * key it by the lock scope declaring each where it loads (bun-lock-scope.ts).
323
348
  */
324
349
  async function eslintWorkspace(workspaceRoot) {
325
350
  const configs = ESLINT_CONFIG_FILES.filter((name) => existsSync(join(workspaceRoot, name)));
326
351
  if (configs.length === 0)
327
352
  return null;
328
353
  const indexed = new Set(await globIndexedFiles(workspaceRoot, [ESLINT_SOURCES_GLOB, '**/*.json']));
354
+ const closure = eslintConfigClosure(workspaceRoot, configs, indexed);
329
355
  return {
330
356
  sources: new Set([...indexed].filter((path) => !path.endsWith('.json'))),
331
- configImports: eslintConfigClosure(workspaceRoot, configs, indexed),
357
+ configImports: closure.files,
358
+ configScopes: bunLoadScopes(workspaceRoot, closure.packageLoads),
332
359
  };
333
360
  }
334
361
  function projectLintCommands(projectRoot, workspaceRoot, eslint) {
@@ -661,14 +688,16 @@ function createCargoWasmTarget(projectRoot, config, repoRooted, cargoTargetDirec
661
688
  * create its parent, so the build consumes what the `mkdir` produced. Outside
662
689
  * Nx there is no task hash, and a build no task names is refused here rather
663
690
  * than by every runner.
691
+ *
692
+ * `inputs` is the workspace's Cargo union; the build also runs the nextest helper (`record`).
664
693
  */
665
- function createCargoTestBuildTarget(projectRoot, toolConfig, nativeTools) {
666
- const helper = nativeToolCommand(nativeTools, projectRoot, 'nextest-extract', 'smoo-nx-nextest-binaries');
694
+ function createCargoTestBuildTarget(projectRoot, toolConfig, nativeTools, inputs) {
695
+ const helper = nativeToolCommand(nativeTools, projectRoot, 'nextest-extract', NEXTEST_HELPER_BIN);
667
696
  return {
668
697
  executor: 'nx:run-commands',
669
698
  metadata: CARGO_PRODUCER_METADATA,
670
699
  cache: true,
671
- inputs: CARGO_INPUTS,
700
+ inputs: [...inputs, ...nextestHelperInputs(nativeTools)],
672
701
  outputs: [
673
702
  `{projectRoot}/${NEXTEST_BINARIES_METADATA}`,
674
703
  `{projectRoot}/${NEXTEST_CARGO_METADATA}`,
@@ -696,6 +725,17 @@ function createCargoTestBuildTarget(projectRoot, toolConfig, nativeTools) {
696
725
  function nextestBinariesBuild(toolConfig) {
697
726
  return cargoFrozen(`${NEXTEST_BINARIES_BUILD_ARGS.join(' ')} ${toolConfig}`);
698
727
  }
728
+ /** The nextest helper the test build and every runner run (`record`, `ensure`, `target-dir`). */
729
+ const NEXTEST_HELPER_BIN = 'smoo-nx-nextest-binaries';
730
+ /**
731
+ * The helper's bytes, for a target that runs it, where this workspace builds it: the producer edge orders the build and
732
+ * this input keys what the target runs. An installed helper is its package's, keyed as the package.
733
+ */
734
+ function nextestHelperInputs(nativeTools) {
735
+ return nativeTools !== null && nativeToolDependsOn(nativeTools, 'nextest-extract').length > 0
736
+ ? [{ dependentTasksOutputFiles: `**/dist/bin/${nativeTools.platform}/${NEXTEST_HELPER_BIN}`, transitive: false }]
737
+ : [];
738
+ }
699
739
  /**
700
740
  * One foreign triple's test archive, and the target that EXECUTES it.
701
741
  *
@@ -1033,11 +1073,13 @@ export const postTasksExecution = async (options, context) => {
1033
1073
  export const createDependencies = (options, context) => [
1034
1074
  ...bunLockDependencies(context),
1035
1075
  ...builtOutputLockfileDependencies(options, context),
1076
+ ...bunVersionAliasDependencies(context.externalNodes ?? {}),
1036
1077
  ];
1037
1078
  /** Nx invokes this only after merging inferred/declarative targets and every plugin's project dependencies. */
1038
1079
  export const createMetadata = (graph, _options, context) => {
1039
1080
  refuseOverlappingOutputs(graph, context.workspaceRoot);
1040
1081
  refuseBuildTestDependencies(graph, context.workspaceRoot);
1082
+ refuseUndeclaredImports(graph);
1041
1083
  return {};
1042
1084
  };
1043
1085
  export default { createNodesV2, createDependencies, createMetadata, postTasksExecution, preTasksExecution };
@@ -1337,19 +1379,33 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1337
1379
  // whole `extends` chain of the configs its commands name and not just those
1338
1380
  // two files. Resolved once per project: every target below shares it.
1339
1381
  const typescriptConfigChain = typescriptConfigChainInputs([...(hasLibTsconfig ? [libTsconfigPath] : []), ...(hasTestTsconfig ? [testTsconfigPath] : [])], workspaceRoot);
1382
+ // The packages a TypeScript task loads by name beyond its sources' imports, each keyed by the lock scope that
1383
+ // declares it where it loads (bun-lock-scope.ts): the project's own node keys its own declarations, and a root
1384
+ // declaration is named by itself, so no task is keyed on root tooling it never loads. A check reads the @types and
1385
+ // tslib TypeScript finds by ancestry and the installed configs its chain extends. The emit also runs ttsc from the
1386
+ // root's node_modules/.bin, and ttsc loads the TypeScript API from the project and each transform plugin its
1387
+ // configs name.
1388
+ const manifests = manifestsAbove(workspaceRoot, projectRoot);
1389
+ const rootManifests = manifests.filter((manifest) => manifest.root === '.');
1390
+ const checkScopes = [
1391
+ ...bunLoadInput(manifests, typescriptLoads(manifests)).externalDependencies,
1392
+ ...bunLoadScopes(workspaceRoot, typescriptConfigChain.extendsLoads),
1393
+ ];
1394
+ const checkScopeInput = bunScopeInput(projectRoot, checkScopes);
1395
+ const emitScopeInput = bunScopeInput(projectRoot, checkScopes, bunLoadInput(manifests, ['typescript']).externalDependencies, bunLoadInput(rootManifests, ['ttsc', '@typescript/native']).externalDependencies, bunLoadScopes(workspaceRoot, typescriptConfigChain.transformLoads));
1340
1396
  const toolchainInputs = [
1341
1397
  ...RELEASE_REWRITTEN_WORKSPACE_INPUTS,
1342
- bunLockInput(projectRoot),
1398
+ emitScopeInput,
1343
1399
  ...TYPESCRIPT_PATCH_INPUTS,
1344
- ...typescriptConfigChain,
1400
+ ...typescriptConfigChain.inputs,
1345
1401
  ];
1346
1402
  const checkInputs = versionless === null
1347
1403
  ? toolchainInputs
1348
1404
  : [
1349
1405
  ...TYPESCRIPT_PATCH_INPUTS,
1350
- ...typescriptConfigChain,
1406
+ ...typescriptConfigChain.inputs,
1351
1407
  ...VERSIONLESS_TOOLCHAIN_MANIFEST_INPUTS,
1352
- bunLockInput(projectRoot),
1408
+ checkScopeInput,
1353
1409
  ];
1354
1410
  const selfProduction = versionless === null ? 'production' : VERSIONLESS_PRODUCTION_INPUT;
1355
1411
  const selfDefault = versionless === null ? 'default' : VERSIONLESS_DEFAULT_INPUT;
@@ -1513,24 +1569,28 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1513
1569
  memberDir: plan.package.dir,
1514
1570
  cache: cargoWorkspace.inputsCache,
1515
1571
  cargo: cargoWorkspace.closureSource.cargo,
1572
+ sources: cargoWorkspace.closureSource.sources,
1516
1573
  })))).flat()),
1517
1574
  ];
1518
- // Generated crate sources (wire codecs, vocabularies, fixtures) are
1519
- // gitignored and invisible to nx's file hasher; they reach these targets
1520
- // as the outputs of the targets a repository adds to `dependsOn`. Hashing
1521
- // those outputs here means a repository never has to restate `inputs` to
1522
- // add them - and a restated `inputs` REPLACES this union with the root
1523
- // project's `default`, which owns no crate file, so the test build then
1524
- // cache-hits against edited crates while every per-crate test reruns on
1525
- // the stale binary. That verdict is wrong, not merely slow.
1575
+ // Generated crate sources (wire codecs, vocabularies, fixtures) and
1576
+ // compiled-in files are often gitignored and invisible to nx's file
1577
+ // hasher; they reach these targets as the outputs of the targets a
1578
+ // repository adds to `dependsOn`. Hashing those outputs here means a
1579
+ // repository never has to restate `inputs` to add them - and a restated
1580
+ // `inputs` REPLACES this union with the root project's `default`, which
1581
+ // owns no crate file, so the test build then cache-hits against edited
1582
+ // crates while every per-crate test reruns on the stale binary. Only the
1583
+ // outputs under the union's own file sets are hashed
1584
+ // (`cargoProducerOutputInputs`): a compile reads nothing else, and a
1585
+ // producer's TypeScript output outside every crate keys no Rust build.
1586
+ const closureInputs = workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS;
1526
1587
  const workspaceCargoInputs = [
1527
- ...(workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS),
1528
- { dependentTasksOutputFiles: '**/*', transitive: false },
1588
+ ...closureInputs,
1589
+ ...cargoProducerOutputInputs(closureInputs, cargoWorkspaceRoot),
1529
1590
  ];
1530
- targets[CARGO_TEST_BUILD_TARGET] = createCargoTestBuildTarget(cargoWorkspaceRoot, nextestToolConfigArg(cargoWorkspaceRoot), nativeTools);
1531
1591
  // The build's `cargo nextest list` loads the repository's nextest config and
1532
1592
  // refuses an invalid one, so that file keys the build as well as every run.
1533
- targets[CARGO_TEST_BUILD_TARGET].inputs = [...workspaceCargoInputs, `{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`];
1593
+ targets[CARGO_TEST_BUILD_TARGET] = createCargoTestBuildTarget(cargoWorkspaceRoot, nextestToolConfigArg(cargoWorkspaceRoot), nativeTools, [...workspaceCargoInputs, `{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`]);
1534
1594
  // One archive per declared foreign triple, from the same inputs and the
1535
1595
  // same repository nextest config, whose `archive.include` decides what an
1536
1596
  // archive CONTAINS: it is the workspace's test binaries for another
@@ -1797,36 +1857,6 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1797
1857
  [UNRESOLVED_CARGO_LOCK_INPUT]),
1798
1858
  ];
1799
1859
  }
1800
- const napiDebug = targets['napi-debug'];
1801
- if (napiDebug && cargoWorkspace) {
1802
- // A crate whose project also builds the debug cdylib runs its tests after
1803
- // that build: the tests dlopen what `napi-debug` writes into `target/debug`,
1804
- // and a test binary run in place loads it from this tree.
1805
- const runners = [
1806
- ...cargoPackagePlans.flatMap((plan) => plan.pieces.map((piece) => piece.targetName)),
1807
- // The root owns the serial groups' runners, so they take its build as its pieces do.
1808
- ...(ownsCargoWorkspaceTargets
1809
- ? cargoWorkspace.serialGroups.map((group) => cargoTestGroupTargetName(group.group))
1810
- : []),
1811
- ];
1812
- for (const name of runners) {
1813
- const target = targets[name];
1814
- if (target && !hasCargoTargetDependency(target.dependsOn ?? [], 'napi-debug')) {
1815
- target.dependsOn = [...(target.dependsOn ?? []), 'napi-debug'];
1816
- }
1817
- }
1818
- }
1819
- else if (napiDebug) {
1820
- const cargoTest = targets[CARGO_TEST_TARGET];
1821
- if (cargoTest?.options &&
1822
- typeof cargoTest.options.command === 'string' &&
1823
- cargoTest.options.command.startsWith('cargo ')) {
1824
- const dependsOn = cargoTest.dependsOn ?? [];
1825
- if (!dependsOn.includes('napi-debug')) {
1826
- cargoTest.dependsOn = [...dependsOn, 'napi-debug'];
1827
- }
1828
- }
1829
- }
1830
1860
  // The inferring host's own platform binaries join the aggregate `build`;
1831
1861
  // publish still owns foreign platforms.
1832
1862
  const hostPlatformBinaries = hostPlatformTargetNames([...Object.keys(declaredTargets), ...Object.keys(targets)], hostPlatform);
@@ -1980,6 +2010,15 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1980
2010
  validationTargets.push(SHARD_TIMINGS_TARGET);
1981
2011
  }
1982
2012
  const { commands: lintCommands, inputs: lintProgramInputs, eslintFileSet, } = projectLintCommands(projectRoot, workspaceRoot, eslint);
2013
+ // The lint tools run from the root's node_modules/.bin, and ESLint loads the packages its configs name.
2014
+ const runsEslint = eslintFileSet !== null;
2015
+ const lintScopes = [
2016
+ ...bunLoadInput(rootManifests, [
2017
+ ...(runsEslint ? ['eslint'] : []),
2018
+ ...(lintCommands.some((command) => command.startsWith('biome ')) ? ['@biomejs/biome'] : []),
2019
+ ]).externalDependencies,
2020
+ ...(runsEslint ? (eslint?.configScopes ?? []) : []),
2021
+ ];
1983
2022
  // Every lint tool reaches its own verdict in one run: run-commands would end the
1984
2023
  // other tools once one fails, and their findings would surface a run later.
1985
2024
  if (validationTargets.length > 0 || lintCommands.length > 0) {
@@ -1999,6 +2038,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1999
2038
  `{projectRoot}/${name}`,
2000
2039
  ]),
2001
2040
  ...(eslint?.configImports ?? []).map((path) => `{workspaceRoot}/${path}`),
2041
+ ...(lintScopes.length > 0 ? [bunScopeInput(projectRoot, lintScopes)] : []),
2002
2042
  ],
2003
2043
  ...(lintCommands.length > 0
2004
2044
  ? {
@@ -2025,8 +2065,12 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
2025
2065
  ];
2026
2066
  }
2027
2067
  }
2028
- // Runtime observers need the local addon, not the package aggregate (which can deliberately build only JS).
2029
- // Declarations retain these prerequisites and output inputs with Nx's ordinary "..." merge token.
2068
+ // bounded-exec's admission observer loads cowshed's process-lineage entry, and through it the addon, only while a
2069
+ // Cargo leaf waits for mbx admission (specs/cowshed/11_shell.md, "Cargo test-runner boundaries"; mbx-queue.ts). Such
2070
+ // a target runs after the local producers so the observer finds them. Its reading only decides whether that wait is
2071
+ // credited against the idle bound, so the producers' bytes key no target (README, "Bounded exec key"): a command that
2072
+ // reads them keys them itself. A command named in either the declaration or the inference counts.
2073
+ // Declarations retain these prerequisites with Nx's ordinary "..." merge token.
2030
2074
  // The canonical release-check instead judges prebuilt shipping artifacts and must remain dependency-free.
2031
2075
  const observerProducers = [...nativeToolDependsOn(nativeTools, 'cowshed'), ...lineageProducer];
2032
2076
  if (observerProducers.length > 0) {
@@ -2039,14 +2083,66 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
2039
2083
  if (targets[name]?.executor !== undefined && targets[name]?.executor !== executor) {
2040
2084
  targets[name] = {};
2041
2085
  }
2086
+ const runs = [...targetOptionSets(declared), ...targetOptionSets(targets[name])];
2087
+ if (!runs.some((options) => runsAsCargoLeaf(boundedCommandLine(options) ?? '')))
2088
+ continue;
2042
2089
  targets[name] ??= {};
2043
2090
  const target = targets[name];
2044
2091
  target.dependsOn = [...(target.dependsOn ?? []), ...observerProducers];
2092
+ }
2093
+ }
2094
+ // The package's addon loader reads napi-debug's dev-profile addon when NAPI_DEBUG_ADDON=1 (createNapiTestTarget), so
2095
+ // a target whose run sets it, in its declaration or its inference, runs after that build and keys the addon it writes.
2096
+ if (targets['napi-debug'] !== undefined) {
2097
+ for (const name of new Set([...Object.keys(targets), ...Object.keys(declaredTargets)])) {
2098
+ const declared = declaredTargets[name];
2099
+ const runs = [...targetOptionSets(declared), ...targetOptionSets(targets[name])];
2100
+ if (!runs.some((options) => isRecord(options.env) && options.env.NAPI_DEBUG_ADDON === '1'))
2101
+ continue;
2102
+ const executor = isRecord(declared) && declared.executor !== undefined ? declared.executor : targets[name]?.executor;
2103
+ // Nx discards an incompatible executor's inferred configuration; only the addon prerequisite belongs below it.
2104
+ if (targets[name]?.executor !== undefined && targets[name]?.executor !== executor) {
2105
+ targets[name] = {};
2106
+ }
2107
+ targets[name] ??= {};
2108
+ const target = targets[name];
2109
+ const named = [
2110
+ ...(target.dependsOn ?? []),
2111
+ ...(isRecord(declared) && Array.isArray(declared.dependsOn) ? declared.dependsOn : []),
2112
+ ];
2113
+ if (!named.includes('napi-debug')) {
2114
+ target.dependsOn = [...(target.dependsOn ?? []), 'napi-debug'];
2115
+ }
2045
2116
  const inputs = target.inputs ?? (isRecord(declared) && Array.isArray(declared.inputs) ? [] : ['default', '^production']);
2046
- target.inputs = [
2047
- ...inputs,
2048
- { dependentTasksOutputFiles: '**/*.node', transitive: true },
2049
- { dependentTasksOutputFiles: '**/dist/lineage/**/*.js', transitive: true },
2117
+ target.inputs = [...inputs, { dependentTasksOutputFiles: '**/*.node', transitive: false }];
2118
+ }
2119
+ }
2120
+ // A plugin executor is a file the workspace plugin's own build writes, so a target that starts before that build
2121
+ // ends loads the dist a previous build left: one without the executors the plugin gained since (a Linux CLI
2122
+ // target failed "Could not resolve ./dist/executors/cargo-zigbuild/executor.js" in a checkout restored from a
2123
+ // cache that predated it). Every such target of every project but the plugin takes the one edge, so no executor
2124
+ // needs its own: the executors that build the plugin (the bootstrap ones) take none, the plugin's own targets
2125
+ // are ordered by its own graph, and release-check stays dependency-free (specs/cowshed/06_cli.md,
2126
+ // `release-check`). Declarations that replace `dependsOn` keep it with Nx's "..." token.
2127
+ if (packageJson.name !== '@smoothbricks/nx-plugin') {
2128
+ for (const name of new Set([...Object.keys(targets), ...Object.keys(declaredTargets)])) {
2129
+ if (name === 'release-check')
2130
+ continue;
2131
+ const declared = declaredTargets[name];
2132
+ const executor = isRecord(declared) && declared.executor !== undefined ? declared.executor : targets[name]?.executor;
2133
+ const edge = pluginBuildDependsOn(nativeTools, executor);
2134
+ if (edge.length === 0)
2135
+ continue;
2136
+ // Nx discards an incompatible executor's inferred configuration; only the edge belongs below it.
2137
+ if (targets[name]?.executor !== undefined && targets[name]?.executor !== executor) {
2138
+ targets[name] = {};
2139
+ }
2140
+ targets[name] ??= {};
2141
+ const target = targets[name];
2142
+ const present = new Set((target.dependsOn ?? []).map((dependency) => JSON.stringify(dependency)));
2143
+ target.dependsOn = [
2144
+ ...(target.dependsOn ?? []),
2145
+ ...edge.filter((dependency) => !present.has(JSON.stringify(dependency))),
2050
2146
  ];
2051
2147
  }
2052
2148
  }
@@ -2069,6 +2165,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
2069
2165
  // its configuration hash, so defining it everywhere would invalidate every
2070
2166
  // task in the repository to serve projects that can never reference it.
2071
2167
  const namedInputs = {
2168
+ [BUN_LOCK_SCOPE_NAMED_INPUT]: [bunLockInput(projectRoot)],
2072
2169
  ...(versionless === null
2073
2170
  ? {}
2074
2171
  : {
@@ -2143,7 +2240,8 @@ async function lockScopeNodes(projectRoot, inputLists, cargoWorkspaces) {
2143
2240
  }
2144
2241
  }
2145
2242
  const own = bunLockNode(projectRoot);
2146
- const nodes = { [own.name]: own };
2243
+ const runtime = bunLockRuntimeNode(projectRoot);
2244
+ const nodes = { [own.name]: own, [runtime.name]: runtime };
2147
2245
  for (const node of await Promise.all([...directories].map((directory) => cargoLockNode(directory, cargoSourcesUnder(directory, cargoWorkspaces))))) {
2148
2246
  nodes[node.name] = node;
2149
2247
  }
@@ -2439,6 +2537,27 @@ function createNapiTargets(projectRoot, config, hostPlatform, nativeTools, repoR
2439
2537
  }
2440
2538
  return targets;
2441
2539
  }
2540
+ /** A target's own options and each of its configurations' options, as one declaration or inference states them. */
2541
+ function targetOptionSets(target) {
2542
+ if (!isRecord(target))
2543
+ return [];
2544
+ const configurations = isRecord(target.configurations) ? Object.values(target.configurations) : [];
2545
+ return [target.options, ...configurations].filter(isRecord);
2546
+ }
2547
+ /** The command line a bounded-exec run with `options` starts (`boundedCommand`), or null when they name no command. */
2548
+ function boundedCommandLine(options) {
2549
+ const { command, args } = options;
2550
+ if (typeof command !== 'string')
2551
+ return null;
2552
+ return boundedCommand({
2553
+ command,
2554
+ args: typeof args === 'string'
2555
+ ? args
2556
+ : Array.isArray(args)
2557
+ ? args.filter((arg) => typeof arg === 'string')
2558
+ : undefined,
2559
+ });
2560
+ }
2442
2561
  function createNapiTestTarget(projectRoot, hasDedicatedBunfig) {
2443
2562
  const configFlag = hasDedicatedBunfig ? ' --config=../bunfig.napi-test.toml' : ' --config=../bunfig.toml';
2444
2563
  return {
@@ -2643,10 +2762,10 @@ async function resolveCargoWorkspaces(packageJsonPaths, workspaceRoot, hostPlatf
2643
2762
  return [];
2644
2763
  // Started only once every workspace listed cleanly, so a listing that throws
2645
2764
  // leaves no Cargo process behind.
2646
- const indexedManifests = indexedCargoManifests(workspaceRoot);
2765
+ const indexedSources = indexedCargoSources(workspaceRoot);
2647
2766
  return Promise.all(found.map(async (workspace) => ({
2648
2767
  ...workspace,
2649
- closureSource: await resolveCargoClosureSource(posix.join(workspace.projectRoot, 'Cargo.toml'), workspaceRoot, indexedManifests, workspace.inputsCache.compiledInFiles),
2768
+ closureSource: await resolveCargoClosureSource(posix.join(workspace.projectRoot, 'Cargo.toml'), workspaceRoot, indexedSources, workspace.inputsCache.compiledInFiles),
2650
2769
  })));
2651
2770
  }
2652
2771
  /**
@@ -2775,6 +2894,7 @@ async function cargoTestRunnerInputs(workspaceRoot, workspace, memberDirs) {
2775
2894
  memberDir,
2776
2895
  cache: workspace.inputsCache,
2777
2896
  cargo: workspace.closureSource.cargo,
2897
+ sources: workspace.closureSource.sources,
2778
2898
  })));
2779
2899
  // The test build unifies every built package's manifest into every test binary, and a runner's key does not follow
2780
2900
  // the build's outputs, so each runner names them all: the ones Nx holds as files, the rest through the repository's
@@ -2822,7 +2942,7 @@ const NEXTEST_BINARIES_FIXTURE_TIMEOUT_MS = 3_600_000;
2822
2942
  * from the run's, and names the crates loudly when mbx had to compile (smoo-nx-nextest-binaries).
2823
2943
  */
2824
2944
  function nextestRunnerFixture(workspace, nativeTools) {
2825
- const helper = nativeToolCommand(nativeTools, workspace.projectRoot, 'nextest-extract', 'smoo-nx-nextest-binaries');
2945
+ const helper = nativeToolCommand(nativeTools, workspace.projectRoot, 'nextest-extract', NEXTEST_HELPER_BIN);
2826
2946
  return `${helper} ensure ${NEXTEST_BINARIES_METADATA} ${NEXTEST_BUILD_KEY} -- ${nextestBinariesBuild(nextestToolConfigArg(workspace.projectRoot))}`;
2827
2947
  }
2828
2948
  /**
@@ -2833,7 +2953,7 @@ function nextestRunnerFixture(workspace, nativeTools) {
2833
2953
  function nextestRunnerCommand(verb, workspace, nativeTools, selector, flags) {
2834
2954
  const toolConfig = nextestToolConfigArg(workspace.projectRoot);
2835
2955
  // Relative to the runner's cwd, so the hashed command is the same in every checkout.
2836
- const helper = nativeToolCommand(nativeTools, workspace.projectRoot, 'nextest-extract', 'smoo-nx-nextest-binaries');
2956
+ const helper = nativeToolCommand(nativeTools, workspace.projectRoot, 'nextest-extract', NEXTEST_HELPER_BIN);
2837
2957
  const reuseBuild = `--binaries-metadata ${NEXTEST_BINARIES_METADATA} --cargo-metadata ${NEXTEST_CARGO_METADATA} ` +
2838
2958
  `--target-dir-remap "$(${helper} target-dir)"`;
2839
2959
  return cargoFrozen(`nextest ${verb} ${reuseBuild} --workspace-remap . -E ${shellWord(selector)}${flags} --user-config-file none ${toolConfig}`);
@@ -2843,7 +2963,8 @@ function cargoTestRunnerTarget(workspace, nativeTools, build, inputs, piece) {
2843
2963
  return {
2844
2964
  executor: '@smoothbricks/nx-plugin:bounded-exec',
2845
2965
  cache: true,
2846
- inputs,
2966
+ // The command (`target-dir`) and the fixture (`ensure`) run the nextest helper.
2967
+ inputs: [...inputs, ...nextestHelperInputs(nativeTools)],
2847
2968
  dependsOn: [build, ...nativeToolDependsOn(nativeTools, 'nextest-extract')],
2848
2969
  options: {
2849
2970
  command: nextestRunnerCommand('run', workspace, nativeTools, piece.selector, `${piece.extra} --no-fail-fast --no-tests=pass`),
@@ -2869,7 +2990,7 @@ function cargoTestGroupTarget(workspace, nativeTools, inputs, group) {
2869
2990
  return {
2870
2991
  executor: '@smoothbricks/nx-plugin:bounded-exec',
2871
2992
  cache: true,
2872
- inputs: [...inputs, fileHashInput(PLUGIN_NEXTEST_CODE_BOUND)],
2993
+ inputs: [...inputs, fileHashInput(PLUGIN_NEXTEST_CODE_BOUND), ...nextestHelperInputs(nativeTools)],
2873
2994
  dependsOn: [CARGO_TEST_BUILD_TARGET, ...nativeToolDependsOn(nativeTools, 'nextest-extract')],
2874
2995
  options: {
2875
2996
  command: nextestRunnerCommand('run', workspace, nativeTools, group.filter, ' --no-fail-fast --no-tests=fail'),
@@ -2882,14 +3003,3 @@ function cargoTestGroupTarget(workspace, nativeTools, inputs, group) {
2882
3003
  },
2883
3004
  };
2884
3005
  }
2885
- function hasCargoTargetDependency(dependencies, expected) {
2886
- if (typeof expected === 'string') {
2887
- return dependencies.includes(expected);
2888
- }
2889
- return dependencies.some((dependency) => typeof dependency !== 'string' &&
2890
- dependency.target === expected.target &&
2891
- Array.isArray(dependency.projects) &&
2892
- Array.isArray(expected.projects) &&
2893
- dependency.projects.length === expected.projects.length &&
2894
- dependency.projects.every((project, index) => project === expected.projects?.[index]));
2895
- }
@@ -9,7 +9,11 @@ import { type FileResult, type ManagedPathInfo } from './tree.js';
9
9
  * installs dependencies or resolves secrets.
10
10
  */
11
11
  export declare function generateManagedFiles(tree: Tree, projects: WorkspaceProjects, pathInfo?: ReadonlyMap<string, ManagedPathInfo>): Promise<FileResult[]>;
12
- /** Shared rendering boundary; stage only after every consumer formatter has succeeded. */
12
+ /**
13
+ * Shared rendering boundary; stage only after every consumer formatter has succeeded. The render is a function of the
14
+ * context, the workspace's source listing and what it reads through the Tree, so it runs again only when one of those
15
+ * changed (`renderedOnChange`); staging always compares against the Tree as it is.
16
+ */
13
17
  export declare function generateManagedFilesForContext(tree: Tree, context: ManagedFileContext, pathInfo?: ReadonlyMap<string, ManagedPathInfo>): Promise<FileResult[]>;
14
18
  /** Native Nx generate/sync entry point. CLI calls the same transformation with its already-loaded graph. */
15
19
  export default function generator(tree: Tree): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/managed-files/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqE,KAAK,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAGxH,OAAO,EAA4B,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,KAAK,kBAAkB,EAAsB,MAAM,YAAY,CAAC;AAGzE,OAAO,EAA4B,KAAK,UAAU,EAAE,KAAK,eAAe,EAAqB,MAAM,WAAW,CAAC;AAE/G;;;;;GAKG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,iBAAiB,EAC3B,QAAQ,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,GAC9C,OAAO,CAAC,UAAU,EAAE,CAAC,CAcvB;AAED,0FAA0F;AAC1F,wBAAsB,8BAA8B,CAClD,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,GAC9C,OAAO,CAAC,UAAU,EAAE,CAAC,CAYvB;AAED,4GAA4G;AAC5G,wBAA8B,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAIjE"}
1
+ {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/managed-files/generator.ts"],"names":[],"mappings":"AACA,OAAO,EAAqE,KAAK,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAGxH,OAAO,EAA4B,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,KAAK,kBAAkB,EAAsB,MAAM,YAAY,CAAC;AAIzE,OAAO,EAA4B,KAAK,UAAU,EAAE,KAAK,eAAe,EAAqB,MAAM,WAAW,CAAC;AAE/G;;;;;GAKG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,iBAAiB,EAC3B,QAAQ,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,GAC9C,OAAO,CAAC,UAAU,EAAE,CAAC,CAcvB;AAED;;;;GAIG;AACH,wBAAsB,8BAA8B,CAClD,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,GAC9C,OAAO,CAAC,UAAU,EAAE,CAAC,CAqBvB;AAED,4GAA4G;AAC5G,wBAA8B,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAIjE"}
@@ -1,9 +1,11 @@
1
+ import { createHash } from 'node:crypto';
1
2
  import { createProjectGraphAsync, getProjects, joinPathFragments, readJson } 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 { deriveManagedFileContext } from './context.js';
4
5
  import { renderManagedFiles } from './files.js';
5
6
  import { formatManagedContent } from './managed-format.js';
6
7
  import { inspectManagedPaths } from './paths.js';
8
+ import { renderedOnChange } from './render-memo.js';
7
9
  import { assertNoManagedConflicts, stageManagedFiles } from './tree.js';
8
10
  /**
9
11
  * All workspace content comes from Tree. The supplied graph is Nx's resolved
@@ -22,13 +24,26 @@ export async function generateManagedFiles(tree, projects, pathInfo) {
22
24
  });
23
25
  return generateManagedFilesForContext(tree, deriveManagedFileContext(manifest, packages, projects, tree.exists('bun.lock'), tree.read('.npmrc', 'utf8') ?? ''), pathInfo);
24
26
  }
25
- /** Shared rendering boundary; stage only after every consumer formatter has succeeded. */
27
+ /**
28
+ * Shared rendering boundary; stage only after every consumer formatter has succeeded. The render is a function of the
29
+ * context, the workspace's source listing and what it reads through the Tree, so it runs again only when one of those
30
+ * changed (`renderedOnChange`); staging always compares against the Tree as it is.
31
+ */
26
32
  export async function generateManagedFilesForContext(tree, context, pathInfo) {
27
- const files = [...renderManagedFiles(context), ...renderTypecheckTestFiles(tree)];
28
- for (const file of files) {
29
- if (file.content !== null)
30
- file.content = await formatManagedContent(tree.root, file.target, file.content);
31
- }
33
+ const listing = treeSourceListing(tree);
34
+ const key = createHash('sha256')
35
+ .update(JSON.stringify(context))
36
+ .update('\0')
37
+ .update(listing.join('\0'))
38
+ .digest('hex');
39
+ const files = await renderedOnChange(tree, key, async (reading) => {
40
+ const rendered = [...renderManagedFiles(context), ...renderTypecheckTestFiles(reading, listing)];
41
+ for (const file of rendered) {
42
+ if (file.content !== null)
43
+ file.content = await formatManagedContent(reading.root, file.target, file.content);
44
+ }
45
+ return rendered;
46
+ });
32
47
  const paths = pathInfo ??
33
48
  inspectManagedPaths(tree.root, files.filter((file) => file.content !== null).map((file) => file.target));
34
49
  return stageManagedFiles(tree, files, paths);
@@ -0,0 +1,13 @@
1
+ import type { Tree } from 'nx/src/devkit-exports.js';
2
+ import type { ManagedFile } from './tree.js';
3
+ /**
4
+ * The files `render` gives for `tree`, rendered again only when one of its inputs changed: `key`, which names what the
5
+ * render reads beside the Tree (the context, the source listing), or an answer the Tree gave it. Checking the answers
6
+ * reads each file the last render read, once; the render itself (policy, JSON edits, formatter runs) is skipped.
7
+ *
8
+ * A Tree with pending edits is rendered and nothing is kept: no later Tree shows those edits as they are here.
9
+ * The formatters' own configuration is not an answer: Prettier and Biome read it from disk, and Prettier keeps it for
10
+ * the life of the process, so a daemon already formats with what it first read.
11
+ */
12
+ export declare function renderedOnChange(tree: Tree, key: string, render: (tree: Tree) => Promise<ManagedFile[]>): Promise<readonly ManagedFile[]>;
13
+ //# sourceMappingURL=render-memo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-memo.d.ts","sourceRoot":"","sources":["../../src/managed-files/render-memo.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAc,IAAI,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAyG7C;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,WAAW,EAAE,CAAC,GAC7C,OAAO,CAAC,SAAS,WAAW,EAAE,CAAC,CAcjC"}