From 09ebeb52c63b2f96ea834e36218d544623c9bbff Mon Sep 17 00:00:00 2001 From: naganowl Date: Wed, 20 Jul 2016 15:53:00 -0700 Subject: [PATCH 1/2] Add HTTPS option specific for manifest load Similar to the other manifest options (host + port), we should be able to specify the protocol for serving the manifest file. This is helpful for allowing the server be proxied via HTTPS but still run the dev server via HTTP. --- lib/webpack/rails/manifest.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/webpack/rails/manifest.rb b/lib/webpack/rails/manifest.rb index 7226b67..33f2a56 100644 --- a/lib/webpack/rails/manifest.rb +++ b/lib/webpack/rails/manifest.rb @@ -65,7 +65,7 @@ def load_dev_server_manifest host = ::Rails.configuration.webpack.dev_server.manifest_host port = ::Rails.configuration.webpack.dev_server.manifest_port http = Net::HTTP.new(host, port) - http.use_ssl = ::Rails.configuration.webpack.dev_server.https + http.use_ssl = ::Rails.configuration.webpack.dev_server.manifest_https http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.get(dev_server_path).body rescue => e From 559947fa521b7a09ab84443c5d152095b087c5ab Mon Sep 17 00:00:00 2001 From: Juan-Carlos Medina and Naomi Jacobs Date: Wed, 14 Sep 2016 14:52:27 -0700 Subject: [PATCH 2/2] Do not raise if webpack actually bundles But still raise if webpack failed to bundle --- lib/webpack/rails/manifest.rb | 6 +++++- spec/manifest_spec.rb | 39 +++++++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/lib/webpack/rails/manifest.rb b/lib/webpack/rails/manifest.rb index 33f2a56..9bf47cc 100644 --- a/lib/webpack/rails/manifest.rb +++ b/lib/webpack/rails/manifest.rb @@ -26,7 +26,7 @@ class EntryPointMissingError < StandardError class << self # :nodoc: def asset_paths(source) - raise WebpackError, manifest["errors"] if manifest["errors"].present? + raise WebpackError, manifest["errors"] unless manifest_bundled? paths = manifest["assetsByChunkName"][source] if paths @@ -42,6 +42,10 @@ def asset_paths(source) private + def manifest_bundled? + !manifest["errors"].any? { |error| error.include? "Module build failed" } + end + def manifest if ::Rails.configuration.webpack.dev_server.enabled # Don't cache if we're in dev server mode, manifest may change ... diff --git a/spec/manifest_spec.rb b/spec/manifest_spec.rb index aa19f2b..03b615a 100644 --- a/spec/manifest_spec.rb +++ b/spec/manifest_spec.rb @@ -5,6 +5,7 @@ let(:manifest) do <<-EOF { + "errors": [], "assetsByChunkName": { "entry1": [ "entry1.js", "entry1-a.js" ], "entry2": "entry2.js" @@ -55,17 +56,33 @@ expect { Webpack::Rails::Manifest.asset_paths("entry1") }.to raise_error(Webpack::Rails::Manifest::ManifestLoadError) end - it "should error if webpack gives us an error in its manifest" do - error_manifest = JSON.parse(manifest).merge("errors" => ["something went wrong"]).to_json - stub_request(:get, "http://server-host:4000/public_path/my_manifest.json").to_return(body: error_manifest, status: 200) - - expect { Webpack::Rails::Manifest.asset_paths("entry1") }.to raise_error(Webpack::Rails::Manifest::WebpackError) - end - - it "should not error if errors is present but empty" do - error_manifest = JSON.parse(manifest).merge("errors" => []).to_json - stub_request(:get, "http://server-host:4000/public_path/my_manifest.json").to_return(body: error_manifest, status: 200) - expect { Webpack::Rails::Manifest.asset_paths("entry1") }.to_not raise_error + describe "webpack errors" do + context "when webpack has 'Module build failed' errors in its manifest" do + it "should error" do + error_manifest = JSON.parse(manifest).merge("errors" => [ + "somethingModule build failed something", + "I am an error" + ]).to_json + stub_request(:get, "http://server-host:4000/public_path/my_manifest.json").to_return(body: error_manifest, status: 200) + + expect { Webpack::Rails::Manifest.asset_paths("entry1") }.to raise_error(Webpack::Rails::Manifest::WebpackError) + end + end + + context "when webpack does not have 'Module build failed' errors in its manifest" do + it "should not error" do + error_manifest = JSON.parse(manifest).merge("errors" => ["something went wrong"]).to_json + stub_request(:get, "http://server-host:4000/public_path/my_manifest.json").to_return(body: error_manifest, status: 200) + + expect { Webpack::Rails::Manifest.asset_paths("entry1") }.to_not raise_error + end + end + + it "should not error if errors is present but empty" do + error_manifest = JSON.parse(manifest).merge("errors" => []).to_json + stub_request(:get, "http://server-host:4000/public_path/my_manifest.json").to_return(body: error_manifest, status: 200) + expect { Webpack::Rails::Manifest.asset_paths("entry1") }.to_not raise_error + end end end