From c5e661b1d720cf5452c3fd5264b73063ca9c4515 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Thu, 11 Apr 2024 10:21:01 -0600 Subject: [rubygems/rubygems] Fix installing plugins via relative paths This affected both CLI and Gemfile installs https://github.com/rubygems/rubygems/commit/a0d101a8df --- lib/bundler/plugin/installer.rb | 2 +- lib/bundler/plugin/installer/path.rb | 2 +- spec/bundler/plugins/install_spec.rb | 55 ++++++++++++++++++++++++++++++++---- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/lib/bundler/plugin/installer.rb b/lib/bundler/plugin/installer.rb index 6771f3f153..4f60862bb4 100644 --- a/lib/bundler/plugin/installer.rb +++ b/lib/bundler/plugin/installer.rb @@ -77,7 +77,7 @@ module Bundler def install_path(names, version, path) source_list = SourceList.new - source = source_list.add_path_source({ "path" => path }) + source = source_list.add_path_source({ "path" => path, "root_path" => SharedHelpers.pwd }) install_all_sources(names, version, source_list, source) end diff --git a/lib/bundler/plugin/installer/path.rb b/lib/bundler/plugin/installer/path.rb index 1b60724b5e..58a8fa7426 100644 --- a/lib/bundler/plugin/installer/path.rb +++ b/lib/bundler/plugin/installer/path.rb @@ -5,7 +5,7 @@ module Bundler class Installer class Path < Bundler::Source::Path def root - Plugin.root + SharedHelpers.in_bundle? ? Bundler.root : Plugin.root end def generate_bin(spec, disable_extensions = false) diff --git a/spec/bundler/plugins/install_spec.rb b/spec/bundler/plugins/install_spec.rb index 61c513ed72..20c2f1fd26 100644 --- a/spec/bundler/plugins/install_spec.rb +++ b/spec/bundler/plugins/install_spec.rb @@ -212,14 +212,42 @@ RSpec.describe "bundler plugin install" do end end - it "installs from a path source" do - build_lib "path_plugin" do |s| - s.write "plugins.rb" + context "path plugins" do + it "installs from a path source" do + build_lib "path_plugin" do |s| + s.write "plugins.rb" + end + bundle "plugin install path_plugin --path #{lib_path("path_plugin-1.0")}" + + expect(out).to include("Installed plugin path_plugin") + plugin_should_be_installed("path_plugin") + end + + it "installs from a relative path source" do + build_lib "path_plugin" do |s| + s.write "plugins.rb" + end + path = lib_path("path_plugin-1.0").relative_path_from(bundled_app) + bundle "plugin install path_plugin --path #{path}" + + expect(out).to include("Installed plugin path_plugin") + plugin_should_be_installed("path_plugin") end - bundle "plugin install path_plugin --path #{lib_path("path_plugin-1.0")}" - expect(out).to include("Installed plugin path_plugin") - plugin_should_be_installed("path_plugin") + it "installs from a relative path source when inside an app" do + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + gemfile "" + + build_lib "ga-plugin" do |s| + s.write "plugins.rb" + end + + path = lib_path("ga-plugin-1.0").relative_path_from(bundled_app) + bundle "plugin install ga-plugin --path #{path}" + + plugin_should_be_installed("ga-plugin") + expect(local_plugin_gem("foo-1.0")).not_to be_directory + end end context "Gemfile eval" do @@ -291,6 +319,21 @@ RSpec.describe "bundler plugin install" do plugin_should_be_installed("ga-plugin") end + it "accepts relative path sources" do + build_lib "ga-plugin" do |s| + s.write "plugins.rb" + end + + path = lib_path("ga-plugin-1.0").relative_path_from(bundled_app) + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + plugin 'ga-plugin', :path => "#{path}" + G + + expect(out).to include("Installed plugin ga-plugin") + plugin_should_be_installed("ga-plugin") + end + context "in deployment mode" do it "installs plugins" do install_gemfile <<-G -- cgit v1.2.3