From 5456b22a538212bca03bcd70a3b03bc69d2125ad Mon Sep 17 00:00:00 2001 From: Taylor Brown Date: Mon, 3 Jun 2019 14:27:39 -0500 Subject: [PATCH 1/2] Record the compilation digest even on webpack error Fixes rails/webpacker/issues/2113 --- lib/webpacker/compiler.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/webpacker/compiler.rb b/lib/webpacker/compiler.rb index 016afb9cd..814ba0b91 100644 --- a/lib/webpacker/compiler.rb +++ b/lib/webpacker/compiler.rb @@ -19,7 +19,12 @@ def initialize(webpacker) def compile if stale? run_webpack.tap do |success| - record_compilation_digest if success + # We used to only record the digest on success + # However, the output file is still written on error, (at least with ts-loader), meaning that the + # digest should still be updated. If it's not, you can end up in a situation where a recompile doesn't + # take place when it should. + # See https://github.com/rails/webpacker/issues/2113 + record_compilation_digest end else true From a8e42d90e6cd57870f5e98ca36b37a91a9546401 Mon Sep 17 00:00:00 2001 From: Jake Niemiec Date: Fri, 7 Jun 2019 16:14:49 -0500 Subject: [PATCH 2/2] fix: failed builds should return as fresh If it returns stale, the error message will never make it to the `webpack-dev-server` overlay. This also fixes typescript related problems in #2113 --- test/compiler_test.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/compiler_test.rb b/test/compiler_test.rb index d1e5fc7c1..712321860 100644 --- a/test/compiler_test.rb +++ b/test/compiler_test.rb @@ -49,14 +49,13 @@ def test_freshness_on_compile_success end end - def test_staleness_on_compile_fail + def test_freshness_on_compile_fail status = OpenStruct.new(success?: false) assert Webpacker.compiler.stale? Open3.stub :capture3, [:sterr, :stdout, status] do - Webpacker.compiler.compile - assert Webpacker.compiler.stale? + assert Webpacker.compiler.fresh? end end