From 66b278b80d97cc596cce60fb7086170fc9e5f667 Mon Sep 17 00:00:00 2001 From: Jeremiah-Parrack Date: Thu, 21 Sep 2023 10:07:33 -0400 Subject: [PATCH 1/3] try to fix rubocop ci --- .github/workflows/rubocop.yml | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml index 25a0dba..dd98a15 100644 --- a/.github/workflows/rubocop.yml +++ b/.github/workflows/rubocop.yml @@ -5,35 +5,26 @@ on: [push, pull_request] jobs: build: name: Rubocop - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest env: BUNDLE_JOBS: 4 BUNDLE_RETRY: 3 strategy: matrix: - os: [ubuntu-latest] ruby: [ 2.7 ] steps: - - uses: actions/checkout@v2 - - uses: actions/cache@v2 - with: - path: /home/runner/bundle - key: bundle-use-ruby-gems-${{ hashFiles('**/Gemfile.lock') }} - restore-keys: | - bundle-use-ruby-gems- + - uses: actions/checkout@v3 - - uses: ruby/setup-ruby@v1 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} - - - name: Bundle install - run: | - gem install bundler -v 2.1.4 - bundle config path /home/runner/bundle - bundle install + bundler: default + bundler-cache: true + rubygems: latest - name: Ruby linter - run: rubocop + run: bundle exec rubocop From 87255af207d9761830c88d7c03de12675f6f7b71 Mon Sep 17 00:00:00 2001 From: Jeremiah-Parrack Date: Thu, 21 Sep 2023 10:14:42 -0400 Subject: [PATCH 2/3] Upped rubocop version, fixed offenses --- .rubocop.yml | 2 +- jetpacker.gemspec | 4 +- lib/webpacker/commands.rb | 26 +++---- lib/webpacker/compiler.rb | 106 ++++++++++++++--------------- lib/webpacker/configuration.rb | 76 ++++++++++----------- lib/webpacker/dev_server.rb | 12 ++-- lib/webpacker/dev_server_proxy.rb | 6 +- lib/webpacker/dev_server_runner.rb | 84 +++++++++++------------ lib/webpacker/env.rb | 38 +++++------ lib/webpacker/helper.rb | 30 ++++---- lib/webpacker/manifest.rb | 88 ++++++++++++------------ lib/webpacker/webpack_runner.rb | 6 +- test/dev_server_runner_test.rb | 36 +++++----- test/manifest_test.rb | 18 ++--- test/rake_tasks_test.rb | 22 +++--- test/test_helper.rb | 34 ++++----- test/webpack_runner_test.rb | 36 +++++----- 17 files changed, 312 insertions(+), 312 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index d0fe8e0..fc8c223 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -45,7 +45,7 @@ Style/HashSyntax: # extra level of indentation. Layout/IndentationConsistency: Enabled: true - EnforcedStyle: indented_internal_methods + EnforcedStyle: normal # Detect hard tabs, no hard tabs. Layout/IndentationStyle: diff --git a/jetpacker.gemspec b/jetpacker.gemspec index 3d9eeac..f49e06a 100644 --- a/jetpacker.gemspec +++ b/jetpacker.gemspec @@ -26,8 +26,8 @@ Gem::Specification.new do |s| s.add_dependency "rack-proxy", ">= 0.6.1" s.add_dependency "semantic_range", ">= 2.3.0" - s.add_development_dependency "bundler", ">= 1.3.0" - s.add_development_dependency "rubocop", "< 0.69" + s.add_development_dependency "bundler", ">= 2.4.19" + s.add_development_dependency "rubocop", ">= 1.5.6" s.add_development_dependency "rubocop-performance" s.add_development_dependency "rspec-core" diff --git a/lib/webpacker/commands.rb b/lib/webpacker/commands.rb index d384218..889ebfd 100644 --- a/lib/webpacker/commands.rb +++ b/lib/webpacker/commands.rb @@ -54,21 +54,21 @@ def compile end private - def versions - all_files = Dir.glob("#{config.public_output_path}/**/*") - manifest_config = Dir.glob("#{config.public_manifest_path}*") + def versions + all_files = Dir.glob("#{config.public_output_path}/**/*") + manifest_config = Dir.glob("#{config.public_manifest_path}*") - packs = all_files - manifest_config - current_version - packs.reject { |file| File.directory?(file) }.group_by { |file| File.mtime(file).utc.to_i } - end + packs = all_files - manifest_config - current_version + packs.reject { |file| File.directory?(file) }.group_by { |file| File.mtime(file).utc.to_i } + end - def current_version - packs = manifest.refresh.values.map do |value| - next if value.is_a?(Hash) + def current_version + packs = manifest.refresh.values.map do |value| + next if value.is_a?(Hash) - File.join(config.root_path, "public", "#{value}*") - end.compact + File.join(config.root_path, "public", "#{value}*") + end.compact - Dir.glob(packs).uniq - end + Dir.glob(packs).uniq + end end diff --git a/lib/webpacker/compiler.rb b/lib/webpacker/compiler.rb index 8c1ce6e..7f57806 100644 --- a/lib/webpacker/compiler.rb +++ b/lib/webpacker/compiler.rb @@ -44,68 +44,68 @@ def stale? end private - attr_reader :webpacker + attr_reader :webpacker - def last_compilation_digest - compilation_digest_path.read if compilation_digest_path.exist? && config.public_manifest_path.exist? - rescue Errno::ENOENT, Errno::ENOTDIR - end + def last_compilation_digest + compilation_digest_path.read if compilation_digest_path.exist? && config.public_manifest_path.exist? + rescue Errno::ENOENT, Errno::ENOTDIR + end - def watched_files_digest - warn "Webpacker::Compiler.watched_paths has been deprecated. Set additional_paths in webpacker.yml instead." unless watched_paths.empty? + def watched_files_digest + warn "Webpacker::Compiler.watched_paths has been deprecated. Set additional_paths in webpacker.yml instead." unless watched_paths.empty? - files = Dir[*default_watched_paths, *watched_paths].reject { |f| File.directory?(f) } - file_ids = files.sort.map { |f| "#{File.basename(f)}/#{Digest::SHA1.file(f).hexdigest}" } - Digest::SHA1.hexdigest(file_ids.join("/")) - end + files = Dir[*default_watched_paths, *watched_paths].reject { |f| File.directory?(f) } + file_ids = files.sort.map { |f| "#{File.basename(f)}/#{Digest::SHA1.file(f).hexdigest}" } + Digest::SHA1.hexdigest(file_ids.join("/")) + end - def record_compilation_digest - config.cache_path.mkpath - compilation_digest_path.write(watched_files_digest) - end + def record_compilation_digest + config.cache_path.mkpath + compilation_digest_path.write(watched_files_digest) + end - def run_webpack - logger.info "Compiling..." - - stdout, stderr, status = Open3.capture3( - webpack_env, - "#{RbConfig.ruby} ./bin/webpack", - chdir: File.expand_path(config.root_path) - ) - - if status.success? - logger.info "Compiled all packs in #{config.public_output_path}" - logger.error "#{stderr}" unless stderr.empty? - - if config.webpack_compile_output? - logger.info stdout - end - else - non_empty_streams = [stdout, stderr].delete_if(&:empty?) - logger.error "Compilation failed:\n#{non_empty_streams.join("\n\n")}" - end + def run_webpack + logger.info "Compiling..." - status.success? - end + stdout, stderr, status = Open3.capture3( + webpack_env, + "#{RbConfig.ruby} ./bin/webpack", + chdir: File.expand_path(config.root_path) + ) - def default_watched_paths - [ - *config.additional_paths_globbed, - config.source_path_globbed, - "yarn.lock", "package.json", - "config/webpack/**/*" - ].freeze - end + if status.success? + logger.info "Compiled all packs in #{config.public_output_path}" + logger.error "#{stderr}" unless stderr.empty? - def compilation_digest_path - config.cache_path.join("last-compilation-digest-#{webpacker.env}") + if config.webpack_compile_output? + logger.info stdout + end + else + non_empty_streams = [stdout, stderr].delete_if(&:empty?) + logger.error "Compilation failed:\n#{non_empty_streams.join("\n\n")}" end - def webpack_env - return env unless defined?(ActionController::Base) + status.success? + end - env.merge("WEBPACKER_ASSET_HOST" => ENV.fetch("WEBPACKER_ASSET_HOST", ActionController::Base.helpers.compute_asset_host), - "WEBPACKER_RELATIVE_URL_ROOT" => ENV.fetch("WEBPACKER_RELATIVE_URL_ROOT", ActionController::Base.relative_url_root), - "WEBPACKER_CONFIG" => webpacker.config_path.to_s) - end + def default_watched_paths + [ + *config.additional_paths_globbed, + config.source_path_globbed, + "yarn.lock", "package.json", + "config/webpack/**/*" + ].freeze + end + + def compilation_digest_path + config.cache_path.join("last-compilation-digest-#{webpacker.env}") + end + + def webpack_env + return env unless defined?(ActionController::Base) + + env.merge("WEBPACKER_ASSET_HOST" => ENV.fetch("WEBPACKER_ASSET_HOST", ActionController::Base.helpers.compute_asset_host), + "WEBPACKER_RELATIVE_URL_ROOT" => ENV.fetch("WEBPACKER_RELATIVE_URL_ROOT", ActionController::Base.relative_url_root), + "WEBPACKER_CONFIG" => webpacker.config_path.to_s) + end end diff --git a/lib/webpacker/configuration.rb b/lib/webpacker/configuration.rb index 3a88e0c..b9507c3 100644 --- a/lib/webpacker/configuration.rb +++ b/lib/webpacker/configuration.rb @@ -76,53 +76,53 @@ def extract_css? end private - def resolved_paths - paths = data.fetch(:resolved_paths, []) + def resolved_paths + paths = data.fetch(:resolved_paths, []) - warn "The resolved_paths option has been deprecated. Use additional_paths instead." unless paths.empty? + warn "The resolved_paths option has been deprecated. Use additional_paths instead." unless paths.empty? - paths - end + paths + end - def fetch(key) - data.fetch(key, defaults[key]) - end + def fetch(key) + data.fetch(key, defaults[key]) + end - def data - @data ||= load + def data + @data ||= load + end + + def load + config = begin + YAML.load_file(config_path.to_s, aliases: true) + rescue ArgumentError + YAML.load_file(config_path.to_s) end + config[env].deep_symbolize_keys + rescue Errno::ENOENT => e + raise "Webpacker configuration file not found #{config_path}. " \ + "Please run rails webpacker:install " \ + "Error: #{e.message}" + + rescue Psych::SyntaxError => e + raise "YAML syntax error occurred while parsing #{config_path}. " \ + "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \ + "Error: #{e.message}" + end - def load + def defaults + @defaults ||= begin + path = File.expand_path("../../install/config/webpacker.yml", __FILE__) config = begin - YAML.load_file(config_path.to_s, aliases: true) + YAML.load_file(path, aliases: true) rescue ArgumentError - YAML.load_file(config_path.to_s) - end - config[env].deep_symbolize_keys - rescue Errno::ENOENT => e - raise "Webpacker configuration file not found #{config_path}. " \ - "Please run rails webpacker:install " \ - "Error: #{e.message}" - - rescue Psych::SyntaxError => e - raise "YAML syntax error occurred while parsing #{config_path}. " \ - "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \ - "Error: #{e.message}" - end - - def defaults - @defaults ||= begin - path = File.expand_path("../../install/config/webpacker.yml", __FILE__) - config = begin - YAML.load_file(path, aliases: true) - rescue ArgumentError - YAML.load_file(path) - end - HashWithIndifferentAccess.new(config[env]) + YAML.load_file(path) end + HashWithIndifferentAccess.new(config[env]) end + end - def globbed_path_with_extensions(path) - "#{path}/**/*{#{extensions.join(',')}}" - end + def globbed_path_with_extensions(path) + "#{path}/**/*{#{extensions.join(',')}}" + end end diff --git a/lib/webpacker/dev_server.rb b/lib/webpacker/dev_server.rb index c38a2f7..6ecc710 100644 --- a/lib/webpacker/dev_server.rb +++ b/lib/webpacker/dev_server.rb @@ -56,11 +56,11 @@ def env_prefix end private - def fetch(key) - ENV["#{env_prefix}_#{key.upcase}"] || config.dev_server.fetch(key, defaults[key]) - end + def fetch(key) + ENV["#{env_prefix}_#{key.upcase}"] || config.dev_server.fetch(key, defaults[key]) + end - def defaults - config.send(:defaults)[:dev_server] || {} - end + def defaults + config.send(:defaults)[:dev_server] || {} + end end diff --git a/lib/webpacker/dev_server_proxy.rb b/lib/webpacker/dev_server_proxy.rb index be8fbd1..cec6bdb 100644 --- a/lib/webpacker/dev_server_proxy.rb +++ b/lib/webpacker/dev_server_proxy.rb @@ -27,7 +27,7 @@ def perform_request(env) end private - def public_output_uri_path - config.public_output_path.relative_path_from(config.public_path).to_s + "/" - end + def public_output_uri_path + config.public_output_path.relative_path_from(config.public_path).to_s + "/" + end end diff --git a/lib/webpacker/dev_server_runner.rb b/lib/webpacker/dev_server_runner.rb index 1e5bf75..8c3c8a7 100644 --- a/lib/webpacker/dev_server_runner.rb +++ b/lib/webpacker/dev_server_runner.rb @@ -13,60 +13,60 @@ def run end private - def load_config - app_root = Pathname.new(@app_path) + def load_config + app_root = Pathname.new(@app_path) - @config = Configuration.new( - root_path: app_root, - config_path: app_root.join("config/webpacker.yml"), - env: ENV["JETS_ENV"] - ) + @config = Configuration.new( + root_path: app_root, + config_path: app_root.join("config/webpacker.yml"), + env: ENV["JETS_ENV"] + ) - dev_server = DevServer.new(@config) + dev_server = DevServer.new(@config) - @hostname = dev_server.host - @port = dev_server.port - @pretty = dev_server.pretty? + @hostname = dev_server.host + @port = dev_server.port + @pretty = dev_server.pretty? - rescue Errno::ENOENT, NoMethodError - $stdout.puts "webpack dev_server configuration not found in #{@config.config_path}[#{ENV["JETS_ENV"]}]." - $stdout.puts "Please run bundle exec rails webpacker:install to install Webpacker" - exit! - end + rescue Errno::ENOENT, NoMethodError + $stdout.puts "webpack dev_server configuration not found in #{@config.config_path}[#{ENV["JETS_ENV"]}]." + $stdout.puts "Please run bundle exec rails webpacker:install to install Webpacker" + exit! + end - def detect_port! - server = TCPServer.new(@hostname, @port) - server.close + def detect_port! + server = TCPServer.new(@hostname, @port) + server.close - rescue Errno::EADDRINUSE - $stdout.puts "Another program is running on port #{@port}. Set a new port in #{@config.config_path} for dev_server" - exit! - end + rescue Errno::EADDRINUSE + $stdout.puts "Another program is running on port #{@port}. Set a new port in #{@config.config_path} for dev_server" + exit! + end - def execute_cmd - env = Webpacker::Compiler.env - env["WEBPACKER_CONFIG"] = @webpacker_config + def execute_cmd + env = Webpacker::Compiler.env + env["WEBPACKER_CONFIG"] = @webpacker_config - cmd = if node_modules_bin_exist? - ["#{@node_modules_bin_path}/webpack-dev-server"] - else - ["yarn", "webpack-dev-server"] - end + cmd = if node_modules_bin_exist? + ["#{@node_modules_bin_path}/webpack-dev-server"] + else + ["yarn", "webpack-dev-server"] + end - if @argv.include?("--debug-webpacker") - cmd = [ "node", "--inspect-brk"] + cmd - end + if @argv.include?("--debug-webpacker") + cmd = [ "node", "--inspect-brk"] + cmd + end - cmd += ["--config", @webpack_config] - cmd += ["--progress", "--color"] if @pretty + cmd += ["--config", @webpack_config] + cmd += ["--progress", "--color"] if @pretty - Dir.chdir(@app_path) do - Kernel.exec env, *cmd - end + Dir.chdir(@app_path) do + Kernel.exec env, *cmd end + end - def node_modules_bin_exist? - File.exist?("#{@node_modules_bin_path}/webpack-dev-server") - end + def node_modules_bin_exist? + File.exist?("#{@node_modules_bin_path}/webpack-dev-server") + end end end diff --git a/lib/webpacker/env.rb b/lib/webpacker/env.rb index 7c2fa23..8ed84f4 100644 --- a/lib/webpacker/env.rb +++ b/lib/webpacker/env.rb @@ -17,27 +17,27 @@ def inquire end private - def current - Jets.env.presence_in(available_environments) - end + def current + Jets.env.presence_in(available_environments) + end - def fallback_env_warning - logger.info "JETS_ENV=#{Jets.env} environment is not defined in config/webpacker.yml, falling back to #{DEFAULT} environment" - end + def fallback_env_warning + logger.info "JETS_ENV=#{Jets.env} environment is not defined in config/webpacker.yml, falling back to #{DEFAULT} environment" + end - def available_environments - if config_path.exist? - begin - YAML.load_file(config_path.to_s, aliases: true) - rescue ArgumentError - YAML.load_file(config_path.to_s) - end - else - [].freeze + def available_environments + if config_path.exist? + begin + YAML.load_file(config_path.to_s, aliases: true) + rescue ArgumentError + YAML.load_file(config_path.to_s) end - rescue Psych::SyntaxError => e - raise "YAML syntax error occurred while parsing #{config_path}. " \ - "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \ - "Error: #{e.message}" + else + [].freeze end + rescue Psych::SyntaxError => e + raise "YAML syntax error occurred while parsing #{config_path}. " \ + "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \ + "Error: #{e.message}" + end end diff --git a/lib/webpacker/helper.rb b/lib/webpacker/helper.rb index 156bed6..b576c37 100644 --- a/lib/webpacker/helper.rb +++ b/lib/webpacker/helper.rb @@ -174,22 +174,22 @@ def stylesheet_packs_with_chunks_tag(*names, **options) end private - def stylesheet?(name) - File.extname(name) == ".css" - end + def stylesheet?(name) + File.extname(name) == ".css" + end - def sources_from_manifest_entries(names, type:) - names.map { |name| current_webpacker_instance.manifest.lookup!(name, type: type) }.flatten - end + def sources_from_manifest_entries(names, type:) + names.map { |name| current_webpacker_instance.manifest.lookup!(name, type: type) }.flatten + end - def sources_from_manifest_entrypoints(names, type:) - names.map { |name| current_webpacker_instance.manifest.lookup_pack_with_chunks!(name, type: type) }.flatten.uniq - end + def sources_from_manifest_entrypoints(names, type:) + names.map { |name| current_webpacker_instance.manifest.lookup_pack_with_chunks!(name, type: type) }.flatten.uniq + end - def resolve_path_to_image(name) - path = name.starts_with?("media/images/") ? name : "media/images/#{name}" - path_to_asset(current_webpacker_instance.manifest.lookup!(path)) - rescue - path_to_asset(current_webpacker_instance.manifest.lookup!(name)) - end + def resolve_path_to_image(name) + path = name.starts_with?("media/images/") ? name : "media/images/#{name}" + path_to_asset(current_webpacker_instance.manifest.lookup!(path)) + rescue + path_to_asset(current_webpacker_instance.manifest.lookup!(name)) + end end diff --git a/lib/webpacker/manifest.rb b/lib/webpacker/manifest.rb index 0fc1186..23b8bdf 100644 --- a/lib/webpacker/manifest.rb +++ b/lib/webpacker/manifest.rb @@ -50,61 +50,61 @@ def lookup!(name, pack_type = {}) end private - def compiling? - config.compile? && !dev_server.running? - end + def compiling? + config.compile? && !dev_server.running? + end - def compile - Webpacker.logger.tagged("Webpacker") { compiler.compile } - end + def compile + Webpacker.logger.tagged("Webpacker") { compiler.compile } + end - def data - if config.cache_manifest? - @data ||= load - else - refresh - end + def data + if config.cache_manifest? + @data ||= load + else + refresh end + end - def find(name) - data[name.to_s].presence - end + def find(name) + data[name.to_s].presence + end - def full_pack_name(name, pack_type) - return name unless File.extname(name.to_s).empty? - "#{name}.#{manifest_type(pack_type)}" - end + def full_pack_name(name, pack_type) + return name unless File.extname(name.to_s).empty? + "#{name}.#{manifest_type(pack_type)}" + end - def handle_missing_entry(name, pack_type) - raise Webpacker::Manifest::MissingEntryError, missing_file_from_manifest_error(full_pack_name(name, pack_type[:type])) - end + def handle_missing_entry(name, pack_type) + raise Webpacker::Manifest::MissingEntryError, missing_file_from_manifest_error(full_pack_name(name, pack_type[:type])) + end - def load - if config.public_manifest_path.exist? - JSON.parse config.public_manifest_path.read - else - {} - end + def load + if config.public_manifest_path.exist? + JSON.parse config.public_manifest_path.read + else + {} end + end - # The `manifest_name` method strips of the file extension of the name, because in the - # manifest hash the entrypoints are defined by their pack name without the extension. - # When the user provides a name with a file extension, we want to try to strip it off. - def manifest_name(name, pack_type) - return name if File.extname(name.to_s).empty? - File.basename(name, pack_type) - end + # The `manifest_name` method strips of the file extension of the name, because in the + # manifest hash the entrypoints are defined by their pack name without the extension. + # When the user provides a name with a file extension, we want to try to strip it off. + def manifest_name(name, pack_type) + return name if File.extname(name.to_s).empty? + File.basename(name, pack_type) + end - def manifest_type(pack_type) - case pack_type - when :javascript then "js" - when :stylesheet then "css" - else pack_type.to_s - end + def manifest_type(pack_type) + case pack_type + when :javascript then "js" + when :stylesheet then "css" + else pack_type.to_s end + end - def missing_file_from_manifest_error(bundle_name) - <<-MSG + def missing_file_from_manifest_error(bundle_name) + <<-MSG Webpacker can't find #{bundle_name} in #{config.public_manifest_path}. Possible causes: 1. You want to set webpacker.yml value of compile to true for your environment unless you are using the `webpack -w` or the webpack-dev-server. @@ -114,5 +114,5 @@ def missing_file_from_manifest_error(bundle_name) Your manifest contains: #{JSON.pretty_generate(@data)} MSG - end + end end diff --git a/lib/webpacker/webpack_runner.rb b/lib/webpacker/webpack_runner.rb index c0e5608..bad2af4 100644 --- a/lib/webpacker/webpack_runner.rb +++ b/lib/webpacker/webpack_runner.rb @@ -25,8 +25,8 @@ def run end private - def node_modules_bin_exist? - File.exist?("#{@node_modules_bin_path}/webpack") - end + def node_modules_bin_exist? + File.exist?("#{@node_modules_bin_path}/webpack") + end end end diff --git a/test/dev_server_runner_test.rb b/test/dev_server_runner_test.rb index 54716c7..d36a442 100644 --- a/test/dev_server_runner_test.rb +++ b/test/dev_server_runner_test.rb @@ -25,27 +25,27 @@ def test_run_cmd_via_yarn end private - def test_app_path - File.expand_path("test_app", __dir__) - end + def test_app_path + File.expand_path("test_app", __dir__) + end - def verify_command(cmd, use_node_modules: true) - cwd = Dir.pwd - Dir.chdir(test_app_path) + def verify_command(cmd, use_node_modules: true) + cwd = Dir.pwd + Dir.chdir(test_app_path) - klass = Webpacker::DevServerRunner - instance = klass.new([]) - mock = Minitest::Mock.new - mock.expect(:call, nil, [Webpacker::Compiler.env, *cmd]) + klass = Webpacker::DevServerRunner + instance = klass.new([]) + mock = Minitest::Mock.new + mock.expect(:call, nil, [Webpacker::Compiler.env, *cmd]) - klass.stub(:new, instance) do - instance.stub(:node_modules_bin_exist?, use_node_modules) do - Kernel.stub(:exec, mock) { klass.run([]) } - end + klass.stub(:new, instance) do + instance.stub(:node_modules_bin_exist?, use_node_modules) do + Kernel.stub(:exec, mock) { klass.run([]) } end - - mock.verify - ensure - Dir.chdir(cwd) end + + mock.verify + ensure + Dir.chdir(cwd) + end end diff --git a/test/manifest_test.rb b/test/manifest_test.rb index efacc93..905cc49 100644 --- a/test/manifest_test.rb +++ b/test/manifest_test.rb @@ -59,15 +59,15 @@ def test_lookup_entrypoint private - def assert_raises_manifest_missing_entry_error(&block) - error = nil - Webpacker.config.stub :compile?, false do - error = assert_raises Webpacker::Manifest::MissingEntryError, &block - end - error + def assert_raises_manifest_missing_entry_error(&block) + error = nil + Webpacker.config.stub :compile?, false do + error = assert_raises Webpacker::Manifest::MissingEntryError, &block end + error + end - def manifest_path - File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs", "manifest.json").to_s - end + def manifest_path + File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs", "manifest.json").to_s + end end diff --git a/test/rake_tasks_test.rb b/test/rake_tasks_test.rb index de5ec86..e90f6b3 100644 --- a/test/rake_tasks_test.rb +++ b/test/rake_tasks_test.rb @@ -65,17 +65,17 @@ def test_rake_webpacker_yarn_install_in_production_environment end private - def test_app_path - File.expand_path("test_app", __dir__) - end + def test_app_path + File.expand_path("test_app", __dir__) + end - def test_app_dev_dependencies - package_json = File.expand_path("package.json", test_app_path) - JSON.parse(File.read(package_json))["devDependencies"] - end + def test_app_dev_dependencies + package_json = File.expand_path("package.json", test_app_path) + JSON.parse(File.read(package_json))["devDependencies"] + end - def installed_node_module_names - node_modules_path = File.expand_path("node_modules", test_app_path) - Dir.chdir(node_modules_path) { Dir.glob("*") } - end + def installed_node_module_names + node_modules_path = File.expand_path("node_modules", test_app_path) + Dir.chdir(node_modules_path) { Dir.glob("*") } + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 164bb24..75c829f 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -12,22 +12,22 @@ class Webpacker::Test < Minitest::Test private - def reloaded_config - Webpacker.instance.instance_variable_set(:@env, nil) - Webpacker.instance.instance_variable_set(:@config, nil) - Webpacker.instance.instance_variable_set(:@dev_server, nil) - Webpacker.env - Webpacker.config - Webpacker.dev_server - end + def reloaded_config + Webpacker.instance.instance_variable_set(:@env, nil) + Webpacker.instance.instance_variable_set(:@config, nil) + Webpacker.instance.instance_variable_set(:@dev_server, nil) + Webpacker.env + Webpacker.config + Webpacker.dev_server + end - def with_rails_env(env) - original = Rails.env - Rails.env = ActiveSupport::StringInquirer.new(env) - reloaded_config - yield - ensure - Rails.env = ActiveSupport::StringInquirer.new(original) - reloaded_config - end + def with_rails_env(env) + original = Rails.env + Rails.env = ActiveSupport::StringInquirer.new(env) + reloaded_config + yield + ensure + Rails.env = ActiveSupport::StringInquirer.new(original) + reloaded_config + end end diff --git a/test/webpack_runner_test.rb b/test/webpack_runner_test.rb index 3af5913..ceb2133 100644 --- a/test/webpack_runner_test.rb +++ b/test/webpack_runner_test.rb @@ -25,27 +25,27 @@ def test_run_cmd_via_yarn end private - def test_app_path - File.expand_path("test_app", __dir__) - end + def test_app_path + File.expand_path("test_app", __dir__) + end - def verify_command(cmd, use_node_modules: true) - cwd = Dir.pwd - Dir.chdir(test_app_path) + def verify_command(cmd, use_node_modules: true) + cwd = Dir.pwd + Dir.chdir(test_app_path) - klass = Webpacker::WebpackRunner - instance = klass.new([]) - mock = Minitest::Mock.new - mock.expect(:call, nil, [Webpacker::Compiler.env, *cmd]) + klass = Webpacker::WebpackRunner + instance = klass.new([]) + mock = Minitest::Mock.new + mock.expect(:call, nil, [Webpacker::Compiler.env, *cmd]) - klass.stub(:new, instance) do - instance.stub(:node_modules_bin_exist?, use_node_modules) do - Kernel.stub(:exec, mock) { klass.run([]) } - end + klass.stub(:new, instance) do + instance.stub(:node_modules_bin_exist?, use_node_modules) do + Kernel.stub(:exec, mock) { klass.run([]) } end - - mock.verify - ensure - Dir.chdir(cwd) end + + mock.verify + ensure + Dir.chdir(cwd) + end end From af51967af0ec0a3a64b2ecc0c919420e68843a6e Mon Sep 17 00:00:00 2001 From: Jeremiah-Parrack Date: Thu, 21 Sep 2023 12:32:26 -0400 Subject: [PATCH 3/3] remove old versions of node --- .github/workflows/jest.yml | 2 +- .github/workflows/js-lint.yml | 2 +- .github/workflows/ruby.yml | 58 ----------------------------------- 3 files changed, 2 insertions(+), 60 deletions(-) delete mode 100644 .github/workflows/ruby.yml diff --git a/.github/workflows/jest.yml b/.github/workflows/jest.yml index ed7a31e..62270ea 100644 --- a/.github/workflows/jest.yml +++ b/.github/workflows/jest.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - node: [10.x, 12.x, 14.x] + node: [16.x] runs-on: ${{ matrix.os }} diff --git a/.github/workflows/js-lint.yml b/.github/workflows/js-lint.yml index c73d9c7..06b5b41 100644 --- a/.github/workflows/js-lint.yml +++ b/.github/workflows/js-lint.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - node: [12.x] + node: [16.x] runs-on: ${{ matrix.os }} diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml deleted file mode 100644 index 01c38d5..0000000 --- a/.github/workflows/ruby.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: Ruby specs - -on: [push, pull_request] - -jobs: - build: - name: Ruby specs - runs-on: ${{ matrix.os }} - continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' || matrix.experimental }} - env: - BUNDLE_JOBS: 4 - BUNDLE_RETRY: 3 - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest] - ruby: [ - 2.4, - 2.5, - 2.6, - 2.7 - ] - gemfile: [ - "gemfiles/Gemfile-rails.5.2.x", - "gemfiles/Gemfile-rails.6.0.x" - ] - exclude: - - ruby: "2.4" - gemfile: gemfiles/Gemfile-rails.6.0.x - experimental: [false] - include: - - ruby: 2.7 - os: ubuntu-latest - gemfile: gemfiles/Gemfile-rails-edge - experimental: true - - steps: - - uses: actions/checkout@v2 - - uses: actions/cache@v2 - with: - path: /home/runner/bundle - key: bundle-use-ruby-${{ matrix.ruby }}-${{ matrix.gemfile }}-gems-${{ hashFiles(matrix.gemfile) }}-${{ hashFiles('**/*.gemspec') }} - restore-keys: | - bundle-use-ruby-${{ matrix.ruby }}-${{ matrix.gemfile }}-gems- - - - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - - - name: Bundle install - run: | - gem install bundler -v 2.1.4 - bundle config path /home/runner/bundle - bundle config --global gemfile ${{ matrix.gemfile }} - bundle install --jobs 4 --retry 3 - - - name: Ruby specs - run: bundle exec rake test