Skip to content

Commit

Permalink
Merge pull request #3223 from shakacode/justin808-fix-webpakcer-install
Browse files Browse the repository at this point in the history
Fix so webpacker:install does not require webpacker.yml pre-existing
  • Loading branch information
guillaumebriday committed Nov 15, 2021
2 parents d21f87e + eab7a02 commit 63f59de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/tasks/webpacker/install.rake
Expand Up @@ -4,6 +4,8 @@ bin_path = ENV["BUNDLE_BIN"] || Rails.root.join("bin")
namespace :webpacker do
desc "Install Webpacker in this application"
task install: [:check_node, :check_yarn] do |task|
Webpacker::Configuration.installing = true

prefix = task.name.split(/#|webpacker:install/).first

if Rails::VERSION::MAJOR >= 5
Expand Down
15 changes: 11 additions & 4 deletions lib/webpacker/configuration.rb
Expand Up @@ -3,6 +3,10 @@
require "active_support/core_ext/hash/indifferent_access"

class Webpacker::Configuration
class << self
attr_accessor :installing
end

attr_reader :root_path, :config_path, :env

def initialize(root_path:, config_path:, env:)
Expand Down Expand Up @@ -80,10 +84,13 @@ def load
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}"

if self.class.installing
{}
else
raise "Webpacker configuration file not found #{config_path}. " \
"Please run rails webpacker:install " \
"Error: #{e.message}"
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. " \
Expand Down

0 comments on commit 63f59de

Please sign in to comment.