Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Utils.bundle_js_file_path for manifest.json in webpacker projects #1012

Merged
merged 2 commits into from
Jan 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: [Issue #1011](https://github.com/shakacode/react_on_rails/issues/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).
Expand Down
3 changes: 1 addition & 2 deletions lib/react_on_rails/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 18 additions & 5 deletions spec/react_on_rails/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down