Skip to content

Commit 63f59de

Browse files
Merge pull request #3223 from shakacode/justin808-fix-webpakcer-install
Fix so webpacker:install does not require webpacker.yml pre-existing
2 parents d21f87e + eab7a02 commit 63f59de

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/tasks/webpacker/install.rake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ bin_path = ENV["BUNDLE_BIN"] || Rails.root.join("bin")
44
namespace :webpacker do
55
desc "Install Webpacker in this application"
66
task install: [:check_node, :check_yarn] do |task|
7+
Webpacker::Configuration.installing = true
8+
79
prefix = task.name.split(/#|webpacker:install/).first
810

911
if Rails::VERSION::MAJOR >= 5

lib/webpacker/configuration.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
require "active_support/core_ext/hash/indifferent_access"
44

55
class Webpacker::Configuration
6+
class << self
7+
attr_accessor :installing
8+
end
9+
610
attr_reader :root_path, :config_path, :env
711

812
def initialize(root_path:, config_path:, env:)
@@ -80,10 +84,13 @@ def load
8084
end
8185
config[env].deep_symbolize_keys
8286
rescue Errno::ENOENT => e
83-
raise "Webpacker configuration file not found #{config_path}. " \
84-
"Please run rails webpacker:install " \
85-
"Error: #{e.message}"
86-
87+
if self.class.installing
88+
{}
89+
else
90+
raise "Webpacker configuration file not found #{config_path}. " \
91+
"Please run rails webpacker:install " \
92+
"Error: #{e.message}"
93+
end
8794
rescue Psych::SyntaxError => e
8895
raise "YAML syntax error occurred while parsing #{config_path}. " \
8996
"Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \

0 commit comments

Comments
 (0)