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