@smoothbricks/nx-plugin 0.3.8 → 0.3.10

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 (35) hide show
  1. package/README.md +7 -0
  2. package/dist/cross-check-policy.d.ts +65 -0
  3. package/dist/cross-check-policy.d.ts.map +1 -0
  4. package/dist/cross-check-policy.js +64 -0
  5. package/dist/executors/napi-cross-toolchain/executor.d.ts +42 -0
  6. package/dist/executors/napi-cross-toolchain/executor.d.ts.map +1 -0
  7. package/dist/executors/napi-cross-toolchain/executor.js +118 -0
  8. package/dist/executors/napi-cross-toolchain/schema.d.ts +4 -0
  9. package/dist/executors/napi-cross-toolchain/schema.d.ts.map +1 -0
  10. package/dist/executors/napi-cross-toolchain/schema.js +1 -0
  11. package/dist/generators/create-package/generator.d.ts.map +1 -1
  12. package/dist/generators/create-package/generator.js +77 -5
  13. package/dist/index.d.ts +13 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +122 -12
  16. package/dist/typecheck-test-policy.d.ts.map +1 -1
  17. package/dist/typecheck-test-policy.js +22 -2
  18. package/dist/workspace-config-policy.js +14 -0
  19. package/executors.json +5 -0
  20. package/generators.json +1 -1
  21. package/package.json +7 -46
  22. package/src/cross-check-policy.test.ts +81 -0
  23. package/src/cross-check-policy.ts +70 -0
  24. package/src/executors/napi-cross-toolchain/executor.test.ts +112 -0
  25. package/src/executors/napi-cross-toolchain/executor.ts +157 -0
  26. package/src/executors/napi-cross-toolchain/schema.json +15 -0
  27. package/src/executors/napi-cross-toolchain/schema.ts +3 -0
  28. package/src/generators/create-package/generator.test.ts +49 -0
  29. package/src/generators/create-package/generator.ts +88 -6
  30. package/src/generators/create-package/schema.d.ts +2 -1
  31. package/src/generators/create-package/schema.json +7 -2
  32. package/src/index.test.ts +92 -14
  33. package/src/index.ts +136 -12
  34. package/src/typecheck-test-policy.ts +24 -2
  35. package/src/workspace-config-policy.ts +14 -0
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import { dirname, join, posix } from 'node:path';
4
4
  import { readJsonFile, } from 'nx/src/devkit-exports.js';
5
5
  import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
6
6
  import { parse as parseToml } from 'smol-toml';
7
+ import { CARGO_CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET } from './cross-check-policy.js';
7
8
  import { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
8
9
  const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|android|native|napi|bun|wasm)$/;
9
10
  const TYPESCRIPT_TOOLCHAIN_INPUTS = [
@@ -12,6 +13,28 @@ const TYPESCRIPT_TOOLCHAIN_INPUTS = [
12
13
  '{workspaceRoot}/patches/**/*',
13
14
  '{workspaceRoot}/tsconfig.base.json',
14
15
  ];
16
+ // The aggregate `build` pulls in platform-suffixed binary targets for THIS
17
+ // machine only: `<tool>-<arch>-<os>` names matching the host (for example
18
+ // cli-arm64-macos on Apple Silicon) build locally as part of `nx build`, while
19
+ // every foreign platform stays publish-workflow-only. nx.json targetDefaults
20
+ // cannot express "current platform" — its dependsOn lists are static — so the
21
+ // inference plugin owns this edge.
22
+ const HOST_PLATFORM_SUFFIX = (() => {
23
+ const os = process.platform === 'darwin' ? 'macos' : process.platform === 'linux' ? 'linux' : null;
24
+ const arch = process.arch === 'arm64' ? 'arm64' : process.arch === 'x64' ? 'x64' : null;
25
+ return os !== null && arch !== null ? `-${arch}-${os}` : null;
26
+ })();
27
+ export function hostPlatformTargetNames(targetNames) {
28
+ if (HOST_PLATFORM_SUFFIX === null)
29
+ return [];
30
+ return [...new Set(targetNames)]
31
+ .filter(
32
+ // Binary targets only. A toolchain prerequisite carries the same platform
33
+ // suffix but produces no artifact: the cross builds that need it depend
34
+ // on it directly, so the aggregate stays a list of outputs.
35
+ (name) => name.endsWith(HOST_PLATFORM_SUFFIX) && !name.startsWith(NAPI_TOOLCHAIN_TARGET_PREFIX))
36
+ .sort();
37
+ }
15
38
  //#region smoo!n/rust-output-target-inference
16
39
  // Cargo workspace inference: a package.json sitting next to a Cargo.toml that
17
40
  // declares [workspace] gets direct cargo-test/test targets, cargo-lint feeding
@@ -60,6 +83,15 @@ const NAPI_TARGET_CONVENTIONS = {
60
83
  useNapiCross: true,
61
84
  },
62
85
  };
