create configuration from options only once in the boot process (#5487)
Merge pull request 5487
This commit is contained in:
parent
76fb728f72
commit
0108b22f3c
|
@ -37,6 +37,7 @@ module Jekyll
|
|||
#
|
||||
# Returns a full Jekyll configuration
|
||||
def configuration_from_options(options)
|
||||
return options if options.is_a?(Jekyll::Configuration)
|
||||
Jekyll.configuration(options)
|
||||
end
|
||||
|
||||
|
|
|
@ -32,11 +32,12 @@ module Jekyll
|
|||
cmd.action do |_, opts|
|
||||
opts["serving"] = true
|
||||
opts["watch" ] = true unless opts.key?("watch")
|
||||
config = opts["config"]
|
||||
opts["url"] = default_url(opts) if Jekyll.env == "development"
|
||||
Build.process(opts)
|
||||
opts["config"] = config
|
||||
Serve.process(opts)
|
||||
|
||||
config = configuration_from_options(opts)
|
||||
if Jekyll.env == "development"
|
||||
config["url"] = default_url(config)
|
||||
end
|
||||
[Build, Serve].each { |klass| klass.process(config) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -82,16 +82,26 @@ class TestCommandsServe < JekyllUnitTest
|
|||
end
|
||||
|
||||
should "keep config between build and serve" do
|
||||
custom_options = {
|
||||
options = {
|
||||
"config" => %w(_config.yml _development.yml),
|
||||
"serving" => true,
|
||||
"watch" => false, # for not having guard output when running the tests
|
||||
"url" => "http://localhost:4000",
|
||||
}
|
||||
config = Jekyll::Configuration.from(options)
|
||||
|
||||
expect(Jekyll::Commands::Serve).to receive(:process).with(custom_options)
|
||||
@merc.execute(:serve, { "config" => %w(_config.yml _development.yml),
|
||||
"watch" => false, })
|
||||
allow(Jekyll::Command).to(
|
||||
receive(:configuration_from_options).with(options).and_return(config)
|
||||
)
|
||||
allow(Jekyll::Command).to(
|
||||
receive(:configuration_from_options).with(config).and_return(config)
|
||||
)
|
||||
|
||||
expect(Jekyll::Commands::Build).to(
|
||||
receive(:process).with(config).and_call_original
|
||||
)
|
||||
expect(Jekyll::Commands::Serve).to receive(:process).with(config)
|
||||
@merc.execute(:serve, options)
|
||||
end
|
||||
|
||||
context "in development environment" do
|
||||
|
@ -175,5 +185,12 @@ class TestCommandsServe < JekyllUnitTest
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
should "read `configuration` only once" do
|
||||
allow(Jekyll::Commands::Serve).to receive(:start_up_webrick)
|
||||
|
||||
expect(Jekyll).to receive(:configuration).once.and_call_original
|
||||
@merc.execute(:serve, { "watch" => false })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue