[7.1 API] Equivalent of `BuilderProgram.getAllDependencies` / batched module resolution
维护者通常 1 天内回复
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- typescript
- 领域
- api
调研方向
Start by reading the Program API changes in #64247 and the builder/watch/solution-builder scope discussion in #64709, then compare the batched methods in #63904. The issue proposes either a server-side dependency graph method or batched module resolution, without choosing between them. Done means an API direction is agreed on and it addresses the per-import IPC cost and project-reference redirects described here.
由索引模型根据 Issue 内容生成。
描述
🔍 Search Terms
getAllDependencies, dependency graph, getResolvedModule, batched, 7.1 API, typescript/sync, typescript/async
✅ Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
⭐ Suggestion
In TypeScript ≤ 6, BuilderProgram.getAllDependencies(sourceFile) returned the transitive set of files a given source file depends on (module imports, /// <reference path>, type reference directives, and project-reference redirects).
With the 7.1 beta, builder/watch/solution-builder APIs are explicitly out of scope for stable (#64709), so there is no equivalent. The building blocks are mostly present (program.getSourceFileNames(), program.getSourceFile(), and the new program.getResolvedModule() / getResolvedTypeReferenceDirective() from #64247), but reconstructing the dependency graph requires one IPC round-trip per import per file, which gets expensive quickly on larger projects.
I'd like to request one (or both) of the following:
- A dependency-graph method on
Program— e.g.program.getAllDependencies(sourceFile)orprogram.getDependencies(sourceFile)returning the direct/transitive dependency file names, computed server-side. - A batched resolution method — e.g.
program.getResolvedModules(sourceFile)returning all resolutions for a file in a single call, similar in spirit to the batched methods added in #63904. This would let consumers build the graph themselves with one call per file instead of one call per import.
Option 1 is the ergonomic fit for the old API; option 2 is a smaller primitive and can be used independently.
📃 Motivating Example
I use getAllDependencies in StrykerJS to identify inrelated files and use that to implement mutant grouping (a roughly 50% performance improvement over single mutant validation). Migrating to 7.1 currently means re-implementing the traversal client-side.
Current client-side reconstruction (7.1 beta) (using AI)
import { API } from "typescript/sync";
function getAllDependencies(program: Program, rootFileName: string) {
const seen = new Set<string>();
const queue = [rootFileName];
while (queue.length) {
const fileName = queue.pop()!;
if (seen.has(fileName)) continue;
seen.add(fileName);
const sf = program.getSourceFile(fileName);
if (!sf) continue;
// One round-trip per import
for (const imp of sf.imports) {
const r = program.getResolvedModule(sf, imp.text /*, mode */);
if (r?.resolvedModule) queue.push(r.resolvedModule.resolvedFileName);
}
// One round-trip per type reference directive
for (const ref of sf.typeReferenceDirectives) {
const r = program.getResolvedTypeReferenceDirective(sf, ref.fileName);
if (r?.resolvedTypeReferenceDirective?.resolvedFileName) {
queue.push(r.resolvedTypeReferenceDirective.resolvedFileName);
}
}
for (const ref of sf.referencedFiles) {
queue.push(resolve(dirname(fileName), ref.fileName));
}
}
seen.delete(rootFileName);
return [...seen];
}
Issues with this approach:
- Round-trip count scales with total import count, not file count.
- Project-reference output redirects (handled by the old builder method) have to be reimplemented manually.
- Resolution mode (
ESNextvsCommonJS) must be derived client-side per import.
💻 Use Cases
- What do you want to use this for?
Generate a list of unrelated files so we can validate multiple mutants in a single type-check run.
- What shortcomings exist with current approaches?
Per-import IPC calls make the client-side traversal slow on large graphs, and project-reference redirects are easy to get subtly wrong.
- What workarounds are you using in the meantime?
The reconstruction above.
- 主要语言
- Go
- 星标
- 112k
- 派生
- 15.4k
- 平均合并
- 2 天 21 小时
- 30 天内合并 PR
- 126
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/TypeScript 的其他 Issue
-
Won't Fix
难度 2/5 1-3 小时 新手友好度 62/100
microsoft/TypeScript#65107 · 1 条评论 ·
维护者通常 1 天内回复
-
Native API: formatDiagnosticsWithColorAndContext drops related information without a file location可能已有人在做 @timurzvural 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
microsoft/TypeScript#65087 ·
维护者通常 1 天内回复
-
TS7 LSP: documentHighlight returns nothing when the file path contains '@'可能重新可做 关联的 PR 已关闭且未合并。 未关闭Bug
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/TypeScript#64758 ·
维护者通常 1 天内回复
-
Language server (tsc --lsp) exits with code 1 after `shutdown` and `exit`可能已有人在做 @rajnish-verma-22172 于 12 天前认领。 未关闭Bug
难度 2/5 1-3 小时 新手友好度 76/100
microsoft/TypeScript#64742 · 1 条评论 ·
维护者通常 1 天内回复
-
Class names `eval` and `arguments` are not reported as invalid strict mode bindings可能已有人在做 @dmety 于 26 天前认领。 未关闭Bug
难度 2/5 1-3 小时 新手友好度 68/100
microsoft/TypeScript#64661 ·
维护者通常 1 天内回复
查看 microsoft/TypeScript 的全部 Issue
相似的 Issue
-
bug good first issue help wanted
难度 2/5 1-3 小时 新手友好度 70/100
-
[mesheryctl] design delete fails when passing file or URL as positional argument可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭component/mesheryctl kind/bug language/go
难度 2/5 1-3 小时 新手友好度 74/100
meshery/meshery#22772 · 3 条评论 ·
维护者通常 1 天内回复
-
backend security size:S
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
limitlessprojects/Go-Hybrid#3342 ·
维护者通常 1 天内回复
-
status/ready type/bug
难度 2/5 1-3 小时 新手友好度 65/100
buildpacks/pack#2733 ·
维护者通常 1 天内回复