@smoothbricks/nx-plugin 0.4.22 → 0.4.24

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 (72) hide show
  1. package/README.md +93 -33
  2. package/dist/bin/smoo-nx-exec.js +35 -11
  3. package/dist/bin/smoo-nx-nextest-extract.d.ts +3 -0
  4. package/dist/bin/smoo-nx-nextest-extract.d.ts.map +1 -0
  5. package/dist/bin/smoo-nx-nextest-extract.js +41 -0
  6. package/dist/cargo-closure-input.d.ts +63 -0
  7. package/dist/cargo-closure-input.d.ts.map +1 -0
  8. package/dist/cargo-closure-input.js +197 -0
  9. package/dist/cargo-source-hash.d.ts +37 -0
  10. package/dist/cargo-source-hash.d.ts.map +1 -1
  11. package/dist/cargo-source-hash.js +108 -190
  12. package/dist/cross-check-policy.d.ts +14 -0
  13. package/dist/cross-check-policy.d.ts.map +1 -1
  14. package/dist/cross-check-policy.js +15 -1
  15. package/dist/ensure-built.d.ts +3 -2
  16. package/dist/ensure-built.d.ts.map +1 -1
  17. package/dist/ensure-built.js +33 -56
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +152 -91
  20. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  21. package/dist/managed-files/ci-workflow.js +12 -15
  22. package/dist/managed-files/files.d.ts.map +1 -1
  23. package/dist/managed-files/files.js +10 -0
  24. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  25. package/dist/managed-files/publish-workflow.js +12 -6
  26. package/dist/manifest-hash.d.ts.map +1 -1
  27. package/dist/manifest-hash.js +24 -30
  28. package/dist/nextest-extraction.d.ts +101 -0
  29. package/dist/nextest-extraction.d.ts.map +1 -0
  30. package/dist/nextest-extraction.js +268 -0
  31. package/dist/package-target-policy.js +1 -1
  32. package/dist/platform-targets.d.ts +7 -0
  33. package/dist/platform-targets.d.ts.map +1 -1
  34. package/dist/platform-targets.js +7 -0
  35. package/dist/workspace-config-policy.d.ts +1 -1
  36. package/dist/workspace-config-policy.d.ts.map +1 -1
  37. package/dist/workspace-config-policy.js +1 -1
  38. package/managed/raw/envrc +38 -1
  39. package/managed/raw/tooling/direnv/developer-links.ts +201 -0
  40. package/managed/raw/tooling/direnv/devenv.smoo.nix +75 -51
  41. package/managed/raw/tooling/direnv/secret-references.ts +3 -1
  42. package/managed/raw/tooling/direnv/setup-environment.ts +562 -78
  43. package/managed/raw/tooling/direnv/shared-caches.sh +53 -0
  44. package/managed/raw/tooling/git-hooks/pre-push.sh +22 -1
  45. package/managed/templates/github/workflows/managed-files.yml +4 -3
  46. package/nextest.toml +5 -5
  47. package/package.json +4 -3
  48. package/src/__tests__/fixture-nx-env.ts +31 -0
  49. package/src/__tests__/in-process-nx-index.ts +9 -0
  50. package/src/bin/smoo-nx-exec.ts +40 -11
  51. package/src/bin/smoo-nx-nextest-extract.ts +43 -0
  52. package/src/bounded-test-policy.test.ts +4 -1
  53. package/src/cargo-closure-input.test.ts +184 -0
  54. package/src/cargo-closure-input.ts +247 -0
  55. package/src/cargo-source-hash.test.ts +8 -9
  56. package/src/cargo-source-hash.ts +146 -47
  57. package/src/cross-check-policy.ts +15 -3
  58. package/src/ensure-built.test.ts +65 -5
  59. package/src/ensure-built.ts +40 -85
  60. package/src/index.test.ts +222 -75
  61. package/src/index.ts +213 -101
  62. package/src/managed-files/ci-workflow.ts +12 -15
  63. package/src/managed-files/files.ts +10 -0
  64. package/src/managed-files/generator.test.ts +29 -0
  65. package/src/managed-files/publish-workflow.ts +17 -6
  66. package/src/manifest-hash.test.ts +21 -1
  67. package/src/manifest-hash.ts +26 -29
  68. package/src/nextest-extraction.test.ts +74 -0
  69. package/src/nextest-extraction.ts +329 -0
  70. package/src/package-target-policy.ts +1 -1
  71. package/src/platform-targets.ts +8 -0
  72. package/src/workspace-config-policy.ts +6 -1
