Skip to content

Commit 7e47ec5

Browse files
committed
Cover export config binstub edge cases
1 parent ee16a71 commit 7e47ec5

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

lib/shakapacker/utils/misc.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Misc
1010
extend FileUtils
1111

1212
NODE_BINSTUB_EXECUTABLES = %w[node nodejs].freeze
13-
ENV_FLAGS_WITH_ARGUMENTS = %w[-u --unset -C --chdir].freeze
13+
ENV_FLAGS_WITH_ARGUMENTS = %w[-u --unset -C --chdir -P --path -a --argv0].freeze
1414
private_constant :NODE_BINSTUB_EXECUTABLES
1515
private_constant :ENV_FLAGS_WITH_ARGUMENTS
1616

@@ -60,6 +60,7 @@ def self.js_binstub_executable(path)
6060
executable = shebang_tokens.first.to_s
6161
end
6262

63+
# Preserve direct interpreter paths so stale absolute Node shebangs fail with actionable binstub guidance.
6364
NODE_BINSTUB_EXECUTABLES.include?(File.basename(executable)) ? executable : nil
6465
end
6566
end

spec/shakapacker/export_bundler_config_task_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ def capture_stderr
142142
end
143143
end
144144

145+
it "uses the gem version when bin/shakapacker-config is a directory" do
146+
Dir.mktmpdir("shakapacker-export-bundler-config-") do |app_path|
147+
FileUtils.mkdir_p(File.join(app_path, "bin", "shakapacker-config"))
148+
gem_bin_path = File.expand_path("../../lib/install/bin/shakapacker-config", __dir__)
149+
150+
expect(invoke_task(app_path)).to eq([RbConfig.ruby, gem_bin_path])
151+
end
152+
end
153+
145154
it "aborts when the Ruby binstub interpreter is missing" do
146155
Dir.mktmpdir("shakapacker-export-bundler-config-") do |app_path|
147156
write_app_binstub(app_path, <<~RUBY)

spec/shakapacker/utils_misc_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def with_binstub(contents)
3535
end
3636

3737
it "returns node for a node `env` shebang with env flags that take arguments" do
38-
with_binstub("#!/usr/bin/env -u NODE_PATH -C /tmp node\nconsole.log('legacy')\n") do |path|
38+
with_binstub("#!/usr/bin/env -u NODE_PATH -C /tmp -P /opt/node/bin -a node-shim node\nconsole.log('legacy')\n") do |path|
3939
expect(described_class.js_binstub_executable(path)).to eq "node"
4040
end
4141
end

0 commit comments

Comments
 (0)