Skip to content

bun: Classify transitive dependencies as production or development - #16287

Open
sgerrand wants to merge 20 commits into
dependabot:mainfrom
sgerrand:feat/bun-subdependency-types
Open

sgerrand wants to merge 20 commits into
dependabot:mainfrom
sgerrand:feat/bun-subdependency-types

Conversation

@sgerrand

@sgerrand sgerrand commented Sep 13, 2026 •

Copy link
Copy Markdown

💁 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.json group. Transitive dependencies get no subdependency_metadata, so Dependency#production? always returns true for them. As a result, a package reached only through devDependencies (for example @types/node via @types/bun):

  • is skipped by security updates with allow: dependency-type: development, and included with production
  • lands in dependency-type: production groups
  • gets the deps commit prefix instead of deps-dev
  • is sent to the dependency graph with runtime: true

npm and pnpm avoid this by reading a dev flag from their lockfiles. bun.lock has no such flag, but it does list each workspace's dependencies and devDependencies, and each package's children. This PR walks that graph:

  • A package is production if any path to it starts with a dependencies, optionalDependencies or peerDependencies entry on a workspace.
  • It is development only if every path starts with devDependencies.
  • Nested copies are found the way Bun keys them: under the closest parent first (debug/ms, or app/ms for a workspace named app), then one level up at a time.

Where the result is used:

  • Transitive dependencies: the result goes into subdependency_metadata in the same shape npm and pnpm use.
  • Direct dependencies: each manifest dependency resolves to one lockfile copy: the closest lockfile that has it, and in that lockfile the workspace's nested copy (such as app/ms) if there is one, otherwise the hoisted copy. LockfileParser#manifest_copy finds that copy once, and the parser takes the version, the source and the dependency type from it. A package declared only in devDependencies is production when its copy is on a production path; other copies of the same name do not count. The parser sets metadata[:reachable_from_production], and Dependency#production? (in common/) returns true when that flag is set.
  • Several manifests: when the root and a workspace both declare a package, it is production if any declaration's copy is.
  • Combining metadata: Dependency.combine_metadata (in common/) merges metadata but keeps reachable_from_production true when either side sets it. DependencySet#combined_dependency uses it when declarations are combined, and Bun::UpdateChecker#build_updated_dependency uses it to merge explicit metadata such as information_only over the parsed metadata, so an update can never drop the flag.
  • Updates: updated dependencies keep subdependency_metadata too, 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 existing dependency-type rules. 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?

  • The common/ changes are small and opt-in. Requirement groups can't express "declared for development but installed through production", and PackageJsonUpdater uses groups to find the section to edit. A metadata flag read by production?, and kept by Dependency.combine_metadata, avoids changing groups. DependencySet still keeps the first declaration's other metadata, so other ecosystems do not change.
  • Workspace declarations now read their own copy. Before, a workspace declaration's version and source came from the hoisted copy even when the workspace had its own nested copy. This applies to all Bun jobs.
  • Only the dependency's own copy counts. A root devDependency on ms@2.0.0 stays development even when a production debug installs its own separate debug/ms@2.1.2.
  • Why walk the lockfile in Ruby, not run bun why at parse time? bun why gives Bun's own answer, but its output is a text tree for people, and using it would mean running bun on every parse. Instead, dependency_type_resolver_bun_why_spec.rb runs bun why on 7 fixtures and checks it agrees with the resolver, so a Bun upgrade that changes the rules fails a spec. It skips itself when bun is not installed.
  • Every transitive package gets an explicit production value, not only dev ones. DependencySet joins subdependency_metadata across copies of a package. Leaving production copies unmarked would make a package with one dev-only copy look dev-only.
  • Packages no workspace reaches stay production, which is the existing behaviour.
  • Root peerDependencies are production. bun why labels them peer, not dev.
  • One graph walk per lockfile. BunLock caches the resolver result, which both dependency parsing and the manifest copy lookups use, and the parser builds the lockfile dependency set once.
  • Fixtures: workspace_dependency_types, direct_dev_transitive_production, direct_dev_unrelated_production_copy and multi_manifest_dev_dependency were generated with bun install (Bun 1.4.2), then set to lockfileVersion 1, because the parser rejects anything higher. The workspaces and packages shapes they use are the same in both versions.
  • Sigils: the new lib files use typed: strong, as spoom srb bump requires, and the new spec files use typed: strict.

