Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/rbs/collection/config/lockfile_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def generate
end
end
else
unless NONGEM_STDLIBS.include?(name)
unless NONGEM_STDLIBS.include?(name) || default_gem?(name)
RBS.logger.warn "Cannot find `#{name}` gem. Using incorrect Bundler context? (#{definition.lockfile})"
end
end
Expand Down Expand Up @@ -250,6 +250,11 @@ def generate
end
end

# Default gems are always available without being listed in Gemfile.lock.
private def default_gem?(name)
Gem::Specification.default_stubs("#{name}-*.gemspec").any? { |stub| stub.name == name }
end

private def find_source(name:)
sources = config.sources

Expand Down
4 changes: 4 additions & 0 deletions sig/collection/config/lockfile_generator.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ module RBS
#
def assign_stdlib: (name: String, ?from_gem: String) -> void

# Returns `true` if a default gem with the name is installed.
#
def default_gem?: (String name) -> bool

# Find a source of a gem from ones registered in `config.sources`
#
# Returns `nil` if no source contains the definition of the gem.
Expand Down
6 changes: 6 additions & 0 deletions sig/shims/rubygems.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ module Gem

def self.find_by_name: (String name, *String requirements) -> instance

def self.default_stubs: (?String pattern) -> Array[StubSpecification]

def dependencies: () -> Array[Dependency]
end

class StubSpecification
def name: () -> String
end

class Dependency
def name: () -> String
end
Expand Down
7 changes: 6 additions & 1 deletion test/rbs/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,12 @@ def test_collection_install__pathname_set
bundle_install('ast', 'logger', 'tsort')
_stdout, stderr = run_rbs_collection("install", bundler: true)

assert_include stderr, 'Cannot find `set` gem.'
# `set` is a default gem until Ruby 3.5, where it became a core class.
if Gem::Specification.default_stubs("set-*.gemspec").any? { _1.name == "set" }
refute_match(/Cannot find `set` gem/, stderr)
else
assert_include stderr, 'Cannot find `set` gem.'
end

lockfile = RBS::Collection::Config::Lockfile.from_lockfile(
lockfile_path: dir + "rbs_collection.lock.yaml",
Expand Down
44 changes: 44 additions & 0 deletions test/rbs/collection/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,50 @@ def test_generate_lockfile__gems_not_included_in_gemfile
end
end

def test_generate_lockfile__default_gems_not_included_in_gemfile
omit unless Gem::Specification.default_stubs("un-*.gemspec").any? { _1.name == "un" }

mktmpdir do |tmpdir|
config_path = tmpdir / 'rbs_collection.yaml'
config_path.write <<~YAML
sources: []
path: '.gem_rbs_collection'
gems:
- name: un
YAML
gemfile_path = tmpdir / 'Gemfile'
gemfile_path.write <<~GEMFILE
source 'https://rubygems.org'
GEMFILE
gemfile_lock_path = tmpdir / 'Gemfile.lock'
gemfile_lock_path.write <<~GEMFILE_LOCK
GEM
remote: https://rubygems.org/
specs:

PLATFORMS
x86_64-linux

DEPENDENCIES

BUNDLED WITH
2.2.0
GEMFILE_LOCK

definition = Bundler::Definition.build(gemfile_path, gemfile_lock_path, false)

log = StringIO.new
RBS.logger_output = log
begin
RBS::Collection::Config.generate_lockfile(config_path: config_path, definition: definition)
ensure
RBS.logger_output = nil
end

refute_match(/Cannot find `un` gem/, log.string)
end
end

def test_generate_lockfile__dependency_source
mktmpdir do |tmpdir|
config_path = tmpdir / 'rbs_collection.yaml'
Expand Down
Loading