@smoothbricks/nx-plugin 0.4.0 → 0.4.2
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 +80 -20
- package/dist/bin/smoo-nx-cargo-hash.d.ts +3 -0
- package/dist/bin/smoo-nx-cargo-hash.d.ts.map +1 -0
- package/dist/bin/smoo-nx-cargo-hash.js +16 -0
- package/dist/cargo-source-hash.d.ts +12 -0
- package/dist/cargo-source-hash.d.ts.map +1 -0
- package/dist/cargo-source-hash.js +208 -0
- package/dist/cargo-workspace.d.ts +22 -20
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +268 -58
- package/dist/cross-check-policy.d.ts +5 -10
- package/dist/cross-check-policy.d.ts.map +1 -1
- package/dist/cross-check-policy.js +7 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +344 -191
- package/dist/package-target-policy.d.ts.map +1 -1
- package/dist/package-target-policy.js +2 -1
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +54 -0
- package/package.json +9 -3
- package/src/bin/smoo-nx-cargo-hash.ts +18 -0
- package/src/cargo-source-hash.test.ts +51 -0
- package/src/cargo-source-hash.ts +138 -0
- package/src/cargo-workspace.test.ts +236 -90
- package/src/cargo-workspace.ts +337 -64
- package/src/cross-check-policy.test.ts +37 -7
- package/src/cross-check-policy.ts +9 -21
- package/src/ensure-built.test.ts +8 -3
- package/src/index.test.ts +340 -49
- package/src/index.ts +383 -224
- package/src/package-target-policy.test.ts +13 -0
- package/src/package-target-policy.ts +2 -1
- package/src/workspace-config-policy.test.ts +48 -0
- package/src/workspace-config-policy.ts +60 -0
package/README.md
CHANGED
|
@@ -14,20 +14,80 @@ with `tsconfig.lib.json` receives transformer-aware `tsc-js` and native `typeche
|
|
|
14
14
|
- Cargo workspace targets from a neighboring workspace-root `Cargo.toml`
|
|
15
15
|
- aggregate `build` and `lint` targets
|
|
16
16
|
|
|
17
|
+
Lint commands are inferred per project. A workspace Biome configuration enables the project-wide Biome check; an ESLint
|
|
18
|
+
flat configuration enables ESLint only for existing JavaScript/TypeScript files under that project's `src`. Rust-only
|
|
19
|
+
source trees therefore keep their Cargo validation and manifest checks without invoking ESLint on nonexistent JavaScript
|
|
20
|
+
inputs. Adding JavaScript or TypeScript sources adds their lint coverage automatically.
|
|
21
|
+
|
|
22
|
+
Keep `targetDefaults.lint` limited to shared cache policy. Smoo's workspace policy removes static lint executors,
|
|
23
|
+
commands, dependencies, inputs and outputs because they override source-aware inference for every project. Project-local
|
|
24
|
+
`nx.targets.lint` declarations retain normal Nx override precedence.
|
|
25
|
+
|
|
17
26
|
## Cargo Workspace Layouts
|
|
18
27
|
|
|
19
|
-
The plugin
|
|
28
|
+
The plugin discovers Cargo workspaces beside Nx project manifests at any depth:
|
|
29
|
+
|
|
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` aggregates reach all workspace
|
|
32
|
+
crates, including a root `[package]`.
|
|
33
|
+
- **Crate owner:** the deepest Nx project directory containing a crate owns `cargo-lint-<crate>` and
|
|
34
|
+
`cargo-test-<crate>` targets. Its `cargo-lint` and `lint` aggregates reach only its own crates; lint never depends on
|
|
35
|
+
the workspace test suite. Projects can own multiple crates. A nested independent workspace has its own prerequisites
|
|
36
|
+
and does not inherit those of an outer workspace.
|
|
37
|
+
- **Commands:** validation runs from the governing Cargo workspace directory. Formatting uses
|
|
38
|
+
`cargo fmt -p <crate> --check`; Clippy uses
|
|
39
|
+
`cargo --frozen clippy -p <crate> --all-targets --target-dir target/cargo-lint-<crate> -- -D warnings`. The package
|
|
40
|
+
selector narrows both tools, and each Clippy target has a separate build directory.
|
|
41
|
+
- **Overrides:** normal Nx merging applies. Explicit `nx.targets` fields replace inferred fields, while omitted fields
|
|
42
|
+
retain their inferred base. Use `"dependsOn": ["...", "extra"]` to preserve inferred prerequisites when adding an
|
|
43
|
+
edge; replacing the array makes its author responsible for fetching before frozen Cargo commands.
|
|
44
|
+
|
|
45
|
+
Member and exclude patterns may use `*` and `?` in any path segment (for example, `packages/*/crates/*`). Unsupported
|
|
46
|
+
patterns and member patterns that match no directory fail graph construction instead of silently omitting crates.
|
|
47
|
+
|
|
48
|
+
### Cargo cache boundaries
|
|
49
|
+
|
|
50
|
+
`cargo-fetch` is uncached because the registry lives outside Nx outputs. `cargo-test-compile` is also uncached: it warms
|
|
51
|
+
Cargo's shared mutable build directory before the bounded runner, even if that directory was deleted after an earlier
|
|
52
|
+
successful run. Cargo's own incremental cache avoids recompiling unchanged code. Nx never restores or collects shared
|
|
53
|
+
Cargo build directories; lint and test **results**, and dedicated Wasm/N-API **outputs**, remain cacheable.
|
|
54
|
+
|
|
55
|
+
Validation inputs include the crate's files, local dependency closure, governing manifests and configuration, toolchain
|
|
56
|
+
versions, Cargo/Rust/native-build environment, target/profile overrides, and global Cargo configuration. Workspace test
|
|
57
|
+
runners additionally hash all workspace member manifests because those affect unified features, and the nextest
|
|
58
|
+
executable/configuration. Production test configurations use release compilation and release runners together. Keep
|
|
59
|
+
explicit inputs for arbitrary build-script reads or custom environment variables that Cargo metadata cannot name.
|
|
60
|
+
|
|
61
|
+
Cargo keeps the caller's `CARGO_HOME`. Moving configuration into an isolated home can change relative paths or lose
|
|
62
|
+
source replacement, credentials, and toolchain settings; forwarding it with `--config` changes precedence. Registry
|
|
63
|
+
access may consequently serialize on Cargo's package-cache lock, while separate Clippy target directories still avoid
|
|
64
|
+
contention with the test build directory.
|
|
65
|
+
|
|
66
|
+
### External Rust sources
|
|
67
|
+
|
|
68
|
+
For a repository-root Cargo workspace, declare the shared input once:
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"namedInputs": {
|
|
73
|
+
"externalRustCrates": [{ "runtime": "smoo-nx-cargo-hash" }]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
For a package-root Cargo workspace, pass its manifest relative to the Nx root:
|
|
79
|
+
`smoo-nx-cargo-hash packages/example/Cargo.toml`. A shared input covering several Cargo workspaces includes one runtime
|
|
80
|
+
entry per manifest.
|
|
81
|
+
|
|
82
|
+
The command queries `cargo metadata --locked --offline` and hashes the resolved external path packages, including
|
|
83
|
+
transitive dependencies, Rust sources, target source files, governing Cargo manifests, and Cargo configuration. It also
|
|
84
|
+
covers path packages under `node_modules`, which Nx's normal file map ignores. Adding or moving a dependency does not
|
|
85
|
+
require maintaining a second list of source roots. The command refuses missing dependencies or an unavailable locked
|
|
86
|
+
dependency cache instead of emitting a partial digest.
|
|
20
87
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
below several `packages/*` projects. The root Nx project owns the single `cargo-fetch`, `cargo-test-compile`,
|
|
25
|
-
`cargo-lint`, mutation, bench, and sweep targets. Each crate's `cargo-test-<crate>` target and declared Wasm/N-API
|
|
26
|
-
output targets belong to the deepest Nx project directory containing that crate. All Cargo commands run from the
|
|
27
|
-
repository root, select the crate with `-p <crate>`, and share the root `target/`; cross-project dependencies keep the
|
|
28
|
-
runners in one serialization chain. Member and exclude patterns may use `*` and `?` in any path segment (for example,
|
|
29
|
-
`packages/*/crates/*`); unsupported patterns and member patterns that match no directory fail graph construction
|
|
30
|
-
instead of silently omitting crates.
|
|
88
|
+
Git and registry dependencies are identified by `Cargo.lock`; uncommitted changes in a Git repository are not changes to
|
|
89
|
+
a pinned Git dependency. Local `path` dependencies stay live and their source edits change the digest. Build-script data
|
|
90
|
+
and environment inputs outside the Rust/Cargo inputs above still require explicit Nx inputs.
|
|
31
91
|
|
|
32
92
|
## Nx Target Naming
|
|
33
93
|
|
|
@@ -46,15 +106,15 @@ Concrete targets come from concrete files:
|
|
|
46
106
|
- `test:watch` is inferred when the package already defines an explicit Bun or Vitest `test` command. The plugin derives
|
|
47
107
|
the corresponding watch command and makes it depend on `typecheck-tests`.
|
|
48
108
|
- A workspace-root `Cargo.toml` provides `cargo-test`, `test`, `cargo-lint`, `mutation`, and `bench`.
|
|
49
|
-
`cargo-test-compile`
|
|
50
|
-
run (30s per-test timeout like `bun test --timeout=30000`) whose inputs
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
109
|
+
`cargo-test-compile` warms one workspace `cargo test --no-run`. Each member crate gets a cached `cargo-test-<package>`
|
|
110
|
+
run (30s per-test timeout like `bun test --timeout=30000`) whose inputs include that crate and its path dependencies.
|
|
111
|
+
Package-rooted workspaces use `cargo nextest run --workspace -E 'package(<crate>)'`; repository-rooted workspaces
|
|
112
|
+
additionally use `-p <crate>` to bind the runner to the project that owns the crate. Per-crate runners accept an empty
|
|
113
|
+
nextest selection because a valid workspace member may have no tests and a hash partition may legitimately be empty.
|
|
114
|
+
Those runs are chained across project boundaries to serialize their Cargo writers; `napi-debug` sits on that chain
|
|
115
|
+
after compile. Clippy uses a separate per-crate target directory so lint can overlap tests. A crate declaring
|
|
116
|
+
`[package.metadata.smoothbricks.wasm-bindgen]` also receives the cacheable `cargo-wasm` output target in its owning
|
|
117
|
+
project.
|
|
58
118
|
- A crate whose suite outgrows one bounded window declares `[package.metadata.smoothbricks.test] shards = N`, and gets
|
|
59
119
|
`cargo-test-<package>-shard1..N`, each running `--partition hash:i/N` with the full bound. nextest assigns a test to a
|
|
60
120
|
shard by hashing its name, so the shards stay an exact partition of the crate as tests and test binaries are added,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smoo-nx-cargo-hash.d.ts","sourceRoot":"","sources":["../../src/bin/smoo-nx-cargo-hash.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { hashCargoPathInputs } from '../cargo-source-hash.js';
|
|
4
|
+
const args = process.argv.slice(2);
|
|
5
|
+
if (args.length > 1) {
|
|
6
|
+
process.stderr.write('usage: smoo-nx-cargo-hash [Cargo.toml]\n');
|
|
7
|
+
process.exit(2);
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
process.stdout.write(`${await hashCargoPathInputs(resolve(args[0] ?? 'Cargo.toml'), process.cwd())}\n`);
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
process.stderr.write(`smoo-nx-cargo-hash: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
14
|
+
process.stderr.write('Restore the declared Cargo path dependencies and locked offline dependency cache, then rerun the Nx target.\n');
|
|
15
|
+
process.exitCode = 1;
|
|
16
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cargo owns resolution, including workspace inheritance, target dependencies,
|
|
3
|
+
* patches, and transitive path dependencies. A locked offline query observes
|
|
4
|
+
* that graph without fetching dependencies or changing the lockfile. Git and
|
|
5
|
+
* registry packages are immutable inputs already identified by Cargo.lock.
|
|
6
|
+
*
|
|
7
|
+
* This covers Rust sources and Cargo configuration, matching the plugin's
|
|
8
|
+
* in-workspace Rust inputs. Build scripts' other data/environment inputs remain
|
|
9
|
+
* explicit Nx inputs, just as they are for in-workspace crates.
|
|
10
|
+
*/
|
|
11
|
+
export declare function hashCargoPathInputs(manifestPath: string, workspaceRoot: string): Promise<string>;
|
|
12
|
+
//# sourceMappingURL=cargo-source-hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cargo-source-hash.d.ts","sourceRoot":"","sources":["../src/cargo-source-hash.ts"],"names":[],"mappings":"AA+BA;;;;;;;;;GASG;AACH,wBAAsB,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAgGtG"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import * as _assertGuard_1 from "typia/lib/internal/_assertGuard";
|
|
2
|
+
import { execFileSync } from 'node:child_process';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { statSync } from 'node:fs';
|
|
5
|
+
import { lstat, readdir, readFile, readlink, realpath } from 'node:fs/promises';
|
|
6
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
7
|
+
import typia from 'typia';
|
|
8
|
+
const parseMetadata = (() => {
|
|
9
|
+
const _ao0 = (input, _path, _exceptionable = true) => ((Array.isArray(input.packages) || _assertGuard_1._assertGuard(_exceptionable, {
|
|
10
|
+
method: "typia.json.createAssertParse",
|
|
11
|
+
path: _path + ".packages",
|
|
12
|
+
expected: "{ source: string | null; manifest_path: string; targets: { src_path: string; }[]; }[]",
|
|
13
|
+
value: input.packages
|
|
14
|
+
}, _errorFactory)) && input.packages.every((elem, _index3) => ("object" === typeof elem && null !== elem || _assertGuard_1._assertGuard(_exceptionable, {
|
|
15
|
+
method: "typia.json.createAssertParse",
|
|
16
|
+
path: _path + ".packages[" + _index3 + "]",
|
|
17
|
+
expected: "{ source: string | null; manifest_path: string; targets: { src_path: string; }[]; }",
|
|
18
|
+
value: elem
|
|
19
|
+
}, _errorFactory)) && _ao1(elem, _path + ".packages[" + _index3 + "]", true && _exceptionable) || _assertGuard_1._assertGuard(_exceptionable, {
|
|
20
|
+
method: "typia.json.createAssertParse",
|
|
21
|
+
path: _path + ".packages[" + _index3 + "]",
|
|
22
|
+
expected: "{ source: string | null; manifest_path: string; targets: { src_path: string; }[]; }",
|
|
23
|
+
value: elem
|
|
24
|
+
}, _errorFactory)) || _assertGuard_1._assertGuard(_exceptionable, {
|
|
25
|
+
method: "typia.json.createAssertParse",
|
|
26
|
+
path: _path + ".packages",
|
|
27
|
+
expected: "{ source: string | null; manifest_path: string; targets: { src_path: string; }[]; }[]",
|
|
28
|
+
value: input.packages
|
|
29
|
+
}, _errorFactory)) && ("string" === typeof input.workspace_root || _assertGuard_1._assertGuard(_exceptionable, {
|
|
30
|
+
method: "typia.json.createAssertParse",
|
|
31
|
+
path: _path + ".workspace_root",
|
|
32
|
+
expected: "string",
|
|
33
|
+
value: input.workspace_root
|
|
34
|
+
}, _errorFactory));
|
|
35
|
+
const _ao1 = (input, _path, _exceptionable = true) => (null === input.source || "string" === typeof input.source || _assertGuard_1._assertGuard(_exceptionable, {
|
|
36
|
+
method: "typia.json.createAssertParse",
|
|
37
|
+
path: _path + ".source",
|
|
38
|
+
expected: "(null | string)",
|
|
39
|
+
value: input.source
|
|
40
|
+
}, _errorFactory)) && ("string" === typeof input.manifest_path || _assertGuard_1._assertGuard(_exceptionable, {
|
|
41
|
+
method: "typia.json.createAssertParse",
|
|
42
|
+
path: _path + ".manifest_path",
|
|
43
|
+
expected: "string",
|
|
44
|
+
value: input.manifest_path
|
|
45
|
+
}, _errorFactory)) && ((Array.isArray(input.targets) || _assertGuard_1._assertGuard(_exceptionable, {
|
|
46
|
+
method: "typia.json.createAssertParse",
|
|
47
|
+
path: _path + ".targets",
|
|
48
|
+
expected: "{ src_path: string; }[]",
|
|
49
|
+
value: input.targets
|
|
50
|
+
}, _errorFactory)) && input.targets.every((elem, _index4) => ("object" === typeof elem && null !== elem || _assertGuard_1._assertGuard(_exceptionable, {
|
|
51
|
+
method: "typia.json.createAssertParse",
|
|
52
|
+
path: _path + ".targets[" + _index4 + "]",
|
|
53
|
+
expected: "{ src_path: string; }",
|
|
54
|
+
value: elem
|
|
55
|
+
}, _errorFactory)) && _ao2(elem, _path + ".targets[" + _index4 + "]", true && _exceptionable) || _assertGuard_1._assertGuard(_exceptionable, {
|
|
56
|
+
method: "typia.json.createAssertParse",
|
|
57
|
+
path: _path + ".targets[" + _index4 + "]",
|
|
58
|
+
expected: "{ src_path: string; }",
|
|
59
|
+
value: elem
|
|
60
|
+
}, _errorFactory)) || _assertGuard_1._assertGuard(_exceptionable, {
|
|
61
|
+
method: "typia.json.createAssertParse",
|
|
62
|
+
path: _path + ".targets",
|
|
63
|
+
expected: "{ src_path: string; }[]",
|
|
64
|
+
value: input.targets
|
|
65
|
+
}, _errorFactory));
|
|
66
|
+
const _ao2 = (input, _path, _exceptionable = true) => "string" === typeof input.src_path || _assertGuard_1._assertGuard(_exceptionable, {
|
|
67
|
+
method: "typia.json.createAssertParse",
|
|
68
|
+
path: _path + ".src_path",
|
|
69
|
+
expected: "string",
|
|
70
|
+
value: input.src_path
|
|
71
|
+
}, _errorFactory);
|
|
72
|
+
const _io0 = input => Array.isArray(input.packages) && input.packages.every(elem => "object" === typeof elem && null !== elem && _io1(elem)) && "string" === typeof input.workspace_root;
|
|
73
|
+
const _io1 = input => (null === input.source || "string" === typeof input.source) && "string" === typeof input.manifest_path && (Array.isArray(input.targets) && input.targets.every(elem => "object" === typeof elem && null !== elem && _io2(elem)));
|
|
74
|
+
const _io2 = input => "string" === typeof input.src_path;
|
|
75
|
+
const __is = input => "object" === typeof input && null !== input && _io0(input);
|
|
76
|
+
let _errorFactory;
|
|
77
|
+
const __assert = (input, errorFactory) => {
|
|
78
|
+
if (false === __is(input)) {
|
|
79
|
+
_errorFactory = errorFactory;
|
|
80
|
+
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _assertGuard_1._assertGuard(true, {
|
|
81
|
+
method: "typia.json.createAssertParse",
|
|
82
|
+
path: _path + "",
|
|
83
|
+
expected: "CargoMetadata",
|
|
84
|
+
value: input
|
|
85
|
+
}, _errorFactory)) && _ao0(input, _path + "", true) || _assertGuard_1._assertGuard(true, {
|
|
86
|
+
method: "typia.json.createAssertParse",
|
|
87
|
+
path: _path + "",
|
|
88
|
+
expected: "CargoMetadata",
|
|
89
|
+
value: input
|
|
90
|
+
}, _errorFactory))(input, "$input", true);
|
|
91
|
+
}
|
|
92
|
+
return input;
|
|
93
|
+
};
|
|
94
|
+
return (input, errorFactory) => __assert(JSON.parse(input), errorFactory);
|
|
95
|
+
})();
|
|
96
|
+
const ignoredDirectories = new Set([
|
|
97
|
+
'target',
|
|
98
|
+
'.git',
|
|
99
|
+
'node_modules',
|
|
100
|
+
'.cache',
|
|
101
|
+
'.cowshed',
|
|
102
|
+
'.fseventsd',
|
|
103
|
+
'.TemporaryItems',
|
|
104
|
+
'.Trashes',
|
|
105
|
+
'.Spotlight-V100',
|
|
106
|
+
'.DocumentRevisions-V100',
|
|
107
|
+
]);
|
|
108
|
+
const ancestorInputs = ['Cargo.toml', '.cargo/config', '.cargo/config.toml'];
|
|
109
|
+
/**
|
|
110
|
+
* Cargo owns resolution, including workspace inheritance, target dependencies,
|
|
111
|
+
* patches, and transitive path dependencies. A locked offline query observes
|
|
112
|
+
* that graph without fetching dependencies or changing the lockfile. Git and
|
|
113
|
+
* registry packages are immutable inputs already identified by Cargo.lock.
|
|
114
|
+
*
|
|
115
|
+
* This covers Rust sources and Cargo configuration, matching the plugin's
|
|
116
|
+
* in-workspace Rust inputs. Build scripts' other data/environment inputs remain
|
|
117
|
+
* explicit Nx inputs, just as they are for in-workspace crates.
|
|
118
|
+
*/
|
|
119
|
+
export async function hashCargoPathInputs(manifestPath, workspaceRoot) {
|
|
120
|
+
const root = await realpath(workspaceRoot);
|
|
121
|
+
const metadata = parseMetadata(execFileSync('cargo', ['metadata', '--format-version', '1', '--locked', '--offline', '--manifest-path', resolve(manifestPath)], { cwd: root, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, stdio: ['ignore', 'pipe', 'inherit'] }));
|
|
122
|
+
const cargoRoot = await realpath(metadata.workspace_root);
|
|
123
|
+
const directories = new Set();
|
|
124
|
+
const files = new Set();
|
|
125
|
+
const ancestors = new Set();
|
|
126
|
+
const links = new Map();
|
|
127
|
+
for (const pkg of metadata.packages) {
|
|
128
|
+
if (pkg.source !== null)
|
|
129
|
+
continue;
|
|
130
|
+
const manifest = await realpath(pkg.manifest_path);
|
|
131
|
+
const directory = dirname(manifest);
|
|
132
|
+
const fromRoot = relative(root, directory);
|
|
133
|
+
const fromCargo = relative(cargoRoot, directory);
|
|
134
|
+
if (fromRoot !== '..' &&
|
|
135
|
+
!fromRoot.startsWith(`..${sep}`) &&
|
|
136
|
+
!isAbsolute(fromRoot) &&
|
|
137
|
+
fromCargo !== '..' &&
|
|
138
|
+
!fromCargo.startsWith(`..${sep}`) &&
|
|
139
|
+
!isAbsolute(fromCargo) &&
|
|
140
|
+
!fromRoot.split(sep).includes('node_modules'))
|
|
141
|
+
continue;
|
|
142
|
+
directories.add(directory);
|
|
143
|
+
files.add(manifest);
|
|
144
|
+
// Cargo resolves explicit package.workspace ownership as well as ancestor
|
|
145
|
+
// workspaces. Metadata's workspace_root describes only the invoking root.
|
|
146
|
+
const governingManifest = execFileSync('cargo', ['locate-project', '--workspace', '--manifest-path', manifest, '--message-format', 'plain'], { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'inherit'] }).trim();
|
|
147
|
+
files.add(await realpath(governingManifest));
|
|
148
|
+
for (const target of pkg.targets)
|
|
149
|
+
files.add(await realpath(target.src_path));
|
|
150
|
+
// An external member can inherit edition, lint policy, dependencies and
|
|
151
|
+
// profiles from a workspace above its package directory. Those manifests
|
|
152
|
+
// are not descendants of the source roots returned by Cargo metadata.
|
|
153
|
+
for (let ancestor = dirname(directory); !ancestors.has(ancestor); ancestor = dirname(ancestor)) {
|
|
154
|
+
ancestors.add(ancestor);
|
|
155
|
+
for (const name of ancestorInputs) {
|
|
156
|
+
const file = join(ancestor, name);
|
|
157
|
+
if (statSync(file, { throwIfNoEntry: false })?.isFile())
|
|
158
|
+
files.add(await realpath(file));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// Overlapping packages (a facade root plus its child crates) share one walk.
|
|
163
|
+
const visited = new Set();
|
|
164
|
+
async function walk(directory) {
|
|
165
|
+
const canonical = await realpath(directory);
|
|
166
|
+
if (visited.has(canonical))
|
|
167
|
+
return;
|
|
168
|
+
visited.add(canonical);
|
|
169
|
+
for (const entry of await readdir(canonical, { withFileTypes: true })) {
|
|
170
|
+
if (ignoredDirectories.has(entry.name))
|
|
171
|
+
continue;
|
|
172
|
+
const path = join(canonical, entry.name);
|
|
173
|
+
if (entry.isSymbolicLink())
|
|
174
|
+
links.set(path, await readlink(path));
|
|
175
|
+
const info = entry.isSymbolicLink() ? await lstat(await realpath(path)) : entry;
|
|
176
|
+
if (info.isDirectory()) {
|
|
177
|
+
await walk(path);
|
|
178
|
+
}
|
|
179
|
+
else if (info.isFile() &&
|
|
180
|
+
(entry.name.endsWith('.rs') ||
|
|
181
|
+
entry.name === 'Cargo.toml' ||
|
|
182
|
+
(canonical.endsWith(`${sep}.cargo`) && (entry.name === 'config' || entry.name === 'config.toml')))) {
|
|
183
|
+
files.add(await realpath(path));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
for (const directory of directories)
|
|
188
|
+
await walk(directory);
|
|
189
|
+
const hash = createHash('sha256');
|
|
190
|
+
hash.update('cargo-path-inputs-v1\0');
|
|
191
|
+
for (const [path, target] of [...links].sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))) {
|
|
192
|
+
hash.update(relative(root, path));
|
|
193
|
+
hash.update('\0symlink\0');
|
|
194
|
+
hash.update(target);
|
|
195
|
+
hash.update('\0');
|
|
196
|
+
}
|
|
197
|
+
for (const file of [...files].sort()) {
|
|
198
|
+
const bytes = await readFile(file);
|
|
199
|
+
// Both names and bytes matter: moving a module can change resolution even
|
|
200
|
+
// when its contents are unchanged. Length framing makes boundaries unique.
|
|
201
|
+
hash.update(relative(root, file));
|
|
202
|
+
hash.update('\0');
|
|
203
|
+
hash.update(String(bytes.length));
|
|
204
|
+
hash.update('\0');
|
|
205
|
+
hash.update(bytes);
|
|
206
|
+
}
|
|
207
|
+
return hash.digest('hex');
|
|
208
|
+
}
|
|
@@ -22,7 +22,23 @@ export declare function listCargoWorkspacePackages(absoluteProjectRoot: string):
|
|
|
22
22
|
* wins by path depth so projects under `packages/*` own their own crates.
|
|
23
23
|
*/
|
|
24
24
|
export declare function attributeCargoWorkspacePackages(packages: readonly CargoWorkspacePackage[], projects: readonly CargoWorkspaceProject[]): AttributedCargoWorkspacePackage[];
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* The named input a workspace must declare when a crate's path dependencies
|
|
27
|
+
* resolve outside the Nx workspace. Nx hashes filesets against the workspace
|
|
28
|
+
* file map only, so a glob pointing above the root — or an absolute path
|
|
29
|
+
* spliced under `{workspaceRoot}` — matches nothing and every cached verdict
|
|
30
|
+
* silently ignores the dependency. A runtime named input can hash any tree.
|
|
31
|
+
*/
|
|
32
|
+
export declare const EXTERNAL_RUST_CRATES_INPUT = "externalRustCrates";
|
|
33
|
+
export interface CargoPackageTestInputsOptions {
|
|
34
|
+
/** The Nx workspace root, where `nx.json` declares named inputs. */
|
|
35
|
+
workspaceRoot: string;
|
|
36
|
+
/** The cargo workspace root holding the top-level `Cargo.toml`. */
|
|
37
|
+
absoluteProjectRoot: string;
|
|
38
|
+
memberDir: string;
|
|
39
|
+
inputRoot?: string;
|
|
40
|
+
}
|
|
41
|
+
export declare function cargoPackageTestInputs({ workspaceRoot, absoluteProjectRoot, memberDir, inputRoot, }: CargoPackageTestInputsOptions): Promise<string[]>;
|
|
26
42
|
/**
|
|
27
43
|
* The aggregate that actually runs a cargo workspace's tests. Named here because
|
|
28
44
|
* both target inference and the policy that verifies `test` reaches it need the
|
|
@@ -39,7 +55,7 @@ export declare const CARGO_TEST_COMPILE_TARGET = "cargo-test-compile";
|
|
|
39
55
|
export declare const CARGO_TEST_EXCEPTIONS_SUFFIX = "exceptions";
|
|
40
56
|
/**
|
|
41
57
|
* A crate on one target keeps the bare name; a split crate suffixes the piece,
|
|
42
|
-
* so `cargo-test-
|
|
58
|
+
* so `cargo-test-example-core-shard2` still reads as "example-core's tests".
|
|
43
59
|
*/
|
|
44
60
|
export declare function cargoTestPackageTargetName(packageName: string, piece?: string): string;
|
|
45
61
|
/**
|
|
@@ -51,24 +67,10 @@ export declare function packageNameFromCargoTestTarget(targetName: string): stri
|
|
|
51
67
|
/**
|
|
52
68
|
* The tests nextest.toml singles out with an override, as one filterset.
|
|
53
69
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* - a `test-group` is scoped to a single nextest RUN, so letting the hash
|
|
59
|
-
* scatter its members across shards silently dissolves it. The real-APFS
|
|
60
|
-
* group exists because those tests contend on Disk Arbitration
|
|
61
|
-
* machine-wide, where an unscoped `diskutil apfs list -plist` measured 0.7s
|
|
62
|
-
* idle against 14.4s while another process is attaching.
|
|
63
|
-
* - a raised `slow-timeout` marks a test whose cost is not the suite's cost.
|
|
64
|
-
* `lesser_capabilities_fail_to_compile_...` rustc's a fixture that
|
|
65
|
-
* `cargo test --no-run` cannot pre-build, so it costs 25.6s on a cold
|
|
66
|
-
* target directory against 1.8s warm. Every CI runner is cold, and left in
|
|
67
|
-
* a shard that spike lands on whichever 250-odd tests share it.
|
|
68
|
-
*
|
|
69
|
-
* One target for all of them rather than one each: they sit in different groups
|
|
70
|
-
* so they run concurrently, making the combined wall the max of the classes
|
|
71
|
-
* rather than their sum.
|
|
70
|
+
* Overrides can encode constraints that must survive sharding: a test group
|
|
71
|
+
* limits concurrency within one nextest run, while a raised slow timeout can
|
|
72
|
+
* identify expensive tests that should not delay an otherwise bounded shard.
|
|
73
|
+
* Keep the configured exceptions in one run so group limits remain effective.
|
|
72
74
|
*
|
|
73
75
|
* Deriving this from the config that declares the classes, rather than
|
|
74
76
|
* restating their filters, means adding an override there is the whole change —
|
|
@@ -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":"AAMA,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,MAAM,GAAG,qBAAqB,EAAE,CAkF/F;AA0ED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,QAAQ,EAAE,SAAS,qBAAqB,EAAE,EAC1C,QAAQ,EAAE,SAAS,qBAAqB,EAAE,GACzC,+BAA+B,EAAE,CAgBnC;AAED;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,uBAAuB,CAAC;AAE/D,MAAM,WAAW,6BAA6B;IAC5C,oEAAoE;IACpE,aAAa,EAAE,MAAM,CAAC;IACtB,mEAAmE;IACnE,mBAAmB,EAAE,MAAM,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAsB,sBAAsB,CAAC,EAC3C,aAAa,EACb,mBAAmB,EACnB,SAAS,EACT,SAA2B,GAC5B,EAAE,6BAA6B,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAyMnD;AAoID;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,eAAe,CAAC;AAE9C,wEAAwE;AACxE,eAAO,MAAM,yBAAyB,uBAAuB,CAAC;AAE9D;;;;GAIG;AACH,eAAO,MAAM,4BAA4B,eAAe,CAAC;AAEzD;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAGtF;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQhF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CAAC,iBAAiB,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAoB9E;AAED,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAG1G"}
|