@smoothbricks/nx-plugin 0.4.13 → 0.4.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,7 +10,7 @@ with `tsconfig.lib.json` receives transformer-aware `tsc-js` and native `typeche
10
10
  `@smoothbricks/nx-plugin` also owns inferred targets Nx does not provide here:
11
11
 
12
12
  - `typecheck-tests` and `typecheck-tests:watch` from `tsconfig.test.json`
13
- - `test:watch` from explicit `test` commands for Bun and Vitest packages
13
+ - `test-watch` from explicit `test` commands for Bun and Vitest packages
14
14
  - Cargo workspace targets from a neighboring workspace-root `Cargo.toml`
15
15
  - aggregate `build` and `lint` targets
16
16
  - an uncached `deploy` for a PRIVATE project with a wrangler manifest, running
@@ -68,11 +68,22 @@ Cargo's shared mutable build directory before the bounded runner, even if that d
68
68
  successful run. Cargo's own incremental cache avoids recompiling unchanged code. Nx never restores or collects shared
69
69
  Cargo build directories; lint and test **results**, and dedicated Wasm/N-API **outputs**, remain cacheable.
70
70
 
71
- Validation inputs include the crate's files, local dependency closure, governing manifests and configuration, toolchain
72
- versions, Cargo/Rust/native-build environment, target/profile overrides, and global Cargo configuration. Workspace test
73
- runners additionally hash all workspace member manifests because those affect unified features, and the nextest
74
- executable/configuration. Production test configurations use release compilation and release runners together. Keep
75
- explicit inputs for arbitrary build-script reads or custom environment variables that Cargo metadata cannot name.
71
+ Validation inputs include the crate's files, local dependency closure, governing manifests and configuration, the
72
+ declared toolchain pin, and the toolchain's own reported versions. The pin is `devenv.lock`, hashed as an ordinary file
73
+ input at both `{workspaceRoot}/devenv.lock` and `{workspaceRoot}/tooling/direnv/devenv.lock` — devenv resolves it into
74
+ the rustc, cargo, linker, C toolchain and SDK every cargo command inherits, so bumping it invalidates every cached cargo
75
+ target. Workspace test runners additionally hash all workspace member manifests because those affect unified features,
76
+ and the nextest executable/configuration. Production test configurations use release compilation and release runners
77
+ together.
78
+
79
+ Nothing machine-local takes part. The ambient cargo environment and the global `$CARGO_HOME/config.toml` are
80
+ deliberately not hashed: their values carry absolute store paths and per-checkout state directories, which would make
81
+ every cache entry private to the machine that wrote it and make one target hash differently inside a devenv profile than
82
+ outside it — enough to make a pre-push cross-compile probe unsatisfiable. Keep explicit inputs for arbitrary
83
+ build-script reads or custom environment variables that Cargo metadata cannot name.
84
+
85
+ A target whose inputs a repository DECLARES replaces the inferred list, pin included. Name the two `devenv.lock` entries
86
+ in that declaration, or in the named input it uses, or a toolchain bump will not invalidate it.
76
87
 
77
88
  Cargo keeps the caller's `CARGO_HOME`. Moving configuration into an isolated home can change relative paths or lose
78
89
  source replacement, credentials, and toolchain settings; forwarding it with `--config` changes precedence. Registry
@@ -160,7 +171,7 @@ Concrete targets come from concrete files:
160
171
  - `typecheck-tests` is inferred from `tsconfig.test.json` and runs `tsc -p tsconfig.test.json --noEmit`. It first
161
172
  rebuilds the current package's `tsc-js` output (or its non-TypeScript `build`) so self-imports resolve after `clean`.
162
173
  - `typecheck-tests:watch` is inferred from `tsconfig.test.json` and runs the same typecheck in watch mode.
163
- - `test:watch` is inferred when the package already defines an explicit Bun or Vitest `test` command. The plugin derives
174
+ - `test-watch` is inferred when the package already defines an explicit Bun or Vitest `test` command. The plugin derives
164
175
  the corresponding watch command and makes it depend on `typecheck-tests`.
165
176
  - A workspace-root `Cargo.toml` provides `cargo-test`, `test`, `cargo-lint`, `mutation`, and `bench`.
166
177
  `cargo-test-compile` warms one workspace `cargo test --no-run`. `cargo-test-archive` runs one
@@ -246,7 +257,7 @@ target such as `nx run pkg:cargo-wasm`.
246
257
  There is no Nx `lint:fix` target; repository formatting is handled by the root `lint:fix` script.
247
258
 
248
259
  `typecheck-tests` and `typecheck-tests:watch` are inferred only when `tsconfig.test.json` exists. Test typechecking must
249
- not emit `dist-test`. `test:watch` is continuous and depends on `typecheck-tests` before entering Bun or Vitest watch
260
+ not emit `dist-test`. `test-watch` is continuous and depends on `typecheck-tests` before entering Bun or Vitest watch
250
261
  mode. Smoo validation creates/requires this config for test runners that do not typecheck test files by default.
251
262
 
252
263
  `tsconfig.test.json` is not a TypeScript build-mode project. It should reference library tsconfigs it needs to typecheck
@@ -0,0 +1,61 @@
1
+ /**
2
+ * The toolchain half of a cargo task's identity, shared by the two things that
3
+ * must agree about it: target inference, which attaches it, and the monorepo
4
+ * policy, which refuses a repository's own declaration that drops it.
5
+ */
6
+ /**
7
+ * The DECLARED pin, hashed as an ordinary file. devenv resolves this lock into
8
+ * the rustc, cargo, linker, C toolchain and SDK that every cargo command
9
+ * inherits, so a bump here is exactly the event that must invalidate a cached
10
+ * artifact — and it is the only such event the workspace can state portably.
11
+ *
12
+ * This replaces a runtime input that dumped the ambient cargo environment
13
+ * (every `CARGO_`, `RUST`, `CC`, `CXX`, `AR`, `SDKROOT`, `LIBCLANG_PATH`,
14
+ * `CMAKE_` and `ZIG` prefixed variable, plus the contents of
15
+ * `$CARGO_HOME/config{,.toml}`). That bought the same
16
+ * invalidation at the price of two defects. Its values are absolute
17
+ * `/nix/store/<hash>-…` paths and per-checkout devenv state directories, so no
18
+ * two machines ever agree and no cargo target can share a cache entry with a
19
+ * peer or with CI — a remote cache for Rust was dead on arrival. And the dump
20
+ * differs between a bare shell and a devenv profile for the SAME sources: in
21
+ * the `linux-cross` profile `AR` becomes `x86_64-unknown-linux-gnu-ar`,
22
+ * `CARGO_INSTALL_ROOT` moves under `profiles/linux-cross/`, and
23
+ * `CC_x86_64_unknown_linux_gnu` appears, so the entry `check:linux` writes
24
+ * inside the profile could never be hit by the pre-push probe, which runs
25
+ * bare. Measured on one repository-root archive target with the dump still in
26
+ * place: bare 18197306115812424011, in-profile 12567954759860890767.
27
+ *
28
+ * A file input has neither defect. The lock's bytes are identical bare and
29
+ * in-profile and on every machine holding the checkout, while the toolchain
30
+ * VERSIONS the dump was really guarding stay covered twice over — by the pin
31
+ * itself, and by the `rustc -vV && cargo -V` runtime input attached beside it,
32
+ * whose stdout is byte-identical in both shells (measured). Nothing
33
+ * machine-local survives. A NARROWED dump was rejected rather than kept: a
34
+ * subset re-acquires a store path the moment anyone widens it.
35
+ *
36
+ * Both fleet locations are stated: the pin lives under `tooling/direnv/` in
37
+ * every repository and additionally at the root in some. A fileset that
38
+ * matches nothing contributes nothing — the same property the inert
39
+ * `rust-toolchain*` entries already rely on.
40
+ */
41
+ export declare const CARGO_TOOLCHAIN_PIN_INPUTS: readonly string[];
42
+ /**
43
+ * The name a repository's own `inputs` declaration uses to reach the pin
44
+ * without restating its paths.
45
+ *
46
+ * A declared target REPLACES the inferred input list, pin included, so a
47
+ * hand-written `inputs` array silently drops the toolchain identity and the
48
+ * target stops seeing a toolchain bump at all. Inference defines this named
49
+ * input on every project that has cargo targets so a declaration can name one
50
+ * token that cannot drift from what the plugin attaches.
51
+ */
52
+ export declare const CARGO_TOOLCHAIN_NAMED_INPUT = "cargoToolchain";
53
+ /**
54
+ * Does one resolved input string carry the toolchain identity?
55
+ *
56
+ * Resolved: named inputs already expanded. The check is by suffix rather than
57
+ * by exact path because a repository may keep its lock at a location this list
58
+ * does not name; what matters is that a devenv lock is hashed, not which one.
59
+ */
60
+ export declare function isCargoToolchainInput(input: string): boolean;
61
+ //# sourceMappingURL=cargo-toolchain-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cargo-toolchain-policy.d.ts","sourceRoot":"","sources":["../src/cargo-toolchain-policy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,0BAA0B,EAAE,SAAS,MAAM,EAGvD,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,2BAA2B,mBAAmB,CAAC;AAE5D;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE5D"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * The toolchain half of a cargo task's identity, shared by the two things that
3
+ * must agree about it: target inference, which attaches it, and the monorepo
4
+ * policy, which refuses a repository's own declaration that drops it.
5
+ */
6
+ /**
7
+ * The DECLARED pin, hashed as an ordinary file. devenv resolves this lock into
8
+ * the rustc, cargo, linker, C toolchain and SDK that every cargo command
9
+ * inherits, so a bump here is exactly the event that must invalidate a cached
10
+ * artifact — and it is the only such event the workspace can state portably.
11
+ *
12
+ * This replaces a runtime input that dumped the ambient cargo environment
13
+ * (every `CARGO_`, `RUST`, `CC`, `CXX`, `AR`, `SDKROOT`, `LIBCLANG_PATH`,
14
+ * `CMAKE_` and `ZIG` prefixed variable, plus the contents of
15
+ * `$CARGO_HOME/config{,.toml}`). That bought the same
16
+ * invalidation at the price of two defects. Its values are absolute
17
+ * `/nix/store/<hash>-…` paths and per-checkout devenv state directories, so no
18
+ * two machines ever agree and no cargo target can share a cache entry with a
19
+ * peer or with CI — a remote cache for Rust was dead on arrival. And the dump
20
+ * differs between a bare shell and a devenv profile for the SAME sources: in
21
+ * the `linux-cross` profile `AR` becomes `x86_64-unknown-linux-gnu-ar`,
22
+ * `CARGO_INSTALL_ROOT` moves under `profiles/linux-cross/`, and
23
+ * `CC_x86_64_unknown_linux_gnu` appears, so the entry `check:linux` writes
24
+ * inside the profile could never be hit by the pre-push probe, which runs
25
+ * bare. Measured on one repository-root archive target with the dump still in
26
+ * place: bare 18197306115812424011, in-profile 12567954759860890767.
27
+ *
28
+ * A file input has neither defect. The lock's bytes are identical bare and
29
+ * in-profile and on every machine holding the checkout, while the toolchain
30
+ * VERSIONS the dump was really guarding stay covered twice over — by the pin
31
+ * itself, and by the `rustc -vV && cargo -V` runtime input attached beside it,
32
+ * whose stdout is byte-identical in both shells (measured). Nothing
33
+ * machine-local survives. A NARROWED dump was rejected rather than kept: a
34
+ * subset re-acquires a store path the moment anyone widens it.
35
+ *
36
+ * Both fleet locations are stated: the pin lives under `tooling/direnv/` in
37
+ * every repository and additionally at the root in some. A fileset that
38
+ * matches nothing contributes nothing — the same property the inert
39
+ * `rust-toolchain*` entries already rely on.
40
+ */
41
+ export const CARGO_TOOLCHAIN_PIN_INPUTS = [
42
+ '{workspaceRoot}/devenv.lock',
43
+ '{workspaceRoot}/tooling/direnv/devenv.lock',
44
+ ];
45
+ /**
46
+ * The name a repository's own `inputs` declaration uses to reach the pin
47
+ * without restating its paths.
48
+ *
49
+ * A declared target REPLACES the inferred input list, pin included, so a
50
+ * hand-written `inputs` array silently drops the toolchain identity and the
51
+ * target stops seeing a toolchain bump at all. Inference defines this named
52
+ * input on every project that has cargo targets so a declaration can name one
53
+ * token that cannot drift from what the plugin attaches.
54
+ */
55
+ export const CARGO_TOOLCHAIN_NAMED_INPUT = 'cargoToolchain';
56
+ /**
57
+ * Does one resolved input string carry the toolchain identity?
58
+ *
59
+ * Resolved: named inputs already expanded. The check is by suffix rather than
60
+ * by exact path because a repository may keep its lock at a location this list
61
+ * does not name; what matters is that a devenv lock is hashed, not which one.
62
+ */
63
+ export function isCargoToolchainInput(input) {
64
+ return !input.startsWith('!') && input.endsWith('/devenv.lock');
65
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,aAAa,EAGnB,MAAM,0BAA0B,CAAC;AAKlC,OAAO,EAKL,yBAAyB,EAa1B,MAAM,sBAAsB,CAAC;AAiB9B,OAAO,EAAE,yBAAyB,EAAE,CAAC;AAErC,gEAAgE;AAChE,eAAO,MAAM,aAAa,WAAW,CAAC;AACtC,uEAAuE;AACvE,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AA4GlD,KAAK,gBAAgB,GAAG,OAAO,GAAG,KAAK,CAAC;AACxC,KAAK,gBAAgB,GAAG,OAAO,GAAG,OAAO,CAAC;AAE1C,UAAU,YAAY;IACpB,YAAY,EAAE,gBAAgB,CAAC;IAC/B,YAAY,EAAE,gBAAgB,CAAC;CAChC;AAkJD,UAAU,oBAAqB,SAAQ,YAAY;IACjD,UAAU,EAAE,MAAM,CAAC;CACpB;AA0CD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,oBAAoB,GAAG,MAAM,CAEhF;AAoWD,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,GAAG,aAAa,CAEvG;AAED,eAAO,MAAM,aAAa,EAAE,aAG3B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,aAAa,EAGnB,MAAM,0BAA0B,CAAC;AAMlC,OAAO,EAKL,yBAAyB,EAa1B,MAAM,sBAAsB,CAAC;AAiB9B,OAAO,EAAE,yBAAyB,EAAE,CAAC;AAErC,gEAAgE;AAChE,eAAO,MAAM,aAAa,WAAW,CAAC;AACtC,uEAAuE;AACvE,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AA2GlD,KAAK,gBAAgB,GAAG,OAAO,GAAG,KAAK,CAAC;AACxC,KAAK,gBAAgB,GAAG,OAAO,GAAG,OAAO,CAAC;AAE1C,UAAU,YAAY;IACpB,YAAY,EAAE,gBAAgB,CAAC;IAC/B,YAAY,EAAE,gBAAgB,CAAC;CAChC;AAmID,UAAU,oBAAqB,SAAQ,YAAY;IACjD,UAAU,EAAE,MAAM,CAAC;CACpB;AA0CD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,oBAAoB,GAAG,MAAM,CAEhF;AAuWD,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,GAAG,aAAa,CAEvG;AAED,eAAO,MAAM,aAAa,EAAE,aAG3B,CAAC"}
package/dist/index.js CHANGED
@@ -7,17 +7,17 @@ import { readJsonFile, } from 'nx/src/devkit-exports.js';
7
7
  import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
8
8
  import { parse as parseToml } from 'smol-toml';
9
9
  import { BOUNDED_TEST_KILL_AFTER_MS, BOUNDED_TEST_TIMEOUT_MS } from './bounded-test-policy.js';
10
+ import { CARGO_TOOLCHAIN_NAMED_INPUT, CARGO_TOOLCHAIN_PIN_INPUTS } from './cargo-toolchain-policy.js';
10
11
  import { attributeCargoWorkspacePackages, CARGO_TEST_ARCHIVE_FILE, CARGO_TEST_ARCHIVE_TARGET, CARGO_TEST_COMPILE_TARGET, CARGO_TEST_EXCEPTIONS_SUFFIX, CARGO_TEST_TARGET, cargoPackageTestInputs, cargoTestPackageTargetName, createCargoInputsCache, exceptionalTestFilter, listCargoCrossTestTargets, listCargoWorkspacePackages, NEXTEST_REPO_CONFIG_PATH, nextestToolConfigArg, } from './cargo-workspace.js';
11
12
  import { CARGO_CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET, CARGO_FETCH_COMMAND, CARGO_FETCH_TARGET, CARGO_FROZEN_PREFIX, CARGO_LINT_CLIPPY_COMMAND, cargoCrossTestArchiveFile, cargoCrossTestArchiveTargetName, cargoCrossTestTargetName, cargoFrozen, } from './cross-check-policy.js';
12
13
  import { hashVersionlessCrateManifests } from './manifest-hash.js';
13
14
  import { isNonSourceDirectory } from './source-directories.js';
14
- import { PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
15
+ import { isBuildOutputTargetName, isTestRunnerTargetName, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
15
16
  export { CARGO_TEST_COMPILE_TARGET };
16
17
  /** Makes a version live and proves it answers; never cached. */
17
18
  export const DEPLOY_TARGET = 'deploy';
18
19
  /** The purely file-derived half a deploy needs built first; cached. */
19
20
  export const DEPLOY_BUILD_TARGET = 'deploy-build';
20
- const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|android|native|napi|bun|wasm)$/;
21
21
  /** The workspace-wide manifests a release rewrites: the version of every member, and the lockfile mirror of it. */
22
22
  const RELEASE_REWRITTEN_WORKSPACE_INPUTS = ['{workspaceRoot}/package.json', '{workspaceRoot}/bun.lock'];
23
23
  const TYPESCRIPT_TOOLCHAIN_INPUTS = [
@@ -147,32 +147,17 @@ function hostPlatformTargetNames(targetNames, hostPlatform) {
147
147
  * its name ends in a family: `*-js`, `*-web`, `*-html`, `*-css`, `*-android`,
148
148
  * `*-native`, `*-napi`, `*-bun`, `*-wasm`.
149
149
  *
150
- * Two spellings of the same collision. A per-crate cargo test runner is
151
- * `cargo-test-<crate>`, so any crate whose name ends in a family put its RUNNER
152
- * in the aggregate; the runners are one serialized chain, so a single such
153
- * crate made `build` pull an entire cargo test suite. A bun suite named
154
- * `test-bun` is the collision without the prefix — a runner reading as
155
- * "tool=test, output=bun", swept into `build` by suffix alone. That one forced
156
- * a consumer to hand-declare `build` purely to replace the inferred list.
157
- *
158
150
  * So the rule is the CLASS, not one namespace: a target that RUNS tests is
159
151
  * never a build output, however it is spelled. Expanding the families here
160
- * rather than delegating to Nx's matcher is what makes that expressible.
152
+ * rather than delegating to Nx's matcher is what makes that expressible, and
153
+ * `package-target-policy` reads the same two predicates to decide whether a
154
+ * hand-declared aggregate is naming an edge this list already produces.
161
155
  */
162
156
  function buildOutputTargetNames(targetNames) {
163
157
  return [...new Set(targetNames)]
164
- .filter((name) => BUILD_OUTPUT_TARGET_PATTERN.test(name) && !isTestRunnerTargetName(name))
158
+ .filter((name) => isBuildOutputTargetName(name) && !isTestRunnerTargetName(name))
165
159
  .sort();
166
160
  }
167
- /**
168
- * A target whose job is to RUN tests. `test`, anything under `test-`/`test:`,
169
- * and the plugin's own `cargo-test-<crate>` namespace. Deliberately name-based:
170
- * the aggregate is assembled from declared AND inferred target names, and a
171
- * declaration carries no marker saying "this executes rather than emits".
172
- */
173
- function isTestRunnerTargetName(name) {
174
- return (name === 'test' || name.startsWith('test-') || name.startsWith('test:') || name.startsWith(`${CARGO_TEST_TARGET}-`));
175
- }
176
161
  //#region smoo!n/rust-output-target-inference
177
162
  // Cargo workspace inference: a package.json sitting next to a Cargo.toml that
178
163
  // declares [workspace] gets direct cargo-test/test targets, cargo-lint feeding
@@ -209,15 +194,10 @@ const REPO_ROOT_CARGO_OUTPUT_INPUTS = [
209
194
  '{workspaceRoot}/scripts/*.sh',
210
195
  '!{workspaceRoot}/**/target/**',
211
196
  ];
212
- // The environment half of a cargo task's identity. Beyond cargo/rustc's own
213
- // variables, every build script that compiles C/C++ reads the Apple SDK
214
- // (SDKROOT, DEVELOPER_DIR, the deployment targets), bindgen reads its libclang
215
- // and extra clang args, cmake-rs forwards CMAKE_*, and zig-based cross links
216
- // read ZIG*. An output linked against one sysroot must never hash equal to
217
- // the same sources linked against another.
218
- const CARGO_ENVIRONMENT_INPUT = {
219
- runtime: `bun -e 'const fs = require("node:fs"); const path = require("node:path"); const home = process.env.CARGO_HOME || path.join(require("node:os").homedir(), ".cargo"); console.log(JSON.stringify({env: Object.entries(process.env).filter(([name]) => /^(?:CARGO_|RUST|NEXTEST_|CLIPPY_|CC(?:_|$)|CXX(?:_|$)|AR(?:_|$)|CFLAGS|CXXFLAGS|CPPFLAGS|LDFLAGS|PKG_CONFIG|TARGET_|HOST_|SDKROOT$|DEVELOPER_DIR$|MACOSX_DEPLOYMENT_TARGET$|IPHONEOS_DEPLOYMENT_TARGET$|LIBCLANG_PATH$|BINDGEN_EXTRA_CLANG_ARGS|CMAKE_|ZIG)/.test(name)).sort(([a], [b]) => a.localeCompare(b)), config: ["config", "config.toml"].map(name => { const file = path.join(home, name); return fs.existsSync(file) ? fs.readFileSync(file, "utf8") : null; })}));'`,
220
- };
197
+ // The toolchain half of a cargo task's identity lives in its own module
198
+ // because `smoo monorepo validate` reads the same two constants to refuse a
199
+ // declaration that drops it. See cargo-toolchain-policy.ts for why it is the
200
+ // declared pin and not the ambient environment.
221
201
  function cargoRuntimeInput(projectRoot, command) {
222
202
  const quotedRoot = `'${projectRoot.replaceAll("'", "'\"'\"'")}'`;
