@smoothbricks/nx-plugin 0.4.0 → 0.4.2

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.
package/src/index.test.ts CHANGED
@@ -1,20 +1,98 @@
1
1
  import { describe, expect, it } from 'bun:test';
2
- import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
2
+ import { mkdir, mkdtemp, rm, symlink, writeFile } from 'node:fs/promises';
3
3
  import { tmpdir } from 'node:os';
4
4
  import { dirname, join } from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
6
6
 
7
7
  import type { CreateNodesContextV2, CreateNodesV2, TargetConfiguration } from 'nx/src/devkit-exports.js';
8
8
  import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
9
+ import { createTargetDefaultsResults } from 'nx/src/project-graph/utils/project-configuration/target-defaults.js';
9
10
  import { mergeTargetConfigurations } from 'nx/src/project-graph/utils/project-configuration-utils.js';
10
11
  import { BOUNDED_TEST_TIMEOUT_MS } from './bounded-test-policy.js';
11
12
  import { exceptionalTestFilter } from './cargo-workspace.js';
12
13
  import { CARGO_CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET, CARGO_LINT_CLIPPY_COMMAND } from './cross-check-policy.js';
13
14
  import { createNodesV2, createNodesV2ForPlatform } from './index.js';
15
+ import { applyWorkspaceConfig } from './workspace-config-policy.js';
14
16
 
15
17
  const [, inferTargets] = createNodesV2;
16
18
 