package/src/index.test.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from 'bun:test';
2
- import { mkdir, mkdtemp, readFile, rm, symlink, writeFile } from 'node:fs/promises';
2
+ import { chmod, mkdir, mkdtemp, readdir, readFile, 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';
@@ -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,23 +895,28 @@ 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
- // The runner executes the archive's binaries and remaps the workspace
904
- // root: without `--workspace-remap`, a restored archive hands tests the
905
- // PRODUCING tree's absolute CARGO_MANIFEST_DIR (measured on a moved tree).
906
- // `--workspace` is not merely redundant here, nextest rejects it with
907
- // `--archive-file`.
907
+ // The runner executes the archive's binaries, unpacked once for every
908
+ // runner by the plugin's helper (through the root `node_modules` link,
909
+ // so the hashed command names no machine path), and remaps the
910
+ // workspace root: without `--workspace-remap`, a restored archive hands
911
+ // tests the PRODUCING tree's absolute CARGO_MANIFEST_DIR (measured on a
912
+ // moved tree). `--workspace` is not merely redundant here, nextest
913
+ // rejects it beside a reused build.
908
914
  expect(targets['cargo-test-ferris-core']?.options?.command).toMatch(
909
- /^cargo --frozen nextest run --archive-file target\/nextest\/archive\.tar\.zst --workspace-remap \. -E 'package\(ferris-core\)' --no-tests=pass --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
915
+ /^extracted="\$\(node \.\.\/\.\.\/node_modules\/@smoothbricks\/nx-plugin\/dist\/bin\/smoo-nx-nextest-extract\.js target\/nextest\/archive\.tar\.zst\)" && cargo --frozen nextest run --binaries-metadata "\$extracted\/target\/nextest\/binaries-metadata\.json" --cargo-metadata "\$extracted\/target\/nextest\/cargo-metadata\.json" --target-dir-remap "\$extracted\/target" --workspace-remap \. -E 'package\(ferris-core\)' --no-tests=pass --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
910
916
  );
911
917
  expect(targets['cargo-test-ferris-core']?.inputs).toContain(
912
918
  '{workspaceRoot}/packages/ferris/.config/nextest.toml',
913
919
  );
914
- expect(targets['cargo-test-ferris-core']?.configurations?.production).toEqual({});
915
920
  expect(targets['cargo-test-ferris-core']?.inputs).toEqual(
916
921
  expect.arrayContaining([
917
922
  '{workspaceRoot}/packages/ferris/Cargo.toml',
@@ -922,15 +927,15 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
922
927
  expect(targets['cargo-test-ferris-core']?.inputs).not.toContain(
923
928
  '{workspaceRoot}/packages/ferris/crates/ferris-wasm/**/*',
924
929
  );
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
- });
930
+ // One clippy for the workspace, writing the same `target/` as the dev
931
+ // test compile: a directory of its own compiled every host unit twice.
932
+ const [fmt, clippy] = targets['cargo-lint']?.options?.commands ?? [];
933
+ expect(fmt).toBe('cargo fmt --all --check');
934
+ expect(clippy).toMatch(/^cargo --frozen clippy --workspace --all-targets .*-- -D warnings$/);
935
+ for (const command of [clippy, targets['cargo-test-compile']?.options?.command]) {
936
+ expect(command).not.toContain('--target-dir');
937
+ }
938
+ expect(targets['cargo-lint']?.options?.cwd).toBe(targets['cargo-test-compile']?.options?.cwd);
934
939
  expect(targets['cargo-lint']?.cache).toBe(true);
935
940
  expect(targets['cargo-lint']?.outputs).toEqual([]);
936
941
  expect(targets['cargo-lint']?.inputs).toEqual(
@@ -965,15 +970,15 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
965
970
 
966
971
  const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
967
972
 
968
- // A clippy target dir is not an Nx output — restoring an 11 GiB build
973
+ // A clippy target dir is not an Nx output — restoring a multi-GiB build
969
974
  // tree from a cache is worse than rebuilding it — so `clean` cannot find
970
975
  // these through `outputs`. They are read back off the commands that
971
976
  // write them, which is why a new `--target-dir` cannot be forgotten here.
977
+ // The workspace `target/` every dev build shares is not one of them.
972
978
  expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
973
979
  expect(targets.clean?.cache).toBe(false);
974
980
  expect(targets.clean?.options?.outputs).toEqual([
975
981
  '{projectRoot}/dist',
976
- '{workspaceRoot}/packages/ferris/target/cargo-lint',
977
982
  '{workspaceRoot}/packages/ferris/target/cargo-lint-cross',
978
983
  '{workspaceRoot}/packages/ferris/target/nextest',
979
984
  ]);
@@ -1118,10 +1123,9 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1118
1123
  command: 'cargo --frozen test --workspace --no-run',
1119
1124
  cwd: '.',
1120
1125
  });
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
- ]);
1126
+ // The root owns the one workspace clippy, run where the dev build runs.
1127
+ expect(String(root['cargo-lint']?.options?.commands?.[1])).toContain('clippy --workspace');
1128
+ expect(root['cargo-lint']?.options?.cwd).toBe(root['cargo-test-compile']?.options?.cwd);
1125
1129
  expect(root['cargo-lint']?.dependsOn).toContain('cargo-fetch');