How will you know you've accomplished your goal?

  • DependencyTypeResolver specs cover the simple_v1, wildcard and 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_spec checks per-version and combined production? with the experiment on, and no metadata with it off. It also checks manifest_key and production_reachable?: the root's ms is development while app's nested ms is production.
  • lockfile_parser_spec checks manifest_copy: a workspace with its own bun.lock gets 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_spec checks 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_spec checks @types/node reports runtime: false with the experiment on, and runtime: true with it off.
  • update_checker_spec checks full-unlock updates keep both classification fields and give the right commit prefix: chore(deps-dev): for a dev-only transitive dependency, and build(deps): for a devDependency reachable from production. It also checks information_only is merged, explicit reachable_from_production: false cannot drop the flag, and the security fix path keeps the parent's metadata.
  • dependency_spec and dependency_set_spec (common) check the reachable_from_production flag, Dependency.combine_metadata, and combining declarations.
  • The bun why oracle spec passes with the Bun 1.3.14 bundled in the image.
  • On the current head: full bun suite 482 examples, 0 failures; common dependency_spec and dependency_set_spec 77 examples, 0 failures. Rubocop is clean on the changed files.

Checklist

  • I have run the complete test suite to ensure all tests and linters pass. (I ran the full bun suite, the common specs above and rubocop, but not other ecosystems or srb tc, which CI runs.)
  • I have thoroughly tested my code changes to ensure they work as expected, including adding additional tests for new functionality.
  • I have written clear and descriptive commit messages.
  • I have provided a detailed description of the changes in the pull request, including the problem it addresses, how it fixes the problem, and any relevant details about the implementation.
  • I have ensured that the code is well-documented and easy to understand.

@sgerrand
sgerrand requested a review from a team as a code owner September 13, 2026 16:19
Copilot AI balanced review requested due to automatic review settings September 13, 2026 16:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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 why oracle 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.

Copilot AI review requested due to automatic review settings September 13, 2026 16:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The graph traversal is consistent with the described semantics and has comprehensive focused coverage.

Review details
  • Files reviewed: 11/12 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Copilot AI review requested due to automatic review settings September 13, 2026 16:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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

Comment thread bun/lib/dependabot/bun/file_parser.rb Resolved
Copilot AI review requested due to automatic review settings September 13, 2026 16:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 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_dependency defaults the new dependency's metadata to {}, while VersionResolver only supplies dependency, version, and previous_version; consequently a direct devDependency marked here as production-reachable becomes development again in the DependencyChange, and commit-message generation still selects deps-dev. Preserve original_dep.metadata when building updated dependencies (while merging explicit metadata such as information_only) and cover that update path.
            requirement: requirement_for(requirement),
  • Files reviewed: 16/18 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Copilot AI review requested due to automatic review settings September 13, 2026 16:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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

Copilot AI review requested due to automatic review settings September 13, 2026 16:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings September 13, 2026 16:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sgerrand
sgerrand requested a balanced review from Copilot September 14, 2026 08:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 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 in subdependency_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 direct devDependencies package to this set and make Dependency#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 to reachable_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_names then uses any { production: true } entry as evidence for reachable_from_production, so a stale/orphan lockfile record can make a manifest-only devDependency production even though no production path reaches it. Keep the fallback for transitive production? 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

@v-kbukum1 v-kbukum1 moved this to Scoping in Dependabot Sep 14, 2026
Copilot AI review requested due to automatic review settings September 15, 2026 13:27
@sgerrand
sgerrand force-pushed the feat/bun-subdependency-types branch from 4b5ced0 to 1f1695b Compare October 16, 2026 10:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sgerrand

Copy link
Copy Markdown
Author

🙏 @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.
Copilot AI balanced review requested due to automatic review settings October 19, 2026 14:40
@sgerrand
sgerrand force-pushed the feat/bun-subdependency-types branch from 1f1695b to 4e28a6f Compare October 19, 2026 14:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI balanced review requested due to automatic review settings November 18, 2026 18:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@sgerrand
sgerrand requested a lite review from Copilot November 18, 2026 18:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Scoping

Development

Successfully merging this pull request may close these issues.

2 participants