86
+ const NAPI_TOOLCHAIN_TARGET_PREFIX = 'napi-toolchain-';
87
+ /**
88
+ * Prerequisite target that extracts the cross toolchain one triple needs. The
89
+ * platform suffix keeps it inside its own platform family, so it can be a
90
+ * dependency of `napi-<arch>-linux` and package-local `cli-<arch>-linux`.
91
+ */
92
+ export function napiToolchainTargetName(convention) {
93
+ return `${NAPI_TOOLCHAIN_TARGET_PREFIX}${convention.architecture}-${convention.targetFamily}`;
94
+ }
63
95
  function createCargoWasmTarget(projectRoot, config) {
64
96
  const cargoTargetDirectory = posix.join(posix.dirname(config.manifestPath), 'target/cargo-wasm');
65
97
  const wasmInput = `${cargoTargetDirectory}/wasm32-unknown-unknown/release/${config.libraryName}.wasm`;
@@ -216,10 +248,11 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
216
248
  targets['cargo-wasm'] = createCargoWasmTarget(projectRoot, cargoWasmConfig);
217
249
  }
218
250
  if (napiConfig) {
219
- Object.assign(targets, createNapiTargets(projectRoot, napiConfig));
251
+ const napiTargets = createNapiTargets(projectRoot, napiConfig);
252
+ Object.assign(targets, napiTargets.targets);
220
253
  if (!('napi-test' in (packageJson.nx?.targets ?? {})) &&
221
254
  existsSync(join(absoluteProjectRoot, 'src/native.test.ts'))) {
222
- targets['napi-test'] = createNapiTestTarget(projectRoot, existsSync(join(absoluteProjectRoot, 'bunfig.napi-test.toml')));
255
+ targets['napi-test'] = createNapiTestTarget(projectRoot, existsSync(join(absoluteProjectRoot, 'bunfig.napi-test.toml')), napiTargets.hostProvider);
223
256
  }
224
257
  }
225
258
  // Member crates get their targets from the workspace-root package.json,
@@ -242,6 +275,41 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
242
275
  };
243
276
  }
244
277
  validationTargets.push('cargo-lint');
278
+ // The Linux arm of `cargo-lint`, as its own target. Rationale for the name,
279
+ // the command and the absent cross test leg lives in ./cross-check-policy.ts.
280
+ //
281
+ // Inferred rather than declared package-locally: the rule reserving
282
+ // package-local declaration for output families (`cargo-wasm`, `cargo-napi`)
283
+ // governs targets that PRODUCE artifacts, where "does this package ship this
284
+ // artifact" is a packaging decision no crate manifest can answer. This target
285
+ // emits nothing — clippy type-checks and discards — so it belongs with
286
+ // cargo-lint and cargo-test on the inferred validation side.
287
+ //
288
+ // The discriminator for "has cross-platform Rust" is deliberately the same
289
+ // `[workspace]` Cargo.toml that already grants cargo-lint, NOT a scan of
290
+ // sources for `cfg` arms and NOT an opt-in flag. A source scan looks more
291
+ // precise and is strictly worse: target-specific code arrives through
292
+ // DEPENDENCIES as well as own source, which no scan of this repo's files can
293
+ // see, so it would silently skip projects — today's bug in a new costume. An
294
+ // opt-in flag has the same failure mode by construction. Every Rust project is
295
+ // in scope because CI compiles every Rust project on Linux; a project that
296
+ // genuinely cannot cross-compile overrides the target by declaring it, which is
297
+ // a visible edit to its package.json rather than a silent absence.
298
+ //
299
+ // Deliberately NOT pushed to validationTargets: joining the lint aggregate
300
+ // would make `bun run lint` — and CI's own Linux lint, already native — demand
301
+ // the 0.4 GiB cross toolchain that the devenv profile exists to keep opt-in.
302
+ if (!(CARGO_CROSS_LINT_TARGET in declared)) {
303
+ targets[CARGO_CROSS_LINT_TARGET] = {
304
+ executor: 'nx:run-commands',
305
+ cache: true,
306
+ inputs: CARGO_INPUTS,
307
+ options: {
308
+ command: CARGO_CROSS_LINT_COMMAND,
309
+ cwd: projectRoot,
310
+ },
311
+ };
312
+ }
245
313
  if (!targets.test && !('test' in declared) && typeof packageJson.scripts?.test !== 'string') {
246
314
  // Execute Cargo directly: workspace targetDefaults may replace test.dependsOn.
247
315
  targets.test = createCargoTestTarget(projectRoot);
@@ -267,7 +335,11 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
267
335
  targets.build = {
268
336
  executor: 'nx:noop',
269
337
  cache: true,
270
- dependsOn: ['^build', ...BUILD_OUTPUT_DEPENDENCIES],
338
+ dependsOn: [
339
+ '^build',
340
+ ...BUILD_OUTPUT_DEPENDENCIES,
341
+ ...hostPlatformTargetNames([...Object.keys(declaredTargets), ...Object.keys(targets)]),
342
+ ],
271
343
  };
272
344
  }