1126
1130
  expect(root['cargo-test']?.dependsOn).toHaveLength(5);
1127
1131
 
@@ -1132,8 +1136,12 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1132
1136
  expect(runtime['cargo-test-runtime-core-shard2']?.dependsOn).toEqual([rootFetch, rootArchive]);
1133
1137
  expect(runtime['cargo-test-runtime-core-exceptions']?.dependsOn).toEqual([rootFetch, rootArchive]);
1134
1138
  expect(runtime['cargo-test-runtime-core-shard1']?.options).toMatchObject({ cwd: '.' });
1139
+ // At the root the helper is the root's own `node_modules` link, no `../`.
1140
+ expect(runtime['cargo-test-runtime-core-shard1']?.options?.command).toStartWith(
1141
+ 'extracted="$(node node_modules/@smoothbricks/nx-plugin/dist/bin/smoo-nx-nextest-extract.js target/nextest/archive.tar.zst)" && ',
1142
+ );
1135
1143
  expect(runtime['cargo-test-runtime-core-shard1']?.options?.command).toContain(
1136
- "nextest run --archive-file target/nextest/archive.tar.zst --workspace-remap . -E 'package(runtime-core)",
1144
+ `--target-dir-remap "$extracted/target" --workspace-remap . -E 'package(runtime-core)`,
1137
1145
  );
1138
1146
  expect(native['cargo-test-native-napi']?.options?.command).toContain('--no-tests=pass');
1139
1147
  expect(runtime['cargo-test']?.dependsOn).toEqual([
@@ -1149,9 +1157,16 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1149
1157
 
1150
1158
  expect(wasm['cargo-test-runtime-wasm']?.dependsOn).toEqual([rootFetch, rootArchive]);
1151
1159
  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
- );
1160
+ // Dev by default, in the workspace's own `target/`; only the release
1161
+ // configuration compiles, and binds, the release artifact.
1162
+ expect(wasm['cargo-wasm']?.options?.commands).toEqual([
1163
+ 'cargo --frozen build --target wasm32-unknown-unknown -p runtime-wasm',
1164
+ 'wasm-bindgen --target web --out-dir packages/wasm/dist-wasm/web target/wasm32-unknown-unknown/debug/runtime_wasm.wasm',
1165
+ ]);
1166
+ expect(wasm['cargo-wasm']?.configurations?.[RELEASE_CONFIGURATION]?.commands).toEqual([
1167
+ 'cargo --frozen build --release --target wasm32-unknown-unknown -p runtime-wasm',
1168
+ 'wasm-bindgen --target web --out-dir packages/wasm/dist-wasm/web target/wasm32-unknown-unknown/release/runtime_wasm.wasm',
1169
+ ]);
1155
1170
  expect(wasm['cargo-wasm']?.outputs).toEqual(['{projectRoot}/dist-wasm']);
1156
1171
  expect(wasm['cargo-wasm']?.dependsOn).toEqual([rootFetch, '^build']);
1157
1172
  expect(wasm.build?.dependsOn).toContainEqual(rootCompile);
@@ -1181,10 +1196,11 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1181
1196
  command:
1182
1197
  '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
1198
  });
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',
1199
+ const platformBuild = (release: string): string =>
1200
+ `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`;
1201
+ expect(native['napi-arm64-macos']?.options).toMatchObject({ cwd: '.', command: platformBuild('') });
1202
+ expect(native['napi-arm64-macos']?.configurations?.[RELEASE_CONFIGURATION]).toEqual({
1203
+ command: platformBuild(' --release'),
1188
1204
  });
