Skip to content

Commit

Permalink
Merge pull request #7 from jeremiahlukus/fix-tests
Browse files Browse the repository at this point in the history
Fix github rubocop workflow, remove ruby test workflow
  • Loading branch information
jeremiahlukus authored Dec 13, 2023
2 parents 59671fc + af51967 commit 947b177
Show file tree
Hide file tree
Showing 21 changed files with 322 additions and 389 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/jest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node: [10.x, 12.x, 14.x]
node: [16.x]

runs-on: ${{ matrix.os }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/js-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node: [12.x]
node: [16.x]

runs-on: ${{ matrix.os }}

Expand Down
25 changes: 8 additions & 17 deletions .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
58 changes: 0 additions & 58 deletions .github/workflows/ruby.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions jetpacker.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
26 changes: 13 additions & 13 deletions lib/webpacker/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
106 changes: 53 additions & 53 deletions lib/webpacker/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
76 changes: 38 additions & 38 deletions lib/webpacker/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit 947b177

Please sign in to comment.