Skip to content

Commit

Permalink
Merge branch 'main' into esbuild-update-to-esm
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcwhite authored Nov 16, 2024
2 parents 865af5f + 3870ddb commit ecc0e45
Show file tree
Hide file tree
Showing 67 changed files with 228 additions and 236 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ group :test do
gem "nokolexbor"
gem "rack-test"
gem "rspec-mocks"
gem "rubocop-bridgetown", "~> 0.4", require: false
gem "rubocop-bridgetown", "~> 0.6", require: false
gem "shoulda"
gem "simplecov"
gem "terminal-table"
Expand Down
12 changes: 6 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ GEM
concurrent-ruby (~> 1.0)
inclusive (1.0.0)
jaro_winkler (1.6.0)
json (2.7.2)
json (2.7.5)
kramdown (2.4.0)
rexml
kramdown-parser-gfm (1.1.0)
Expand Down Expand Up @@ -144,7 +144,7 @@ GEM
nokolexbor (0.5.4-x86_64-darwin)
nokolexbor (0.5.4-x86_64-linux)
parallel (1.26.3)
parser (3.3.5.0)
parser (3.3.5.1)
ast (~> 2.4.1)
racc
public_suffix (6.0.1)
Expand Down Expand Up @@ -172,7 +172,7 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
rubocop (1.67.0)
rubocop (1.68.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand All @@ -182,9 +182,9 @@ GEM
rubocop-ast (>= 1.32.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.32.3)
rubocop-ast (1.33.1)
parser (>= 3.3.1.0)
rubocop-bridgetown (0.5.0)
rubocop-bridgetown (0.6.1)
rubocop (~> 1.23)
rubocop-performance (~> 1.12)
rubocop-performance (1.22.1)
Expand Down Expand Up @@ -262,7 +262,7 @@ DEPENDENCIES
rack-test
rake (~> 13.0)
rspec-mocks
rubocop-bridgetown (~> 0.4)
rubocop-bridgetown (~> 0.6)
shoulda
simplecov
solargraph
Expand Down
4 changes: 2 additions & 2 deletions bridgetown-core/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ Style/StringConcatenation:
Exclude:
- test/test_apply_command.rb

Style/MixinGrouping:
Enabled: false
Style/SafeNavigationChainLength:
Enabled: false
3 changes: 1 addition & 2 deletions bridgetown-core/lib/bridgetown-core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def require_all(path)
require "bridgetown-foundation"

# 3rd party
require "active_support" # TODO: remove by the end of 2024
require "active_support" # TODO: remove by the end of 2025
require "active_support/core_ext/object/blank"
require "active_support/core_ext/string/inflections"
require "active_support/core_ext/string/output_safety"
Expand Down Expand Up @@ -76,7 +76,6 @@ module Bridgetown
autoload :DefaultsReader, "bridgetown-core/readers/defaults_reader"
autoload :Deprecator, "bridgetown-core/deprecator"
autoload :EntryFilter, "bridgetown-core/entry_filter"
# TODO: we have too many errors! This is silly
autoload :Errors, "bridgetown-core/errors"
autoload :FrontMatter, "bridgetown-core/front_matter"
autoload :GeneratedPage, "bridgetown-core/generated_page"
Expand Down
7 changes: 1 addition & 6 deletions bridgetown-core/lib/bridgetown-core/commands/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ def build
build_site(config_options)
end

# TODO: remove this logic…I can't find "detach" anywhere
if config_options.fetch("detach", false)
Bridgetown.logger.info "Auto-regeneration:",
"disabled when running server detached."
elsif config_options.fetch("watch", false)
if config_options.fetch("watch", false)
watch_site(config_options)
else
Bridgetown.logger.info "Auto-regeneration:", "disabled. Use --watch to enable."
Expand Down Expand Up @@ -111,7 +107,6 @@ def display_folder_paths(config_options)
Bridgetown.logger.info "Environment:", Bridgetown.environment.cyan
Bridgetown.logger.info "Source:", source
Bridgetown.logger.info "Destination:", destination
# TODO: work with arrays
return unless config_options["plugins_dir"].is_a?(String)

plugins_dir = File.expand_path(config_options["plugins_dir"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ def fast_refresh(paths = [], reload_if_needed: false) # rubocop:todo Metrics
@fast_refresh_ordering = 0
full_abort = false
found_gen_pages = false
paths.each do |path|
res = resources.find do |resource|
paths.each do |path| # rubocop:todo Metrics
found_res = resources.select do |resource|
resource.id.start_with?("repo://") && in_source_dir(resource.relative_path) == path
end

layouts_to_reload = Set.new
locate_resource_layouts_and_partials_for_fash_refresh(path, layouts_to_reload) unless res
locate_resource_layouts_and_partials_for_fash_refresh(path, layouts_to_reload) unless
found_res.any?

locate_components_for_fast_refresh(path) unless res
locate_components_for_fast_refresh(path) unless found_res.any?

pages = locate_layouts_and_pages_for_fast_refresh(path, layouts_to_reload)

Expand All @@ -27,20 +28,22 @@ def fast_refresh(paths = [], reload_if_needed: false) # rubocop:todo Metrics
self, layout.instance_variable_get(:@base), layout.name
)
end
next unless res || !pages.empty?
next unless found_res.any? || pages.any?

unless pages.empty?
if pages.any?
found_gen_pages = true
mark_original_page_resources_for_fast_refresh(pages)
next
end

res.prepare_for_fast_refresh!.tap { full_abort = true unless _1 }
next unless res.collection.data?
found_res.each do |res|
res.prepare_for_fast_refresh!.tap { full_abort = true unless _1 }
next unless res.collection.data?

res.collection.merge_data_resources.each do |k, v|
data[k] = v
signals[k] = v
res.collection.merge_data_resources.each do |k, v|
data[k] = v
signals[k] = v
end
end
end

Expand Down Expand Up @@ -134,7 +137,11 @@ def mark_original_page_resources_for_fast_refresh(pages)
end

def transform_resources_for_fast_refresh(marked_resources, found_gen_pages)
marked_resources.each { _1.transform!.write }
marked_resources.each do |res|
render_with_locale(res) do
res.transform!.write
end
end
number_of_resources = marked_resources.length
number_of_resources += 1 if found_gen_pages
Bridgetown.logger.info(
Expand Down
1 change: 0 additions & 1 deletion bridgetown-core/lib/bridgetown-core/concerns/site/ssr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def ssr_setup(&block)
end

def ssr_first_read
# TODO: this shouldn't be running twice, right?!
Bridgetown::Hooks.trigger :site, :pre_read, self
defaults_reader.tap do |d|
d.path_defaults.clear
Expand Down
15 changes: 6 additions & 9 deletions bridgetown-core/lib/bridgetown-core/drops/drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,22 @@ def [](key)
end
alias_method :invoke_drop, :[]

# Set a field in the Drop. If mutable, sets in the mutations and
# returns. If not mutable, checks first if it's trying to override a
# Drop method and raises a DropMutationException if so. If not
# mutable and the key is not a method on the Drop, then it sets the
# key to the value in the underlying hash (e.g. document front
# matter)
# Set a field in the Drop. If mutable, sets in the mutations and returns. If not mutable,
# checks first if it's trying to override a Drop method and raises an exception if so.
# If not mutable and the key is not a method on the Drop, then it sets the key to the value
# in the underlying hash (e.g. document front matter)
#
# @param key [String] key whose value to set
# @param val [Object] what to set the key's value to
# @return [Object] the value the key was set to unless the Drop is not mutable
# and the key matches a method in which case it raises a
# DropMutationException.
# and the key matches a method in which case it raises an exception
def []=(key, val)
setter = "#{key}="
if respond_to?(setter)
public_send(setter, val)
elsif respond_to?(key.to_s)
unless self.class.mutable?
raise Errors::DropMutationException, "Key #{key} cannot be set in the drop."
raise Errors::FatalException, "Key #{key} cannot be set in the drop."
end

mutations[key] = val
Expand Down
10 changes: 2 additions & 8 deletions bridgetown-core/lib/bridgetown-core/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@ module Bridgetown
module Errors
FatalException = Class.new(::RuntimeError)

DropMutationException = Class.new(FatalException)
InvalidPermalinkError = Class.new(FatalException)
InvalidYAMLFrontMatterError = Class.new(FatalException)
MissingDependencyException = Class.new(FatalException)

InvalidConfigurationError = Class.new(FatalException)
InvalidDateError = Class.new(FatalException)
InvalidPostNameError = Class.new(FatalException)
InvalidYAMLFrontMatterError = Class.new(FatalException)
PostURLError = Class.new(FatalException)
InvalidURLError = Class.new(FatalException)
InvalidConfigurationError = Class.new(FatalException)

def self.print_build_error(exc, trace: false, logger: Bridgetown.logger, server: false) # rubocop:todo Metrics
logger.error "Exception raised:", exc.class.to_s.bold
Expand Down
2 changes: 1 addition & 1 deletion bridgetown-core/lib/bridgetown-core/filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def where(input, property, value) # rubocop:disable Metrics/CyclomaticComplexity
def where_exp(input, variable, expression)
return input unless input.respond_to?(:select)

input = input.values if input.is_a?(Hash) # FIXME
input = input.values if input.is_a?(Hash)

condition = parse_condition(expression)
@context.stack do
Expand Down
1 change: 0 additions & 1 deletion bridgetown-core/lib/bridgetown-core/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def to_s

@registry = {}

NotAvailable = Class.new(RuntimeError)
Uncallable = Class.new(RuntimeError)

def self.priority_value(priority)
Expand Down
11 changes: 5 additions & 6 deletions bridgetown-core/lib/bridgetown-core/resource/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ def data
#
# @param new_data [HashWithDotAccess::Hash]
def data=(new_data)
if site.config.fast_refresh && write?
# TODO: investigate if this would be better:
# @data.value = front_matter_defaults
mark_for_fast_refresh!
end
mark_for_fast_refresh! if site.config.fast_refresh && write?

Signalize.batch do
@content_signal.value += 1
Expand Down Expand Up @@ -365,7 +361,10 @@ def prepare_for_fast_refresh! # rubocop:todo Metrics
past_values = @data.peek.select do |key|
key == "categories" || key == "tags" || site.taxonomy_types.keys.any?(key)
end
model.attributes = model.origin.read
origin_data = model.origin.read
correct_locale = origin_data["locale"] || origin_data[:locale] || data.locale
model.attributes = origin_data
model.attributes.locale = correct_locale
@relative_url = @absolute_url = nil # wipe memoizations
read!
tax_diff = past_values.any? { |k, v| @data.peek[k] != v }
Expand Down
1 change: 0 additions & 1 deletion bridgetown-core/lib/bridgetown-core/ruby_template_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ def _liquid_context
def _partial_path(partial_name, ext)
partial_name = partial_name.split("/").tap { _1.last.prepend("_") }.join("/")

# TODO: see if there's a workaround for this to speed up performance
site.in_source_dir(site.config[:partials_dir], "#{partial_name}.#{ext}")
end
end
Expand Down
2 changes: 1 addition & 1 deletion bridgetown-core/lib/bridgetown-core/tags/post_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(name)

all, @path, @date, @slug = *name.sub(%r!^/!, "").match(MATCHER)
unless all
raise Bridgetown::Errors::InvalidPostNameError,
raise Bridgetown::Errors::FatalException,
"'#{name}' does not contain valid date and/or title."
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def within?(other) # rubocop:disable Metrics
# NOTE: if you _really_ need to preserve Active Support's `in?` functionality, you can just
# require "active_support/core_ext/object/inclusion"
def in?(...) = Bridgetown::Foundation.deprecation_warning(
self, :in?, :within?, 2024, 12
self, :in?, :within?, 2025, 12
).then { within?(...) }
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def indent(indent_by, *args)
def questionable = Bridgetown::Foundation::QuestionableString.new(self)

def inquiry = Bridgetown::Foundation.deprecation_warning(
self, :inquiry, :questionable, 2024, 12
self, :inquiry, :questionable, 2025, 12
).then { questionable }
end
end
Expand Down
Loading

0 comments on commit ecc0e45

Please sign in to comment.