1189
1205
  expect(native.build?.dependsOn).toContainEqual(rootCompile);
1190
1206
  expect(native.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
@@ -1231,13 +1247,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1231
1247
  const leaf = projects.get('nested/modules/leaf')?.targets ?? {};
1232
1248
  // Each cargo workspace root runs one clippy over all its members; the
1233
1249
  // 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
- });
1250
+ expect(outer['cargo-lint']?.options?.cwd).toBe('.');
1251
+ expect(String(outer['cargo-lint']?.options?.commands?.[1])).toContain('clippy --workspace');
1241
1252
  // Workspace-anchored, because Nx hashes a `{projectRoot}` glob against
1242
1253
  // only the files its project owns, and the group project owns alpha and
1243
1254
  // beta: spelled from the root project, those globs hash nothing and the
@@ -1274,9 +1285,6 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1274
1285
  { projects: ['inner-root'], target: 'cargo-fetch' },
1275
1286
  { projects: ['inner-root'], target: 'cargo-test-archive' },
1276
1287
  ]);
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
1288
  expect(inner['cargo-test-archive']?.options?.cwd).toBe('nested');
1281
1289
  expect(resolveDeclaredOverInferred(group, declared, 'cargo-lint')).toMatchObject({
1282
1290
  executor: 'nx:noop',
@@ -1375,12 +1383,12 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1375
1383
  // Scoped by filterset over one archived workspace build: exactly one
1376
1384
  // crate runs, and no `-p` re-resolves its features.
1377
1385
  expect(cargoPackageSelection(String(targets['cargo-test-ferris-core']?.options?.command ?? ''))).toEqual({
1378
- archiveRun: true,
1386
+ prebuiltRun: true,
1379
1387
  packageFlags: [],
1380
1388
  filtered: ['ferris-core'],
1381
1389
  });
1382
1390
  expect(cargoPackageSelection(String(targets['cargo-test-ferris-wasm']?.options?.command ?? ''))).toEqual({
1383
- archiveRun: true,
1391
+ prebuiltRun: true,
1384
1392
  packageFlags: [],
1385
1393
  filtered: ['ferris-wasm'],
1386
1394
  });
@@ -1392,6 +1400,106 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1392
1400
  }
1393
1401
  });
1394
1402
 
