Skip to content

Commit 61054a1

Browse files
authored
Merge pull request #239 from calebowens/fix-rakefile-loading-twice
Invoke app:template via Rake::Task[].invoke to avoid reloading rakefile
2 parents 2ecde30 + 6e4b036 commit 61054a1

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Diff for: lib/tasks/importmap_tasks.rake

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
namespace :importmap do
22
desc "Setup Importmap for the app"
33
task :install do
4-
system RbConfig.ruby, "./bin/rails", "app:template", "LOCATION=#{File.expand_path("../install/install.rb", __dir__)}"
4+
previous_location = ENV["LOCATION"]
5+
ENV["LOCATION"] = File.expand_path("../install/install.rb", __dir__)
6+
Rake::Task["app:template"].invoke
7+
ENV["LOCATION"] = previous_location
58
end
69
end

Diff for: test/installer_test.rb

+13-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ class InstallerTest < ActiveSupport::TestCase
3131
end
3232
end
3333

34+
test "doesn't load rakefile twice" do
35+
with_new_rails_app do |app_dir|
36+
rakefile = File.read("#{app_dir}/Rakefile")
37+
rakefile = "puts \"I've been logged twice!\" \n" + rakefile
38+
File.write("#{app_dir}/Rakefile", rakefile)
39+
40+
out, err = run_command("bin/rails", "importmap:install")
41+
42+
assert_equal 1, out.scan(/I've been logged twice!/).size
43+
end
44+
end
45+
3446
private
3547
def with_new_rails_app
3648
# Unset testing dummy app so app generator doesn't get confused in Rails 6.1 and 7.0.
@@ -54,7 +66,7 @@ def with_new_rails_app
5466

5567
run_command("bundle", "install")
5668

57-
yield
69+
yield(app_dir)
5870
end
5971
end
6072
end

0 commit comments

Comments
 (0)