Skip to content

Commit

Permalink
Ensure absolute lockfile remotes for gems nested inside project (Shop…
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock authored Oct 29, 2024
1 parent 0fa1ec9 commit eadd431
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/ruby_lsp/setup_bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require "pathname"
require "digest"
require "time"
require "uri"

# This file is a script that will configure a custom bundle for the Ruby LSP. The custom bundle allows developers to use
# the Ruby LSP without including the gem in their application's Gemfile while at the same time giving us access to the
Expand Down Expand Up @@ -300,7 +301,7 @@ def correct_relative_remote_paths

# We should only apply the correction if the remote is a relative path. It might also be a URI, like
# `https://rubygems.org` or an absolute path, in which case we shouldn't do anything
if path&.start_with?(".")
if path && !URI(path).scheme
"remote: #{File.expand_path(path, T.must(@gemfile).dirname)}"
else
match
Expand Down
48 changes: 48 additions & 0 deletions test/setup_bundler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,54 @@ def test_ensures_lockfile_remotes_are_relative_to_default_gemfile
end
end

def test_ensures_lockfile_remotes_are_absolute_in_projects_with_nested_gems
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
File.write(File.join(dir, "Gemfile"), <<~GEMFILE)
# frozen_string_literal: true
source "https://rubygems.org"
gem "nested", path: "gems/nested"
GEMFILE

FileUtils.mkdir_p(File.join(dir, "gems", "nested", "lib"))

File.write(File.join(dir, "gems", "nested", "nested.gemspec"), <<~GEMSPEC)
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = "nested"
s.version = "1.0.0"
s.summary = "Nested gemspec"
s.description = "Nested gemspec"
s.license = "MIT"
s.author = "User"
s.email = "user@example.com"
s.homepage = "https://rubyonrails.org"
s.files = Dir[]
s.require_path = "lib"
end
GEMSPEC

File.write(File.join(dir, "gems", "nested", "Gemfile"), <<~GEMFILE)
source "https://rubygems.org"
gemspec
GEMFILE

real_path = File.realpath(dir)

Bundler.with_unbundled_env do
capture_subprocess_io do
system("bundle install")
run_script(real_path)
end
end

assert_path_exists(".ruby-lsp")
assert_path_exists(".ruby-lsp/Gemfile.lock")
assert_match("remote: #{File.join(real_path, "gems", "nested")}", File.read(".ruby-lsp/Gemfile.lock"))
end
end
end

def test_ruby_lsp_rails_is_automatically_included_in_rails_apps
Dir.mktmpdir do |dir|
FileUtils.mkdir("#{dir}/config")
Expand Down

0 comments on commit eadd431

Please sign in to comment.