Skip to content

feat(import): add --dependencies-depth flag to limit traversal depth#10373

Open
davidfirst wants to merge 8 commits into
masterfrom
feat/import-dependencies-depth
Open

feat(import): add --dependencies-depth flag to limit traversal depth#10373
davidfirst wants to merge 8 commits into
masterfrom
feat/import-dependencies-depth

Conversation

@davidfirst
Copy link
Copy Markdown
Member

@davidfirst davidfirst commented May 13, 2026

Adds --dependencies-depth <n> to bit import, controlling how many levels deep to traverse when used with --dependencies or --dependencies-head. 1 imports only direct dependencies, 2 adds direct deps of direct deps, and so on. Without the flag, the existing all-transitive behavior is preserved.

Implementation BFS-fetches one level at a time from the remote: each iteration calls getManyRemoteComponents for the current batch and reads their direct deps (prod + dev + extension; matches flattenedDependencies semantics — peers excluded). N levels = N round-trips, which is the deliberate tradeoff to keep depth honoring with the data actually delivered to the client.

Test plan

  • bit import scope/foo --dependencies --dependencies-depth 1 imports only direct deps
  • bit import scope/foo --dependencies --dependencies-depth 2 adds the next level
  • bit import scope/foo --dependencies-head --dependencies-depth 1 imports direct deps at head
  • bit import scope/foo --dependencies (no depth) preserves existing all-transitive behavior
  • --dependencies-depth without --dependencies/--dependencies-head errors
  • Non-positive / non-integer values for --dependencies-depth error

Copilot AI review requested due to automatic review settings May 13, 2026 20:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new --dependencies-depth <n> flag to bit import to limit how many dependency levels are imported when using --dependencies or --dependencies-head, while preserving the current “import all transitive deps” behavior when the flag is omitted.

Changes:

  • Adds CLI flag parsing/validation for --dependencies-depth, including enforcement that it’s only used alongside --dependencies/--dependencies-head.
  • Extends ImportOptions with dependenciesDepth?: number and wires it through to the importer.
  • Implements depth-limited dependency collection via BFS using Version.getFlattenedEdges().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
scopes/scope/importer/import.cmd.ts Adds the new CLI flag, help text, and validation, then forwards the parsed numeric depth into ImportOptions.
scopes/scope/importer/import-components.ts Adds dependenciesDepth option and implements depth-limited dependency collection (BFS) using flattened dependency edges.

Comment thread scopes/scope/importer/import-components.ts Outdated
Comment thread scopes/scope/importer/import-components.ts Outdated
…tive remote fetch

flattenedEdges Source isn't fetched by getManyRemoteComponents, so BFS through
a single Version's graph returned empty edges past level 1. Switch to fetching
one level at a time from the remote and walking direct deps (getAllDependenciesIds).
Copilot AI review requested due to automatic review settings May 13, 2026 21:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

Comment thread scopes/scope/importer/import-components.ts Outdated
Comment thread scopes/scope/importer/import-components.ts Outdated
Comment thread scopes/scope/importer/import-components.ts Outdated
Comment thread scopes/scope/importer/import-components.ts
…rsion

- getAllDependencies() (prod + dev + extension) matches flattenedDependencies semantics; was including peers via getAllDependenciesIds()
- root tracking switched to toStringWithoutVersion so versionless input IDs aren't re-added as deps
- e2e: add --dependencies-head --dependencies-depth coverage
Copilot AI review requested due to automatic review settings May 14, 2026 13:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread e2e/commands/import.e2e.ts
Comment thread e2e/commands/import.e2e.ts
Use importWithoutDeps to persist root versions (and their flattenedEdges Source) locally,
then walk the dependency graph in-process via Version.getFlattenedEdges. Replaces N sequential
remote round-trips with a single fetch.
Copilot AI review requested due to automatic review settings May 14, 2026 18:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment on lines +736 to +744
for (const { version } of componentsAndVersions) {
const edges = await version.getFlattenedEdges(this.scope.objects);
for (const edge of edges) {
const key = edge.source.toString();
const targets = adjacency.get(key);
if (targets) targets.push(edge.target);
else adjacency.set(key, [edge.target]);
}
}
Comment on lines +725 to +732
/**
* Single remote fetch; BFS in-process over each root version's `flattenedEdges`
* (which captures the full transitive graph rooted at that version).
*/
private async getDepsByDepth(bitIds: ComponentID[], depth: number): Promise<ComponentIdList> {
const idList = ComponentIdList.fromArray(bitIds);
await this.scope.scopeImporter.importWithoutDeps(idList, { cache: true, lane: this.remoteLane });
const componentsAndVersions = await this.scope.getComponentsAndVersions(idList);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants