From b6a636bb049230a5d82b7c6f76238b50b96f70e8 Mon Sep 17 00:00:00 2001 From: Jared White Date: Fri, 13 Dec 2024 23:34:51 -0800 Subject: [PATCH] Preserve the `_bridgetown` default value in `keep_files` config (#945) --- .../lib/bridgetown-core/configuration.rb | 15 ++++++++++++--- bridgetown-core/test/test_site.rb | 5 +++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/bridgetown-core/lib/bridgetown-core/configuration.rb b/bridgetown-core/lib/bridgetown-core/configuration.rb index 26533dd7f..dec848e8c 100644 --- a/bridgetown-core/lib/bridgetown-core/configuration.rb +++ b/bridgetown-core/lib/bridgetown-core/configuration.rb @@ -122,7 +122,7 @@ def from(user_config, starting_defaults = DEFAULTS) .setup_load_paths! .setup_locales .add_default_collections - .add_default_excludes + .add_destination_paths .check_include_exclude end end @@ -148,11 +148,15 @@ def run_initializers!(context:) # rubocop:todo Metrics/AbcSize, Metrics/Cyclomat dsl._run_builtins! self.url = cached_url if cached_url # restore local development URL if need be - setup_load_paths! appending: true + setup_post_init! self end + def setup_post_init! + add_destination_paths.setup_load_paths! appending: true + end + # @return [Set] def source_manifests @source_manifests ||= Set.new @@ -357,13 +361,18 @@ def add_default_collections # rubocop:todo all vendor/bundle/ vendor/cache/ vendor/gems/ vendor/ruby/ ).freeze - def add_default_excludes + def add_destination_paths + self["keep_files"] << "_bridgetown" unless + self["keep_files"].nil?.! && self["keep_files"].include?("_bridgetown") + return self if self["exclude"].nil? self["exclude"].concat(DEFAULT_EXCLUDES).uniq! self end + alias_method :add_default_excludes, :add_destination_paths + def should_execute_inline_ruby? ENV["BRIDGETOWN_RUBY_IN_FRONT_MATTER"] != "false" && self["ruby_in_front_matter"] diff --git a/bridgetown-core/test/test_site.rb b/bridgetown-core/test/test_site.rb index a61b68065..d4bbbb2aa 100644 --- a/bridgetown-core/test/test_site.rb +++ b/bridgetown-core/test/test_site.rb @@ -267,6 +267,8 @@ class TestSite < BridgetownUnitTest FileUtils.touch(dest_dir(".git/HEAD")) FileUtils.touch(dest_dir(".svn/HEAD")) FileUtils.touch(dest_dir(".hg/HEAD")) + FileUtils.mkdir(dest_dir("_bridgetown")) + FileUtils.touch(dest_dir("_bridgetown/static")) end teardown do @@ -276,6 +278,7 @@ class TestSite < BridgetownUnitTest FileUtils.rm_rf(dest_dir(".git")) FileUtils.rm_rf(dest_dir(".svn")) FileUtils.rm_rf(dest_dir(".hg")) + FileUtils.rm_rf(dest_dir("_bridgetown")) end should "remove orphaned files in destination" do @@ -285,6 +288,7 @@ class TestSite < BridgetownUnitTest refute_exist dest_dir("quux") assert_exist dest_dir(".git") assert_exist dest_dir(".git", "HEAD") + assert_exist dest_dir("_bridgetown", "static") end should "remove orphaned files in destination - keep_files .svn" do @@ -299,6 +303,7 @@ class TestSite < BridgetownUnitTest refute_exist dest_dir(".git", "HEAD") assert_exist dest_dir(".svn") assert_exist dest_dir(".svn", "HEAD") + assert_exist dest_dir("_bridgetown", "static") end end