@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.
Files changed (64) hide show
  1. package/README.md +95 -18
  2. package/dist/bin/smoo-nx-cargo-hash.js +32 -6
  3. package/dist/bin/smoo-nx-exec.js +35 -11
  4. package/dist/cargo-closure-input.d.ts +63 -0
  5. package/dist/cargo-closure-input.d.ts.map +1 -0
  6. package/dist/cargo-closure-input.js +197 -0
  7. package/dist/cargo-source-hash.d.ts +46 -2
  8. package/dist/cargo-source-hash.d.ts.map +1 -1
  9. package/dist/cargo-source-hash.js +238 -114
  10. package/dist/cross-check-policy.d.ts +14 -0
  11. package/dist/cross-check-policy.d.ts.map +1 -1
  12. package/dist/cross-check-policy.js +15 -1
  13. package/dist/ensure-built.d.ts +3 -2
  14. package/dist/ensure-built.d.ts.map +1 -1
  15. package/dist/ensure-built.js +33 -56
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +112 -76
  18. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  19. package/dist/managed-files/ci-workflow.js +12 -15
  20. package/dist/managed-files/files.d.ts.map +1 -1
  21. package/dist/managed-files/files.js +10 -0
  22. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  23. package/dist/managed-files/publish-workflow.js +12 -6
  24. package/dist/manifest-hash.d.ts.map +1 -1
  25. package/dist/manifest-hash.js +24 -30
  26. package/dist/package-target-policy.js +1 -1
  27. package/dist/platform-targets.d.ts +7 -0
  28. package/dist/platform-targets.d.ts.map +1 -1
  29. package/dist/platform-targets.js +7 -0
  30. package/dist/workspace-config-policy.d.ts +1 -1
  31. package/dist/workspace-config-policy.d.ts.map +1 -1
  32. package/dist/workspace-config-policy.js +1 -1
  33. package/managed/raw/envrc +38 -1
  34. package/managed/raw/tooling/direnv/developer-links.ts +201 -0
  35. package/managed/raw/tooling/direnv/devenv.smoo.nix +75 -51
  36. package/managed/raw/tooling/direnv/secret-references.ts +3 -1
  37. package/managed/raw/tooling/direnv/setup-environment.ts +562 -78
  38. package/managed/raw/tooling/direnv/shared-caches.sh +53 -0
  39. package/managed/raw/tooling/git-hooks/pre-push.sh +22 -1
  40. package/managed/templates/github/workflows/managed-files.yml +4 -3
  41. package/nextest.toml +5 -5
  42. package/package.json +2 -2
  43. package/src/__tests__/fixture-nx-env.ts +31 -0
  44. package/src/__tests__/in-process-nx-index.ts +9 -0
  45. package/src/bin/smoo-nx-cargo-hash.ts +29 -9
  46. package/src/bin/smoo-nx-exec.ts +40 -11
  47. package/src/cargo-closure-input.test.ts +184 -0
  48. package/src/cargo-closure-input.ts +247 -0
  49. package/src/cargo-source-hash.test.ts +104 -10
  50. package/src/cargo-source-hash.ts +290 -37
  51. package/src/cross-check-policy.ts +15 -3
  52. package/src/ensure-built.test.ts +65 -5
  53. package/src/ensure-built.ts +40 -85
  54. package/src/index.test.ts +94 -53
  55. package/src/index.ts +164 -84
  56. package/src/managed-files/ci-workflow.ts +12 -15
  57. package/src/managed-files/files.ts +10 -0
  58. package/src/managed-files/generator.test.ts +29 -0
  59. package/src/managed-files/publish-workflow.ts +17 -6
  60. package/src/manifest-hash.test.ts +21 -1
  61. package/src/manifest-hash.ts +26 -29
  62. package/src/package-target-policy.ts +1 -1
  63. package/src/platform-targets.ts +8 -0
  64. package/src/workspace-config-policy.ts +6 -1
@@ -1,99 +1,66 @@
1
- import * as _assertGuard_1 from "typia/lib/internal/_assertGuard";
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
- 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;
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
- return (input, errorFactory) => __assert(JSON.parse(input), errorFactory);
95
- })();
96
- const ignoredDirectories = new Set([
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
- const ancestorInputs = ['Cargo.toml', '.cargo/config', '.cargo/config.toml'];
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 execFileSync attaches it to
126
- // the thrown error.
127
- const CARGO_STDIO = ['ignore', 'pipe', 'pipe'];
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 metadata = parseMetadata(execFileSync('cargo', ['metadata', '--format-version', '1', '--locked', '--offline', '--manifest-path', resolve(manifestPath)], { cwd: root, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, stdio: CARGO_STDIO }));
131
- const cargoRoot = await realpath(metadata.workspace_root);
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
- for (const pkg of metadata.packages) {
137
- if (pkg.source !== null)
143
+ const packageSources = [];
144
+ for (const pkg of cargo.local) {
145
+ if (members !== undefined && !members.has(pkg.id))
138
146
  continue;
139
- const manifest = await realpath(pkg.manifest_path);
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(cargoRoot, directory);
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
- // Cargo resolves explicit package.workspace ownership as well as ancestor
156
- // workspaces. Metadata's workspace_root describes only the invoking root.
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 ancestorInputs) {
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 (ignoredDirectories.has(entry.name))
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;;;;;;;;;;;;;;;;;;;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;;;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EJ;;;;;;;;;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
- export const CARGO_LINT_CLIPPY_COMMAND = cargoFrozen('clippy --workspace --all-targets --target-dir target/cargo-lint -- -D warnings');
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
  /**
@@ -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. Nx's task runner is only invoked once something needs running.
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;AAqDhE;;;;;;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;CAC5C;AAED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