rbs icon indicating copy to clipboard operation
rbs copied to clipboard

manifest.yaml does not allow gems as dependencies

Open pocke opened this issue 2 years ago • 0 comments

Currently manifest.yaml does not allow gems as dependencies. For example:

# manifest.yaml for gem X
dependencies:
  - name: ast

When your Gemfile.lock contains the gem X, rbs collection install generates the following rbs_collection.lock.yaml.

$ rbs -v
rbs 3.2.1
# snip

gems:
- name: X
  version: '0.1'
  source:
    type: git
    name: local_collection
    revision: 2908d5a84c0364fceaa6046b35c290e720052172
    remote: "..."
    repo_dir: gems
- name: ast
  version: '0'
  source:
    type: stdlib
gemfile_lock_path: Gemfile.lock

This RBS is invalid. ast is a gem, but the lockfile indicates that it is a stdlib. Therefore rbs validate fails with the lockfile.

$ rbs validate
/path/to/rbs/environment_loader.rb:118:in `block in each_dir': Cannot find type definitions for library: ast (0) (RBS::EnvironmentLoader::UnknownLibraryError)

(snip)

BTW, it is a regression of a recent RBS version. Because it works well on rbs 2.0.0, which is the version introduced manifest.yaml.

rbs collection install generates the following lockfile on rbs v2.0.0.

(snip)
gems:
- name: X
  version: '0.1'
  source:
    type: git
    name: local_collection
    revision: 2908d5a84c0364fceaa6046b35c290e720052172
    remote: "..."
    repo_dir: gems
- name: ast
  version: '2.4'
  source:
    type: git
    name: ruby/gem_rbs_collection
    revision: 267dd270bb5aabcc1e21c87f44360f0680a8501c
    remote: https://github.com/ruby/gem_rbs_collection.git
    repo_dir: gems

So I think manifest.yaml should allows containing a gem as a dependency.

Problem if it contains a gem as a dependency

It has a problem if manifest.yaml contains a gem as a dependency. Becaues rbs collection cannot resolve dependency of the gem written in manifest.yaml. For example:

  • Gemfile.lock only contains dependency of gem X
  • ruby/gem_rbs_collection has an RBS for gem X
  • gem X has a dependency on gem Y, which is specified by manifest.yaml.
  • gem Y has a dependency on gem Z, which is specified by the gemspec.

In this case, rbs collection finds gem X and gem Y. But it cannot find gem Z if Gemfile.lock does not contain gem Y or gem Z.

I'm not sure this problem is critical. I guess allowing gems in manifest.yaml is better even if it has the dependency resolution problem.

pocke avatar Sep 22 '23 08:09 pocke