zedbee 0.1.0-beta.17 → 0.1.0-beta.18

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 (193) hide show
  1. package/dist/cache/captured-dependencies.d.ts +24 -1
  2. package/dist/cache/captured-dependencies.d.ts.map +1 -1
  3. package/dist/cache/captured-dependencies.js +146 -25
  4. package/dist/cache/captured-dependencies.js.map +1 -1
  5. package/dist/cache/dependency-inputs.d.ts +3 -1
  6. package/dist/cache/dependency-inputs.d.ts.map +1 -1
  7. package/dist/cache/dependency-inputs.js +7 -3
  8. package/dist/cache/dependency-inputs.js.map +1 -1
  9. package/dist/checks/adapter.d.ts +1 -0
  10. package/dist/checks/adapter.d.ts.map +1 -1
  11. package/dist/checks/comparison-context.d.ts +3 -1
  12. package/dist/checks/comparison-context.d.ts.map +1 -1
  13. package/dist/checks/comparison-context.js +122 -7
  14. package/dist/checks/comparison-context.js.map +1 -1
  15. package/dist/checks/compiler-change-inputs.d.ts +12 -0
  16. package/dist/checks/compiler-change-inputs.d.ts.map +1 -0
  17. package/dist/checks/compiler-change-inputs.js +104 -0
  18. package/dist/checks/compiler-change-inputs.js.map +1 -0
  19. package/dist/checks/compiler-inputs.d.ts.map +1 -1
  20. package/dist/checks/compiler-inputs.js +47 -18
  21. package/dist/checks/compiler-inputs.js.map +1 -1
  22. package/dist/checks/dispatch-cache.d.ts.map +1 -1
  23. package/dist/checks/dispatch-cache.js +9 -0
  24. package/dist/checks/dispatch-cache.js.map +1 -1
  25. package/dist/checks/dispatch-context.d.ts.map +1 -1
  26. package/dist/checks/dispatch-context.js +1 -0
  27. package/dist/checks/dispatch-context.js.map +1 -1
  28. package/dist/checks/dispatch-target.d.ts.map +1 -1
  29. package/dist/checks/dispatch-target.js +36 -5
  30. package/dist/checks/dispatch-target.js.map +1 -1
  31. package/dist/checks/dispatcher.d.ts.map +1 -1
  32. package/dist/checks/dispatcher.js +20 -7
  33. package/dist/checks/dispatcher.js.map +1 -1
  34. package/dist/checks/engine-identity.js +5 -5
  35. package/dist/checks/engine-identity.js.map +1 -1
  36. package/dist/checks/incomplete-error.d.ts +3 -0
  37. package/dist/checks/incomplete-error.d.ts.map +1 -1
  38. package/dist/checks/incomplete-error.js +4 -0
  39. package/dist/checks/incomplete-error.js.map +1 -1
  40. package/dist/checks/incomplete-result.d.ts +1 -0
  41. package/dist/checks/incomplete-result.d.ts.map +1 -1
  42. package/dist/checks/incomplete-result.js +3 -0
  43. package/dist/checks/incomplete-result.js.map +1 -1
  44. package/dist/checks/installation-diagnostic.d.ts +11 -0
  45. package/dist/checks/installation-diagnostic.d.ts.map +1 -0
  46. package/dist/checks/installation-diagnostic.js +71 -0
  47. package/dist/checks/installation-diagnostic.js.map +1 -0
  48. package/dist/checks/prettier/settings.d.ts +2 -2
  49. package/dist/checks/project-inputs.d.ts.map +1 -1
  50. package/dist/checks/project-inputs.js +3 -3
  51. package/dist/checks/project-inputs.js.map +1 -1
  52. package/dist/checks/react/adapter.d.ts.map +1 -1
  53. package/dist/checks/react/adapter.js +14 -3
  54. package/dist/checks/react/adapter.js.map +1 -1
  55. package/dist/checks/runner/envelope.d.ts.map +1 -1
  56. package/dist/checks/runner/envelope.js +1 -0
  57. package/dist/checks/runner/envelope.js.map +1 -1
  58. package/dist/checks/runner/worker.js +3 -0
  59. package/dist/checks/runner/worker.js.map +1 -1
  60. package/dist/checks/sanitize-result.d.ts +1 -0
  61. package/dist/checks/sanitize-result.d.ts.map +1 -1
  62. package/dist/checks/sanitize-result.js +7 -0
  63. package/dist/checks/sanitize-result.js.map +1 -1
  64. package/dist/checks/structural-security/adapter.d.ts.map +1 -1
  65. package/dist/checks/structural-security/adapter.js +35 -55
  66. package/dist/checks/structural-security/adapter.js.map +1 -1
  67. package/dist/checks/structural-security/parse-failures.d.ts +6 -0
  68. package/dist/checks/structural-security/parse-failures.d.ts.map +1 -0
  69. package/dist/checks/structural-security/parse-failures.js +76 -0
  70. package/dist/checks/structural-security/parse-failures.js.map +1 -0
  71. package/dist/checks/structural-security/parser.d.ts +18 -0
  72. package/dist/checks/structural-security/parser.d.ts.map +1 -0
  73. package/dist/checks/structural-security/parser.js +96 -0
  74. package/dist/checks/structural-security/parser.js.map +1 -0
  75. package/dist/checks/structural-security/rules.d.ts.map +1 -1
  76. package/dist/checks/structural-security/rules.js +67 -113
  77. package/dist/checks/structural-security/rules.js.map +1 -1
  78. package/dist/checks/typescript/compiler-host.d.ts.map +1 -1
  79. package/dist/checks/typescript/compiler-host.js +68 -49
  80. package/dist/checks/typescript/compiler-host.js.map +1 -1
  81. package/dist/checks/typescript/compiler-scope-graph.d.ts +11 -0
  82. package/dist/checks/typescript/compiler-scope-graph.d.ts.map +1 -0
  83. package/dist/checks/typescript/compiler-scope-graph.js +694 -0
  84. package/dist/checks/typescript/compiler-scope-graph.js.map +1 -0
  85. package/dist/checks/typescript/compiler-scope-inputs.d.ts +20 -0
  86. package/dist/checks/typescript/compiler-scope-inputs.d.ts.map +1 -0
  87. package/dist/checks/typescript/compiler-scope-inputs.js +183 -0
  88. package/dist/checks/typescript/compiler-scope-inputs.js.map +1 -0
  89. package/dist/checks/typescript/config.d.ts +3 -0
  90. package/dist/checks/typescript/config.d.ts.map +1 -1
  91. package/dist/checks/typescript/config.js +2 -2
  92. package/dist/checks/typescript/config.js.map +1 -1
  93. package/dist/checks/typescript/configuration-paths.d.ts +3 -2
  94. package/dist/checks/typescript/configuration-paths.d.ts.map +1 -1
  95. package/dist/checks/typescript/configuration-paths.js +67 -12
  96. package/dist/checks/typescript/configuration-paths.js.map +1 -1
  97. package/dist/checks/typescript/convert-diagnostic.d.ts +1 -2
  98. package/dist/checks/typescript/convert-diagnostic.d.ts.map +1 -1
  99. package/dist/checks/typescript/convert-diagnostic.js +2 -16
  100. package/dist/checks/typescript/convert-diagnostic.js.map +1 -1
  101. package/dist/checks/typescript/diagnostic-message.d.ts +3 -0
  102. package/dist/checks/typescript/diagnostic-message.d.ts.map +1 -0
  103. package/dist/checks/typescript/diagnostic-message.js +18 -0
  104. package/dist/checks/typescript/diagnostic-message.js.map +1 -0
  105. package/dist/checks/typescript/project-coverage.d.ts.map +1 -1
  106. package/dist/checks/typescript/project-coverage.js +3 -2
  107. package/dist/checks/typescript/project-coverage.js.map +1 -1
  108. package/dist/checks/typescript/reuse-inputs.d.ts +3 -0
  109. package/dist/checks/typescript/reuse-inputs.d.ts.map +1 -1
  110. package/dist/checks/typescript/reuse-inputs.js +14 -4
  111. package/dist/checks/typescript/reuse-inputs.js.map +1 -1
  112. package/dist/cli.d.ts.map +1 -1
  113. package/dist/cli.js +2 -0
  114. package/dist/cli.js.map +1 -1
  115. package/dist/commands/diagnostics.d.ts +1 -0
  116. package/dist/commands/diagnostics.d.ts.map +1 -1
  117. package/dist/commands/diagnostics.js +7 -1
  118. package/dist/commands/diagnostics.js.map +1 -1
  119. package/dist/commands/scan.d.ts +1 -0
  120. package/dist/commands/scan.d.ts.map +1 -1
  121. package/dist/commands/scan.js +27 -3
  122. package/dist/commands/scan.js.map +1 -1
  123. package/dist/config/schema.d.ts +6 -6
  124. package/dist/core/types.d.ts +14 -0
  125. package/dist/core/types.d.ts.map +1 -1
  126. package/dist/diagnostics/local-scan-diagnostics.d.ts +12 -0
  127. package/dist/diagnostics/local-scan-diagnostics.d.ts.map +1 -0
  128. package/dist/diagnostics/local-scan-diagnostics.js +138 -0
  129. package/dist/diagnostics/local-scan-diagnostics.js.map +1 -0
  130. package/dist/diagnostics/scan-performance.d.ts +2 -0
  131. package/dist/diagnostics/scan-performance.d.ts.map +1 -1
  132. package/dist/diagnostics/scan-performance.js +22 -20
  133. package/dist/diagnostics/scan-performance.js.map +1 -1
  134. package/dist/doctor/diagnostics.d.ts.map +1 -1
  135. package/dist/doctor/diagnostics.js +22 -3
  136. package/dist/doctor/diagnostics.js.map +1 -1
  137. package/dist/doctor/workspace-installation.d.ts +9 -0
  138. package/dist/doctor/workspace-installation.d.ts.map +1 -0
  139. package/dist/doctor/workspace-installation.js +165 -0
  140. package/dist/doctor/workspace-installation.js.map +1 -0
  141. package/dist/hooks/detect.d.ts +4 -0
  142. package/dist/hooks/detect.d.ts.map +1 -1
  143. package/dist/hooks/detect.js +5 -4
  144. package/dist/hooks/detect.js.map +1 -1
  145. package/dist/hooks/update-notice.d.ts +5 -0
  146. package/dist/hooks/update-notice.d.ts.map +1 -0
  147. package/dist/hooks/update-notice.js +145 -0
  148. package/dist/hooks/update-notice.js.map +1 -0
  149. package/dist/init/presentation.d.ts +2 -2
  150. package/dist/renderers/incomplete.d.ts +5 -1
  151. package/dist/renderers/incomplete.d.ts.map +1 -1
  152. package/dist/renderers/incomplete.js +29 -2
  153. package/dist/renderers/incomplete.js.map +1 -1
  154. package/dist/renderers/json.d.ts.map +1 -1
  155. package/dist/renderers/json.js +20 -3
  156. package/dist/renderers/json.js.map +1 -1
  157. package/dist/renderers/sarif.d.ts.map +1 -1
  158. package/dist/renderers/sarif.js +7 -0
  159. package/dist/renderers/sarif.js.map +1 -1
  160. package/dist/renderers/text.d.ts.map +1 -1
  161. package/dist/renderers/text.js +16 -0
  162. package/dist/renderers/text.js.map +1 -1
  163. package/dist/reporting/agent-guidance.d.ts.map +1 -1
  164. package/dist/reporting/agent-guidance.js +7 -0
  165. package/dist/reporting/agent-guidance.js.map +1 -1
  166. package/dist/reporting/fix-presentation.d.ts +1 -1
  167. package/dist/reporting/hook-update-notice.d.ts +12 -0
  168. package/dist/reporting/hook-update-notice.d.ts.map +1 -0
  169. package/dist/reporting/hook-update-notice.js +13 -0
  170. package/dist/reporting/hook-update-notice.js.map +1 -0
  171. package/dist/scan/report.d.ts +6 -0
  172. package/dist/scan/report.d.ts.map +1 -1
  173. package/dist/scan/run-scan.d.ts.map +1 -1
  174. package/dist/scan/run-scan.js +17 -8
  175. package/dist/scan/run-scan.js.map +1 -1
  176. package/dist/service/server-connection.d.ts.map +1 -1
  177. package/dist/service/server-connection.js +2 -1
  178. package/dist/service/server-connection.js.map +1 -1
  179. package/dist/telemetry/schema.d.ts +45 -45
  180. package/dist/telemetry/state.d.ts +5 -5
  181. package/dist/ui/incomplete-list.d.ts.map +1 -1
  182. package/dist/ui/incomplete-list.js +4 -2
  183. package/dist/ui/incomplete-list.js.map +1 -1
  184. package/dist/ui/scan-result-dashboard.d.ts.map +1 -1
  185. package/dist/ui/scan-result-dashboard.js +7 -3
  186. package/dist/ui/scan-result-dashboard.js.map +1 -1
  187. package/docs/checks.md +19 -9
  188. package/docs/cli-reference.md +7 -1
  189. package/docs/privacy.md +2 -0
  190. package/docs/react-analysis.md +7 -0
  191. package/docs/reporting.md +8 -0
  192. package/docs/support.md +19 -0
  193. package/package.json +1 -1
