Load Jekyll plugins from BUNDLE_GEMFILE location (#8585)

Merge pull request 8585
This commit is contained in:
Liam Bigelow 2021-05-17 08:06:05 +12:00 committed by GitHub
parent 6a6d735db2
commit 93ef9389ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -46,7 +46,7 @@ module Jekyll
end
def self.require_from_bundler
if !ENV["JEKYLL_NO_BUNDLER_REQUIRE"] && File.file?("Gemfile")
if !ENV["JEKYLL_NO_BUNDLER_REQUIRE"] && gemfile_exists?
require "bundler"
Bundler.setup
@ -61,6 +61,13 @@ module Jekyll
end
end
# Check for the existence of a Gemfile.
#
# Returns true if a Gemfile exists in the places bundler will look
def self.gemfile_exists?
File.file?("Gemfile") || (ENV["BUNDLE_GEMFILE"] && File.file?(ENV["BUNDLE_GEMFILE"]))
end
# Check whether a gem plugin is allowed to be used during this build.
#
# plugin_name - the name of the plugin

View File

@ -10,6 +10,13 @@ class TestPluginManager < JekyllUnitTest
FileUtils.mv "Gemfile.old", "Gemfile"
end
def with_bundle_gemfile
FileUtils.mv "Gemfile", "AlternateGemfile"
yield
ensure
FileUtils.mv "AlternateGemfile", "Gemfile"
end
context "JEKYLL_NO_BUNDLER_REQUIRE set to `nil`" do
should "require from bundler" do
with_env("JEKYLL_NO_BUNDLER_REQUIRE", nil) do
@ -20,6 +27,18 @@ class TestPluginManager < JekyllUnitTest
end
end
context "BUNDLE_GEMFILE set to `AlternateGemfile`" do
should "require from bundler" do
with_env("BUNDLE_GEMFILE", "AlternateGemfile") do
with_bundle_gemfile do
assert Jekyll::PluginManager.require_from_bundler,
"require_from_bundler should return true"
assert ENV["JEKYLL_NO_BUNDLER_REQUIRE"], "Gemfile plugins were not required."
end
end
end
end
context "JEKYLL_NO_BUNDLER_REQUIRE set to `true`" do
should "not require from bundler" do
with_env("JEKYLL_NO_BUNDLER_REQUIRE", "true") do