@smoothbricks/nx-plugin 0.3.14 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +36 -13
  2. package/dist/bin/smoo-nx-exec.d.ts +3 -0
  3. package/dist/bin/smoo-nx-exec.d.ts.map +1 -0
  4. package/dist/bin/{ensure-built.js → smoo-nx-exec.js} +17 -5
  5. package/dist/bounded-test-policy.d.ts.map +1 -1
  6. package/dist/bounded-test-policy.js +5 -2
  7. package/dist/cargo-workspace.d.ts +15 -1
  8. package/dist/cargo-workspace.d.ts.map +1 -1
  9. package/dist/cargo-workspace.js +113 -8
  10. package/dist/ensure-built.d.ts +3 -0
  11. package/dist/ensure-built.d.ts.map +1 -1
  12. package/dist/ensure-built.js +21 -1
  13. package/dist/executors/typescript-emit/executor.d.ts.map +1 -1
  14. package/dist/executors/typescript-emit/executor.js +20 -2
  15. package/dist/executors/typescript-emit/schema.d.ts +1 -0
  16. package/dist/executors/typescript-emit/schema.d.ts.map +1 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +335 -87
  19. package/package.json +4 -4
  20. package/src/bin/{ensure-built.ts → smoo-nx-exec.ts} +18 -6
  21. package/src/bounded-test-policy.test.ts +21 -0
  22. package/src/bounded-test-policy.ts +6 -2
  23. package/src/cargo-workspace.test.ts +142 -0
  24. package/src/cargo-workspace.ts +137 -8
  25. package/src/ensure-built.test.ts +121 -21
  26. package/src/ensure-built.ts +23 -1
  27. package/src/executors/typescript-emit/executor.test.ts +37 -1
  28. package/src/executors/typescript-emit/executor.ts +24 -2
  29. package/src/executors/typescript-emit/schema.json +8 -0
  30. package/src/executors/typescript-emit/schema.ts +1 -0
  31. package/src/index.test.ts +173 -6
  32. package/src/index.ts +426 -89
  33. package/dist/bin/ensure-built.d.ts +0 -3
  34. package/dist/bin/ensure-built.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { existsSync } from 'node:fs';
2
2
  import { readdir, readFile } from 'node:fs/promises';
3
- import { dirname, join, posix } from 'node:path';
3
+ import { dirname, join, posix, relative } from 'node:path';
4
4
  import { fileURLToPath } from 'node:url';
5
5
  import { readJsonFile, } from 'nx/src/devkit-exports.js';
6
6
  import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
7
7
  import { parse as parseToml } from 'smol-toml';
8
8
  import { BOUNDED_TEST_KILL_AFTER_MS, BOUNDED_TEST_TIMEOUT_MS } from './bounded-test-policy.js';
9
- import { CARGO_TEST_COMPILE_TARGET, CARGO_TEST_EXCEPTIONS_SUFFIX, CARGO_TEST_TARGET, cargoPackageTestInputs, cargoTestPackageTargetName, exceptionalTestFilter, listCargoWorkspacePackages, nextestConfigRelPath, } from './cargo-workspace.js';
9
+ import { attributeCargoWorkspacePackages, CARGO_TEST_COMPILE_TARGET, CARGO_TEST_EXCEPTIONS_SUFFIX, CARGO_TEST_TARGET, cargoPackageTestInputs, cargoTestPackageTargetName, exceptionalTestFilter, listCargoWorkspacePackages, nextestConfigRelPath, } from './cargo-workspace.js';
10
10
  import { CARGO_CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET, CARGO_FETCH_COMMAND, CARGO_FETCH_TARGET, CARGO_FROZEN_PREFIX, CARGO_LINT_CLIPPY_COMMAND, cargoFrozen, } from './cross-check-policy.js';
11
11
  import { PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
12
12
  export { CARGO_TEST_COMPILE_TARGET };
@@ -76,6 +76,16 @@ const CARGO_INPUTS = [
76
76
  '!{projectRoot}/**/target/**',
77
77
  ];
78
78
  const CARGO_OUTPUT_INPUTS = [...CARGO_INPUTS, '{projectRoot}/package.json', '{workspaceRoot}/bun.lock'];
79
+ const REPO_ROOT_CARGO_OUTPUT_INPUTS = [
80
+ '{workspaceRoot}/**/*.rs',
81
+ '{workspaceRoot}/**/Cargo.toml',
82
+ '{workspaceRoot}/Cargo.lock',
83
+ '{workspaceRoot}/**/.cargo/config.toml',
84
+ '{workspaceRoot}/scripts/*.sh',
85
+ '!{workspaceRoot}/**/target/**',
86
+ '{projectRoot}/package.json',
87
+ '{workspaceRoot}/bun.lock',
88
+ ];
79
89
  const NAPI_INPUTS = CARGO_OUTPUT_INPUTS;
80
90
  const NAPI_TARGET_CONVENTIONS = {
81
91
  'aarch64-apple-darwin': {
@@ -118,21 +128,25 @@ const NAPI_TOOLCHAIN_TARGET_PREFIX = 'napi-toolchain-';
118
128
  export function napiToolchainTargetName(convention) {
119
129
  return `${NAPI_TOOLCHAIN_TARGET_PREFIX}${convention.architecture}-${convention.targetFamily}`;
120
130
  }
121
- function createCargoWasmTarget(projectRoot, config) {
122
- const cargoTargetDirectory = posix.join(posix.dirname(config.manifestPath), 'target/cargo-wasm');
131
+ function createCargoWasmTarget(projectRoot, config, repoRooted) {
132
+ const cargoTargetDirectory = repoRooted
133
+ ? 'target/cargo-wasm'
134
+ : posix.join(posix.dirname(config.manifestPath), 'target/cargo-wasm');
123
135
  const wasmInput = `${cargoTargetDirectory}/wasm32-unknown-unknown/release/${config.libraryName}.wasm`;
136
+ const outputDirectory = repoRooted ? posix.join(projectRoot, config.outputDirectory) : config.outputDirectory;
137
+ const cargoSelection = repoRooted ? `-p ${config.cargoPackage}` : `--manifest-path ${config.manifestPath}`;
124
138
  return {
125
139
  executor: 'nx:run-commands',
126
140
  cache: true,
127
141
  dependsOn: ['^build'],
128
- inputs: CARGO_OUTPUT_INPUTS,
142
+ inputs: repoRooted ? REPO_ROOT_CARGO_OUTPUT_INPUTS : CARGO_OUTPUT_INPUTS,
129
143
  outputs: [`{projectRoot}/${config.outputDirectory}`],
130
144
  options: {
131
145
  commands: [
132
- cargoFrozen(`build --release --target wasm32-unknown-unknown --target-dir ${cargoTargetDirectory} --manifest-path ${config.manifestPath}`),
133
- ...config.targets.map(({ bindgenTarget, outputName }) => `wasm-bindgen --target ${bindgenTarget} --out-dir ${config.outputDirectory}/${outputName} ${wasmInput}`),
146
+ cargoFrozen(`build --release --target wasm32-unknown-unknown --target-dir ${cargoTargetDirectory} ${cargoSelection}`),
147
+ ...config.targets.map(({ bindgenTarget, outputName }) => `wasm-bindgen --target ${bindgenTarget} --out-dir ${outputDirectory}/${outputName} ${wasmInput}`),
134
148
  ],
135
- cwd: projectRoot,
149
+ cwd: repoRooted ? '.' : projectRoot,
136
150
  parallel: false,
137
151
  },
138
152
  };
@@ -205,11 +219,16 @@ const PLUGIN_NEXTEST_CONFIG = fileURLToPath(new URL('../nextest.toml', import.me
205
219
  * depending on how the hash happened to fall.
206
220
  *
207
221
  * The two filtersets are exact complements, so their union is the crate whatever
208
- * either one matches; an empty exception set (every real-APFS test is
209
- * `cfg(target_os = "macos")`, so on Linux there are none) costs coverage
210
- * nothing, which is why that target may pass having run zero tests. It cannot
211
- * hide a lost test — only a pin that stopped matching, whose members then fall
212
- * into the shards.
222
+ * either one matches. Every piece uses `--no-tests=pass`: a valid workspace
223
+ * member may expose no nextest tests, a small suite can leave a declared hash
224
+ * shard empty, and platform-specific exceptions may not exist on this host.
225
+ * Manifest discovery proves the package exists and generates the selector from
226
+ * its Cargo name, so accepting an empty run cannot hide a misspelled package.
227
+ *
228
+ * The trade is explicit: a generated target cannot distinguish an intentionally
229
+ * test-less crate from one whose entire suite stopped matching, so both pass.
230
+ * Detecting that regression requires a separate coverage policy rather than
231
+ * making valid empty crates and shards fail execution.
213
232
  *
214
233
  * Pieces chain rather than fan out, like the crates do: cargo flocks one
215
234
  * `target/`, and chaining keeps even the pinned group from overlapping the
@@ -237,7 +256,7 @@ async function addPerPackageCargoTestTargets(targets, projectRoot, workspaceRoot
237
256
  inputs,
238
257
  dependsOn: [previous],
239
258
  options: {
240
- command: cargoFrozen(`nextest run --workspace -E '${selector}'${extra} --user-config-file none --config-file ${configFile}`),
259
+ command: cargoFrozen(`nextest run --workspace -E '${selector}'${extra} --no-tests=pass --user-config-file none --config-file ${configFile}`),
241
260
  cwd: projectRoot,
242
261
  timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
243
262
  killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
@@ -252,7 +271,7 @@ async function addPerPackageCargoTestTargets(targets, projectRoot, workspaceRoot
252
271
  addTarget(sharded ? `shard${index}` : undefined, shardable, sharded ? ` --partition hash:${index}/${pkg.testShards}` : '');
253
272
  }
254
273
  if (pin !== null) {
255
- addTarget(CARGO_TEST_EXCEPTIONS_SUFFIX, `package(${pkg.name}) and (${pin})`, ' --no-tests=pass');
274
+ addTarget(CARGO_TEST_EXCEPTIONS_SUFFIX, `package(${pkg.name}) and (${pin})`, '');
256
275
  }
257
276
  }
258
277
  return packageTargetNames;
@@ -261,17 +280,22 @@ function createNodesHandler(hostPlatform) {
261
280
  return async (projectConfigurationFiles, _options, context) => {
262
281
  const results = [];
263
282
  const errors = [];
283
+ const repoRootCargoWorkspace = await resolveRepoRootCargoWorkspace(projectConfigurationFiles, context.workspaceRoot);
264
284
  await Promise.all(projectConfigurationFiles.map(async (packageJsonPath) => {
265
285
  try {
266
- if (isManagedPackageJsonSource(packageJsonPath)) {
286
+ if (isManagedPackageJsonSource(packageJsonPath) || isBuildOutputPackageJson(packageJsonPath)) {
267
287
  // smoo monorepo managed raw/templates are source copies, not projects.
268
288
  // Dogfood trees symlink live paths here; discovering both doubles names.
289
+ // A package.json a build wrote (napi's platform dirs, dist, cargo's
290
+ // target, a package cache) is an artifact, never a project: inferring
291
+ // one races every task that rebuilds the graph against the build that
292
+ // is writing it, and a name collision drops the real project.
269
293
  results.push([packageJsonPath, {}]);
270
294
  return;
271
295
  }
272
296
  results.push([
273
297
  packageJsonPath,
274
- await createProjectTargets(packageJsonPath, context.workspaceRoot, hostPlatform),
298
+ await createProjectTargets(packageJsonPath, context.workspaceRoot, hostPlatform, repoRootCargoWorkspace),
275
299
  ]);
276
300
  }
277
301
  catch (error) {
@@ -295,25 +319,63 @@ function isManagedPackageJsonSource(packageJsonPath) {
295
319
  const normalized = packageJsonPath.replaceAll('\\', '/');
296
320
  return normalized.includes('/managed/raw/') || normalized.includes('/managed/templates/');
297
321
  }
322
+ /** Directories only builds write into; a package.json found under one is an output. */
323
+ const BUILD_OUTPUT_SEGMENTS = ['/node_modules/', '/dist/', '/target/', '/.cache/', '/.nx/'];
324
+ function isBuildOutputPackageJson(packageJsonPath) {
325
+ const normalized = `/${packageJsonPath.replaceAll('\\', '/')}`;
326
+ return BUILD_OUTPUT_SEGMENTS.some((segment) => normalized.includes(segment));
327
+ }
298
328
  export default { createNodesV2 };
299
- async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform) {
329
+ function packageBinOutputs(packageJson, packageJsonPath) {
330
+ if (packageJson.bin === undefined) {
331
+ return [];
332
+ }
333
+ if (typeof packageJson.bin === 'string') {
334
+ if (packageJson.bin.length === 0) {
335
+ throw new Error(`${packageJsonPath}: bin must not be empty`);
336
+ }
337
+ return [packageJson.bin];
338
+ }
339
+ if (!isRecord(packageJson.bin)) {
340
+ throw new Error(`${packageJsonPath}: bin must be a string or an object of executable paths`);
341
+ }
342
+ const outputs = new Set();
343
+ for (const [name, output] of Object.entries(packageJson.bin)) {
344
+ if (typeof output !== 'string' || output.length === 0) {
345
+ throw new Error(`${packageJsonPath}: bin.${name} must be a non-empty executable path`);
346
+ }
347
+ outputs.add(output);
348
+ }
349
+ return [...outputs];
350
+ }
351
+ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform, repoRootCargoWorkspace) {
300
352
  const projectRoot = dirname(packageJsonPath);
301
353
  const absoluteProjectRoot = join(workspaceRoot, projectRoot);
302
354
  const packageJson = await readPackageJson(join(workspaceRoot, packageJsonPath));
355
+ const projectName = packageJson.nx?.name ?? packageJson.name;
356
+ if (typeof projectName !== 'string' || projectName.length === 0) {
357
+ throw new Error(`${packageJsonPath} must declare a non-empty package or nx project name`);
358
+ }
303
359
  const targets = {};
304
360
  const validationTargets = [];
305
361
  const libTsconfigPath = join(absoluteProjectRoot, 'tsconfig.lib.json');
306
362
  const hasLibTsconfig = existsSync(libTsconfigPath);
307
363
  const cargoTomlPath = join(absoluteProjectRoot, 'Cargo.toml');
308
364
  const isCargoWorkspace = existsSync(cargoTomlPath) && CARGO_WORKSPACE_PATTERN.test(await readFile(cargoTomlPath, 'utf-8'));
309
- const napiConfig = resolveNapiConfig(packageJson, packageJsonPath, absoluteProjectRoot, isCargoWorkspace);
365
+ const repoRootPackagePlans = repoRootCargoWorkspace?.packages.filter((plan) => plan.package.projectRoot === projectRoot) ?? [];
366
+ const isRepoRootWorkspaceRoot = repoRootCargoWorkspace !== null && projectRoot === '.';
367
+ const isRepoRootCargoProject = isRepoRootWorkspaceRoot || repoRootPackagePlans.length > 0;
368
+ const repoRootPackages = repoRootPackagePlans.map((plan) => plan.package);
369
+ const isRepoRootedCargoProject = isRepoRootCargoProject && (!isCargoWorkspace || isRepoRootWorkspaceRoot);
370
+ const napiConfig = resolveNapiConfig(packageJson, packageJsonPath, absoluteProjectRoot, isCargoWorkspace, repoRootPackages);
310
371
  const declaredTargets = packageJson.nx?.targets ?? {};
311
- const cargoWasmConfig = await resolveCargoWasmConfig(absoluteProjectRoot, packageJsonPath);
372
+ const cargoWasmConfig = await resolveCargoWasmConfig(absoluteProjectRoot, packageJsonPath, workspaceRoot, repoRootPackages);
312
373
  const inferCargoWasm = cargoWasmConfig !== null && !('cargo-wasm' in declaredTargets);
313
374
  const packageLocalBuildOutputs = classifyPackageLocalBuildOutputs(packageJson);
314
375
  const hasOrdinaryBuildOutputTarget = hasLibTsconfig || napiConfig !== null || cargoWasmConfig !== null || packageLocalBuildOutputs.ordinary;
315
376
  const hasAnyBuildOutputTarget = hasOrdinaryBuildOutputTarget || packageLocalBuildOutputs.platform;
316
377
  if (hasLibTsconfig) {
378
+ const executableOutputs = packageBinOutputs(packageJson, packageJsonPath);
317
379
  // Dependency packages may publish bundled entries that raw tsc does not produce.
318
380
  // Build every JavaScript output lane before resolving package exports, without pulling
319
381
  // unrelated Wasm, N-API, native, or web outputs onto the compiler critical path.
@@ -329,6 +391,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
329
391
  outputs: inferTypescriptOutputs(libTsconfigPath, packageJsonPath),
330
392
  dependsOn: ['^*-js', ...(cargoWasmConfig ? ['cargo-wasm'] : [])],
331
393
  options: {
394
+ ...(executableOutputs.length > 0 ? { executableOutputs } : {}),
332
395
  tsConfig: 'tsconfig.lib.json',
333
396
  cwd: projectRoot,
334
397
  },
@@ -383,10 +446,10 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
383
446
  validationTargets.push('typecheck');
384
447
  }
385
448
  if (inferCargoWasm && cargoWasmConfig) {
386
- targets['cargo-wasm'] = createCargoWasmTarget(projectRoot, cargoWasmConfig);
449
+ targets['cargo-wasm'] = createCargoWasmTarget(projectRoot, cargoWasmConfig, isRepoRootedCargoProject);
387
450
  }
388
451
  if (napiConfig) {
389
- Object.assign(targets, createNapiTargets(projectRoot, napiConfig, hostPlatform));
452
+ Object.assign(targets, createNapiTargets(projectRoot, napiConfig, hostPlatform, isRepoRootedCargoProject));
390
453
  if (!('napi-test' in (packageJson.nx?.targets ?? {})) &&
391
454
  existsSync(join(absoluteProjectRoot, 'src/native.test.ts'))) {
392
455
  targets['napi-test'] = createNapiTestTarget(projectRoot, existsSync(join(absoluteProjectRoot, 'bunfig.napi-test.toml')));
@@ -438,20 +501,30 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
438
501
  // all-or-nothing, because for those the package decides whether the target
439
502
  // EXISTS — a packaging decision for output families, the bounded-test policy's
440
503
  // rewrite for `test` — so there is no inferred base to partially override.
441
- if (isCargoWorkspace) {
442
- targets[CARGO_TEST_COMPILE_TARGET] = createCargoTestCompileTarget(projectRoot);
443
- const packageTargetNames = await addPerPackageCargoTestTargets(targets, projectRoot, workspaceRoot, absoluteProjectRoot);
504
+ const ownsCargoWorkspaceTargets = isCargoWorkspace || isRepoRootWorkspaceRoot;
505
+ if (ownsCargoWorkspaceTargets) {
506
+ const cargoWorkspaceRoot = isRepoRootWorkspaceRoot ? '.' : projectRoot;
507
+ targets[CARGO_TEST_COMPILE_TARGET] = createCargoTestCompileTarget(cargoWorkspaceRoot);
508
+ const packageTargetNames = isRepoRootWorkspaceRoot
509
+ ? await addRepoRootCargoTestTargets(targets, projectName, projectRoot, workspaceRoot, repoRootCargoWorkspace)
510
+ : await addPerPackageCargoTestTargets(targets, projectRoot, workspaceRoot, absoluteProjectRoot);
511
+ const aggregateDependencies = isRepoRootWorkspaceRoot
512
+ ? repoRootCargoWorkspace.packages.flatMap((plan) => plan.pieces.map((piece) => cargoTargetDependency(projectName, {
513
+ projectName: plan.package.projectName,
514
+ targetName: piece.targetName,
515
+ })))
516
+ : packageTargetNames;
444
517
  targets[CARGO_TEST_TARGET] =
445
- packageTargetNames.length > 0
446
- ? { executor: 'nx:noop', cache: true, dependsOn: packageTargetNames }
447
- : createCargoTestTarget(projectRoot);
518
+ aggregateDependencies.length > 0
519
+ ? { executor: 'nx:noop', cache: true, dependsOn: aggregateDependencies }
520
+ : createCargoTestTarget(cargoWorkspaceRoot);
448
521
  targets['cargo-lint'] = {
449
522
  executor: 'nx:run-commands',
450
523
  cache: true,
451
524
  inputs: CARGO_INPUTS,
452
525
  options: {
453
526
  commands: ['cargo fmt --all --check', CARGO_LINT_CLIPPY_COMMAND],
454
- cwd: projectRoot,
527
+ cwd: cargoWorkspaceRoot,
455
528
  parallel: false,
456
529
  },
457
530
  };
@@ -464,7 +537,9 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
464
537
  // governs targets that PRODUCE artifacts, where "does this package ship this
465
538
  // artifact" is a packaging decision no crate manifest can answer. This target
466
539
  // emits nothing — clippy type-checks and discards — so it belongs with
467
- // cargo-lint and cargo-test on the inferred validation side.
540
+ // cargo-lint and cargo-test on the inferred validation side. Repository-root
541
+ // workspaces own it once at the root because `--workspace` already checks
542
+ // every member.
468
543
  //
469
544
  // The discriminator for "has cross-platform Rust" is deliberately the same
470
545
  // `[workspace]` Cargo.toml that already grants cargo-lint, NOT a scan of
@@ -487,7 +562,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
487
562
  inputs: CARGO_INPUTS,
488
563
  options: {
489
564
  command: CARGO_CROSS_LINT_COMMAND,
490
- cwd: projectRoot,
565
+ cwd: cargoWorkspaceRoot,
491
566
  },
492
567
  };
493
568
  if (!targets.test && !('test' in declaredTargets) && typeof packageJson.scripts?.test !== 'string') {
@@ -502,12 +577,12 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
502
577
  targets.mutation = {
503
578
  executor: 'nx:run-commands',
504
579
  cache: false,
505
- options: { command: cargoFrozen('mutants --workspace'), cwd: projectRoot },
580
+ options: { command: cargoFrozen('mutants --workspace'), cwd: cargoWorkspaceRoot },
506
581
  };
507
582
  targets.bench = {
508
583
  executor: 'nx:run-commands',
509
584
  cache: false,
510
- options: { command: cargoFrozen('bench --workspace'), cwd: projectRoot },
585
+ options: { command: cargoFrozen('bench --workspace'), cwd: cargoWorkspaceRoot },
511
586
  };
512
587
  // Target-dir GC. Cargo never removes superseded artifacts, so a busy
513
588
  // workspace grows tens of GB of stale variants no fingerprint references;
@@ -517,9 +592,24 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
517
592
  targets['cargo-sweep'] = {
518
593
  executor: 'nx:run-commands',
519
594
  cache: false,
520
- options: { command: 'cargo sweep --time 7', cwd: projectRoot },
595
+ options: { command: 'cargo sweep --time 7', cwd: cargoWorkspaceRoot },
521
596
  };
522
597
  }
598
+ if (!isCargoWorkspace && !isRepoRootWorkspaceRoot && repoRootPackagePlans.length > 0 && repoRootCargoWorkspace) {
599
+ const packageTargetNames = await addRepoRootCargoTestTargets(targets, projectName, projectRoot, workspaceRoot, repoRootCargoWorkspace);
600
+ targets[CARGO_TEST_TARGET] = {
601
+ executor: 'nx:noop',
602
+ cache: true,
603
+ dependsOn: packageTargetNames,
604
+ };
605
+ if (!targets.test && !('test' in declaredTargets) && typeof packageJson.scripts?.test !== 'string') {
606
+ targets.test = {
607
+ executor: 'nx:noop',
608
+ cache: true,
609
+ dependsOn: [CARGO_TEST_TARGET],
610
+ };
611
+ }
612
+ }
523
613
  // Every `cargoFrozen` command needs a registry cache holding the whole locked
524
614
  // graph, and offline cargo checks that at RESOLUTION — so a dev-dependency no
525
615
  // build ever downloaded takes down `cargo --frozen build` just as surely as
@@ -534,6 +624,8 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
534
624
  // frozen target added later is covered without anyone remembering to. The edge
535
625
  // goes on EVERY frozen target, not just the head of the serialization chain,
536
626
  // so re-routing that chain cannot strip a surviving target's precondition.
627
+ // Package-rooted workspaces fetch beside their package.json; members of a
628
+ // repository-root workspace all depend on the root project's one fetch.
537
629
  //
538
630
  // A package that REPLACES one of these `dependsOn` lists drops the edge with
539
631
  // it (see the merge rules above) and gets its cold-cache failure back; `"..."`
@@ -542,9 +634,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
542
634
  if (isCargoWorkspace) {
543
635
  frozenCargoManifests.add('Cargo.toml');
544
636
  }
545
- if (inferCargoWasm && cargoWasmConfig) {
546
- // A wasm-bindgen crate can sit in a nested Cargo workspace the project root
547
- // is not a member of, so its graph is a second fetch, not the same one.
637
+ if (inferCargoWasm && cargoWasmConfig && !isRepoRootedCargoProject) {
548
638
  frozenCargoManifests.add(cargoWasmConfig.manifestPath);
549
639
  }
550
640
  if (frozenCargoManifests.size > 0) {
@@ -561,7 +651,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
561
651
  .map((manifestPath) => manifestPath === 'Cargo.toml'
562
652
  ? CARGO_FETCH_COMMAND
563
653
  : `${CARGO_FETCH_COMMAND} --manifest-path ${manifestPath}`),
564
- cwd: projectRoot,
654
+ cwd: isRepoRootWorkspaceRoot ? '.' : projectRoot,
565
655
  // Two fetches into one CARGO_HOME contend on its package-cache flock;
566
656
  // serializing here spends the wait in Nx instead of inside cargo.
567
657
  parallel: false,
@@ -577,32 +667,66 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
577
667
  typeof command === 'string' ? command : '',
578
668
  ...(Array.isArray(commands) ? commands.filter((entry) => typeof entry === 'string') : []),
579
669
  ].join('\n');
580
- if (!text.includes(CARGO_FROZEN_PREFIX)) {
581
- continue;
670
+ if (text.includes(CARGO_FROZEN_PREFIX)) {
671
+ target.dependsOn = [CARGO_FETCH_TARGET, ...(target.dependsOn ?? [])];
582
672
  }
583
- const dependsOn = target.dependsOn ?? [];
584
- if (!dependsOn.includes(CARGO_FETCH_TARGET)) {
585
- target.dependsOn = [CARGO_FETCH_TARGET, ...dependsOn];
673
+ }
674
+ }
675
+ else if (isRepoRootedCargoProject && repoRootCargoWorkspace) {
676
+ const rootFetch = cargoTargetDependency(projectName, {
677
+ projectName: repoRootCargoWorkspace.rootProjectName,
678
+ targetName: CARGO_FETCH_TARGET,
679
+ });
680
+ for (const target of Object.values(targets)) {
681
+ const command = target.options?.command;
682
+ const commands = target.options?.commands;
683
+ const text = [
684
+ typeof command === 'string' ? command : '',
685
+ ...(Array.isArray(commands) ? commands.filter((entry) => typeof entry === 'string') : []),
686
+ ].join('\n');
687
+ if (text.includes(CARGO_FROZEN_PREFIX)) {
688
+ target.dependsOn = [rootFetch, ...(target.dependsOn ?? [])];
586
689
  }
587
690
  }
588
691
  }
589
- // Cargo flocks the package's default `target/`. Writers that share it must
590
- // not be Nx siblings. Clippy is not in this set: it has its own --target-dir.
692
+ // Cargo flocks the workspace's default target/. Keep every writer out of the
693
+ // bounded test window by placing N-API debug builds on the same serialized
694
+ // chain as the root compile and per-crate runners.
695
+ const cargoTestCompileDependency = targets[CARGO_TEST_COMPILE_TARGET]
696
+ ? CARGO_TEST_COMPILE_TARGET
697
+ : isRepoRootCargoProject && repoRootCargoWorkspace
698
+ ? cargoTargetDependency(projectName, {
699
+ projectName: repoRootCargoWorkspace.rootProjectName,
700
+ targetName: CARGO_TEST_COMPILE_TARGET,
701
+ })
702
+ : null;
591
703
  const napiDebug = targets['napi-debug'];
592
- if (napiDebug && targets[CARGO_TEST_COMPILE_TARGET]) {
704
+ if (napiDebug && cargoTestCompileDependency) {
593
705
  const dependsOn = napiDebug.dependsOn ?? [];
594
- if (!dependsOn.includes(CARGO_TEST_COMPILE_TARGET)) {
595
- napiDebug.dependsOn = [...dependsOn, CARGO_TEST_COMPILE_TARGET];
706
+ if (!hasCargoTargetDependency(dependsOn, cargoTestCompileDependency)) {
707
+ napiDebug.dependsOn = [...dependsOn, cargoTestCompileDependency];
708
+ }
709
+ }
710
+ if (napiDebug && isRepoRootedCargoProject) {
711
+ const firstCargoTest = repoRootPackagePlans.flatMap((plan) => plan.pieces)[0];
712
+ const firstTarget = firstCargoTest ? targets[firstCargoTest.targetName] : undefined;
713
+ if (firstCargoTest && firstTarget) {
714
+ const previous = cargoTargetDependency(projectName, firstCargoTest.previous);
715
+ const debugDependencies = napiDebug.dependsOn ?? [];
716
+ if (!hasCargoTargetDependency(debugDependencies, previous)) {
717
+ napiDebug.dependsOn = [...debugDependencies, previous];
718
+ }
719
+ firstTarget.dependsOn = (firstTarget.dependsOn ?? []).map((dependency) => hasCargoTargetDependency([dependency], previous) ? 'napi-debug' : dependency);
596
720
  }
597
721
  }
598
- if (napiDebug) {
722
+ else if (napiDebug) {
599
723
  for (const [name, target] of Object.entries(targets)) {
600
724
  if (!name.startsWith('cargo-test-') || name === CARGO_TEST_COMPILE_TARGET) {
601
725
  continue;
602
726
  }
603
727
  const dependsOn = target.dependsOn ?? [];
604
728
  if (dependsOn.includes(CARGO_TEST_COMPILE_TARGET) && !dependsOn.includes('napi-debug')) {
605
- target.dependsOn = dependsOn.map((dep) => (dep === CARGO_TEST_COMPILE_TARGET ? 'napi-debug' : dep));
729
+ target.dependsOn = dependsOn.map((dependency) => dependency === CARGO_TEST_COMPILE_TARGET ? 'napi-debug' : dependency);
606
730
  }
607
731
  }
608
732
  const cargoTest = targets[CARGO_TEST_TARGET];
@@ -616,8 +740,8 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
616
740
  }
617
741
  }
618
742
  // `build` lists cargo-test-compile beside the host's platform binaries, and
619
- // every one of those is a `napi build` — another cargo writer on the package's
620
- // default `target/`, which cargo flocks.
743
+ // every one of those is a `napi build` — another cargo writer on the
744
+ // workspace's default `target/`, which cargo flocks.
621
745
  //
622
746
  // Only `cargo-napi` gets the ordering edge. A platform-suffixed target may NOT
623
747
  // have one: `validatePlatformTargetDependencies` (package-target-policy.ts:674)
@@ -636,10 +760,10 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
636
760
  // targets, so the wait is not charged against a test budget.
637
761
  const cargoWriterNames = hostPlatformTargetNames([...Object.keys(declaredTargets), ...Object.keys(targets)], hostPlatform);
638
762
  const cargoNapi = targets['cargo-napi'];
639
- if (cargoNapi && targets[CARGO_TEST_COMPILE_TARGET]) {
763
+ if (cargoNapi && cargoTestCompileDependency) {
640
764
  const dependsOn = cargoNapi.dependsOn ?? [];
641
- if (!dependsOn.includes(CARGO_TEST_COMPILE_TARGET)) {
642
- cargoNapi.dependsOn = [...dependsOn, CARGO_TEST_COMPILE_TARGET];
765
+ if (!hasCargoTargetDependency(dependsOn, cargoTestCompileDependency)) {
766
+ cargoNapi.dependsOn = [...dependsOn, cargoTestCompileDependency];
643
767
  }
644
768
  }
645
769
  // No `outputs`, deliberately: this aggregate runs no command, so every file
@@ -666,7 +790,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
666
790
  // cacheable, while every RUNNER is a bounded-exec target reached only
667
791
  // through the `test` aggregate. That split is what keeps a cold cargo
668
792
  // workspace's compile time out of the bounded test window.
669
- ...(targets[CARGO_TEST_COMPILE_TARGET] ? [CARGO_TEST_COMPILE_TARGET] : []),
793
+ ...(cargoTestCompileDependency ? [cargoTestCompileDependency] : []),
670
794
  ...buildOutputTargetNames([...Object.keys(declaredTargets), ...Object.keys(targets)]),
671
795
  ...cargoWriterNames,
672
796
  ]),
@@ -696,10 +820,6 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
696
820
  dependsOn: validationTargets,
697
821
  };
698
822
  }
699
- const projectName = packageJson.nx?.name ?? packageJson.name;
700
- if (typeof projectName !== 'string' || projectName.length === 0) {
701
- throw new Error(`${packageJsonPath} must declare a non-empty package or nx project name`);
702
- }
703
823
  return {
704
824
  projects: {
705
825
  [projectRoot]: { name: projectName, targets },
@@ -714,23 +834,26 @@ const WASM_BINDGEN_OUTPUT_NAMES = {
714
834
  nodejs: 'node',
715
835
  web: 'web',
716
836
  };
717
- async function resolveCargoWasmConfig(absoluteProjectRoot, packageJsonPath) {
718
- const manifestPaths = ['Cargo.toml'];
719
- const cratesDirectory = join(absoluteProjectRoot, 'crates');
720
- if (existsSync(cratesDirectory)) {
721
- const crateEntries = await readdir(cratesDirectory, { withFileTypes: true });
722
- for (const entry of crateEntries.sort((left, right) => left.name.localeCompare(right.name))) {
723
- if (entry.isDirectory()) {
724
- const manifestPath = posix.join('crates', entry.name, 'Cargo.toml');
725
- if (existsSync(join(absoluteProjectRoot, manifestPath))) {
726
- manifestPaths.push(manifestPath);
837
+ async function resolveCargoWasmConfig(absoluteProjectRoot, packageJsonPath, workspaceRoot, repoRootPackages) {
838
+ const manifestPaths = repoRootPackages.map((pkg) => posix.join(pkg.dir, 'Cargo.toml'));
839
+ if (manifestPaths.length === 0) {
840
+ manifestPaths.push('Cargo.toml');
841
+ const cratesDirectory = join(absoluteProjectRoot, 'crates');
842
+ if (existsSync(cratesDirectory)) {
843
+ const crateEntries = await readdir(cratesDirectory, { withFileTypes: true });
844
+ for (const entry of crateEntries.sort((left, right) => left.name.localeCompare(right.name))) {
845
+ if (entry.isDirectory()) {
846
+ const manifestPath = posix.join('crates', entry.name, 'Cargo.toml');
847
+ if (existsSync(join(absoluteProjectRoot, manifestPath))) {
848
+ manifestPaths.push(manifestPath);
849
+ }
727
850
  }
728
851
  }
729
852
  }
730
853
  }
731
854
  const resolved = [];
732
855
  for (const manifestPath of manifestPaths) {
733
- const absoluteManifestPath = join(absoluteProjectRoot, manifestPath);
856
+ const absoluteManifestPath = repoRootPackages.length > 0 ? join(workspaceRoot, manifestPath) : join(absoluteProjectRoot, manifestPath);
734
857
  if (!existsSync(absoluteManifestPath)) {
735
858
  continue;
736
859
  }
@@ -780,7 +903,13 @@ async function resolveCargoWasmConfig(absoluteProjectRoot, packageJsonPath) {
780
903
  outputDirectory.startsWith('/')) {
781
904
  throw new Error(`${packageJsonPath}: ${manifestPath} smoothbricks.wasm-bindgen.out-dir must stay inside the project`);
782
905
  }
783
- resolved.push({ libraryName: rawLibraryName, manifestPath, outputDirectory, targets });
906
+ resolved.push({
907
+ cargoPackage: packageName,
908
+ libraryName: rawLibraryName,
909
+ manifestPath,
910
+ outputDirectory,
911
+ targets,
912
+ });
784
913
  }
785
914
  if (resolved.length > 1) {
786
915
  throw new Error(`${packageJsonPath}: only one Cargo crate may declare smoothbricks.wasm-bindgen metadata`);
@@ -800,12 +929,12 @@ function inferTypescriptOutputs(tsconfigPath, packageJsonPath) {
800
929
  }
801
930
  return [`{projectRoot}/${normalized}`];
802
931
  }
803
- function resolveNapiConfig(packageJson, packageJsonPath, absoluteProjectRoot, isCargoWorkspace) {
932
+ function resolveNapiConfig(packageJson, packageJsonPath, absoluteProjectRoot, isCargoWorkspace, repoRootPackages) {
804
933
  if (!packageJson.napi) {
805
934
  return null;
806
935
  }
807
- if (!isCargoWorkspace) {
808
- throw new Error(`${packageJsonPath}: napi target inference requires a Cargo workspace beside package.json`);
936
+ if (!isCargoWorkspace && repoRootPackages.length === 0) {
937
+ throw new Error(`${packageJsonPath}: napi target inference requires a Cargo workspace containing this project`);
809
938
  }
810
939
  const binaryName = packageJson.napi.binaryName;
811
940
  if (typeof binaryName !== 'string' || !/^[A-Za-z0-9_-]+$/.test(binaryName)) {
@@ -824,14 +953,21 @@ function resolveNapiConfig(packageJson, packageJsonPath, absoluteProjectRoot, is
824
953
  }
825
954
  }
826
955
  const cargoPackage = `${binaryName}-napi`;
827
- const manifestPath = `crates/${cargoPackage}/Cargo.toml`;
828
- if (!existsSync(join(absoluteProjectRoot, manifestPath))) {
956
+ const rootMember = repoRootPackages.find((pkg) => pkg.name === cargoPackage);
957
+ const manifestPath = rootMember ? posix.join(rootMember.dir, 'Cargo.toml') : `crates/${cargoPackage}/Cargo.toml`;
958
+ const absoluteManifestPath = rootMember
959
+ ? join(absoluteProjectRoot, relative(dirname(packageJsonPath), manifestPath))
960
+ : join(absoluteProjectRoot, manifestPath);
961
+ if (!existsSync(absoluteManifestPath)) {
829
962
  throw new Error(`${packageJsonPath}: inferred N-API crate is missing at ${manifestPath}`);
830
963
  }
831
964
  return { binaryName, cargoPackage, manifestPath, targets };
832
965
  }
833
- function createNapiTargets(projectRoot, config, hostPlatform) {
966
+ function createNapiTargets(projectRoot, config, hostPlatform, repoRooted) {
834
967
  const commonCommand = `--manifest-path ${config.manifestPath} --package ${config.cargoPackage}`;
968
+ const cargoInputs = repoRooted ? REPO_ROOT_CARGO_OUTPUT_INPUTS : NAPI_INPUTS;
969
+ const cargoCwd = repoRooted ? '.' : projectRoot;
970
+ const outputPath = (projectOutput) => (repoRooted ? posix.join(projectRoot, projectOutput) : projectOutput);
835
971
  const hostPlatformTargetName = hostPlatform === null ? null : `napi-${hostPlatform.architecture}-${hostPlatform.targetFamily}`;
836
972
  let nativeHostTargetName = null;
837
973
  if (hostPlatformTargetName !== null) {
@@ -857,11 +993,11 @@ function createNapiTargets(projectRoot, config, hostPlatform) {
857
993
  executor: 'nx:run-commands',
858
994
  cache: true,
859
995
  dependsOn: ['^build'],
860
- inputs: NAPI_INPUTS,
996
+ inputs: cargoInputs,
861
997
  outputs: ['{projectRoot}/.cache/native-debug'],
862
998
  options: {
863
- cwd: projectRoot,
864
- command: `napi build --platform --no-js --dts ${config.binaryName}.napi.d.ts ${commonCommand} --output-dir .cache/native-debug`,
999
+ cwd: cargoCwd,
1000
+ command: `napi build --platform --no-js --dts ${config.binaryName}.napi.d.ts ${commonCommand} --output-dir ${outputPath('.cache/native-debug')}`,
865
1001
  ...(hostCompilerEnv ? { env: hostCompilerEnv } : {}),
866
1002
  },
867
1003
  };
@@ -874,11 +1010,11 @@ function createNapiTargets(projectRoot, config, hostPlatform) {
874
1010
  executor: 'nx:run-commands',
875
1011
  cache: true,
876
1012
  dependsOn: ['^build'],
877
- inputs: NAPI_INPUTS,
1013
+ inputs: cargoInputs,
878
1014
  outputs: ['{projectRoot}/dist/native/host'],
879
1015
  options: {
880
- cwd: projectRoot,
881
- command: `napi build --release --platform --no-js --dts ${config.binaryName}.napi.d.ts ${commonCommand} --output-dir dist/native/host`,
1016
+ cwd: cargoCwd,
1017
+ command: `napi build --release --platform --no-js --dts ${config.binaryName}.napi.d.ts ${commonCommand} --output-dir ${outputPath('dist/native/host')}`,
882
1018
  ...(hostCompilerEnv ? { env: hostCompilerEnv } : {}),
883
1019
  },
884
1020
  };
@@ -916,11 +1052,11 @@ function createNapiTargets(projectRoot, config, hostPlatform) {
916
1052
  executor: 'nx:run-commands',
917
1053
  cache: true,
918
1054
  ...(useNapiCross ? { dependsOn: [napiToolchainTargetName(convention)] } : {}),
919
- inputs: NAPI_INPUTS,
1055
+ inputs: cargoInputs,
920
1056
  outputs: [`{projectRoot}/${outputDirectory}`],
921
1057
  options: {
922
- cwd: projectRoot,
923
- command: `napi build --release --platform --no-js --dts ${config.binaryName}.${convention.outputName}.d.ts --target ${triple}${crossFlag} ${commonCommand} --output-dir ${outputDirectory}`,
1058
+ cwd: cargoCwd,
1059
+ command: `napi build --release --platform --no-js --dts ${config.binaryName}.${convention.outputName}.d.ts --target ${triple}${crossFlag} ${commonCommand} --output-dir ${outputPath(outputDirectory)}`,
924
1060
  // Genuine Linux cross-compiles use Clang plus napi-rs's downloaded
925
1061
  // GNU sysroot. A native Linux target uses Nix's cc wrapper so C build
926
1062
  // scripts resolve the host libc headers instead.
@@ -963,6 +1099,7 @@ async function readPackageJson(packageJsonPath) {
963
1099
  }
964
1100
  const rawNx = isRecord(parsed.nx) ? parsed.nx : undefined;
965
1101
  return {
1102
+ ...('bin' in parsed ? { bin: parsed.bin } : {}),
966
1103
  ...(typeof parsed.name === 'string' ? { name: parsed.name } : {}),
967
1104
  ...(isRecord(parsed.napi) ? { napi: parsed.napi } : {}),
968
1105
  ...(isRecord(parsed.scripts) ? { scripts: parsed.scripts } : {}),
@@ -1025,3 +1162,114 @@ function classifyPackageLocalBuildOutputs(packageJson) {
1025
1162
  platform: targetNames.some((targetName) => PLATFORM_TARGET_GLOBS.some((glob) => targetName.endsWith(glob.slice(1)))),
1026
1163
  };
1027
1164
  }
1165
+ function cargoTargetDependency(currentProjectName, target) {
1166
+ return target.projectName === currentProjectName
1167
+ ? target.targetName
1168
+ : { projects: [target.projectName], target: target.targetName };
1169
+ }
1170
+ async function resolveRepoRootCargoWorkspace(packageJsonPaths, workspaceRoot) {
1171
+ const cargoTomlPath = join(workspaceRoot, 'Cargo.toml');
1172
+ if (!existsSync(cargoTomlPath) || !CARGO_WORKSPACE_PATTERN.test(await readFile(cargoTomlPath, 'utf-8'))) {
1173
+ return null;
1174
+ }
1175
+ const projects = [];
1176
+ for (const packageJsonPath of packageJsonPaths) {
1177
+ if (isManagedPackageJsonSource(packageJsonPath) || isBuildOutputPackageJson(packageJsonPath)) {
1178
+ continue;
1179
+ }
1180
+ try {
1181
+ const packageJson = await readPackageJson(join(workspaceRoot, packageJsonPath));
1182
+ const name = packageJson.nx?.name ?? packageJson.name;
1183
+ if (typeof name === 'string' && name.length > 0) {
1184
+ projects.push({ name, root: dirname(packageJsonPath) });
1185
+ }
1186
+ }
1187
+ catch {
1188
+ // createProjectTargets records the path-specific parse failure below.
1189
+ }
1190
+ }
1191
+ const rootProject = projects.find((project) => project.root === '.');
1192
+ if (!rootProject) {
1193
+ return null;
1194
+ }
1195
+ const attributed = attributeCargoWorkspacePackages(listCargoWorkspacePackages(workspaceRoot), projects);
1196
+ const packages = [];
1197
+ let previous = {
1198
+ projectName: rootProject.name,
1199
+ targetName: CARGO_TEST_COMPILE_TARGET,
1200
+ };
1201
+ const exceptional = exceptionalTestFilter(PLUGIN_NEXTEST_CONFIG);
1202
+ for (const pkg of attributed) {
1203
+ const pieces = [];
1204
+ const sharded = pkg.testShards > 1;
1205
+ const pin = sharded && exceptional !== null ? exceptional : null;
1206
+ const shardable = pin === null ? `package(${pkg.name})` : `package(${pkg.name}) and not (${pin})`;
1207
+ for (let index = 1; index <= pkg.testShards; index += 1) {
1208
+ const targetName = cargoTestPackageTargetName(pkg.name, sharded ? `shard${index}` : undefined);
1209
+ pieces.push({
1210
+ extra: sharded ? ` --partition hash:${index}/${pkg.testShards}` : '',
1211
+ previous,
1212
+ selector: shardable,
1213
+ targetName,
1214
+ });
1215
+ previous = { projectName: pkg.projectName, targetName };
1216
+ }
1217
+ if (pin !== null) {
1218
+ const targetName = cargoTestPackageTargetName(pkg.name, CARGO_TEST_EXCEPTIONS_SUFFIX);
1219
+ pieces.push({
1220
+ extra: '',
1221
+ previous,
1222
+ selector: `package(${pkg.name}) and (${pin})`,
1223
+ targetName,
1224
+ });
1225
+ previous = { projectName: pkg.projectName, targetName };
1226
+ }
1227
+ packages.push({ package: pkg, pieces });
1228
+ }
1229
+ return { packages, rootProjectName: rootProject.name };
1230
+ }
1231
+ /**
1232
+ * Root mode keeps `--workspace` and adds `-p` only to make the owning crate
1233
+ * explicit in the command Nx attributes to its project. Cargo treats
1234
+ * `--workspace -p X` as the full workspace selection, so `-p` is inert for
1235
+ * feature resolution; the nextest filterset is what narrows the tests that run.
1236
+ * Never drop `--workspace`: `-p X` alone re-resolves features for one package
1237
+ * and defeats the compile target's shared artifacts.
1238
+ */
1239
+ async function addRepoRootCargoTestTargets(targets, currentProjectName, projectRoot, workspaceRoot, workspace) {
1240
+ const targetNames = [];
1241
+ const configFile = nextestConfigRelPath(workspaceRoot, '.', PLUGIN_NEXTEST_CONFIG);
1242
+ for (const plan of workspace.packages) {
1243
+ if (plan.package.projectRoot !== projectRoot) {
1244
+ continue;
1245
+ }
1246
+ const inputs = await cargoPackageTestInputs(workspaceRoot, plan.package.dir, '{workspaceRoot}');
1247
+ for (const piece of plan.pieces) {
1248
+ targetNames.push(piece.targetName);
1249
+ targets[piece.targetName] = {
1250
+ executor: '@smoothbricks/nx-plugin:bounded-exec',
1251
+ cache: true,
1252
+ inputs,
1253
+ dependsOn: [cargoTargetDependency(currentProjectName, piece.previous)],
1254
+ options: {
1255
+ command: cargoFrozen(`nextest run --workspace -p ${plan.package.name} -E '${piece.selector}'${piece.extra} --no-tests=pass --user-config-file none --config-file ${configFile}`),
1256
+ cwd: '.',
1257
+ timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
1258
+ killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
1259
+ },
1260
+ };
1261
+ }
1262
+ }
1263
+ return targetNames;
1264
+ }
1265
+ function hasCargoTargetDependency(dependencies, expected) {
1266
+ if (typeof expected === 'string') {
1267
+ return dependencies.includes(expected);
1268
+ }
1269
+ return dependencies.some((dependency) => typeof dependency !== 'string' &&
1270
+ dependency.target === expected.target &&
1271
+ Array.isArray(dependency.projects) &&
1272
+ Array.isArray(expected.projects) &&
1273
+ dependency.projects.length === expected.projects.length &&
1274
+ dependency.projects.every((project, index) => project === expected.projects?.[index]));
1275
+ }