Skip to content

Commit 6fad1af

Browse files
committed
Handle case of no webpacker installed
1 parent b2868ce commit 6fad1af

3 files changed

Lines changed: 29 additions & 24 deletions

File tree

lib/react_on_rails/test_helper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def self.ensure_assets_compiled(webpack_assets_status_checker: nil,
7676
puts
7777
@printed_once = true
7878

79-
if ReactOnRails::Utils.source_path_is_not_defined_and_custom_node_modules?
79+
if ReactOnRails::WebpackerUtils.using_webpacker? &&
80+
ReactOnRails::Utils.using_webpacker_source_path_is_not_defined_and_custom_node_modules?
8081
msg = <<-MSG.strip_heredoc
8182
WARNING: Define config.webpacker.yml to include sourcePath to configure
8283
the location of your JavaScript source for React on Rails.

lib/react_on_rails/utils.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ def self.source_path
137137
end
138138
end
139139

140-
def self.source_path_is_not_defined_and_custom_node_modules?
140+
def self.using_webpacker_source_path_is_not_defined_and_custom_node_modules?
141+
return false unless ReactOnRails::WebpackerUtils.using_webpacker?
142+
141143
!ReactOnRails::WebpackerUtils.webpacker_source_path_explicit? &&
142144
ReactOnRails.configuration.node_modules_location.present?
143145
end

spec/react_on_rails/utils_spec.rb

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,32 +71,34 @@ module ReactOnRails
7171
end
7272
end
7373

74-
describe ".source_path_is_not_defined_and_custom_node_modules?" do
75-
it "returns false if node_modules is blank" do
76-
allow(ReactOnRails).to receive_message_chain("configuration.node_modules_location")
77-
.and_return("")
78-
allow(Webpacker).to receive_message_chain("config.send").with(:data)
79-
.and_return({})
80-
81-
expect(ReactOnRails::Utils.source_path_is_not_defined_and_custom_node_modules?).to eq(false)
82-
end
74+
if ReactOnRails::WebpackerUtils.using_webpacker?
75+
describe ".source_path_is_not_defined_and_custom_node_modules?" do
76+
it "returns false if node_modules is blank" do
77+
allow(ReactOnRails).to receive_message_chain("configuration.node_modules_location")
78+
.and_return("")
79+
allow(Webpacker).to receive_message_chain("config.send").with(:data)
80+
.and_return({})
8381

84-
it "returns false if source_path is defined in the config/webpacker.yml and node_modules defined" do
85-
allow(ReactOnRails).to receive_message_chain("configuration.node_modules_location")
86-
.and_return("client")
87-
allow(Webpacker).to receive_message_chain("config.send").with(:data)
88-
.and_return(source_path: "client/app")
82+
expect(ReactOnRails::Utils.using_webpacker_source_path_is_not_defined_and_custom_node_modules?).to eq(false)
83+
end
8984

90-
expect(ReactOnRails::Utils.source_path_is_not_defined_and_custom_node_modules?).to eq(false)
91-
end
85+
it "returns false if source_path is defined in the config/webpacker.yml and node_modules defined" do
86+
allow(ReactOnRails).to receive_message_chain("configuration.node_modules_location")
87+
.and_return("client")
88+
allow(Webpacker).to receive_message_chain("config.send").with(:data)
89+
.and_return(source_path: "client/app")
9290

93-
it "returns true if node_modules is not blank and the source_path is not defined in config/webpacker.yml" do
94-
allow(ReactOnRails).to receive_message_chain("configuration.node_modules_location")
95-
.and_return("node_modules")
96-
allow(Webpacker).to receive_message_chain("config.send").with(:data)
97-
.and_return({})
91+
expect(ReactOnRails::Utils.using_webpacker_source_path_is_not_defined_and_custom_node_modules?).to eq(false)
92+
end
93+
94+
it "returns true if node_modules is not blank and the source_path is not defined in config/webpacker.yml" do
95+
allow(ReactOnRails).to receive_message_chain("configuration.node_modules_location")
96+
.and_return("node_modules")
97+
allow(Webpacker).to receive_message_chain("config.send").with(:data)
98+
.and_return({})
9899

99-
expect(ReactOnRails::Utils.source_path_is_not_defined_and_custom_node_modules?).to eq(true)
100+
expect(ReactOnRails::Utils.using_webpacker_source_path_is_not_defined_and_custom_node_modules?).to eq(true)
101+
end
100102
end
101103
end
102104

0 commit comments

Comments
 (0)