Skip to content

Commit

Permalink
Add support for alternative gemfile gems.rb to core (#658)
Browse files Browse the repository at this point in the history
  • Loading branch information
svoop authored Dec 14, 2022
1 parent 6286c21 commit c428cd0
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 11 deletions.
1 change: 1 addition & 0 deletions bridgetown-core/lib/bridgetown-core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def require_all(path)

# rubygems
require "rubygems"
require "bundler/shared_helpers"

# stdlib
require "find"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ def add_gem(gemname, group: nil, version: nil)
options = +""
options += " -v \"#{version}\"" if version
options += " -g #{group}" if group
# in_bundle? returns the path to the gemfile
run "bundle add #{gemname}#{options}",
env: { "BUNDLE_GEMFILE" => File.join(destination_root, "Gemfile") }
env: { "BUNDLE_GEMFILE" => Bundler::SharedHelpers.in_bundle? }
rescue SystemExit
say_status :run, "Gem not added due to bundler error", :red
end
Expand Down
2 changes: 1 addition & 1 deletion bridgetown-core/lib/bridgetown-core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def add_default_collections # rubocop:todo all

DEFAULT_EXCLUDES = %w(
.sass-cache .bridgetown-cache
gemfiles Gemfile Gemfile.lock
gemfiles Gemfile Gemfile.lock gems.rb gems.locked
node_modules
vendor/bundle/ vendor/cache/ vendor/gems/ vendor/ruby/
).freeze
Expand Down
3 changes: 2 additions & 1 deletion bridgetown-core/lib/bridgetown-core/plugin_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def source_manifests
end

def self.setup_bundler(skip_yarn: false)
if !ENV["BRIDGETOWN_NO_BUNDLER_REQUIRE"] && (File.file?("Gemfile") || Bridgetown.env.test?)
if !ENV["BRIDGETOWN_NO_BUNDLER_REQUIRE"] &&
(Bundler::SharedHelpers.in_bundle? || Bridgetown.env.test?)
require "bundler"

require_relative "utils/initializers"
Expand Down
9 changes: 1 addition & 8 deletions bridgetown-core/test/test_plugin_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
require "helper"

class TestPluginManager < BridgetownUnitTest
def with_no_gemfile
FileUtils.mv "../Gemfile", "../Gemfile.old"
yield
ensure
FileUtils.mv "../Gemfile.old", "../Gemfile"
end

context "BRIDGETOWN_NO_BUNDLER_REQUIRE set to `nil`" do
setup do
FileUtils.cp "../Gemfile", "."
Expand Down Expand Up @@ -50,7 +43,7 @@ def with_no_gemfile
should "not setup bundler" do
with_env("BRIDGETOWN_NO_BUNDLER_REQUIRE", nil) do
with_env("BRIDGETOWN_ENV", nil) do
with_no_gemfile do
Bundler::SharedHelpers.stub(:in_bundle?, nil) do
refute Bridgetown::PluginManager.setup_bundler,
"Gemfile plugins were required but shouldn't have been"
assert_nil ENV["BRIDGETOWN_NO_BUNDLER_REQUIRE"]
Expand Down

0 comments on commit c428cd0

Please sign in to comment.