Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure absolute lockfile remotes for gems nested inside project #2799

Merged
merged 1 commit into from
Oct 29, 2024
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
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
Loading