@smoothbricks/nx-plugin 0.4.28 → 0.4.30
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 +277 -89
- package/dist/bin/smoo-nx-test-clocks.d.ts +3 -0
- package/dist/bin/smoo-nx-test-clocks.d.ts.map +1 -0
- package/dist/bin/smoo-nx-test-clocks.js +28 -0
- package/dist/bounded-test-policy.d.ts +8 -8
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +18 -30
- package/dist/cargo-closure-input.d.ts +23 -0
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +41 -9
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +42 -19
- package/dist/ensure-built-receipt.d.ts +40 -6
- package/dist/ensure-built-receipt.d.ts.map +1 -1
- package/dist/ensure-built-receipt.js +297 -159
- package/dist/ensure-built-witness.d.ts +65 -4
- package/dist/ensure-built-witness.d.ts.map +1 -1
- package/dist/ensure-built-witness.js +2237 -23
- package/dist/ensure-built.d.ts +99 -1
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +45 -56
- package/dist/executors/bounded-exec/cpu-pool.d.ts +22 -7
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool.js +51 -22
- package/dist/executors/bounded-exec/executor.d.ts +12 -3
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +174 -51
- package/dist/executors/bounded-exec/no-space.d.ts +8 -0
- package/dist/executors/bounded-exec/no-space.d.ts.map +1 -0
- package/dist/executors/bounded-exec/no-space.js +31 -0
- package/dist/executors/bounded-exec/ram-temp.d.ts +20 -11
- package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
- package/dist/executors/bounded-exec/ram-temp.js +42 -17
- package/dist/executors/bounded-exec/verdict.d.ts +34 -4
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.js +54 -3
- package/dist/generators/bun-test-tracing/generator.js +2 -2
- package/dist/graph-input-contract.d.ts +102 -0
- package/dist/graph-input-contract.d.ts.map +1 -0
- package/dist/graph-input-contract.js +637 -0
- package/dist/index.d.ts +12 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -3
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +5 -2
- package/dist/managed-files/publish-workflow.d.ts +11 -1
- package/dist/managed-files/publish-workflow.d.ts.map +1 -1
- package/dist/owned-installation.d.ts +14 -0
- package/dist/owned-installation.d.ts.map +1 -0
- package/dist/owned-installation.js +324 -0
- package/dist/producer-receipts.d.ts +19 -0
- package/dist/producer-receipts.d.ts.map +1 -0
- package/dist/producer-receipts.js +926 -0
- package/dist/test-backstop.d.ts +9 -0
- package/dist/test-backstop.d.ts.map +1 -0
- package/dist/test-backstop.js +10 -0
- package/dist/test-clock-policy.d.ts +30 -0
- package/dist/test-clock-policy.d.ts.map +1 -0
- package/dist/test-clock-policy.js +686 -0
- package/dist/testing.d.ts +8 -0
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +66 -1
- package/managed/raw/patches/nx@23.2.1.patch +328 -50
- package/managed/raw/tooling/direnv/developer-links.ts +148 -29
- package/managed/raw/tooling/direnv/devenv.smoo.nix +7 -7
- package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -5
- package/managed/raw/tooling/direnv/linked-snapshots.ts +206 -40
- package/managed/raw/tooling/direnv/repo-path +15 -2
- package/managed/raw/tooling/direnv/setup-environment.ts +179 -115
- package/managed/templates/github/actions/cache-node-modules/action.yml +9 -0
- package/managed/templates/github/actions/setup-devenv/action.yml +63 -7
- package/nextest.toml +1 -1
- package/package.json +25 -9
- package/src/__tests__/cargo-closure-fixture.ts +113 -0
- package/src/__tests__/counted-cargo.ts +8 -25
- package/src/__tests__/directory-change.ts +27 -0
- package/src/__tests__/fixture-nx-env.ts +7 -0
- package/src/__tests__/owned-installation.ts +14 -0
- package/src/__tests__/past-tick.ts +12 -0
- package/src/bin/smoo-nx-bound-failures.test.ts +1 -1
- package/src/bin/smoo-nx-test-clocks.ts +29 -0
- package/src/bounded-test-policy.test.ts +36 -22
- package/src/bounded-test-policy.ts +18 -32
- package/src/bun-bootstrap.test.ts +1 -1
- package/src/cargo-closure-input.property.test.ts +50 -0
- package/src/cargo-closure-input.test.ts +73 -121
- package/src/cargo-closure-input.ts +47 -8
- package/src/cargo-closure-key.test.ts +239 -0
- package/src/cargo-resolve-cache.test.ts +168 -31
- package/src/cargo-source-hash.test.ts +78 -3
- package/src/cargo-source-hash.ts +48 -30
- package/src/cross-check-policy.test.ts +2 -2
- package/src/ensure-built-receipt.test.ts +111 -16
- package/src/ensure-built-receipt.ts +294 -149
- package/src/ensure-built-witness.test.ts +306 -13
- package/src/ensure-built-witness.ts +255 -24
- package/src/ensure-built.test.ts +228 -102
- package/src/ensure-built.ts +127 -66
- package/src/executors/bounded-exec/cpu-pool.test.ts +134 -32
- package/src/executors/bounded-exec/cpu-pool.ts +64 -20
- package/src/executors/bounded-exec/cpu-tokens.test.ts +2 -2
- package/src/executors/bounded-exec/disk-lease.test.ts +47 -13
- package/src/executors/bounded-exec/executor-host.test.ts +74 -52
- package/src/executors/bounded-exec/executor.test.ts +343 -97
- package/src/executors/bounded-exec/executor.ts +192 -56
- package/src/executors/bounded-exec/hang-diagnostics.test.ts +14 -8
- package/src/executors/bounded-exec/no-space.ts +40 -0
- package/src/executors/bounded-exec/progress.test.ts +1 -1
- package/src/executors/bounded-exec/ram-temp-host.test.ts +51 -21
- package/src/executors/bounded-exec/ram-temp.test.ts +92 -16
- package/src/executors/bounded-exec/ram-temp.ts +49 -20
- package/src/executors/bounded-exec/verdict.test.ts +127 -22
- package/src/executors/bounded-exec/verdict.ts +78 -3
- package/src/generators/bounded-test-targets/generator.test.ts +1 -3
- package/src/generators/bun-test-tracing/generator.test.ts +2 -2
- package/src/generators/bun-test-tracing/generator.ts +2 -2
- package/src/graph-input-contract.test.ts +379 -0
- package/src/graph-input-contract.ts +627 -0
- package/src/index.test.ts +3 -3
- package/src/index.ts +24 -3
- package/src/linked-snapshots.nx.test.ts +112 -30
- package/src/managed-files/ci-workflow.ts +5 -2
- package/src/managed-files/publish-workflow.ts +12 -1
- package/src/managed-files/repo-path.test.ts +44 -1
- package/src/managed-files/setup-devenv-free-disk.test.ts +95 -0
- package/src/nextest-code-bound.test.ts +23 -17
- package/src/nextest-extraction.test.ts +114 -4
- package/src/nextest-partitions.test.ts +7 -1
- package/src/nx-cache-restore-mtime.test.ts +2 -2
- package/src/nx-daemon-claim.test.ts +10 -8
- package/src/nx-daemon-idle-cpu.test.ts +0 -1
- package/src/nx-daemon-idle-policy.test.ts +61 -1
- package/src/nx-daemon-ignore-files.test.ts +2 -2
- package/src/nx-daemon-validity.test.ts +36 -22
- package/src/nx-dot-input-policy.test.ts +5 -5
- package/src/nx-files-archive-racy.test.ts +1 -1
- package/src/nx-incomplete-run-summary.test.ts +1 -1
- package/src/nx-plugin-load-errors.test.ts +2 -2
- package/src/nx-project-graph-errors.test.ts +70 -0
- package/src/nx-skipped-task-exit.test.ts +2 -2
- package/src/nx-store-resolution.test.ts +7 -25
- package/src/nx-task-output-lease.test.ts +3 -3
- package/src/nx-use-local.test.ts +7 -5
- package/src/owned-installation.ts +174 -0
- package/src/producer-receipts.test.ts +164 -0
- package/src/producer-receipts.ts +636 -0
- package/src/runtime-input.test.ts +1 -1
- package/src/serial-group-wiring.test.ts +4 -4
- package/src/task-results.test.ts +18 -16
- package/src/test-backstop.ts +11 -0
- package/src/test-clock-policy.test.ts +338 -0
- package/src/test-clock-policy.ts +708 -0
- package/src/test-timings.test.ts +2 -2
- package/src/testing.test.ts +5 -5
- package/src/testing.ts +67 -1
- package/src/typecheck-test-policy.test.ts +1 -1
- package/src/typescript-resolution.test.ts +76 -0
- package/test-timings.json +8 -0
|
@@ -12,18 +12,78 @@ import {
|
|
|
12
12
|
rmSync,
|
|
13
13
|
writeFileSync,
|
|
14
14
|
} from 'node:fs';
|
|
15
|
-
import {
|
|
15
|
+
import { createRequire } from 'node:module';
|
|
16
|
+
import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
16
17
|
import type { NxJsonConfiguration } from 'nx/src/config/nx-json';
|
|
17
18
|
import type { ProjectGraph } from 'nx/src/config/project-graph';
|
|
18
|
-
import type { FileData, WorkspaceContext } from 'nx/src/native';
|
|
19
|
-
import type { readModulePackageJsonWithoutFallbacks } from 'nx/src/utils/package-json';
|
|
19
|
+
import type { expandOutputs, FileData, WorkspaceContext } from 'nx/src/native';
|
|
20
|
+
import type { PackageJson, readModulePackageJsonWithoutFallbacks } from 'nx/src/utils/package-json';
|
|
20
21
|
import typia from 'typia';
|
|
22
|
+
import type { GraphInputContractProof } from './graph-input-contract.js';
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
interface InstalledPackageManifest {
|
|
25
|
+
readonly path: string;
|
|
26
|
+
readonly packageJson: PackageJson;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The stat fields a node's identity is read from. */
|
|
30
|
+
export type StampFields = Pick<BigIntStats, 'dev' | 'ino' | 'mode' | 'size' | 'mtimeNs' | 'ctimeNs'>;
|
|
31
|
+
|
|
32
|
+
/** The stamp a node reads as now: device, inode, mode, size, mtime and ctime. What a recorded stamp is compared with. */
|
|
33
|
+
export function nodeStamp(stats: StampFields): string {
|
|
24
34
|
return `${stats.dev}:${stats.ino}:${stats.mode}:${stats.size}:${stats.mtimeNs}:${stats.ctimeNs}`;
|
|
25
35
|
}
|
|
26
36
|
|
|
37
|
+
/**
|
|
38
|
+
* How an observed stamp compares with the recorded one: `same`; `ctime` when device, inode, mode, size and mtime are
|
|
39
|
+
* kept and only the ctime moved (a same-mode chmod, which Bun's bin linking does to a shared store file on any
|
|
40
|
+
* checkout's install) or was recorded `unproven` ({@link recordedStamp}); otherwise `moved`. A function of the two
|
|
41
|
+
* stamps alone, so no filesystem or clock decides it.
|
|
42
|
+
*/
|
|
43
|
+
export function stampMove(recorded: string, observed: string): 'same' | 'ctime' | 'moved' {
|
|
44
|
+
if (observed === recorded) return 'same';
|
|
45
|
+
// nodeStamp ends with the ctime: everything before it is the identity a same-mode chmod keeps.
|
|
46
|
+
const kept = observed.slice(0, observed.lastIndexOf(':')) === recorded.slice(0, recorded.lastIndexOf(':'));
|
|
47
|
+
return kept ? 'ctime' : 'moved';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* How long after a node's last change a stamp read of it proves nothing about the next change: git's racily clean
|
|
52
|
+
* rule (git's Documentation/technical/racy-git.txt), which the Nx archive repair already applies to Nx's own file
|
|
53
|
+
* hashes (patches/README.md). A filesystem dates a change by the kernel's clock. On Linux, on a filesystem without
|
|
54
|
+
* fine-grained timestamps such as ZFS, that is the coarse clock, which moves once a jiffy: 1 ms at CONFIG_HZ=1000, as
|
|
55
|
+
* on CI's runner, and 10 ms at CONFIG_HZ=100, the slowest. A same-size rewrite in the tick a stamp was read in leaves
|
|
56
|
+
* every field of it as it was. Node can read neither the jiffy nor a filesystem's granularity, and a shorter window
|
|
57
|
+
* reopens the gap on a slower kernel, so this is the slowest tick, and no option.
|
|
58
|
+
*/
|
|
59
|
+
export const SAME_TICK_NS = 10_000_000n;
|
|
60
|
+
|
|
61
|
+
/** The time a census starts, read before its first stat: what {@link unproven} judges each node's change by. */
|
|
62
|
+
export function censusStart(): bigint {
|
|
63
|
+
return BigInt(Date.now()) * 1_000_000n;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Whether a census that started at `start` read a node within {@link SAME_TICK_NS} of its last change (the later of
|
|
68
|
+
* its ctime and mtime, so a node dated ahead counts). Its stamp is then unproven, not unchanged: a rewrite in the same
|
|
69
|
+
* tick could leave it as it is.
|
|
70
|
+
*/
|
|
71
|
+
export function unproven(stats: StampFields, start: bigint): boolean {
|
|
72
|
+
return start - (stats.ctimeNs > stats.mtimeNs ? stats.ctimeNs : stats.mtimeNs) < SAME_TICK_NS;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The stamp a census that started at `start` records for a later reader: its {@link nodeStamp}, or, when that is
|
|
77
|
+
* {@link unproven}, the same with its ctime recorded as `unproven`. No stamp read later equals that, so the reader
|
|
78
|
+
* re-reads the node rather than trust the stamp, as it does a node whose ctime alone moved ({@link stampMove}), or
|
|
79
|
+
* counts it moved when it holds nothing to re-read it against. Only such a node costs a re-read.
|
|
80
|
+
*/
|
|
81
|
+
export function recordedStamp(stats: StampFields, start: bigint): string {
|
|
82
|
+
return unproven(stats, start)
|
|
83
|
+
? `${stats.dev}:${stats.ino}:${stats.mode}:${stats.size}:${stats.mtimeNs}:unproven`
|
|
84
|
+
: nodeStamp(stats);
|
|
85
|
+
}
|
|
86
|
+
|
|
27
87
|
export interface NodeWitness {
|
|
28
88
|
readonly path: string;
|
|
29
89
|
readonly stamp: string;
|
|
@@ -68,36 +128,44 @@ export function writeWitness(path: string, value: GraphWitness | ArtifactWitness
|
|
|
68
128
|
* Nx's Unix archive uses whole-second mtimes, so allFileData alone cannot
|
|
69
129
|
* prove an immediate same-second rewrite. An unbound archive hash is never
|
|
70
130
|
* admitted: on the first capture every file is rehashed through Nx itself.
|
|
131
|
+
* The nodes are recorded for later captures and readers (recordedStamp), so a
|
|
132
|
+
* node this capture read in the tick it changed in is rehashed by the next.
|
|
71
133
|
*/
|
|
72
134
|
export function workspaceSnapshot(
|
|
73
135
|
workspaceRoot: string,
|
|
74
136
|
context: WorkspaceContext,
|
|
75
137
|
previous: WorkspaceSnapshot | undefined,
|
|
76
138
|
): WorkspaceSnapshot {
|
|
139
|
+
const start = censusStart();
|
|
77
140
|
const files = context.allFileData();
|
|
78
141
|
const prior = new Map(previous?.nodes.map((node) => [node.path, node.stamp]));
|
|
79
142
|
const nodes: NodeWitness[] = [];
|
|
143
|
+
// What this capture read of each node it records unproven: its own stability check compares what it read.
|
|
144
|
+
const read = new Map<string, string>();
|
|
80
145
|
const changed: string[] = [];
|
|
81
146
|
let complete = true;
|
|
147
|
+
function record(path: string, stats: BigIntStats): string {
|
|
148
|
+
const stamp = nodeStamp(stats);
|
|
149
|
+
if (unproven(stats, start)) read.set(path, stamp);
|
|
150
|
+
nodes.push({ path, stamp: read.has(path) ? recordedStamp(stats, start) : stamp });
|
|
151
|
+
return stamp;
|
|
152
|
+
}
|
|
82
153
|
for (const { file } of files) {
|
|
83
154
|
const path = join(workspaceRoot, file);
|
|
84
155
|
const stats = lstatSync(path, { bigint: true });
|
|
85
|
-
|
|
86
|
-
nodes.push(node);
|
|
87
|
-
let moved = prior.get(path) !== node.stamp;
|
|
156
|
+
let moved = prior.get(path) !== record(path, stats);
|
|
88
157
|
if (stats.isSymbolicLink()) {
|
|
89
158
|
const physical = realpathSync(path);
|
|
90
159
|
const targetStats = lstatSync(physical, { bigint: true });
|
|
91
|
-
|
|
92
|
-
nodes.push(target);
|
|
93
|
-
moved ||= prior.get(physical) !== target.stamp;
|
|
160
|
+
moved ||= prior.get(physical) !== record(physical, targetStats);
|
|
94
161
|
// A file table does not prove the membership of an external directory.
|
|
95
162
|
if (!targetStats.isFile()) complete = false;
|
|
96
163
|
}
|
|
97
164
|
if (moved) changed.push(file);
|
|
98
165
|
}
|
|
99
166
|
if (changed.length > 0) context.incrementalUpdate(changed, []);
|
|
100
|
-
|
|
167
|
+
const asRead = read.size === 0 ? nodes : nodes.map(({ path, stamp }) => ({ path, stamp: read.get(path) ?? stamp }));
|
|
168
|
+
return { files: context.allFileData(), nodes, stable: complete && nodesUnchanged(asRead) };
|
|
101
169
|
}
|
|
102
170
|
|
|
103
171
|
export function nodesUnchanged(nodes: readonly NodeWitness[]): boolean {
|
|
@@ -112,6 +180,32 @@ export function nodesUnchanged(nodes: readonly NodeWitness[]): boolean {
|
|
|
112
180
|
return true;
|
|
113
181
|
}
|
|
114
182
|
|
|
183
|
+
/**
|
|
184
|
+
* The witnessed nodes whose stamp is no longer the one read, named for a refusal (the first eight in witness order, a
|
|
185
|
+
* gone one with its error code, and how many more), or null when none moved. A node whose device, inode, mode, size
|
|
186
|
+
* and mtime are unchanged and only its ctime moved (a same-mode chmod, which Bun's bin linking does to a shared store
|
|
187
|
+
* file on any checkout's install), or whose ctime was recorded unproven ({@link recordedStamp}), asks for a comparison,
|
|
188
|
+
* not a verdict: `same` re-reads it, and one it finds as recorded has not changed. Without `same` every move counts.
|
|
189
|
+
*/
|
|
190
|
+
export function movedNodes(
|
|
191
|
+
nodes: readonly NodeWitness[],
|
|
192
|
+
same: (path: string) => boolean = () => false,
|
|
193
|
+
): string | null {
|
|
194
|
+
const moved: string[] = [];
|
|
195
|
+
for (const node of nodes) {
|
|
196
|
+
try {
|
|
197
|
+
const move = stampMove(node.stamp, nodeStamp(lstatSync(node.path, { bigint: true })));
|
|
198
|
+
if (move === 'same') continue;
|
|
199
|
+
if (move === 'moved' || !same(node.path)) moved.push(node.path);
|
|
200
|
+
} catch (error) {
|
|
201
|
+
if (!systemError(error)) throw error;
|
|
202
|
+
moved.push(`${node.path} (${error.code})`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (moved.length === 0) return null;
|
|
206
|
+
return `${moved.slice(0, 8).join(', ')}${moved.length > 8 ? ` and ${moved.length - 8} more` : ''}`;
|
|
207
|
+
}
|
|
208
|
+
|
|
115
209
|
/** Membership and content are exact. Outputs do not exempt manifests or
|
|
116
210
|
* newly created/deleted files; this graph witness has no output exclusions.
|
|
117
211
|
*/
|
|
@@ -139,6 +233,15 @@ export function reusableGraph(
|
|
|
139
233
|
: null;
|
|
140
234
|
}
|
|
141
235
|
|
|
236
|
+
/** What {@link graphInstallationIdentity} binds: resolution edges `[from, name, physical manifest]`, node stamps and
|
|
237
|
+
* file hashes, read once.
|
|
238
|
+
*/
|
|
239
|
+
export interface GraphInstallationCensus {
|
|
240
|
+
readonly resolutions: readonly (readonly [string, string, string | null])[];
|
|
241
|
+
readonly nodes: readonly NodeWitness[];
|
|
242
|
+
readonly files: readonly { readonly path: string; readonly sha256: string }[];
|
|
243
|
+
}
|
|
244
|
+
|
|
142
245
|
/** Plugins with opaque external graph inputs cannot borrow this proof.
|
|
143
246
|
* For the repository plugin and Nx, bind the entire owned module/file tree
|
|
144
247
|
* and its dependency/optional/peer resolution closure, including each alias,
|
|
@@ -150,16 +253,63 @@ export function graphInstallationIdentity(
|
|
|
150
253
|
workspaceRoot: string,
|
|
151
254
|
nxJson: NxJsonConfiguration,
|
|
152
255
|
resolvePackage: typeof readModulePackageJsonWithoutFallbacks,
|
|
256
|
+
expand: typeof expandOutputs,
|
|
257
|
+
localInputs: GraphInputContractProof | null,
|
|
258
|
+
onUnproved?: (detail: string) => void,
|
|
153
259
|
): string | null {
|
|
260
|
+
const census = graphInstallationCensus(workspaceRoot, nxJson, resolvePackage, expand, localInputs, onUnproved);
|
|
261
|
+
if (census === null) return null;
|
|
262
|
+
try {
|
|
263
|
+
// A file whose ctime alone moved is re-hashed: Bun's bin linking on any checkout's install re-chmods a shared
|
|
264
|
+
// store file to the mode it already has (movedNodes).
|
|
265
|
+
const hashes = new Map(census.files.map(({ path, sha256 }) => [path, sha256]));
|
|
266
|
+
const moved = movedNodes(
|
|
267
|
+
census.nodes,
|
|
268
|
+
(path) => hashes.get(path) === createHash('sha256').update(readFileSync(path)).digest('hex'),
|
|
269
|
+
);
|
|
270
|
+
if (moved !== null) {
|
|
271
|
+
onUnproved?.(`Installed module node changed during inspection: ${moved}`);
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
} catch (error) {
|
|
275
|
+
if (systemError(error) && ['EACCES', 'EPERM', 'EIO'].includes(error.code)) throw error;
|
|
276
|
+
if (error instanceof Error) {
|
|
277
|
+
onUnproved?.(error.message);
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
throw error;
|
|
281
|
+
}
|
|
282
|
+
return JSON.stringify({ ...census, localInputs: localInputs?.identity ?? null });
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** One read of the installation closure {@link graphInstallationIdentity} binds, without its final check that no node
|
|
286
|
+
* moved while it was read: what a caller that needs the closure, not a proof of it, reads. `null`, with `onUnproved`
|
|
287
|
+
* told why, for a closure that cannot be read.
|
|
288
|
+
*/
|
|
289
|
+
export function graphInstallationCensus(
|
|
290
|
+
workspaceRoot: string,
|
|
291
|
+
nxJson: NxJsonConfiguration,
|
|
292
|
+
resolvePackage: typeof readModulePackageJsonWithoutFallbacks,
|
|
293
|
+
expand: typeof expandOutputs,
|
|
294
|
+
localInputs: GraphInputContractProof | null,
|
|
295
|
+
onUnproved?: (detail: string) => void,
|
|
296
|
+
): GraphInstallationCensus | null {
|
|
154
297
|
const plugins = (nxJson.plugins ?? []).map((plugin) => (typeof plugin === 'string' ? plugin : plugin.plugin));
|
|
155
|
-
|
|
298
|
+
const unproved = plugins.filter(
|
|
299
|
+
(plugin) => plugin !== '@smoothbricks/nx-plugin' && !localInputs?.plugins.includes(plugin),
|
|
300
|
+
);
|
|
301
|
+
if (unproved.length > 0) {
|
|
302
|
+
onUnproved?.(`Unproved configured graph plugins: ${unproved.join(', ')}`);
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
156
305
|
const nodes: NodeWitness[] = [];
|
|
157
306
|
const files: { path: string; sha256: string }[] = [];
|
|
158
307
|
const buffer = Buffer.allocUnsafe(64 * 1024);
|
|
159
308
|
const resolutions: [string, string, string | null][] = [];
|
|
160
309
|
const visited = new Set<string>();
|
|
161
310
|
const declaredDirectoryLinks = new Set<string>();
|
|
162
|
-
|
|
311
|
+
const expandedRoots = new Set<string>();
|
|
312
|
+
function walk(path: string, selected?: ReadonlySet<string>): void {
|
|
163
313
|
const stats = lstatSync(path, { bigint: true });
|
|
164
314
|
nodes.push({ path, stamp: nodeStamp(stats) });
|
|
165
315
|
if (stats.isSymbolicLink()) {
|
|
@@ -169,8 +319,16 @@ export function graphInstallationIdentity(
|
|
|
169
319
|
}
|
|
170
320
|
walk(physical);
|
|
171
321
|
} else if (stats.isDirectory()) {
|
|
322
|
+
const visible = expandedRoots.has(path) ? undefined : selected;
|
|
172
323
|
for (const name of readdirSync(path).sort()) {
|
|
173
|
-
|
|
324
|
+
const child = join(path, name);
|
|
325
|
+
if (
|
|
326
|
+
name !== 'node_modules' &&
|
|
327
|
+
name !== '.git' &&
|
|
328
|
+
name !== '.nx' &&
|
|
329
|
+
(visible === undefined || visible.has(child))
|
|
330
|
+
)
|
|
331
|
+
walk(child, visible);
|
|
174
332
|
}
|
|
175
333
|
} else if (!stats.isFile()) {
|
|
176
334
|
throw new Error(`Unproved graph package node: ${path}`);
|
|
@@ -187,10 +345,29 @@ export function graphInstallationIdentity(
|
|
|
187
345
|
files.push({ path, sha256: hash.digest('hex') });
|
|
188
346
|
}
|
|
189
347
|
}
|
|
348
|
+
function installedManifest(name: string, from: string): InstalledPackageManifest {
|
|
349
|
+
try {
|
|
350
|
+
return resolvePackage(name, [from]);
|
|
351
|
+
} catch (original) {
|
|
352
|
+
if (systemError(original) && ['EACCES', 'EPERM', 'EIO'].includes(original.code)) throw original;
|
|
353
|
+
// A package may expose only subpaths: its dependency declaration still owns its installed manifest and files.
|
|
354
|
+
for (const directory of createRequire(join(from, 'package.json')).resolve.paths(name) ?? []) {
|
|
355
|
+
const path = join(directory, name, 'package.json');
|
|
356
|
+
try {
|
|
357
|
+
const packageJson = typia.json.assertParse<PackageJson>(readFileSync(path, 'utf8'));
|
|
358
|
+
return { path, packageJson };
|
|
359
|
+
} catch (error) {
|
|
360
|
+
if (systemError(error) && ['ENOENT', 'ENOTDIR'].includes(error.code)) continue;
|
|
361
|
+
throw error;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
throw original;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
190
367
|
function visit(name: string, from: string, optional: boolean): void {
|
|
191
|
-
let resolved:
|
|
368
|
+
let resolved: InstalledPackageManifest;
|
|
192
369
|
try {
|
|
193
|
-
resolved =
|
|
370
|
+
resolved = installedManifest(name, from);
|
|
194
371
|
} catch (error) {
|
|
195
372
|
if (optional && systemError(error) && error.code === 'MODULE_NOT_FOUND') {
|
|
196
373
|
resolutions.push([from, name, null]);
|
|
@@ -204,10 +381,59 @@ export function graphInstallationIdentity(
|
|
|
204
381
|
visited.add(physical);
|
|
205
382
|
const packageRoot = dirname(physical);
|
|
206
383
|
const manifest = resolved.packageJson;
|
|
207
|
-
//
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
384
|
+
// Explicit publication owns this tree; unknown declarations keep the conservative full census.
|
|
385
|
+
if (manifest.files !== undefined && manifest.files.length > 0) {
|
|
386
|
+
const patterns = manifest.files.map((pattern) => {
|
|
387
|
+
const negative = pattern.startsWith('!');
|
|
388
|
+
const relativePattern = (negative ? pattern.slice(1) : pattern).replace(/^\/+/u, '') || '.';
|
|
389
|
+
return negative ? `!${relativePattern}` : relativePattern;
|
|
390
|
+
});
|
|
391
|
+
const declared = new Set<string>();
|
|
392
|
+
const literal = (pattern: string) => !/[*?[\]{}]/u.test(pattern);
|
|
393
|
+
const validate = (entry: string) => {
|
|
394
|
+
if (isAbsolute(entry) || entry.split(/[\\/]/u).includes('..'))
|
|
395
|
+
throw new Error(`Published graph package path escapes its owner: ${entry}`);
|
|
396
|
+
};
|
|
397
|
+
const addDeclaration = (entry: string) => {
|
|
398
|
+
validate(entry);
|
|
399
|
+
if (literal(entry)) {
|
|
400
|
+
const absolute = resolve(packageRoot, entry);
|
|
401
|
+
declared.add(absolute);
|
|
402
|
+
declaredDirectoryLinks.add(absolute);
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
for (const pattern of patterns) {
|
|
406
|
+
validate(pattern.startsWith('!') ? pattern.slice(1) : pattern);
|
|
407
|
+
if (!pattern.startsWith('!')) addDeclaration(pattern);
|
|
408
|
+
}
|
|
409
|
+
const exported = (value: unknown): void => {
|
|
410
|
+
if (typeof value === 'string') {
|
|
411
|
+
if (value.startsWith('./')) {
|
|
412
|
+
patterns.push(value);
|
|
413
|
+
addDeclaration(value);
|
|
414
|
+
}
|
|
415
|
+
} else if (Array.isArray(value)) {
|
|
416
|
+
for (const entry of value) exported(entry);
|
|
417
|
+
} else if (typeof value === 'object' && value !== null) {
|
|
418
|
+
for (const entry of Object.values(value)) exported(entry);
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
exported(manifest.exports);
|
|
422
|
+
const selected = new Set<string>([packageRoot]);
|
|
423
|
+
const select = (entry: string) => {
|
|
424
|
+
validate(entry);
|
|
425
|
+
for (let path = resolve(packageRoot, entry); path !== packageRoot; path = dirname(path)) selected.add(path);
|
|
426
|
+
};
|
|
427
|
+
select('package.json');
|
|
428
|
+
for (const path of declared) select(relative(packageRoot, path));
|
|
429
|
+
for (const path of expand(packageRoot, patterns)) {
|
|
430
|
+
select(path);
|
|
431
|
+
expandedRoots.add(resolve(packageRoot, path));
|
|
432
|
+
}
|
|
433
|
+
walk(packageRoot, selected);
|
|
434
|
+
} else {
|
|
435
|
+
walk(packageRoot);
|
|
436
|
+
}
|
|
211
437
|
const dependencies = { ...manifest.peerDependencies, ...manifest.dependencies, ...manifest.optionalDependencies };
|
|
212
438
|
for (const dependency of Object.keys(dependencies).sort()) {
|
|
213
439
|
visit(
|
|
@@ -219,14 +445,19 @@ export function graphInstallationIdentity(
|
|
|
219
445
|
}
|
|
220
446
|
}
|
|
221
447
|
try {
|
|
222
|
-
for (const name of ['nx', ...plugins
|
|
448
|
+
for (const name of ['nx', ...plugins.filter((plugin) => plugin === '@smoothbricks/nx-plugin')])
|
|
449
|
+
visit(name, workspaceRoot, false);
|
|
450
|
+
for (const input of localInputs?.packages ?? []) visit(input.name, input.from, false);
|
|
223
451
|
visit('typescript', workspaceRoot, true);
|
|
224
|
-
return
|
|
452
|
+
return { resolutions, nodes, files };
|
|
225
453
|
} catch (error) {
|
|
226
454
|
if (systemError(error) && ['EACCES', 'EPERM', 'EIO'].includes(error.code)) throw error;
|
|
227
455
|
// Installation uncertainty disables only graph reuse. Nx's authoritative
|
|
228
456
|
// RPC remains responsible for diagnosing invalid plugin installations.
|
|
229
|
-
if (error instanceof Error)
|
|
457
|
+
if (error instanceof Error) {
|
|
458
|
+
onUnproved?.(error.message);
|
|
459
|
+
return null;
|
|
460
|
+
}
|
|
230
461
|
throw error;
|
|
231
462
|
}
|
|
232
463
|
}
|