223
203
  return { runtime: `cd ${quotedRoot} && ${command}` };
@@ -237,10 +217,17 @@ function targetCommandText(target) {
237
217
  ].join('\n');
238
218
  }
239
219
  /**
240
- * The N-API build's inputs beyond the Cargo sources: the package's `napi`
241
- * block, which names the binary and the targets, and the napi CLI's resolved
242
- * version from the lockfile. Neither the package version nor any other
243
- * lockfile entry is part of the artifact.
220
+ * The N-API build's inputs beyond the Cargo sources: the toolchain pin, the
221
+ * package's `napi` block, which names the binary and the targets, and the napi
222
+ * CLI's resolved version from the lockfile. Neither the package version nor
223
+ * any other lockfile entry is part of the artifact.
224
+ *
225
+ * The pin is stated here rather than inherited: `napi build` compiles with the
226
+ * same rustc and links against the same SDK as any other cargo target, but its
227
+ * command does not spell `cargo --frozen`, which is how every other cached
228
+ * cargo target acquires its toolchain identity. Without it a `.node` linked
229
+ * against one toolchain hashed equal to the same sources linked against the
230
+ * next one.
244
231
  */
245
232
  function napiInputs(projectRoot, repoRooted) {
246
233
  // Runtime inputs execute from the workspace root, so the manifest is named
@@ -248,6 +235,7 @@ function napiInputs(projectRoot, repoRooted) {
248
235
  const packageJson = `./${posix.join(projectRoot, 'package.json')}`;
249
236
  return [
250
237
  ...(repoRooted ? REPO_ROOT_CARGO_OUTPUT_INPUTS : CARGO_OUTPUT_INPUTS),
238
+ ...CARGO_TOOLCHAIN_PIN_INPUTS,
251
239
  { runtime: `bun -e 'console.log(JSON.stringify(require(${JSON.stringify(packageJson)}).napi ?? null))'` },
252
240
  { externalDependencies: ['@napi-rs/cli'] },
253
241
  ];
@@ -406,7 +394,7 @@ function createCargoTestArchiveTarget(projectRoot, toolConfig) {
406
394
  * (measured: `metadata … --frozen` and `test --no-run … --frozen`).
407
395
  *
408
396
  * The archive target therefore states `CARGO_FETCH_TARGET` and the toolchain
409
- * runtime inputs itself: both are otherwise attached by matching the
397
+ * inputs itself: both are otherwise attached by matching the
410
398
  * `cargo --frozen` prefix in a command, and this command does not carry it.
411
399
  *
412
400
  * The RUNNER declares no dependency on the archive and is not cached. That is
@@ -426,18 +414,21 @@ function createCargoCrossTestTargets(projectRoot, toolConfig, crossTarget, archi
426
414
  [cargoCrossTestArchiveTargetName(triple)]: {
427
415
  executor: 'nx:run-commands',
428
416
  cache: true,
429
- // The two runtime inputs every cached cargo target carries, plus the
430
- // declared driver's own bytes. They are attached elsewhere by matching
431
- // the `cargo --frozen` prefix in a command, which this one does not
432
- // spell — and they matter MORE here than anywhere else: the cross
433
- // environment (SDKROOT, CC_<triple>, ZIG*, and CARGO itself) is what
434
- // decides whether these bytes are Mach-O at all, so an archive linked
435
- // against one sysroot must never hash equal to the same sources linked
436
- // against another.
417
+ // The toolchain inputs every cached cargo target carries, plus the
418
+ // declared driver's own bytes. Those toolchain inputs are attached
419
+ // elsewhere by matching the `cargo --frozen` prefix in a command,
420
+ // which this one does not spell — and the pin matters MORE here than
421
+ // anywhere else: the cross regime this archive links under (the C
422
+ // toolchain for the triple, its sysroot, and the `CARGO` driver below)
423
+ // comes out of the same devenv lock, so an archive built under one pin
424
+ // must never hash equal to the same sources built under another. The
425
+ // declared driver is hashed by its own bytes; nothing samples the shell
426
+ // that supplies it, which is why this hash is the same bare and inside
427
+ // the cross profile.
437
428
  inputs: [
438
429
  ...archiveInputs,
430
+ ...CARGO_TOOLCHAIN_PIN_INPUTS,
439
431
  ...(cargo === undefined ? [] : [`{projectRoot}/${cargo}`]),
440
- cargoRuntimeInput(projectRoot, CARGO_ENVIRONMENT_INPUT.runtime),
441
432
  cargoRuntimeInput(projectRoot, 'rustc -vV && cargo -V && cargo nextest --version'),
442
433
  ],
443
434
  outputs: [`{projectRoot}/${archiveFile}`],
@@ -754,7 +745,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
754
745
  };
755
746
  const inferredTestWatchCommand = inferTestWatchCommand(packageJson);
756
747
  if (inferredTestWatchCommand) {
757
- targets['test:watch'] = {
748
+ targets['test-watch'] = {
758
749
  executor: 'nx:run-commands',
759
750
  continuous: true,
760
751
  dependsOn: ['typecheck-tests'],
@@ -1088,7 +1079,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1088
1079
  : '';
1089
1080
  target.inputs = [
1090
1081
  ...(target.inputs ?? CARGO_INPUTS),
1091
- cargoRuntimeInput(typeof cwd === 'string' ? cwd : projectRoot, CARGO_ENVIRONMENT_INPUT.runtime),
1082
+ ...CARGO_TOOLCHAIN_PIN_INPUTS,
1092
1083
  cargoRuntimeInput(typeof cwd === 'string' ? cwd : projectRoot, `rustc -vV && cargo -V${versions}`),
1093
1084
  ];
1094
1085
  }
@@ -1325,6 +1316,26 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1325
1316
  : {}),
1326
1317
  };
1327
1318
  }
1319
+ // A declared target REPLACES the inferred input list, pin included, so a
1320
+ // repository that hand-writes `inputs` for a cargo target silently loses its
1321
+ // toolchain identity. Name the pin once here so such a declaration can
1322
+ // reference it as `cargoToolchain` instead of restating two paths that could
1323
+ // drift from the plugin; `smoo monorepo validate` refuses a cached cargo
1324
+ // target whose resolved inputs reach neither. Defined only for projects that
1325
+ // HAVE cargo targets: a project's namedInputs definitions are hashed into
1326
+ // its configuration hash, so defining it everywhere would invalidate every
1327
+ // task in the repository to serve projects that can never reference it.
1328
+ const namedInputs = {
1329
+ ...(versionless === null
1330
+ ? {}
1331
+ : {
1332
+ [VERSIONLESS_PRODUCTION_INPUT]: ['production', ...versionlessProjectInputs],
1333
+ [VERSIONLESS_DEFAULT_INPUT]: ['default', ...versionlessProjectInputs],
1334
+ }),
1335
+ ...(Object.keys(targets).some((name) => name.startsWith('cargo-') || name.startsWith('napi-'))
1336
+ ? { [CARGO_TOOLCHAIN_NAMED_INPUT]: [...CARGO_TOOLCHAIN_PIN_INPUTS] }
1337
+ : {}),
1338
+ };
1328
1339
  return {
1329
1340
  projects: {
1330
1341
  [projectRoot]: {
@@ -1338,14 +1349,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1338
1349
  // Nx resolves a named input from the project first and nx.json second,
1339
1350
  // so a workspace-wide definition still covers projects this plugin
1340
1351
  // never inferred.
1341
- ...(versionless === null
1342
- ? {}
1343
- : {
1344
- namedInputs: {
1345
- [VERSIONLESS_PRODUCTION_INPUT]: ['production', ...versionlessProjectInputs],
1346
- [VERSIONLESS_DEFAULT_INPUT]: ['default', ...versionlessProjectInputs],
1347
- },
1348
- }),
1352
+ ...(Object.keys(namedInputs).length === 0 ? {} : { namedInputs }),
1349
1353
  },
1350
1354
  },
1351
1355
  };
@@ -1695,7 +1699,7 @@ function classifyPackageLocalBuildOutputs(packageJson) {
1695
1699
  const targets = packageJson.nx?.targets;
1696
1700
  const targetNames = isRecord(targets) ? Object.keys(targets) : [];
1697
1701
  return {
1698
- ordinary: targetNames.some((targetName) => BUILD_OUTPUT_TARGET_PATTERN.test(targetName)),
1702
+ ordinary: targetNames.some(isBuildOutputTargetName),
1699
1703
  platform: targetNames.some((targetName) => PLATFORM_TARGET_GLOBS.some((glob) => targetName.endsWith(glob.slice(1)))),
1700
1704
  };
1701
1705
  }
@@ -5,7 +5,6 @@ export type { NxPolicyIssue };
5
5
  export interface ResolvedProjectTargets {
6
6
  root?: string;
7
7
  targets: ReadonlySet<string>;
8
- buildDependsOn?: readonly string[];
9
8
  targetDependencies?: ReadonlyMap<string, readonly string[]>;
10
9
  targetExecutors?: ReadonlyMap<string, string>;
11
10
  targetOptions?: ReadonlyMap<string, Readonly<Record<string, unknown>>>;
@@ -1 +1 @@
1
- {"version":3,"file":"package-target-policy.d.ts","sourceRoot":"","sources":["../src/package-target-policy.ts"],"names":[],"mappings":"AAGA,OAAO,EAAyB,KAAK,IAAI,EAAc,MAAM,0BAA0B,CAAC;AAIxF,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAChG,YAAY,EAAE,aAAa,EAAE,CAAC;AAE9B,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC7B,cAAc,CAAC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B,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,0BAA+B,GAAG,OAAO,CA8BxG"}
@@ -3,7 +3,7 @@ import { join } from 'node:path';
3
3
  import { getProjects, readJson, updateJson } from 'nx/src/devkit-exports.js';
4
4
  import { boundedTestScriptAlias } from './bounded-test-policy.js';
5
5
  import { isNonSourceDirectory } from './source-directories.js';
6
- import { BUILD_OUTPUT_DEPENDENCIES, LINUX_PLATFORM_TARGET_GLOBS, MACOS_PLATFORM_TARGET_GLOBS, } from './workspace-config-policy.js';
6
+ import { BUILD_OUTPUT_DEPENDENCIES, isBuildOutputTargetName, isTestRunnerTargetName, LINUX_PLATFORM_TARGET_GLOBS, MACOS_PLATFORM_TARGET_GLOBS, } from './workspace-config-policy.js';
7
7
  export { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
8
8
  const workspaceDependencyFields = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'];
9
9
  function isRecord(value) {
@@ -126,12 +126,6 @@ function resolvedProjectTargetNames(resolvedProject) {
126
126
  }
127
127
  return isResolvedProjectTargets(resolvedProject) ? resolvedProject.targets : resolvedProject;
128
128
  }
129
- function resolvedProjectBuildDependsOn(resolvedProject) {
130
- if (!isResolvedProjectTargets(resolvedProject)) {
131
- return undefined;
132
- }
133
- return resolvedProject.buildDependsOn;
134
- }
135
129
  function resolvedProjectTargetExecutor(resolvedProject, targetName) {
136
130
  return isResolvedProjectTargets(resolvedProject) ? resolvedProject.targetExecutors?.get(targetName) : undefined;
137
131
  }
@@ -198,34 +192,67 @@ function isNoopTarget(target) {
198
192
  const options = recordProperty(target, 'options');
199
193
  return !options || stringProperty(options, 'command') === null;
200
194
  }
201
- function targetDependenciesMatchResolvedBuild(target, resolvedBuildDependsOn) {
202
- if (!Array.isArray(target.dependsOn)) {
195
+ /**
196
+ * Properties the inferred aggregate already sets to exactly these values. A
197
+ * declaration carrying anything else — `inputs`, `outputs`, `cache: false`, a
198
+ * `configurations` block — is CHANGING the aggregate, not restating it.
199
+ */
200
+ const inferredNoopBuildProperties = { executor: true, cache: true, dependsOn: true };
201
+ /**
202
+ * Can the build-aggregate inference produce this edge on its own?
203
+ *
204
+ * The inferred aggregate is `^build` plus the project's own build-output
205
+ * targets — `isBuildOutputTargetName`, test runners excluded — and
206
+ * `BUILD_OUTPUT_DEPENDENCIES` is the glob spelling of that same list. Anything
207
+ * else is an edge only the declaration carries: a project-local target outside
208
+ * the families (`build-cli`), or a `project:target` edge to a sibling target
209
+ * that is not named `build`, which `^build` never visits.
210
+ */
211
+ function isInferredBuildDependency(dependency, resolvedTargets) {
212
+ if (typeof dependency !== 'string') {
213
+ return false;
214
+ }
215
+ if (dependency === '^build' || isBuildOutputDependencyPattern(dependency)) {
216
+ return true;
217
+ }
218
+ return isBuildOutputTargetName(dependency) && !isTestRunnerTargetName(dependency) && resolvedTargets.has(dependency);
219
+ }
220
+ function isRedundantBuildDeclaration(build, resolvedTargets) {
221
+ if (!Object.keys(build).every((key) => inferredNoopBuildProperties[key] === true)) {
203
222
  return false;
204
223
  }
205
- const expected = new Set(resolvedBuildDependsOn);
206
- if (target.dependsOn.length !== expected.size) {
224
+ if ('cache' in build && build.cache !== true) {
207
225
  return false;
208
226
  }
209
- return target.dependsOn.every((dependency) => {
210
- if (typeof dependency !== 'string') {
211
- return false;
212
- }
213
- return expected.has(dependency);
214
- });
227
+ // An empty list is a deliberate cut — "this aggregate waits for nothing" —
228
+ // and restoring the inferred edges by deleting it is a behaviour change.
229
+ return (Array.isArray(build.dependsOn) &&
230
+ build.dependsOn.length > 0 &&
231
+ build.dependsOn.every((dependency) => isInferredBuildDependency(dependency, resolvedTargets)));
215
232
  }
233
+ /**
234
+ * A hand-declared `build` is deleted only when inference provably rebuilds it.
235
+ *
236
+ * Deliberately NOT decided against the resolved project graph. Nx replaces a
237
+ * named property of an inferred target with the declared one, so the resolved
238
+ * `build.dependsOn` IS the declaration: comparing them answered "redundant"
239
+ * for every noop aggregate anyone ever wrote. AxE's `containium` lost seven
240
+ * edges that way — four of them targets no inference can reach — and a clean
241
+ * checkout then built it without its producers. The question this has to
242
+ * answer is what inference yields WITHOUT the declaration, so the test is
243
+ * structural: every declared edge must be one the aggregate already collects.
244
+ */
216
245
  function removeRedundantNoopBuildTarget(pkg, resolvedProject) {
217
246
  const resolvedTargets = resolvedProjectTargetNames(resolvedProject);
218
- const resolvedBuildDependsOn = resolvedProjectBuildDependsOn(resolvedProject);
219
- if (!resolvedTargets?.has('build') || !resolvedBuildDependsOn) {
247
+ // No build-output target in the project, no inferred aggregate to fall back
248
+ // on: deleting the declaration would leave it with no `build` at all.
249
+ if (!resolvedTargets?.has('build') || ![...resolvedTargets].some(isBuildOutputTargetName)) {
220
250
  return false;
221
251
  }
222
252
  const nx = recordProperty(pkg, 'nx');
223
253
  const targets = nx ? recordProperty(nx, 'targets') : null;
224
254
  const build = targets ? recordProperty(targets, 'build') : null;
225
- if (!targets ||
226
- !build ||
227
- !isNoopTarget(build) ||
228
- !targetDependenciesMatchResolvedBuild(build, resolvedBuildDependsOn)) {
255
+ if (!targets || !build || !isNoopTarget(build) || !isRedundantBuildDeclaration(build, resolvedTargets)) {
229
256
  return false;
230
257
  }
231
258
  delete targets.build;
@@ -7,6 +7,27 @@ export declare const BUILD_OUTPUT_DEPENDENCIES: readonly ['*-js', '*-web', '*-ht
7
7
  export declare const MACOS_PLATFORM_TARGET_GLOBS: readonly ['*-macos', '*-ios'];
8
8
  export declare const LINUX_PLATFORM_TARGET_GLOBS: readonly ['*-linux'];
9
9
  export declare const PLATFORM_TARGET_GLOBS: readonly ["*-macos", "*-ios", "*-linux"];
10
+ /**
11
+ * The glob list above, spelled as a target name: a target whose name ends in a
12
+ * reserved family suffix EMITS that kind of artifact. Inference collects
13
+ * exactly these names into the `nx:noop` build aggregate, which makes this the
14
+ * same rule that decides whether a hand-declared aggregate names an edge
15
+ * inference could have produced on its own — one definition, two readers, so
16
+ * the removal policy cannot drift away from what it judges redundant.
17
+ */
18
+ export declare function isBuildOutputTargetName(name: string): boolean;
19
+ /**
20
+ * A target whose job is to RUN tests. `test`, anything under `test-`/`test:`,
21
+ * and the plugin's own `cargo-test-<crate>` namespace. Deliberately name-based:
22
+ * the aggregate is assembled from declared AND inferred target names, and a
23
+ * declaration carries no marker saying "this executes rather than emits".
24
+ *
25
+ * A runner collides with the families by construction whenever its name ends in
26
+ * one: a crate named `…-js` puts `cargo-test-<crate>` in the family, and a bun
27
+ * suite named `test-bun` reads as "tool=test, output=bun". Both would drag a
28
+ * test suite into `build`, so the rule is the CLASS, not one namespace.
29
+ */
30
+ export declare function isTestRunnerTargetName(name: string): boolean;
10
31
  /**
11
32
  * Check workspace config policy on an in-memory nx.json object.
12
33
  */
@@ -1 +1 @@
1
- {"version":3,"file":"workspace-config-policy.d.ts","sourceRoot":"","sources":["../src/workspace-config-policy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAGrD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,yBAAyB,YACpC,MAAM,EACN,OAAO,EACP,QAAQ,EACR,OAAO,EACP,WAAW,EACX,UAAU,EACV,QAAQ,EACR,OAAO,EACP,QAAQ,CACA,CAAC;AAEX,eAAO,MAAM,2BAA2B,YAAI,SAAS,EAAE,OAAO,CAAU,CAAC;AACzE,eAAO,MAAM,2BAA2B,YAAI,SAAS,CAAU,CAAC;AAChE,eAAO,MAAM,qBAAqB,0CAA4E,CAAC;AAgB/G;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,EAAE,CA4DrF;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,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AAG,OAAO,CAe7E;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,GAAG,aAAa,EAAE,CAKpE;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAU5D;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAYxE;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAWhE"}
@@ -1,6 +1,7 @@
1
1
  import { existsSync, readFileSync, writeFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { readJson, updateJson } from 'nx/src/devkit-exports.js';
4
+ import { CARGO_TEST_TARGET } from './cargo-workspace.js';
4
5
  export const BUILD_OUTPUT_DEPENDENCIES = [
5
6
  '*-js',
6
7
  '*-web',
@@ -15,6 +16,32 @@ export const BUILD_OUTPUT_DEPENDENCIES = [
15
16
  export const MACOS_PLATFORM_TARGET_GLOBS = ['*-macos', '*-ios'];
16
17
  export const LINUX_PLATFORM_TARGET_GLOBS = ['*-linux'];
17
18
  export const PLATFORM_TARGET_GLOBS = [...MACOS_PLATFORM_TARGET_GLOBS, ...LINUX_PLATFORM_TARGET_GLOBS];
19
+ const buildOutputTargetSuffixes = BUILD_OUTPUT_DEPENDENCIES.map((glob) => glob.slice(1));
20
+ /**
21
+ * The glob list above, spelled as a target name: a target whose name ends in a
22
+ * reserved family suffix EMITS that kind of artifact. Inference collects
23
+ * exactly these names into the `nx:noop` build aggregate, which makes this the
24
+ * same rule that decides whether a hand-declared aggregate names an edge
25
+ * inference could have produced on its own — one definition, two readers, so
26
+ * the removal policy cannot drift away from what it judges redundant.
27
+ */
28
+ export function isBuildOutputTargetName(name) {
29
+ return buildOutputTargetSuffixes.some((suffix) => name.endsWith(suffix));
30
+ }
31
+ /**
32
+ * A target whose job is to RUN tests. `test`, anything under `test-`/`test:`,
33
+ * and the plugin's own `cargo-test-<crate>` namespace. Deliberately name-based:
34
+ * the aggregate is assembled from declared AND inferred target names, and a
35
+ * declaration carries no marker saying "this executes rather than emits".
36
+ *
37
+ * A runner collides with the families by construction whenever its name ends in
38
+ * one: a crate named `…-js` puts `cargo-test-<crate>` in the family, and a bun
39
+ * suite named `test-bun` reads as "tool=test, output=bun". Both would drag a
40
+ * test suite into `build`, so the rule is the CLASS, not one namespace.
41
+ */
42
+ export function isTestRunnerTargetName(name) {
43
+ return (name === 'test' || name.startsWith('test-') || name.startsWith('test:') || name.startsWith(`${CARGO_TEST_TARGET}-`));
44
+ }
18
45
  const nxJsTypescriptPlugin = '@nx/js/typescript';
19
46
  const smoothBricksNxPlugin = '@smoothbricks/nx-plugin';
20
47
  const cleanOutputsExecutor = '@smoothbricks/nx-plugin:clean-outputs';