17
19
  describe('@smoothbricks/nx-plugin inferred targets', () => {
20
+ it('runs Rust-only lint without ESLint and checks JavaScript when sources appear', async () => {
21
+ const workspace = await createWorkspace();
22
+ const root = workspace.context.workspaceRoot;
23
+ const repositoryRoot = fileURLToPath(new URL('../../../', import.meta.url));
24
+ try {
25
+ await symlink(join(repositoryRoot, 'node_modules'), join(root, 'node_modules'), 'dir');
26
+ await workspace.write('package.json', '{"name":"lint-workspace","private":true,"workspaces":["packages/*"]}\n');
27
+ await workspace.write(
28
+ 'nx.json',
29
+ JSON.stringify({
30
+ plugins: [fileURLToPath(new URL('../dist/index.js', import.meta.url))],
31
+ namedInputs: { default: ['{projectRoot}/**/*'] },
32
+ targetDefaults: { lint: { cache: true } },
33
+ }),
34
+ );
35
+ await workspace.write(
36
+ 'biome.json',
37
+ '{"formatter":{"enabled":false},"linter":{"rules":{"suspicious":{"noDebugger":"off"}}}}\n',
38
+ );
39
+ await workspace.write(
40
+ 'eslint.config.mjs',
41
+ 'export default [{ files: ["**/*.{js,ts}"], rules: { "no-debugger": "error" } }];\n',
42
+ );
43
+ await workspace.write('Cargo.toml', '[workspace]\nmembers = ["packages/rust"]\nresolver = "2"\n');
44
+ await workspace.write('Cargo.lock', 'version = 4\n\n[[package]]\nname = "lint-crate"\nversion = "0.1.0"\n');
45
+ await workspace.write('packages/rust/package.json', '{"name":"rust-fixture"}\n');
46
+ await workspace.write(
47
+ 'packages/rust/Cargo.toml',
48
+ '[package]\nname = "lint-crate"\nversion = "0.1.0"\nedition = "2021"\n',
49
+ );
50
+ await workspace.write('packages/rust/src/lib.rs', 'pub fn answer() -> u32 {\n 42\n}\n');
51
+ const runLint = async () => {
52
+ const child = Bun.spawn(['bun', join(repositoryRoot, 'node_modules/.bin/nx'), 'run', 'rust-fixture:lint'], {
53
+ cwd: root,
54
+ env: {
55
+ ...process.env,
56
+ PATH: `${join(repositoryRoot, 'node_modules/.bin')}:${process.env.PATH ?? ''}`,
57
+ NX_DAEMON: 'false',
58
+ NX_ISOLATE_PLUGINS: 'false',
59
+ NX_WORKSPACE_DATA_DIRECTORY: join(root, '.nx/workspace-data'),
60
+ NX_CACHE_DIRECTORY: join(root, '.nx/cache'),
61
+ RUSTC_WRAPPER: '',
62
+ RUSTC_WORKSPACE_WRAPPER: '',
63
+ },
64
+ stdout: 'pipe',
65
+ stderr: 'pipe',
66
+ });
67
+ const [exitCode, stdout, stderr] = await Promise.all([
68
+ child.exited,
69
+ new Response(child.stdout).text(),
70
+ new Response(child.stderr).text(),
71
+ ]);
72
+ return { exitCode, output: stdout + stderr };
73
+ };
74
+ const rustOnly = await runLint();
75
+ expect(rustOnly).toMatchObject({ exitCode: 0 });
76
+ expect(rustOnly.output).toContain('cargo-lint-lint-crate');
77
+ await workspace.write('packages/rust/src/check.js', 'debugger;\n');
78
+ const withJavaScript = await runLint();
79
+ expect(withJavaScript.exitCode).not.toBe(0);
80
+ expect(withJavaScript.output).toContain('no-debugger');
81
+ await workspace.write(
82
+ 'packages/rust/package.json',
83
+ JSON.stringify({
84
+ name: 'rust-fixture',
85
+ nx: { targets: { lint: { executor: 'nx:run-commands', options: { command: 'printf explicit-lint' } } } },
86
+ }),
87
+ );
88
+ const overridden = await runLint();
89
+ expect(overridden).toMatchObject({ exitCode: 0 });
90
+ expect(overridden.output).toContain('explicit-lint');
91
+ } finally {
92
+ await workspace.cleanup();
93
+ }
94
+ }, 120_000);
95
+
18
96
  it('names standalone package projects from package metadata', async () => {
19
97
  const workspace = await createWorkspace();
20
98
  try {
@@ -175,7 +253,6 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
175
253
  cwd: 'packages/example',
176
254
  });
177
255
 
178
- expect(targets.lint?.executor).toBeUndefined();
179
256
  expect(targets.lint?.cache).toBe(true);
180
257
  expect(targets.lint?.dependsOn).toEqual(['typecheck-tests']);
181
258
  } finally {
@@ -289,20 +366,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
289
366
 
290
367
  // Even a cdylib crate named *-wasm infers no cargo-wasm: rust output
291
368
  // targets are declared package-locally, never derived from crate metadata.
292
- expect(Object.keys(targets).sort()).toEqual([
293
- 'bench',
294
- 'cargo-fetch',
295
- 'cargo-lint',
296
- 'cargo-lint-cross',
297
- 'cargo-sweep',
298
- 'cargo-test',
299
- 'cargo-test-compile',
300
- 'cargo-test-ferris-core',
301
- 'cargo-test-ferris-wasm',
302
- 'lint',
303
- 'mutation',
304
- 'test',
305
- ]);
369
+ expect(targets['cargo-wasm']).toBeUndefined();
370
+ expect(targets['cargo-napi']).toBeUndefined();
306
371
  expect(targets['cargo-sweep']?.options).toMatchObject({
307
372
  command: 'cargo sweep --time 7',
308
373
  cwd: 'packages/ferris',
@@ -319,11 +384,19 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
319
384
  // Every frozen cargo command carries the edge, not just the head of the
320
385
  // serialization chain: offline cargo fails at resolution, so each one
321
386
  // needs the locked graph downloaded whether or not the chain runs first.
322
- for (const name of ['cargo-test-compile', 'cargo-lint', CARGO_CROSS_LINT_TARGET, 'mutation', 'bench']) {
387
+ for (const name of [
388
+ 'cargo-test-compile',
389
+ 'cargo-lint-ferris-core',
390
+ CARGO_CROSS_LINT_TARGET,
391
+ 'mutation',
392
+ 'bench',
393
+ ]) {
323
394
  expect(targets[name]?.dependsOn).toContain('cargo-fetch');
324
395
  }
325
396
  expect(targets['cargo-sweep']?.dependsOn).toBeUndefined();
326
397
  expect(targets['cargo-test-compile']?.executor).toBe('nx:run-commands');
398
+ expect(targets['cargo-test-compile']?.cache).toBe(false);
399
+ expect(targets['cargo-test-compile']?.outputs).toEqual([]);
327
400
  expect(targets['cargo-test-compile']?.options).toMatchObject({
328
401
  command: 'cargo --frozen test --workspace --no-run',
329
402
  cwd: 'packages/ferris',
@@ -339,18 +412,24 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
339
412
  expect(targets['cargo-test-ferris-core']?.options?.command).toMatch(
340
413
  /^cargo --frozen nextest run --workspace -E 'package\(ferris-core\)' --no-tests=pass --user-config-file none --config-file /,
341
414
  );
342
- expect(targets['cargo-test-ferris-core']?.inputs).toEqual([
343
- '{projectRoot}/Cargo.toml',
344
- '{projectRoot}/Cargo.lock',
345
- '{projectRoot}/crates/ferris-core/**/*.rs',
346
- '{projectRoot}/crates/ferris-core/Cargo.toml',
347
- '{projectRoot}/**/.cargo/config.toml',
348
- '{projectRoot}/scripts/*.sh',
349
- '!{projectRoot}/**/target/**',
350
- ]);
351
- expect(targets['cargo-lint']?.options).toMatchObject({
352
- commands: ['cargo fmt --all --check', CARGO_LINT_CLIPPY_COMMAND],
415
+ expect(targets['cargo-test-ferris-core']?.inputs).toEqual(
416
+ expect.arrayContaining([
417
+ '{projectRoot}/Cargo.toml',
418
+ '{projectRoot}/Cargo.lock',
419
+ '{projectRoot}/crates/ferris-core/**/*',
420
+ ]),
421
+ );
422
+ expect(targets['cargo-test-ferris-core']?.inputs).not.toContain('{projectRoot}/crates/ferris-wasm/**/*');
423
+ expect(targets['cargo-lint']?.dependsOn).toEqual(['cargo-lint-ferris-core', 'cargo-lint-ferris-wasm']);
424
+ expect(targets['cargo-lint-ferris-core']?.options).toMatchObject({
425
+ cwd: 'packages/ferris',
426
+ commands: [
427
+ 'cargo fmt -p ferris-core --check',
428
+ 'cargo --frozen clippy -p ferris-core --all-targets --target-dir target/cargo-lint-ferris-core -- -D warnings',
429
+ ],
353
430
  });
431
+ expect(targets['cargo-lint-ferris-core']?.cache).toBe(true);
432
+ expect(targets['cargo-lint-ferris-core']?.outputs).toEqual([]);
354
433
  expect(targets.lint?.dependsOn).toEqual(['cargo-lint']);
355
434
  expect(targets[CARGO_CROSS_LINT_TARGET]?.options).toMatchObject({
356
435
  command: CARGO_CROSS_LINT_COMMAND,
@@ -368,16 +447,74 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
368
447
  }
369
448
  });
370
449
 
450
+ it('keeps Rust-only lint source-aware after migrating defaults without replacing mixed or custom lint', async () => {
451
+ const workspace = await createWorkspace();
452
+ const root = 'packages/ferris';
453
+ const defaults = {
454
+ targetDefaults: {
455
+ lint: {
456
+ executor: 'nx:run-commands',
457
+ options: { commands: ['biome check {projectRoot}', 'eslint {projectRoot}/src'] },
458
+ },
459
+ },
460
+ };
461
+ applyWorkspaceConfig(defaults);
462
+ const resolveLint = (targets: Record<string, TargetConfiguration>, declared: TargetConfiguration = {}) => {
463
+ let lint = targets.lint ?? {};
464
+ const synthesized = createTargetDefaultsResults(
465
+ { [root]: { root, targets } },
466
+ { [root]: { root, targets: { lint: declared } } },
467
+ defaults,
468
+ );
469
+ for (const [, , result] of synthesized) {
470
+ const target = result.projects?.[root]?.targets?.lint;
471
+ if (target) lint = mergeTargetConfigurations(target, lint);
472
+ }
473
+ return mergeTargetConfigurations(declared, lint);
474
+ };
475
+ try {
476
+ await workspace.write('biome.json', '{}\n');
477
+ await workspace.write('eslint.config.mjs', 'export default [{ files: ["**/*.ts"] }];\n');
478
+ await workspace.write(`${root}/package.json`, '{"name":"ferris"}\n');
479
+ await workspace.write(`${root}/Cargo.toml`, '[workspace]\nmembers = ["crates/core"]\n');
480
+ await workspace.write(`${root}/crates/core/Cargo.toml`, '[package]\nname = "ferris-core"\n');
481
+ const rust = await inferProjectTargets(workspace, `${root}/package.json`);
482
+ const rustLint = resolveLint(rust);
483
+ expect(rustLint.executor).toBe('nx:run-commands');
484
+ expect(rustLint.dependsOn).toEqual(['cargo-lint']);
485
+ expect(rustLint.options?.commands).toEqual([`biome check --files-ignore-unknown=true '${root}'`]);
486
+
487
+ const custom = { executor: 'nx:run-commands', options: { command: 'custom-linter package.json' } };
488
+ await workspace.write(
489
+ `${root}/package.json`,
490
+ JSON.stringify({ name: 'ferris', nx: { targets: { lint: custom } } }),
491
+ );
492
+ const declared = await inferProjectTargets(workspace, `${root}/package.json`);
493
+ expect(resolveLint(declared, custom).options?.command).toBe(custom.options.command);
494
+
495
+ await workspace.write(`${root}/package.json`, '{"name":"ferris"}\n');
496
+ await workspace.write(`${root}/tsconfig.lib.json`, '{"compilerOptions":{"outDir":"dist"}}\n');
497
+ await workspace.write(`${root}/src/index.ts`, 'export const value = 1;\n');
498
+ const mixed = await inferProjectTargets(workspace, `${root}/package.json`);
499
+ expect(resolveLint(mixed).options?.commands).toEqual([
500
+ `biome check --files-ignore-unknown=true '${root}'`,
501
+ `eslint '${root}/src/index.ts'`,
502
+ ]);
503
+ } finally {
504
+ await workspace.cleanup();
505
+ }
506
+ });
507
+
371
508
  it('attributes one repository-root Cargo workspace across package projects', async () => {
372
509
  const workspace = await createWorkspace();
373
510
  try {
374
- await workspace.write('package.json', '{"name":"@axe.sc/codebase"}\n');
375
- await workspace.write('packages/runtime/package.json', '{"name":"@axe.sc/runtime","nx":{"name":"runtime"}}\n');
376
- await workspace.write('packages/wasm/package.json', '{"name":"@axe.sc/wasm","nx":{"name":"wasm"}}\n');
511
+ await workspace.write('package.json', '{"name":"@fixture/codebase"}\n');
512
+ await workspace.write('packages/runtime/package.json', '{"name":"@fixture/runtime","nx":{"name":"runtime"}}\n');
513
+ await workspace.write('packages/wasm/package.json', '{"name":"@fixture/wasm","nx":{"name":"wasm"}}\n');
377
514
  await workspace.write(
378
515
  'packages/native/package.json',
379
516
  JSON.stringify({
380
- name: '@axe.sc/native',
517
+ name: '@fixture/native',
381
518
  nx: { name: 'native' },
382
519
  napi: {
383
520
  binaryName: 'native',
@@ -427,7 +564,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
427
564
  const runtime = projects.get('packages/runtime')?.targets ?? {};
428
565
  const wasm = projects.get('packages/wasm')?.targets ?? {};
429
566
  const native = projects.get('packages/native')?.targets ?? {};
430
- const rootProject = '@axe.sc/codebase';
567
+ const rootProject = '@fixture/codebase';
431
568
  const rootFetch = { projects: [rootProject], target: 'cargo-fetch' };
432
569
  const rootCompile = { projects: [rootProject], target: 'cargo-test-compile' };
433
570
 
@@ -445,7 +582,11 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
445
582
  command: 'cargo --frozen test --workspace --no-run',
446
583
  cwd: '.',
447
584
  });
448
- expect(root['cargo-lint']?.options).toMatchObject({ cwd: '.' });
585
+ expect(root['cargo-lint']?.dependsOn).toEqual([
586
+ { projects: ['native'], target: 'cargo-lint-native-napi' },
587
+ { projects: ['runtime'], target: 'cargo-lint-runtime-core' },
588
+ { projects: ['wasm'], target: 'cargo-lint-runtime-wasm' },
589
+ ]);
449
590
  expect(root['cargo-test']?.dependsOn).toHaveLength(5);
450
591
 
451
592
  expect(runtime['cargo-test-runtime-core-shard1']?.dependsOn).toEqual([
@@ -470,7 +611,10 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
470
611
  'cargo-test-runtime-core-shard2',
471
612
  'cargo-test-runtime-core-exceptions',
472
613
  ]);
473
- expect(runtime['cargo-lint']).toBeUndefined();
614
+ expect(runtime['cargo-lint']?.dependsOn).toEqual(['cargo-lint-runtime-core']);
615
+ expect(runtime.lint?.dependsOn).toEqual(['cargo-lint']);
616
+ expect(runtime['cargo-lint-runtime-core']?.dependsOn).toEqual([rootFetch]);
617
+ expect(runtime['cargo-lint-runtime-core']?.options?.cwd).toBe('.');
474
618
  expect(runtime.clean).toBeUndefined();
475
619
 
476
620
  expect(wasm['cargo-test-runtime-wasm']?.dependsOn).toEqual([
@@ -491,12 +635,12 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
491
635
  expect(native['napi-debug']?.options).toMatchObject({
492
636
  cwd: '.',
493
637
  command:
494
- 'napi build --platform --no-js --dts native.napi.d.ts --manifest-path packages/native/crates/native-napi/Cargo.toml --package native-napi --output-dir packages/native/.cache/native-debug',
638
+ 'packages/native/node_modules/.bin/napi build --platform --no-js --dts native.napi.d.ts --manifest-path packages/native/crates/native-napi/Cargo.toml --package native-napi --package-json-path packages/native/package.json --output-dir packages/native/.cache/native-debug',
495
639
  });
496
640
  expect(native['napi-arm64-macos']?.options).toMatchObject({
497
641
  cwd: '.',
498
642
  command:
499
- 'napi build --release --platform --no-js --dts native.darwin-arm64.d.ts --target aarch64-apple-darwin --manifest-path packages/native/crates/native-napi/Cargo.toml --package native-napi --output-dir packages/native/dist/native/darwin-arm64',
643
+ 'packages/native/node_modules/.bin/napi build --release --platform --no-js --dts native.darwin-arm64.d.ts --target aarch64-apple-darwin --manifest-path packages/native/crates/native-napi/Cargo.toml --package native-napi --package-json-path packages/native/package.json --output-dir packages/native/dist/native/darwin-arm64',
500
644
  });
501
645
  expect(native.build?.dependsOn).toContainEqual(rootCompile);
502
646
  expect(native.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
@@ -505,6 +649,128 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
505
649
  }
506
650
  });
507
651
 
652
+ it('keeps root packages, nested workspaces and multiple owned crates in their own lint graph', async () => {
653
+ const workspace = await createWorkspace();
654
+ const declared: Record<string, TargetConfiguration> = {
655
+ 'cargo-lint-alpha-core': { dependsOn: ['...', 'prepare-check'] },
656
+ 'cargo-lint': { dependsOn: ['cargo-lint-alpha-core'] },
657
+ lint: { dependsOn: ['cargo-lint', 'custom-check'] },
658
+ };
659
+ try {
660
+ await workspace.write('package.json', '{"name":"outer-root"}\n');
661
+ await workspace.write(
662
+ 'Cargo.toml',
663
+ '[workspace]\nmembers = ["packages/group/crates/*"]\nexclude = ["nested"]\n\n[package]\nname = "host-core"\n',
664
+ );
665
+ await workspace.write(
666
+ 'packages/group/package.json',
667
+ JSON.stringify({ name: 'group', nx: { targets: declared } }),
668
+ );
669
+ await workspace.write('packages/group/tsconfig.lib.json', '{}\n');
670
+ await workspace.write('packages/group/crates/alpha/Cargo.toml', '[package]\nname = "alpha-core"\n');
671
+ await workspace.write('packages/group/crates/beta/Cargo.toml', '[package]\nname = "beta-wasm"\n');
672
+ await workspace.write('nested/package.json', '{"name":"inner-root"}\n');
673
+ await workspace.write(
674
+ 'nested/Cargo.toml',
675
+ '[workspace]\nmembers = ["modules/leaf"]\n\n[package]\nname = "inner-host"\n',
676
+ );
677
+ await workspace.write('nested/modules/leaf/package.json', '{"name":"inner-leaf-project"}\n');
678
+ await workspace.write('nested/modules/leaf/Cargo.toml', '[package]\nname = "inner-leaf"\n');
679
+ const inferred = await inferTargets(
680
+ ['package.json', 'packages/group/package.json', 'nested/package.json', 'nested/modules/leaf/package.json'],
681
+ undefined,
682
+ workspace.context,
683
+ );
684
+ const projects = new Map(inferred.flatMap(([, result]) => Object.entries(result.projects ?? {})));
685
+ const outer = projects.get('.')?.targets ?? {};
686
+ const group = projects.get('packages/group')?.targets ?? {};
687
+ const inner = projects.get('nested')?.targets ?? {};
688
+ const leaf = projects.get('nested/modules/leaf')?.targets ?? {};
689
+ expect(outer['cargo-lint']?.dependsOn).toEqual([
690
+ { projects: ['group'], target: 'cargo-lint-alpha-core' },
691
+ { projects: ['group'], target: 'cargo-lint-beta-wasm' },
692
+ 'cargo-lint-host-core',
693
+ ]);
694
+ expect(group['cargo-lint']?.dependsOn).toEqual(['cargo-lint-alpha-core', 'cargo-lint-beta-wasm']);
695
+ expect(group.build?.dependsOn).toEqual([
696
+ '^build',
697
+ { projects: ['outer-root'], target: 'cargo-test-compile' },
698
+ 'tsc-js',
699
+ ]);
700
+ expect(outer['cargo-lint-host-core']?.options?.commands).toEqual([
701
+ 'cargo fmt -p host-core --check',
702
+ 'cargo --frozen clippy -p host-core --all-targets --target-dir target/cargo-lint-host-core -- -D warnings',
703
+ ]);
704
+ expect(inner['cargo-lint']?.dependsOn).toEqual([
705
+ 'cargo-lint-inner-host',
706
+ { projects: ['inner-leaf-project'], target: 'cargo-lint-inner-leaf' },
707
+ ]);
708
+ expect(leaf['cargo-lint-inner-leaf']?.options).toMatchObject({
709
+ cwd: 'nested',
710
+ commands: [
711
+ 'cargo fmt -p inner-leaf --check',
712
+ 'cargo --frozen clippy -p inner-leaf --all-targets --target-dir target/cargo-lint-inner-leaf -- -D warnings',
713
+ ],
714
+ });
715
+ expect(leaf['cargo-lint-inner-leaf']?.dependsOn).toEqual([{ projects: ['inner-root'], target: 'cargo-fetch' }]);
716
+ expect(leaf['cargo-lint-inner-leaf']?.inputs).toContain('{workspaceRoot}/nested/modules/leaf/**/*');
717
+ expect(leaf['cargo-lint-inner-leaf']?.inputs).not.toContain('{workspaceRoot}/packages/group/crates/alpha/**/*');
718
+ expect(leaf['cargo-test-inner-leaf']?.options?.cwd).toBe('nested');
719
+ expect(inner['cargo-test-compile']?.options?.cwd).toBe('nested');
720
+ expect(leaf['cargo-test-inner-leaf']?.configurations?.production?.command).toContain('--workspace --release');
721
+ expect(resolveDeclaredOverInferred(group, declared, 'cargo-lint-alpha-core')).toMatchObject({
722
+ executor: 'nx:run-commands',
723
+ cache: true,
724
+ outputs: [],
725
+ dependsOn: [{ projects: ['outer-root'], target: 'cargo-fetch' }, 'prepare-check'],
726
+ });
727
+ expect(resolveDeclaredOverInferred(group, declared, 'cargo-lint')?.dependsOn).toEqual(['cargo-lint-alpha-core']);
728
+ expect(resolveDeclaredOverInferred(group, declared, 'lint')?.dependsOn).toEqual(['cargo-lint', 'custom-check']);
729
+ } finally {
730
+ await workspace.cleanup();
731
+ }
732
+ });
733
+
734
+ it('invalidates cached lint verdicts for Cargo target, profile and global configuration changes', async () => {
735
+ const workspace = await createWorkspace();
736
+ try {
737
+ await workspace.write('package.json', '{"name":"cache-fixture"}\n');
738
+ await workspace.write('Cargo.toml', '[workspace]\nmembers = ["crate"]\n');
739
+ await workspace.write('crate/Cargo.toml', '[package]\nname = "cache-crate"\n');
740
+ await workspace.write('cargo-home/config.toml', '[build]\njobs = 1\n');
741
+ const targets = await inferProjectTargets(workspace, 'package.json');
742
+ const runtimeCommands = (targets['cargo-lint-cache-crate']?.inputs ?? []).flatMap((input) =>
743
+ typeof input !== 'string' && 'runtime' in input ? [input.runtime] : [],
744
+ );
745
+ const capture = async (extraEnv: Record<string, string>) =>
746
+ Promise.all(
747
+ runtimeCommands.map(async (command) => {
748
+ const child = Bun.spawn(['sh', '-c', command], {
749
+ cwd: workspace.context.workspaceRoot,
750
+ env: { ...process.env, CARGO_HOME: join(workspace.context.workspaceRoot, 'cargo-home'), ...extraEnv },
751
+ stdout: 'pipe',
752
+ stderr: 'pipe',
753
+ });
754
+ const [exitCode, stdout, stderr] = await Promise.all([
755
+ child.exited,
756
+ new Response(child.stdout).text(),
757
+ new Response(child.stderr).text(),
758
+ ]);
759
+ expect({ exitCode, stderr }).toMatchObject({ exitCode: 0 });
760
+ return stdout;
761
+ }),
762
+ );
763
+ const baseline = await capture({});
764
+ expect(await capture({ CARGO_BUILD_TARGET: 'wasm32-unknown-unknown' })).not.toEqual(baseline);
765
+ expect(await capture({ CARGO_PROFILE_DEV_OPT_LEVEL: '2' })).not.toEqual(baseline);
766
+ expect(await capture({ UNRELATED_FIXTURE_VARIABLE: 'changed' })).toEqual(baseline);
767
+ await workspace.write('cargo-home/config.toml', '[build]\njobs = 2\n');
768
+ expect(await capture({})).not.toEqual(baseline);
769
+ } finally {
770
+ await workspace.cleanup();
771
+ }
772
+ }, 30_000);
773
+
508
774
  it('scopes each per-crate cargo-test command to exactly one package', async () => {
509
775
  const workspace = await createWorkspace();
510
776
  try {
@@ -566,16 +832,12 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
566
832
  executor: 'nx:run-commands',
567
833
  cache: true,
568
834
  dependsOn: ['cargo-fetch', '^build'],
569
- inputs: [
835
+ inputs: expect.arrayContaining([
570
836
  '{projectRoot}/**/*.rs',
571
837
  '{projectRoot}/**/Cargo.toml',
572
- '{projectRoot}/**/Cargo.lock',
573
- '{projectRoot}/**/.cargo/config.toml',
574
- '{projectRoot}/scripts/*.sh',
575
- '!{projectRoot}/**/target/**',
576
838
  '{projectRoot}/package.json',
577
839
  '{workspaceRoot}/bun.lock',
578
- ],
840
+ ]),
579
841
  outputs: ['{projectRoot}/generated/wasm'],
580
842
  options: {
581
843
  commands: [
@@ -679,14 +941,14 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
679
941
  options: {
680
942
  cwd: 'packages/cowshed',
681
943
  command:
682
- 'napi build --release --platform --no-js --dts cowshed.napi.d.ts --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --output-dir dist/native/host',
944
+ 'napi build --release --platform --no-js --dts cowshed.napi.d.ts --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --package-json-path package.json --output-dir dist/native/host',
683
945
  },
684
946
  });
685
947
  expect(unservedHostTargets.build?.dependsOn).toEqual(['^build', 'cargo-test-compile', 'cargo-napi', 'tsc-js']);
686
948
  expect(targets['napi-arm64-macos']?.outputs).toEqual(['{projectRoot}/dist/native/darwin-arm64']);
687
949
  expect(targets['napi-arm64-macos']?.options).toMatchObject({
688
950
  command:
689
- 'napi build --release --platform --no-js --dts cowshed.darwin-arm64.d.ts --target aarch64-apple-darwin --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --output-dir dist/native/darwin-arm64',
951
+ 'napi build --release --platform --no-js --dts cowshed.darwin-arm64.d.ts --target aarch64-apple-darwin --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --package-json-path package.json --output-dir dist/native/darwin-arm64',
690
952
  });
691
953
  expect(targets['napi-arm64-macos']?.options?.env).toBeUndefined();
692
954
  // No cargo-test-compile edge here, on ANY host: a platform target's
@@ -747,7 +1009,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
747
1009
  expect(darwinArm64Targets['napi-arm64-linux']?.dependsOn).toEqual(['napi-toolchain-arm64-linux']);
748
1010
  expect(darwinArm64Targets['napi-x64-linux']?.outputs).toEqual(['{projectRoot}/dist/native/linux-x64-gnu']);
749
1011
  expect(darwinArm64Targets['napi-x64-linux']?.options?.command).toBe(
750
- 'napi build --release --platform --no-js --dts cowshed.linux-x64-gnu.d.ts --target x86_64-unknown-linux-gnu --use-napi-cross --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --output-dir dist/native/linux-x64-gnu',
1012
+ 'napi build --release --platform --no-js --dts cowshed.linux-x64-gnu.d.ts --target x86_64-unknown-linux-gnu --use-napi-cross --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --package-json-path package.json --output-dir dist/native/linux-x64-gnu',
751
1013
  );
752
1014
 
753
1015
  // The whole rule, stated once per forced host: a triple gets a cross
@@ -817,7 +1079,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
817
1079
  options: {
818
1080
  cwd: 'packages/cowshed',
819
1081
  command:
820
- 'napi build --platform --no-js --dts cowshed.napi.d.ts --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --output-dir .cache/native-debug',
1082
+ 'napi build --platform --no-js --dts cowshed.napi.d.ts --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --package-json-path package.json --output-dir .cache/native-debug',
821
1083
  },
822
1084
  });
823
1085
  expect(targets['cargo-test']?.dependsOn).toEqual(['cargo-test-cowshed-napi']);
@@ -995,7 +1257,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
995
1257
 
996
1258
  const targets = await inferProjectTargets(workspace, 'packages/custom/package.json');
997
1259
  expect(targets['cargo-wasm']).toBeUndefined();
998
- expect(targets.test).toBeUndefined();
1260
+ expect(targets.test).toEqual({ dependsOn: ['^build', 'build'] });
999
1261
  expect(targets['cargo-test']).toBeDefined();
1000
1262
 
1001
1263
  // A member crate's own Cargo.toml (no [workspace]) infers nothing.
@@ -1008,6 +1270,33 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1008
1270
  }
1009
1271
  });
1010
1272
 
1273
+ it('gives a declared TypeScript test the ^build/build dependsOn base targetDefaults must not supply', async () => {
1274
+ const workspace = await createWorkspace();
1275
+ try {
1276
+ await workspace.write(
1277
+ 'packages/money/package.json',
1278
+ JSON.stringify({
1279
+ name: 'money',
1280
+ nx: {
1281
+ targets: {
1282
+ test: {
1283
+ executor: '@smoothbricks/nx-plugin:bounded-exec',
1284
+ options: { command: 'bun test', cwd: '{projectRoot}' },
1285
+ },
1286
+ },
1287
+ },
1288
+ }),
1289
+ );
1290
+ await workspace.write('packages/money/tsconfig.lib.json', '{}\n');
1291
+
1292
+ const targets = await inferProjectTargets(workspace, 'packages/money/package.json');
1293
+ expect(targets.test).toEqual({ dependsOn: ['^build', 'build'] });
1294
+ expect(targets['cargo-test']).toBeUndefined();
1295
+ } finally {
1296
+ await workspace.cleanup();
1297
+ }
1298
+ });
1299
+
1011
1300
  it('keeps inferring a cargo target the package partially declares', async () => {
1012
1301
  const workspace = await createWorkspace();
1013
1302
  const declared: Record<string, TargetConfiguration> = {
@@ -1201,6 +1490,8 @@ function cargoPackageSelection(command: string): {
1201
1490
  return {
1202
1491
  workspaceBuild: tokens.includes('--workspace'),
1203
1492
  packageFlags,
1204
- filtered: [...command.matchAll(/\bpackage\(([^)]+)\)/g)].map((match) => match[1] as string),
1493
+ filtered: [...command.matchAll(/\bpackage\(([^)]+)\)/g)].flatMap((match) =>
1494
+ match[1] === undefined ? [] : [match[1]],
1495
+ ),
1205
1496
  };
1206
1497
  }