From a6baeb5fc62357a16db1d581c7f5a4c8171be7e5 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Thu, 17 Oct 2024 10:58:16 -0400 Subject: [PATCH 1/3] test: verify the contents of tailwind.css in integration test --- test/integration/user_journey_test.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/integration/user_journey_test.sh b/test/integration/user_journey_test.sh index 00818f2d..a585017b 100755 --- a/test/integration/user_journey_test.sh +++ b/test/integration/user_journey_test.sh @@ -55,3 +55,9 @@ fi # TEST: presence of the generated file bin/rails generate scaffold post title:string body:text published:boolean grep -q "Show this post" app/views/posts/index.html.erb + +# TEST: contents of the css file +bin/rails tailwindcss:build[verbose] +grep -q "py-2" app/assets/builds/tailwind.css + +echo "OK" From 3a3a0eb4127128de171618057ad3b187e711bf15 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Thu, 17 Oct 2024 10:58:47 -0400 Subject: [PATCH 2/3] test: matrix tailwind 3.4 and 4.0 in integration test --- .github/workflows/ci.yml | 3 +++ .github/workflows/upstream.yml | 2 ++ test/integration/user_journey_test.sh | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 78413ae9..190294f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,7 +37,10 @@ jobs: fail-fast: false matrix: plat: ["ubuntu", "windows", "macos"] + tailwind: ["--version=~>3.4.14", "--version=~>4.0.0.alpha.27"] + env: runs-on: ${{matrix.plat}}-latest + TAILWINDCSSOPTS: ${{ matrix.tailwind }} steps: - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 diff --git a/.github/workflows/upstream.yml b/.github/workflows/upstream.yml index 0ba5507a..17e02892 100644 --- a/.github/workflows/upstream.yml +++ b/.github/workflows/upstream.yml @@ -42,8 +42,10 @@ jobs: matrix: plat: ["ubuntu"] ref: ["7-2-stable", "v8.0.0.beta1", "main"] + tailwind: ["--version=~>3.4.14", "--version=~>4.0.0.alpha.27"] env: RAILSOPTS: --git=https://github.com/rails/rails --ref=${{ matrix.ref }} + TAILWINDCSSOPTS: ${{ matrix.tailwind }} steps: - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 diff --git a/test/integration/user_journey_test.sh b/test/integration/user_journey_test.sh index a585017b..178d5a57 100755 --- a/test/integration/user_journey_test.sh +++ b/test/integration/user_journey_test.sh @@ -26,7 +26,8 @@ bundle remove rails --skip-install bundle add rails --skip-install ${RAILSOPTS:-} # use the tailwindcss-rails under test -bundle add tailwindcss-rails --path="../.." +bundle add tailwindcss-rails --skip-install --path="../.." +bundle add tailwindcss-ruby --skip-install ${TAILWINDCSSOPTS:-} bundle install bundle show --paths bundle binstubs --all From 6e828ebf094e43ffa01add8f5233316a397e94d8 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Thu, 17 Oct 2024 11:14:16 -0400 Subject: [PATCH 3/3] Add support for Tailwind CSS v4 which doesn't need a config file or an input file anymore. Closes #419 --- CHANGELOG.md | 5 +++++ lib/tailwindcss/commands.rb | 15 +++++++++++--- test/lib/tailwindcss/commands_test.rb | 28 ++++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26d72880..dc3b89b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## next / unreleased + +* Add experimental support for Tailwind CSS v4. (#420) @flavorjones + + ## v3.0.0 ### Notable changes diff --git a/lib/tailwindcss/commands.rb b/lib/tailwindcss/commands.rb index 26c5178a..c065b91a 100644 --- a/lib/tailwindcss/commands.rb +++ b/lib/tailwindcss/commands.rb @@ -3,14 +3,23 @@ module Tailwindcss module Commands class << self + def tailwindcss_version + Tailwindcss::Ruby::VERSION + end + def compile_command(debug: false, **kwargs) command = [ Tailwindcss::Ruby.executable(**kwargs), - "-i", Rails.root.join("app/assets/stylesheets/application.tailwind.css").to_s, - "-o", Rails.root.join("app/assets/builds/tailwind.css").to_s, - "-c", Rails.root.join("config/tailwind.config.js").to_s, + "-o", Rails.root.join("app/assets/builds/tailwind.css").to_s ] + unless tailwindcss_version >= "4.0" + command += [ + "-i", Rails.root.join("app/assets/stylesheets/application.tailwind.css").to_s, + "-c", Rails.root.join("config/tailwind.config.js").to_s, + ] + end + command << "--minify" unless (debug || rails_css_compressor?) postcss_path = Rails.root.join("config/postcss.config.js") diff --git a/test/lib/tailwindcss/commands_test.rb b/test/lib/tailwindcss/commands_test.rb index a273e45e..ef0e80ba 100644 --- a/test/lib/tailwindcss/commands_test.rb +++ b/test/lib/tailwindcss/commands_test.rb @@ -9,7 +9,33 @@ def setup @executable = Tailwindcss::Ruby.executable end - test ".compile_command" do + test ".compile_command with tailwindcss v3" do + Rails.stub(:root, File) do # Rails.root won't work in this test suite + Tailwindcss::Commands.stub(:tailwindcss_version, "3.4.13") do + actual = Tailwindcss::Commands.compile_command + assert_kind_of(Array, actual) + assert_equal(executable, actual.first) + assert_includes(actual, "-i") + assert_includes(actual, "-c") + assert_includes(actual, "-o") + end + end + end + + test ".compile_command with tailwindcss v4" do + Rails.stub(:root, File) do # Rails.root won't work in this test suite + Tailwindcss::Commands.stub(:tailwindcss_version, "4.0.0") do + actual = Tailwindcss::Commands.compile_command + assert_kind_of(Array, actual) + assert_equal(executable, actual.first) + refute_includes(actual, "-i") + refute_includes(actual, "-c") + assert_includes(actual, "-o") + end + end + end + + test ".compile_command debug flag" do Rails.stub(:root, File) do # Rails.root won't work in this test suite actual = Tailwindcss::Commands.compile_command assert_kind_of(Array, actual)