Skip to content

feat: allow overriding executable with environment variable #259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/tailwindcss/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ def executable(
MESSAGE
end

exe_path = Dir.glob(File.expand_path(File.join(exe_path, "*", "tailwindcss"))).find do |f|
Gem::Platform.match(Gem::Platform.new(File.basename(File.dirname(f))))
# Let the user override the executable path with an environment variable
# Useful for when running under Nix
exe_file = ENV["TAILWINDCSS_RAILS_EXECUTABLE_PATH"]

if exe_file.nil? || exe_file.empty?
exe_file = Dir.glob(File.expand_path(File.join(exe_path, "*", "tailwindcss"))).find do |f|
Gem::Platform.match(Gem::Platform.new(File.basename(File.dirname(f))))
end
end

if exe_path.nil?
if exe_file.nil? || exe_file.empty?
raise ExecutableNotFoundException, <<~MESSAGE
Cannot find the tailwindcss executable for #{platform} in #{exe_path}

Expand All @@ -52,7 +58,7 @@ def executable(
MESSAGE
end

exe_path
exe_file
end

def compile_command(debug: false, **kwargs)
Expand Down
7 changes: 7 additions & 0 deletions test/lib/tailwindcss/commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ def mock_exe_directory(platform)
end
end

test ".executable accepts an override through the TAILWINDCSS_RAILS_EXECUTABLE_PATH environment variable" do
filename = "/nix/store/li4jwsd16y68yjyznbffaf98jccipg36-tailwindcss-3.2.7/bin/tailwindcss"
ENV["TAILWINDCSS_RAILS_EXECUTABLE_PATH"] = filename
assert_equal(filename, Tailwindcss::Commands.executable)
ENV["TAILWINDCSS_RAILS_EXECUTABLE_PATH"] = ""
end

test ".executable raises UnsupportedPlatformException when we're not on a supported platform" do
Gem::Platform.stub(:match, false) do # nothing is supported
assert_raises(Tailwindcss::Commands::UnsupportedPlatformException) do
Expand Down