Repository navigation
Add program.getAllDependencies to the API - #64942
Open
Adarsh (jackeddisciple) wants to merge 2 commits into
Open
Adarsh (jackeddisciple) wants to merge 2 commits into
Adarsh (jackeddisciple) wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 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
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #64920
The 7.x API had no equivalent of
BuilderProgram.getAllDependencies. Rebuilding a file's dependency graph meant onegetResolvedModuleround 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 throughapi.batchandbatchContext.Tests:
GetAllDependencies: transitive imports, module augmentations, ambient modules, triple slash references, type reference directives and global scope filesdisableSourceOfProjectReferenceRedirect, plus the missing file errorClaude Code was used for code review and quality checks. I tested the changes.