diff options
author | David RodrÃguez <[email protected]> | 2024-10-08 23:56:32 +0200 |
---|---|---|
committer | git <[email protected]> | 2024-10-14 17:51:24 +0000 |
commit | 48fdb9faa0a408c0855e84cfd6451393c8b67180 (patch) | |
tree | 06ea39baafebbd5c792532c9bba5387e0126460a /lib/rubygems/commands/contents_command.rb | |
parent | 57404e4369df11f77f089d5d11d310679b2e749f (diff) |
[rubygems/rubygems] Fix `gem contents` for default gems
A default gem does not always live in the same place. For example,
Bundler may be installed to `site_dir` when RubyGems have been upgraded.
A more reliable way seems to actually activate the default gem, so that
we can know for sure where it lives.
https://github.com/rubygems/rubygems/commit/c69f6dfb18
Diffstat (limited to 'lib/rubygems/commands/contents_command.rb')
-rw-r--r-- | lib/rubygems/commands/contents_command.rb | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/lib/rubygems/commands/contents_command.rb b/lib/rubygems/commands/contents_command.rb index 807158d9c9..bd0cbce8ba 100644 --- a/lib/rubygems/commands/contents_command.rb +++ b/lib/rubygems/commands/contents_command.rb @@ -103,16 +103,23 @@ prefix or only the files that are requireable. def files_in_default_gem(spec) spec.files.map do |file| - case file - when %r{\A#{spec.bindir}/} - # $' is POSTMATCH - [RbConfig::CONFIG["bindir"], $'] - when /\.so\z/ - [RbConfig::CONFIG["archdir"], file] + if file.start_with?("#{spec.bindir}/") + [RbConfig::CONFIG["bindir"], file.delete_prefix("#{spec.bindir}/")] else - [RbConfig::CONFIG["rubylibdir"], file] + gem spec.name, spec.version + + require_path = spec.require_paths.find do |path| + file.start_with?("#{path}/") + end + + requirable_part = file.delete_prefix("#{require_path}/") + + resolve = $LOAD_PATH.resolve_feature_path(requirable_part)&.last + next unless resolve + + [resolve.delete_suffix(requirable_part), requirable_part] end - end + end.compact end def gem_contents(name) |