1403
+ it('extracts the test archive once for all per-crate runners, and again only when its bytes change', async () => {
1404
+ const workspace = await createWorkspace();
1405
+ const root = workspace.context.workspaceRoot;
1406
+ const crates = ['ferris-a', 'ferris-b', 'ferris-c'];
1407
+ try {
1408
+ await workspace.write('packages/ferris/package.json', '{"name":"ferris"}\n');
1409
+ await workspace.write('packages/ferris/Cargo.toml', '[workspace]\nmembers = ["crates/*"]\n');
1410
+ for (const crate of crates) {
1411
+ await workspace.write(`packages/ferris/crates/${crate}/Cargo.toml`, `[package]\nname = "${crate}"\n`);
1412
+ }
1413
+ const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
1414
+ // Installed the way a consumer has it, so each command finds the helper it names.
1415
+ await mkdir(join(root, 'node_modules/@smoothbricks'), { recursive: true });
1416
+ await symlink(fileURLToPath(new URL('..', import.meta.url)), join(root, 'node_modules/@smoothbricks/nx-plugin'));
1417
+ // A cargo that does what nextest does with an archive, and says so: an
1418
+ // `--archive-file` unpacks it (into `--extract-to`, or a private temp
1419
+ // dir when a run is given the archive itself), and a run reports which
1420
+ // archive's binaries it executed.
1421
+ const log = join(root, 'nextest.log');
1422
+ await workspace.write(
1423
+ 'bin/cargo',
1424
+ [
1425
+ '#!/bin/sh',
1426
+ 'archive= dest= binaries=',
1427
+ 'while [ $# -gt 0 ]; do',
1428
+ ' case "$1" in',
1429
+ ' --archive-file) archive=$2; shift ;;',
1430
+ ' --extract-to) dest=$2; shift ;;',
1431
+ ' --binaries-metadata) binaries=$2; shift ;;',
1432
+ ' esac',
1433
+ ' shift',
1434
+ 'done',
1435
+ 'if [ -n "$archive" ]; then',
1436
+ ' echo "extract $(cat "$archive")" >> "$FAKE_NEXTEST_LOG"',
1437
+ ' if [ -z "$dest" ]; then echo "run $(cat "$archive")" >> "$FAKE_NEXTEST_LOG"; exit 0; fi',
1438
+ ' mkdir -p "$dest/target/nextest"',
1439
+ ' cat "$archive" > "$dest/target/nextest/binaries-metadata.json"',
1440
+ ' cat "$archive" > "$dest/target/nextest/cargo-metadata.json"',
1441
+ ' exit 0',
1442
+ 'fi',
1443
+ 'echo "run $(cat "$binaries")" >> "$FAKE_NEXTEST_LOG"',
1444
+ '',
1445
+ ].join('\n'),
1446
+ );
1447
+ await chmod(join(root, 'bin/cargo'), 0o755);
1448
+ // Every runner at once, through `sh -c` exactly as bounded-exec spawns it.
1449
+ const runAll = () =>
1450
+ Promise.all(
1451
+ crates.map(async (crate) => {
1452
+ const options = targets[`cargo-test-${crate}`]?.options;
1453
+ const child = Bun.spawn(['sh', '-c', String(options?.command)], {
1454
+ cwd: join(root, String(options?.cwd)),
1455
+ env: { ...process.env, PATH: `${join(root, 'bin')}:${process.env.PATH}`, FAKE_NEXTEST_LOG: log },
1456
+ stdout: 'pipe',
1457
+ stderr: 'pipe',
1458
+ });
1459
+ const [exitCode, stderr] = await Promise.all([child.exited, new Response(child.stderr).text()]);
1460
+ return { crate, exitCode, stderr };
1461
+ }),
1462
+ );
1463
+
1464
+ await workspace.write('packages/ferris/target/nextest/archive.tar.zst', 'first archive');
1465
+ for (const run of await runAll()) {
1466
+ expect(run).toMatchObject({ exitCode: 0 });
1467
+ }
1468
+ expect((await readFile(log, 'utf8')).trim().split('\n').sort()).toEqual([
1469
+ 'extract first archive',
1470
+ 'run first archive',
1471
+ 'run first archive',
1472
+ 'run first archive',
1473
+ ]);
1474
+
1475
+ // A rebuilt archive is new bytes at the same path: the runners must not
1476
+ // execute what the old one unpacked, and the old unpacking is garbage.
1477
+ await workspace.write('packages/ferris/target/nextest/archive.tar.zst', 'second archive');
1478
+ for (const run of await runAll()) {
1479
+ expect(run).toMatchObject({ exitCode: 0 });
1480
+ }
1481
+ expect((await readFile(log, 'utf8')).trim().split('\n').sort()).toEqual([
1482
+ 'extract first archive',
1483
+ 'extract second archive',
1484
+ 'run first archive',
1485
+ 'run first archive',
1486
+ 'run first archive',
1487
+ 'run second archive',
1488
+ 'run second archive',
1489
+ 'run second archive',
1490
+ ]);
1491
+ const target = join(root, 'packages/ferris/target');
1492
+ const unpacked = (await readdir(target, { recursive: true })).filter((path) =>
1493
+ path.endsWith('binaries-metadata.json'),
1494
+ );
1495
+ expect(await Promise.all(unpacked.map((path) => readFile(join(target, path), 'utf8')))).toEqual([
1496
+ 'second archive',
1497
+ ]);
1498
+ } finally {
1499
+ await workspace.cleanup();
1500
+ }
1501
+ });
1502
+
1395
1503
  it('infers a cached Cargo Wasm build directly from crate metadata', async () => {
1396
1504
  const workspace = await createWorkspace();
1397
1505
  try {
@@ -1428,14 +1536,22 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1428
1536
  outputs: ['{projectRoot}/generated/wasm'],
1429
1537
  options: {
1430
1538
  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',
1539
+ 'cargo --frozen build --target wasm32-unknown-unknown --manifest-path crates/git-do/Cargo.toml',
1540
+ 'wasm-bindgen --target nodejs --out-dir generated/wasm/node crates/git-do/target/wasm32-unknown-unknown/debug/gitoxide_engine.wasm',
1541
+ 'wasm-bindgen --target web --out-dir generated/wasm/web crates/git-do/target/wasm32-unknown-unknown/debug/gitoxide_engine.wasm',
1434
1542
  ],
1435
1543
  cwd: 'packages/git-do',
1436
1544
  parallel: false,
1437
1545
  },
1438
1546
  });
