feat(import): add --dependencies-depth flag to limit traversal depth#10373
Open
davidfirst wants to merge 8 commits into
Open
feat(import): add --dependencies-depth flag to limit traversal depth#10373davidfirst wants to merge 8 commits into
davidfirst wants to merge 8 commits into
Conversation
Contributor
There was a problem hiding this comment.
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
ImportOptionswithdependenciesDepth?: numberand 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. |
…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).
…, idiomatic bitMap assertions in e2e
…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
…n-integer/fractional depth cases
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.
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); |
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.
Adds
--dependencies-depth <n>tobit import, controlling how many levels deep to traverse when used with--dependenciesor--dependencies-head.1imports only direct dependencies,2adds 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
getManyRemoteComponentsfor the current batch and reads their direct deps (prod + dev + extension; matchesflattenedDependenciessemantics — 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 1imports only direct depsbit import scope/foo --dependencies --dependencies-depth 2adds the next levelbit import scope/foo --dependencies-head --dependencies-depth 1imports direct deps at headbit import scope/foo --dependencies(no depth) preserves existing all-transitive behavior--dependencies-depthwithout--dependencies/--dependencies-headerrors--dependencies-deptherror