From e16c8400c1a784d1de5b2aeedf7928d2a1f79e51 Mon Sep 17 00:00:00 2001 From: Judah Meek Date: Tue, 17 Oct 2017 00:55:08 -0500 Subject: [PATCH] attempt to support both 3.0.1 & 3.0.2 --- lib/react_on_rails/utils.rb | 3 ++- spec/react_on_rails/utils_spec.rb | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/react_on_rails/utils.rb b/lib/react_on_rails/utils.rb index c90f34734..ea26bdf18 100644 --- a/lib/react_on_rails/utils.rb +++ b/lib/react_on_rails/utils.rb @@ -142,7 +142,8 @@ def self.using_webpacker? end def self.bundle_js_file_path_from_webpacker(bundle_name) - hashed_bundle_name = Webpacker.manifest.lookup!(bundle_name) + possible_result = Webpacker.manifest.lookup(bundle_name) + hashed_bundle_name = possible_result.nil? ? Webpacker.manifest.lookup!(bundle_name) : possible_result if Webpacker.dev_server.running? result = "#{Webpacker.dev_server.protocol}://#{Webpacker.dev_server.host_with_port}#{hashed_bundle_name}" result diff --git a/spec/react_on_rails/utils_spec.rb b/spec/react_on_rails/utils_spec.rb index 5a152789f..63c3384a3 100644 --- a/spec/react_on_rails/utils_spec.rb +++ b/spec/react_on_rails/utils_spec.rb @@ -21,7 +21,7 @@ module ReactOnRails .and_return(false) allow(Webpacker).to receive_message_chain("config.public_output_path") .and_return("/webpack/development") - allow(Webpacker).to receive_message_chain("manifest.lookup!") + allow(Webpacker).to receive_message_chain("manifest.lookup") .with("webpack-bundle.js") .and_return("/webpack/development/webpack-bundle-0123456789abcdef.js") allow(Utils).to receive(:using_webpacker?).and_return(true) @@ -42,13 +42,32 @@ module ReactOnRails Utils.server_bundle_js_file_path end - context "With Webpacker enabled and server file not in manifest", :webpacker do + context "With Webpacker 3.0.1 enabled and server file not in manifest", :webpacker do + before do + allow(Rails).to receive(:root).and_return(Pathname.new(".")) + allow(ReactOnRails).to receive_message_chain("configuration.server_bundle_js_file") + .and_return("webpack-bundle.js") + allow(Webpacker).to receive_message_chain("config.public_output_path") + .and_return("public/webpack/development") + allow(Webpacker).to receive_message_chain("manifest.lookup") + .with("webpack-bundle.js") + .and_raise(Webpacker::Manifest::MissingEntryError) + allow(Utils).to receive(:using_webpacker?).and_return(true) + end + + it { expect(subject).to eq("public/webpack/development/webpack-bundle.js") } + end + + context "With Webpacker 3.0.2 enabled and server file not in manifest", :webpacker do before do allow(Rails).to receive(:root).and_return(Pathname.new(".")) allow(ReactOnRails).to receive_message_chain("configuration.server_bundle_js_file") .and_return("webpack-bundle.js") allow(Webpacker).to receive_message_chain("config.public_output_path") .and_return("public/webpack/development") + allow(Webpacker).to receive_message_chain("manifest.lookup") + .with("webpack-bundle.js") + .and_return(nil) allow(Webpacker).to receive_message_chain("manifest.lookup!") .with("webpack-bundle.js") .and_raise(Webpacker::Manifest::MissingEntryError)