1547
+ // No workspace claims the crate, so cargo's default target dir is the one
1548
+ // beside its own manifest, and the release configuration reads the
1549
+ // release artifact from it.
1550
+ expect(targets['cargo-wasm']?.configurations?.[RELEASE_CONFIGURATION]?.commands).toEqual([
1551
+ 'cargo --frozen build --release --target wasm32-unknown-unknown --manifest-path crates/git-do/Cargo.toml',
1552
+ 'wasm-bindgen --target nodejs --out-dir generated/wasm/node crates/git-do/target/wasm32-unknown-unknown/release/gitoxide_engine.wasm',
1553
+ 'wasm-bindgen --target web --out-dir generated/wasm/web crates/git-do/target/wasm32-unknown-unknown/release/gitoxide_engine.wasm',
1554
+ ]);
1439
1555
  // A wasm-bindgen crate in a nested Cargo workspace still needs its locked
1440
1556
  // graph downloaded, and the project root is not a member of it, so the
1441
1557
  // fetch names the crate manifest instead of relying on cwd.
@@ -1528,14 +1644,23 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1528
1644
  options: {
1529
1645
  cwd: 'packages/cowshed',
1530
1646
  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',
1647
+ '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',
1648
+ },
1649
+ configurations: {
1650
+ [RELEASE_CONFIGURATION]: {
1651
+ command:
1652
+ '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',
1653
+ },
1532
1654
  },
1533
1655
  });
1534
1656
  expect(unservedHostTargets.build?.dependsOn).toEqual(['^build', 'cargo-test-compile', 'cargo-napi', 'tsc-js']);
1535
1657
  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',
1658
+ // Every local build compiles dev; only the release configuration ships.
1659
+ const darwinArm64Build = (release: string): string =>
1660
+ `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`;
1661
+ expect(targets['napi-arm64-macos']?.options).toMatchObject({ command: darwinArm64Build('') });
1662
+ expect(targets['napi-arm64-macos']?.configurations?.[RELEASE_CONFIGURATION]).toEqual({
1663
+ command: darwinArm64Build(' --release'),
1539
1664
  });
1540
1665
  expect(targets['napi-arm64-macos']?.options?.env).toBeUndefined();
1541
1666
  // No cargo-test-compile edge here, on ANY host: a platform target's
@@ -1596,7 +1721,10 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1596
1721
  expect(darwinArm64Targets['napi-arm64-linux']?.dependsOn).toEqual(['napi-toolchain-arm64-linux']);
1597
1722
  expect(darwinArm64Targets['napi-x64-linux']?.outputs).toEqual(['{projectRoot}/dist/native/linux-x64-gnu']);
1598
1723
  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',
