@diffci.com/diffci 0.3.38 → 0.3.39
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 +3 -3
- package/dist-client/src/client/agent-setup.d.ts +1 -1
- package/dist-client/src/client/agent-setup.js +1 -1
- package/node_modules/@diffci.com/core/README.md +15 -4
- package/node_modules/@diffci.com/core/dist/cache/economics-context.d.ts +4 -1
- package/node_modules/@diffci.com/core/dist/cache/economics-context.js +7 -3
- package/node_modules/@diffci.com/core/dist/cache/economics-context.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/cache/graph-cache.d.ts +1 -1
- package/node_modules/@diffci.com/core/dist/cache/graph-cache.js +5 -1
- package/node_modules/@diffci.com/core/dist/cache/graph-cache.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/evidence.js +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/evidence.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/git-diff.d.ts +2 -0
- package/node_modules/@diffci.com/core/dist/git/git-diff.js +7 -6
- package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/go.js +24 -7
- package/node_modules/@diffci.com/core/dist/repo/adapters/go.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/analyzer.js +16 -1
- package/node_modules/@diffci.com/core/dist/repo/analyzer.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/export-reach.d.ts +16 -0
- package/node_modules/@diffci.com/core/dist/repo/export-reach.js +113 -0
- package/node_modules/@diffci.com/core/dist/repo/export-reach.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/repo/file-references.js +2 -1
- package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/graph.js +429 -39
- package/node_modules/@diffci.com/core/dist/repo/graph.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/impact-types.d.ts +1 -1
- package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +51 -0
- package/node_modules/@diffci.com/core/dist/repo/impact.js +296 -9
- package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/lockfiles.d.ts +5 -0
- package/node_modules/@diffci.com/core/dist/repo/lockfiles.js +12 -0
- package/node_modules/@diffci.com/core/dist/repo/lockfiles.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/repo-config.d.ts +5 -0
- package/node_modules/@diffci.com/core/dist/repo/repo-config.js +3 -1
- package/node_modules/@diffci.com/core/dist/repo/repo-config.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/types.d.ts +35 -1
- package/node_modules/@diffci.com/core/dist/repo/workspace-sources.d.ts +35 -0
- package/node_modules/@diffci.com/core/dist/repo/workspace-sources.js +292 -0
- package/node_modules/@diffci.com/core/dist/repo/workspace-sources.js.map +1 -0
- package/node_modules/@diffci.com/core/package.json +1 -1
- package/node_modules/@diffci.com/core/src/cache/economics-context.ts +7 -3
- package/node_modules/@diffci.com/core/src/cache/graph-cache.ts +5 -1
- package/node_modules/@diffci.com/core/src/ci-inference/evidence.ts +1 -1
- package/node_modules/@diffci.com/core/src/git/git-diff.ts +7 -6
- package/node_modules/@diffci.com/core/src/repo/adapters/go.ts +23 -7
- package/node_modules/@diffci.com/core/src/repo/analyzer.ts +15 -1
- package/node_modules/@diffci.com/core/src/repo/export-reach.ts +92 -0
- package/node_modules/@diffci.com/core/src/repo/file-references.ts +2 -1
- package/node_modules/@diffci.com/core/src/repo/graph.ts +365 -35
- package/node_modules/@diffci.com/core/src/repo/impact-types.ts +2 -0
- package/node_modules/@diffci.com/core/src/repo/impact.ts +267 -9
- package/node_modules/@diffci.com/core/src/repo/lockfiles.ts +13 -0
- package/node_modules/@diffci.com/core/src/repo/repo-config.ts +8 -1
- package/node_modules/@diffci.com/core/src/repo/types.ts +32 -1
- package/node_modules/@diffci.com/core/src/repo/workspace-sources.ts +273 -0
- package/package.json +3 -3
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
2
2
|
import { createTestFileMatcher, DEFAULT_TEST_FILE_MATCHER, testFileMatcherForProfile, type TestFileMatcher } from "./test-discovery.js";
|
|
3
3
|
import { isBuiltin } from "node:module";
|
|
4
|
-
import { dirname, extname, join, normalize, relative, resolve, sep } from "node:path";
|
|
4
|
+
import { dirname, extname, isAbsolute, join, normalize, posix, relative, resolve, sep } from "node:path";
|
|
5
5
|
import ts from "typescript";
|
|
6
6
|
import { adapterFiles, REPOSITORY_ADAPTERS } from "./adapters/index.js";
|
|
7
7
|
import { pythonAdapter } from "./adapters/python.js";
|
|
8
8
|
import { analyzeRepository, type AnalyzeRepositoryOptions } from "./analyzer.js";
|
|
9
9
|
import { applyVueScope, inVuePackage } from "./vue-scope.js";
|
|
10
10
|
import { declaredWorkspaceRoots } from "./workspaces.js";
|
|
11
|
+
import { infrastructureRole } from "./file-references.js";
|
|
12
|
+
import { WorkspaceSources } from "./workspace-sources.js";
|
|
11
13
|
import type {
|
|
12
14
|
DependencyEdge,
|
|
15
|
+
ModuleBindings,
|
|
13
16
|
DependencyEdgeKind,
|
|
14
17
|
DependencyGraph,
|
|
15
18
|
DependencyGraphNode,
|
|
@@ -40,6 +43,15 @@ interface ImportRef {
|
|
|
40
43
|
/** A `vi.mock("./x")` / `jest.mock("./x")` target. Vitest counts these as dependencies of the test;
|
|
41
44
|
* an unresolvable one (a virtual or aliased module) is dropped rather than made unsafe. */
|
|
42
45
|
mock?: boolean;
|
|
46
|
+
/** Runtime names an `import` statement binds (`default` for a default import); absent means the whole
|
|
47
|
+
* module (namespace and side-effect imports, dynamic imports, require, mocks). */
|
|
48
|
+
names?: string[];
|
|
49
|
+
/** For `export ... from`: the names it forwards as [exported, imported] pairs, `star` for `export *`,
|
|
50
|
+
* or `namespace` for `export * as ns`. */
|
|
51
|
+
reexport?: { pairs?: [string, string][]; star?: boolean; namespace?: string };
|
|
52
|
+
/** A computed load outside any function body (or in an immediately invoked one): it runs when the
|
|
53
|
+
* module loads, so a test that merely loads the module may run it. */
|
|
54
|
+
atLoad?: boolean;
|
|
43
55
|
}
|
|
44
56
|
|
|
45
57
|
/** Test-runner calls whose literal first argument names a module the test depends on. */
|
|
@@ -274,9 +286,20 @@ function extractImportRefs(sourceFile: ts.SourceFile): ImportRef[] {
|
|
|
274
286
|
let shadowDepth = 0;
|
|
275
287
|
let consts: Map<string, ts.Expression> | undefined;
|
|
276
288
|
|
|
289
|
+
// A function body runs when called, not when the module loads; an immediately invoked one runs at load.
|
|
290
|
+
// Program source files have no parent pointers, so a call marks the function it invokes on the way down.
|
|
291
|
+
let functionDepth = 0;
|
|
292
|
+
const invokedAtOnce = new Set<ts.Node>();
|
|
277
293
|
function visit(node: ts.Node) {
|
|
278
294
|
const shadows = scopeShadowsRequire(node);
|
|
279
295
|
if (shadows) shadowDepth++;
|
|
296
|
+
if (ts.isCallExpression(node)) {
|
|
297
|
+
let callee: ts.Expression = node.expression;
|
|
298
|
+
while (ts.isParenthesizedExpression(callee)) callee = callee.expression;
|
|
299
|
+
if (ts.isFunctionLike(callee)) invokedAtOnce.add(callee);
|
|
300
|
+
}
|
|
301
|
+
const body = ts.isFunctionLike(node) && !invokedAtOnce.has(node);
|
|
302
|
+
if (body) functionDepth++;
|
|
280
303
|
if (ts.isImportDeclaration(node)) {
|
|
281
304
|
const specifier = node.moduleSpecifier;
|
|
282
305
|
if (ts.isStringLiteral(specifier)) {
|
|
@@ -285,7 +308,11 @@ function extractImportRefs(sourceFile: ts.SourceFile): ImportRef[] {
|
|
|
285
308
|
const kind: DependencyEdgeKind = isTypeOnly ? "type-import" : "import";
|
|
286
309
|
const inlineTypeOnly = !isTypeOnly && !!clause && !clause.name && !!clause.namedBindings
|
|
287
310
|
&& ts.isNamedImports(clause.namedBindings) && allInlineType(clause.namedBindings.elements);
|
|
288
|
-
|
|
311
|
+
const bindings = clause && !(clause.namedBindings && ts.isNamespaceImport(clause.namedBindings))
|
|
312
|
+
? [...(clause.name ? ["default"] : []), ...(clause.namedBindings && ts.isNamedImports(clause.namedBindings)
|
|
313
|
+
? clause.namedBindings.elements.filter((el) => !el.isTypeOnly).map((el) => (el.propertyName ?? el.name).text) : [])]
|
|
314
|
+
: undefined;
|
|
315
|
+
refs.push({ specifier: specifier.text, kind, dynamic: false, ...(inlineTypeOnly ? { inlineTypeOnly } : {}), ...(bindings ? { names: bindings } : {}) });
|
|
289
316
|
}
|
|
290
317
|
} else if (ts.isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference)) {
|
|
291
318
|
const specifier = node.moduleReference.expression;
|
|
@@ -297,7 +324,11 @@ function extractImportRefs(sourceFile: ts.SourceFile): ImportRef[] {
|
|
|
297
324
|
if (ts.isStringLiteral(specifier)) {
|
|
298
325
|
const kind: DependencyEdgeKind = node.isTypeOnly ? "type-import" : "re-export";
|
|
299
326
|
const inlineTypeOnly = !node.isTypeOnly && !!node.exportClause && ts.isNamedExports(node.exportClause) && allInlineType(node.exportClause.elements);
|
|
300
|
-
|
|
327
|
+
const clause = node.exportClause;
|
|
328
|
+
const reexport = !clause ? { star: true }
|
|
329
|
+
: ts.isNamespaceExport(clause) ? { namespace: clause.name.text }
|
|
330
|
+
: { pairs: clause.elements.filter((el) => !el.isTypeOnly).map((el): [string, string] => [el.name.text, (el.propertyName ?? el.name).text]) };
|
|
331
|
+
refs.push({ specifier: specifier.text, kind, dynamic: false, ...(inlineTypeOnly ? { inlineTypeOnly } : {}), reexport });
|
|
301
332
|
}
|
|
302
333
|
} else if (ts.isCallExpression(node)) {
|
|
303
334
|
const firstArg = node.arguments[0];
|
|
@@ -314,6 +345,7 @@ function extractImportRefs(sourceFile: ts.SourceFile): ImportRef[] {
|
|
|
314
345
|
dynamic: isImport || !syntaxLiteral,
|
|
315
346
|
computed: !literal,
|
|
316
347
|
...(patterns ? { patterns } : {}),
|
|
348
|
+
...(!literal && functionDepth === 0 ? { atLoad: true } : {}),
|
|
317
349
|
});
|
|
318
350
|
} else if (firstArg && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.expression)
|
|
319
351
|
&& MOCK_MODULE_CALLS.has(`${node.expression.expression.text}.${node.expression.name.text}`)
|
|
@@ -330,11 +362,13 @@ function extractImportRefs(sourceFile: ts.SourceFile): ImportRef[] {
|
|
|
330
362
|
dynamic: true,
|
|
331
363
|
computed: true,
|
|
332
364
|
...(patterns.length && patterns.every(Boolean) ? { patterns: patterns as NonNullable<ImportRef["patterns"]> } : {}),
|
|
365
|
+
...(functionDepth === 0 ? { atLoad: true } : {}),
|
|
333
366
|
});
|
|
334
367
|
}
|
|
335
368
|
}
|
|
336
369
|
|
|
337
370
|
ts.forEachChild(node, visit);
|
|
371
|
+
if (body) functionDepth--;
|
|
338
372
|
if (shadows) shadowDepth--;
|
|
339
373
|
}
|
|
340
374
|
|
|
@@ -342,6 +376,103 @@ function extractImportRefs(sourceFile: ts.SourceFile): ImportRef[] {
|
|
|
342
376
|
return refs;
|
|
343
377
|
}
|
|
344
378
|
|
|
379
|
+
/**
|
|
380
|
+
* Whether the nearest package.json at or above `path` (inside the repository) declares its JavaScript free of
|
|
381
|
+
* side effects: `"sideEffects": false`, or a list naming only stylesheets. This is the contract bundlers
|
|
382
|
+
* rely on to drop unused re-exports; without it a module's evaluation may matter, so imports stay whole.
|
|
383
|
+
*/
|
|
384
|
+
function sideEffectFreePackage(repoPath: string, path: string, cache: Map<string, boolean | undefined>): boolean {
|
|
385
|
+
let dir = dirname(path);
|
|
386
|
+
while (true) {
|
|
387
|
+
let declared = cache.get(dir);
|
|
388
|
+
if (!cache.has(dir)) {
|
|
389
|
+
declared = undefined;
|
|
390
|
+
try {
|
|
391
|
+
const pkg = JSON.parse(readFileSync(join(repoPath, dir, "package.json"), "utf8")) as { sideEffects?: unknown };
|
|
392
|
+
const se = pkg.sideEffects;
|
|
393
|
+
declared = se === false || (Array.isArray(se) && se.length > 0 && se.every((glob) => typeof glob === "string" && /\.(s?css|sass|less|styl)$/.test(glob)));
|
|
394
|
+
} catch (error) {
|
|
395
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") declared = false;
|
|
396
|
+
}
|
|
397
|
+
cache.set(dir, declared);
|
|
398
|
+
}
|
|
399
|
+
if (declared !== undefined) return declared;
|
|
400
|
+
if (dir === "." || dir === "" || dirname(dir) === dir) return false;
|
|
401
|
+
dir = dirname(dir);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Runtime names a module defines itself, for export-level selection. `opaque` when they cannot be listed
|
|
407
|
+
* (CommonJS `module.exports`/`exports.x`, `export =`, destructured `export const { a } = ...`): an import of
|
|
408
|
+
* such a module always counts as the whole module.
|
|
409
|
+
*/
|
|
410
|
+
function exportedLocals(sourceFile: ts.SourceFile): { locals: string[]; opaque: boolean } {
|
|
411
|
+
const locals = new Set<string>();
|
|
412
|
+
let opaque = false;
|
|
413
|
+
const has = (node: ts.Node, kind: ts.SyntaxKind) => ts.canHaveModifiers(node) && (ts.getModifiers(node) ?? []).some((m) => m.kind === kind);
|
|
414
|
+
for (const st of sourceFile.statements) {
|
|
415
|
+
if (ts.isExportDeclaration(st)) {
|
|
416
|
+
if (!st.moduleSpecifier && !st.isTypeOnly && st.exportClause && ts.isNamedExports(st.exportClause)) {
|
|
417
|
+
for (const el of st.exportClause.elements) if (!el.isTypeOnly) locals.add(el.name.text);
|
|
418
|
+
}
|
|
419
|
+
} else if (ts.isExportAssignment(st)) {
|
|
420
|
+
locals.add("default");
|
|
421
|
+
if (st.isExportEquals) opaque = true;
|
|
422
|
+
} else if (has(st, ts.SyntaxKind.ExportKeyword)) {
|
|
423
|
+
if (ts.isInterfaceDeclaration(st) || ts.isTypeAliasDeclaration(st)) continue;
|
|
424
|
+
if (has(st, ts.SyntaxKind.DefaultKeyword)) locals.add("default");
|
|
425
|
+
else if (ts.isVariableStatement(st)) {
|
|
426
|
+
for (const d of st.declarationList.declarations) {
|
|
427
|
+
if (ts.isIdentifier(d.name)) locals.add(d.name.text);
|
|
428
|
+
else opaque = true;
|
|
429
|
+
}
|
|
430
|
+
} else if ((ts.isFunctionDeclaration(st) || ts.isClassDeclaration(st) || ts.isEnumDeclaration(st) || ts.isModuleDeclaration(st)) && st.name && ts.isIdentifier(st.name)) {
|
|
431
|
+
locals.add(st.name.text);
|
|
432
|
+
} else opaque = true;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
const visit = (node: ts.Node): void => {
|
|
436
|
+
if (opaque) return;
|
|
437
|
+
if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression)
|
|
438
|
+
&& (node.expression.text === "exports" || (node.expression.text === "module" && node.name.text === "exports"))) opaque = true;
|
|
439
|
+
else ts.forEachChild(node, visit);
|
|
440
|
+
};
|
|
441
|
+
visit(sourceFile);
|
|
442
|
+
return { locals: [...locals].sort(), opaque };
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/** A string that reads as a relative path to a code file: `./x`, `../x`, or a relative path ending in a code
|
|
446
|
+
* extension (`config.ts`, `jobs/handler.js`). */
|
|
447
|
+
const PATH_LITERAL = /^(?:\.{1,2}\/[^\s:*?"<>|]+|(?:[\w@.-]+\/)*[\w@.-]+\.[cm]?[jt]sx?)$/;
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Strings that name a code file by path, outside import and require specifiers, which already are edges
|
|
451
|
+
* (2026-11-10). payloadcms/payload's integration tests pass `{ config: './config.ts' }` to a helper that
|
|
452
|
+
* `import()`s it; the string is the only trace of that dependency. Type positions are skipped.
|
|
453
|
+
*/
|
|
454
|
+
function extractPathLiterals(sourceFile: ts.SourceFile): string[] {
|
|
455
|
+
const found = new Set<string>();
|
|
456
|
+
const specifiers = new Set<ts.Node>();
|
|
457
|
+
const visit = (node: ts.Node): void => {
|
|
458
|
+
if (ts.isTypeNode(node)) return;
|
|
459
|
+
if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.moduleSpecifier) specifiers.add(node.moduleSpecifier);
|
|
460
|
+
if (ts.isExternalModuleReference(node)) specifiers.add(node.expression);
|
|
461
|
+
if (ts.isCallExpression(node) && node.arguments[0]) {
|
|
462
|
+
const e = node.expression;
|
|
463
|
+
const loads = e.kind === ts.SyntaxKind.ImportKeyword || (ts.isIdentifier(e) && e.text === "require")
|
|
464
|
+
|| (ts.isPropertyAccessExpression(e) && ts.isIdentifier(e.expression) && MOCK_MODULE_CALLS.has(`${e.expression.text}.${e.name.text}`));
|
|
465
|
+
if (loads) specifiers.add(node.arguments[0]);
|
|
466
|
+
}
|
|
467
|
+
if ((ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) && !specifiers.has(node) && node.text.length < 300 && PATH_LITERAL.test(node.text)) {
|
|
468
|
+
found.add(node.text);
|
|
469
|
+
}
|
|
470
|
+
ts.forEachChild(node, visit);
|
|
471
|
+
};
|
|
472
|
+
visit(sourceFile);
|
|
473
|
+
return [...found];
|
|
474
|
+
}
|
|
475
|
+
|
|
345
476
|
class DependencyGraphImpl implements DependencyGraph {
|
|
346
477
|
readonly nodes: DependencyGraphNode[];
|
|
347
478
|
readonly edges: DependencyEdge[];
|
|
@@ -886,6 +1017,17 @@ export async function buildDependencyGraph(
|
|
|
886
1017
|
const packageDirectories = new Map<string, string>();
|
|
887
1018
|
const packageScope = (path: string) => nearestPackageDirectory(repoPath, path, packageDirectories);
|
|
888
1019
|
const workspaceRoots = new Set(declaredWorkspaceRoots(repoPath));
|
|
1020
|
+
const workspaceSources = new WorkspaceSources(repoPath, workspaceRoots);
|
|
1021
|
+
// The package manager links workspace packages only into workspace members (and the root project).
|
|
1022
|
+
const inWorkspace = (rel: string) => { const directory = packageScope(rel); return directory === "" || workspaceRoots.has(directory); };
|
|
1023
|
+
let realRepoRoot: string | undefined;
|
|
1024
|
+
const physicalRelative = (file: string): string | undefined => {
|
|
1025
|
+
try {
|
|
1026
|
+
realRepoRoot ??= realpathSync.native(repoPath);
|
|
1027
|
+
const rel = relative(realRepoRoot, realpathSync.native(file)).replace(/\\/g, "/");
|
|
1028
|
+
return rel && !rel.startsWith("../") && rel !== ".." && !isAbsolute(rel) ? rel : undefined;
|
|
1029
|
+
} catch { return undefined; }
|
|
1030
|
+
};
|
|
889
1031
|
for (const item of contributions) for (const { path, reason } of [...(item.fileBlockers ?? []), ...(item.subjectBlockers ?? [])]) addScope(reason, packageScope(path));
|
|
890
1032
|
if (profile.diffciConfig?.configurationError && !adapterBlockers.includes(profile.diffciConfig.configurationError)) adapterBlockers.push(profile.diffciConfig.configurationError);
|
|
891
1033
|
if (contributions.some((item) => item.id === "go") && files.some((file) => /\.(?:[cm]?[jt]sx?|vue)$/.test(file))) {
|
|
@@ -961,8 +1103,31 @@ export async function buildDependencyGraph(
|
|
|
961
1103
|
const assetPaths = new Set<string>(contributions.flatMap((item) => item.assetPaths));
|
|
962
1104
|
for (const item of contributions) for (const path of item.sourcePaths) internalSourcePaths.add(path);
|
|
963
1105
|
const edgeKeys = new Set<string>(edges.map((edge) => `${edge.from}|${edge.to}|${edge.kind}`));
|
|
1106
|
+
const bindings: Record<string, ModuleBindings> = {};
|
|
1107
|
+
const bindingsOf = (path: string): ModuleBindings => (bindings[path] ??= { locals: [], imports: {}, reexports: {} });
|
|
1108
|
+
|
|
1109
|
+
/** Records what a runtime edge binds; an edge without a parsed statement binds the whole module. */
|
|
1110
|
+
function recordBinding(from: string, to: string, kind: DependencyEdgeKind, ref?: ImportRef): void {
|
|
1111
|
+
if (kind === "asset") return;
|
|
1112
|
+
const b = bindingsOf(from);
|
|
1113
|
+
if (kind === "type-import") {
|
|
1114
|
+
if (!(b.typeImports ??= []).includes(to)) b.typeImports.push(to);
|
|
1115
|
+
return;
|
|
1116
|
+
}
|
|
1117
|
+
if (ref?.reexport) {
|
|
1118
|
+
const r = (b.reexports[to] ??= { pairs: [], star: false, namespaces: [] });
|
|
1119
|
+
if (ref.reexport.star) r.star = true;
|
|
1120
|
+
if (ref.reexport.namespace) r.namespaces.push(ref.reexport.namespace);
|
|
1121
|
+
for (const pair of ref.reexport.pairs ?? []) r.pairs.push(pair);
|
|
1122
|
+
return;
|
|
1123
|
+
}
|
|
1124
|
+
const current = b.imports[to];
|
|
1125
|
+
if (!ref?.names || current === "*") b.imports[to] = "*";
|
|
1126
|
+
else b.imports[to] = [...new Set([...(current ?? []), ...ref.names])];
|
|
1127
|
+
}
|
|
964
1128
|
|
|
965
|
-
function addEdge(from: string, to: string, kind: DependencyEdgeKind): void {
|
|
1129
|
+
function addEdge(from: string, to: string, kind: DependencyEdgeKind, ref?: ImportRef): void {
|
|
1130
|
+
recordBinding(from, to, kind, ref);
|
|
966
1131
|
const key = `${from}|${to}|${kind}`;
|
|
967
1132
|
if (edgeKeys.has(key)) return;
|
|
968
1133
|
edgeKeys.add(key);
|
|
@@ -1134,6 +1299,37 @@ export async function buildDependencyGraph(
|
|
|
1134
1299
|
return compilerOptions;
|
|
1135
1300
|
}
|
|
1136
1301
|
|
|
1302
|
+
/** The existing code file a path string names, relative to the file holding it. */
|
|
1303
|
+
function pathLiteralTarget(importerRel: string, literal: string): string | undefined {
|
|
1304
|
+
const base = posix.normalize(posix.join(posix.dirname(importerRel), literal));
|
|
1305
|
+
if (base.startsWith("../") || base === "..") return undefined;
|
|
1306
|
+
const stem = base.replace(/\.[cm]?jsx?$/, "");
|
|
1307
|
+
const candidates = [base, ...[".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"].map((ext) => stem + ext), ...["index.ts", "index.tsx", "index.js"].map((name) => `${base}/${name}`)];
|
|
1308
|
+
for (const candidate of candidates) {
|
|
1309
|
+
if (!isSourceFileName(candidate) || candidate.endsWith(".d.ts") || isExcludedPath(candidate, options.excludeDirs ?? [])) continue;
|
|
1310
|
+
if (internalSourcePaths.has(candidate) || existsSync(join(repoPath, candidate))) return candidate;
|
|
1311
|
+
}
|
|
1312
|
+
return undefined;
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
/** Parses an implementation file an import reaches outside the initial walk, rather than silently dropping
|
|
1316
|
+
* the edge or loading every TypeScript declaration library again; false, with a blocker, past the budget. */
|
|
1317
|
+
function followImplementation(absolute: string, rel: string): boolean {
|
|
1318
|
+
if (internalSourcePaths.has(rel)) return true;
|
|
1319
|
+
try {
|
|
1320
|
+
if (isExcludedPath(rel, options.excludeDirs ?? []) || followedImplementationFiles >= followBudget || statSync(absolute).size > 5 * 1024 * 1024) throw new Error("excluded or exceeds parse budget");
|
|
1321
|
+
const followed = ts.createSourceFile(absolute, readFileSync(absolute, "utf8"), ts.ScriptTarget.Latest, true);
|
|
1322
|
+
if ((followed as unknown as { parseDiagnostics?: unknown[] }).parseDiagnostics?.length) throw new Error("invalid implementation syntax");
|
|
1323
|
+
sourceFiles.push(followed);
|
|
1324
|
+
followedImplementationFiles++;
|
|
1325
|
+
} catch {
|
|
1326
|
+
adapterBlockers.push(`Resolved implementation cannot be included in the scoped source inventory: ${rel}`);
|
|
1327
|
+
return false;
|
|
1328
|
+
}
|
|
1329
|
+
internalSourcePaths.add(rel);
|
|
1330
|
+
return true;
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1137
1333
|
for (const sf of sourceFiles) {
|
|
1138
1334
|
const importerRel = toRelativeInternal(repoPath, sf.fileName);
|
|
1139
1335
|
if (!importerRel || !isSourceFileName(sf.fileName)) continue;
|
|
@@ -1143,15 +1339,29 @@ export async function buildDependencyGraph(
|
|
|
1143
1339
|
|
|
1144
1340
|
const keepsTypeImports = keepsTypeOnlyImports(importerOptions);
|
|
1145
1341
|
const refs = extractImportRefs(sf).map((ref) => ref.inlineTypeOnly && !keepsTypeImports ? { ...ref, kind: "type-import" as const } : ref);
|
|
1342
|
+
const { locals, opaque } = exportedLocals(sf);
|
|
1343
|
+
const own = bindingsOf(importerRel);
|
|
1344
|
+
own.locals = locals;
|
|
1345
|
+
if (opaque) own.opaque = true;
|
|
1346
|
+
for (const literal of extractPathLiterals(sf)) {
|
|
1347
|
+
const target = pathLiteralTarget(importerRel, literal);
|
|
1348
|
+
if (!target || target === importerRel) continue;
|
|
1349
|
+
// Infrastructure code outside the graph (ops/, a Worker entry) is resolved through the tests that read
|
|
1350
|
+
// it, and stays global when a deployment definition runs it (ImpactAnalyzer, INFRASTRUCTURE_GLOBAL); a
|
|
1351
|
+
// string naming it must not pull it into the graph and around that rule.
|
|
1352
|
+
if (!internalSourcePaths.has(target) && infrastructureRole(target) === "code") continue;
|
|
1353
|
+
if (followImplementation(join(repoPath, target), target)) addEdge(importerRel, target, "path-literal");
|
|
1354
|
+
}
|
|
1146
1355
|
if (scope && sf.referencedFiles.length) adapterBlockers.push(`Triple-slash file references in the scoped suite require full validation: ${importerRel}`);
|
|
1147
1356
|
for (const ref of refs) {
|
|
1148
1357
|
// Expression text is not a module name. In particular, import(name) must
|
|
1149
1358
|
// not be classified as an external package called "name".
|
|
1359
|
+
if (ref.computed && ref.atLoad) bindingsOf(importerRel).computedAtLoad = true;
|
|
1150
1360
|
if (ref.computed && ref.patterns) {
|
|
1151
1361
|
const targets = resolvePatternTargets(sf.fileName, ref.patterns, importerOptions);
|
|
1152
1362
|
if (targets) {
|
|
1153
1363
|
for (const target of targets) {
|
|
1154
|
-
if (internalSourcePaths.has(target)) addEdge(importerRel, target, ref.kind);
|
|
1364
|
+
if (internalSourcePaths.has(target)) addEdge(importerRel, target, ref.kind, ref);
|
|
1155
1365
|
else recordAssetEdge(importerRel, target);
|
|
1156
1366
|
}
|
|
1157
1367
|
recordReference(targets.some((target) => internalSourcePaths.has(target)) ? "internal-source" : "internal-asset", importerRel, ref);
|
|
@@ -1182,7 +1392,7 @@ export async function buildDependencyGraph(
|
|
|
1182
1392
|
const candidate = findAssetCandidate(sf.fileName, resolvableSpecifier, compilerAliases.length ? compilerAliases : profile.pathAliases, importerOptions.baseUrl ?? dirname(sf.fileName));
|
|
1183
1393
|
const target = candidate && toRelativeInternal(repoPath, candidate);
|
|
1184
1394
|
if (target && internalSourcePaths.has(target)) {
|
|
1185
|
-
addEdge(importerRel, target, ref.kind);
|
|
1395
|
+
addEdge(importerRel, target, ref.kind, ref);
|
|
1186
1396
|
recordReference("internal-source", importerRel, ref);
|
|
1187
1397
|
continue;
|
|
1188
1398
|
}
|
|
@@ -1198,6 +1408,39 @@ export async function buildDependencyGraph(
|
|
|
1198
1408
|
moduleResolutionCache,
|
|
1199
1409
|
);
|
|
1200
1410
|
|
|
1411
|
+
// A workspace package's build output is not its source (2026-11-09, Sentry: `@sentry/server-utils`
|
|
1412
|
+
// resolves to nothing before a build and to build/types/index.d.ts after one). Map the import to the
|
|
1413
|
+
// package's source file, or leave it external so the workspace guard falls back.
|
|
1414
|
+
const workspaceImport = !scope && specifierCategory === "package" && workspaceSources.size && inWorkspace(importerRel)
|
|
1415
|
+
? workspaceSources.packageFor(resolvableSpecifier)
|
|
1416
|
+
: undefined;
|
|
1417
|
+
if (workspaceImport) {
|
|
1418
|
+
const { pkg, subpath } = workspaceImport;
|
|
1419
|
+
const resolvedFile = resolution.resolvedModule?.resolvedFileName;
|
|
1420
|
+
// Through real paths: a workspace link, or a repository path spelled differently (a Windows 8.3
|
|
1421
|
+
// short name), must still land inside the package.
|
|
1422
|
+
const resolvedRel = resolvedFile ? physicalRelative(resolvedFile) : undefined;
|
|
1423
|
+
const insidePackage = resolvedRel !== undefined && resolvedRel.startsWith(`${pkg.root}/`);
|
|
1424
|
+
if (!resolvedFile || (insidePackage && (/\.d\.[mc]?ts$/.test(resolvedRel!) || !internalSourcePaths.has(resolvedRel!)))) {
|
|
1425
|
+
const source = (insidePackage ? workspaceSources.sourceForFile(pkg, resolvedRel!) : undefined) ?? workspaceSources.sourceForSubpath(pkg, subpath);
|
|
1426
|
+
const asset = source ? undefined : workspaceSources.assetForSubpath(pkg, subpath);
|
|
1427
|
+
if (asset) {
|
|
1428
|
+
recordAssetEdge(importerRel, asset);
|
|
1429
|
+
recordReference("internal-asset", importerRel, ref);
|
|
1430
|
+
continue;
|
|
1431
|
+
}
|
|
1432
|
+
// The package's source may sit outside the tsconfig inventory (payloadcms/payload's solution tsconfig
|
|
1433
|
+
// references only some packages): parse it like any other followed implementation.
|
|
1434
|
+
if (source && (internalSourcePaths.has(source) || (!/\.d\.[mc]?ts$/.test(source) && followImplementation(join(repoPath, source), source)))) {
|
|
1435
|
+
addEdge(importerRel, source, ref.kind, ref);
|
|
1436
|
+
recordReference("internal-source", importerRel, ref);
|
|
1437
|
+
} else {
|
|
1438
|
+
recordReference("external-package", importerRel, ref);
|
|
1439
|
+
}
|
|
1440
|
+
continue;
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1201
1444
|
if (!resolution.resolvedModule || !resolution.resolvedModule.resolvedFileName) {
|
|
1202
1445
|
const category = classifySpecifier(ref.specifier);
|
|
1203
1446
|
if (category === "relative" || category === "absolute" || category === "alias") {
|
|
@@ -1215,6 +1458,19 @@ export async function buildDependencyGraph(
|
|
|
1215
1458
|
continue;
|
|
1216
1459
|
}
|
|
1217
1460
|
}
|
|
1461
|
+
// Build output a fresh checkout does not have, inside a workspace package whose tsconfig maps it back:
|
|
1462
|
+
// payloadcms/payload's packages/payload/bin.js does `import('./dist/cli/index.js')`, compiled from
|
|
1463
|
+
// src/cli/index.ts. The import depends on that source, so follow it rather than leave it unresolved.
|
|
1464
|
+
if (category === "relative") {
|
|
1465
|
+
const built = posix.normalize(posix.join(posix.dirname(importerRel), resolvableSpecifier));
|
|
1466
|
+
const pkg = workspaceSources.packageContaining(built);
|
|
1467
|
+
const source = pkg ? workspaceSources.sourceForFile(pkg, built) : undefined;
|
|
1468
|
+
if (source && source !== built && followImplementation(join(repoPath, source), source)) {
|
|
1469
|
+
addEdge(importerRel, source, ref.kind, ref);
|
|
1470
|
+
recordReference("internal-source", importerRel, ref);
|
|
1471
|
+
continue;
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1218
1474
|
recordUnresolved(importerRel, ref, "unresolved internal module");
|
|
1219
1475
|
recordReference("unresolved", importerRel, ref);
|
|
1220
1476
|
} else {
|
|
@@ -1238,23 +1494,9 @@ export async function buildDependencyGraph(
|
|
|
1238
1494
|
}
|
|
1239
1495
|
|
|
1240
1496
|
if (targetRel && isSourceFileName(resolved)) {
|
|
1241
|
-
if (!resolved.endsWith(".d.ts") && !
|
|
1242
|
-
// A real import can reach generated implementation excluded from the
|
|
1243
|
-
// initial walk. Parse it (and its imports) rather than silently dropping
|
|
1244
|
-
// the edge or loading every TypeScript declaration library again.
|
|
1245
|
-
try {
|
|
1246
|
-
if (isExcludedPath(targetRel, options.excludeDirs ?? []) || followedImplementationFiles >= followBudget || statSync(resolved).size > 5 * 1024 * 1024) throw new Error("excluded or exceeds parse budget");
|
|
1247
|
-
const followed = ts.createSourceFile(resolved, readFileSync(resolved, "utf8"), ts.ScriptTarget.Latest, true);
|
|
1248
|
-
if ((followed as unknown as { parseDiagnostics?: unknown[] }).parseDiagnostics?.length) throw new Error("invalid implementation syntax");
|
|
1249
|
-
sourceFiles.push(followed);
|
|
1250
|
-
followedImplementationFiles++;
|
|
1251
|
-
} catch {
|
|
1252
|
-
adapterBlockers.push(`Resolved implementation cannot be included in the scoped source inventory: ${targetRel}`);
|
|
1253
|
-
continue;
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1497
|
+
if (!resolved.endsWith(".d.ts") && !followImplementation(resolved, targetRel)) continue;
|
|
1256
1498
|
internalSourcePaths.add(targetRel);
|
|
1257
|
-
addEdge(importerRel, targetRel, ref.kind);
|
|
1499
|
+
addEdge(importerRel, targetRel, ref.kind, ref);
|
|
1258
1500
|
recordReference("internal-source", importerRel, ref);
|
|
1259
1501
|
continue;
|
|
1260
1502
|
}
|
|
@@ -1323,7 +1565,27 @@ export async function buildDependencyGraph(
|
|
|
1323
1565
|
if (scope && unresolved.length) adapterBlockers.push("Unresolved dependencies in the declared Vue suite require full validation");
|
|
1324
1566
|
if (scope && edges.some(edge => outsideScope(edge.from) || outsideScope(edge.to))) adapterBlockers.push("Vue asset or macro dependency crosses the declared package boundary");
|
|
1325
1567
|
const scopedAdapterBlockers = scopeAdapterBlockers(adapterBlockers, blockerScopes);
|
|
1326
|
-
|
|
1568
|
+
// A type-only import of a subpath the package neither exports nor contains resolves nowhere, installed or not
|
|
1569
|
+
// (payloadcms/payload's stale `import type { ... } from 'payload/types'`): it hides no edge a change can reach.
|
|
1570
|
+
const namesNothing = (ref: ResolutionReference) => {
|
|
1571
|
+
if (ref.kind !== "type-import") return false;
|
|
1572
|
+
const target = workspaceSources.packageFor(stripImportQuery(ref.specifier));
|
|
1573
|
+
return target !== undefined && !workspaceSources.names(target.pkg, target.subpath);
|
|
1574
|
+
};
|
|
1575
|
+
// A file only path strings point at (payloadcms/payload's codemod fixtures `basic.input.ts`, read as text
|
|
1576
|
+
// and full of deliberately stale imports) may never run. Its unmapped workspace imports are unresolved
|
|
1577
|
+
// imports of that file, which matter to a change that reaches it (refineConfidenceForDelta), rather than a
|
|
1578
|
+
// blocker on every change that reaches the imported package.
|
|
1579
|
+
const testFiles = new Set(profile.testFilePaths);
|
|
1580
|
+
const incomingKinds = new Map<string, Set<DependencyEdgeKind>>();
|
|
1581
|
+
for (const edge of edges) (incomingKinds.get(edge.to) ?? incomingKinds.set(edge.to, new Set()).get(edge.to)!).add(edge.kind);
|
|
1582
|
+
const pathLiteralOnly = new Set([...incomingKinds].filter(([file, kinds]) => !testFiles.has(file) && kinds.has("path-literal") && [...kinds].every((kind) => kind === "path-literal")).map(([file]) => file));
|
|
1583
|
+
const workspaceRefs = references.filter((ref) => inWorkspace(ref.importer) && !namesNothing(ref));
|
|
1584
|
+
for (const ref of workspaceRefs) {
|
|
1585
|
+
if (!pathLiteralOnly.has(ref.importer) || ref.resolution !== "external-package" || !workspaceSources.packageFor(stripImportQuery(ref.specifier))) continue;
|
|
1586
|
+
unresolved.push({ importer: ref.importer, specifier: ref.specifier, reason: "workspace import not mapped to source, in a file only path strings name", dynamic: ref.dynamic, typeOnly: ref.kind === "type-import" });
|
|
1587
|
+
}
|
|
1588
|
+
scopedAdapterBlockers.push(...uninstalledWorkspaceBlockers(repoPath, workspaceRefs.filter((ref) => !pathLiteralOnly.has(ref.importer)), workspaceRoots));
|
|
1327
1589
|
profile.adapterBlockers = [...adapterBlockers];
|
|
1328
1590
|
markPhase("importExtractionAndResolution");
|
|
1329
1591
|
|
|
@@ -1408,8 +1670,12 @@ export async function buildDependencyGraph(
|
|
|
1408
1670
|
filesParsed: filesParsed,
|
|
1409
1671
|
};
|
|
1410
1672
|
|
|
1673
|
+
const sideEffectsByDir = new Map<string, boolean | undefined>();
|
|
1674
|
+
for (const [path, b] of Object.entries(bindings)) if (sideEffectFreePackage(repoPath, path, sideEffectsByDir)) b.sideEffectFree = true;
|
|
1675
|
+
|
|
1411
1676
|
return {
|
|
1412
1677
|
graph,
|
|
1678
|
+
bindings,
|
|
1413
1679
|
adapterBlockers,
|
|
1414
1680
|
...(scopedAdapterBlockers.length ? { scopedAdapterBlockers, confidenceWithoutScopedBlockers } : {}),
|
|
1415
1681
|
profile,
|
|
@@ -1424,6 +1690,7 @@ export async function buildDependencyGraph(
|
|
|
1424
1690
|
integrity,
|
|
1425
1691
|
resolvedViaProjectReferences,
|
|
1426
1692
|
runtimeTestSelection: runtimeTestSelectionEligible(repoPath, files, profile),
|
|
1693
|
+
typeTestGlobs: typeTestGlobs(repoPath, files),
|
|
1427
1694
|
};
|
|
1428
1695
|
}
|
|
1429
1696
|
|
|
@@ -1595,10 +1862,10 @@ export function validateDependencyGraph(graph: DependencyGraph): GraphIntegrityR
|
|
|
1595
1862
|
|
|
1596
1863
|
/**
|
|
1597
1864
|
* Whether an `import type` edge can be ignored when selecting tests (2026-11-03). Vitest transpiles
|
|
1598
|
-
* without type checking, so a type-only change cannot alter a runtime test's outcome; ts-jest
|
|
1599
|
-
*
|
|
1600
|
-
*
|
|
1601
|
-
* selected through every edge either way (impact.ts).
|
|
1865
|
+
* without type checking, so a type-only change cannot alter a runtime test's outcome; ts-jest and Vitest's
|
|
1866
|
+
* typecheck mode check every test's types. Vitest typecheck mode anywhere, or Jest at the repository root,
|
|
1867
|
+
* keeps type-only edges selecting every test. Jest in a sub-package, tsd and tstyche check only their own
|
|
1868
|
+
* files (typeTestGlobs), and those tests are selected through every edge either way (impact.ts).
|
|
1602
1869
|
*/
|
|
1603
1870
|
function runtimeTestSelectionEligible(repoPath: string, files: readonly string[], profile: RepositoryProfile): boolean {
|
|
1604
1871
|
const configs = profile.testRunnerConfigs ?? [];
|
|
@@ -1607,7 +1874,9 @@ function runtimeTestSelectionEligible(repoPath: string, files: readonly string[]
|
|
|
1607
1874
|
for (const file of files) {
|
|
1608
1875
|
if (file.split("/").includes("node_modules")) continue;
|
|
1609
1876
|
const name = file.slice(file.lastIndexOf("/") + 1);
|
|
1610
|
-
|
|
1877
|
+
// Jest inside a sub-package governs that package's tests only (typeCheckedPackageDirs, typeTestGlobs).
|
|
1878
|
+
const atRoot = !file.includes("/");
|
|
1879
|
+
if (/^jest\.config\./.test(name)) { if (atRoot) return false; continue; }
|
|
1611
1880
|
if (/^vit(?:e|est)[\w.-]*\.(?:config|workspace|projects)\.[cm]?[jt]s$/.test(name)) {
|
|
1612
1881
|
const text = read(file);
|
|
1613
1882
|
if (text === undefined || /\btypecheck\b/.test(text)) return false;
|
|
@@ -1615,13 +1884,73 @@ function runtimeTestSelectionEligible(repoPath: string, files: readonly string[]
|
|
|
1615
1884
|
let manifest: { scripts?: Record<string, unknown>; dependencies?: object; devDependencies?: object; peerDependencies?: object; optionalDependencies?: object };
|
|
1616
1885
|
try { manifest = JSON.parse(read(file) ?? ""); } catch { return false; }
|
|
1617
1886
|
const packages = [manifest.dependencies, manifest.devDependencies, manifest.peerDependencies, manifest.optionalDependencies].flatMap((group) => Object.keys(group ?? {}));
|
|
1618
|
-
|
|
1619
|
-
|
|
1887
|
+
// tsd and tstyche check types only in their own test files (typeTestGlobs), which keep type edges;
|
|
1888
|
+
// Jest (ts-jest) and `--typecheck` type-check every test they run (2026-11-10: tstyche alone turned
|
|
1889
|
+
// off runtime selection for all of payloadcms/payload's Vitest tests).
|
|
1890
|
+
const scripts = Object.values(manifest.scripts ?? {});
|
|
1891
|
+
if (scripts.some((script) => typeof script !== "string" || /--typecheck/.test(script))) return false;
|
|
1892
|
+
if (atRoot && (packages.some((name) => ["jest", "ts-jest"].includes(name)) || scripts.some((script) => /(?:^|[\s&;|(])jest(?:\s|$)/.test(String(script))))) return false;
|
|
1620
1893
|
}
|
|
1621
1894
|
}
|
|
1622
1895
|
return true;
|
|
1623
1896
|
}
|
|
1624
1897
|
|
|
1898
|
+
/** The files tstyche or tsd check, when either is installed: tstyche.json's `testFileMatch` or tstyche's
|
|
1899
|
+
* defaults, and tsd's `*.test-d.ts`. */
|
|
1900
|
+
function typeTestGlobs(repoPath: string, files: readonly string[]): string[] {
|
|
1901
|
+
const read = (path: string) => { try { return readFileSync(join(repoPath, path), "utf8"); } catch { return undefined; } };
|
|
1902
|
+
let tstyche = false, tsd = false;
|
|
1903
|
+
for (const file of files) {
|
|
1904
|
+
if (file.split("/").includes("node_modules") || !file.endsWith("package.json")) continue;
|
|
1905
|
+
let manifest: { scripts?: Record<string, unknown>; dependencies?: object; devDependencies?: object; peerDependencies?: object; optionalDependencies?: object };
|
|
1906
|
+
try { manifest = JSON.parse(read(file) ?? ""); } catch { continue; }
|
|
1907
|
+
const packages = [manifest.dependencies, manifest.devDependencies, manifest.peerDependencies, manifest.optionalDependencies].flatMap((group) => Object.keys(group ?? {}));
|
|
1908
|
+
const scripts = Object.values(manifest.scripts ?? {}).filter((script): script is string => typeof script === "string");
|
|
1909
|
+
if (packages.includes("tstyche") || scripts.some((script) => /(?:^|[\s&;|(])tstyche(?:\s|$)/.test(script))) tstyche = true;
|
|
1910
|
+
if (packages.includes("tsd") || scripts.some((script) => /(?:^|[\s&;|(])tsd(?:\s|$)/.test(script))) tsd = true;
|
|
1911
|
+
}
|
|
1912
|
+
const globs: string[] = [];
|
|
1913
|
+
if (tstyche) {
|
|
1914
|
+
let match: unknown;
|
|
1915
|
+
for (const name of ["tstyche.config.json", "tstyche.json"]) {
|
|
1916
|
+
const text = read(name);
|
|
1917
|
+
if (text === undefined) continue;
|
|
1918
|
+
const parsed = ts.parseConfigFileTextToJson(name, text);
|
|
1919
|
+
match = (parsed.config as { testFileMatch?: unknown } | undefined)?.testFileMatch;
|
|
1920
|
+
break;
|
|
1921
|
+
}
|
|
1922
|
+
globs.push(...(Array.isArray(match) && match.every((glob) => typeof glob === "string") ? match as string[]
|
|
1923
|
+
: ["**/*.tst.*", "**/__typetests__/*.test.*", "**/typetests/*.test.*"]));
|
|
1924
|
+
}
|
|
1925
|
+
if (tsd) globs.push("**/*.test-d.ts", "**/*.test-d.tsx");
|
|
1926
|
+
for (const dir of typeCheckedPackageDirs(repoPath, files)) globs.push(`${dir}/**`);
|
|
1927
|
+
return globs;
|
|
1928
|
+
}
|
|
1929
|
+
|
|
1930
|
+
/**
|
|
1931
|
+
* Sub-package directories whose own tests Jest (or ts-jest) may type-check as they run: a jest.config there, or
|
|
1932
|
+
* a package.json depending on jest/ts-jest or running `jest`. 2026-11-10: payloadcms/payload's
|
|
1933
|
+
* `.github/actions/triage` (a GitHub Action with its own Jest setup) and `packages/payload-cloud` (a `jest`
|
|
1934
|
+
* test script) had turned off runtime selection for the whole Vitest suite. A repository-root signal still
|
|
1935
|
+
* turns it off everywhere (runtimeTestSelectionEligible).
|
|
1936
|
+
*/
|
|
1937
|
+
function typeCheckedPackageDirs(repoPath: string, files: readonly string[]): string[] {
|
|
1938
|
+
const dirs = new Set<string>();
|
|
1939
|
+
for (const file of files) {
|
|
1940
|
+
if (file.split("/").includes("node_modules") || !file.includes("/")) continue;
|
|
1941
|
+
const name = file.slice(file.lastIndexOf("/") + 1);
|
|
1942
|
+
const dir = file.slice(0, file.lastIndexOf("/"));
|
|
1943
|
+
if (/^jest\.config\./.test(name)) dirs.add(dir);
|
|
1944
|
+
else if (name === "package.json") {
|
|
1945
|
+
let manifest: { scripts?: Record<string, unknown>; dependencies?: object; devDependencies?: object; peerDependencies?: object; optionalDependencies?: object };
|
|
1946
|
+
try { manifest = JSON.parse(readFileSync(join(repoPath, file), "utf8")); } catch { dirs.add(dir); continue; }
|
|
1947
|
+
const packages = [manifest.dependencies, manifest.devDependencies, manifest.peerDependencies, manifest.optionalDependencies].flatMap((group) => Object.keys(group ?? {}));
|
|
1948
|
+
if (packages.some((pkg) => pkg === "jest" || pkg === "ts-jest") || Object.values(manifest.scripts ?? {}).some((script) => /(?:^|[\s&;|(])jest(?:\s|$)/.test(String(script)))) dirs.add(dir);
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
return [...dirs].sort();
|
|
1952
|
+
}
|
|
1953
|
+
|
|
1625
1954
|
function computeConfidence(
|
|
1626
1955
|
unresolvedCount: number,
|
|
1627
1956
|
dynamicUnresolvedCount: number,
|
|
@@ -1809,10 +2138,11 @@ function scopeAdapterBlockers(adapterBlockers: string[], scopes: Map<string, Set
|
|
|
1809
2138
|
return [...scoped].map(([reason, directories]) => ({ reason, directories: [...directories].sort() }));
|
|
1810
2139
|
}
|
|
1811
2140
|
|
|
1812
|
-
/** A declared workspace package imported by name
|
|
1813
|
-
*
|
|
1814
|
-
*
|
|
1815
|
-
*
|
|
2141
|
+
/** A declared workspace package imported by name from a workspace member whose import could not be mapped
|
|
2142
|
+
* to the package's source files hides every edge into that package (2026-11-08: in an uninstalled Sentry
|
|
2143
|
+
* checkout, 18 packages import `@sentry/server-utils`, and none of those edges existed). A change reaching
|
|
2144
|
+
* the package then falls back instead of skipping its dependents. Imports from outside the workspace get
|
|
2145
|
+
* the package from elsewhere (a registry or a tarball) and are left out by the caller. */
|
|
1816
2146
|
function uninstalledWorkspaceBlockers(repoPath: string, references: ResolutionReference[], workspaceRoots: ReadonlySet<string>): ScopedAdapterBlocker[] {
|
|
1817
2147
|
const external = references.filter((ref) => ref.resolution === "external-package");
|
|
1818
2148
|
if (!external.length) return [];
|
|
@@ -1834,7 +2164,7 @@ function uninstalledWorkspaceBlockers(repoPath: string, references: ResolutionRe
|
|
|
1834
2164
|
set.add(ref.importer);
|
|
1835
2165
|
}
|
|
1836
2166
|
return [...importers].sort(([a], [b]) => a.localeCompare(b)).map(([name, files]) => ({
|
|
1837
|
-
reason: `Workspace package ${name} is imported by ${files.size} file${files.size === 1 ? "" : "s"} but
|
|
2167
|
+
reason: `Workspace package ${name} is imported by ${files.size} file${files.size === 1 ? "" : "s"} but DiffCI cannot map the import to the package's source files; point the package's types entry at a tsconfig outDir or declarationDir with a rootDir, or at source`,
|
|
1838
2168
|
directories: [packages.get(name)!],
|
|
1839
2169
|
}));
|
|
1840
2170
|
}
|
|
@@ -25,6 +25,7 @@ export type ImpactReason =
|
|
|
25
25
|
| "TEST_FIXTURE_OWNER"
|
|
26
26
|
| "ALWAYS_RUN_POLICY"
|
|
27
27
|
| "DECLARED_INPUT"
|
|
28
|
+
| "GO_TESTDATA"
|
|
28
29
|
| "ROUTE_VISIT"
|
|
29
30
|
| "DELETED_FILE_LEGACY_DEPENDENTS"
|
|
30
31
|
| "DELETED_FILE_UNKNOWABLE_GRAPH"
|
|
@@ -33,6 +34,7 @@ export type ImpactReason =
|
|
|
33
34
|
| "DIRECT_TEST_CHANGE"
|
|
34
35
|
| "TEST_SELECTION_INVARIANT"
|
|
35
36
|
| "TEST_UNIVERSE_EMPTY"
|
|
37
|
+
| "WORKSPACE_TEST_UNIVERSE_EMPTY"
|
|
36
38
|
| "EMPTY_DELTA";
|
|
37
39
|
|
|
38
40
|
export interface ImpactEvidencePath {
|