@smoothbricks/nx-plugin 0.4.5 → 0.4.7
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 +35 -21
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +10 -4
- package/dist/cargo-workspace.d.ts +60 -2
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +96 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +198 -119
- package/nextest.toml +9 -3
- package/package.json +1 -1
- package/src/bounded-test-policy.test.ts +67 -0
- package/src/bounded-test-policy.ts +11 -4
- package/src/cargo-workspace.ts +117 -29
- package/src/index.test.ts +176 -103
- package/src/index.ts +216 -129
package/README.md
CHANGED
|
@@ -28,16 +28,17 @@ commands, dependencies, inputs and outputs because they override source-aware in
|
|
|
28
28
|
The plugin discovers Cargo workspaces beside Nx project manifests at any depth:
|
|
29
29
|
|
|
30
30
|
- **Workspace owner:** the project beside a workspace `Cargo.toml` owns one `cargo-fetch`, `cargo-test-compile`,
|
|
31
|
-
cross-check, mutation, bench, and sweep target. Its `cargo-lint` and `cargo-test`
|
|
32
|
-
crates, including a root `[package]`.
|
|
33
|
-
- **Crate owner:** the deepest Nx project directory containing a crate owns `cargo-
|
|
34
|
-
`cargo-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
- **Commands:** validation runs from the governing Cargo workspace directory.
|
|
38
|
-
`cargo
|
|
39
|
-
|
|
40
|
-
|
|
31
|
+
`cargo-test-archive`, `cargo-lint`, cross-check, mutation, bench, and sweep target. Its `cargo-lint` and `cargo-test`
|
|
32
|
+
aggregates reach all workspace crates, including a root `[package]`.
|
|
33
|
+
- **Crate owner:** the deepest Nx project directory containing a crate owns `cargo-test-<crate>` targets. Its
|
|
34
|
+
`cargo-lint` delegates to the workspace owner's one verdict, and `lint` never depends on the workspace test suite.
|
|
35
|
+
Projects can own multiple crates. A nested independent workspace has its own prerequisites and does not inherit those
|
|
36
|
+
of an outer workspace.
|
|
37
|
+
- **Commands:** validation runs from the governing Cargo workspace directory. One `cargo fmt --all --check` and one
|
|
38
|
+
`cargo --frozen clippy --workspace --all-targets --target-dir target/cargo-lint -- -D warnings` cover every member.
|
|
39
|
+
Clippy of a crate is a check build of its whole closure, so a target directory per crate rebuilt every shared
|
|
40
|
+
dependency once per crate — 49 closures and 11 GiB on one repository — and no per-crate cache hit repaid it. Cargo's
|
|
41
|
+
own lock serializes the invocations that share the directory.
|
|
41
42
|
- **Overrides:** normal Nx merging applies. Explicit `nx.targets` fields replace inferred fields, while omitted fields
|
|
42
43
|
retain their inferred base. Use `"dependsOn": ["...", "extra"]` to preserve inferred prerequisites when adding an
|
|
43
44
|
edge; replacing the array makes its author responsible for fetching before frozen Cargo commands.
|
|
@@ -60,8 +61,8 @@ explicit inputs for arbitrary build-script reads or custom environment variables
|
|
|
60
61
|
|
|
61
62
|
Cargo keeps the caller's `CARGO_HOME`. Moving configuration into an isolated home can change relative paths or lose
|
|
62
63
|
source replacement, credentials, and toolchain settings; forwarding it with `--config` changes precedence. Registry
|
|
63
|
-
access may consequently serialize on Cargo's package-cache lock
|
|
64
|
-
|
|
64
|
+
access may consequently serialize on Cargo's package-cache lock. Clippy's dedicated target directory keeps its check
|
|
65
|
+
artifacts out of the test build directory without splitting one directory per crate.
|
|
65
66
|
|
|
66
67
|
### External Rust sources
|
|
67
68
|
|
|
@@ -106,15 +107,28 @@ Concrete targets come from concrete files:
|
|
|
106
107
|
- `test:watch` is inferred when the package already defines an explicit Bun or Vitest `test` command. The plugin derives
|
|
107
108
|
the corresponding watch command and makes it depend on `typecheck-tests`.
|
|
108
109
|
- A workspace-root `Cargo.toml` provides `cargo-test`, `test`, `cargo-lint`, `mutation`, and `bench`.
|
|
109
|
-
`cargo-test-compile` warms one workspace `cargo test --no-run`.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
110
|
+
`cargo-test-compile` warms one workspace `cargo test --no-run`. `cargo-test-archive` runs one
|
|
111
|
+
`cargo --frozen nextest archive --workspace` into `target/nextest/archive.tar.zst` and is the only cached cargo BUILD:
|
|
112
|
+
it produces a file rather than a mutable build tree. Each member crate gets a cached `cargo-test-<package>` run (30s
|
|
113
|
+
per-test timeout like `bun test --timeout=30000`) whose inputs include that crate and its path dependencies, and whose
|
|
114
|
+
command is `cargo --frozen nextest run --archive-file <archive> --workspace-remap . -E 'package(<crate>)'`. Runners
|
|
115
|
+
therefore execute rather than build: they extract binaries into their own temporary directory, write nothing to
|
|
116
|
+
cargo's flocked `target/`, and fan out instead of chaining. `--workspace-remap` is required — an archive records the
|
|
117
|
+
producing tree's absolute paths, and without it a restored archive hands tests another checkout's
|
|
118
|
+
`CARGO_MANIFEST_DIR`. With it the archive is relocatable, so one cache entry serves every checkout of the same commit;
|
|
119
|
+
nextest re-points `CARGO_BIN_EXE_<name>`/`NEXTEST_BIN_EXE_<name>` at the extracted binaries at runtime, but a test
|
|
120
|
+
that reads them through the compile-time `env!` macro keeps the producing tree's path. Per-crate runners accept an
|
|
121
|
+
empty nextest selection because a valid workspace member may have no tests and a hash partition may legitimately be
|
|
122
|
+
empty. `napi-debug` stays behind `cargo-test-compile`, and a crate in the project that builds the debug cdylib runs
|
|
123
|
+
after it. A crate declaring `[package.metadata.smoothbricks.wasm-bindgen]` also receives the cacheable `cargo-wasm`
|
|
124
|
+
output target in its owning project.
|
|
125
|
+
- The plugin's own `nextest.toml` is passed as `--tool-config-file "smoo:$PWD/<path>"`, so it is a layer BENEATH the
|
|
126
|
+
repository's `<cargo-workspace>/.config/nextest.toml` rather than a replacement for it: a repository can raise a
|
|
127
|
+
timeout, add a test group, or declare `archive.include` for a cdylib or fixture the archived test binaries need, and
|
|
128
|
+
its settings win. That file is an input of both the archive and every runner, so changing it invalidates the verdicts
|
|
129
|
+
it governs. `$PWD` keeps the command text identical across checkouts while satisfying nextest's requirement that a
|
|
130
|
+
tool config path be absolute; `--user-config-file none` still holds, because a developer's `~/.config/nextest` must
|
|
131
|
+
not decide a cached verdict.
|
|
118
132
|
- A crate whose suite outgrows one bounded window declares `[package.metadata.smoothbricks.test] shards = N`, and gets
|
|
119
133
|
`cargo-test-<package>-shard1..N`, each running `--partition hash:i/N` with the full bound. nextest assigns a test to a
|
|
120
134
|
shard by hashing its name, so the shards stay an exact partition of the crate as tests and test binaries are added,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bounded-test-policy.d.ts","sourceRoot":"","sources":["../src/bounded-test-policy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAErG,eAAO,MAAM,qBAAqB,yCAAyC,CAAC;AAC5E,eAAO,MAAM,uBAAuB,SAAU,CAAC;AAC/C,eAAO,MAAM,0BAA0B,QAAS,CAAC;AAKjD,eAAO,MAAM,gCAAgC,QAAS,CAAC;AAEvD,MAAM,WAAW,4BAA4B;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,EAAE,CAAC,EAAE;QACH,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;KACnD,CAAC;CACH;AAED,MAAM,WAAW,4BAA4B;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACnD;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,W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C,GAAG,MAAM,CAa9G"}
|
|
@@ -160,9 +160,12 @@ export function checkWorkspaceCargoTestReachabilityPolicy(root, options = {}) {
|
|
|
160
160
|
}
|
|
161
161
|
/**
|
|
162
162
|
* True when `target`, or something in its dependency closure, invokes cargo in a
|
|
163
|
-
* mode that executes tests.
|
|
164
|
-
* `cargo test --no-run
|
|
165
|
-
*
|
|
163
|
+
* mode that executes tests. The two workspace-wide preparation targets are
|
|
164
|
+
* deliberately excluded: `cargo-test-compile` is `cargo test --no-run` and
|
|
165
|
+
* `cargo-test-archive` is `cargo nextest archive`. Both prove the binaries
|
|
166
|
+
* build and nothing about them running, and both say "test"/"nextest" in their
|
|
167
|
+
* command — a closure holding only these is the silent green this check exists
|
|
168
|
+
* to catch.
|
|
166
169
|
*/
|
|
167
170
|
function resolvedTargetRunsTests(project, target) {
|
|
168
171
|
const visiting = new Set();
|
|
@@ -172,7 +175,10 @@ function resolvedTargetRunsTests(project, target) {
|
|
|
172
175
|
}
|
|
173
176
|
visiting.add(targetName);
|
|
174
177
|
const command = commandOf(project, targetName);
|
|
175
|
-
const runs = command !== undefined &&
|
|
178
|
+
const runs = command !== undefined &&
|
|
179
|
+
/\btest\b|\bnextest\b/.test(command) &&
|
|
180
|
+
!command.includes('--no-run') &&
|
|
181
|
+
!command.includes('nextest archive');
|
|
176
182
|
const reached = runs ||
|
|
177
183
|
(project.targetDependencies?.get(targetName) ?? []).some((dependency) => matchingResolvedTargets(dependency, project.targets).some(visit));
|
|
178
184
|
visiting.delete(targetName);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type TomlTable } from 'smol-toml';
|
|
1
2
|
export interface CargoWorkspacePackage {
|
|
2
3
|
name: string;
|
|
3
4
|
dir: string;
|
|
@@ -37,8 +38,25 @@ export interface CargoPackageTestInputsOptions {
|
|
|
37
38
|
absoluteProjectRoot: string;
|
|
38
39
|
memberDir: string;
|
|
39
40
|
inputRoot?: string;
|
|
41
|
+
/** Shared across every call of one graph computation; see {@link createCargoInputsCache}. */
|
|
42
|
+
cache?: CargoInputsCache;
|
|
40
43
|
}
|
|
41
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Memo for one project-graph computation. Every crate's compile, lint and
|
|
46
|
+
* test targets derive the same closure, and every crate re-reads the same
|
|
47
|
+
* manifests and re-walks the same trees for nested `Cargo.toml` files; with
|
|
48
|
+
* three targets over ~45 crates that was ~135 derivations and the dominant
|
|
49
|
+
* cost of loading the graph. The cache lives exactly as long as one
|
|
50
|
+
* `createNodes` call — Nx recomputes the graph when a manifest changes, so
|
|
51
|
+
* nothing here can go stale across runs.
|
|
52
|
+
*/
|
|
53
|
+
export interface CargoInputsCache {
|
|
54
|
+
readonly manifests: Map<string, Promise<TomlTable>>;
|
|
55
|
+
readonly nestedCrateDirs: Map<string, string[]>;
|
|
56
|
+
readonly results: Map<string, Promise<string[]>>;
|
|
57
|
+
}
|
|
58
|
+
export declare function createCargoInputsCache(): CargoInputsCache;
|
|
59
|
+
export declare function cargoPackageTestInputs(options: CargoPackageTestInputsOptions): Promise<string[]>;
|
|
42
60
|
/**
|
|
43
61
|
* The aggregate that actually runs a cargo workspace's tests. Named here because
|
|
44
62
|
* both target inference and the policy that verifies `test` reaches it need the
|
|
@@ -47,6 +65,21 @@ export declare function cargoPackageTestInputs({ workspaceRoot, absoluteProjectR
|
|
|
47
65
|
export declare const CARGO_TEST_TARGET = "cargo-test";
|
|
48
66
|
/** Prerequisite that compiles the workspace; not a per-crate runner. */
|
|
49
67
|
export declare const CARGO_TEST_COMPILE_TARGET = "cargo-test-compile";
|
|
68
|
+
/**
|
|
69
|
+
* The one workspace-wide `cargo nextest archive` every per-crate runner
|
|
70
|
+
* executes from. Named here beside the other cargo target names so the policy
|
|
71
|
+
* that checks a workspace's test graph and the inference that builds it read
|
|
72
|
+
* the same string.
|
|
73
|
+
*/
|
|
74
|
+
export declare const CARGO_TEST_ARCHIVE_TARGET = "cargo-test-archive";
|
|
75
|
+
/**
|
|
76
|
+
* Where that archive lands, relative to the cargo workspace root — the cwd both
|
|
77
|
+
* the archive command and every runner already use. `cargo nextest archive`
|
|
78
|
+
* does NOT create this parent directory and fails the whole build when it is
|
|
79
|
+
* missing ("error writing to archive ... No such file or directory"), so the
|
|
80
|
+
* target mkdir's it first.
|
|
81
|
+
*/
|
|
82
|
+
export declare const CARGO_TEST_ARCHIVE_FILE = "target/nextest/archive.tar.zst";
|
|
50
83
|
/**
|
|
51
84
|
* Tests that nextest.toml singles out are pinned to this suffix instead of
|
|
52
85
|
* being sharded. Only a sharded crate has one: an unsharded crate runs its
|
|
@@ -62,6 +95,10 @@ export declare function cargoTestPackageTargetName(packageName: string, piece?:
|
|
|
62
95
|
* Inverse of `cargoTestPackageTargetName`, used by the reachability policy to
|
|
63
96
|
* check that the per-crate targets cover every workspace member. Pieces of one
|
|
64
97
|
* crate collapse back to that crate, so a split crate counts as covered once.
|
|
98
|
+
*
|
|
99
|
+
* The two workspace-wide `cargo-test-*` targets are not crates: reading them as
|
|
100
|
+
* one would invent members named "compile" and "archive" and report every real
|
|
101
|
+
* crate's coverage against a set that can never match.
|
|
65
102
|
*/
|
|
66
103
|
export declare function packageNameFromCargoTestTarget(targetName: string): string | null;
|
|
67
104
|
/**
|
|
@@ -79,5 +116,26 @@ export declare function packageNameFromCargoTestTarget(targetName: string): stri
|
|
|
79
116
|
* Returns null when nothing is singled out, the "nothing to pin" case.
|
|
80
117
|
*/
|
|
81
118
|
export declare function exceptionalTestFilter(nextestConfigPath: string): string | null;
|
|
82
|
-
|
|
119
|
+
/**
|
|
120
|
+
* The plugin's own nextest settings, as a config layer BENEATH the repository's.
|
|
121
|
+
*
|
|
122
|
+
* `--config-file` replaces `<workspace>/.config/nextest.toml` outright, which
|
|
123
|
+
* made every plugin default unoverridable and — now that per-crate runs execute
|
|
124
|
+
* from an archive — left a repository no way to declare `archive.include` for a
|
|
125
|
+
* cdylib or fixture its tests need. `--tool-config-file` is nextest's mechanism
|
|
126
|
+
* for exactly this: "lower than --config-file in priority but above the default
|
|
127
|
+
* config shipped with nextest". Measured: with only this layer a 1s
|
|
128
|
+
* slow-timeout terminates a 3s test; adding `.config/nextest.toml` with 10s
|
|
129
|
+
* lets the same test pass.
|
|
130
|
+
*
|
|
131
|
+
* The path must be absolute, and an absolute path written into the command text
|
|
132
|
+
* would differ per checkout and split one Nx cache entry per machine. `$PWD`
|
|
133
|
+
* resolves at exec time — both the archive (`nx:run-commands`) and the runners
|
|
134
|
+
* (`bounded-exec`, which spawns with `shell: true`) go through a shell — so the
|
|
135
|
+
* command text stays identical everywhere. Quoted, because a workspace path may
|
|
136
|
+
* contain spaces.
|
|
137
|
+
*/
|
|
138
|
+
export declare function nextestToolConfigArg(workspaceRoot: string, projectRoot: string, configAbs: string): string;
|
|
139
|
+
/** The repository's own nextest config, which now layers over the plugin's. */
|
|
140
|
+
export declare const NEXTEST_REPO_CONFIG_PATH = ".config/nextest.toml";
|
|
83
141
|
//# sourceMappingURL=cargo-workspace.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cargo-workspace.d.ts","sourceRoot":"","sources":["../src/cargo-workspace.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cargo-workspace.d.ts","sourceRoot":"","sources":["../src/cargo-workspace.ts"],"names":[],"mappings":"AAIA,OAAO,EAAsB,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAE/D,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,+BAAgC,SAAQ,qBAAqB;IAC5E,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,0BAA0B,CAAC,mBAAmB,EAAE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;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAGtF;AAED;;;;;;;;GAQG;AACH,wBAAgB,8BAA8B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAYhF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CAAC,iBAAiB,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAoB9E;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAI1G;AAED,+EAA+E;AAC/E,eAAO,MAAM,wBAAwB,yBAAyB,CAAC"}
|
package/dist/cargo-workspace.js
CHANGED
|
@@ -169,15 +169,27 @@ export function attributeCargoWorkspacePackages(packages, projects) {
|
|
|
169
169
|
* silently ignores the dependency. A runtime named input can hash any tree.
|
|
170
170
|
*/
|
|
171
171
|
export const EXTERNAL_RUST_CRATES_INPUT = 'externalRustCrates';
|
|
172
|
-
export
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
export function createCargoInputsCache() {
|
|
173
|
+
return { manifests: new Map(), nestedCrateDirs: new Map(), results: new Map() };
|
|
174
|
+
}
|
|
175
|
+
export function cargoPackageTestInputs(options) {
|
|
176
|
+
const cache = options.cache ?? createCargoInputsCache();
|
|
177
|
+
const key = `${options.absoluteProjectRoot}\0${options.memberDir}\0${options.inputRoot ?? '{projectRoot}'}`;
|
|
178
|
+
const cached = cache.results.get(key);
|
|
179
|
+
if (cached !== undefined)
|
|
180
|
+
return cached;
|
|
181
|
+
const derived = deriveCargoPackageTestInputs(options, cache);
|
|
182
|
+
cache.results.set(key, derived);
|
|
183
|
+
return derived;
|
|
184
|
+
}
|
|
185
|
+
async function deriveCargoPackageTestInputs({ workspaceRoot, absoluteProjectRoot, memberDir, inputRoot = '{projectRoot}' }, cache) {
|
|
186
|
+
const loadManifest = (path) => {
|
|
175
187
|
const normalized = resolve(path);
|
|
176
|
-
const cached = manifests.get(normalized);
|
|
188
|
+
const cached = cache.manifests.get(normalized);
|
|
177
189
|
if (cached !== undefined)
|
|
178
190
|
return cached;
|
|
179
|
-
const parsed =
|
|
180
|
-
manifests.set(normalized, parsed);
|
|
191
|
+
const parsed = readFile(normalized, 'utf-8').then(parseToml);
|
|
192
|
+
cache.manifests.set(normalized, parsed);
|
|
181
193
|
return parsed;
|
|
182
194
|
};
|
|
183
195
|
const rootManifest = await loadManifest(join(absoluteProjectRoot, 'Cargo.toml'));
|
|
@@ -270,26 +282,10 @@ export async function cargoPackageTestInputs({ workspaceRoot, absoluteProjectRoo
|
|
|
270
282
|
// Cargo packages can compile include_bytes!, headers, schemas and build.rs,
|
|
271
283
|
// not only Rust sources. Nested packages are separate source owners.
|
|
272
284
|
inputs.add(`${inputPath(absoluteDir)}/**/*`);
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
continue;
|
|
278
|
-
for (const entry of readdirSync(current, { withFileTypes: true })) {
|
|
279
|
-
if (!entry.isDirectory())
|
|
280
|
-
continue;
|
|
281
|
-
const child = join(current, entry.name);
|
|
282
|
-
if (['target', '.git', 'node_modules', '.nx'].includes(entry.name)) {
|
|
283
|
-
}
|
|
284
|
-
else if (existsSync(join(child, 'Cargo.toml'))) {
|
|
285
|
-
const childDir = relative(absoluteProjectRoot, child).split(sep).join('/');
|
|
286
|
-
if (!dirs.has(childDir))
|
|
287
|
-
exclusions.add(`!${inputPath(child)}/**`);
|
|
288
|
-
}
|
|
289
|
-
else {
|
|
290
|
-
scan.push(child);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
285
|
+
for (const child of nestedCrateDirs(absoluteDir, cache)) {
|
|
286
|
+
const childDir = relative(absoluteProjectRoot, child).split(sep).join('/');
|
|
287
|
+
if (!dirs.has(childDir))
|
|
288
|
+
exclusions.add(`!${inputPath(child)}/**`);
|
|
293
289
|
}
|
|
294
290
|
}
|
|
295
291
|
for (const source of [...declaredSources].sort()) {
|
|
@@ -355,6 +351,34 @@ export async function cargoPackageTestInputs({ workspaceRoot, absoluteProjectRoo
|
|
|
355
351
|
}
|
|
356
352
|
return [...inputs];
|
|
357
353
|
}
|
|
354
|
+
/** Every directory beneath `root` that holds its own `Cargo.toml`, the walk stopping at each. */
|
|
355
|
+
function nestedCrateDirs(root, cache) {
|
|
356
|
+
const cached = cache.nestedCrateDirs.get(root);
|
|
357
|
+
if (cached !== undefined)
|
|
358
|
+
return cached;
|
|
359
|
+
const found = [];
|
|
360
|
+
const scan = [root];
|
|
361
|
+
while (scan.length > 0) {
|
|
362
|
+
const current = scan.pop();
|
|
363
|
+
if (current === undefined || !existsSync(current))
|
|
364
|
+
continue;
|
|
365
|
+
for (const entry of readdirSync(current, { withFileTypes: true })) {
|
|
366
|
+
if (!entry.isDirectory())
|
|
367
|
+
continue;
|
|
368
|
+
const child = join(current, entry.name);
|
|
369
|
+
if (['target', '.git', 'node_modules', '.nx'].includes(entry.name)) {
|
|
370
|
+
}
|
|
371
|
+
else if (existsSync(join(child, 'Cargo.toml'))) {
|
|
372
|
+
found.push(child);
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
scan.push(child);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
cache.nestedCrateDirs.set(root, found);
|
|
380
|
+
return found;
|
|
381
|
+
}
|
|
358
382
|
function enqueuePathDependencies(scope, memberDir, workspacePathDeps, pending, external, absoluteProjectRoot, workspaceRoot) {
|
|
359
383
|
for (const tableName of ['dependencies', 'dev-dependencies', 'build-dependencies']) {
|
|
360
384
|
const table = scope[tableName];
|
|
@@ -461,6 +485,21 @@ function readTestShards(cratePackage, crateTomlPath) {
|
|
|
461
485
|
export const CARGO_TEST_TARGET = 'cargo-test';
|
|
462
486
|
/** Prerequisite that compiles the workspace; not a per-crate runner. */
|
|
463
487
|
export const CARGO_TEST_COMPILE_TARGET = 'cargo-test-compile';
|
|
488
|
+
/**
|
|
489
|
+
* The one workspace-wide `cargo nextest archive` every per-crate runner
|
|
490
|
+
* executes from. Named here beside the other cargo target names so the policy
|
|
491
|
+
* that checks a workspace's test graph and the inference that builds it read
|
|
492
|
+
* the same string.
|
|
493
|
+
*/
|
|
494
|
+
export const CARGO_TEST_ARCHIVE_TARGET = 'cargo-test-archive';
|
|
495
|
+
/**
|
|
496
|
+
* Where that archive lands, relative to the cargo workspace root — the cwd both
|
|
497
|
+
* the archive command and every runner already use. `cargo nextest archive`
|
|
498
|
+
* does NOT create this parent directory and fails the whole build when it is
|
|
499
|
+
* missing ("error writing to archive ... No such file or directory"), so the
|
|
500
|
+
* target mkdir's it first.
|
|
501
|
+
*/
|
|
502
|
+
export const CARGO_TEST_ARCHIVE_FILE = 'target/nextest/archive.tar.zst';
|
|
464
503
|
/**
|
|
465
504
|
* Tests that nextest.toml singles out are pinned to this suffix instead of
|
|
466
505
|
* being sharded. Only a sharded crate has one: an unsharded crate runs its
|
|
@@ -479,9 +518,15 @@ export function cargoTestPackageTargetName(packageName, piece) {
|
|
|
479
518
|
* Inverse of `cargoTestPackageTargetName`, used by the reachability policy to
|
|
480
519
|
* check that the per-crate targets cover every workspace member. Pieces of one
|
|
481
520
|
* crate collapse back to that crate, so a split crate counts as covered once.
|
|
521
|
+
*
|
|
522
|
+
* The two workspace-wide `cargo-test-*` targets are not crates: reading them as
|
|
523
|
+
* one would invent members named "compile" and "archive" and report every real
|
|
524
|
+
* crate's coverage against a set that can never match.
|
|
482
525
|
*/
|
|
483
526
|
export function packageNameFromCargoTestTarget(targetName) {
|
|
484
|
-
if (!targetName.startsWith('cargo-test-') ||
|
|
527
|
+
if (!targetName.startsWith('cargo-test-') ||
|
|
528
|
+
targetName === CARGO_TEST_COMPILE_TARGET ||
|
|
529
|
+
targetName === CARGO_TEST_ARCHIVE_TARGET) {
|
|
485
530
|
return null;
|
|
486
531
|
}
|
|
487
532
|
const name = targetName
|
|
@@ -524,7 +569,29 @@ export function exceptionalTestFilter(nextestConfigPath) {
|
|
|
524
569
|
const unique = [...new Set(filters)];
|
|
525
570
|
return unique.length === 0 ? null : unique.map((filter) => `(${filter})`).join(' or ');
|
|
526
571
|
}
|
|
527
|
-
|
|
572
|
+
/**
|
|
573
|
+
* The plugin's own nextest settings, as a config layer BENEATH the repository's.
|
|
574
|
+
*
|
|
575
|
+
* `--config-file` replaces `<workspace>/.config/nextest.toml` outright, which
|
|
576
|
+
* made every plugin default unoverridable and — now that per-crate runs execute
|
|
577
|
+
* from an archive — left a repository no way to declare `archive.include` for a
|
|
578
|
+
* cdylib or fixture its tests need. `--tool-config-file` is nextest's mechanism
|
|
579
|
+
* for exactly this: "lower than --config-file in priority but above the default
|
|
580
|
+
* config shipped with nextest". Measured: with only this layer a 1s
|
|
581
|
+
* slow-timeout terminates a 3s test; adding `.config/nextest.toml` with 10s
|
|
582
|
+
* lets the same test pass.
|
|
583
|
+
*
|
|
584
|
+
* The path must be absolute, and an absolute path written into the command text
|
|
585
|
+
* would differ per checkout and split one Nx cache entry per machine. `$PWD`
|
|
586
|
+
* resolves at exec time — both the archive (`nx:run-commands`) and the runners
|
|
587
|
+
* (`bounded-exec`, which spawns with `shell: true`) go through a shell — so the
|
|
588
|
+
* command text stays identical everywhere. Quoted, because a workspace path may
|
|
589
|
+
* contain spaces.
|
|
590
|
+
*/
|
|
591
|
+
export function nextestToolConfigArg(workspaceRoot, projectRoot, configAbs) {
|
|
528
592
|
const rel = relative(join(workspaceRoot, projectRoot), configAbs);
|
|
529
|
-
|
|
593
|
+
const path = rel.length === 0 ? configAbs : rel.split(sep).join('/');
|
|
594
|
+
return `--tool-config-file "smoo:$PWD/${path}"`;
|
|
530
595
|
}
|
|
596
|
+
/** The repository's own nextest config, which now layers over the plugin's. */
|
|
597
|
+
export const NEXTEST_REPO_CONFIG_PATH = '.config/nextest.toml';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,aAAa,EAGnB,MAAM,0BAA0B,CAAC;AAKlC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,aAAa,EAGnB,MAAM,0BAA0B,CAAC;AAKlC,OAAO,EAKL,yBAAyB,EAW1B,MAAM,sBAAsB,CAAC;AAa9B,OAAO,EAAE,yBAAyB,EAAE,CAAC;AAmDrC,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;AAoGD,UAAU,oBAAqB,SAAQ,YAAY;IACjD,UAAU,EAAE,MAAM,CAAC;CACpB;AA0CD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,oBAAoB,GAAG,MAAM,CAEhF;AA+KD,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,GAAG,aAAa,CAEvG;AAED,eAAO,MAAM,aAAa,EAAE,aAG3B,CAAC"}
|