@smoothbricks/nx-plugin 0.4.12 → 0.4.14
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 +24 -6
- package/dist/cargo-toolchain-policy.d.ts +61 -0
- package/dist/cargo-toolchain-policy.d.ts.map +1 -0
- package/dist/cargo-toolchain-policy.js +65 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +77 -52
- package/package.json +7 -2
- package/src/cargo-toolchain-policy.ts +68 -0
- package/src/index.test.ts +157 -41
- package/src/index.ts +80 -52
package/README.md
CHANGED
|
@@ -13,7 +13,8 @@ with `tsconfig.lib.json` receives transformer-aware `tsc-js` and native `typeche
|
|
|
13
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
|
-
- an uncached `deploy` for a project with a wrangler manifest, running
|
|
16
|
+
- an uncached `deploy` for a PRIVATE project with a wrangler manifest, running
|
|
17
|
+
`smoo wrangler deploy-stage --stage {args.stage}`
|
|
17
18
|
|
|
18
19
|
The deploy is one target that takes whichever stage it is given, never a configuration per stage: pull-request stages
|
|
19
20
|
are `prN` for unbounded N, so `nx run <project>:deploy --stage=pr42` has to work for a stage no enumeration could list.
|
|
@@ -22,6 +23,12 @@ Declaring `deploy` locally overrides only the properties it names, so a project
|
|
|
22
23
|
`"dependsOn": ["...", "backend:deploy"]` and keeps the inferred command; a project that declares `deploy-build` gets
|
|
23
24
|
that edge instead of `build`, and the plugin caches that half without inventing its command.
|
|
24
25
|
|
|
26
|
+
`private: true` is half the detection, because a wrangler manifest alone does not mean deployable: a published library
|
|
27
|
+
ships one to document the Durable Object binding it implements, and that manifest carries the same `name`, `main` and
|
|
28
|
+
`compatibility_date` a deployable worker's does. So the inferred target goes to packages npm will never publish, and a
|
|
29
|
+
published package that really is deployed declares `deploy` itself. Whether CI deploys any of them is a separate
|
|
30
|
+
question, answered only by the deploy tags the CLI reads (`stage-deploy-target` and its three siblings).
|
|
31
|
+
|
|
25
32
|
Lint commands are inferred per project. A workspace Biome configuration enables the project-wide Biome check; an ESLint
|
|
26
33
|
flat configuration enables ESLint only for existing JavaScript/TypeScript files under that project's `src`. Rust-only
|
|
27
34
|
source trees therefore keep their Cargo validation and manifest checks without invoking ESLint on nonexistent JavaScript
|
|
@@ -61,11 +68,22 @@ Cargo's shared mutable build directory before the bounded runner, even if that d
|
|
|
61
68
|
successful run. Cargo's own incremental cache avoids recompiling unchanged code. Nx never restores or collects shared
|
|
62
69
|
Cargo build directories; lint and test **results**, and dedicated Wasm/N-API **outputs**, remain cacheable.
|
|
63
70
|
|
|
64
|
-
Validation inputs include the crate's files, local dependency closure, governing manifests and configuration,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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.
|
|
69
87
|
|
|
70
88
|
Cargo keeps the caller's `CARGO_HOME`. Moving configuration into an isolated home can change relative paths or lose
|
|
71
89
|
source replacement, credentials, and toolchain settings; forwarding it with `--config` changes precedence. Registry
|
|
@@ -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
|
+
}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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;
|
|
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;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;AAqJD,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,6 +7,7 @@ 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';
|
|
@@ -209,15 +210,10 @@ const REPO_ROOT_CARGO_OUTPUT_INPUTS = [
|
|
|
209
210
|
'{workspaceRoot}/scripts/*.sh',
|
|
210
211
|
'!{workspaceRoot}/**/target/**',
|
|
211
212
|
];
|
|
212
|
-
// The
|
|
213
|
-
//
|
|
214
|
-
//
|
|
215
|
-
//
|
|
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
|
-
};
|
|
213
|
+
// The toolchain half of a cargo task's identity lives in its own module
|
|
214
|
+
// because `smoo monorepo validate` reads the same two constants to refuse a
|
|
215
|
+
// declaration that drops it. See cargo-toolchain-policy.ts for why it is the
|
|
216
|
+
// declared pin and not the ambient environment.
|
|
221
217
|
function cargoRuntimeInput(projectRoot, command) {
|
|
222
218
|
const quotedRoot = `'${projectRoot.replaceAll("'", "'\"'\"'")}'`;
|
|
223
219
|
return { runtime: `cd ${quotedRoot} && ${command}` };
|
|
@@ -237,10 +233,17 @@ function targetCommandText(target) {
|
|
|
237
233
|
].join('\n');
|
|
238
234
|
}
|
|
239
235
|
/**
|
|
240
|
-
* The N-API build's inputs beyond the Cargo sources: the
|
|
241
|
-
* block, which names the binary and the targets, and the napi
|
|
242
|
-
* version from the lockfile. Neither the package version nor
|
|
243
|
-
* lockfile entry is part of the artifact.
|
|
236
|
+
* The N-API build's inputs beyond the Cargo sources: the toolchain pin, the
|
|
237
|
+
* package's `napi` block, which names the binary and the targets, and the napi
|
|
238
|
+
* CLI's resolved version from the lockfile. Neither the package version nor
|
|
239
|
+
* any other lockfile entry is part of the artifact.
|
|
240
|
+
*
|
|
241
|
+
* The pin is stated here rather than inherited: `napi build` compiles with the
|
|
242
|
+
* same rustc and links against the same SDK as any other cargo target, but its
|
|
243
|
+
* command does not spell `cargo --frozen`, which is how every other cached
|
|
244
|
+
* cargo target acquires its toolchain identity. Without it a `.node` linked
|
|
245
|
+
* against one toolchain hashed equal to the same sources linked against the
|
|
246
|
+
* next one.
|
|
244
247
|
*/
|
|
245
248
|
function napiInputs(projectRoot, repoRooted) {
|
|
246
249
|
// Runtime inputs execute from the workspace root, so the manifest is named
|
|
@@ -248,6 +251,7 @@ function napiInputs(projectRoot, repoRooted) {
|
|
|
248
251
|
const packageJson = `./${posix.join(projectRoot, 'package.json')}`;
|
|
249
252
|
return [
|
|
250
253
|
...(repoRooted ? REPO_ROOT_CARGO_OUTPUT_INPUTS : CARGO_OUTPUT_INPUTS),
|
|
254
|
+
...CARGO_TOOLCHAIN_PIN_INPUTS,
|
|
251
255
|
{ runtime: `bun -e 'console.log(JSON.stringify(require(${JSON.stringify(packageJson)}).napi ?? null))'` },
|
|
252
256
|
{ externalDependencies: ['@napi-rs/cli'] },
|
|
253
257
|
];
|
|
@@ -406,7 +410,7 @@ function createCargoTestArchiveTarget(projectRoot, toolConfig) {
|
|
|
406
410
|
* (measured: `metadata … --frozen` and `test --no-run … --frozen`).
|
|
407
411
|
*
|
|
408
412
|
* The archive target therefore states `CARGO_FETCH_TARGET` and the toolchain
|
|
409
|
-
*
|
|
413
|
+
* inputs itself: both are otherwise attached by matching the
|
|
410
414
|
* `cargo --frozen` prefix in a command, and this command does not carry it.
|
|
411
415
|
*
|
|
412
416
|
* The RUNNER declares no dependency on the archive and is not cached. That is
|
|
@@ -426,18 +430,21 @@ function createCargoCrossTestTargets(projectRoot, toolConfig, crossTarget, archi
|
|
|
426
430
|
[cargoCrossTestArchiveTargetName(triple)]: {
|
|
427
431
|
executor: 'nx:run-commands',
|
|
428
432
|
cache: true,
|
|
429
|
-
// The
|
|
430
|
-
// declared driver's own bytes.
|
|
431
|
-
// the `cargo --frozen` prefix in a command,
|
|
432
|
-
// spell — and
|
|
433
|
-
//
|
|
434
|
-
//
|
|
435
|
-
//
|
|
436
|
-
//
|
|
433
|
+
// The toolchain inputs every cached cargo target carries, plus the
|
|
434
|
+
// declared driver's own bytes. Those toolchain inputs are attached
|
|
435
|
+
// elsewhere by matching the `cargo --frozen` prefix in a command,
|
|
436
|
+
// which this one does not spell — and the pin matters MORE here than
|
|
437
|
+
// anywhere else: the cross regime this archive links under (the C
|
|
438
|
+
// toolchain for the triple, its sysroot, and the `CARGO` driver below)
|
|
439
|
+
// comes out of the same devenv lock, so an archive built under one pin
|
|
440
|
+
// must never hash equal to the same sources built under another. The
|
|
441
|
+
// declared driver is hashed by its own bytes; nothing samples the shell
|
|
442
|
+
// that supplies it, which is why this hash is the same bare and inside
|
|
443
|
+
// the cross profile.
|
|
437
444
|
inputs: [
|
|
438
445
|
...archiveInputs,
|
|
446
|
+
...CARGO_TOOLCHAIN_PIN_INPUTS,
|
|
439
447
|
...(cargo === undefined ? [] : [`{projectRoot}/${cargo}`]),
|
|
440
|
-
cargoRuntimeInput(projectRoot, CARGO_ENVIRONMENT_INPUT.runtime),
|
|
441
448
|
cargoRuntimeInput(projectRoot, 'rustc -vV && cargo -V && cargo nextest --version'),
|
|
442
449
|
],
|
|
443
450
|
outputs: [`{projectRoot}/${archiveFile}`],
|
|
@@ -618,20 +625,22 @@ function packageBinOutputs(packageJson, packageJsonPath) {
|
|
|
618
625
|
}
|
|
619
626
|
/**
|
|
620
627
|
* The deployment manifests wrangler itself looks for, in its own precedence
|
|
621
|
-
* order. Finding one
|
|
622
|
-
*
|
|
628
|
+
* order. Finding one is HALF the detection: a published library ships one to
|
|
629
|
+
* document a Durable Object binding for its consumers, and that manifest is
|
|
630
|
+
* structurally indistinguishable from a deployable worker's — same `name`,
|
|
631
|
+
* `main` and `compatibility_date`. So presence alone cannot mean deployable,
|
|
632
|
+
* and the other half is `private: true` below.
|
|
623
633
|
*
|
|
624
634
|
* Deploy POLICY is deliberately NOT read from the manifest. `smoo.wrangler.stages`
|
|
625
635
|
* belongs to the CLI, which reads it to decide which secrets a stage requires; a
|
|
626
636
|
* second copy in the graph would disagree the first time a stage was added. And
|
|
627
|
-
* which stages CI actually runs is the four-way vocabulary in the CLI's
|
|
637
|
+
* which stages CI actually runs is the four-way tag vocabulary in the CLI's
|
|
628
638
|
* `deploy-tags.ts` — every stage, staging only, excluded, production-on-push —
|
|
629
|
-
* that a flag here could express exactly one of. So
|
|
630
|
-
* the target, and
|
|
639
|
+
* that a flag here could express exactly one of. So a private wrangler project
|
|
640
|
+
* gets the target, and the tags alone decide what CI deploys.
|
|
631
641
|
*
|
|
632
642
|
* A worker deployed by some other mechanism declares its own `options.command`,
|
|
633
|
-
* which replaces this one;
|
|
634
|
-
* it, because the `deploy-stage` string went with it.
|
|
643
|
+
* which replaces this one; the tag is what CI reads either way.
|
|
635
644
|
*/
|
|
636
645
|
const WRANGLER_CONFIG_FILES = ['wrangler.jsonc', 'wrangler.json', 'wrangler.toml'];
|
|
637
646
|
/**
|
|
@@ -640,11 +649,10 @@ const WRANGLER_CONFIG_FILES = ['wrangler.jsonc', 'wrangler.json', 'wrangler.toml
|
|
|
640
649
|
* `configurations` map cannot describe the surface that actually exists, and a
|
|
641
650
|
* project carrying both spellings would have two ways to say one thing.
|
|
642
651
|
*
|
|
643
|
-
* No `stage-deploy-target` tag either, deliberately: the
|
|
644
|
-
*
|
|
645
|
-
*
|
|
646
|
-
*
|
|
647
|
-
* answers, and the two would drift the first time either moved.
|
|
652
|
+
* No `stage-deploy-target` tag either, deliberately: that tag is the repository's
|
|
653
|
+
* statement that CI deploys this project on every stage, and only the repository
|
|
654
|
+
* can make it. A plugin that tagged what it inferred would enrol every private
|
|
655
|
+
* wrangler project in CI deploys by writing the policy it is supposed to read.
|
|
648
656
|
*
|
|
649
657
|
* `{args.stage}` rather than `forwardAllArgs`: run-commands'
|
|
650
658
|
* `interpolateArgsIntoCommand` returns as soon as it sees `{args.` and never
|
|
@@ -696,7 +704,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
696
704
|
const packageLocalBuildOutputs = classifyPackageLocalBuildOutputs(packageJson);
|
|
697
705
|
const hasOrdinaryBuildOutputTarget = hasLibTsconfig || napiConfig !== null || cargoWasmConfig !== null || packageLocalBuildOutputs.ordinary;
|
|
698
706
|
const hasAnyBuildOutputTarget = hasOrdinaryBuildOutputTarget || packageLocalBuildOutputs.platform;
|
|
699
|
-
const
|
|
707
|
+
const isDeployableWranglerProject = packageJson.private === true && WRANGLER_CONFIG_FILES.some((file) => existsSync(join(absoluteProjectRoot, file)));
|
|
700
708
|
if (hasLibTsconfig) {
|
|
701
709
|
const executableOutputs = packageBinOutputs(packageJson, packageJsonPath);
|
|
702
710
|
// Dependency packages may publish bundled entries that raw tsc does not produce.
|
|
@@ -1087,7 +1095,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1087
1095
|
: '';
|
|
1088
1096
|
target.inputs = [
|
|
1089
1097
|
...(target.inputs ?? CARGO_INPUTS),
|
|
1090
|
-
|
|
1098
|
+
...CARGO_TOOLCHAIN_PIN_INPUTS,
|
|
1091
1099
|
cargoRuntimeInput(typeof cwd === 'string' ? cwd : projectRoot, `rustc -vV && cargo -V${versions}`),
|
|
1092
1100
|
];
|
|
1093
1101
|
}
|
|
@@ -1198,16 +1206,19 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1198
1206
|
// `"dependsOn": ["...", "backend:deploy"]` and keeps both the edge below and this command —
|
|
1199
1207
|
// measured, not assumed, against an inferred base.
|
|
1200
1208
|
//
|
|
1201
|
-
// `deploy` is INFERRED for a wrangler project rather than patched onto a hand-written
|
|
1202
|
-
// command is a constant of the convention, not of the project: every consumer wrote
|
|
1203
|
-
// `nx:run-commands` wrapper around it
|
|
1204
|
-
// a
|
|
1205
|
-
//
|
|
1206
|
-
//
|
|
1209
|
+
// `deploy` is INFERRED for a private wrangler project rather than patched onto a hand-written
|
|
1210
|
+
// one. The command is a constant of the convention, not of the project: every consumer wrote
|
|
1211
|
+
// the same `nx:run-commands` wrapper around it. `private: true` is the second half of the
|
|
1212
|
+
// detection: a PUBLISHED package's wrangler manifest documents a binding for its consumers,
|
|
1213
|
+
// so inferring a deploy from it would put a live `wrangler deploy` of someone's documentation
|
|
1214
|
+
// one `nx run-many -t deploy` away. A published package that really is deployed declares
|
|
1215
|
+
// `deploy` itself. `deploy-build` stays declaration-driven in the other direction, because
|
|
1216
|
+
// only the project knows what building it means — the plugin supplies its POLICY (cache
|
|
1217
|
+
// honestly) and nothing else.
|
|
1207
1218
|
if (DEPLOY_BUILD_TARGET in declaredTargets) {
|
|
1208
1219
|
targets[DEPLOY_BUILD_TARGET] = { cache: true };
|
|
1209
1220
|
}
|
|
1210
|
-
if (
|
|
1221
|
+
if (isDeployableWranglerProject) {
|
|
1211
1222
|
// Naming only an edge that exists is tidiness, not a guard: Nx tolerates a `dependsOn` on a
|
|
1212
1223
|
// target the project lacks — measured, the task just runs alone — and a wrangler worker can
|
|
1213
1224
|
// legitimately have no build at all, since wrangler bundles its own TypeScript. Pointing at a
|
|
@@ -1321,6 +1332,26 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1321
1332
|
: {}),
|
|
1322
1333
|
};
|
|
1323
1334
|
}
|
|
1335
|
+
// A declared target REPLACES the inferred input list, pin included, so a
|
|
1336
|
+
// repository that hand-writes `inputs` for a cargo target silently loses its
|
|
1337
|
+
// toolchain identity. Name the pin once here so such a declaration can
|
|
1338
|
+
// reference it as `cargoToolchain` instead of restating two paths that could
|
|
1339
|
+
// drift from the plugin; `smoo monorepo validate` refuses a cached cargo
|
|
1340
|
+
// target whose resolved inputs reach neither. Defined only for projects that
|
|
1341
|
+
// HAVE cargo targets: a project's namedInputs definitions are hashed into
|
|
1342
|
+
// its configuration hash, so defining it everywhere would invalidate every
|
|
1343
|
+
// task in the repository to serve projects that can never reference it.
|
|
1344
|
+
const namedInputs = {
|
|
1345
|
+
...(versionless === null
|
|
1346
|
+
? {}
|
|
1347
|
+
: {
|
|
1348
|
+
[VERSIONLESS_PRODUCTION_INPUT]: ['production', ...versionlessProjectInputs],
|
|
1349
|
+
[VERSIONLESS_DEFAULT_INPUT]: ['default', ...versionlessProjectInputs],
|
|
1350
|
+
}),
|
|
1351
|
+
...(Object.keys(targets).some((name) => name.startsWith('cargo-') || name.startsWith('napi-'))
|
|
1352
|
+
? { [CARGO_TOOLCHAIN_NAMED_INPUT]: [...CARGO_TOOLCHAIN_PIN_INPUTS] }
|
|
1353
|
+
: {}),
|
|
1354
|
+
};
|
|
1324
1355
|
return {
|
|
1325
1356
|
projects: {
|
|
1326
1357
|
[projectRoot]: {
|
|
@@ -1334,14 +1365,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1334
1365
|
// Nx resolves a named input from the project first and nx.json second,
|
|
1335
1366
|
// so a workspace-wide definition still covers projects this plugin
|
|
1336
1367
|
// never inferred.
|
|
1337
|
-
...(
|
|
1338
|
-
? {}
|
|
1339
|
-
: {
|
|
1340
|
-
namedInputs: {
|
|
1341
|
-
[VERSIONLESS_PRODUCTION_INPUT]: ['production', ...versionlessProjectInputs],
|
|
1342
|
-
[VERSIONLESS_DEFAULT_INPUT]: ['default', ...versionlessProjectInputs],
|
|
1343
|
-
},
|
|
1344
|
-
}),
|
|
1368
|
+
...(Object.keys(namedInputs).length === 0 ? {} : { namedInputs }),
|
|
1345
1369
|
},
|
|
1346
1370
|
},
|
|
1347
1371
|
};
|
|
@@ -1634,6 +1658,7 @@ async function readPackageJson(packageJsonPath) {
|
|
|
1634
1658
|
...('bin' in parsed ? { bin: parsed.bin } : {}),
|
|
1635
1659
|
...(typeof parsed.name === 'string' ? { name: parsed.name } : {}),
|
|
1636
1660
|
...(isRecord(parsed.napi) ? { napi: parsed.napi } : {}),
|
|
1661
|
+
...(typeof parsed.private === 'boolean' ? { private: parsed.private } : {}),
|
|
1637
1662
|
...(isRecord(parsed.scripts) ? { scripts: parsed.scripts } : {}),
|
|
1638
1663
|
...(rawNx
|
|
1639
1664
|
? {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smoothbricks/nx-plugin",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./loader.js",
|
|
@@ -52,6 +52,11 @@
|
|
|
52
52
|
"types": "./dist/cross-check-policy.d.ts",
|
|
53
53
|
"import": "./dist/cross-check-policy.js",
|
|
54
54
|
"default": "./dist/cross-check-policy.js"
|
|
55
|
+
},
|
|
56
|
+
"./cargo-toolchain-policy": {
|
|
57
|
+
"types": "./dist/cargo-toolchain-policy.d.ts",
|
|
58
|
+
"import": "./dist/cargo-toolchain-policy.js",
|
|
59
|
+
"default": "./dist/cargo-toolchain-policy.js"
|
|
55
60
|
}
|
|
56
61
|
},
|
|
57
62
|
"bin": {
|
|
@@ -108,7 +113,7 @@
|
|
|
108
113
|
"typia": "14.0.2"
|
|
109
114
|
},
|
|
110
115
|
"devDependencies": {
|
|
111
|
-
"@smoothbricks/lmao": "0.3.
|
|
116
|
+
"@smoothbricks/lmao": "0.3.13",
|
|
112
117
|
"@smoothbricks/validation": "0.1.8"
|
|
113
118
|
}
|
|
114
119
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
/**
|
|
8
|
+
* The DECLARED pin, hashed as an ordinary file. devenv resolves this lock into
|
|
9
|
+
* the rustc, cargo, linker, C toolchain and SDK that every cargo command
|
|
10
|
+
* inherits, so a bump here is exactly the event that must invalidate a cached
|
|
11
|
+
* artifact — and it is the only such event the workspace can state portably.
|
|
12
|
+
*
|
|
13
|
+
* This replaces a runtime input that dumped the ambient cargo environment
|
|
14
|
+
* (every `CARGO_`, `RUST`, `CC`, `CXX`, `AR`, `SDKROOT`, `LIBCLANG_PATH`,
|
|
15
|
+
* `CMAKE_` and `ZIG` prefixed variable, plus the contents of
|
|
16
|
+
* `$CARGO_HOME/config{,.toml}`). That bought the same
|
|
17
|
+
* invalidation at the price of two defects. Its values are absolute
|
|
18
|
+
* `/nix/store/<hash>-…` paths and per-checkout devenv state directories, so no
|
|
19
|
+
* two machines ever agree and no cargo target can share a cache entry with a
|
|
20
|
+
* peer or with CI — a remote cache for Rust was dead on arrival. And the dump
|
|
21
|
+
* differs between a bare shell and a devenv profile for the SAME sources: in
|
|
22
|
+
* the `linux-cross` profile `AR` becomes `x86_64-unknown-linux-gnu-ar`,
|
|
23
|
+
* `CARGO_INSTALL_ROOT` moves under `profiles/linux-cross/`, and
|
|
24
|
+
* `CC_x86_64_unknown_linux_gnu` appears, so the entry `check:linux` writes
|
|
25
|
+
* inside the profile could never be hit by the pre-push probe, which runs
|
|
26
|
+
* bare. Measured on one repository-root archive target with the dump still in
|
|
27
|
+
* place: bare 18197306115812424011, in-profile 12567954759860890767.
|
|
28
|
+
*
|
|
29
|
+
* A file input has neither defect. The lock's bytes are identical bare and
|
|
30
|
+
* in-profile and on every machine holding the checkout, while the toolchain
|
|
31
|
+
* VERSIONS the dump was really guarding stay covered twice over — by the pin
|
|
32
|
+
* itself, and by the `rustc -vV && cargo -V` runtime input attached beside it,
|
|
33
|
+
* whose stdout is byte-identical in both shells (measured). Nothing
|
|
34
|
+
* machine-local survives. A NARROWED dump was rejected rather than kept: a
|
|
35
|
+
* subset re-acquires a store path the moment anyone widens it.
|
|
36
|
+
*
|
|
37
|
+
* Both fleet locations are stated: the pin lives under `tooling/direnv/` in
|
|
38
|
+
* every repository and additionally at the root in some. A fileset that
|
|
39
|
+
* matches nothing contributes nothing — the same property the inert
|
|
40
|
+
* `rust-toolchain*` entries already rely on.
|
|
41
|
+
*/
|
|
42
|
+
export const CARGO_TOOLCHAIN_PIN_INPUTS: readonly string[] = [
|
|
43
|
+
'{workspaceRoot}/devenv.lock',
|
|
44
|
+
'{workspaceRoot}/tooling/direnv/devenv.lock',
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The name a repository's own `inputs` declaration uses to reach the pin
|
|
49
|
+
* without restating its paths.
|
|
50
|
+
*
|
|
51
|
+
* A declared target REPLACES the inferred input list, pin included, so a
|
|
52
|
+
* hand-written `inputs` array silently drops the toolchain identity and the
|
|
53
|
+
* target stops seeing a toolchain bump at all. Inference defines this named
|
|
54
|
+
* input on every project that has cargo targets so a declaration can name one
|
|
55
|
+
* token that cannot drift from what the plugin attaches.
|
|
56
|
+
*/
|
|
57
|
+
export const CARGO_TOOLCHAIN_NAMED_INPUT = 'cargoToolchain';
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Does one resolved input string carry the toolchain identity?
|
|
61
|
+
*
|
|
62
|
+
* Resolved: named inputs already expanded. The check is by suffix rather than
|
|
63
|
+
* by exact path because a repository may keep its lock at a location this list
|
|
64
|
+
* does not name; what matters is that a devenv lock is hashed, not which one.
|
|
65
|
+
*/
|
|
66
|
+
export function isCargoToolchainInput(input: string): boolean {
|
|
67
|
+
return !input.startsWith('!') && input.endsWith('/devenv.lock');
|
|
68
|
+
}
|
package/src/index.test.ts
CHANGED
|
@@ -882,6 +882,11 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
882
882
|
).toBe(true);
|
|
883
883
|
expect(napiInputs).not.toContain('{workspaceRoot}/bun.lock');
|
|
884
884
|
expect(napiInputs.some((input) => typeof input === 'string' && input.endsWith('/package.json'))).toBe(false);
|
|
885
|
+
// ... and on the toolchain pin, which it must state itself: `napi build`
|
|
886
|
+
// compiles with the pinned rustc but never spells `cargo --frozen`, so
|
|
887
|
+
// the sweep that gives every other cargo target its identity skips it.
|
|
888
|
+
expect(napiInputs).toContain('{workspaceRoot}/devenv.lock');
|
|
889
|
+
expect(napiInputs).toContain('{workspaceRoot}/tooling/direnv/devenv.lock');
|
|
885
890
|
expect(native['napi-debug']?.options).toMatchObject({
|
|
886
891
|
cwd: '.',
|
|
887
892
|
command:
|
|
@@ -984,45 +989,74 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
984
989
|
}
|
|
985
990
|
});
|
|
986
991
|
|
|
987
|
-
it('
|
|
992
|
+
it('keys every cached cargo target on the declared toolchain pin', async () => {
|
|
988
993
|
const workspace = await createWorkspace();
|
|
989
994
|
try {
|
|
990
|
-
await workspace
|
|
991
|
-
await workspace
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
new Response(child.stdout).text(),
|
|
1010
|
-
new Response(child.stderr).text(),
|
|
1011
|
-
]);
|
|
1012
|
-
expect({ exitCode, stderr }).toMatchObject({ exitCode: 0 });
|
|
1013
|
-
return stdout;
|
|
1014
|
-
}),
|
|
995
|
+
await writeCargoIdentityFixture(workspace);
|
|
996
|
+
const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
|
|
997
|
+
const cached = cachedCargoTargets(targets);
|
|
998
|
+
|
|
999
|
+
// Named, so a family that stops being cached — or a new one that starts —
|
|
1000
|
+
// shows up here rather than silently leaving the sweep below empty.
|
|
1001
|
+
expect(cached.map(([name]) => name).sort()).toEqual([
|
|
1002
|
+
'cargo-cross-test-archive-aarch64-apple-darwin',
|
|
1003
|
+
'cargo-lint',
|
|
1004
|
+
'cargo-lint-cross',
|
|
1005
|
+
'cargo-test-archive',
|
|
1006
|
+
'cargo-test-ferris-core',
|
|
1007
|
+
]);
|
|
1008
|
+
// An SDK or toolchain change must invalidate every one of them. The pin
|
|
1009
|
+
// is the only thing in the identity that can see one, and it is declared
|
|
1010
|
+
// at both fleet locations because a fileset matching nothing is free.
|
|
1011
|
+
for (const [name, target] of cached) {
|
|
1012
|
+
const declared = (target.inputs ?? []).filter(
|
|
1013
|
+
(input) => typeof input === 'string' && input.endsWith('devenv.lock'),
|
|
1015
1014
|
);
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1015
|
+
expect([name, declared]).toEqual([
|
|
1016
|
+
name,
|
|
1017
|
+
['{workspaceRoot}/devenv.lock', '{workspaceRoot}/tooling/direnv/devenv.lock'],
|
|
1018
|
+
]);
|
|
1019
|
+
}
|
|
1020
|
+
} finally {
|
|
1021
|
+
await workspace.cleanup();
|
|
1022
|
+
}
|
|
1023
|
+
});
|
|
1024
|
+
|
|
1025
|
+
// The property that decides whether Rust can ever use a shared cache. A cargo
|
|
1026
|
+
// target's identity used to include a dump of the ambient cargo environment,
|
|
1027
|
+
// whose values are absolute `/nix/store/…` and per-checkout devenv state
|
|
1028
|
+
// paths: no two machines agreed, and the same target hashed differently in a
|
|
1029
|
+
// bare shell and inside a devenv profile, which made the pre-push
|
|
1030
|
+
// cross-compile probe unsatisfiable by construction.
|
|
1031
|
+
//
|
|
1032
|
+
// Runtime inputs are checked by their OUTPUT, not their command text, because
|
|
1033
|
+
// that is what Nx hashes: measured, two workspaces at different absolute
|
|
1034
|
+
// paths whose only difference is the spelling of a runtime command producing
|
|
1035
|
+
// identical stdout hash identically.
|
|
1036
|
+
it('hashes no machine-local value into a cached cargo target', async () => {
|
|
1037
|
+
const workspace = await createWorkspace();
|
|
1038
|
+
try {
|
|
1039
|
+
await writeCargoIdentityFixture(workspace);
|
|
1040
|
+
const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
|
|
1041
|
+
const offenders: string[] = [];
|
|
1042
|
+
for (const [name, target] of cachedCargoTargets(targets)) {
|
|
1043
|
+
for (const input of target.inputs ?? []) {
|
|
1044
|
+
if (typeof input === 'string') {
|
|
1045
|
+
if (!WORKSPACE_ANCHORED_INPUT.test(input)) offenders.push(`${name}: fileset ${input}`);
|
|
1046
|
+
continue;
|
|
1047
|
+
}
|
|
1048
|
+
if ('env' in input) offenders.push(`${name}: environment input ${String(input.env)}`);
|
|
1049
|
+
if (!('runtime' in input)) continue;
|
|
1050
|
+
const value = await runtimeInputValue(input.runtime, workspace.context.workspaceRoot);
|
|
1051
|
+
const rooted = PATH_OUTSIDE_WORKSPACE.exec(value);
|
|
1052
|
+
if (rooted) offenders.push(`${name}: runtime input yields ${rooted[0].trim()} — from ${input.runtime}`);
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
expect(offenders).toEqual([]);
|
|
1022
1056
|
} finally {
|
|
1023
1057
|
await workspace.cleanup();
|
|
1024
1058
|
}
|
|
1025
|
-
},
|
|
1059
|
+
}, 60_000);
|
|
1026
1060
|
|
|
1027
1061
|
it('scopes each per-crate cargo-test command to exactly one package', async () => {
|
|
1028
1062
|
const workspace = await createWorkspace();
|
|
@@ -1659,10 +1693,10 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1659
1693
|
}
|
|
1660
1694
|
});
|
|
1661
1695
|
|
|
1662
|
-
it('gives a wrangler project a deploy that runs the stage CLI, uncached, behind its build half', async () => {
|
|
1696
|
+
it('gives a private wrangler project a deploy that runs the stage CLI, uncached, behind its build half', async () => {
|
|
1663
1697
|
const workspace = await createWorkspace();
|
|
1664
1698
|
try {
|
|
1665
|
-
await workspace.write('packages/site/package.json', '{"name":"site"}\n');
|
|
1699
|
+
await workspace.write('packages/site/package.json', '{"name":"site","private":true}\n');
|
|
1666
1700
|
await workspace.write('packages/site/wrangler.toml', 'name = "site"\n');
|
|
1667
1701
|
const targets = await inferProjectTargets(workspace, 'packages/site/package.json');
|
|
1668
1702
|
|
|
@@ -1672,9 +1706,6 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1672
1706
|
command: 'smoo wrangler deploy-stage --stage {args.stage}',
|
|
1673
1707
|
cwd: 'packages/site',
|
|
1674
1708
|
});
|
|
1675
|
-
// That exact string is load-bearing beyond running: the CLI's `isStageDerivedDeploy`
|
|
1676
|
-
// recognises a stage deploy by it, which is why the plugin emits it instead of asking
|
|
1677
|
-
// every consumer to retype it and drift.
|
|
1678
1709
|
// A cache hit on deploy would mean "we once uploaded this hash", which a rollback falsifies
|
|
1679
1710
|
// silently; the step has to run and read live state instead.
|
|
1680
1711
|
expect(targets.deploy?.cache).toBe(false);
|
|
@@ -1687,13 +1718,38 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1687
1718
|
}
|
|
1688
1719
|
});
|
|
1689
1720
|
|
|
1721
|
+
it('infers no deploy for a PUBLISHED package whose wrangler manifest documents a binding', async () => {
|
|
1722
|
+
const workspace = await createWorkspace();
|
|
1723
|
+
try {
|
|
1724
|
+
// The shape that regressed a consumer: a library published to npm that ships a wrangler
|
|
1725
|
+
// manifest so consumers can declare the Durable Object binding it implements. Structurally
|
|
1726
|
+
// identical to a worker's, so only the manifest's own `private` flag tells them apart.
|
|
1727
|
+
await workspace.write(
|
|
1728
|
+
'packages/acme-cloudflare/package.json',
|
|
1729
|
+
'{"name":"@acme/cloudflare","nx":{"tags":["npm:private"]}}\n',
|
|
1730
|
+
);
|
|
1731
|
+
await workspace.write(
|
|
1732
|
+
'packages/acme-cloudflare/wrangler.toml',
|
|
1733
|
+
'# Wrangler configuration for @acme/cloudflare Durable Object\nname = "acme-cloudflare"\nmain = "src/index.ts"\ncompatibility_date = "2025-01-01"\n',
|
|
1734
|
+
);
|
|
1735
|
+
const targets = await inferProjectTargets(workspace, 'packages/acme-cloudflare/package.json');
|
|
1736
|
+
|
|
1737
|
+
expect(Object.keys(targets)).not.toContain('deploy');
|
|
1738
|
+
} finally {
|
|
1739
|
+
await workspace.cleanup();
|
|
1740
|
+
}
|
|
1741
|
+
});
|
|
1742
|
+
|
|
1690
1743
|
it('points an inferred deploy at the declared deploy-build, and caches that half', async () => {
|
|
1691
1744
|
const workspace = await createWorkspace();
|
|
1692
1745
|
const declared = {
|
|
1693
1746
|
'deploy-build': { executor: 'nx:run-commands', options: { command: 'bun tooling/build-site.ts' } },
|
|
1694
1747
|
};
|
|
1695
1748
|
try {
|
|
1696
|
-
await workspace.write(
|
|
1749
|
+
await workspace.write(
|
|
1750
|
+
'packages/site/package.json',
|
|
1751
|
+
JSON.stringify({ name: 'site', private: true, nx: { targets: declared } }),
|
|
1752
|
+
);
|
|
1697
1753
|
await workspace.write('packages/site/wrangler.toml', 'name = "site"\n');
|
|
1698
1754
|
const targets = await inferProjectTargets(workspace, 'packages/site/package.json');
|
|
1699
1755
|
|
|
@@ -1712,7 +1768,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1712
1768
|
it('falls back to the aggregate build when a wrangler project emits one', async () => {
|
|
1713
1769
|
const workspace = await createWorkspace();
|
|
1714
1770
|
try {
|
|
1715
|
-
await workspace.write('packages/site/package.json', '{"name":"site"}\n');
|
|
1771
|
+
await workspace.write('packages/site/package.json', '{"name":"site","private":true}\n');
|
|
1716
1772
|
await workspace.write('packages/site/wrangler.toml', 'name = "site"\n');
|
|
1717
1773
|
// tsconfig.lib.json is what puts an emitting target, and so the `build` aggregate, on a project.
|
|
1718
1774
|
await workspace.write('packages/site/tsconfig.lib.json', '{}\n');
|
|
@@ -1733,7 +1789,10 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1733
1789
|
deploy: { dependsOn: ['...', { projects: ['backend'], target: 'deploy', params: 'forward' }] },
|
|
1734
1790
|
};
|
|
1735
1791
|
try {
|
|
1736
|
-
await workspace.write(
|
|
1792
|
+
await workspace.write(
|
|
1793
|
+
'packages/site/package.json',
|
|
1794
|
+
JSON.stringify({ name: 'site', private: true, nx: { targets: declared } }),
|
|
1795
|
+
);
|
|
1737
1796
|
await workspace.write('packages/site/wrangler.toml', 'name = "site"\n');
|
|
1738
1797
|
await workspace.write('packages/site/tsconfig.lib.json', '{}\n');
|
|
1739
1798
|
const targets = await inferProjectTargets(workspace, 'packages/site/package.json');
|
|
@@ -1790,6 +1849,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1790
1849
|
`packages/${name}/package.json`,
|
|
1791
1850
|
JSON.stringify({
|
|
1792
1851
|
name,
|
|
1852
|
+
private: true,
|
|
1793
1853
|
nx: {
|
|
1794
1854
|
targets: {
|
|
1795
1855
|
deploy: {
|
|
@@ -1957,6 +2017,62 @@ interface WorkspaceFixture {
|
|
|
1957
2017
|
cleanup(): Promise<void>;
|
|
1958
2018
|
}
|
|
1959
2019
|
|
|
2020
|
+
/**
|
|
2021
|
+
* A fileset Nx resolves against the workspace, or a named input nx.json
|
|
2022
|
+
* declares. Anything else is a path this machine happens to have.
|
|
2023
|
+
*/
|
|
2024
|
+
const WORKSPACE_ANCHORED_INPUT = /^!?(?:\{(?:projectRoot|workspaceRoot)\}\/|\^?[A-Za-z][\w-]*$)/;
|
|
2025
|
+
|
|
2026
|
+
/** A path rooted outside the workspace, wherever it appears in a hashed value. */
|
|
2027
|
+
const PATH_OUTSIDE_WORKSPACE = /(?:^|[^\w.\-~])(\/[\w.-]+\/[\w.-]+)/;
|
|
2028
|
+
|
|
2029
|
+
/**
|
|
2030
|
+
* One Cargo workspace producing every cached cargo target family inference can
|
|
2031
|
+
* make: the host archive, a per-crate run, both lint verdicts, and — through
|
|
2032
|
+
* the `cross-targets` declaration — the foreign-triple archive, which states
|
|
2033
|
+
* its own inputs instead of receiving them from the `cargo --frozen` sweep.
|
|
2034
|
+
*/
|
|
2035
|
+
async function writeCargoIdentityFixture(workspace: WorkspaceFixture): Promise<void> {
|
|
2036
|
+
await workspace.write('packages/ferris/package.json', '{"name":"ferris"}\n');
|
|
2037
|
+
await workspace.write(
|
|
2038
|
+
'packages/ferris/Cargo.toml',
|
|
2039
|
+
'[workspace]\nmembers = ["crates/ferris-core"]\n\n' +
|
|
2040
|
+
'[workspace.metadata.smoothbricks.test]\n' +
|
|
2041
|
+
'cross-targets = [{ target = "aarch64-apple-darwin", cargo = "scripts/cargo-for-nextest.sh" }]\n',
|
|
2042
|
+
);
|
|
2043
|
+
await workspace.write('packages/ferris/crates/ferris-core/Cargo.toml', '[package]\nname = "ferris-core"\n');
|
|
2044
|
+
await workspace.write('packages/ferris/scripts/cargo-for-nextest.sh', '#!/bin/sh\nexec cargo "$@"\n');
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2047
|
+
/**
|
|
2048
|
+
* The targets a cache verdict can be wrong about: cached, and running cargo.
|
|
2049
|
+
* Derived rather than listed, so a new cargo family joins these assertions the
|
|
2050
|
+
* day it is inferred instead of the day someone remembers to add it.
|
|
2051
|
+
*/
|
|
2052
|
+
function cachedCargoTargets(targets: Record<string, TargetConfiguration>): [string, TargetConfiguration][] {
|
|
2053
|
+
return Object.entries(targets).filter(([, target]) => {
|
|
2054
|
+
const command: unknown = target.options?.command;
|
|
2055
|
+
const commands: unknown = target.options?.commands;
|
|
2056
|
+
const text = [
|
|
2057
|
+
typeof command === 'string' ? command : '',
|
|
2058
|
+
...(Array.isArray(commands) ? commands.filter((entry) => typeof entry === 'string') : []),
|
|
2059
|
+
].join('\n');
|
|
2060
|
+
return target.cache === true && /\bcargo/.test(text);
|
|
2061
|
+
});
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
/** What Nx actually hashes for a `runtime` input: the command's stdout. */
|
|
2065
|
+
async function runtimeInputValue(command: string, cwd: string): Promise<string> {
|
|
2066
|
+
const child = Bun.spawn(['sh', '-c', command], { cwd, stdout: 'pipe', stderr: 'pipe' });
|
|
2067
|
+
const [exitCode, stdout, stderr] = await Promise.all([
|
|
2068
|
+
child.exited,
|
|
2069
|
+
new Response(child.stdout).text(),
|
|
2070
|
+
new Response(child.stderr).text(),
|
|
2071
|
+
]);
|
|
2072
|
+
expect({ command, exitCode, stderr }).toMatchObject({ command, exitCode: 0 });
|
|
2073
|
+
return stdout;
|
|
2074
|
+
}
|
|
2075
|
+
|
|
1960
2076
|
async function inferProject(
|
|
1961
2077
|
workspace: WorkspaceFixture,
|
|
1962
2078
|
packageJsonPath: string,
|
package/src/index.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
|
|
|
15
15
|
import { parse as parseToml } from 'smol-toml';
|
|
16
16
|
|
|
17
17
|
import { BOUNDED_TEST_KILL_AFTER_MS, BOUNDED_TEST_TIMEOUT_MS } from './bounded-test-policy.js';
|
|
18
|
+
import { CARGO_TOOLCHAIN_NAMED_INPUT, CARGO_TOOLCHAIN_PIN_INPUTS } from './cargo-toolchain-policy.js';
|
|
18
19
|
import {
|
|
19
20
|
type AttributedCargoWorkspacePackage,
|
|
20
21
|
attributeCargoWorkspacePackages,
|
|
@@ -269,15 +270,10 @@ const REPO_ROOT_CARGO_OUTPUT_INPUTS = [
|
|
|
269
270
|
'{workspaceRoot}/scripts/*.sh',
|
|
270
271
|
'!{workspaceRoot}/**/target/**',
|
|
271
272
|
];
|
|
272
|
-
// The
|
|
273
|
-
//
|
|
274
|
-
//
|
|
275
|
-
//
|
|
276
|
-
// read ZIG*. An output linked against one sysroot must never hash equal to
|
|
277
|
-
// the same sources linked against another.
|
|
278
|
-
const CARGO_ENVIRONMENT_INPUT = {
|
|
279
|
-
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; })}));'`,
|
|
280
|
-
};
|
|
273
|
+
// The toolchain half of a cargo task's identity lives in its own module
|
|
274
|
+
// because `smoo monorepo validate` reads the same two constants to refuse a
|
|
275
|
+
// declaration that drops it. See cargo-toolchain-policy.ts for why it is the
|
|
276
|
+
// declared pin and not the ambient environment.
|
|
281
277
|
|
|
282
278
|
function cargoRuntimeInput(projectRoot: string, command: string): { runtime: string } {
|
|
283
279
|
const quotedRoot = `'${projectRoot.replaceAll("'", "'\"'\"'")}'`;
|
|
@@ -299,10 +295,17 @@ function targetCommandText(target: TargetConfiguration): string {
|
|
|
299
295
|
].join('\n');
|
|
300
296
|
}
|
|
301
297
|
/**
|
|
302
|
-
* The N-API build's inputs beyond the Cargo sources: the
|
|
303
|
-
* block, which names the binary and the targets, and the napi
|
|
304
|
-
* version from the lockfile. Neither the package version nor
|
|
305
|
-
* lockfile entry is part of the artifact.
|
|
298
|
+
* The N-API build's inputs beyond the Cargo sources: the toolchain pin, the
|
|
299
|
+
* package's `napi` block, which names the binary and the targets, and the napi
|
|
300
|
+
* CLI's resolved version from the lockfile. Neither the package version nor
|
|
301
|
+
* any other lockfile entry is part of the artifact.
|
|
302
|
+
*
|
|
303
|
+
* The pin is stated here rather than inherited: `napi build` compiles with the
|
|
304
|
+
* same rustc and links against the same SDK as any other cargo target, but its
|
|
305
|
+
* command does not spell `cargo --frozen`, which is how every other cached
|
|
306
|
+
* cargo target acquires its toolchain identity. Without it a `.node` linked
|
|
307
|
+
* against one toolchain hashed equal to the same sources linked against the
|
|
308
|
+
* next one.
|
|
306
309
|
*/
|
|
307
310
|
function napiInputs(projectRoot: string, repoRooted: boolean): TargetConfiguration['inputs'] {
|
|
308
311
|
// Runtime inputs execute from the workspace root, so the manifest is named
|
|
@@ -310,6 +313,7 @@ function napiInputs(projectRoot: string, repoRooted: boolean): TargetConfigurati
|
|
|
310
313
|
const packageJson = `./${posix.join(projectRoot, 'package.json')}`;
|
|
311
314
|
return [
|
|
312
315
|
...(repoRooted ? REPO_ROOT_CARGO_OUTPUT_INPUTS : CARGO_OUTPUT_INPUTS),
|
|
316
|
+
...CARGO_TOOLCHAIN_PIN_INPUTS,
|
|
313
317
|
{ runtime: `bun -e 'console.log(JSON.stringify(require(${JSON.stringify(packageJson)}).napi ?? null))'` },
|
|
314
318
|
{ externalDependencies: ['@napi-rs/cli'] },
|
|
315
319
|
];
|
|
@@ -496,7 +500,7 @@ function createCargoTestArchiveTarget(projectRoot: string, toolConfig: string):
|
|
|
496
500
|
* (measured: `metadata … --frozen` and `test --no-run … --frozen`).
|
|
497
501
|
*
|
|
498
502
|
* The archive target therefore states `CARGO_FETCH_TARGET` and the toolchain
|
|
499
|
-
*
|
|
503
|
+
* inputs itself: both are otherwise attached by matching the
|
|
500
504
|
* `cargo --frozen` prefix in a command, and this command does not carry it.
|
|
501
505
|
*
|
|
502
506
|
* The RUNNER declares no dependency on the archive and is not cached. That is
|
|
@@ -522,18 +526,21 @@ function createCargoCrossTestTargets(
|
|
|
522
526
|
[cargoCrossTestArchiveTargetName(triple)]: {
|
|
523
527
|
executor: 'nx:run-commands',
|
|
524
528
|
cache: true,
|
|
525
|
-
// The
|
|
526
|
-
// declared driver's own bytes.
|
|
527
|
-
// the `cargo --frozen` prefix in a command,
|
|
528
|
-
// spell — and
|
|
529
|
-
//
|
|
530
|
-
//
|
|
531
|
-
//
|
|
532
|
-
//
|
|
529
|
+
// The toolchain inputs every cached cargo target carries, plus the
|
|
530
|
+
// declared driver's own bytes. Those toolchain inputs are attached
|
|
531
|
+
// elsewhere by matching the `cargo --frozen` prefix in a command,
|
|
532
|
+
// which this one does not spell — and the pin matters MORE here than
|
|
533
|
+
// anywhere else: the cross regime this archive links under (the C
|
|
534
|
+
// toolchain for the triple, its sysroot, and the `CARGO` driver below)
|
|
535
|
+
// comes out of the same devenv lock, so an archive built under one pin
|
|
536
|
+
// must never hash equal to the same sources built under another. The
|
|
537
|
+
// declared driver is hashed by its own bytes; nothing samples the shell
|
|
538
|
+
// that supplies it, which is why this hash is the same bare and inside
|
|
539
|
+
// the cross profile.
|
|
533
540
|
inputs: [
|
|
534
541
|
...archiveInputs,
|
|
542
|
+
...CARGO_TOOLCHAIN_PIN_INPUTS,
|
|
535
543
|
...(cargo === undefined ? [] : [`{projectRoot}/${cargo}`]),
|
|
536
|
-
cargoRuntimeInput(projectRoot, CARGO_ENVIRONMENT_INPUT.runtime),
|
|
537
544
|
cargoRuntimeInput(projectRoot, 'rustc -vV && cargo -V && cargo nextest --version'),
|
|
538
545
|
],
|
|
539
546
|
outputs: [`{projectRoot}/${archiveFile}`],
|
|
@@ -750,6 +757,8 @@ interface PackageJson {
|
|
|
750
757
|
bin?: unknown;
|
|
751
758
|
name?: string;
|
|
752
759
|
napi?: Record<string, unknown>;
|
|
760
|
+
/** npm's own "never published" flag, which is what makes a package a deployable target rather than a library. */
|
|
761
|
+
private?: boolean;
|
|
753
762
|
scripts?: Record<string, unknown>;
|
|
754
763
|
nx?: {
|
|
755
764
|
name?: string;
|
|
@@ -782,20 +791,22 @@ function packageBinOutputs(packageJson: PackageJson, packageJsonPath: string): s
|
|
|
782
791
|
|
|
783
792
|
/**
|
|
784
793
|
* The deployment manifests wrangler itself looks for, in its own precedence
|
|
785
|
-
* order. Finding one
|
|
786
|
-
*
|
|
794
|
+
* order. Finding one is HALF the detection: a published library ships one to
|
|
795
|
+
* document a Durable Object binding for its consumers, and that manifest is
|
|
796
|
+
* structurally indistinguishable from a deployable worker's — same `name`,
|
|
797
|
+
* `main` and `compatibility_date`. So presence alone cannot mean deployable,
|
|
798
|
+
* and the other half is `private: true` below.
|
|
787
799
|
*
|
|
788
800
|
* Deploy POLICY is deliberately NOT read from the manifest. `smoo.wrangler.stages`
|
|
789
801
|
* belongs to the CLI, which reads it to decide which secrets a stage requires; a
|
|
790
802
|
* second copy in the graph would disagree the first time a stage was added. And
|
|
791
|
-
* which stages CI actually runs is the four-way vocabulary in the CLI's
|
|
803
|
+
* which stages CI actually runs is the four-way tag vocabulary in the CLI's
|
|
792
804
|
* `deploy-tags.ts` — every stage, staging only, excluded, production-on-push —
|
|
793
|
-
* that a flag here could express exactly one of. So
|
|
794
|
-
* the target, and
|
|
805
|
+
* that a flag here could express exactly one of. So a private wrangler project
|
|
806
|
+
* gets the target, and the tags alone decide what CI deploys.
|
|
795
807
|
*
|
|
796
808
|
* A worker deployed by some other mechanism declares its own `options.command`,
|
|
797
|
-
* which replaces this one;
|
|
798
|
-
* it, because the `deploy-stage` string went with it.
|
|
809
|
+
* which replaces this one; the tag is what CI reads either way.
|
|
799
810
|
*/
|
|
800
811
|
const WRANGLER_CONFIG_FILES = ['wrangler.jsonc', 'wrangler.json', 'wrangler.toml'];
|
|
801
812
|
|
|
@@ -805,11 +816,10 @@ const WRANGLER_CONFIG_FILES = ['wrangler.jsonc', 'wrangler.json', 'wrangler.toml
|
|
|
805
816
|
* `configurations` map cannot describe the surface that actually exists, and a
|
|
806
817
|
* project carrying both spellings would have two ways to say one thing.
|
|
807
818
|
*
|
|
808
|
-
* No `stage-deploy-target` tag either, deliberately: the
|
|
809
|
-
*
|
|
810
|
-
*
|
|
811
|
-
*
|
|
812
|
-
* answers, and the two would drift the first time either moved.
|
|
819
|
+
* No `stage-deploy-target` tag either, deliberately: that tag is the repository's
|
|
820
|
+
* statement that CI deploys this project on every stage, and only the repository
|
|
821
|
+
* can make it. A plugin that tagged what it inferred would enrol every private
|
|
822
|
+
* wrangler project in CI deploys by writing the policy it is supposed to read.
|
|
813
823
|
*
|
|
814
824
|
* `{args.stage}` rather than `forwardAllArgs`: run-commands'
|
|
815
825
|
* `interpolateArgsIntoCommand` returns as soon as it sees `{args.` and never
|
|
@@ -884,7 +894,8 @@ async function createProjectTargets(
|
|
|
884
894
|
const hasOrdinaryBuildOutputTarget =
|
|
885
895
|
hasLibTsconfig || napiConfig !== null || cargoWasmConfig !== null || packageLocalBuildOutputs.ordinary;
|
|
886
896
|
const hasAnyBuildOutputTarget = hasOrdinaryBuildOutputTarget || packageLocalBuildOutputs.platform;
|
|
887
|
-
const
|
|
897
|
+
const isDeployableWranglerProject =
|
|
898
|
+
packageJson.private === true && WRANGLER_CONFIG_FILES.some((file) => existsSync(join(absoluteProjectRoot, file)));
|
|
888
899
|
|
|
889
900
|
if (hasLibTsconfig) {
|
|
890
901
|
const executableOutputs = packageBinOutputs(packageJson, packageJsonPath);
|
|
@@ -1316,7 +1327,7 @@ async function createProjectTargets(
|
|
|
1316
1327
|
: '';
|
|
1317
1328
|
target.inputs = [
|
|
1318
1329
|
...(target.inputs ?? CARGO_INPUTS),
|
|
1319
|
-
|
|
1330
|
+
...CARGO_TOOLCHAIN_PIN_INPUTS,
|
|
1320
1331
|
cargoRuntimeInput(typeof cwd === 'string' ? cwd : projectRoot, `rustc -vV && cargo -V${versions}`),
|
|
1321
1332
|
];
|
|
1322
1333
|
}
|
|
@@ -1436,16 +1447,19 @@ async function createProjectTargets(
|
|
|
1436
1447
|
// `"dependsOn": ["...", "backend:deploy"]` and keeps both the edge below and this command —
|
|
1437
1448
|
// measured, not assumed, against an inferred base.
|
|
1438
1449
|
//
|
|
1439
|
-
// `deploy` is INFERRED for a wrangler project rather than patched onto a hand-written
|
|
1440
|
-
// command is a constant of the convention, not of the project: every consumer wrote
|
|
1441
|
-
// `nx:run-commands` wrapper around it
|
|
1442
|
-
// a
|
|
1443
|
-
//
|
|
1444
|
-
//
|
|
1450
|
+
// `deploy` is INFERRED for a private wrangler project rather than patched onto a hand-written
|
|
1451
|
+
// one. The command is a constant of the convention, not of the project: every consumer wrote
|
|
1452
|
+
// the same `nx:run-commands` wrapper around it. `private: true` is the second half of the
|
|
1453
|
+
// detection: a PUBLISHED package's wrangler manifest documents a binding for its consumers,
|
|
1454
|
+
// so inferring a deploy from it would put a live `wrangler deploy` of someone's documentation
|
|
1455
|
+
// one `nx run-many -t deploy` away. A published package that really is deployed declares
|
|
1456
|
+
// `deploy` itself. `deploy-build` stays declaration-driven in the other direction, because
|
|
1457
|
+
// only the project knows what building it means — the plugin supplies its POLICY (cache
|
|
1458
|
+
// honestly) and nothing else.
|
|
1445
1459
|
if (DEPLOY_BUILD_TARGET in declaredTargets) {
|
|
1446
1460
|
targets[DEPLOY_BUILD_TARGET] = { cache: true };
|
|
1447
1461
|
}
|
|
1448
|
-
if (
|
|
1462
|
+
if (isDeployableWranglerProject) {
|
|
1449
1463
|
// Naming only an edge that exists is tidiness, not a guard: Nx tolerates a `dependsOn` on a
|
|
1450
1464
|
// target the project lacks — measured, the task just runs alone — and a wrangler worker can
|
|
1451
1465
|
// legitimately have no build at all, since wrangler bundles its own TypeScript. Pointing at a
|
|
@@ -1568,6 +1582,26 @@ async function createProjectTargets(
|
|
|
1568
1582
|
};
|
|
1569
1583
|
}
|
|
1570
1584
|
|
|
1585
|
+
// A declared target REPLACES the inferred input list, pin included, so a
|
|
1586
|
+
// repository that hand-writes `inputs` for a cargo target silently loses its
|
|
1587
|
+
// toolchain identity. Name the pin once here so such a declaration can
|
|
1588
|
+
// reference it as `cargoToolchain` instead of restating two paths that could
|
|
1589
|
+
// drift from the plugin; `smoo monorepo validate` refuses a cached cargo
|
|
1590
|
+
// target whose resolved inputs reach neither. Defined only for projects that
|
|
1591
|
+
// HAVE cargo targets: a project's namedInputs definitions are hashed into
|
|
1592
|
+
// its configuration hash, so defining it everywhere would invalidate every
|
|
1593
|
+
// task in the repository to serve projects that can never reference it.
|
|
1594
|
+
const namedInputs: Record<string, NonNullable<TargetConfiguration['inputs']>> = {
|
|
1595
|
+
...(versionless === null
|
|
1596
|
+
? {}
|
|
1597
|
+
: {
|
|
1598
|
+
[VERSIONLESS_PRODUCTION_INPUT]: ['production', ...versionlessProjectInputs],
|
|
1599
|
+
[VERSIONLESS_DEFAULT_INPUT]: ['default', ...versionlessProjectInputs],
|
|
1600
|
+
}),
|
|
1601
|
+
...(Object.keys(targets).some((name) => name.startsWith('cargo-') || name.startsWith('napi-'))
|
|
1602
|
+
? { [CARGO_TOOLCHAIN_NAMED_INPUT]: [...CARGO_TOOLCHAIN_PIN_INPUTS] }
|
|
1603
|
+
: {}),
|
|
1604
|
+
};
|
|
1571
1605
|
return {
|
|
1572
1606
|
projects: {
|
|
1573
1607
|
[projectRoot]: {
|
|
@@ -1581,14 +1615,7 @@ async function createProjectTargets(
|
|
|
1581
1615
|
// Nx resolves a named input from the project first and nx.json second,
|
|
1582
1616
|
// so a workspace-wide definition still covers projects this plugin
|
|
1583
1617
|
// never inferred.
|
|
1584
|
-
...(
|
|
1585
|
-
? {}
|
|
1586
|
-
: {
|
|
1587
|
-
namedInputs: {
|
|
1588
|
-
[VERSIONLESS_PRODUCTION_INPUT]: ['production', ...versionlessProjectInputs],
|
|
1589
|
-
[VERSIONLESS_DEFAULT_INPUT]: ['default', ...versionlessProjectInputs],
|
|
1590
|
-
},
|
|
1591
|
-
}),
|
|
1618
|
+
...(Object.keys(namedInputs).length === 0 ? {} : { namedInputs }),
|
|
1592
1619
|
},
|
|
1593
1620
|
},
|
|
1594
1621
|
};
|
|
@@ -1946,6 +1973,7 @@ async function readPackageJson(packageJsonPath: string): Promise<PackageJson> {
|
|
|
1946
1973
|
...('bin' in parsed ? { bin: parsed.bin } : {}),
|
|
1947
1974
|
...(typeof parsed.name === 'string' ? { name: parsed.name } : {}),
|
|
1948
1975
|
...(isRecord(parsed.napi) ? { napi: parsed.napi } : {}),
|
|
1976
|
+
...(typeof parsed.private === 'boolean' ? { private: parsed.private } : {}),
|
|
1949
1977
|
...(isRecord(parsed.scripts) ? { scripts: parsed.scripts } : {}),
|
|
1950
1978
|
...(rawNx
|
|
1951
1979
|
? {
|