zedbee 0.1.0-beta.17 → 0.1.0-beta.19

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