@smoothbricks/nx-plugin 0.4.22 → 0.4.23
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 +77 -21
- package/dist/bin/smoo-nx-exec.js +35 -11
- package/dist/cargo-closure-input.d.ts +63 -0
- package/dist/cargo-closure-input.d.ts.map +1 -0
- package/dist/cargo-closure-input.js +197 -0
- package/dist/cargo-source-hash.d.ts +37 -0
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +108 -190
- package/dist/cross-check-policy.d.ts +14 -0
- package/dist/cross-check-policy.d.ts.map +1 -1
- package/dist/cross-check-policy.js +15 -1
- package/dist/ensure-built.d.ts +3 -2
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +33 -56
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +112 -76
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +12 -15
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +10 -0
- package/dist/managed-files/publish-workflow.d.ts.map +1 -1
- package/dist/managed-files/publish-workflow.js +12 -6
- package/dist/manifest-hash.d.ts.map +1 -1
- package/dist/manifest-hash.js +24 -30
- package/dist/package-target-policy.js +1 -1
- package/dist/platform-targets.d.ts +7 -0
- package/dist/platform-targets.d.ts.map +1 -1
- package/dist/platform-targets.js +7 -0
- package/dist/workspace-config-policy.d.ts +1 -1
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +1 -1
- package/managed/raw/envrc +38 -1
- package/managed/raw/tooling/direnv/developer-links.ts +201 -0
- package/managed/raw/tooling/direnv/devenv.smoo.nix +75 -51
- package/managed/raw/tooling/direnv/secret-references.ts +3 -1
- package/managed/raw/tooling/direnv/setup-environment.ts +562 -78
- package/managed/raw/tooling/direnv/shared-caches.sh +53 -0
- package/managed/raw/tooling/git-hooks/pre-push.sh +22 -1
- package/managed/templates/github/workflows/managed-files.yml +4 -3
- package/nextest.toml +5 -5
- package/package.json +2 -2
- package/src/__tests__/fixture-nx-env.ts +31 -0
- package/src/__tests__/in-process-nx-index.ts +9 -0
- package/src/bin/smoo-nx-exec.ts +40 -11
- package/src/cargo-closure-input.test.ts +184 -0
- package/src/cargo-closure-input.ts +247 -0
- package/src/cargo-source-hash.test.ts +8 -9
- package/src/cargo-source-hash.ts +146 -47
- package/src/cross-check-policy.ts +15 -3
- package/src/ensure-built.test.ts +65 -5
- package/src/ensure-built.ts +40 -85
- package/src/index.test.ts +94 -53
- package/src/index.ts +164 -84
- package/src/managed-files/ci-workflow.ts +12 -15
- package/src/managed-files/files.ts +10 -0
- package/src/managed-files/generator.test.ts +29 -0
- package/src/managed-files/publish-workflow.ts +17 -6
- package/src/manifest-hash.test.ts +21 -1
- package/src/manifest-hash.ts +26 -29
- package/src/package-target-policy.ts +1 -1
- package/src/platform-targets.ts +8 -0
- package/src/workspace-config-policy.ts +6 -1
|
@@ -1,167 +1,66 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { execFileSync, spawnSync } from 'node:child_process';
|
|
1
|
+
import { execFile, execFileSync, spawnSync } from 'node:child_process';
|
|
3
2
|
import { createHash } from 'node:crypto';
|
|
4
3
|
import { realpathSync, statSync } from 'node:fs';
|
|
5
4
|
import { lstat, readdir, readFile, readlink, realpath } from 'node:fs/promises';
|
|
6
5
|
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
method: "typia.json.createAssertParse",
|
|
48
|
-
path: _path + ".workspace_root",
|
|
49
|
-
expected: "string",
|
|
50
|
-
value: input.workspace_root
|
|
51
|
-
}, _errorFactory));
|
|
52
|
-
const _ao1 = (input, _path, _exceptionable = true) => _ap0(input, _path, true && _exceptionable) && (null === input.source || "string" === typeof input.source || _assertGuard_1._assertGuard(_exceptionable, {
|
|
53
|
-
method: "typia.json.createAssertParse",
|
|
54
|
-
path: _path + ".source",
|
|
55
|
-
expected: "(null | string)",
|
|
56
|
-
value: input.source
|
|
57
|
-
}, _errorFactory)) && ("string" === typeof input.manifest_path || _assertGuard_1._assertGuard(_exceptionable, {
|
|
58
|
-
method: "typia.json.createAssertParse",
|
|
59
|
-
path: _path + ".manifest_path",
|
|
60
|
-
expected: "string",
|
|
61
|
-
value: input.manifest_path
|
|
62
|
-
}, _errorFactory)) && ((Array.isArray(input.targets) || _assertGuard_1._assertGuard(_exceptionable, {
|
|
63
|
-
method: "typia.json.createAssertParse",
|
|
64
|
-
path: _path + ".targets",
|
|
65
|
-
expected: "{ src_path: string; }[]",
|
|
66
|
-
value: input.targets
|
|
67
|
-
}, _errorFactory)) && input.targets.every((elem, _index6) => ("object" === typeof elem && null !== elem || _assertGuard_1._assertGuard(_exceptionable, {
|
|
68
|
-
method: "typia.json.createAssertParse",
|
|
69
|
-
path: _path + ".targets[" + _index6 + "]",
|
|
70
|
-
expected: "{ src_path: string; }",
|
|
71
|
-
value: elem
|
|
72
|
-
}, _errorFactory)) && _ao2(elem, _path + ".targets[" + _index6 + "]", true && _exceptionable) || _assertGuard_1._assertGuard(_exceptionable, {
|
|
73
|
-
method: "typia.json.createAssertParse",
|
|
74
|
-
path: _path + ".targets[" + _index6 + "]",
|
|
75
|
-
expected: "{ src_path: string; }",
|
|
76
|
-
value: elem
|
|
77
|
-
}, _errorFactory)) || _assertGuard_1._assertGuard(_exceptionable, {
|
|
78
|
-
method: "typia.json.createAssertParse",
|
|
79
|
-
path: _path + ".targets",
|
|
80
|
-
expected: "{ src_path: string; }[]",
|
|
81
|
-
value: input.targets
|
|
82
|
-
}, _errorFactory));
|
|
83
|
-
const _ao2 = (input, _path, _exceptionable = true) => "string" === typeof input.src_path || _assertGuard_1._assertGuard(_exceptionable, {
|
|
84
|
-
method: "typia.json.createAssertParse",
|
|
85
|
-
path: _path + ".src_path",
|
|
86
|
-
expected: "string",
|
|
87
|
-
value: input.src_path
|
|
88
|
-
}, _errorFactory);
|
|
89
|
-
const _ao3 = (input, _path, _exceptionable = true) => (Array.isArray(input.nodes) || _assertGuard_1._assertGuard(_exceptionable, {
|
|
90
|
-
method: "typia.json.createAssertParse",
|
|
91
|
-
path: _path + ".nodes",
|
|
92
|
-
expected: "{ id: string; deps: { pkg: string; }[]; }[]",
|
|
93
|
-
value: input.nodes
|
|
94
|
-
}, _errorFactory)) && input.nodes.every((elem, _index7) => ("object" === typeof elem && null !== elem || _assertGuard_1._assertGuard(_exceptionable, {
|
|
95
|
-
method: "typia.json.createAssertParse",
|
|
96
|
-
path: _path + ".nodes[" + _index7 + "]",
|
|
97
|
-
expected: "{ id: string; deps: { pkg: string; }[]; }",
|
|
98
|
-
value: elem
|
|
99
|
-
}, _errorFactory)) && _ao4(elem, _path + ".nodes[" + _index7 + "]", true && _exceptionable) || _assertGuard_1._assertGuard(_exceptionable, {
|
|
100
|
-
method: "typia.json.createAssertParse",
|
|
101
|
-
path: _path + ".nodes[" + _index7 + "]",
|
|
102
|
-
expected: "{ id: string; deps: { pkg: string; }[]; }",
|
|
103
|
-
value: elem
|
|
104
|
-
}, _errorFactory)) || _assertGuard_1._assertGuard(_exceptionable, {
|
|
105
|
-
method: "typia.json.createAssertParse",
|
|
106
|
-
path: _path + ".nodes",
|
|
107
|
-
expected: "{ id: string; deps: { pkg: string; }[]; }[]",
|
|
108
|
-
value: input.nodes
|
|
109
|
-
}, _errorFactory);
|
|
110
|
-
const _ao4 = (input, _path, _exceptionable = true) => _ap0(input, _path, true && _exceptionable) && ((Array.isArray(input.deps) || _assertGuard_1._assertGuard(_exceptionable, {
|
|
111
|
-
method: "typia.json.createAssertParse",
|
|
112
|
-
path: _path + ".deps",
|
|
113
|
-
expected: "{ pkg: string; }[]",
|
|
114
|
-
value: input.deps
|
|
115
|
-
}, _errorFactory)) && input.deps.every((elem, _index8) => ("object" === typeof elem && null !== elem || _assertGuard_1._assertGuard(_exceptionable, {
|
|
116
|
-
method: "typia.json.createAssertParse",
|
|
117
|
-
path: _path + ".deps[" + _index8 + "]",
|
|
118
|
-
expected: "{ pkg: string; }",
|
|
119
|
-
value: elem
|
|
120
|
-
}, _errorFactory)) && _ao5(elem, _path + ".deps[" + _index8 + "]", true && _exceptionable) || _assertGuard_1._assertGuard(_exceptionable, {
|
|
121
|
-
method: "typia.json.createAssertParse",
|
|
122
|
-
path: _path + ".deps[" + _index8 + "]",
|
|
123
|
-
expected: "{ pkg: string; }",
|
|
124
|
-
value: elem
|
|
125
|
-
}, _errorFactory)) || _assertGuard_1._assertGuard(_exceptionable, {
|
|
126
|
-
method: "typia.json.createAssertParse",
|
|
127
|
-
path: _path + ".deps",
|
|
128
|
-
expected: "{ pkg: string; }[]",
|
|
129
|
-
value: input.deps
|
|
130
|
-
}, _errorFactory));
|
|
131
|
-
const _ao5 = (input, _path, _exceptionable = true) => "string" === typeof input.pkg || _assertGuard_1._assertGuard(_exceptionable, {
|
|
132
|
-
method: "typia.json.createAssertParse",
|
|
133
|
-
path: _path + ".pkg",
|
|
134
|
-
expected: "string",
|
|
135
|
-
value: input.pkg
|
|
136
|
-
}, _errorFactory);
|
|
137
|
-
const _io0 = input => Array.isArray(input.packages) && input.packages.every(elem => "object" === typeof elem && null !== elem && _io1(elem)) && (null === input.resolve || "object" === typeof input.resolve && null !== input.resolve && _io3(input.resolve)) && "string" === typeof input.workspace_root;
|
|
138
|
-
const _io1 = input => _ip0(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)));
|
|
139
|
-
const _io2 = input => "string" === typeof input.src_path;
|
|
140
|
-
const _io3 = input => Array.isArray(input.nodes) && input.nodes.every(elem => "object" === typeof elem && null !== elem && _io4(elem));
|
|
141
|
-
const _io4 = input => _ip0(input) && (Array.isArray(input.deps) && input.deps.every(elem => "object" === typeof elem && null !== elem && _io5(elem)));
|
|
142
|
-
const _io5 = input => "string" === typeof input.pkg;
|
|
143
|
-
const __is = input => "object" === typeof input && null !== input && _io0(input);
|
|
144
|
-
let _errorFactory;
|
|
145
|
-
const __assert = (input, errorFactory) => {
|
|
146
|
-
if (false === __is(input)) {
|
|
147
|
-
_errorFactory = errorFactory;
|
|
148
|
-
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _assertGuard_1._assertGuard(true, {
|
|
149
|
-
method: "typia.json.createAssertParse",
|
|
150
|
-
path: _path + "",
|
|
151
|
-
expected: "CargoMetadata",
|
|
152
|
-
value: input
|
|
153
|
-
}, _errorFactory)) && _ao0(input, _path + "", true) || _assertGuard_1._assertGuard(true, {
|
|
154
|
-
method: "typia.json.createAssertParse",
|
|
155
|
-
path: _path + "",
|
|
156
|
-
expected: "CargoMetadata",
|
|
157
|
-
value: input
|
|
158
|
-
}, _errorFactory))(input, "$input", true);
|
|
159
|
-
}
|
|
160
|
-
return input;
|
|
6
|
+
/**
|
|
7
|
+
* Narrowed field by field, not by typia: graph inference imports this module,
|
|
8
|
+
* and a workspace that loads the plugin from its sources runs them without
|
|
9
|
+
* typia's compile-time transform.
|
|
10
|
+
*/
|
|
11
|
+
function parseCargoMetadata(json) {
|
|
12
|
+
const member = (value, key) => typeof value === 'object' && value !== null && key in value ? Reflect.get(value, key) : undefined;
|
|
13
|
+
const text = (value, field) => {
|
|
14
|
+
if (typeof value !== 'string')
|
|
15
|
+
throw new Error(`cargo metadata reported no valid ${field}`);
|
|
16
|
+
return value;
|
|
17
|
+
};
|
|
18
|
+
const list = (value, field) => {
|
|
19
|
+
if (!Array.isArray(value))
|
|
20
|
+
throw new Error(`cargo metadata reported no valid ${field}`);
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
const document = JSON.parse(json);
|
|
24
|
+
const resolveGraph = member(document, 'resolve');
|
|
25
|
+
return {
|
|
26
|
+
packages: list(member(document, 'packages'), 'packages').map((pkg) => ({
|
|
27
|
+
id: text(member(pkg, 'id'), 'package id'),
|
|
28
|
+
source: member(pkg, 'source') === null ? null : text(member(pkg, 'source'), 'package source'),
|
|
29
|
+
manifest_path: text(member(pkg, 'manifest_path'), 'package manifest_path'),
|
|
30
|
+
targets: list(member(pkg, 'targets'), 'package targets').map((target) => ({
|
|
31
|
+
src_path: text(member(target, 'src_path'), 'target src_path'),
|
|
32
|
+
})),
|
|
33
|
+
})),
|
|
34
|
+
resolve: resolveGraph === null
|
|
35
|
+
? null
|
|
36
|
+
: {
|
|
37
|
+
nodes: list(member(resolveGraph, 'nodes'), 'resolve').map((node) => ({
|
|
38
|
+
id: text(member(node, 'id'), 'resolve node id'),
|
|
39
|
+
deps: list(member(node, 'deps'), 'resolve node deps').map((dependency) => ({
|
|
40
|
+
pkg: text(member(dependency, 'pkg'), 'resolve edge'),
|
|
41
|
+
})),
|
|
42
|
+
})),
|
|
43
|
+
},
|
|
44
|
+
workspace_members: list(member(document, 'workspace_members'), 'workspace_members').map((id) => text(id, 'workspace member')),
|
|
45
|
+
workspace_root: text(member(document, 'workspace_root'), 'workspace_root'),
|
|
161
46
|
};
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Cargo's stdout, or its failure with Cargo's stderr in the message. Not
|
|
50
|
+
* `promisify` from `node:util`: importing that module makes Node probe color
|
|
51
|
+
* support at startup, and with FORCE_COLOR and NO_COLOR both set (an Nx
|
|
52
|
+
* inside an Nx task, in a shell that exports NO_COLOR) it warns on stderr
|
|
53
|
+
* under its own pid, which a runtime input would hash as a new digest on
|
|
54
|
+
* every run.
|
|
55
|
+
*/
|
|
56
|
+
function runCargo(args, cwd) {
|
|
57
|
+
// The executor form: the workspace compiles against es2022, which has no `Promise.withResolvers`.
|
|
58
|
+
return new Promise((settle, reject) => {
|
|
59
|
+
execFile('cargo', args, { cwd, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 }, (error, stdout) => error === null ? settle(stdout) : reject(error));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/** Directories the hash never descends into: build output, VCS and volume metadata, installed packages. */
|
|
63
|
+
export const HASH_SKIPPED_DIRECTORIES = [
|
|
165
64
|
'target',
|
|
166
65
|
'.git',
|
|
167
66
|
'node_modules',
|
|
@@ -172,8 +71,9 @@ const ignoredDirectories = new Set([
|
|
|
172
71
|
'.Trashes',
|
|
173
72
|
'.Spotlight-V100',
|
|
174
73
|
'.DocumentRevisions-V100',
|
|
175
|
-
]
|
|
176
|
-
|
|
74
|
+
];
|
|
75
|
+
/** Files in every ancestor of a package directory that Cargo reads while building it. */
|
|
76
|
+
export const CARGO_ANCESTOR_INPUTS = ['Cargo.toml', '.cargo/config', '.cargo/config.toml'];
|
|
177
77
|
/**
|
|
178
78
|
* Cargo owns resolution, including workspace inheritance, target dependencies,
|
|
179
79
|
* patches, and transitive path dependencies. A locked offline query observes
|
|
@@ -197,36 +97,57 @@ const ancestorInputs = ['Cargo.toml', '.cargo/config', '.cargo/config.toml'];
|
|
|
197
97
|
// on stderr ("Blocking waiting for file lock on package cache") a
|
|
198
98
|
// timing-dependent number of times when Nx hashes many tasks at once, which
|
|
199
99
|
// made one unchanged tree produce four different task hashes per run. Cargo's
|
|
200
|
-
// stderr is kept for the failure path only, where
|
|
201
|
-
//
|
|
100
|
+
// stderr is kept for the failure path only, where execFile attaches it to the
|
|
101
|
+
// rejected error. Git runs under the same rule.
|
|
202
102
|
const CHILD_STDIO = ['ignore', 'pipe', 'pipe'];
|
|
103
|
+
/** Locked, offline `cargo metadata` for the workspace `manifestPath` names, run from `cwd`. */
|
|
104
|
+
export async function readCargoResolve(manifestPath, cwd) {
|
|
105
|
+
const stdout = await runCargo(['metadata', '--format-version', '1', '--locked', '--offline', '--manifest-path', resolve(manifestPath)], cwd);
|
|
106
|
+
const metadata = parseCargoMetadata(stdout);
|
|
107
|
+
const local = await Promise.all(metadata.packages
|
|
108
|
+
.filter((pkg) => pkg.source === null)
|
|
109
|
+
.map(async (pkg) => {
|
|
110
|
+
const manifest = await realpath(pkg.manifest_path);
|
|
111
|
+
const sources = await Promise.all(pkg.targets.map((target) => realpath(target.src_path)));
|
|
112
|
+
return { id: pkg.id, directory: dirname(manifest), manifest, sources };
|
|
113
|
+
}));
|
|
114
|
+
return {
|
|
115
|
+
root: await realpath(metadata.workspace_root),
|
|
116
|
+
members: new Set(metadata.workspace_members),
|
|
117
|
+
local,
|
|
118
|
+
edges: metadata.resolve === null
|
|
119
|
+
? null
|
|
120
|
+
: new Map(metadata.resolve.nodes.map((node) => [node.id, node.deps.map((dependency) => dependency.pkg)])),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The canonical root manifest of the Cargo workspace that governs `pkg`.
|
|
125
|
+
* Metadata's `workspace_root` describes only the invoking workspace, which is
|
|
126
|
+
* the answer for its own members. Any other path package asks Cargo, which
|
|
127
|
+
* resolves an explicit `package.workspace` as well as the ancestor search.
|
|
128
|
+
*/
|
|
129
|
+
export async function governingManifest(cargo, pkg, cwd) {
|
|
130
|
+
if (cargo.members.has(pkg.id))
|
|
131
|
+
return realpath(join(cargo.root, 'Cargo.toml'));
|
|
132
|
+
const stdout = await runCargo(['locate-project', '--workspace', '--manifest-path', pkg.manifest, '--message-format', 'plain'], cwd);
|
|
133
|
+
return realpath(stdout.trim());
|
|
134
|
+
}
|
|
203
135
|
export async function hashCargoPathInputs(manifestPath, workspaceRoot, options) {
|
|
204
136
|
const root = await realpath(workspaceRoot);
|
|
205
|
-
const
|
|
206
|
-
const
|
|
207
|
-
const local = [];
|
|
208
|
-
for (const pkg of metadata.packages) {
|
|
209
|
-
if (pkg.source !== null)
|
|
210
|
-
continue;
|
|
211
|
-
const manifest = await realpath(pkg.manifest_path);
|
|
212
|
-
const sources = [];
|
|
213
|
-
for (const target of pkg.targets)
|
|
214
|
-
sources.push(await realpath(target.src_path));
|
|
215
|
-
local.push({ id: pkg.id, directory: dirname(manifest), manifest, sources });
|
|
216
|
-
}
|
|
217
|
-
const members = options?.closure === undefined ? undefined : await dependencyClosure(metadata, local, resolve(options.closure));
|
|
137
|
+
const cargo = await readCargoResolve(manifestPath, root);
|
|
138
|
+
const members = options?.closure === undefined ? undefined : await dependencyClosure(cargo, resolve(options.closure));
|
|
218
139
|
const directories = new Set();
|
|
219
140
|
const files = new Set();
|
|
220
141
|
const ancestors = new Set();
|
|
221
142
|
const links = new Map();
|
|
222
143
|
const packageSources = [];
|
|
223
|
-
for (const pkg of local) {
|
|
144
|
+
for (const pkg of cargo.local) {
|
|
224
145
|
if (members !== undefined && !members.has(pkg.id))
|
|
225
146
|
continue;
|
|
226
147
|
const directory = pkg.directory;
|
|
227
148
|
if (!options?.includeWorkspace) {
|
|
228
149
|
const fromRoot = relative(root, directory);
|
|
229
|
-
const fromCargo = relative(
|
|
150
|
+
const fromCargo = relative(cargo.root, directory);
|
|
230
151
|
if (fromRoot !== '..' &&
|
|
231
152
|
!fromRoot.startsWith(`..${sep}`) &&
|
|
232
153
|
!isAbsolute(fromRoot) &&
|
|
@@ -238,17 +159,14 @@ export async function hashCargoPathInputs(manifestPath, workspaceRoot, options)
|
|
|
238
159
|
}
|
|
239
160
|
directories.add(directory);
|
|
240
161
|
files.add(pkg.manifest);
|
|
241
|
-
|
|
242
|
-
// workspaces. Metadata's workspace_root describes only the invoking root.
|
|
243
|
-
const governingManifest = execFileSync('cargo', ['locate-project', '--workspace', '--manifest-path', pkg.manifest, '--message-format', 'plain'], { cwd: root, encoding: 'utf8', stdio: CHILD_STDIO }).trim();
|
|
244
|
-
files.add(await realpath(governingManifest));
|
|
162
|
+
files.add(await governingManifest(cargo, pkg, root));
|
|
245
163
|
packageSources.push(...pkg.sources);
|
|
246
164
|
// A member can inherit edition, lint policy, dependencies and
|
|
247
165
|
// profiles from a workspace above its package directory. Those manifests
|
|
248
166
|
// are not descendants of the source roots returned by Cargo metadata.
|
|
249
167
|
for (let ancestor = dirname(directory); !ancestors.has(ancestor); ancestor = dirname(ancestor)) {
|
|
250
168
|
ancestors.add(ancestor);
|
|
251
|
-
for (const name of
|
|
169
|
+
for (const name of CARGO_ANCESTOR_INPUTS) {
|
|
252
170
|
const file = join(ancestor, name);
|
|
253
171
|
if (statSync(file, { throwIfNoEntry: false })?.isFile())
|
|
254
172
|
files.add(await realpath(file));
|
|
@@ -259,6 +177,7 @@ export async function hashCargoPathInputs(manifestPath, workspaceRoot, options)
|
|
|
259
177
|
for (const source of packageSources)
|
|
260
178
|
if (!ignored(source))
|
|
261
179
|
files.add(source);
|
|
180
|
+
const skipped = new Set(HASH_SKIPPED_DIRECTORIES);
|
|
262
181
|
// Overlapping packages (a facade root plus its child crates) share one walk.
|
|
263
182
|
const visited = new Set();
|
|
264
183
|
async function walk(directory) {
|
|
@@ -267,7 +186,7 @@ export async function hashCargoPathInputs(manifestPath, workspaceRoot, options)
|
|
|
267
186
|
return;
|
|
268
187
|
visited.add(canonical);
|
|
269
188
|
for (const entry of await readdir(canonical, { withFileTypes: true })) {
|
|
270
|
-
if (
|
|
189
|
+
if (skipped.has(entry.name))
|
|
271
190
|
continue;
|
|
272
191
|
const path = join(canonical, entry.name);
|
|
273
192
|
if (ignored(path))
|
|
@@ -313,23 +232,22 @@ export async function hashCargoPathInputs(manifestPath, workspaceRoot, options)
|
|
|
313
232
|
* `directory`, over every dependency kind: a target may build, test or run
|
|
314
233
|
* build scripts, and any of those compiles the edge's source.
|
|
315
234
|
*/
|
|
316
|
-
async function dependencyClosure(
|
|
235
|
+
export async function dependencyClosure(cargo, directory) {
|
|
317
236
|
const base = await realpath(directory);
|
|
318
|
-
const pending = local
|
|
237
|
+
const pending = cargo.local
|
|
319
238
|
.filter((pkg) => pkg.directory === base || pkg.directory.startsWith(`${base}${sep}`))
|
|
320
239
|
.map((pkg) => pkg.id);
|
|
321
240
|
if (pending.length === 0)
|
|
322
241
|
throw new Error(`no local Cargo package lies under ${directory}`);
|
|
323
|
-
if (
|
|
242
|
+
if (cargo.edges === null)
|
|
324
243
|
throw new Error('cargo metadata reported no dependency resolution');
|
|
325
|
-
const edges = new Map(metadata.resolve.nodes.map((node) => [node.id, node.deps]));
|
|
326
244
|
const reached = new Set();
|
|
327
245
|
for (let id = pending.pop(); id !== undefined; id = pending.pop()) {
|
|
328
246
|
if (reached.has(id))
|
|
329
247
|
continue;
|
|
330
248
|
reached.add(id);
|
|
331
|
-
for (const dependency of edges.get(id) ?? [])
|
|
332
|
-
pending.push(dependency
|
|
249
|
+
for (const dependency of cargo.edges.get(id) ?? [])
|
|
250
|
+
pending.push(dependency);
|
|
333
251
|
}
|
|
334
252
|
return reached;
|
|
335
253
|
}
|
|
@@ -104,8 +104,22 @@ export declare const CARGO_FETCH_COMMAND = "cargo fetch --locked";
|
|
|
104
104
|
* or replaying it through --config changes path resolution or precedence.
|
|
105
105
|
* Cargo may serialize registry access on its package-cache lock; these checks
|
|
106
106
|
* are unbounded, and correctness takes priority over overlapping that access.
|
|
107
|
+
*
|
|
108
|
+
* `target/cargo-lint-cross` stays its own directory: a foreign triple's units
|
|
109
|
+
* are distinct anyway, and its own lock keeps the cross check from queueing
|
|
110
|
+
* behind host builds.
|
|
107
111
|
*/
|
|
108
112
|
export declare const CARGO_CROSS_LINT_COMMAND: string;
|
|
113
|
+
/**
|
|
114
|
+
* No `--target-dir`: clippy writes the workspace's own `target/`, beside every
|
|
115
|
+
* dev build. Check units carry their mode in the unit hash, so they never
|
|
116
|
+
* collide with build units, and the host units a dev build already compiled —
|
|
117
|
+
* build scripts and their host-only dependencies — are reused rather than
|
|
118
|
+
* compiled a second time in a directory of their own. A dependency that both
|
|
119
|
+
* a proc-macro and ordinary code use stays a distinct unit: a dev build
|
|
120
|
+
* compiles it once at the target profile, while a check build needs a separate
|
|
121
|
+
* host copy. Distinct hashes coexist, so neither command dirties the other.
|
|
122
|
+
*/
|
|
109
123
|
export declare const CARGO_LINT_CLIPPY_COMMAND: string;
|
|
110
124
|
/** Root `package.json` script name, in the repo's `verb:qualifier` style. */
|
|
111
125
|
export declare const CROSS_CHECK_SCRIPT_NAME = "check:linux";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cross-check-policy.d.ts","sourceRoot":"","sources":["../src/cross-check-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;GAGG;AACH,eAAO,MAAM,kBAAkB,6BAA6B,CAAC;AAE7D;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,gBAAgB,CAAC;AAElD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAI1D;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AAErD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,gBAAgB,CAAC;AAEhD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,yBAAyB,CAAC;AAE1D
|
|
1
|
+
{"version":3,"file":"cross-check-policy.d.ts","sourceRoot":"","sources":["../src/cross-check-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;GAGG;AACH,eAAO,MAAM,kBAAkB,6BAA6B,CAAC;AAE7D;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,gBAAgB,CAAC;AAElD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAI1D;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AAErD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,gBAAgB,CAAC;AAEhD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,yBAAyB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,wBAAwB,QAElC,CAAC;AAEJ;;;;;;;;;GASG;AACH,eAAO,MAAM,yBAAyB,QAAiE,CAAC;AAExG,6EAA6E;AAC7E,eAAO,MAAM,uBAAuB,gBAAgB,CAAC;AAErD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,0BAA0B,2EAAiG,CAAC;AAEzI;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,6DAA6D;AAC7D,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE/D;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEhE;AAID,iFAAiF;AACjF,wBAAgB,qCAAqC,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKvF"}
|
|
@@ -107,9 +107,23 @@ export const CARGO_FETCH_COMMAND = 'cargo fetch --locked';
|
|
|
107
107
|
* or replaying it through --config changes path resolution or precedence.
|
|
108
108
|
* Cargo may serialize registry access on its package-cache lock; these checks
|
|
109
109
|
* are unbounded, and correctness takes priority over overlapping that access.
|
|
110
|
+
*
|
|
111
|
+
* `target/cargo-lint-cross` stays its own directory: a foreign triple's units
|
|
112
|
+
* are distinct anyway, and its own lock keeps the cross check from queueing
|
|
113
|
+
* behind host builds.
|
|
110
114
|
*/
|
|
111
115
|
export const CARGO_CROSS_LINT_COMMAND = `${CARGO_CROSS_LINT_GUARD}; ${cargoFrozen(`clippy --workspace --all-targets --target ${CARGO_LINUX_TRIPLE} --target-dir target/cargo-lint-cross -- -D warnings`)}`;
|
|
112
|
-
|
|
116
|
+
/**
|
|
117
|
+
* No `--target-dir`: clippy writes the workspace's own `target/`, beside every
|
|
118
|
+
* dev build. Check units carry their mode in the unit hash, so they never
|
|
119
|
+
* collide with build units, and the host units a dev build already compiled —
|
|
120
|
+
* build scripts and their host-only dependencies — are reused rather than
|
|
121
|
+
* compiled a second time in a directory of their own. A dependency that both
|
|
122
|
+
* a proc-macro and ordinary code use stays a distinct unit: a dev build
|
|
123
|
+
* compiles it once at the target profile, while a check build needs a separate
|
|
124
|
+
* host copy. Distinct hashes coexist, so neither command dirties the other.
|
|
125
|
+
*/
|
|
126
|
+
export const CARGO_LINT_CLIPPY_COMMAND = cargoFrozen('clippy --workspace --all-targets -- -D warnings');
|
|
113
127
|
/** Root `package.json` script name, in the repo's `verb:qualifier` style. */
|
|
114
128
|
export const CROSS_CHECK_SCRIPT_NAME = 'check:linux';
|
|
115
129
|
/**
|
package/dist/ensure-built.d.ts
CHANGED
|
@@ -52,7 +52,8 @@ export type MissReason = {
|
|
|
52
52
|
* `built` means the work was handed to Nx — which may have restored outputs
|
|
53
53
|
* from the local cache rather than recompiled anything. The line `hit` draws is
|
|
54
54
|
* "did this process have to do work", which is what a CLI wrapper needs in
|
|
55
|
-
* order to decide whether to stay quiet.
|
|
55
|
+
* order to decide whether to stay quiet. A run writes only to stderr: stdout
|
|
56
|
+
* belongs to whatever the caller goes on to run.
|
|
56
57
|
*
|
|
57
58
|
* `failed` is an operational outcome, not an exception: the target ran and did
|
|
58
59
|
* not succeed. A caller re-raises `signal` when there is one and exits with
|
|
@@ -115,7 +116,7 @@ export declare function unvouched<Entry>(entries: readonly Entry[], verdicts: re
|
|
|
115
116
|
* on every invocation. So it never spawns the `nx` CLI: a native filesystem
|
|
116
117
|
* snapshot refreshes the daemon's inputs, the task hashes and on-disk output
|
|
117
118
|
* verification are daemon round-trips, and the cache lookup is a local SQLite
|
|
118
|
-
* read.
|
|
119
|
+
* read. Only a miss starts the workspace's `nx` CLI, to run the target.
|
|
119
120
|
*
|
|
120
121
|
* With the daemon disabled there is no probe to make — hashing would have to
|
|
121
122
|
* build the project graph in this process, and no service holds the recorded
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ensure-built.d.ts","sourceRoot":"","sources":["../src/ensure-built.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,IAAI,EAAa,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"ensure-built.d.ts","sourceRoot":"","sources":["../src/ensure-built.ts"],"names":[],"mappings":"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"}
|
package/dist/ensure-built.js
CHANGED
|
@@ -92,7 +92,7 @@ export function unvouched(entries, verdicts) {
|
|
|
92
92
|
* on every invocation. So it never spawns the `nx` CLI: a native filesystem
|
|
93
93
|
* snapshot refreshes the daemon's inputs, the task hashes and on-disk output
|
|
94
94
|
* verification are daemon round-trips, and the cache lookup is a local SQLite
|
|
95
|
-
* read.
|
|
95
|
+
* read. Only a miss starts the workspace's `nx` CLI, to run the target.
|
|
96
96
|
*
|
|
97
97
|
* With the daemon disabled there is no probe to make — hashing would have to
|
|
98
98
|
* build the project graph in this process, and no service holds the recorded
|
|
@@ -141,7 +141,7 @@ async function ensureBuiltInWorkspace(workspaceRoot, selector, onMiss) {
|
|
|
141
141
|
// this explicit fallback path, which also lets a deliberately minimal
|
|
142
142
|
// checkout-local CLI stand in for Nx.
|
|
143
143
|
if (process.env.NX_DAEMON === 'false') {
|
|
144
|
-
return runViaCli(workspaceRoot, selector);
|
|
144
|
+
return runViaCli(workspaceRoot, selector, { kind: 'no-daemon', taskId: selectorTaskId(selector) });
|
|
145
145
|
}
|
|
146
146
|
// Nx rejects daemon access when the client package's version differs from
|
|
147
147
|
// the workspace's running daemon. Resolve every runtime module from the
|
|
@@ -151,7 +151,7 @@ async function ensureBuiltInWorkspace(workspaceRoot, selector, onMiss) {
|
|
|
151
151
|
bindWorkspaceRoot(workspaceRoot, requireNx);
|
|
152
152
|
const { daemonClient } = requireNx('nx/src/daemon/client/client');
|
|
153
153
|
if (!daemonClient.enabled()) {
|
|
154
|
-
return runViaCli(workspaceRoot, selector);
|
|
154
|
+
return runViaCli(workspaceRoot, selector, { kind: 'no-daemon', taskId: selectorTaskId(selector) });
|
|
155
155
|
}
|
|
156
156
|
// An outer Nx task exports its own cache-bypass setting to the process it
|
|
157
157
|
// launches. That setting describes the outer task, not the nested target:
|
|
@@ -199,32 +199,34 @@ async function ensureBuiltInWorkspace(workspaceRoot, selector, onMiss) {
|
|
|
199
199
|
});
|
|
200
200
|
performance.mark('ensureBuilt:probe:start');
|
|
201
201
|
let reason;
|
|
202
|
-
const selectorTaskId = selector.configuration === undefined
|
|
203
|
-
? `${selector.project}:${selector.target}`
|
|
204
|
-
: `${selector.project}:${selector.target}:${selector.configuration}`;
|
|
205
202
|
if (process.env.NX_SKIP_NX_CACHE === 'true' || process.env.NX_DISABLE_NX_CACHE === 'true') {
|
|
206
|
-
reason = { kind: 'cache-disabled', taskId: selectorTaskId };
|
|
203
|
+
reason = { kind: 'cache-disabled', taskId: selectorTaskId(selector) };
|
|
207
204
|
}
|
|
208
205
|
else if (inputsChanged) {
|
|
209
|
-
reason = { kind: 'stale-inputs', taskId: selectorTaskId };
|
|
206
|
+
reason = { kind: 'stale-inputs', taskId: selectorTaskId(selector) };
|
|
210
207
|
}
|
|
211
208
|
else {
|
|
212
209
|
reason = await probe(workspaceRoot, nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx);
|
|
213
210
|
}
|
|
214
211
|
performance.measure('ensureBuilt:probe', 'ensureBuilt:probe:start');
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
212
|
+
// The CLI runs the hooks around its own run, under its own id. This process
|
|
213
|
+
// ran none of the tasks, so it reports none for the id it opened.
|
|
214
|
+
const result = reason === null ? HIT : await runViaCli(workspaceRoot, selector, reason);
|
|
218
215
|
await hooks.runPostTasksExecution({
|
|
219
216
|
id: runId,
|
|
220
|
-
taskResults:
|
|
217
|
+
taskResults: NO_TASK_RESULTS,
|
|
221
218
|
workspaceRoot,
|
|
222
219
|
nxJsonConfiguration: nxJson,
|
|
223
220
|
argv: process.argv,
|
|
224
221
|
startTime,
|
|
225
222
|
endTime: Date.now(),
|
|
226
223
|
});
|
|
227
|
-
return
|
|
224
|
+
return result;
|
|
225
|
+
}
|
|
226
|
+
function selectorTaskId(selector) {
|
|
227
|
+
return selector.configuration === undefined
|
|
228
|
+
? `${selector.project}:${selector.target}`
|
|
229
|
+
: `${selector.project}:${selector.target}:${selector.configuration}`;
|
|
228
230
|
}
|
|
229
231
|
/**
|
|
230
232
|
* Nx computes `workspaceRoot` once, at module load, from
|
|
@@ -576,56 +578,31 @@ function firstMovedClaim(observed) {
|
|
|
576
578
|
function isSystemError(error) {
|
|
577
579
|
return error instanceof Error && 'code' in error && typeof error.code === 'string';
|
|
578
580
|
}
|
|
579
|
-
async function runTarget(nxJson, nxArgs, overrides, selector, reason, requireNx) {
|
|
580
|
-
const { runCommandForTasks } = requireNx('nx/src/tasks-runner/run-command');
|
|
581
|
-
const { createProjectGraphAsync } = requireNx('nx/src/project-graph/project-graph');
|
|
582
|
-
const { signalToCode } = requireNx('nx/src/utils/exit-codes');
|
|
583
|
-
// `runCommandForTasks` derives its own task graph and hashes, so the probe's
|
|
584
|
-
// work is not reusable. That duplication is one daemon round-trip on a path
|
|
585
|
-
// that is about to run a build.
|
|
586
|
-
const projectGraph = await createProjectGraphAsync();
|
|
587
|
-
const { taskResults, completed } = await runCommandForTasks([requireProject(projectGraph, selector.project)], projectGraph, { nxJson }, nxArgs, overrides, selector.project, {}, { excludeTaskDependencies: false, loadDotEnvFiles: process.env.NX_LOAD_DOT_ENV_FILES !== 'false' });
|
|
588
|
-
if (!completed) {
|
|
589
|
-
// Nx's own encoding of an interrupted run: `runCommand` reports
|
|
590
|
-
// `signalToCode('SIGINT')` here. The runner does not surface which signal
|
|
591
|
-
// actually arrived, so there is none to forward — only the code Nx's CLI
|
|
592
|
-
// would have exited with.
|
|
593
|
-
return {
|
|
594
|
-
result: { disposition: 'failed', reason, exitCode: signalToCode('SIGINT'), signal: null },
|
|
595
|
-
taskResults,
|
|
596
|
-
};
|
|
597
|
-
}
|
|
598
|
-
for (const taskResult of Object.values(taskResults)) {
|
|
599
|
-
if (taskResult.status === 'failure' || taskResult.status === 'skipped') {
|
|
600
|
-
return { result: { disposition: 'failed', reason, exitCode: 1, signal: null }, taskResults };
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
return { result: { disposition: 'built', reason }, taskResults };
|
|
604
|
-
}
|
|
605
581
|
/**
|
|
606
|
-
*
|
|
607
|
-
*
|
|
582
|
+
* Run the target through the workspace's own `nx`, the invocation whose hashes
|
|
583
|
+
* the probe reproduces, with the child's stdout on this process's stderr.
|
|
608
584
|
*
|
|
609
|
-
*
|
|
585
|
+
* A child, because Nx does not only write through `process.stdout`: its Rust
|
|
586
|
+
* pseudo-terminal and the forked executors it starts with inherited stdio
|
|
587
|
+
* write task output straight to file descriptor 1, and Node cannot point that
|
|
588
|
+
* descriptor elsewhere in its own process. In a child it is simply stderr, so
|
|
589
|
+
* the stdout of a wrapper that goes on to exec a binary carries nothing but
|
|
590
|
+
* that binary's output (`<cli> list | jq` reads only data).
|
|
591
|
+
*
|
|
592
|
+
* Inheriting rather than piping is the other half. The wrapper this facility
|
|
610
593
|
* replaces piped Nx's output so it could read a cache marker out of the log and
|
|
611
594
|
* stay silent on a hit — a text heuristic over ANSI-coloured, format-unstable
|
|
612
|
-
* output.
|
|
613
|
-
*
|
|
614
|
-
* child's exit status is forwarded verbatim.
|
|
595
|
+
* output. The probe already decided this is no hit, so the output is the run's
|
|
596
|
+
* own, and the child's exit status is forwarded verbatim.
|
|
615
597
|
*/
|
|
616
|
-
async function runViaCli(workspaceRoot, selector) {
|
|
598
|
+
async function runViaCli(workspaceRoot, selector, reason) {
|
|
617
599
|
const nxCli = join(workspaceRoot, 'node_modules', '.bin', 'nx');
|
|
618
600
|
if (!existsSync(nxCli)) {
|
|
619
|
-
throw new Error(`ensureBuilt:
|
|
620
|
-
}
|
|
621
|
-
const
|
|
622
|
-
const targetSpec = selector.configuration
|
|
623
|
-
? `${selector.project}:${selector.target}:${selector.configuration}`
|
|
624
|
-
: `${selector.project}:${selector.target}`;
|
|
625
|
-
const signalToCode = nxSignalToCode;
|
|
626
|
-
const child = spawn(nxCli, ['run', targetSpec, '--outputStyle=stream'], {
|
|
601
|
+
throw new Error(`ensureBuilt: ${describeMiss(reason)}, and ${nxCli} does not exist`);
|
|
602
|
+
}
|
|
603
|
+
const child = spawn(nxCli, ['run', selectorTaskId(selector), '--outputStyle=stream'], {
|
|
627
604
|
cwd: workspaceRoot,
|
|
628
|
-
stdio: 'inherit',
|
|
605
|
+
stdio: ['inherit', 2, 'inherit'],
|
|
629
606
|
});
|
|
630
607
|
// `Promise.withResolvers` would read better but needs lib es2024; this
|
|
631
608
|
// package inherits lib es2022 from tsconfig.base.json.
|
|
@@ -633,7 +610,7 @@ async function runViaCli(workspaceRoot, selector) {
|
|
|
633
610
|
child.once('error', reject);
|
|
634
611
|
child.once('exit', (code, signal) => settle({ code, signal }));
|
|
635
612
|
});
|
|
636
|
-
return cliExitOutcome(reason, exit,
|
|
613
|
+
return cliExitOutcome(reason, exit, nxSignalToCode);
|
|
637
614
|
}
|
|
638
615
|
function nxSignalToCode(signal) {
|
|
639
616
|
switch (signal) {
|