Skip to content

Commit 628b126

Browse files
r-sierraflavorjones
authored andcommitted
ENV var should take precedence over command argument
1 parent d5fc0d3 commit 628b126

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@ The `tailwindcss:build` task is automatically attached to the `test:prepare` Rak
291291
If you want unminified assets, you can:
292292
293293
- pass a `debug` argument to the rake task, i.e. `rails tailwindcss:build[debug]` or `rails tailwindcss:watch[debug]`.
294-
- set an environment variable named `TAILWINDCSS_DEBUG` with a value of `true` or `1`
294+
- set an environment variable named `TAILWINDCSS_DEBUG` with a non-blank value
295+
296+
If both values are set, the environment variable will take precedence over the rake task argument.
295297
296298
### Live rebuild
297299

lib/tailwindcss/commands.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Tailwindcss
44
module Commands
55
class << self
66
def compile_command(debug: false, **kwargs)
7-
debug ||= ["true", "1"].include?(ENV["TAILWINDCSS_DEBUG"])
7+
debug = ENV["TAILWINDCSS_DEBUG"].present? unless ENV["TAILWINDCSS_DEBUG"].nil?
88
rails_root = defined?(Rails) ? Rails.root : Pathname.new(Dir.pwd)
99

1010
command = [

test/lib/tailwindcss/commands_test.rb

+6-8
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,21 @@ def setup
3636
test ".compile_command debug environment variable" do
3737
begin
3838
Rails.stub(:root, File) do # Rails.root won't work in this test suite
39-
ENV["TAILWINDCSS_DEBUG"] = "0"
39+
ENV["TAILWINDCSS_DEBUG"] = ""
4040
actual = Tailwindcss::Commands.compile_command
4141
assert_kind_of(Array, actual)
4242
assert_includes(actual, "--minify")
4343

44-
ENV["TAILWINDCSS_DEBUG"] = "1"
45-
actual = Tailwindcss::Commands.compile_command
44+
actual = Tailwindcss::Commands.compile_command(debug: true)
4645
assert_kind_of(Array, actual)
47-
refute_includes(actual, "--minify")
46+
assert_includes(actual, "--minify")
4847

49-
ENV["TAILWINDCSS_DEBUG"] = "false"
48+
ENV["TAILWINDCSS_DEBUG"] = "any non-blank value"
5049
actual = Tailwindcss::Commands.compile_command
5150
assert_kind_of(Array, actual)
52-
assert_includes(actual, "--minify")
51+
refute_includes(actual, "--minify")
5352

54-
ENV["TAILWINDCSS_DEBUG"] = "true"
55-
actual = Tailwindcss::Commands.compile_command
53+
actual = Tailwindcss::Commands.compile_command(debug: true)
5654
assert_kind_of(Array, actual)
5755
refute_includes(actual, "--minify")
5856
end

0 commit comments

Comments
 (0)