@smoothbricks/nx-plugin 0.4.21 → 0.4.23

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 (64) hide show
  1. package/README.md +95 -18
  2. package/dist/bin/smoo-nx-cargo-hash.js +32 -6
  3. package/dist/bin/smoo-nx-exec.js +35 -11
  4. package/dist/cargo-closure-input.d.ts +63 -0
  5. package/dist/cargo-closure-input.d.ts.map +1 -0
  6. package/dist/cargo-closure-input.js +197 -0
  7. package/dist/cargo-source-hash.d.ts +46 -2
  8. package/dist/cargo-source-hash.d.ts.map +1 -1
  9. package/dist/cargo-source-hash.js +238 -114
  10. package/dist/cross-check-policy.d.ts +14 -0
  11. package/dist/cross-check-policy.d.ts.map +1 -1
  12. package/dist/cross-check-policy.js +15 -1
  13. package/dist/ensure-built.d.ts +3 -2
  14. package/dist/ensure-built.d.ts.map +1 -1
  15. package/dist/ensure-built.js +33 -56
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +112 -76
  18. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  19. package/dist/managed-files/ci-workflow.js +12 -15
  20. package/dist/managed-files/files.d.ts.map +1 -1
  21. package/dist/managed-files/files.js +10 -0
  22. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  23. package/dist/managed-files/publish-workflow.js +12 -6
  24. package/dist/manifest-hash.d.ts.map +1 -1
  25. package/dist/manifest-hash.js +24 -30
  26. package/dist/package-target-policy.js +1 -1
  27. package/dist/platform-targets.d.ts +7 -0
  28. package/dist/platform-targets.d.ts.map +1 -1
  29. package/dist/platform-targets.js +7 -0
  30. package/dist/workspace-config-policy.d.ts +1 -1
  31. package/dist/workspace-config-policy.d.ts.map +1 -1
  32. package/dist/workspace-config-policy.js +1 -1
  33. package/managed/raw/envrc +38 -1
  34. package/managed/raw/tooling/direnv/developer-links.ts +201 -0
  35. package/managed/raw/tooling/direnv/devenv.smoo.nix +75 -51
  36. package/managed/raw/tooling/direnv/secret-references.ts +3 -1
  37. package/managed/raw/tooling/direnv/setup-environment.ts +562 -78
  38. package/managed/raw/tooling/direnv/shared-caches.sh +53 -0
  39. package/managed/raw/tooling/git-hooks/pre-push.sh +22 -1
  40. package/managed/templates/github/workflows/managed-files.yml +4 -3
  41. package/nextest.toml +5 -5
  42. package/package.json +2 -2
  43. package/src/__tests__/fixture-nx-env.ts +31 -0
  44. package/src/__tests__/in-process-nx-index.ts +9 -0
  45. package/src/bin/smoo-nx-cargo-hash.ts +29 -9
  46. package/src/bin/smoo-nx-exec.ts +40 -11
  47. package/src/cargo-closure-input.test.ts +184 -0
  48. package/src/cargo-closure-input.ts +247 -0
  49. package/src/cargo-source-hash.test.ts +104 -10
  50. package/src/cargo-source-hash.ts +290 -37
  51. package/src/cross-check-policy.ts +15 -3
  52. package/src/ensure-built.test.ts +65 -5
  53. package/src/ensure-built.ts +40 -85
  54. package/src/index.test.ts +94 -53
  55. package/src/index.ts +164 -84
  56. package/src/managed-files/ci-workflow.ts +12 -15
  57. package/src/managed-files/files.ts +10 -0
  58. package/src/managed-files/generator.test.ts +29 -0
  59. package/src/managed-files/publish-workflow.ts +17 -6
  60. package/src/manifest-hash.test.ts +21 -1
  61. package/src/manifest-hash.ts +26 -29
  62. package/src/package-target-policy.ts +1 -1
  63. package/src/platform-targets.ts +8 -0
  64. package/src/workspace-config-policy.ts +6 -1
@@ -14,7 +14,6 @@ import type * as NxHashTask from 'nx/src/hasher/hash-task';
14
14
  import type * as NxTaskHasher from 'nx/src/hasher/task-hasher';
15
15
  import type * as NxNative from 'nx/src/native';
16
16
  import type * as NxExecutionHooks from 'nx/src/project-graph/plugins/tasks-execution-hooks';
17
- import type * as NxProjectGraph from 'nx/src/project-graph/project-graph';
18
17
  import type * as NxCache from 'nx/src/tasks-runner/cache';
19
18
  import type * as NxCreateTaskGraph from 'nx/src/tasks-runner/create-task-graph';
