Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logs and console for Ruby 3.3 #834

Merged
merged 8 commits into from Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby_version: [2.7.2, 3.0.0, 3.1.2, 3.2.0]
ruby_version: [3.0.0, 3.1.2, 3.2.0, 3.3.0]
continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }}
# Has to be top level to cache properly
env:
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
@@ -1 +1 @@
ruby-2.7.2
ruby-3.0.6
22 changes: 12 additions & 10 deletions Gemfile.lock
Expand Up @@ -13,6 +13,7 @@ PATH
addressable (~> 2.4)
amazing_print (~> 1.2)
colorator (~> 1.0)
csv (~> 3.2)
erubi (~> 1.9)
faraday (~> 2.0)
faraday-follow_redirects (~> 0.3)
Expand Down Expand Up @@ -66,6 +67,7 @@ GEM
builder (3.2.4)
colorator (1.1.0)
concurrent-ruby (1.2.2)
csv (3.2.8)
cucumber (8.0.0)
builder (~> 3.2, >= 3.2.4)
cucumber-ci-environment (~> 9.0, >= 9.0.4)
Expand Down Expand Up @@ -120,7 +122,7 @@ GEM
mime-types (3.5.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2023.0808)
mini_portile2 (2.8.4)
mini_portile2 (2.8.5)
minitest (5.19.0)
minitest-profile (0.0.2)
minitest-reporters (1.6.1)
Expand All @@ -129,25 +131,25 @@ GEM
minitest (>= 5.0)
ruby-progressbar
multi_test (1.1.0)
nokogiri (1.15.4)
nokogiri (1.16.0)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.15.4-arm64-darwin)
nokogiri (1.16.0-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.4-x86_64-darwin)
nokogiri (1.16.0-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.15.4-x86_64-linux)
nokogiri (1.16.0-x86_64-linux)
racc (~> 1.4)
nokolexbor (0.5.0)
nokolexbor (0.5.0-arm64-darwin)
nokolexbor (0.5.0-x86_64-darwin)
nokolexbor (0.5.0-x86_64-linux)
nokolexbor (0.5.2)
nokolexbor (0.5.2-arm64-darwin)
nokolexbor (0.5.2-x86_64-darwin)
nokolexbor (0.5.2-x86_64-linux)
parallel (1.23.0)
parser (3.2.2.3)
ast (~> 2.4.1)
racc
public_suffix (5.0.3)
racc (1.7.1)
racc (1.7.3)
rack (3.0.8)
rack-test (2.1.0)
rack (>= 1.3)
Expand Down
1 change: 1 addition & 0 deletions bridgetown-core/bridgetown-core.gemspec
Expand Up @@ -36,6 +36,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency("addressable", "~> 2.4")
s.add_runtime_dependency("amazing_print", "~> 1.2")
s.add_runtime_dependency("colorator", "~> 1.0")
s.add_runtime_dependency("csv", "~> 3.2")
s.add_runtime_dependency("erubi", "~> 1.9")
s.add_runtime_dependency("faraday", "~> 2.0")
s.add_runtime_dependency("faraday-follow_redirects", "~> 0.3")
Expand Down
12 changes: 10 additions & 2 deletions bridgetown-core/lib/bridgetown-core/commands/console.rb
Expand Up @@ -66,9 +66,15 @@ def self.banner
type: :boolean,
desc: "Print verbose output."

def console
def console # rubocop:disable Metrics
require "irb"
require "irb/ext/save-history"
new_history_behavior = false
begin
require "irb/ext/save-history"
rescue LoadError
# Code path for Ruby 3.3+
new_history_behavior = true
end
require "amazing_print" unless options[:"bypass-ap"]

Bridgetown.logger.adjust_verbosity(options)
Expand Down Expand Up @@ -96,6 +102,7 @@ def console
irb = IRB::Irb.new(workspace)
IRB.conf[:IRB_RC]&.call(irb.context)
IRB.conf[:MAIN_CONTEXT] = irb.context
irb.context.io.load_history if new_history_behavior
Bridgetown.logger.info "Console:", "Your site is now available as #{"site".cyan}"
Bridgetown.logger.info "",
"You can also access #{"collections".cyan} or perform a " \
Expand All @@ -117,6 +124,7 @@ def console
end
ensure
IRB.conf[:AT_EXIT].each(&:call)
irb.context.io.save_history if new_history_behavior
end
end
end
Expand Down
12 changes: 3 additions & 9 deletions bridgetown-core/lib/bridgetown-core/log_writer.rb
Expand Up @@ -2,18 +2,12 @@

module Bridgetown
class LogWriter < ::Logger
def initialize # rubocop:disable Lint/MissingSuper
@progname = nil
@level = DEBUG
@default_formatter = Formatter.new
@logdev = $stdout
@formatter = proc do |_, _, _, msg|
msg.to_s
end
def initialize
super $stdout, formatter: proc { |_, _, _, msg| msg.to_s }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

end

def enable_prefix
@formatter = proc do |_, _, _, msg|
self.formatter = proc do |_, _, _, msg|
"\e[32m[Bridgetown]\e[0m #{msg}"
end
end
Expand Down
2 changes: 2 additions & 0 deletions bridgetown-website/Gemfile.lock
Expand Up @@ -13,6 +13,7 @@ PATH
addressable (~> 2.4)
amazing_print (~> 1.2)
colorator (~> 1.0)
csv (~> 3.2)
erubi (~> 1.9)
faraday (~> 2.0)
faraday-follow_redirects (~> 0.3)
Expand Down Expand Up @@ -69,6 +70,7 @@ GEM
nokogiri
colorator (1.1.0)
concurrent-ruby (1.2.2)
csv (3.2.6)
erubi (1.12.0)
faraday (2.7.10)
faraday-net_http (>= 2.0, < 3.1)
Expand Down