Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Direct development dependencies that are also transitively production remain incorrectly classified as development.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds experiment-gated Bun lockfile graph traversal to classify transitive dependencies as production or development.
Changes:
- Resolves dependency types across workspaces and nested package copies.
- Adds production metadata to parsed lockfile dependencies.
- Adds unit, integration, and
bun whyoracle coverage.
File summaries
| File | Description |
|---|---|
bun/lib/dependabot/bun/file_parser/bun_lock.rb |
Integrates experiment-gated classification. |
bun/lib/dependabot/bun/file_parser/bun_lock/record.rb |
Extracts dependency graph edges. |
bun/lib/dependabot/bun/file_parser/bun_lock/workspace.rb |
Models workspace graph roots. |
bun/lib/dependabot/bun/file_parser/bun_lock/dependency_type_resolver.rb |
Walks and classifies the dependency graph. |
bun/spec/dependabot/bun/file_parser/bun_lock_spec.rb |
Tests metadata and workspace parsing. |
bun/spec/dependabot/bun/file_parser/bun_lock/dependency_type_resolver_spec.rb |
Tests graph resolution behavior. |
bun/spec/dependabot/bun/file_parser/bun_lock/dependency_type_resolver_bun_why_spec.rb |
Compares results with bun why. |
bun/spec/dependabot/bun/dependency_grapher_spec.rb |
Tests dependency graph runtime flags. |
bun/spec/fixtures/projects/bun/workspace_dependency_types/bun.lock |
Adds a workspace graph fixture. |
bun/spec/fixtures/projects/bun/workspace_dependency_types/package.json |
Defines root fixture dependencies. |
bun/spec/fixtures/projects/bun/workspace_dependency_types/packages/app/package.json |
Defines application workspace dependencies. |
bun/spec/fixtures/projects/bun/workspace_dependency_types/packages/tool/package.json |
Defines tool workspace dependencies. |
Review details
- Files reviewed: 11/12 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
🟡 Changes recommended
The new specs bypass required strict Sorbet typing, and enabled parsing redundantly processes the lockfile graph twice.
Get a fresh assessment by requesting another Copilot review.
Review details
- Files reviewed: 16/18 changed files
- Comments generated: 3
- Review effort level: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
Bun’s full-unlock update path drops the new metadata, causing updated dependencies to regain the incorrect development classification.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
bun/lib/dependabot/bun/file_parser.rb:265
- This classification is lost on Bun's full-unlock update path.
Bun::UpdateChecker#build_updated_dependencydefaults the new dependency's metadata to{}, whileVersionResolveronly suppliesdependency,version, andprevious_version; consequently a directdevDependencymarked here as production-reachable becomes development again in theDependencyChange, and commit-message generation still selectsdeps-dev. Preserveoriginal_dep.metadatawhen building updated dependencies (while merging explicit metadata such asinformation_only) and cover that update path.
requirement: requirement_for(requirement),
- Files reviewed: 16/18 changed files
- Comments generated: 0 new
- Review effort level: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
Bun’s full-unlock update path discards the new classification metadata before PR naming.
Get a fresh assessment by requesting another Copilot review.
Review details
- Files reviewed: 18/20 changed files
- Comments generated: 1
- Review effort level: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
Unresolved fallback handling can incorrectly mark orphan or unknown lockfile records as production-reachable.
Review details
Suppressed comments (4)
bun/lib/dependabot/bun/file_parser.rb:219
- This treats the fallback
{ production: true }for unknown package keys (set insubdependency_metadata_for) as proof that the package is reachable from a production root. A stale/orphan lockfile record, or a parsed lockfile with no workspace roots, can therefore add a directdevDependenciespackage to this set and makeDependency#production?ignore its development group even though no production path exists. Please derive this explicit flag only from keys present in the resolver's actual production reachability map; unknown/default-production entries should not be promoted toreachable_from_production.
lockfile_dependencies.dependencies.filter_map do |dep|
dep.name if dep.subdependency_metadata&.any? { |data| data[:production] == true }
end.to_set
bun/lib/dependabot/bun/file_parser/bun_lock.rb:130
fetch(key, true)treats every record that the workspace walk did not reach as production.production_reachable_namesthen uses any{ production: true }entry as evidence forreachable_from_production, so a stale/orphan lockfile record can make a manifest-onlydevDependencyproduction even though no production path reaches it. Keep the fallback for transitiveproduction?if needed, but derive the top-level reachability flag only from keys explicitly marked production by the resolver (or carry a separate reachability marker).
[{ production: production_by_key.fetch(key, true) }]
bun/lib/dependabot/bun/file_parser/bun_lock/dependency_type_resolver.rb:21
- This comment is grammatically incorrect: “packages” should be singular when modifying “key.”
# A parent packages key (nil for a workspace root) and the name of a package it pulls in.
bun/lib/dependabot/bun/file_parser/bun_lock/dependency_type_resolver.rb:33
- This comment is grammatically incorrect: “packages” should be singular when modifying “key.”
# Maps each reachable packages key to true (production) or false (development).
- Files reviewed: 18/20 changed files
- Comments generated: 0 new
- Review effort level: Lite
4b5ced0 to
1f1695b
Compare
|
🙏 @robaiken / @v-robaiken, seeking a review of these changes. |
Expose each workspaces entry as a graph root with its production and development names, and add Record#edge_names for the packages an entry installs. Nested copies installed for a workspace are keyed under the workspace's package name, so that name is kept as the key prefix. Both readers skip malformed data instead of raising, because only dependency type classification uses them.
bun.lock has no dev flag like package-lock.json, so walk the graph from every workspace root. A package is production if any path to it starts with a dependencies, optionalDependencies or peerDependencies entry, and development only if every path starts with devDependencies. Nested copies are found the way Bun keys them: under the closest parent first (e.g. "debug/ms"), then one level up at a time, keeping scoped names whole. The workspace_dependency_types fixture was generated with bun install and covers copies nested under packages and workspaces.
When enable_bun_subdependency_types is on, BunLock#dependencies sets subdependency_metadata from the dependency type resolver, the same contract npm and pnpm lockfiles use. Updater dependency-type rules, group rules, PR prefixes and dependency graph runtime flags then treat packages reached only through devDependencies as development. Every package gets an explicit production value. DependencySet joins metadata across copies of a package, so leaving production copies unmarked would make a package with one dev-only copy look dev-only. Packages that no workspace reaches stay production, as before.
Run bun why over lockfile fixtures and compare its answer with the resolver, so a Bun upgrade that changes how packages are keyed or linked fails a spec instead of mislabelling dependencies. A package is development when every path bun why prints starts at a dev entry. The spec skips itself when bun is not installed.
Hash#[] on T::Hash[Object, Object] already returns Object, so srb tc reports these casts as useless (error 7015).
…duction Dependency#production? decides top-level dependencies from requirement groups alone, and drops subdependency_metadata for them. A lockfile can show that a package declared only for development is also installed through a production dependency, but groups cannot express that. Ecosystems that know this can now set metadata[:reachable_from_production] to true. Dependencies without the flag behave as before.
FileParser#parse merges manifest dependencies before lockfile ones, so a package declared only in devDependencies becomes a top-level dependency and its lockfile subdependency_metadata is dropped. production? then checked only the devDependencies group, even when a production dependency also installs the package. With enable_bun_subdependency_types on, mark manifest dependencies whose lockfile copies include a production one with reachable_from_production. The direct_dev_transitive_production fixture was generated with bun install: debug depends on ms, which is also a direct devDependency.
With enable_bun_subdependency_types on, manifest dependencies read the lockfile DependencySet to find production reachability, and #parse then built it again. Each build parses bun.lock records and walks the whole dependency graph, so an enabled parse did that work twice. Cache the set so both consumers reuse it. #parse only merges it into its own set, so the cached set is not changed.
spoom srb bump reports that dependency_type_resolver.rb and workspace.rb type-check at strong, and CI requires files to use the highest sigil they pass.
Bun::UpdateChecker#build_updated_dependency set the new dependency's metadata from the update details only, and VersionResolver passes just the dependency and versions. A direct devDependency marked reachable_from_production by the parser became development again in the DependencyChange, so commit messages still used deps-dev. Merge the original dependency's metadata with any explicit metadata such as information_only. The security fix path now also copies the looked up top-level dependency's metadata onto each fix update.
Bun::UpdateChecker#build_updated_dependency rebuilt each dependency
without original_dep.subdependency_metadata. A transitive dependency
marked { production: false } by the lockfile parser became production
again, so its pull request used the deps scope instead of deps-dev.
Pass the original subdependency metadata through, alongside the parsed
metadata kept earlier. Specs now check the commit prefix for both a
development-only transitive dependency and a devDependency reachable
from production.
…ction production_reachable_names collected names from every lockfile copy, so a direct devDependency was marked reachable_from_production whenever any copy of that name was production. A root devDependency on ms@2.0.0 was flagged because debug installs its own nested debug/ms@2.1.2, even though the root's copy never ships to production. Look up the specific copy instead: a workspace's own nested key (such as app/ms) first, then the hoisted key. BunLock caches the resolver result so dependency parsing and these lookups share one graph walk. The direct_dev_unrelated_production_copy fixture was generated with bun install.
DependencySet#combined_dependency kept only the first declaration's metadata. Bun parses the root manifest before workspace manifests, so a workspace declaration marked reachable_from_production was dropped, and a package that both manifests declare for development still reported development. Keep the first declaration's metadata, and set reachable_from_production when either declaration has it.
…file LockfileParser#reachable_from_production? checked every candidate lockfile, so a workspace with its own bun.lock had a development-only copy marked production when the root lockfile had a production copy of the same name. Pick the lockfile the same way as #lockfile_details: the closest one to the manifest that has the dependency.
The multi_manifest_dev_dependency fixture, generated with bun install, has the root and app both declare ms for development. app's own copy is installed by its production debug, so the combined dependency is production. bun why reports each name and version once across all copies, so the oracle spec now treats a name and version as development only when every copy is.
…data DependencySet and the Bun update checker each combined dependency metadata their own way, and the Bun checker let explicit metadata override reachable_from_production. Add Dependency.combine_metadata, which merges extra metadata over a base while keeping flags in ANY_TRUE_METADATA_KEYS true when either side sets them. DependencySet passes only those flags from the added declaration, so it still keeps the first declaration's other metadata.
build_updated_dependency merged explicit update metadata over the original dependency's metadata, so explicit metadata could drop reachable_from_production. Use Dependency.combine_metadata so explicit details such as information_only still merge, but the flag is kept.
The parser read a workspace declaration's version and source from the hoisted copy (BunLock#details only looks up the name), but its dependency type from the workspace's nested copy. In multi_manifest_dev_dependency, app declares ms@2.1.2 and has its own app/ms@2.1.2, yet the version came from the root's ms@2.0.0. A lockfile with only the nested copy was also skipped, so a farther lockfile could be used instead. Add LockfileParser#manifest_copy. It takes the closest lockfile whose BunLock#manifest_key finds the workspace's nested key or the hoisted key, and returns that copy's details and production reachability together. FileParser uses it for the version, source and reachable_from_production. Resolving the workspace copy is not behind the experiment, because it also corrects workspace declaration versions.
1f1695b to
4e28a6f
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
Approval is deferred because Bun-specific graph resolution across workspace roots, nested copies, peers, and security metadata requires runtime-parity and container-update validation that was unavailable in the static review environment.
No open issues 🎉
Review effort: Lite
💁 These changes let Dependabot tell development and production dependencies apart for Bun packages that are only in
bun.lock, and keep that answer through updates.What are you trying to accomplish?
For direct dependencies, Bun reads the
package.jsongroup. Transitive dependencies get nosubdependency_metadata, soDependency#production?always returnstruefor them. As a result, a package reached only throughdevDependencies(for example@types/nodevia@types/bun):allow: dependency-type: development, and included withproductiondependency-type: productiongroupsdepscommit prefix instead ofdeps-devruntime: truenpm and pnpm avoid this by reading a
devflag from their lockfiles.bun.lockhas no such flag, but it does list each workspace'sdependenciesanddevDependencies, and each package's children. This PR walks that graph:dependencies,optionalDependenciesorpeerDependenciesentry on a workspace.devDependencies.debug/ms, orapp/msfor a workspace namedapp), then one level up at a time.Where the result is used:
subdependency_metadatain the same shape npm and pnpm use.app/ms) if there is one, otherwise the hoisted copy.LockfileParser#manifest_copyfinds that copy once, and the parser takes the version, the source and the dependency type from it. A package declared only indevDependenciesis production when its copy is on a production path; other copies of the same name do not count. The parser setsmetadata[:reachable_from_production], andDependency#production?(incommon/) returnstruewhen that flag is set.Dependency.combine_metadata(incommon/) merges metadata but keepsreachable_from_productiontrue when either side sets it.DependencySet#combined_dependencyuses it when declarations are combined, andBun::UpdateChecker#build_updated_dependencyuses it to merge explicit metadata such asinformation_onlyover the parsed metadata, so an update can never drop the flag.subdependency_metadatatoo, and the security fix path copies the parsed top-level dependency's metadata onto each fix update. The PR commit prefix therefore matches the parsed type.Dependency classification is behind a new experiment,
enable_bun_subdependency_types, because it changes which packages match existingdependency-typerules. Resolving a workspace declaration's own copy is not behind it, because it also corrects the version and source of workspace declarations.Anything you want to highlight for special attention from reviewers?
common/changes are small and opt-in. Requirement groups can't express "declared for development but installed through production", andPackageJsonUpdateruses groups to find the section to edit. A metadata flag read byproduction?, and kept byDependency.combine_metadata, avoids changing groups.DependencySetstill keeps the first declaration's other metadata, so other ecosystems do not change.ms@2.0.0stays development even when a productiondebuginstalls its own separatedebug/ms@2.1.2.bun whyat parse time?bun whygives Bun's own answer, but its output is a text tree for people, and using it would mean runningbunon every parse. Instead,dependency_type_resolver_bun_why_spec.rbrunsbun whyon 7 fixtures and checks it agrees with the resolver, so a Bun upgrade that changes the rules fails a spec. It skips itself whenbunis not installed.productionvalue, not only dev ones.DependencySetjoinssubdependency_metadataacross copies of a package. Leaving production copies unmarked would make a package with one dev-only copy look dev-only.peerDependenciesare production.bun whylabels thempeer, notdev.BunLockcaches the resolver result, which both dependency parsing and the manifest copy lookups use, and the parser builds the lockfile dependency set once.workspace_dependency_types,direct_dev_transitive_production,direct_dev_unrelated_production_copyandmulti_manifest_dev_dependencywere generated withbun install(Bun 1.4.2), then set tolockfileVersion1, because the parser rejects anything higher. Theworkspacesandpackagesshapes they use are the same in both versions.typed: strong, asspoom srb bumprequires, and the new spec files usetyped: strict.How will you know you've accomplished your goal?
DependencyTypeResolverspecs cover thesimple_v1,wildcardand workspace fixtures, plus synthetic cases: a package on both paths, cycles, nested copies under a scoped package, and walking up past a missing nested copy.bun_lock_specchecks per-version and combinedproduction?with the experiment on, and no metadata with it off. It also checksmanifest_keyandproduction_reachable?: the root'smsis development whileapp's nestedmsis production.lockfile_parser_specchecksmanifest_copy: a workspace with its ownbun.lockgets that lockfile's version and type, a lockfile with only the workspace's nested copy is used instead of a farther one, and one lockfile gives the root and a workspace their own copies.file_parser_specchecks three direct dependency cases with the experiment on: a devDependency whose own copy production installs is production; a devDependency with only an unrelated production copy stays development; and a package both manifests declare for development is production when the workspace's copy is, with each declaration's version taken from its own copy. It also checks the lockfile set is built once.dependency_grapher_specchecks@types/nodereportsruntime: falsewith the experiment on, andruntime: truewith it off.update_checker_specchecks full-unlock updates keep both classification fields and give the right commit prefix:chore(deps-dev):for a dev-only transitive dependency, andbuild(deps):for a devDependency reachable from production. It also checksinformation_onlyis merged, explicitreachable_from_production: falsecannot drop the flag, and the security fix path keeps the parent's metadata.dependency_specanddependency_set_spec(common) check thereachable_from_productionflag,Dependency.combine_metadata, and combining declarations.bun whyoracle spec passes with the Bun 1.3.14 bundled in the image.bunsuite 482 examples, 0 failures; commondependency_specanddependency_set_spec77 examples, 0 failures. Rubocop is clean on the changed files.Checklist
bunsuite, the common specs above and rubocop, but not other ecosystems orsrb tc, which CI runs.)