feat(deps): parse Cargo build-dependencies and target.* dependency tables#93
Merged
Merged
Conversation
…bles extractCargoDependencies only recognized [dependencies]/[dev-dependencies], so [build-dependencies] and platform-specific [target.<spec>.dependencies] tables were silently dropped, undercounting deps for many real Rust crates. Now also parse: - [build-dependencies] (+ detailed .<crate> tables) → dev (build.rs-only, not shipped at runtime; the Dependency type enum has no "build" member, so "dev" is the accurate non-runtime bucket) - [target.<triple-or-cfg>.dependencies] → runtime - [target.<...>.dev-dependencies] / [target.<...>.build-dependencies] → dev The target prefix is matched with an optional, backtracking `target.<spec>.` group so cfg() expressions and dotted triples (which contain dots, quotes, and parens) classify correctly. [features]/[profile]/[[bin]] are still ignored, and the existing dedup-by-section-key behavior is preserved. Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR expands the Rust Cargo.toml dependency extraction so dependency tables beyond the top-level [dependencies] / [dev-dependencies] are no longer silently ignored, improving accuracy for crates that use build tooling deps (build.rs) and platform-gated deps.
Changes:
- Extend Cargo parsing to recognize
[build-dependencies](including detailed.<crate>tables) and classify them asdev. - Add support for platform-specific
[target.<spec>.(dependencies|dev-dependencies|build-dependencies)]tables, mappingdependencies→runtimeand the others →dev. - Add targeted tests covering build deps, target cfg/triple tables, dedup behavior, and continued ignoring of
[features]/[profile].
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/deps.ts |
Updates Cargo table-header recognition to include build-dependencies and target.* tables; maps build/dev tables to dev and keeps non-dependency tables from leaking keys into results. |
test/deps-parsers.test.ts |
Adds new Cargo-focused unit tests validating classification, detailed-table version backfill, dedup across target/runtime deps, and ignoring non-dependency tables. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
extractCargoDependenciesonly recognized[dependencies]and[dev-dependencies], so[build-dependencies]and platform-specific[target.<spec>.dependencies]tables were silently dropped — undercounting dependencies for a large class of real Rust crates (anything usingbuild.rsdeps likecc/bindgen, or platform-gated deps likewinapi/nix).Now also parses:
[build-dependencies](+ detailed.<crate>tables) → dev. Build-deps run only at compile time (build.rs) and aren't shipped in the runtime artifact. TheDependency.typeenum has no"build"member, so"dev"(not-shipped-at-runtime tooling) is the accurate bucket and keepstotalCountcorrect.[target.<triple-or-cfg>.dependencies]→ runtime[target.<...>.dev-dependencies]/[target.<...>.build-dependencies]→ devImplementation note
The target prefix is matched with an optional, backtracking
(?:target\..+\.)?group, socfg()expressions and dotted triples — which contain dots, quotes, and parens (e.g.[target.'cfg(windows)'.dependencies],[target.x86_64-pc-windows-msvc.dependencies]) — classify correctly, and the existing[dependencies.<crate>]detailed-table path extends for free to[target.<x>.dependencies.<crate>].[features]/[profile]/[[bin]]are still ignored, and dedup-by-${section}:${name}is preserved.Test plan
[features]/[profile]still ignored, dedup across[dependencies]+[target.*][dependencies.<crate>]) still pass