From 195396f1e6dd1cb94d4c12887ae40884a6c18505 Mon Sep 17 00:00:00 2001 From: Taylor Brown Date: Mon, 10 Jun 2019 09:08:57 -0500 Subject: [PATCH] Record the compilation digest even on webpack error (#2117) * Record the compilation digest even on webpack error Fixes rails/webpacker/issues/2113 * 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 --- lib/webpacker/compiler.rb | 7 ++++++- test/compiler_test.rb | 5 ++--- 2 files changed, 8 insertions(+), 4 deletions(-) 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 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