20
19
  import type { TaskResults } from 'nx/src/tasks-runner/life-cycle';
@@ -24,7 +23,6 @@ import type * as NxTasksRunnerUtils from 'nx/src/tasks-runner/utils';
24
23
  import type * as NxCacheDirectory from 'nx/src/utils/cache-directory';
25
24
  import type * as NxCommandLineUtils from 'nx/src/utils/command-line-utils';
26
25
  import type { NxArgs } from 'nx/src/utils/command-line-utils';
27
- import type * as NxExitCodes from 'nx/src/utils/exit-codes';
28
26
  import type * as NxPerfLogging from 'nx/src/utils/perf-logging';
29
27
  import type * as NxWorkspaceRoot from 'nx/src/utils/workspace-root';
30
28
 
@@ -35,7 +33,6 @@ interface NxRuntimeModules {
35
33
  readonly 'nx/src/hasher/task-hasher': typeof NxTaskHasher;
36
34
  readonly 'nx/src/native': typeof NxNative;
37
35
  readonly 'nx/src/project-graph/plugins/tasks-execution-hooks': typeof NxExecutionHooks;
38
- readonly 'nx/src/project-graph/project-graph': typeof NxProjectGraph;
39
36
  readonly 'nx/src/tasks-runner/cache': typeof NxCache;
40
37
  readonly 'nx/src/tasks-runner/create-task-graph': typeof NxCreateTaskGraph;
41
38
  readonly 'nx/src/tasks-runner/run-command': typeof NxRunCommand;
@@ -43,7 +40,6 @@ interface NxRuntimeModules {
43
40
  readonly 'nx/src/tasks-runner/utils': typeof NxTasksRunnerUtils;
44
41
  readonly 'nx/src/utils/cache-directory': typeof NxCacheDirectory;
45
42
  readonly 'nx/src/utils/command-line-utils': typeof NxCommandLineUtils;
46
- readonly 'nx/src/utils/exit-codes': typeof NxExitCodes;
47
43
  readonly 'nx/src/utils/perf-logging': typeof NxPerfLogging;
48
44
  readonly 'nx/src/utils/workspace-root': typeof NxWorkspaceRoot;
49
45
  }
@@ -99,7 +95,8 @@ export type MissReason =
99
95
  * `built` means the work was handed to Nx — which may have restored outputs
100
96
  * from the local cache rather than recompiled anything. The line `hit` draws is
101
97
  * "did this process have to do work", which is what a CLI wrapper needs in
102
- * order to decide whether to stay quiet.
98
+ * order to decide whether to stay quiet. A run writes only to stderr: stdout
99
+ * belongs to whatever the caller goes on to run.
103
100
  *
104
101
  * `failed` is an operational outcome, not an exception: the target ran and did
105
102
  * not succeed. A caller re-raises `signal` when there is one and exits with
@@ -225,7 +222,7 @@ export function unvouched<Entry>(entries: readonly Entry[], verdicts: readonly b
225
222
  * on every invocation. So it never spawns the `nx` CLI: a native filesystem
226
223
  * snapshot refreshes the daemon's inputs, the task hashes and on-disk output
227
224
  * verification are daemon round-trips, and the cache lookup is a local SQLite
228
- * read. Nx's task runner is only invoked once something needs running.
225
+ * read. Only a miss starts the workspace's `nx` CLI, to run the target.
229
226
  *
230
227
  * With the daemon disabled there is no probe to make — hashing would have to
231
228
  * build the project graph in this process, and no service holds the recorded
@@ -278,7 +275,7 @@ async function ensureBuiltInWorkspace(
278
275
  // this explicit fallback path, which also lets a deliberately minimal
279
276
  // checkout-local CLI stand in for Nx.
280
277
  if (process.env.NX_DAEMON === 'false') {
281
- return runViaCli(workspaceRoot, selector);
278
+ return runViaCli(workspaceRoot, selector, { kind: 'no-daemon', taskId: selectorTaskId(selector) });
282
279
  }
283
280
  // Nx rejects daemon access when the client package's version differs from
284
281
  // the workspace's running daemon. Resolve every runtime module from the
@@ -288,7 +285,7 @@ async function ensureBuiltInWorkspace(
288
285
  bindWorkspaceRoot(workspaceRoot, requireNx);
289
286
  const { daemonClient } = requireNx('nx/src/daemon/client/client');
290
287
  if (!daemonClient.enabled()) {
291
- return runViaCli(workspaceRoot, selector);
288
+ return runViaCli(workspaceRoot, selector, { kind: 'no-daemon', taskId: selectorTaskId(selector) });
292
289
  }
293
290
 
294
291
  // An outer Nx task exports its own cache-bypass setting to the process it
@@ -356,32 +353,33 @@ async function ensureBuiltInWorkspace(
356
353
 
357
354
  performance.mark('ensureBuilt:probe:start');
358
355
  let reason: MissReason | null;
359
- const selectorTaskId =
360
- selector.configuration === undefined
361
- ? `${selector.project}:${selector.target}`
362
- : `${selector.project}:${selector.target}:${selector.configuration}`;
363
356
  if (process.env.NX_SKIP_NX_CACHE === 'true' || process.env.NX_DISABLE_NX_CACHE === 'true') {
364
- reason = { kind: 'cache-disabled', taskId: selectorTaskId };
357
+ reason = { kind: 'cache-disabled', taskId: selectorTaskId(selector) };
365
358
  } else if (inputsChanged) {
366
- reason = { kind: 'stale-inputs', taskId: selectorTaskId };
359
+ reason = { kind: 'stale-inputs', taskId: selectorTaskId(selector) };
367
360
  } else {
368
361
  reason = await probe(workspaceRoot, nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx);
369
362
  }
370
363
  performance.measure('ensureBuilt:probe', 'ensureBuilt:probe:start');
371
- const outcome =
372
- reason === null
373
- ? { result: HIT, taskResults: NO_TASK_RESULTS }
374
- : await runTarget(nxJson, nxArgs, overrides, selector, reason, requireNx);
364
+ // The CLI runs the hooks around its own run, under its own id. This process
365
+ // ran none of the tasks, so it reports none for the id it opened.
366
+ const result = reason === null ? HIT : await runViaCli(workspaceRoot, selector, reason);
375
367
  await hooks.runPostTasksExecution({
376
368
  id: runId,
377
- taskResults: outcome.taskResults,
369
+ taskResults: NO_TASK_RESULTS,
378
370
  workspaceRoot,
379
371
  nxJsonConfiguration: nxJson,
380
372
  argv: process.argv,
381
373
  startTime,
382
374
  endTime: Date.now(),
383
375
  });
384
- return outcome.result;
376
+ return result;
377
+ }
378
+
379
+ function selectorTaskId(selector: TargetSelector): string {
380
+ return selector.configuration === undefined
381
+ ? `${selector.project}:${selector.target}`
382
+ : `${selector.project}:${selector.target}:${selector.configuration}`;
385
383
  }
386
384
 
387
385
  /**
@@ -797,78 +795,35 @@ function isSystemError(error: unknown): boolean {
797
795
  return error instanceof Error && 'code' in error && typeof error.code === 'string';
798
796
  }
799
797
 
800
- interface CompletedRun {
801
- readonly result: EnsureBuiltResult;
802
- readonly taskResults: TaskResults;
803
- }
804
-
805
- async function runTarget(
806
- nxJson: NxJsonConfiguration,
807
- nxArgs: NxArgs,
808
- overrides: Record<string, unknown>,
809
- selector: TargetSelector,
810
- reason: MissReason,
811
- requireNx: WorkspaceNxRequire,
812
- ): Promise<CompletedRun> {
813
- const { runCommandForTasks } = requireNx('nx/src/tasks-runner/run-command');
814
- const { createProjectGraphAsync } = requireNx('nx/src/project-graph/project-graph');
815
- const { signalToCode } = requireNx('nx/src/utils/exit-codes');
816
- // `runCommandForTasks` derives its own task graph and hashes, so the probe's
817
- // work is not reusable. That duplication is one daemon round-trip on a path
818
- // that is about to run a build.
819
- const projectGraph = await createProjectGraphAsync();
820
- const { taskResults, completed } = await runCommandForTasks(
821
- [requireProject(projectGraph, selector.project)],
822
- projectGraph,
823
- { nxJson },
824
- nxArgs,
825
- overrides,
826
- selector.project,
827
- {},
828
- { excludeTaskDependencies: false, loadDotEnvFiles: process.env.NX_LOAD_DOT_ENV_FILES !== 'false' },
829
- );
830
- if (!completed) {
831
- // Nx's own encoding of an interrupted run: `runCommand` reports
832
- // `signalToCode('SIGINT')` here. The runner does not surface which signal
833
- // actually arrived, so there is none to forward — only the code Nx's CLI
834
- // would have exited with.
835
- return {
836
- result: { disposition: 'failed', reason, exitCode: signalToCode('SIGINT'), signal: null },
837
- taskResults,
838
- };
839
- }
840
- for (const taskResult of Object.values(taskResults)) {
841
- if (taskResult.status === 'failure' || taskResult.status === 'skipped') {
842
- return { result: { disposition: 'failed', reason, exitCode: 1, signal: null }, taskResults };
843
- }
844
- }
845
- return { result: { disposition: 'built', reason }, taskResults };
846
- }
847
-
848
798
  /**
849
- * The daemon-disabled path: hand the target to the workspace's own `nx`, with
850
- * stdio inherited.
799
+ * Run the target through the workspace's own `nx`, the invocation whose hashes
800
+ * the probe reproduces, with the child's stdout on this process's stderr.
851
801
  *
852
- * Inheriting rather than piping is the point. The wrapper this facility
802
+ * A child, because Nx does not only write through `process.stdout`: its Rust
803
+ * pseudo-terminal and the forked executors it starts with inherited stdio
804
+ * write task output straight to file descriptor 1, and Node cannot point that
805
+ * descriptor elsewhere in its own process. In a child it is simply stderr, so
806
+ * the stdout of a wrapper that goes on to exec a binary carries nothing but
807
+ * that binary's output (`<cli> list | jq` reads only data).
808
+ *
809
+ * Inheriting rather than piping is the other half. The wrapper this facility
853
810
  * replaces piped Nx's output so it could read a cache marker out of the log and
854
811
  * stay silent on a hit — a text heuristic over ANSI-coloured, format-unstable
855
- * output. Without a daemon there is nothing to be silent about: no cheap probe
856
- * exists, so the run is unconditional, the output is the run's own, and the
857
- * child's exit status is forwarded verbatim.
812
+ * output. The probe already decided this is no hit, so the output is the run's
813
+ * own, and the child's exit status is forwarded verbatim.
858
814
  */
859
- async function runViaCli(workspaceRoot: string, selector: TargetSelector): Promise<EnsureBuiltResult> {
815
+ async function runViaCli(
816
+ workspaceRoot: string,
817
+ selector: TargetSelector,
818
+ reason: MissReason,
819
+ ): Promise<EnsureBuiltResult> {
860
820
  const nxCli = join(workspaceRoot, 'node_modules', '.bin', 'nx');
861
821
  if (!existsSync(nxCli)) {
862
- throw new Error(`ensureBuilt: the Nx daemon is disabled and ${nxCli} does not exist`);
863
- }
864
- const reason: MissReason = { kind: 'no-daemon', taskId: `${selector.project}:${selector.target}` };
865
- const targetSpec = selector.configuration
866
- ? `${selector.project}:${selector.target}:${selector.configuration}`
867
- : `${selector.project}:${selector.target}`;
868
- const signalToCode = nxSignalToCode;
869
- const child = spawn(nxCli, ['run', targetSpec, '--outputStyle=stream'], {
822
+ throw new Error(`ensureBuilt: ${describeMiss(reason)}, and ${nxCli} does not exist`);
823
+ }
824
+ const child = spawn(nxCli, ['run', selectorTaskId(selector), '--outputStyle=stream'], {
870
825
  cwd: workspaceRoot,
871
- stdio: 'inherit',
826
+ stdio: ['inherit', 2, 'inherit'],
872
827
  });
873
828
  // `Promise.withResolvers` would read better but needs lib es2024; this
874
829
  // package inherits lib es2022 from tsconfig.base.json.
@@ -876,7 +831,7 @@ async function runViaCli(workspaceRoot: string, selector: TargetSelector): Promi
876
831
  child.once('error', reject);
877
832
  child.once('exit', (code, signal) => settle({ code, signal }));
878
833
  });
879
- return cliExitOutcome(reason, exit, signalToCode);
834
+ return cliExitOutcome(reason, exit, nxSignalToCode);
880
835
  }
881
836
 
882
837
  function nxSignalToCode(signal: NodeJS.Signals | null): number {
package/src/index.test.ts CHANGED
@@ -12,7 +12,7 @@ import { BOUNDED_TEST_TIMEOUT_MS } from './bounded-test-policy.js';
12
12
  import { exceptionalTestFilter, packageNameFromCargoTestTarget } from './cargo-workspace.js';
13
13
  import { CARGO_CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET, CARGO_LINT_CLIPPY_COMMAND } from './cross-check-policy.js';
14
14
  import { createNodesV2, createNodesV2ForPlatform } from './index.js';
15
- import { applyWorkspaceConfig } from './workspace-config-policy.js';
15
+ import { applyWorkspaceConfig, RELEASE_CONFIGURATION } from './workspace-config-policy.js';
16
16
 
17
17
  const [, inferTargets] = createNodesV2;
18
18
 
@@ -895,9 +895,13 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
895
895
  /^cargo --frozen nextest archive --workspace --archive-file target\/nextest\/archive\.tar\.zst --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
896
896
  );
897
897
  expect(targets['cargo-test-archive']?.inputs).toContain('{projectRoot}/.config/nextest.toml');
898
- expect(String(targets['cargo-test-archive']?.configurations?.production?.commands?.[1])).toContain(
899
- 'nextest archive --workspace --release --archive-file',
900
- );
898
+ // Tests compile the dev profile only. Nx forwards a run's configuration
899
+ // down every edge to each target that has it, so a release configuration
900
+ // here would make a release `build` compile test binaries nobody runs.
901
+ for (const name of ['cargo-test-compile', 'cargo-test-archive', 'cargo-test', 'cargo-test-ferris-core', 'test']) {
902
+ expect(targets[name]).toBeDefined();
903
+ expect(targets[name]?.configurations?.[RELEASE_CONFIGURATION]).toBeUndefined();
904
+ }
901
905
  expect(targets['cargo-test-ferris-core']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-archive']);
902
906
  expect(targets['cargo-test-ferris-wasm']?.dependsOn).toEqual(['cargo-fetch', 'cargo-test-archive']);
903
907
  // The runner executes the archive's binaries and remaps the workspace
@@ -911,7 +915,6 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
911
915
  expect(targets['cargo-test-ferris-core']?.inputs).toContain(
912
916
  '{workspaceRoot}/packages/ferris/.config/nextest.toml',
913
917
  );
914
- expect(targets['cargo-test-ferris-core']?.configurations?.production).toEqual({});
915
918
  expect(targets['cargo-test-ferris-core']?.inputs).toEqual(
916
919
  expect.arrayContaining([
917
920
  '{workspaceRoot}/packages/ferris/Cargo.toml',
@@ -922,15 +925,15 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
922
925
  expect(targets['cargo-test-ferris-core']?.inputs).not.toContain(
923
926
  '{workspaceRoot}/packages/ferris/crates/ferris-wasm/**/*',
924
927
  );
925
- // One clippy for the workspace in one target dir: a per-crate closure
926
- // compiled every shared dependency once per crate.
927
- expect(targets['cargo-lint']?.options).toMatchObject({
928
- cwd: 'packages/ferris',
929
- commands: [
930
- 'cargo fmt --all --check',
931
- 'cargo --frozen clippy --workspace --all-targets --target-dir target/cargo-lint -- -D warnings',
932
- ],
933
- });
928
+ // One clippy for the workspace, writing the same `target/` as the dev
929
+ // test compile: a directory of its own compiled every host unit twice.
930
+ const [fmt, clippy] = targets['cargo-lint']?.options?.commands ?? [];
931
+ expect(fmt).toBe('cargo fmt --all --check');
932
+ expect(clippy).toMatch(/^cargo --frozen clippy --workspace --all-targets .*-- -D warnings$/);
933
+ for (const command of [clippy, targets['cargo-test-compile']?.options?.command]) {
934
+ expect(command).not.toContain('--target-dir');
935
+ }
936
+ expect(targets['cargo-lint']?.options?.cwd).toBe(targets['cargo-test-compile']?.options?.cwd);
934
937
  expect(targets['cargo-lint']?.cache).toBe(true);
935
938
  expect(targets['cargo-lint']?.outputs).toEqual([]);
936
939
  expect(targets['cargo-lint']?.inputs).toEqual(
@@ -965,15 +968,15 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
965
968
 
966
969
  const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
967
970
 
968
- // A clippy target dir is not an Nx output — restoring an 11 GiB build
971
+ // A clippy target dir is not an Nx output — restoring a multi-GiB build
969
972
  // tree from a cache is worse than rebuilding it — so `clean` cannot find
970
973
  // these through `outputs`. They are read back off the commands that
971
974
  // write them, which is why a new `--target-dir` cannot be forgotten here.
975
+ // The workspace `target/` every dev build shares is not one of them.
972
976
  expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
973
977
  expect(targets.clean?.cache).toBe(false);
974
978
  expect(targets.clean?.options?.outputs).toEqual([
975
979
  '{projectRoot}/dist',
976
- '{workspaceRoot}/packages/ferris/target/cargo-lint',
977
980
  '{workspaceRoot}/packages/ferris/target/cargo-lint-cross',
978
981
  '{workspaceRoot}/packages/ferris/target/nextest',
979
982
  ]);
@@ -1118,10 +1121,9 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1118
1121
  command: 'cargo --frozen test --workspace --no-run',
1119
1122
  cwd: '.',
1120
1123
  });
1121
- expect(root['cargo-lint']?.options?.commands).toEqual([
1122
- 'cargo fmt --all --check',
1123
- 'cargo --frozen clippy --workspace --all-targets --target-dir target/cargo-lint -- -D warnings',
1124
- ]);
1124
+ // The root owns the one workspace clippy, run where the dev build runs.
1125
+ expect(String(root['cargo-lint']?.options?.commands?.[1])).toContain('clippy --workspace');
1126
+ expect(root['cargo-lint']?.options?.cwd).toBe(root['cargo-test-compile']?.options?.cwd);
1125
1127
  expect(root['cargo-lint']?.dependsOn).toContain('cargo-fetch');
1126
1128
  expect(root['cargo-test']?.dependsOn).toHaveLength(5);
1127
1129
 
@@ -1149,9 +1151,16 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1149
1151
 
1150
1152
  expect(wasm['cargo-test-runtime-wasm']?.dependsOn).toEqual([rootFetch, rootArchive]);
1151
1153
  expect(wasm['cargo-wasm']?.options).toMatchObject({ cwd: '.' });
1152
- expect(wasm['cargo-wasm']?.options?.commands).toContain(
1153
- 'cargo --frozen build --release --target wasm32-unknown-unknown --target-dir target/cargo-wasm -p runtime-wasm',
1154
- );
1154
+ // Dev by default, in the workspace's own `target/`; only the release
1155
+ // configuration compiles, and binds, the release artifact.
1156
+ expect(wasm['cargo-wasm']?.options?.commands).toEqual([
1157
+ 'cargo --frozen build --target wasm32-unknown-unknown -p runtime-wasm',
1158
+ 'wasm-bindgen --target web --out-dir packages/wasm/dist-wasm/web target/wasm32-unknown-unknown/debug/runtime_wasm.wasm',
1159
+ ]);
1160
+ expect(wasm['cargo-wasm']?.configurations?.[RELEASE_CONFIGURATION]?.commands).toEqual([
1161
+ 'cargo --frozen build --release --target wasm32-unknown-unknown -p runtime-wasm',
1162
+ 'wasm-bindgen --target web --out-dir packages/wasm/dist-wasm/web target/wasm32-unknown-unknown/release/runtime_wasm.wasm',
1163
+ ]);
1155
1164
  expect(wasm['cargo-wasm']?.outputs).toEqual(['{projectRoot}/dist-wasm']);
1156
1165
  expect(wasm['cargo-wasm']?.dependsOn).toEqual([rootFetch, '^build']);
1157
1166
  expect(wasm.build?.dependsOn).toContainEqual(rootCompile);
@@ -1181,10 +1190,11 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1181
1190
  command:
1182
1191
  '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',
1183
1192
  });
1184
- expect(native['napi-arm64-macos']?.options).toMatchObject({
1185
- cwd: '.',
1186
- command:
1187
- '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',
1193
+ const platformBuild = (release: string): string =>
1194
+ `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`;
1195
+ expect(native['napi-arm64-macos']?.options).toMatchObject({ cwd: '.', command: platformBuild('') });
1196
+ expect(native['napi-arm64-macos']?.configurations?.[RELEASE_CONFIGURATION]).toEqual({
1197
+ command: platformBuild(' --release'),
1188
1198
  });
1189
1199
  expect(native.build?.dependsOn).toContainEqual(rootCompile);
1190
1200
  expect(native.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
@@ -1231,13 +1241,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1231
1241
  const leaf = projects.get('nested/modules/leaf')?.targets ?? {};
1232
1242
  // Each cargo workspace root runs one clippy over all its members; the
1233
1243
  // packages owning crates validate through that verdict.
1234
- expect(outer['cargo-lint']?.options).toMatchObject({
1235
- cwd: '.',
1236
- commands: [
1237
- 'cargo fmt --all --check',
1238
- 'cargo --frozen clippy --workspace --all-targets --target-dir target/cargo-lint -- -D warnings',
1239
- ],
1240
- });
1244
+ expect(outer['cargo-lint']?.options?.cwd).toBe('.');
1245
+ expect(String(outer['cargo-lint']?.options?.commands?.[1])).toContain('clippy --workspace');
1241
1246
  // Workspace-anchored, because Nx hashes a `{projectRoot}` glob against
1242
1247
  // only the files its project owns, and the group project owns alpha and
1243
1248
  // beta: spelled from the root project, those globs hash nothing and the
@@ -1274,9 +1279,6 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1274
1279
  { projects: ['inner-root'], target: 'cargo-fetch' },
1275
1280
  { projects: ['inner-root'], target: 'cargo-test-archive' },
1276
1281
  ]);
1277
- // The profile lives in the archive, so the runner's production
1278
- // configuration has nothing left to say.
1279
- expect(leaf['cargo-test-inner-leaf']?.configurations?.production).toEqual({});
1280
1282
  expect(inner['cargo-test-archive']?.options?.cwd).toBe('nested');
1281
1283
  expect(resolveDeclaredOverInferred(group, declared, 'cargo-lint')).toMatchObject({
1282
1284
  executor: 'nx:noop',
@@ -1428,14 +1430,22 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1428
1430
  outputs: ['{projectRoot}/generated/wasm'],
1429
1431
  options: {
1430
1432
  commands: [
1431
- 'cargo --frozen build --release --target wasm32-unknown-unknown --target-dir crates/git-do/target/cargo-wasm --manifest-path crates/git-do/Cargo.toml',
1432
- 'wasm-bindgen --target nodejs --out-dir generated/wasm/node crates/git-do/target/cargo-wasm/wasm32-unknown-unknown/release/gitoxide_engine.wasm',
1433
- 'wasm-bindgen --target web --out-dir generated/wasm/web crates/git-do/target/cargo-wasm/wasm32-unknown-unknown/release/gitoxide_engine.wasm',
1433
+ 'cargo --frozen build --target wasm32-unknown-unknown --manifest-path crates/git-do/Cargo.toml',
1434
+ 'wasm-bindgen --target nodejs --out-dir generated/wasm/node crates/git-do/target/wasm32-unknown-unknown/debug/gitoxide_engine.wasm',
1435
+ 'wasm-bindgen --target web --out-dir generated/wasm/web crates/git-do/target/wasm32-unknown-unknown/debug/gitoxide_engine.wasm',
1434
1436
  ],
1435
1437
  cwd: 'packages/git-do',
1436
1438
  parallel: false,
1437
1439
  },
1438
1440
  });
1441
+ // No workspace claims the crate, so cargo's default target dir is the one
1442
+ // beside its own manifest, and the release configuration reads the
1443
+ // release artifact from it.
1444
+ expect(targets['cargo-wasm']?.configurations?.[RELEASE_CONFIGURATION]?.commands).toEqual([
1445
+ 'cargo --frozen build --release --target wasm32-unknown-unknown --manifest-path crates/git-do/Cargo.toml',
1446
+ 'wasm-bindgen --target nodejs --out-dir generated/wasm/node crates/git-do/target/wasm32-unknown-unknown/release/gitoxide_engine.wasm',
1447
+ 'wasm-bindgen --target web --out-dir generated/wasm/web crates/git-do/target/wasm32-unknown-unknown/release/gitoxide_engine.wasm',
1448
+ ]);
1439
1449
  // A wasm-bindgen crate in a nested Cargo workspace still needs its locked
1440
1450
  // graph downloaded, and the project root is not a member of it, so the
1441
1451
  // fetch names the crate manifest instead of relying on cwd.
@@ -1528,14 +1538,23 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1528
1538
  options: {
1529
1539
  cwd: 'packages/cowshed',
1530
1540
  command:
1531
- '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',
1541
+ '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 dist/native/host',
1542
+ },
1543
+ configurations: {
1544
+ [RELEASE_CONFIGURATION]: {
1545
+ command:
1546
+ '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',
1547
+ },
1532
1548
  },
1533
1549
  });
1534
1550
  expect(unservedHostTargets.build?.dependsOn).toEqual(['^build', 'cargo-test-compile', 'cargo-napi', 'tsc-js']);
1535
1551
  expect(targets['napi-arm64-macos']?.outputs).toEqual(['{projectRoot}/dist/native/darwin-arm64']);
1536
- expect(targets['napi-arm64-macos']?.options).toMatchObject({
1537
- command:
1538
- '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',
1552
+ // Every local build compiles dev; only the release configuration ships.
1553
+ const darwinArm64Build = (release: string): string =>
1554
+ `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`;
1555
+ expect(targets['napi-arm64-macos']?.options).toMatchObject({ command: darwinArm64Build('') });
1556
+ expect(targets['napi-arm64-macos']?.configurations?.[RELEASE_CONFIGURATION]).toEqual({
1557
+ command: darwinArm64Build(' --release'),
1539
1558
  });
1540
1559
  expect(targets['napi-arm64-macos']?.options?.env).toBeUndefined();
1541
1560
  // No cargo-test-compile edge here, on ANY host: a platform target's
@@ -1596,7 +1615,10 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1596
1615
  expect(darwinArm64Targets['napi-arm64-linux']?.dependsOn).toEqual(['napi-toolchain-arm64-linux']);
1597
1616
  expect(darwinArm64Targets['napi-x64-linux']?.outputs).toEqual(['{projectRoot}/dist/native/linux-x64-gnu']);
1598
1617
  expect(darwinArm64Targets['napi-x64-linux']?.options?.command).toBe(
1599
- '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',
1618
+ 'napi build --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',
1619
+ );
1620
+ expect(darwinArm64Targets['napi-x64-linux']?.configurations?.[RELEASE_CONFIGURATION]?.command).toContain(
1621
+ 'napi build --release --platform',
1600
1622
  );
1601
1623
 
1602
1624
  // The whole rule, stated once per forced host: a triple gets a cross
@@ -1743,6 +1765,29 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1743
1765
  }
1744
1766
  });
1745
1767
 
1768
+ it('binds the wasm a package workspace member writes into that workspace target dir', async () => {
1769
+ const workspace = await createWorkspace();
1770
+ try {
1771
+ await workspace.write('packages/columine/package.json', '{"name":"columine"}\n');
1772
+ await workspace.write('packages/columine/Cargo.toml', '[workspace]\nmembers = ["crates/columine-wasm"]\n');
1773
+ await workspace.write(
1774
+ 'packages/columine/crates/columine-wasm/Cargo.toml',
1775
+ '[package]\nname = "columine-wasm"\n\n[lib]\ncrate-type = ["cdylib", "rlib"]\n\n[package.metadata.smoothbricks.wasm-bindgen]\ntargets = ["web"]\n',
1776
+ );
1777
+
1778
+ const targets = await inferProjectTargets(workspace, 'packages/columine/package.json');
1779
+
1780
+ // Cargo writes a member's artifacts under its workspace root, not beside
1781
+ // the member's manifest, so the bindgen input is read from there.
1782
+ expect(targets['cargo-wasm']?.options?.commands).toEqual([
1783
+ 'cargo --frozen build --target wasm32-unknown-unknown --manifest-path crates/columine-wasm/Cargo.toml',
1784
+ 'wasm-bindgen --target web --out-dir dist-wasm/web target/wasm32-unknown-unknown/debug/columine_wasm.wasm',
1785
+ ]);
1786
+ } finally {
1787
+ await workspace.cleanup();
1788
+ }
1789
+ });
1790
+
1746
1791
  it('shards a crate around the tests nextest.toml singles out, not through them', async () => {
1747
1792
  const workspace = await createWorkspace();
1748
1793
  try {
@@ -1897,8 +1942,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1897
1942
  const workspace = await createWorkspace();
1898
1943
  const declared: Record<string, TargetConfiguration> = {
1899
1944
  // One added edge per target. Everything that makes each target do its job
1900
- // — executor, options, inputs, cache, configurations — must survive the
1901
- // declaration instead of being replaced wholesale by it.
1945
+ // — executor, options, inputs, cache — must survive the declaration
1946
+ // instead of being replaced wholesale by it.
1902
1947
  'cargo-test': { dependsOn: ['cargo-test-compile', 'cargo-wasm'] },
1903
1948
  'cargo-test-compile': { dependsOn: ['cargo-wasm'] },
1904
1949
  'cargo-lint': { inputs: ['{projectRoot}/clippy.toml'] },
@@ -1933,9 +1978,6 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1933
1978
  timeoutMs: 120000,
1934
1979
  killAfterMs: 10000,
1935
1980
  });
1936
- expect(cargoTest?.configurations).toEqual({
1937
- production: { command: 'cargo --frozen test --workspace --release' },
1938
- });
1939
1981
  expect(cargoTest?.inputs).toContain('{projectRoot}/**/*.rs');
1940
1982
 
1941
1983
  const cargoTestCompile = resolveDeclaredOverInferred(targets, declared, 'cargo-test-compile');
@@ -2244,9 +2286,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
2244
2286
  expect(String(archive?.options?.commands?.[1])).toMatch(
2245
2287
  /^cargo-nextest nextest archive --workspace --target aarch64-apple-darwin --frozen --archive-file target\/nextest\/archive-aarch64-apple-darwin\.tar\.zst --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
2246
2288
  );
2247
- expect(String(archive?.configurations?.production?.commands?.[1])).toContain(
2248
- 'nextest archive --workspace --release --target aarch64-apple-darwin',
2249
- );
2289
+ expect(archive?.configurations?.[RELEASE_CONFIGURATION]).toBeUndefined();
2290
+ expect(run?.configurations?.[RELEASE_CONFIGURATION]).toBeUndefined();
2250
2291
  // The archive BUILDS, so it needs the locked registry graph; the runner
2251
2292
  // never touches cargo, so it needs nothing and depends on nothing.
2252
2293
  expect(archive?.dependsOn).toEqual(['cargo-fetch']);