Skip to content

Commit b52cf0e

Browse files
authored
Merge pull request #423 from rails/flavorjones-unbreak-v4
Unbreak support for tailwind v4.
2 parents 0f282e2 + 1acd6c5 commit b52cf0e

File tree

4 files changed

+29
-35
lines changed

4 files changed

+29
-35
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## next / unreleased
22

3-
* Add experimental support for Tailwind CSS v4. (#420) @flavorjones
3+
* Add experimental support for Tailwind CSS v4. (#420, #423) @flavorjones
44

55

66
## v3.0.0

lib/tailwindcss/commands.rb

+3-12
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,14 @@
33
module Tailwindcss
44
module Commands
55
class << self
6-
def tailwindcss_version
7-
Tailwindcss::Ruby::VERSION
8-
end
9-
106
def compile_command(debug: false, **kwargs)
117
command = [
128
Tailwindcss::Ruby.executable(**kwargs),
13-
"-o", Rails.root.join("app/assets/builds/tailwind.css").to_s
9+
"-i", Rails.root.join("app/assets/stylesheets/application.tailwind.css").to_s,
10+
"-o", Rails.root.join("app/assets/builds/tailwind.css").to_s,
11+
"-c", Rails.root.join("config/tailwind.config.js").to_s,
1412
]
1513

16-
unless tailwindcss_version >= "4.0"
17-
command += [
18-
"-i", Rails.root.join("app/assets/stylesheets/application.tailwind.css").to_s,
19-
"-c", Rails.root.join("config/tailwind.config.js").to_s,
20-
]
21-
end
22-
2314
command << "--minify" unless (debug || rails_css_compressor?)
2415

2516
postcss_path = Rails.root.join("config/postcss.config.js")

test/integration/user_journey_test.sh

+18
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ bundle install
3232
bundle show --paths
3333
bundle binstubs --all
3434

35+
if bundle show | fgrep tailwindcss-ruby | fgrep -q "(4." ; then
36+
TAILWIND4=1
37+
else
38+
TAILWIND4=0
39+
fi
40+
3541
# install tailwindcss
3642
bin/rails tailwindcss:install
3743

@@ -45,6 +51,13 @@ task :still_here do
4551
end
4652
EOF
4753

54+
if [[ $TAILWIND4 = 1 ]] ; then
55+
cat > app/assets/stylesheets/application.tailwind.css <<EOF
56+
@import "tailwindcss";
57+
@theme { --color-special: #abc12399; }
58+
EOF
59+
fi
60+
4861
bin/rails tailwindcss:build still_here | grep "Rake process did not exit early"
4962

5063
if [[ $(rails -v) > "Rails 8.0.0.beta" ]] ; then
@@ -61,4 +74,9 @@ grep -q "Show this post" app/views/posts/index.html.erb
6174
bin/rails tailwindcss:build[verbose]
6275
grep -q "py-2" app/assets/builds/tailwind.css
6376

77+
if [[ $TAILWIND4 = 1 ]] ; then
78+
# TEST: contents include application.tailwind.css
79+
grep -q "#abc12399" app/assets/builds/tailwind.css
80+
fi
81+
6482
echo "OK"

test/lib/tailwindcss/commands_test.rb

+7-22
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,14 @@ def setup
99
@executable = Tailwindcss::Ruby.executable
1010
end
1111

12-
test ".compile_command with tailwindcss v3" do
12+
test ".compile_command" do
1313
Rails.stub(:root, File) do # Rails.root won't work in this test suite
14-
Tailwindcss::Commands.stub(:tailwindcss_version, "3.4.13") do
15-
actual = Tailwindcss::Commands.compile_command
16-
assert_kind_of(Array, actual)
17-
assert_equal(executable, actual.first)
18-
assert_includes(actual, "-i")
19-
assert_includes(actual, "-c")
20-
assert_includes(actual, "-o")
21-
end
22-
end
23-
end
24-
25-
test ".compile_command with tailwindcss v4" do
26-
Rails.stub(:root, File) do # Rails.root won't work in this test suite
27-
Tailwindcss::Commands.stub(:tailwindcss_version, "4.0.0") do
28-
actual = Tailwindcss::Commands.compile_command
29-
assert_kind_of(Array, actual)
30-
assert_equal(executable, actual.first)
31-
refute_includes(actual, "-i")
32-
refute_includes(actual, "-c")
33-
assert_includes(actual, "-o")
34-
end
14+
actual = Tailwindcss::Commands.compile_command
15+
assert_kind_of(Array, actual)
16+
assert_equal(executable, actual.first)
17+
assert_includes(actual, "-i")
18+
assert_includes(actual, "-c")
19+
assert_includes(actual, "-o")
3520
end
3621
end
3722

0 commit comments

Comments
 (0)