1724
+ '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',
1725
+ );
1726
+ expect(darwinArm64Targets['napi-x64-linux']?.configurations?.[RELEASE_CONFIGURATION]?.command).toContain(
1727
+ 'napi build --release --platform',
1600
1728
  );
1601
1729
 
1602
1730
  // The whole rule, stated once per forced host: a triple gets a cross
@@ -1680,7 +1808,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1680
1808
  'napi-debug',
1681
1809
  ]);
1682
1810
  expect(targets['cargo-test-cowshed-napi']?.options?.command).toMatch(
1683
- /^cargo --frozen nextest run --archive-file target\/nextest\/archive\.tar\.zst --workspace-remap \. -E 'package\(cowshed-napi\)' --no-tests=pass --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
1811
+ /^extracted="\$\(node \.\.\/\.\.\/node_modules\/@smoothbricks\/nx-plugin\/dist\/bin\/smoo-nx-nextest-extract\.js target\/nextest\/archive\.tar\.zst\)" && cargo --frozen nextest run --binaries-metadata "\$extracted\/target\/nextest\/binaries-metadata\.json" --cargo-metadata "\$extracted\/target\/nextest\/cargo-metadata\.json" --target-dir-remap "\$extracted\/target" --workspace-remap \. -E 'package\(cowshed-napi\)' --no-tests=pass --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
1684
1812
  );
1685
1813
  expect(targets['napi-test']).toMatchObject({
1686
1814
  executor: '@smoothbricks/nx-plugin:bounded-exec',
@@ -1743,6 +1871,29 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1743
1871
  }
1744
1872
  });
1745
1873
 
1874
+ it('binds the wasm a package workspace member writes into that workspace target dir', async () => {
1875
+ const workspace = await createWorkspace();
1876
+ try {
1877
+ await workspace.write('packages/columine/package.json', '{"name":"columine"}\n');
1878
+ await workspace.write('packages/columine/Cargo.toml', '[workspace]\nmembers = ["crates/columine-wasm"]\n');
1879
+ await workspace.write(
1880
+ 'packages/columine/crates/columine-wasm/Cargo.toml',
1881
+ '[package]\nname = "columine-wasm"\n\n[lib]\ncrate-type = ["cdylib", "rlib"]\n\n[package.metadata.smoothbricks.wasm-bindgen]\ntargets = ["web"]\n',
1882
+ );
1883
+
1884
+ const targets = await inferProjectTargets(workspace, 'packages/columine/package.json');
1885
+
1886
+ // Cargo writes a member's artifacts under its workspace root, not beside
1887
+ // the member's manifest, so the bindgen input is read from there.
1888
+ expect(targets['cargo-wasm']?.options?.commands).toEqual([
1889
+ 'cargo --frozen build --target wasm32-unknown-unknown --manifest-path crates/columine-wasm/Cargo.toml',
1890
+ 'wasm-bindgen --target web --out-dir dist-wasm/web target/wasm32-unknown-unknown/debug/columine_wasm.wasm',
1891
+ ]);
1892
+ } finally {
1893
+ await workspace.cleanup();
1894
+ }
1895
+ });
1896
+
1746
1897
  it('shards a crate around the tests nextest.toml singles out, not through them', async () => {
1747
1898
  const workspace = await createWorkspace();
1748
1899
  try {
@@ -1759,7 +1910,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1759
1910
  // An unsharded crate keeps the bare name and takes no --partition, so
1760
1911
  // declaring nothing is exactly the old single-target behaviour.
1761
1912
  expect(targets['cargo-test-small']?.options?.command).toMatch(
1762
- /nextest run --archive-file target\/nextest\/archive\.tar\.zst --workspace-remap \. -E 'package\(small\)' --no-tests=pass --user-config-file none/,
1913
+ /--workspace-remap \. -E 'package\(small\)' --no-tests=pass --user-config-file none/,
1763
1914
  );
1764
1915
  // The shards partition the crate MINUS the classes nextest.toml singles
1765
1916
  // out, i of N. Those are lifted out because a test-group only holds
@@ -1897,8 +2048,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1897
2048
  const workspace = await createWorkspace();
1898
2049
  const declared: Record<string, TargetConfiguration> = {
1899
2050
  // 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.
2051
+ // — executor, options, inputs, cache — must survive the declaration
2052
+ // instead of being replaced wholesale by it.
1902
2053
  'cargo-test': { dependsOn: ['cargo-test-compile', 'cargo-wasm'] },
1903
2054
  'cargo-test-compile': { dependsOn: ['cargo-wasm'] },
1904
2055
  'cargo-lint': { inputs: ['{projectRoot}/clippy.toml'] },
@@ -1933,9 +2084,6 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
1933
2084
  timeoutMs: 120000,
1934
2085
  killAfterMs: 10000,
1935
2086
  });
1936
- expect(cargoTest?.configurations).toEqual({
1937
- production: { command: 'cargo --frozen test --workspace --release' },
1938
- });
1939
2087
  expect(cargoTest?.inputs).toContain('{projectRoot}/**/*.rs');
1940
2088
 
1941
2089
  const cargoTestCompile = resolveDeclaredOverInferred(targets, declared, 'cargo-test-compile');
@@ -2244,9 +2392,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
2244
2392
  expect(String(archive?.options?.commands?.[1])).toMatch(
2245
2393
  /^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
2394
  );
2247
- expect(String(archive?.configurations?.production?.commands?.[1])).toContain(
2248
- 'nextest archive --workspace --release --target aarch64-apple-darwin',
2249
- );
2395
+ expect(archive?.configurations?.[RELEASE_CONFIGURATION]).toBeUndefined();
2396
+ expect(run?.configurations?.[RELEASE_CONFIGURATION]).toBeUndefined();
2250
2397
  // The archive BUILDS, so it needs the locked registry graph; the runner
2251
2398
  // never touches cargo, so it needs nothing and depends on nothing.
2252
2399
  expect(archive?.dependsOn).toEqual(['cargo-fetch']);
@@ -2450,17 +2597,17 @@ function resolveDeclaredOverInferred(
2450
2597
  * How a cargo test command is scoped to one crate, split into the three facts
2451
2598
  * that can independently go wrong.
2452
2599
  *
2453
- * `--archive-file` must be present: the runner executes binaries one workspace
2454
- * `cargo nextest archive --workspace` already built, so a per-crate run cannot
2455
- * compile anything. Narrowing comes from the nextest filterset, which selects
2456
- * what RUNS. `--package` narrows too, but it re-resolves that crate's features,
2457
- * which is a build — 57.9s of a 120s bounded budget on a hosted 3-core macOS
2458
- * runner when the runners still built — so its presence is a regression even
2459
- * though it selects the same tests. nextest rejects it outright beside
2460
- * `--archive-file`, and this assertion says so before cargo does.
2600
+ * `--binaries-metadata` must be present: the runner executes binaries one
2601
+ * workspace `cargo nextest archive --workspace` already built, so a per-crate
2602
+ * run cannot compile anything. Narrowing comes from the nextest filterset,
2603
+ * which selects what RUNS. `--package` narrows too, but it re-resolves that
2604
+ * crate's features, which is a build — 57.9s of a 120s bounded budget on a
2605
+ * hosted 3-core macOS runner when the runners still built — so its presence is
2606
+ * a regression even though it selects the same tests. nextest rejects it
2607
+ * outright beside a reused build, and this assertion says so before cargo does.
2461
2608
  */
2462
2609
  function cargoPackageSelection(command: string): {
2463
- archiveRun: boolean;
2610
+ prebuiltRun: boolean;
2464
2611
  packageFlags: string[];
2465
2612
  filtered: string[];
2466
2613
  } {
@@ -2475,7 +2622,7 @@ function cargoPackageSelection(command: string): {
2475
2622
  }
2476
2623
  }
2477
2624
  return {
2478
- archiveRun: tokens.includes('--archive-file'),
2625
+ prebuiltRun: tokens.includes('--binaries-metadata'),
2479
2626
  packageFlags,
2480
2627
  filtered: [...command.matchAll(/\bpackage\(([^)]+)\)/g)].flatMap((match) =>
2481
2628
  match[1] === undefined ? [] : [match[1]],