From ff9559edc3894384682619644e793d51721271b0 Mon Sep 17 00:00:00 2001 From: Gavin Elster Date: Wed, 10 Jan 2018 14:35:57 -0800 Subject: [PATCH 1/2] Fix Utils.bundle_js_file_path for manifest.json in webpacker projects Utils.bundle_js_file_path was incorrectly returning `'manifest.json'` instead of, say, `'/path/to/rails/public/packs/manifest.json'` Fixes #1011 --- CHANGELOG.md | 3 +++ lib/react_on_rails/utils.rb | 3 +-- spec/react_on_rails/utils_spec.rb | 23 ++++++++++++++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1ec5de7c..7d8bd9c5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ Changes since last non-beta release. *Please add entries here for your pull requests that are not yet released.* +#### Fixed +- Fixed `Utils.bundle_js_file_path` generating the incorrect path for `manifest.json` in webpacker projects: [#1011] by [elstgav](https://github.com/elstgav) + ### [10.0.2] - 2017-11-10 #### Fixed - Remove unnecessary dependencies from released NPM package: [PR 968](https://github.com/shakacode/react_on_rails/pull/968) by [tricknotes](https://github.com/tricknotes). diff --git a/lib/react_on_rails/utils.rb b/lib/react_on_rails/utils.rb index 2c03a9cdf..60762980e 100644 --- a/lib/react_on_rails/utils.rb +++ b/lib/react_on_rails/utils.rb @@ -85,8 +85,7 @@ def self.server_bundle_js_file_path end def self.bundle_js_file_path(bundle_name) - if using_webpacker? - return bundle_name if bundle_name == "manifest.json" + if using_webpacker? && bundle_name != "manifest.json" bundle_js_file_path_from_webpacker(bundle_name) else # Default to the non-hashed name in the specified output directory, which, for legacy diff --git a/spec/react_on_rails/utils_spec.rb b/spec/react_on_rails/utils_spec.rb index 63c3384a3..4213f9f77 100644 --- a/spec/react_on_rails/utils_spec.rb +++ b/spec/react_on_rails/utils_spec.rb @@ -14,20 +14,33 @@ module ReactOnRails Utils.bundle_js_file_path("webpack-bundle.js") end - context "With Webpacker enabled and file in manifest", :webpacker do + context "With Webpacker enabled", :webpacker do before do allow(Rails).to receive(:root).and_return(Pathname.new(".")) allow(Webpacker).to receive_message_chain("dev_server.running?") .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") - .with("webpack-bundle.js") - .and_return("/webpack/development/webpack-bundle-0123456789abcdef.js") allow(Utils).to receive(:using_webpacker?).and_return(true) end - it { expect(subject).to eq("public/webpack/development/webpack-bundle-0123456789abcdef.js") } + context "and file in manifest", :webpacker do + before do + allow(Webpacker).to receive_message_chain("manifest.lookup") + .with("webpack-bundle.js") + .and_return("/webpack/development/webpack-bundle-0123456789abcdef.js") + end + + it { expect(subject).to eq("public/webpack/development/webpack-bundle-0123456789abcdef.js") } + end + + context "manifest.json" do + subject do + Utils.bundle_js_file_path("manifest.json") + end + + it { expect(subject).to eq("public/webpack/development/manifest.json") } + end end context "Without Webpacker enabled" do From 885806309e571dc28d35307150ba3fcea5e6c918 Mon Sep 17 00:00:00 2001 From: Gavin Elster Date: Wed, 10 Jan 2018 15:43:32 -0800 Subject: [PATCH 2/2] Make issue link explicit --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d8bd9c5f..11fc15789 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ Changes since last non-beta release. *Please add entries here for your pull requests that are not yet released.* #### Fixed -- Fixed `Utils.bundle_js_file_path` generating the incorrect path for `manifest.json` in webpacker projects: [#1011] by [elstgav](https://github.com/elstgav) +- Fixed `Utils.bundle_js_file_path` generating the incorrect path for `manifest.json` in webpacker projects: [Issue #1011](https://github.com/shakacode/react_on_rails/issues/1011) by [elstgav](https://github.com/elstgav) ### [10.0.2] - 2017-11-10 #### Fixed