Skip to content

Commit c38209b

Browse files
rosstagauravtiwari
authored andcommitted
Remove compilation digest file if webpack command fails (#1399)
1 parent fbb7dcc commit c38209b

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

lib/webpacker/compiler.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ def initialize(webpacker)
1919
def compile
2020
if stale?
2121
record_compilation_digest
22-
run_webpack
22+
run_webpack.tap do |success|
23+
remove_compilation_digest if !success
24+
end
2325
else
2426
true
2527
end
@@ -50,6 +52,10 @@ def record_compilation_digest
5052
compilation_digest_path.write(watched_files_digest)
5153
end
5254

55+
def remove_compilation_digest
56+
compilation_digest_path.delete if compilation_digest_path.exist?
57+
end
58+
5359
def run_webpack
5460
logger.info "Compiling…"
5561

test/compiler_test.rb

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
require "test_helper"
22

33
class CompilerTest < Minitest::Test
4-
def setup
4+
def remove_compilation_digest_path
55
Webpacker.compiler.send(:compilation_digest_path).tap do |path|
66
path.delete if path.exist?
77
end
88
end
99

10+
def setup
11+
remove_compilation_digest_path
12+
end
13+
14+
def teardown
15+
remove_compilation_digest_path
16+
end
17+
1018
def test_custom_environment_variables
1119
assert Webpacker.compiler.send(:webpack_env)["FOO"] == nil
1220
Webpacker.compiler.env["FOO"] = "BAR"
@@ -29,6 +37,27 @@ def test_freshness
2937
assert !Webpacker.compiler.fresh?
3038
end
3139

40+
def test_freshness_on_compile_success
41+
status = OpenStruct.new(success?: true)
42+
43+
assert Webpacker.compiler.stale?
44+
Open3.stub :capture3, [:sterr, :stdout, status] do
45+
Webpacker.compiler.compile
46+
assert Webpacker.compiler.fresh?
47+
end
48+
end
49+
50+
def test_staleness_on_compile_fail
51+
status = OpenStruct.new(success?: false)
52+
53+
assert Webpacker.compiler.stale?
54+
Open3.stub :capture3, [:sterr, :stdout, status] do
55+
56+
Webpacker.compiler.compile
57+
assert Webpacker.compiler.stale?
58+
end
59+
end
60+
3261
def test_compilation_digest_path
3362
assert Webpacker.compiler.send(:compilation_digest_path).to_s.ends_with?(Webpacker.env)
3463
end

0 commit comments

Comments
 (0)