Skip to content

Fix bundled gems warning for all subfeatures of hyphenated gems - #15908

Merged
hsbt merged 1 commit into
ruby:masterfrom
khasinski:fix-bundled-gems-warning-subfeatures
Feb 12, 2026
Merged

Fix bundled gems warning for all subfeatures of hyphenated gems#15908
hsbt merged 1 commit into
ruby:masterfrom
khasinski:fix-bundled-gems-warning-subfeatures

Conversation

@khasinski

@khasinski khasinski commented Jan 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #15822 - fix incorrect warning for subfeatures of hyphenated gems like benchmark/timing when benchmark-ips is in the Gemfile. I've only checked loading ips, but wasn't enough 😅

Problem

After #15822, users still get warnings when using gems like benchmark-ips:

$ bundle exec ruby -v script.rb
ruby 4.0.1 (2026-01-13 revision e04267a14b) +PRISM [x86_64-linux]
benchmark/timing is found in benchmark, which is not part of the default gems since Ruby 4.0.0.

This happens because benchmark-ips provides multiple files:

  • benchmark/ips.rb
  • benchmark/timing.rb
  • benchmark/compare.rb

The fix in #15822 only checks for exact hyphenated match (benchmark/timingbenchmark-timing), but benchmark-timing gem doesn't exist.

Solution

Instead of checking for exact hyphenated gem name, check if ANY gem matching {prefix}-* is in the bundle specs:

# Before: only checks for benchmark-timing (doesn't exist)
hyphenated_gem = "#{feature_parts[0]}-#{feature_parts[1]}"
return if specs.include?(hyphenated_gem)

# After: checks for any benchmark-* gem (finds benchmark-ips)
prefix = feature.split("/").first + "-"
return if specs.any? { |spec, _| spec.start_with?(prefix) }

Test

Added test case for benchmark/timing and benchmark/compare with benchmark-ips in specs.

PR ruby#15822 fixed the warning for direct hyphenated gem requires like
`benchmark/ips` → `benchmark-ips`. However, hyphenated gems often
provide multiple files under their namespace.

For example, `benchmark-ips` provides:
- benchmark/ips.rb
- benchmark/timing.rb
- benchmark/compare.rb

When requiring `benchmark/timing`, the previous fix only checked for
`benchmark-timing` gem (doesn't exist), not `benchmark-ips` which
actually provides the file.

This fix checks if ANY gem matching `{prefix}-*` is in the bundle
specs, which covers all subfeatures provided by hyphenated gems.

Reported in ruby#15822 (comment)
@hsbt hsbt self-assigned this Jan 26, 2026

@hsbt hsbt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I consider about resolv-replace-foo case. But I don't know of any famous gems with that name.

I'm +1 to this change. Thanks!

@hsbt
hsbt merged commit b698c35 into ruby:master Feb 12, 2026
92 checks passed
@hsbt hsbt mentioned this pull request Feb 12, 2026
@khasinski
khasinski deleted the fix-bundled-gems-warning-subfeatures branch February 12, 2026 13:09
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