@smoothbricks/nx-plugin 0.4.21 → 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 +95 -18
- package/dist/bin/smoo-nx-cargo-hash.js +32 -6
- 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 +46 -2
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +238 -114
- 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-cargo-hash.ts +29 -9
- 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 +104 -10
- package/src/cargo-source-hash.ts +290 -37
- 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,99 +1,66 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { execFileSync } from 'node:child_process';
|
|
1
|
+
import { execFile, execFileSync, spawnSync } from 'node:child_process';
|
|
3
2
|
import { createHash } from 'node:crypto';
|
|
4
|
-
import { statSync } from 'node:fs';
|
|
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
|
-
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;
|
|
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'),
|
|
93
46
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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 = [
|
|
97
64
|
'target',
|
|
98
65
|
'.git',
|
|
99
66
|
'node_modules',
|
|
@@ -104,8 +71,9 @@ const ignoredDirectories = new Set([
|
|
|
104
71
|
'.Trashes',
|
|
105
72
|
'.Spotlight-V100',
|
|
106
73
|
'.DocumentRevisions-V100',
|
|
107
|
-
]
|
|
108
|
-
|
|
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'];
|
|
109
77
|
/**
|
|
110
78
|
* Cargo owns resolution, including workspace inheritance, target dependencies,
|
|
111
79
|
* patches, and transitive path dependencies. A locked offline query observes
|
|
@@ -113,34 +81,73 @@ const ancestorInputs = ['Cargo.toml', '.cargo/config', '.cargo/config.toml'];
|
|
|
113
81
|
* registry packages are immutable inputs already identified by Cargo.lock.
|
|
114
82
|
* By default, Nx's in-workspace inputs own workspace packages; includeWorkspace
|
|
115
83
|
* also covers those packages for custom targets without inferred Cargo inputs.
|
|
84
|
+
* `closure` narrows the packages to what the local packages under one
|
|
85
|
+
* directory actually depend on, so an edit to an unrelated workspace member
|
|
86
|
+
* leaves the digest alone.
|
|
116
87
|
*
|
|
117
88
|
* This covers Rust sources and Cargo configuration, matching the plugin's
|
|
118
89
|
* in-workspace Rust inputs. Build scripts' other data/environment inputs remain
|
|
119
|
-
* explicit Nx inputs, just as they are for in-workspace crates.
|
|
90
|
+
* explicit Nx inputs, just as they are for in-workspace crates. Files git
|
|
91
|
+
* ignores beneath a package are left out, like Nx's own file inputs: a
|
|
92
|
+
* generated source is its producer's output, which the consuming target hashes
|
|
93
|
+
* through `dependentTasksOutputFiles`, and a tree that has not generated it yet
|
|
94
|
+
* must hash like one that has.
|
|
120
95
|
*/
|
|
121
96
|
// Nx hashes a runtime input's stdout AND stderr. Cargo reports lock contention
|
|
122
97
|
// on stderr ("Blocking waiting for file lock on package cache") a
|
|
123
98
|
// timing-dependent number of times when Nx hashes many tasks at once, which
|
|
124
99
|
// made one unchanged tree produce four different task hashes per run. Cargo's
|
|
125
|
-
// stderr is kept for the failure path only, where
|
|
126
|
-
// the
|
|
127
|
-
const
|
|
100
|
+
// stderr is kept for the failure path only, where execFile attaches it to the
|
|
101
|
+
// rejected error. Git runs under the same rule.
|
|
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
|
+
}
|
|
128
135
|
export async function hashCargoPathInputs(manifestPath, workspaceRoot, options) {
|
|
129
136
|
const root = await realpath(workspaceRoot);
|
|
130
|
-
const
|
|
131
|
-
const
|
|
137
|
+
const cargo = await readCargoResolve(manifestPath, root);
|
|
138
|
+
const members = options?.closure === undefined ? undefined : await dependencyClosure(cargo, resolve(options.closure));
|
|
132
139
|
const directories = new Set();
|
|
133
140
|
const files = new Set();
|
|
134
141
|
const ancestors = new Set();
|
|
135
142
|
const links = new Map();
|
|
136
|
-
|
|
137
|
-
|
|
143
|
+
const packageSources = [];
|
|
144
|
+
for (const pkg of cargo.local) {
|
|
145
|
+
if (members !== undefined && !members.has(pkg.id))
|
|
138
146
|
continue;
|
|
139
|
-
const
|
|
140
|
-
const directory = dirname(manifest);
|
|
147
|
+
const directory = pkg.directory;
|
|
141
148
|
if (!options?.includeWorkspace) {
|
|
142
149
|
const fromRoot = relative(root, directory);
|
|
143
|
-
const fromCargo = relative(
|
|
150
|
+
const fromCargo = relative(cargo.root, directory);
|
|
144
151
|
if (fromRoot !== '..' &&
|
|
145
152
|
!fromRoot.startsWith(`..${sep}`) &&
|
|
146
153
|
!isAbsolute(fromRoot) &&
|
|
@@ -151,25 +158,26 @@ export async function hashCargoPathInputs(manifestPath, workspaceRoot, options)
|
|
|
151
158
|
continue;
|
|
152
159
|
}
|
|
153
160
|
directories.add(directory);
|
|
154
|
-
files.add(manifest);
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const governingManifest = execFileSync('cargo', ['locate-project', '--workspace', '--manifest-path', manifest, '--message-format', 'plain'], { cwd: root, encoding: 'utf8', stdio: CARGO_STDIO }).trim();
|
|
158
|
-
files.add(await realpath(governingManifest));
|
|
159
|
-
for (const target of pkg.targets)
|
|
160
|
-
files.add(await realpath(target.src_path));
|
|
161
|
+
files.add(pkg.manifest);
|
|
162
|
+
files.add(await governingManifest(cargo, pkg, root));
|
|
163
|
+
packageSources.push(...pkg.sources);
|
|
161
164
|
// A member can inherit edition, lint policy, dependencies and
|
|
162
165
|
// profiles from a workspace above its package directory. Those manifests
|
|
163
166
|
// are not descendants of the source roots returned by Cargo metadata.
|
|
164
167
|
for (let ancestor = dirname(directory); !ancestors.has(ancestor); ancestor = dirname(ancestor)) {
|
|
165
168
|
ancestors.add(ancestor);
|
|
166
|
-
for (const name of
|
|
169
|
+
for (const name of CARGO_ANCESTOR_INPUTS) {
|
|
167
170
|
const file = join(ancestor, name);
|
|
168
171
|
if (statSync(file, { throwIfNoEntry: false })?.isFile())
|
|
169
172
|
files.add(await realpath(file));
|
|
170
173
|
}
|
|
171
174
|
}
|
|
172
175
|
}
|
|
176
|
+
const ignored = gitIgnoredBeneath([...directories]);
|
|
177
|
+
for (const source of packageSources)
|
|
178
|
+
if (!ignored(source))
|
|
179
|
+
files.add(source);
|
|
180
|
+
const skipped = new Set(HASH_SKIPPED_DIRECTORIES);
|
|
173
181
|
// Overlapping packages (a facade root plus its child crates) share one walk.
|
|
174
182
|
const visited = new Set();
|
|
175
183
|
async function walk(directory) {
|
|
@@ -178,9 +186,11 @@ export async function hashCargoPathInputs(manifestPath, workspaceRoot, options)
|
|
|
178
186
|
return;
|
|
179
187
|
visited.add(canonical);
|
|
180
188
|
for (const entry of await readdir(canonical, { withFileTypes: true })) {
|
|
181
|
-
if (
|
|
189
|
+
if (skipped.has(entry.name))
|
|
182
190
|
continue;
|
|
183
191
|
const path = join(canonical, entry.name);
|
|
192
|
+
if (ignored(path))
|
|
193
|
+
continue;
|
|
184
194
|
if (entry.isSymbolicLink())
|
|
185
195
|
links.set(path, await readlink(path));
|
|
186
196
|
const info = entry.isSymbolicLink() ? await lstat(await realpath(path)) : entry;
|
|
@@ -217,3 +227,117 @@ export async function hashCargoPathInputs(manifestPath, workspaceRoot, options)
|
|
|
217
227
|
}
|
|
218
228
|
return hash.digest('hex');
|
|
219
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* The ids Cargo's resolve graph reaches from the local packages under
|
|
232
|
+
* `directory`, over every dependency kind: a target may build, test or run
|
|
233
|
+
* build scripts, and any of those compiles the edge's source.
|
|
234
|
+
*/
|
|
235
|
+
export async function dependencyClosure(cargo, directory) {
|
|
236
|
+
const base = await realpath(directory);
|
|
237
|
+
const pending = cargo.local
|
|
238
|
+
.filter((pkg) => pkg.directory === base || pkg.directory.startsWith(`${base}${sep}`))
|
|
239
|
+
.map((pkg) => pkg.id);
|
|
240
|
+
if (pending.length === 0)
|
|
241
|
+
throw new Error(`no local Cargo package lies under ${directory}`);
|
|
242
|
+
if (cargo.edges === null)
|
|
243
|
+
throw new Error('cargo metadata reported no dependency resolution');
|
|
244
|
+
const reached = new Set();
|
|
245
|
+
for (let id = pending.pop(); id !== undefined; id = pending.pop()) {
|
|
246
|
+
if (reached.has(id))
|
|
247
|
+
continue;
|
|
248
|
+
reached.add(id);
|
|
249
|
+
for (const dependency of cargo.edges.get(id) ?? [])
|
|
250
|
+
pending.push(dependency);
|
|
251
|
+
}
|
|
252
|
+
return reached;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Whether git ignores a path beneath one of the package directories. A
|
|
256
|
+
* package whose own directory is ignored (an installed dependency, say) keeps
|
|
257
|
+
* every file, and a directory outside any git repository ignores nothing.
|
|
258
|
+
*/
|
|
259
|
+
function gitIgnoredBeneath(directories) {
|
|
260
|
+
const byRepository = new Map();
|
|
261
|
+
for (const directory of directories) {
|
|
262
|
+
const repository = gitRepository(directory);
|
|
263
|
+
if (repository === undefined)
|
|
264
|
+
continue;
|
|
265
|
+
const members = byRepository.get(repository) ?? [];
|
|
266
|
+
members.push(directory);
|
|
267
|
+
byRepository.set(repository, members);
|
|
268
|
+
}
|
|
269
|
+
const files = new Set();
|
|
270
|
+
const trees = [];
|
|
271
|
+
for (const [repository, members] of byRepository) {
|
|
272
|
+
const relativeMembers = members.map((member) => relative(repository, member) || '.');
|
|
273
|
+
// A package whose own directory git ignores is an installed tree, not a source tree with
|
|
274
|
+
// generated files in it. It also stays out of ls-files, which fails outright on a pathspec
|
|
275
|
+
// inside an ignored directory ("directory entry not superset of prefix").
|
|
276
|
+
const ignoredRoots = new Set(gitCheckIgnore(repository, relativeMembers));
|
|
277
|
+
const sourceRoots = relativeMembers.filter((member) => !ignoredRoots.has(member));
|
|
278
|
+
if (sourceRoots.length === 0)
|
|
279
|
+
continue;
|
|
280
|
+
const installed = [...ignoredRoots].map((member) => join(repository, member));
|
|
281
|
+
const listing = execFileSync('git', [
|
|
282
|
+
'--literal-pathspecs',
|
|
283
|
+
'-C',
|
|
284
|
+
repository,
|
|
285
|
+
'ls-files',
|
|
286
|
+
'-z',
|
|
287
|
+
'--others',
|
|
288
|
+
'--ignored',
|
|
289
|
+
'--exclude-standard',
|
|
290
|
+
'--directory',
|
|
291
|
+
'--',
|
|
292
|
+
...sourceRoots,
|
|
293
|
+
], { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, stdio: CHILD_STDIO });
|
|
294
|
+
for (const entry of listing.split('\0')) {
|
|
295
|
+
if (entry.length === 0)
|
|
296
|
+
continue;
|
|
297
|
+
const path = join(repository, entry);
|
|
298
|
+
if (!entry.endsWith('/')) {
|
|
299
|
+
files.add(path);
|
|
300
|
+
}
|
|
301
|
+
else if (!installed.some((member) => member === path || member.startsWith(`${path}${sep}`))) {
|
|
302
|
+
// An ignored directory holding a nested installed package leaves that package whole.
|
|
303
|
+
trees.push(path);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return (path) => files.has(path) || trees.some((tree) => path === tree || path.startsWith(`${tree}${sep}`));
|
|
308
|
+
}
|
|
309
|
+
/** The members of `paths` (relative to `repository`) that git ignores, own patterns or an ancestor's. */
|
|
310
|
+
function gitCheckIgnore(repository, paths) {
|
|
311
|
+
const result = spawnSync('git', ['-C', repository, 'check-ignore', '-z', '--stdin'], {
|
|
312
|
+
input: `${paths.join('\0')}\0`,
|
|
313
|
+
encoding: 'utf8',
|
|
314
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
315
|
+
});
|
|
316
|
+
// check-ignore answers 1 when nothing is ignored; only 0 carries a listing.
|
|
317
|
+
if (result.status === 1)
|
|
318
|
+
return [];
|
|
319
|
+
if (result.status !== 0) {
|
|
320
|
+
throw new Error(`git check-ignore in ${repository} failed (${result.status ?? result.signal}): ${result.stderr}`);
|
|
321
|
+
}
|
|
322
|
+
return result.stdout.split('\0').filter((path) => path.length > 0);
|
|
323
|
+
}
|
|
324
|
+
/** The canonical top level of the git work tree holding `directory`, or undefined outside any repository. */
|
|
325
|
+
function gitRepository(directory) {
|
|
326
|
+
try {
|
|
327
|
+
// The walk compares realpaths, so git's answer is canonicalized the same way.
|
|
328
|
+
return realpathSync(execFileSync('git', ['-C', directory, 'rev-parse', '--show-toplevel'], {
|
|
329
|
+
encoding: 'utf8',
|
|
330
|
+
stdio: CHILD_STDIO,
|
|
331
|
+
}).trim());
|
|
332
|
+
}
|
|
333
|
+
catch (error) {
|
|
334
|
+
if (typeof error === 'object' &&
|
|
335
|
+
error !== null &&
|
|
336
|
+
'status' in error &&
|
|
337
|
+
error.status === 128 &&
|
|
338
|
+
'stderr' in error &&
|
|
339
|
+
String(error.stderr).includes('not a git repository'))
|
|
340
|
+
return undefined;
|
|
341
|
+
throw error;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
@@ -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;;;;;;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;;;;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":"AAUA,OAAO,KAAK,EAAE,IAAI,EAAa,MAAM,0BAA0B,CAAC;AAiDhE;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5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