From a1b37572a13ba11ce914e682dc5a1b390043e378 Mon Sep 17 00:00:00 2001 From: Roberto Date: Fri, 21 Feb 2025 15:23:52 -0300 Subject: [PATCH 1/4] Add TAILWINDCSS_DEBUG environment variable --- lib/tailwindcss/commands.rb | 1 + test/lib/tailwindcss/commands_test.rb | 28 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/lib/tailwindcss/commands.rb b/lib/tailwindcss/commands.rb index fb90f4f6..558bf733 100644 --- a/lib/tailwindcss/commands.rb +++ b/lib/tailwindcss/commands.rb @@ -4,6 +4,7 @@ module Tailwindcss module Commands class << self def compile_command(debug: false, **kwargs) + debug ||= ["true", "1"].include?(ENV["TAILWINDCSS_DEBUG"]) rails_root = defined?(Rails) ? Rails.root : Pathname.new(Dir.pwd) command = [ diff --git a/test/lib/tailwindcss/commands_test.rb b/test/lib/tailwindcss/commands_test.rb index 3c7e5302..2bc094ec 100644 --- a/test/lib/tailwindcss/commands_test.rb +++ b/test/lib/tailwindcss/commands_test.rb @@ -33,6 +33,34 @@ def setup end end + test ".compile_command debug environment variable" do + begin + Rails.stub(:root, File) do # Rails.root won't work in this test suite + ENV["TAILWINDCSS_DEBUG"] = "0" + actual = Tailwindcss::Commands.compile_command + assert_kind_of(Array, actual) + assert_includes(actual, "--minify") + + ENV["TAILWINDCSS_DEBUG"] = "1" + actual = Tailwindcss::Commands.compile_command + assert_kind_of(Array, actual) + refute_includes(actual, "--minify") + + ENV["TAILWINDCSS_DEBUG"] = "false" + actual = Tailwindcss::Commands.compile_command + assert_kind_of(Array, actual) + assert_includes(actual, "--minify") + + ENV["TAILWINDCSS_DEBUG"] = "true" + actual = Tailwindcss::Commands.compile_command + assert_kind_of(Array, actual) + refute_includes(actual, "--minify") + end + ensure + ENV.delete('TAILWINDCSS_DEBUG') + end + end + test ".compile_command when Rails compression is on" do Rails.stub(:root, File) do # Rails.root won't work in this test suite Tailwindcss::Commands.stub(:rails_css_compressor?, true) do From d5fc0d3d40b321ec257549104b4fd425adee8681 Mon Sep 17 00:00:00 2001 From: Roberto Date: Fri, 21 Feb 2025 15:47:28 -0300 Subject: [PATCH 2/4] Update README --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 10c08036..381ed8e8 100644 --- a/README.md +++ b/README.md @@ -288,8 +288,10 @@ The `tailwindcss:build` task is automatically attached to the `test:prepare` Rak ### Building unminified assets -If you want unminified assets, you can pass a `debug` argument to the rake task, i.e. `rails tailwindcss:build[debug]` or `rails tailwindcss:watch[debug]`. +If you want unminified assets, you can: +- pass a `debug` argument to the rake task, i.e. `rails tailwindcss:build[debug]` or `rails tailwindcss:watch[debug]`. +- set an environment variable named `TAILWINDCSS_DEBUG` with a value of `true` or `1` ### Live rebuild From 628b12615d0bcae572b241d32a03a83e6641bda7 Mon Sep 17 00:00:00 2001 From: Roberto Date: Mon, 24 Feb 2025 11:19:35 -0300 Subject: [PATCH 3/4] ENV var should take precedence over command argument --- README.md | 4 +++- lib/tailwindcss/commands.rb | 2 +- test/lib/tailwindcss/commands_test.rb | 14 ++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 381ed8e8..545ce97a 100644 --- a/README.md +++ b/README.md @@ -291,7 +291,9 @@ The `tailwindcss:build` task is automatically attached to the `test:prepare` Rak If you want unminified assets, you can: - pass a `debug` argument to the rake task, i.e. `rails tailwindcss:build[debug]` or `rails tailwindcss:watch[debug]`. -- set an environment variable named `TAILWINDCSS_DEBUG` with a value of `true` or `1` +- set an environment variable named `TAILWINDCSS_DEBUG` with a non-blank value + +If both values are set, the environment variable will take precedence over the rake task argument. ### Live rebuild diff --git a/lib/tailwindcss/commands.rb b/lib/tailwindcss/commands.rb index 558bf733..6f125070 100644 --- a/lib/tailwindcss/commands.rb +++ b/lib/tailwindcss/commands.rb @@ -4,7 +4,7 @@ module Tailwindcss module Commands class << self def compile_command(debug: false, **kwargs) - debug ||= ["true", "1"].include?(ENV["TAILWINDCSS_DEBUG"]) + debug = ENV["TAILWINDCSS_DEBUG"].present? unless ENV["TAILWINDCSS_DEBUG"].nil? rails_root = defined?(Rails) ? Rails.root : Pathname.new(Dir.pwd) command = [ diff --git a/test/lib/tailwindcss/commands_test.rb b/test/lib/tailwindcss/commands_test.rb index 2bc094ec..d09481a4 100644 --- a/test/lib/tailwindcss/commands_test.rb +++ b/test/lib/tailwindcss/commands_test.rb @@ -36,23 +36,21 @@ def setup test ".compile_command debug environment variable" do begin Rails.stub(:root, File) do # Rails.root won't work in this test suite - ENV["TAILWINDCSS_DEBUG"] = "0" + ENV["TAILWINDCSS_DEBUG"] = "" actual = Tailwindcss::Commands.compile_command assert_kind_of(Array, actual) assert_includes(actual, "--minify") - ENV["TAILWINDCSS_DEBUG"] = "1" - actual = Tailwindcss::Commands.compile_command + actual = Tailwindcss::Commands.compile_command(debug: true) assert_kind_of(Array, actual) - refute_includes(actual, "--minify") + assert_includes(actual, "--minify") - ENV["TAILWINDCSS_DEBUG"] = "false" + ENV["TAILWINDCSS_DEBUG"] = "any non-blank value" actual = Tailwindcss::Commands.compile_command assert_kind_of(Array, actual) - assert_includes(actual, "--minify") + refute_includes(actual, "--minify") - ENV["TAILWINDCSS_DEBUG"] = "true" - actual = Tailwindcss::Commands.compile_command + actual = Tailwindcss::Commands.compile_command(debug: true) assert_kind_of(Array, actual) refute_includes(actual, "--minify") end From 8ad97524a61b651b622bd206420f57953e1153ae Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Tue, 25 Feb 2025 12:20:24 -0500 Subject: [PATCH 4/4] prefer Hash.key? to !Hash[].nil? --- README.md | 2 +- lib/tailwindcss/commands.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 545ce97a..f7afe7a8 100644 --- a/README.md +++ b/README.md @@ -293,7 +293,7 @@ If you want unminified assets, you can: - pass a `debug` argument to the rake task, i.e. `rails tailwindcss:build[debug]` or `rails tailwindcss:watch[debug]`. - set an environment variable named `TAILWINDCSS_DEBUG` with a non-blank value -If both values are set, the environment variable will take precedence over the rake task argument. +If both values are set, the environment variable will take precedence over the rake task argument. ### Live rebuild diff --git a/lib/tailwindcss/commands.rb b/lib/tailwindcss/commands.rb index 6f125070..bef42fd2 100644 --- a/lib/tailwindcss/commands.rb +++ b/lib/tailwindcss/commands.rb @@ -4,7 +4,7 @@ module Tailwindcss module Commands class << self def compile_command(debug: false, **kwargs) - debug = ENV["TAILWINDCSS_DEBUG"].present? unless ENV["TAILWINDCSS_DEBUG"].nil? + debug = ENV["TAILWINDCSS_DEBUG"].present? if ENV.key?("TAILWINDCSS_DEBUG") rails_root = defined?(Rails) ? Rails.root : Pathname.new(Dir.pwd) command = [