273
345
  if (hasAnyBuildOutputTarget) {
@@ -429,8 +501,26 @@ function resolveNapiConfig(packageJson, packageJsonPath, absoluteProjectRoot, is
429
501
  }
430
502
  function createNapiTargets(projectRoot, config) {
431
503
  const commonCommand = `--manifest-path ${config.manifestPath} --package ${config.cargoPackage}`;
432
- const targets = {
433
- 'cargo-napi': {
504
+ const hostPlatformTargetName = HOST_PLATFORM_SUFFIX === null ? null : `napi${HOST_PLATFORM_SUFFIX}`;
505
+ let nativeHostTargetName = null;
506
+ if (hostPlatformTargetName !== null) {
507
+ for (const triple of config.targets) {
508
+ const convention = NAPI_TARGET_CONVENTIONS[triple];
509
+ const targetName = convention ? `napi-${convention.architecture}-${convention.targetFamily}` : null;
510
+ if (targetName === hostPlatformTargetName && !convention?.useNapiCross) {
511
+ nativeHostTargetName = targetName;
512
+ break;
513
+ }
514
+ }
515
+ }
516
+ const hostProvider = nativeHostTargetName ?? 'cargo-napi';
517
+ const targets = {};
518
+ if (nativeHostTargetName === null) {
519
+ // The platform target for this host triple is the same compilation, so a
520
+ // second cargo-napi invocation only buys a duplicate dependency graph in
521
+ // target/release; native.ts already resolves the identical platform-suffixed
522
+ // filename from dist/native/<platform-dir> after dist/native/host.
523
+ targets['cargo-napi'] = {
434
524
  executor: 'nx:run-commands',
435
525
  cache: true,
436
526
  dependsOn: ['^build'],
@@ -440,8 +530,27 @@ function createNapiTargets(projectRoot, config) {
440
530
  cwd: projectRoot,
441
531
  command: `napi build --release --platform --no-js --dts ${config.binaryName}.napi.d.ts ${commonCommand} --output-dir dist/native/host`,
442
532
  },
443
- },
444
- };
533
+ };
534
+ }
535
+ for (const triple of config.targets) {
536
+ const convention = NAPI_TARGET_CONVENTIONS[triple];
537
+ if (!convention?.useNapiCross) {
538
+ continue;
539
+ }
540
+ // One toolchain target per triple, shared by every cross build that needs
541
+ // it: the inferred napi-<arch>-linux plus any package-local cli-<arch>-linux.
542
+ // Nx runs a shared dependency once, which is what stops those builds from
543
+ // racing inside the Bun store. See the executor for the failure it removes.
544
+ // The name carries the platform suffix so a Linux platform target's
545
+ // dependency closure stays Linux-only (package-target-policy).
546
+ targets[napiToolchainTargetName(convention)] = {
547
+ executor: '@smoothbricks/nx-plugin:napi-cross-toolchain',
548
+ // Extraction lands in ~/.napi-rs, outside the workspace: a cache hit
549
+ // would skip work a cold home directory still needs.
550
+ cache: false,
551
+ options: { triple },
552
+ };
553
+ }
445
554
  for (const triple of config.targets) {
446
555
  const convention = NAPI_TARGET_CONVENTIONS[triple];
447
556
  if (!convention) {
@@ -453,6 +562,7 @@ function createNapiTargets(projectRoot, config) {
453
562
  targets[targetName] = {
454
563
  executor: 'nx:run-commands',
455
564
  cache: true,
565
+ ...(convention.useNapiCross ? { dependsOn: [napiToolchainTargetName(convention)] } : {}),
456
566
  inputs: NAPI_INPUTS,
457
567
  outputs: [`{projectRoot}/${outputDirectory}`],
458
568
  options: {
@@ -465,17 +575,17 @@ function createNapiTargets(projectRoot, config) {
465
575
  },
466
576
  };
467
577
  }
468
- return targets;
578
+ return { targets, hostProvider };
469
579
  }
470
- function createNapiTestTarget(projectRoot, hasDedicatedBunfig) {
580
+ function createNapiTestTarget(projectRoot, hasDedicatedBunfig, hostProvider) {
471
581
  const configFlag = hasDedicatedBunfig ? ' --config=../bunfig.napi-test.toml' : ' --config=../bunfig.toml';
472
582
  return {
473
583
  executor: '@smoothbricks/nx-plugin:bounded-exec',
474
584
  cache: true,
475
- dependsOn: ['cargo-test', 'cargo-napi', 'tsc-js', '^build', 'build'],
585
+ dependsOn: ['cargo-test', hostProvider, 'tsc-js', '^build', 'build'],
476
586
  options: {
477
- // cwd is src/, not the package root: `bun test <arg>` treats the arg as
478
- // a FILTER and scans the whole cwd tree for test files, and a Rust
587
+ // cwd is src/, not the package root: `bun test <arg>` treats the arg as a
588
+ // FILTER and scans the whole cwd tree for test files, and a Rust
479
589
  // package's cargo target/ directory turns that scan into tens of
480
590
  // seconds. bun only auto-loads bunfig from the cwd, so the package
481
591
  // config is passed explicitly.
@@ -1 +1 @@
1
- {"version":3,"file":"typecheck-test-policy.d.ts","sourceRoot":"","sources":["../src/typecheck-test-policy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAGrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,QAAQ,CAAC;AAI1C;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvC,WAAW,CAAC,UAAU,CAAC,CAqDzB;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EAC5C,WAAW,EAAE,MAAM,GAClB,aAAa,EAAE,CAgDjB;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EAC/C,WAAW,EAAE,MAAM,GAClB,aAAa,EAAE,CAYjB;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,OAAO,EAAE;IACP,WAAW,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC;IACrC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B,GACA,OAAO,CAoDT;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAO7F;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,IAAI,GAAG,aAAa,EAAE,CAwCxE;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAyDhE;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CA2CtE;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAyD9D"}
1
+ {"version":3,"file":"typecheck-test-policy.d.ts","sourceRoot":"","sources":["../src/typecheck-test-policy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAGrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,QAAQ,CAAC;AAI1C;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvC,WAAW,CAAC,UAAU,CAAC,CAqDzB;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EAC5C,WAAW,EAAE,MAAM,GAClB,aAAa,EAAE,CAgDjB;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EAC/C,WAAW,EAAE,MAAM,GAClB,aAAa,EAAE,CAYjB;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,OAAO,EAAE;IACP,WAAW,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC;IACrC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B,GACA,OAAO,CAoDT;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAO7F;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,IAAI,GAAG,aAAa,EAAE,CAwCxE;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAyDhE;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAiEtE;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAyD9D"}
@@ -283,6 +283,7 @@ export function applyTypecheckTestPolicyTree(tree) {
283
283
  */
284
284
  export function checkTypecheckTestPolicy(root) {
285
285
  const issues = [];
286
+ const workspaceNames = getWorkspacePackageNames(root);
286
287
  for (const packageJsonPath of listWorkspacePackageJsonPaths(root)) {
287
288
  const pkg = readJsonObject(packageJsonPath);
288
289
  if (!pkg) {
@@ -306,12 +307,31 @@ export function checkTypecheckTestPolicy(root) {
306
307
  });
307
308
  continue;
308
309
  }
309
- // tsconfig.test.json must have correct settings
310
+ // The checker and updater share one normalization function. Detailed invariant
311
+ // diagnostics win; otherwise report any subtler missing canonical field so
312
+ // `smoo monorepo check` cannot be green immediately before update rewrites it.
310
313
  const tsconfig = readJsonObject(tsconfigTestPath);
311
314
  if (tsconfig) {
312
- // Use absolute path for filesystem layer
313
315
  const absoluteIssues = checkTypecheckTestConfig(tsconfig, join(root, packagePath));
314
316
  issues.push(...absoluteIssues);
317
+ if (absoluteIssues.length === 0) {
318
+ const libTsconfig = readJsonObject(join(root, packagePath, 'tsconfig.lib.json'));
319
+ const tsconfigLibExtends = stringProperty(libTsconfig ?? {}, 'extends') ?? '../../tsconfig.base.json';
320
+ const libCompilerOptions = libTsconfig ? recordProperty(libTsconfig, 'compilerOptions') : null;
321
+ const referencePaths = collectTsconfigTestReferencePaths(root, packagePath, pkg, workspaceNames);
322
+ const normalized = structuredClone(tsconfig);
323
+ if (applyTypecheckTestDefaults(normalized, {
324
+ testRunners,
325
+ tsconfigLibExtends,
326
+ libCompilerOptions: libCompilerOptions ?? undefined,
327
+ referencePaths,
328
+ })) {
329
+ issues.push({
330
+ path: tsconfigTestPath,
331
+ message: 'must match the canonical no-emit test typecheck configuration',
332
+ });
333
+ }
334
+ }
315
335
  }
316
336
  // tsconfig.json must NOT reference ./tsconfig.test.json
317
337
  const projectTsconfigPath = join(root, packagePath, 'tsconfig.json');
@@ -156,6 +156,16 @@ function validateBuildTargetDefault(nxJson, nxJsonPath, issues) {
156
156
  if (build?.cache !== true) {
157
157
  issues.push({ path: nxJsonPath, message: 'targetDefaults.build.cache must be true' });
158
158
  }
159
+ // dependsOn is owned by the inference plugin: the inferred aggregate carries
160
+ // the output families PLUS this host's platform-suffixed binary targets, and
161
+ // Nx gives targetDefaults precedence over inferred values — a static list
162
+ // here would clobber the host-aware edge on every project.
163
+ if (build !== null && 'dependsOn' in build) {
164
+ issues.push({
165
+ path: nxJsonPath,
166
+ message: 'targetDefaults.build.dependsOn must not be set; @smoothbricks/nx-plugin infers build dependencies',
167
+ });
168
+ }
159
169
  const outputs = build?.outputs;
160
170
  if (!isValidBuildOutputs(outputs)) {
161
171
  issues.push({
@@ -230,6 +240,10 @@ function applyBuildTargetDefault(nxJson) {
230
240
  if (!isValidBuildOutputs(build.outputs)) {
231
241
  changed = setStringArrayProperty(build, 'outputs', ['{projectRoot}/dist']) || changed;
232
242
  }
243
+ if ('dependsOn' in build) {
244
+ delete build.dependsOn;
245
+ changed = true;
246
+ }
233
247
  return changed;
234
248
  }
235
249
  function applyCleanTargetDefault(nxJson) {
package/executors.json CHANGED
@@ -14,6 +14,11 @@
14
14
  "implementation": "./dist/executors/clean-outputs/executor.js",
15
15
  "schema": "./src/executors/clean-outputs/schema.json",
16
16
  "description": "Remove declared build output directories unless they contain tracked files"
17
+ },
18
+ "napi-cross-toolchain": {
19
+ "implementation": "./dist/executors/napi-cross-toolchain/executor.js",
20
+ "schema": "./src/executors/napi-cross-toolchain/schema.json",
21
+ "description": "Extract the pinned @napi-rs cross toolchain so --use-napi-cross never downloads it"
17
22
  }
18
23
  }
19
24
  }
package/generators.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "create-package": {
14
14
  "factory": "./dist/generators/create-package/generator.js",
15
15
  "schema": "./src/generators/create-package/schema.json",
16
- "description": "Scaffold a new TypeScript workspace package"
16
+ "description": "Scaffold a TypeScript library or Rust workspace package"
17
17
  },
18
18
  "make-public": {
19
19
  "factory": "./dist/generators/make-public/generator.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smoothbricks/nx-plugin",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./loader.js",
@@ -10,7 +10,6 @@
10
10
  "./package.json": "./package.json",
11
11
  ".": {
12
12
  "types": "./dist/index.d.ts",
13
- "development": "./src/index.ts",
14
13
  "import": "./loader.js",
15
14
  "default": "./loader.js"
16
15
  },
@@ -21,33 +20,33 @@
21
20
  },
22
21
  "./bounded-test-policy": {
23
22
  "types": "./dist/bounded-test-policy.d.ts",
24
- "development": "./src/bounded-test-policy.ts",
25
23
  "import": "./dist/bounded-test-policy.js",
26
24
  "default": "./dist/bounded-test-policy.js"
27
25
  },
28
26
  "./workspace-config-policy": {
29
27
  "types": "./dist/workspace-config-policy.d.ts",
30
- "development": "./src/workspace-config-policy.ts",
31
28
  "import": "./dist/workspace-config-policy.js",
32
29
  "default": "./dist/workspace-config-policy.js"
33
30
  },
34
31
  "./release-config-policy": {
35
32
  "types": "./dist/release-config-policy.d.ts",
36
- "development": "./src/release-config-policy.ts",
37
33
  "import": "./dist/release-config-policy.js",
38
34
  "default": "./dist/release-config-policy.js"
39
35
  },
40
36
  "./package-target-policy": {
41
37
  "types": "./dist/package-target-policy.d.ts",
42
- "development": "./src/package-target-policy.ts",
43
38
  "import": "./dist/package-target-policy.js",
44
39
  "default": "./dist/package-target-policy.js"
45
40
  },
46
41
  "./typecheck-test-policy": {
47
42
  "types": "./dist/typecheck-test-policy.d.ts",
48
- "development": "./src/typecheck-test-policy.ts",
49
43
  "import": "./dist/typecheck-test-policy.js",
50
44
  "default": "./dist/typecheck-test-policy.js"
45
+ },
46
+ "./cross-check-policy": {
47
+ "types": "./dist/cross-check-policy.d.ts",
48
+ "import": "./dist/cross-check-policy.js",
49
+ "default": "./dist/cross-check-policy.js"
51
50
  }
52
51
  },
53
52
  "generators": "./generators.json",
@@ -84,45 +83,7 @@
84
83
  ],
85
84
  "license": "MIT",
86
85
  "publishConfig": {
87
- "access": "public",
88
- "exports": {
89
- "./package.json": "./package.json",
90
- ".": {
91
- "types": "./dist/index.d.ts",
92
- "import": "./loader.js",
93
- "default": "./loader.js"
94
- },
95
- "./version-actions": {
96
- "types": "./dist/version-actions.d.cts",
97
- "require": "./dist/version-actions.cjs",
98
- "default": "./dist/version-actions.cjs"
99
- },
100
- "./bounded-test-policy": {
101
- "types": "./dist/bounded-test-policy.d.ts",
102
- "import": "./dist/bounded-test-policy.js",
103
- "default": "./dist/bounded-test-policy.js"
104
- },
105
- "./workspace-config-policy": {
106
- "types": "./dist/workspace-config-policy.d.ts",
107
- "import": "./dist/workspace-config-policy.js",
108
- "default": "./dist/workspace-config-policy.js"
109
- },
110
- "./release-config-policy": {
111
- "types": "./dist/release-config-policy.d.ts",
112
- "import": "./dist/release-config-policy.js",
113
- "default": "./dist/release-config-policy.js"
114
- },
115
- "./package-target-policy": {
116
- "types": "./dist/package-target-policy.d.ts",
117
- "import": "./dist/package-target-policy.js",
118
- "default": "./dist/package-target-policy.js"
119
- },
120
- "./typecheck-test-policy": {
121
- "types": "./dist/typecheck-test-policy.d.ts",
122
- "import": "./dist/typecheck-test-policy.js",
123
- "default": "./dist/typecheck-test-policy.js"
124
- }
125
- }
86
+ "access": "public"
126
87
  },
127
88
  "repository": {
128
89
  "type": "git",
@@ -0,0 +1,81 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+
3
+ import {
4
+ CARGO_CROSS_LINT_COMMAND,
5
+ CARGO_CROSS_LINT_TARGET,
6
+ CARGO_LINUX_TRIPLE,
7
+ CROSS_CHECK_SCRIPT_COMMAND,
8
+ CROSS_CHECK_SCRIPT_NAME,
9
+ DEVENV_CROSS_PROFILE,
10
+ } from './cross-check-policy.js';
11
+ import { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
12
+
13
+ const suffixOf = (glob: string): string => (glob.startsWith('*') ? glob.slice(1) : glob);
14
+
15
+ describe('Linux cross-check policy', () => {
16
+ it('keeps the cross target out of every platform artifact family', () => {
17
+ // `*-linux` is not decoration: publish-workflow fans out over
18
+ // LINUX_PLATFORM_TARGET_GLOBS to build RELEASE ARTIFACTS on a Linux runner,
19
+ // platformTargetFamily classifies by it, and a matching name flags the whole
20
+ // project as platform-bearing. Naming this validation target `*-linux` would
21
+ // enrol a clippy run in release artifact production — silently, and only
22
+ // visible at publish time.
23
+ for (const glob of PLATFORM_TARGET_GLOBS) {
24
+ expect(CARGO_CROSS_LINT_TARGET.endsWith(suffixOf(glob))).toBe(false);
25
+ }
26
+ });
27
+
28
+ it('keeps the cross target out of every build output family', () => {
29
+ // A match here would attach the gate to each project's aggregate `build`,
30
+ // making an ordinary macOS build demand the opt-in cross toolchain.
31
+ for (const dependency of BUILD_OUTPUT_DEPENDENCIES) {
32
+ expect(CARGO_CROSS_LINT_TARGET.endsWith(suffixOf(dependency))).toBe(false);
33
+ }
34
+ });
35
+
36
+ it('names targets without colons', () => {
37
+ // Nx CLI syntax is already project:target:configuration.
38
+ expect(CARGO_CROSS_LINT_TARGET).not.toContain(':');
39
+ });
40
+
41
+ it('compiles test code for the target without running anything', () => {
42
+ // --all-targets is the entire test story for the cross arm: bins, tests,
43
+ // benches and examples are type-checked for Linux, and nothing is executed
44
+ // because an x86_64 Linux binary cannot run on Apple Silicon. Dropping it
45
+ // would silently stop checking every #[cfg(test)] and #[bench] block.
46
+ expect(CARGO_CROSS_LINT_COMMAND).toContain('--all-targets');
47
+ // No cargo subcommand here may execute what it built.
48
+ expect(CARGO_CROSS_LINT_COMMAND).not.toContain('cargo test');
49
+ expect(CARGO_CROSS_LINT_COMMAND).not.toContain('cargo run');
50
+ });
51
+
52
+ it('matches the severity and triple CI lints with', () => {
53
+ // A weaker local command passes where CI fails, which is the failure this
54
+ // gate exists to prevent rather than reproduce.
55
+ expect(CARGO_CROSS_LINT_COMMAND).toContain('-D warnings');
56
+ expect(CARGO_CROSS_LINT_COMMAND).toContain(`--target ${CARGO_LINUX_TRIPLE}`);
57
+ });
58
+
59
+ it('carries the triple explicitly so a host lint cannot pass for a cross one', () => {
60
+ // The devenv profile deliberately exports no CARGO_BUILD_TARGET. Were the
61
+ // triple ambient instead, running this target outside the cross shell would
62
+ // lint the host and report green — a gate that cannot fail.
63
+ expect(CARGO_CROSS_LINT_COMMAND).toContain('--target ');
64
+ });
65
+
66
+ it('drives the Nx target through the cross profile from the root script', () => {
67
+ expect(CROSS_CHECK_SCRIPT_NAME).toBe('check:linux');
68
+ // Activates the profile...
69
+ expect(CROSS_CHECK_SCRIPT_COMMAND).toContain(`-P ${DEVENV_CROSS_PROFILE}`);
70
+ // ...via the managed wrapper, so it resolves devenv config in any fleet repo...
71
+ expect(CROSS_CHECK_SCRIPT_COMMAND).toStartWith('tooling/devenv ');
72
+ // ...and runs Nx rather than cargo directly, so caching and project
73
+ // discovery stay Nx's job.
74
+ expect(CROSS_CHECK_SCRIPT_COMMAND).toContain(`nx run-many -t ${CARGO_CROSS_LINT_TARGET}`);
75
+ expect(CROSS_CHECK_SCRIPT_COMMAND).toContain('--quiet');
76
+ });
77
+
78
+ it('uses the verb:qualifier root script convention', () => {
79
+ expect(CROSS_CHECK_SCRIPT_NAME).toMatch(/^[a-z]+:[a-z-]+$/);
80
+ });
81
+ });
@@ -0,0 +1,70 @@
1
+ /**
2
+ * The Linux compile gate, in one place.
3
+ *
4
+ * CI validates on Linux, so Rust behind a `cfg(target_os)` arm that only Linux
5
+ * compiles is invisible to every check a macOS host can run: a full local lint
6
+ * passes and CI still goes red on unused imports, unresolved names and dead code
7
+ * inside the `not(target_os = "macos")` branch. Closing that needs three pieces
8
+ * to agree — a devenv profile carrying the cross C toolchain, an Nx target per
9
+ * Cargo workspace that asks for the triple, and a root script that runs the
10
+ * second inside the first. They live here together because the plugin infers the
11
+ * target while the CLI installs the script and reports a project missing it; kept
12
+ * apart, the three spellings drift and the gate silently stops gating.
13
+ */
14
+
15
+ /**
16
+ * The triple CI's Linux job compiles, and the one a macOS host can cross-check.
17
+ * `languages.rust.targets` in the managed devenv module installs its rust-std.
18
+ */
19
+ export const CARGO_LINUX_TRIPLE = 'x86_64-unknown-linux-gnu';
20
+
21
+ /**
22
+ * The devenv profile carrying the cross C compiler, defined in the managed
23
+ * `tooling/direnv/devenv.smoo.nix`. Opt-in because its closure is 0.4 GiB and
24
+ * nothing on Darwin links a Linux object.
25
+ */
26
+ export const DEVENV_CROSS_PROFILE = 'linux-cross';
27
+
28
+ /**
29
+ * Nx target name. No colons, per the repo's target-naming rule.
30
+ *
31
+ * Deliberately NOT suffixed `-linux`: that suffix is the reserved platform
32
+ * family `LINUX_PLATFORM_TARGET_GLOBS`, which the publish workflow fans out over
33
+ * to build release ARTIFACTS on a Linux runner, which `platformTargetFamily`
34
+ * classifies by, and which flags a project as platform-bearing. A validation
35
+ * target that emits nothing must not be swept into artifact machinery, so it
36
+ * carries the neutral `-cross` qualifier — also outside the `-js`/`-napi`/`-wasm`
37
+ * build-output families, so no aggregate `build` picks it up either.
38
+ */
39
+ export const CARGO_CROSS_LINT_TARGET = 'cargo-lint-cross';
40
+
41
+ /**
42
+ * Clippy rather than `cargo check`, and `-D warnings`, because that is exactly
43
+ * what CI's `lint` runs; a weaker local command would pass where CI fails.
44
+ *
45
+ * `--all-targets` is what answers "what does test mean when cross-compiling": it
46
+ * type-checks bins, tests, benches and examples for the target, so test CODE is
47
+ * verified for Linux while nothing is executed — nothing can be, since an x86_64
48
+ * Linux binary does not run on Apple Silicon. There is deliberately no separate
49
+ * cross test target; it could only recompile these crates to produce a harness it
50
+ * must then refuse to launch.
51
+ *
52
+ * `--target` is explicit rather than inherited from a CARGO_BUILD_TARGET exported
53
+ * by the profile, so running this outside the cross shell fails loudly on a
54
+ * missing tool instead of quietly linting the host and reporting green.
55
+ *
56
+ * `cargo fmt` is absent on purpose: formatting is target-independent and already
57
+ * covered by `cargo-lint`, so repeating it here would only cost time.
58
+ */
59
+ export const CARGO_CROSS_LINT_COMMAND = `cargo clippy --workspace --all-targets --target ${CARGO_LINUX_TRIPLE} -- -D warnings`;
60
+
61
+ /** Root `package.json` script name, in the repo's `verb:qualifier` style. */
62
+ export const CROSS_CHECK_SCRIPT_NAME = 'check:linux';
63
+
64
+ /**
65
+ * The developer entry point: one command on macOS that reports what CI's Linux
66
+ * job would. `tooling/devenv` is the managed wrapper, so this resolves the
67
+ * repository's devenv config from any repo in the fleet without naming its path,
68
+ * and `--quiet` keeps the output to Nx's own.
69
+ */
70
+ export const CROSS_CHECK_SCRIPT_COMMAND = `tooling/devenv --quiet -P ${DEVENV_CROSS_PROFILE} shell -- nx run-many -t ${CARGO_CROSS_LINT_TARGET}`;