Skip to content
Merged
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
13 changes: 10 additions & 3 deletions lib/rbs/collection/config/lockfile_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Config
class LockfileGenerator
# Stdlibs that used to be bundled in rbs-gem but are now maintained in their own gems.
#
# The key is the library name under `stdlib/` (not necessarily the gem name, see `ALUMNI_GEM_NAMES`).
# The value is the version requirement of the gem that ships the type definitions in its `sig/` directory,
# or `nil` if no released version of the gem ships them yet.
ALUMNI_STDLIBS = {
Expand All @@ -20,11 +21,16 @@ class LockfileGenerator
"minitest" => nil,
"net-smtp" => nil,
"nkf" => ">= 0.3.0",
"observer" => nil,
"observable" => nil,
"cgi" => nil,
"pstore" => nil,
}

# Stdlibs in `ALUMNI_STDLIBS` whose gem name differs from the library name.
ALUMNI_GEM_NAMES = {
"observable" => "observer",
}

NONGEM_STDLIBS = Set[
"cgi-escape",
"coverage",
Expand Down Expand Up @@ -217,12 +223,13 @@ def generate
return
when *ALUMNI_STDLIBS.keys
version = ALUMNI_STDLIBS.fetch(name)
gem_name = ALUMNI_GEM_NAMES.fetch(name, name)
if from_gem
# From `dependencies:` of a `manifest.yaml` of a gem
source = find_source(name: name) or raise
if source.is_a?(Sources::Stdlib) && version
RBS.logger.warn {
"`#{name}` is included in the RBS dependencies of `#{from_gem}`, but the type definition as a stdlib in rbs-gem is deprecated. Add `#{name}` (#{version}) to the dependency of your Ruby program to use the gem-bundled type definition."
"`#{name}` is included in the RBS dependencies of `#{from_gem}`, but the type definition as a stdlib in rbs-gem is deprecated. Add `#{gem_name}` (#{version}) to the dependency of your Ruby program to use the gem-bundled type definition."
}
else
RBS.logger.info {
Expand All @@ -235,7 +242,7 @@ def generate
# From `gems:` of a `rbs_collection.yaml`
RBS.logger.warn {
if version
"`#{name}` as a stdlib in rbs-gem is deprecated. Add `#{name}` (#{version}) to the dependency of your Ruby program to use the gem-bundled type definition."
"`#{name}` as a stdlib in rbs-gem is deprecated. Add `#{gem_name}` (#{version}) to the dependency of your Ruby program to use the gem-bundled type definition."
else
"`#{name}` as a stdlib in rbs-gem is deprecated. Delete `#{name}` from the RBS dependencies in your rbs_collection.yaml."
end
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 @@ -8,6 +8,10 @@ module RBS
#
ALUMNI_STDLIBS: Hash[String, String?]

# Stdlibs in `ALUMNI_STDLIBS` whose gem name differs from the library name.
#
ALUMNI_GEM_NAMES: Hash[String, String]

NONGEM_STDLIBS: Set[String]

class GemfileLockMismatchError < StandardError
Expand Down
41 changes: 41 additions & 0 deletions test/rbs/collection/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,47 @@ def test_generate_lock_from_rubygems
2.2.0
GEMFILE_LOCK

def test_generate_lock_from_alumni_stdlib__observable
# The stdlib is named `observable` while the gem is named `observer`.
# The deprecation warning must be keyed by the stdlib name, or it never fires.
mktmpdir do |tmpdir|
config_path = tmpdir / 'rbs_collection.yaml'
config_path.write <<~YAML
sources:
- name: ruby/gem_rbs_collection
remote: https://github.com/ruby/gem_rbs_collection.git
revision: cde6057e7546843ace6420c5783dd945c6ccda54
repo_dir: gems

path: /path/to/somewhere

gems:
- name: observable
YAML
gemfile_path = tmpdir / 'Gemfile'
gemfile_path.write 'source "https://rubygems.org"'
gemfile_lock_path = tmpdir / 'Gemfile.lock'
gemfile_lock_path.write EMPTY_GEMFILE_LOCK

definition = Bundler::Definition.build(gemfile_path, gemfile_lock_path, false)
lockfile, log = with_logger_output(level: Logger::WARN) do
_config, lockfile = RBS::Collection::Config.generate_lockfile(config_path: config_path, definition: definition)
lockfile
end

assert_config <<~YAML, YAML.dump(lockfile.to_lockfile)
path: "/path/to/somewhere"
gemfile_lock_path: 'Gemfile.lock'
gems:
- name: observable
version: "0"
source:
type: stdlib
YAML
assert_include log, '`observable` as a stdlib in rbs-gem is deprecated.'
end
end

def test_generate_lock_from_alumni_stdlib__kconv
# `kconv` is never released as a gem; its types are shipped with the `nkf` gem.
mktmpdir do |tmpdir|
Expand Down
Loading