Skip to content

Add program.getAllDependencies to the API - #64942

Open
Adarsh (jackeddisciple) wants to merge 2 commits into
microsoft:mainfrom
jackeddisciple:getalldependencies-api
Open

Adarsh (jackeddisciple) wants to merge 2 commits into
microsoft:mainfrom
jackeddisciple:getalldependencies-api

Conversation

@jackeddisciple

@jackeddisciple Adarsh (jackeddisciple) commented Oct 23, 2026 •

Copy link
Copy Markdown

Fixes #64920

The 7.x API had no equivalent of BuilderProgram.getAllDependencies. Rebuilding a file's dependency graph meant one getResolvedModule round trip per import, and the client also had to redo resolution modes and project reference redirects itself.

This adds program.getAllDependencies(file) to the async, sync and generator APIs. It runs on the server and reuses the same reference collection the incremental builder uses for its referenced map: imports through checker symbols, /// <reference path>, type reference directives, module augmentations, ambient modules and project reference redirects. So the result matches what tsc itself tracks. Like the old builder method, the result includes the file itself (always first here), and a file that affects the global scope gets every file in the program. Everything else comes back in program order.

I left out a separate batched getResolvedModules, since per file batching already works through api.batch and batchContext.

Tests:

  • Go unit tests for GetAllDependencies: transitive imports, module augmentations, ambient modules, triple slash references, type reference directives and global scope files
  • API session tests for project references with and without disableSourceOfProjectReferenceRedirect, plus the missing file error
  • async and sync API tests, plus a generator parity case

Claude Code was used for code review and quality checks. I tested the changes.

Copilot AI balanced review requested due to automatic review settings October 23, 2026 20:21
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Oct 23, 2026
@typescript-automation typescript-automation Bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Oct 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Package-deduplication redirects can cause valid dependencies to be omitted from the returned list.

1 open issue
What changed in this PR

Adds program.getAllDependencies(file) to the TypeScript API, providing server-side dependency traversal without per-import round trips.

Changes:

  • Reuses incremental-builder reference collection to compute transitive dependencies.
  • Exposes the method through the protocol and async, sync, and generator APIs.
  • Adds coverage for dependency types, project-reference redirects, global-scope files, and missing files.
File Description
tsc/​internal/​execute/​incremental/​programtosnapshot.go Extracts reusable reference collection with a supplied checker.
tsc/​internal/​execute/​incremental/​dependencies.go Implements transitive dependency traversal and result ordering.
tsc/​internal/​execute/​incremental/​dependencies_test.go Tests dependency traversal and global-scope behavior.
tsc/​internal/​api/​session.go Dispatches and handles dependency requests.
tsc/​internal/​api/​session_dependencies_test.go Tests project-reference redirects and missing-file errors.
tsc/​internal/​api/​proto.go Registers the protocol method and parameters.
packages/​typescript/​test/​sync/​api.test.ts Adds synchronous API coverage.
packages/​typescript/​test/​sync/​api-generators.test.ts Adds generator parity coverage.
packages/​typescript/​test/​async/​api.test.ts Adds asynchronous API coverage.
packages/​typescript/​src/​api/​sync/​api.ts Exposes synchronous and generator methods.
packages/​typescript/​src/​api/​proto.generated.ts Adds generated protocol and batch types.
packages/​typescript/​src/​api/​async/​api.ts Exposes the asynchronous method.

Review effort: Balanced

Comment thread tsc/internal/execute/incremental/dependencies.go Outdated

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

[7.1 API] Equivalent of BuilderProgram.getAllDependencies / batched module resolution

2 participants