@@ -0,0 +1,694 @@
1
+ import { setImmediate as yieldTurn } from "node:timers/promises";
2
+ import { builtinModules } from "node:module";
3
+ import { createHash } from "node:crypto";
4
+ import { dirname, resolve, relative, sep, isAbsolute } from "node:path";
5
+ import { CapturedDependencies, } from "../../cache/captured-dependencies.js";
6
+ import { captureSnapshotRegistry } from "../../inspection/snapshot-registry.js";
7
+ import { readContainedFile } from "../../inspection/read-json.js";
8
+ import { classifyCompilerChanges } from "../compiler-change-inputs.js";
9
+ import { CheckIncompleteError } from "../incomplete-error.js";
10
+ import { loadCompilerScopeInputs } from "./compiler-scope-inputs.js";
11
+ const owners = new WeakMap();
12
+ // A proof may temporarily own a full dependency capture. Serialize acquisition
13
+ // and cap retained witness metadata separately, below the reuse owner's budget.
14
+ let activeProof = false;
15
+ const waiting = [];
16
+ async function acquire(signal, run) {
17
+ signal?.throwIfAborted();
18
+ await new Promise((accept, reject) => {
19
+ const start = () => {
20
+ signal?.removeEventListener("abort", cancel);
21
+ activeProof = true;
22
+ accept();
23
+ };
24
+ const cancel = () => {
25
+ const index = waiting.indexOf(start);
26
+ if (index !== -1)
27
+ waiting.splice(index, 1);
28
+ reject(signal.reason);
29
+ };
30
+ if (!activeProof)
31
+ start();
32
+ else {
33
+ waiting.push(start);
34
+ signal?.addEventListener("abort", cancel, { once: true });
35
+ }
36
+ });
37
+ try {
38
+ signal?.throwIfAborted();
39
+ return await run();
40
+ }
41
+ finally {
42
+ activeProof = false;
43
+ waiting.shift()?.();
44
+ }
45
+ }
46
+ class ProofLimit extends Error {
47
+ }
48
+ class SnapshotLookup extends Error {
49
+ path;
50
+ constructor(path) {
51
+ super("Uninventoried resolution input");
52
+ this.path = path;
53
+ }
54
+ }
55
+ const hash = (text) => createHash("sha256").update(text).digest("hex");
56
+ const unknown = {
57
+ independent: false,
58
+ reason: "unknown",
59
+ };
60
+ function within(root, path) {
61
+ const part = relative(root, path);
62
+ return (part === "" ||
63
+ (!isAbsolute(part) && part !== ".." && !part.startsWith(`..${sep}`)));
64
+ }
65
+ async function read(root, path, limit, signal) {
66
+ signal?.throwIfAborted();
67
+ const registry = await captureSnapshotRegistry(root, [path]);
68
+ if (registry.entries().some((e) => e.kind === "symlink"))
69
+ throw Error("Unsupported proof input");
70
+ const text = await readContainedFile(registry, path, { maxBytes: limit });
71
+ signal?.throwIfAborted();
72
+ return text;
73
+ }
74
+ async function valid(record, signal) {
75
+ signal?.throwIfAborted();
76
+ if (!CapturedDependencies.validate(record.manifest, record.context))
77
+ return false;
78
+ for (const w of record.witnesses) {
79
+ if (w.digest === undefined) {
80
+ const registry = await captureSnapshotRegistry(w.root, [w.path]);
81
+ signal?.throwIfAborted();
82
+ if (registry.entries().some((e) => e.kind === "symlink"))
83
+ return false;
84
+ if (w.directory
85
+ ? registry.resolve(w.path)?.targetKind !== "directory"
86
+ : registry.resolve(w.path) !== undefined)
87
+ return false;
88
+ }
89
+ else if (hash(await read(w.root, w.path, w.limit, signal)) !== w.digest)
90
+ return false;
91
+ }
92
+ signal?.throwIfAborted();
93
+ return true;
94
+ }
95
+ /** Required after analyzer work, before allowing any result based on a skip. */
96
+ export async function validateCompilerScopeProofs(context) {
97
+ const signal = context.signal;
98
+ const owner = owners.get(context.targetInspection);
99
+ if (!owner)
100
+ return;
101
+ if (owner.invalidated)
102
+ throw new CheckIncompleteError({
103
+ code: "COMPARISON_INPUTS_CHANGED",
104
+ message: "Inputs used to select compiler checks changed during this scan.",
105
+ remediation: "Wait for dependency installation or file updates to finish, then rerun the scan.",
106
+ });
107
+ for (const record of owner.records.values()) {
108
+ let verified = false;
109
+ try {
110
+ verified = await valid(record, signal);
111
+ }
112
+ catch {
113
+ signal?.throwIfAborted();
114
+ }
115
+ if (!verified)
116
+ throw new CheckIncompleteError({
117
+ code: "COMPARISON_INPUTS_CHANGED",
118
+ message: "Inputs used to select compiler checks changed during this scan.",
119
+ remediation: "Wait for dependency installation or file updates to finish, then rerun the scan.",
120
+ });
121
+ }
122
+ }
123
+ export function releaseCompilerScopeProofs(context) {
124
+ owners.delete(context.targetInspection);
125
+ }
126
+ function identity(owner, value) {
127
+ let id = owner.ids.get(value);
128
+ if (id === undefined) {
129
+ id = owner.next++;
130
+ owner.ids.set(value, id);
131
+ }
132
+ return id;
133
+ }
134
+ export async function proveCompilerWorkspaceIndependence(context, workspace) {
135
+ context.signal?.throwIfAborted();
136
+ if (context.mergeComparison ||
137
+ context.config.checks.lint.when === "always" ||
138
+ context.config.checks.types.when === "always" ||
139
+ context.config.checks.lint.engine === "project")
140
+ return unknown;
141
+ const changes = await classifyCompilerChanges(context);
142
+ if (!changes.complete ||
143
+ changes.requiresBroadComparison ||
144
+ changes.sourcePaths.size === 0)
145
+ return unknown;
146
+ const prefix = workspace.relativeRoot === "." ? "" : `${workspace.relativeRoot}/`;
147
+ if ([...changes.sourcePaths].some((path) => path.startsWith(prefix)))
148
+ return { independent: false, reason: "changed-input" };
149
+ return acquire(context.signal, async () => {
150
+ context.signal?.throwIfAborted();
151
+ let owner = owners.get(context.targetInspection);
152
+ if (owner === undefined) {
153
+ owner = {
154
+ records: new Map(),
155
+ bytes: 0,
156
+ ids: new WeakMap(),
157
+ next: 0,
158
+ invalidated: false,
159
+ };
160
+ owners.set(context.targetInspection, owner);
161
+ }
162
+ const key = owner === undefined
163
+ ? undefined
164
+ : JSON.stringify([
165
+ identity(owner, context.baselineInspection),
166
+ identity(owner, context.targetInspection),
167
+ identity(owner, context.changeSet),
168
+ workspace.relativeRoot,
169
+ context.repositoryRoot,
170
+ ]);
171
+ const previous = key === undefined ? undefined : owner?.records.get(key);
172
+ if (previous !== undefined) {
173
+ try {
174
+ if (await valid(previous, context.signal))
175
+ return { independent: true, reason: "disjoint-inputs" };
176
+ }
177
+ catch {
178
+ context.signal?.throwIfAborted();
179
+ }
180
+ owner.invalidated = true;
181
+ owner.records.delete(key);
182
+ owner.bytes -= JSON.stringify(previous).length * 2;
183
+ }
184
+ try {
185
+ const dependencyContext = { repositoryRoot: context.repositoryRoot };
186
+ const dependencies = new CapturedDependencies(dependencyContext);
187
+ const captured = (operation) => {
188
+ if (dependencies.failure() !== undefined)
189
+ throw Error("Incomplete proof capture");
190
+ const value = operation();
191
+ if (dependencies.failure() !== undefined)
192
+ throw Error("Incomplete proof capture");
193
+ return value;
194
+ };
195
+ const witnesses = [];
196
+ const signatures = [];
197
+ let edges = 0;
198
+ const charge = (count = 1) => {
199
+ edges += count;
200
+ if (edges > 4096)
201
+ throw new ProofLimit();
202
+ };
203
+ const librarySeen = new Set();
204
+ const ts = await import("typescript");
205
+ for (const inspection of [
206
+ context.baselineInspection,
207
+ context.targetInspection,
208
+ ]) {
209
+ context.signal?.throwIfAborted();
210
+ if (inspection.workspaces.length > 32)
211
+ return { independent: false, reason: "limit" };
212
+ const side = inspection.workspaces.find((w) => w.relativeRoot === workspace.relativeRoot);
213
+ if (side === undefined)
214
+ return unknown;
215
+ const inputs = await loadCompilerScopeInputs(inspection, side, context.signal);
216
+ if (!inputs.complete)
217
+ return {
218
+ independent: false,
219
+ reason: inputs.reason === "limit" ? "limit" : "unknown",
220
+ };
221
+ const texts = new Map(), signature = new Map();
222
+ let textBytes = 0;
223
+ const add = async (path, limit) => {
224
+ const remaining = Math.floor((8 * 1024 * 1024 - textBytes) / 2);
225
+ if (remaining <= 0)
226
+ throw new Error("Proof text limit");
227
+ const text = await read(inspection.snapshotRoot, path, Math.min(limit, remaining), context.signal);
228
+ textBytes += text.length * 2;
229
+ texts.set(resolve(inspection.snapshotRoot, path), text);
230
+ signature.set(path, hash(text));
231
+ witnesses.push({
232
+ root: inspection.snapshotRoot,
233
+ path,
234
+ digest: hash(text),
235
+ limit,
236
+ });
237
+ return text;
238
+ };
239
+ for (const path of inputs.inputPaths)
240
+ await add(path, side.sourceFiles.includes(path) ? 1024 * 1024 : 64 * 1024);
241
+ // The production host can see all captured repository source files. Resolve
242
+ // their names too; an edge outside this workspace prevents narrowing.
243
+ const inventory = new Set(inspection.workspaces
244
+ .flatMap((w) => w.sourceFiles)
245
+ .map((p) => resolve(inspection.snapshotRoot, p)));
246
+ for (const w of inspection.workspaces) {
247
+ inventory.add(resolve(inspection.snapshotRoot, w.manifestPath));
248
+ if (!texts.has(resolve(inspection.snapshotRoot, w.manifestPath)))
249
+ await add(w.manifestPath, 64 * 1024);
250
+ }
251
+ // TypeScript may prefer a nested directory's package.json to index.ts.
252
+ // Inventory its possible presence before treating index files as a closed
253
+ // graph. Unsupported nested manifests retain full analyzer coverage.
254
+ const manifests = new Set();
255
+ for (const path of inventory) {
256
+ let directory = dirname(path);
257
+ while (within(inspection.snapshotRoot, directory)) {
258
+ manifests.add(relative(inspection.snapshotRoot, resolve(directory, "package.json"))
259
+ .split(sep)
260
+ .join("/"));
261
+ if (manifests.size > 4096)
262
+ throw new ProofLimit();
263
+ if (directory === inspection.snapshotRoot)
264
+ break;
265
+ directory = dirname(directory);
266
+ }
267
+ }
268
+ const knownManifests = new Set(inspection.workspaces.map((w) => w.manifestPath));
269
+ const absentPaths = new Set();
270
+ for (const path of manifests) {
271
+ if (knownManifests.has(path))
272
+ continue;
273
+ context.signal?.throwIfAborted();
274
+ const registry = await captureSnapshotRegistry(inspection.snapshotRoot, [path]);
275
+ if (registry.resolve(path) !== undefined ||
276
+ registry.entries().some((e) => e.kind === "symlink"))
277
+ return unknown;
278
+ witnesses.push({
279
+ root: inspection.snapshotRoot,
280
+ path,
281
+ limit: 64 * 1024,
282
+ });
283
+ absentPaths.add(resolve(inspection.snapshotRoot, path));
284
+ }
285
+ for (const path of texts.keys())
286
+ inventory.add(path);
287
+ const directories = new Set();
288
+ for (const path of inventory) {
289
+ let directory = dirname(path);
290
+ while (within(inspection.snapshotRoot, directory)) {
291
+ directories.add(directory);
292
+ if (directory === inspection.snapshotRoot)
293
+ break;
294
+ directory = dirname(directory);
295
+ }
296
+ }
297
+ const snapshotFile = (path) => {
298
+ const absolute = resolve(path);
299
+ if (inventory.has(absolute))
300
+ return true;
301
+ if (!within(inspection.snapshotRoot, absolute) ||
302
+ relative(inspection.snapshotRoot, absolute)
303
+ .split(sep)
304
+ .includes("node_modules"))
305
+ return undefined;
306
+ if (!absentPaths.has(absolute))
307
+ throw new SnapshotLookup(absolute);
308
+ return false;
309
+ };
310
+ const snapshotDirectory = (path) => {
311
+ const absolute = resolve(path);
312
+ if (directories.has(absolute))
313
+ return true;
314
+ if (absentPaths.has(absolute))
315
+ return false;
316
+ if (within(inspection.snapshotRoot, absolute) &&
317
+ !relative(inspection.snapshotRoot, absolute)
318
+ .split(sep)
319
+ .includes("node_modules"))
320
+ throw new SnapshotLookup(absolute);
321
+ return undefined;
322
+ };
323
+ const snapshotRead = (path) => {
324
+ snapshotFile(path);
325
+ return texts.get(resolve(path));
326
+ };
327
+ const resolveSnapshotMetadata = async (operation) => {
328
+ for (;;) {
329
+ context.signal?.throwIfAborted();
330
+ try {
331
+ return operation();
332
+ }
333
+ catch (error) {
334
+ if (!(error instanceof SnapshotLookup))
335
+ throw error;
336
+ charge();
337
+ const path = relative(inspection.snapshotRoot, error.path)
338
+ .split(sep)
339
+ .join("/");
340
+ const registry = await captureSnapshotRegistry(inspection.snapshotRoot, [path]);
341
+ context.signal?.throwIfAborted();
342
+ if (registry.entries().some((e) => e.kind === "symlink"))
343
+ throw Error("Unsupported resolution alias");
344
+ const entry = registry.resolve(path);
345
+ if (entry?.targetKind === "file")
346
+ throw Error("Unsupported resolution metadata");
347
+ if (entry?.targetKind === "directory") {
348
+ directories.add(error.path);
349
+ witnesses.push({
350
+ root: inspection.snapshotRoot,
351
+ path,
352
+ limit: 0,
353
+ directory: true,
354
+ });
355
+ }
356
+ else {
357
+ absentPaths.add(error.path);
358
+ witnesses.push({
359
+ root: inspection.snapshotRoot,
360
+ path,
361
+ limit: 0,
362
+ });
363
+ }
364
+ }
365
+ }
366
+ };
367
+ const snapshotHost = {
368
+ fileExists: (path) => snapshotFile(path) ?? false,
369
+ readFile: snapshotRead,
370
+ directoryExists: (path) => snapshotDirectory(path) ?? false,
371
+ realpath: (path) => resolve(path),
372
+ };
373
+ const libraryRoot = dirname(ts.getDefaultLibFilePath({}));
374
+ const dependencyPath = (path) => within(context.repositoryRoot, resolve(path)) ||
375
+ within(libraryRoot, resolve(path));
376
+ const host = {
377
+ fileExists: (path) => snapshotFile(path) ??
378
+ (dependencyPath(path) &&
379
+ captured(() => dependencies.fileExists(path))),
380
+ readFile: (path) => snapshotRead(path) ??
381
+ (dependencyPath(path)
382
+ ? captured(() => dependencies.readCapturedFile(path))
383
+ : undefined),
384
+ directoryExists: (path) => snapshotDirectory(path) ??
385
+ (within(context.repositoryRoot, resolve(path)) ||
386
+ (within(libraryRoot, resolve(path)) &&
387
+ captured(() => dependencies.directoryExists(path)))),
388
+ getDirectories: (path) => dependencyPath(path)
389
+ ? captured(() => dependencies.getDirectories(path))
390
+ : [],
391
+ realpath: (path) => inventory.has(resolve(path))
392
+ ? resolve(path)
393
+ : captured(() => dependencies.realpath(path)),
394
+ };
395
+ // Missing declared installs must not disappear behind an optimization. This
396
+ // is intentionally stricter than the analyzer's usage-based diagnosis.
397
+ for (const w of inspection.workspaces.filter((w) => w.relativeRoot === "." ||
398
+ w.relativeRoot === side.relativeRoot ||
399
+ side.relativeRoot.startsWith(`${w.relativeRoot}/`)))
400
+ for (const declaration of w.dependencyDeclarations) {
401
+ let directory = resolve(context.repositoryRoot, side.relativeRoot), found = false;
402
+ while (within(context.repositoryRoot, directory)) {
403
+ charge();
404
+ if (captured(() => dependencies.fileExists(resolve(directory, "node_modules", declaration.name, "package.json")))) {
405
+ found = true;
406
+ break;
407
+ }
408
+ if (directory === resolve(context.repositoryRoot))
409
+ break;
410
+ directory = dirname(directory);
411
+ }
412
+ if (!found)
413
+ return unknown;
414
+ }
415
+ const allowed = new Set(side.sourceFiles.map((p) => resolve(inspection.snapshotRoot, p)));
416
+ for (const project of inputs.projects) {
417
+ const options = {
418
+ target: ts.ScriptTarget.ES2022,
419
+ module: ts.ModuleKind.NodeNext,
420
+ moduleResolution: ts.ModuleResolutionKind.NodeNext,
421
+ ...project.options,
422
+ };
423
+ // Conditional NodeNext/CJS resolution requires usage-specific mode. Keep
424
+ // broad coverage until that variant has an explicit proof implementation.
425
+ if (options.moduleResolution !== ts.ModuleResolutionKind.Bundler &&
426
+ options.moduleResolution !== ts.ModuleResolutionKind.Node10) {
427
+ if (JSON.stringify(options.types) !== "[]")
428
+ return unknown;
429
+ for (const sourcePath of project.sourcePaths) {
430
+ const text = texts.get(resolve(inspection.snapshotRoot, sourcePath));
431
+ const pre = ts.preProcessFile(text, true, true);
432
+ if (pre.importedFiles.length ||
433
+ pre.referencedFiles.length ||
434
+ pre.typeReferenceDirectives.length ||
435
+ pre.libReferenceDirectives.length ||
436
+ /\.d\.[cm]?ts$/iu.test(sourcePath))
437
+ return unknown;
438
+ const tree = ts.createSourceFile(sourcePath, text, ts.ScriptTarget.Latest, true);
439
+ if (!ts.isExternalModule(tree))
440
+ return unknown;
441
+ let unsafe = false;
442
+ const visit = (node) => {
443
+ if (ts.isModuleDeclaration(node) || ts.isCallExpression(node))
444
+ unsafe = true;
445
+ if (!unsafe)
446
+ ts.forEachChild(node, visit);
447
+ };
448
+ visit(tree);
449
+ if (unsafe)
450
+ return unknown;
451
+ }
452
+ // Static source closure still needs the normal library witnesses.
453
+ }
454
+ if (options.plugins !== undefined ||
455
+ options.moduleSuffixes ||
456
+ options.rootDirs ||
457
+ options.noResolve ||
458
+ options.typeRoots ||
459
+ options.allowJs ||
460
+ options.importHelpers)
461
+ return unknown;
462
+ const typeRoots = [];
463
+ let directory = resolve(context.repositoryRoot, dirname(project.configPath));
464
+ while (within(context.repositoryRoot, directory)) {
465
+ typeRoots.push(resolve(directory, "node_modules/@types"));
466
+ if (directory === resolve(context.repositoryRoot))
467
+ break;
468
+ directory = dirname(directory);
469
+ }
470
+ const typeNames = options.types ?? [
471
+ ...new Set(typeRoots.flatMap((root) => captured(() => dependencies.directoryEntries(root))
472
+ .filter((e) => e.type === "directory" && !e.name.startsWith("."))
473
+ .map((e) => e.name))),
474
+ ];
475
+ const prepared = { ...options, typeRoots };
476
+ const pending = project.sourcePaths.map((path) => resolve(inspection.snapshotRoot, path));
477
+ const seen = new Set();
478
+ const push = (path) => {
479
+ if (!seen.has(path))
480
+ pending.push(path);
481
+ };
482
+ const library = (fileName) => {
483
+ charge();
484
+ if (!/^lib\.[a-z0-9.]+\.d\.ts$/u.test(fileName))
485
+ return undefined;
486
+ const name = fileName.slice(4, -5);
487
+ let directory = resolve(context.repositoryRoot, dirname(project.configPath));
488
+ while (within(context.repositoryRoot, directory)) {
489
+ if (captured(() => dependencies.fileExists(resolve(directory, "node_modules", `@typescript/lib-${name.split(".")[0]}`, "package.json"))))
490
+ return undefined;
491
+ if (directory === resolve(context.repositoryRoot))
492
+ break;
493
+ directory = dirname(directory);
494
+ }
495
+ const file = resolve(libraryRoot, fileName);
496
+ return captured(() => dependencies.fileExists(file))
497
+ ? file
498
+ : undefined;
499
+ };
500
+ if (!options.noLib)
501
+ for (const name of options.lib ?? [
502
+ ts.getDefaultLibFileName(options),
503
+ ]) {
504
+ const file = library(name);
505
+ if (!file)
506
+ return unknown;
507
+ push(file);
508
+ }
509
+ for (const name of typeNames) {
510
+ charge();
511
+ const resolved = (await resolveSnapshotMetadata(() => ts.resolveTypeReferenceDirective(name, resolve(context.repositoryRoot, project.configPath), prepared, host))).resolvedTypeReferenceDirective;
512
+ if (!resolved?.resolvedFileName)
513
+ return unknown;
514
+ push(resolved.resolvedFileName);
515
+ }
516
+ const resolveOne = (specifier, from, mode) => {
517
+ charge();
518
+ const builtin = builtinModules.includes(specifier) ||
519
+ builtinModules.includes(specifier.replace(/^node:/u, ""));
520
+ if (specifier.includes("\\") ||
521
+ (!builtin && /^[A-Za-z][A-Za-z0-9+.-]*:/u.test(specifier)) ||
522
+ isAbsolute(specifier))
523
+ return undefined;
524
+ const local = ts.resolveModuleName(specifier, from, prepared, inventory.has(from) ? snapshotHost : host, undefined, undefined, mode).resolvedModule;
525
+ if (local !== undefined)
526
+ return local.resolvedFileName;
527
+ if (builtin) {
528
+ charge();
529
+ return ts.resolveTypeReferenceDirective("node", resolve(context.repositoryRoot, project.configPath), prepared, host).resolvedTypeReferenceDirective?.resolvedFileName;
530
+ }
531
+ if (specifier.startsWith("."))
532
+ return undefined;
533
+ const relativeContaining = within(inspection.snapshotRoot, from)
534
+ ? relative(inspection.snapshotRoot, from)
535
+ : undefined;
536
+ const synthetic = relativeContaining === undefined
537
+ ? from
538
+ : resolve(context.repositoryRoot, relativeContaining);
539
+ const installed = ts.resolveModuleName(specifier, synthetic, prepared, host, undefined, undefined, mode).resolvedModule;
540
+ return installed !== undefined &&
541
+ captured(() => dependencies.packageFileExists(installed.resolvedFileName))
542
+ ? installed.resolvedFileName
543
+ : undefined;
544
+ };
545
+ const resolveModule = async (specifier, from) => {
546
+ const imports = await resolveSnapshotMetadata(() => resolveOne(specifier, from, ts.ModuleKind.ESNext));
547
+ const requires = await resolveSnapshotMetadata(() => resolveOne(specifier, from, ts.ModuleKind.CommonJS));
548
+ return imports !== undefined && requires !== undefined
549
+ ? [...new Set([imports, requires])]
550
+ : undefined;
551
+ };
552
+ while (pending.length) {
553
+ context.signal?.throwIfAborted();
554
+ const path = resolve(pending.pop());
555
+ if (seen.has(path))
556
+ continue;
557
+ seen.add(path);
558
+ if (seen.size % 16 === 0)
559
+ await yieldTurn(undefined, context.signal === undefined
560
+ ? undefined
561
+ : { signal: context.signal });
562
+ const local = inventory.has(path);
563
+ if (within(libraryRoot, path)) {
564
+ if (librarySeen.has(path))
565
+ continue;
566
+ librarySeen.add(path);
567
+ }
568
+ if (local && !allowed.has(path))
569
+ return { independent: false, reason: "dependency" };
570
+ if (!local && !/\.d\.[cm]?ts$/iu.test(path))
571
+ return unknown;
572
+ const source = local
573
+ ? texts.get(path)
574
+ : captured(() => dependencies.readCapturedFile(path));
575
+ if (source === undefined)
576
+ return unknown;
577
+ if (local && /\.[cm]?jsx?$/iu.test(path))
578
+ return unknown;
579
+ if (local && /@jsx(?:ImportSource|Runtime|Frag)?\b/iu.test(source))
580
+ return unknown;
581
+ const pre = ts.preProcessFile(source, true, true);
582
+ charge(pre.importedFiles.length * 2 +
583
+ pre.referencedFiles.length +
584
+ pre.typeReferenceDirectives.length +
585
+ pre.libReferenceDirectives.length);
586
+ const tree = ts.createSourceFile(path, source, ts.ScriptTarget.Latest, true);
587
+ // Nonliteral module loaders and shadowed require are not a closed graph.
588
+ let unsafe = false;
589
+ const visit = (node) => {
590
+ if (!/\.d\.[cm]?ts$/iu.test(path) &&
591
+ ts.isIdentifier(node) &&
592
+ node.text === "require" &&
593
+ !(ts.isCallExpression(node.parent) &&
594
+ node.parent.expression === node &&
595
+ node.parent.arguments.length === 1 &&
596
+ ts.isStringLiteralLike(node.parent.arguments[0])))
597
+ unsafe = true;
598
+ if (ts.isCallExpression(node) &&
599
+ (node.expression.kind === ts.SyntaxKind.ImportKeyword ||
600
+ (ts.isIdentifier(node.expression) &&
601
+ node.expression.text === "require")) &&
602
+ (node.arguments.length !== 1 ||
603
+ !ts.isStringLiteralLike(node.arguments[0])))
604
+ unsafe = true;
605
+ if (ts.isMetaProperty(node) &&
606
+ node.keywordToken === ts.SyntaxKind.ImportKeyword)
607
+ unsafe = true;
608
+ if (!unsafe)
609
+ ts.forEachChild(node, visit);
610
+ };
611
+ visit(tree);
612
+ if (unsafe)
613
+ return unknown;
614
+ for (const item of pre.importedFiles) {
615
+ const resolved = await resolveModule(item.fileName, path);
616
+ if (!resolved)
617
+ return unknown;
618
+ for (const path of resolved)
619
+ push(path);
620
+ }
621
+ for (const item of pre.referencedFiles) {
622
+ const target = resolve(dirname(path), item.fileName);
623
+ if (local
624
+ ? !inventory.has(target)
625
+ : !captured(() => dependencies.packageFileExists(target)))
626
+ return unknown;
627
+ push(target);
628
+ }
629
+ for (const item of pre.typeReferenceDirectives) {
630
+ for (const mode of [
631
+ ts.ModuleKind.ESNext,
632
+ ts.ModuleKind.CommonJS,
633
+ ]) {
634
+ charge();
635
+ const found = (await resolveSnapshotMetadata(() => ts.resolveTypeReferenceDirective(item.fileName, path, prepared, host, undefined, undefined, mode))).resolvedTypeReferenceDirective;
636
+ if (!found?.resolvedFileName)
637
+ return unknown;
638
+ push(found.resolvedFileName);
639
+ }
640
+ }
641
+ for (const reference of pre.libReferenceDirectives) {
642
+ const name = reference.fileName.toLowerCase();
643
+ if (!/^[a-z0-9.]+$/u.test(name))
644
+ return unknown;
645
+ const file = library(`lib.${name}.d.ts`);
646
+ if (!file)
647
+ return unknown;
648
+ push(file);
649
+ }
650
+ if (local &&
651
+ (options.jsx === ts.JsxEmit.ReactJSX ||
652
+ options.jsx === ts.JsxEmit.ReactJSXDev)) {
653
+ const runtime = await resolveModule(`${options.jsxImportSource ?? "react"}/${options.jsx === ts.JsxEmit.ReactJSXDev ? "jsx-dev-runtime" : "jsx-runtime"}`, path);
654
+ if (!runtime)
655
+ return unknown;
656
+ for (const path of runtime)
657
+ push(path);
658
+ }
659
+ }
660
+ }
661
+ signatures.push(signature);
662
+ }
663
+ if (signatures[0].size !== signatures[1].size ||
664
+ [...signatures[0]].some(([path, digest]) => signatures[1].get(path) !== digest))
665
+ return { independent: false, reason: "changed-input" };
666
+ const manifest = dependencies.manifest();
667
+ if (!manifest || !dependencies.validate(manifest))
668
+ return unknown;
669
+ const record = {
670
+ key: key ?? "",
671
+ manifest,
672
+ context: dependencyContext,
673
+ witnesses,
674
+ };
675
+ if (!(await valid(record, context.signal)))
676
+ return unknown;
677
+ if (owner !== undefined && key !== undefined) {
678
+ const bytes = JSON.stringify(record).length * 2;
679
+ if (owner.records.size >= 256 || owner.bytes + bytes > 32 * 1024 * 1024)
680
+ return { independent: false, reason: "limit" };
681
+ owner.records.set(key, record);
682
+ owner.bytes += bytes;
683
+ }
684
+ return { independent: true, reason: "disjoint-inputs" };
685
+ }
686
+ catch (error) {
687
+ context.signal?.throwIfAborted();
688
+ if (error instanceof ProofLimit)
689
+ return { independent: false, reason: "limit" };
690
+ return unknown;
691
+ }
692
+ });
693
+ }
694
+ //# sourceMappingURL=compiler-scope-graph.js.map