Skip to content

Commit d73218c

Browse files
committed
fix: provide more helpful error messages
See rails#101 and comments in rails#96 for examples of what's confusing users.
1 parent 9108d53 commit d73218c

File tree

4 files changed

+44
-10
lines changed

4 files changed

+44
-10
lines changed

Diff for: .github/workflows/gem-install.yml

+15-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
strategy:
66
fail-fast: false
77
matrix:
8-
platform: ["x64-mingw32", "x86_64-darwin", "x86_64-linux"]
8+
platform: ["ruby", "x64-mingw32", "x86_64-darwin", "x86_64-linux"]
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@v2
@@ -21,6 +21,20 @@ jobs:
2121
path: pkg
2222
retention-days: 1
2323

24+
vanilla-install:
25+
needs: ["package"]
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: ruby/setup-ruby@v1
29+
with:
30+
ruby-version: "3.0"
31+
- uses: actions/download-artifact@v2
32+
with:
33+
name: gem-ruby
34+
path: pkg
35+
- run: "gem install pkg/tailwindcss-rails-*.gem"
36+
- run: "tailwindcss 2>&1 | fgrep 'ERROR: Cannot find the tailwindcss executable'"
37+
2438
linux-install:
2539
needs: ["package"]
2640
runs-on: ubuntu-latest

Diff for: exe/tailwindcss

+28-8
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,37 @@
22
# because rubygems shims assume a gem's executables are Ruby
33

44
require "shellwords"
5+
require "tailwindcss/upstream"
56

6-
platform_dir = Dir.glob(File.join(__dir__, "*")).select do |f|
7-
File.directory?(f) && Gem::Platform.match(File.basename(f))
8-
end.first
9-
if platform_dir.nil?
10-
raise "Cannot find the tailwindcss executable in #{__dir__} (1)"
7+
supported_platforms = Tailwindcss::Upstream::NATIVE_PLATFORMS.keys
8+
9+
if supported_platforms.none? { |supported_platform| Gem::Platform.match(supported_platform) }
10+
STDERR.puts(<<~ERRMSG)
11+
ERROR: tailwindcss-rails does not support the #{::Gem::Platform.local} platform
12+
Please install tailwindcss following instructions at https://tailwindcss.com/docs/installation
13+
ERRMSG
14+
exit 1
15+
end
16+
17+
exe_path = Dir.glob(File.join(__dir__, "*", "tailwindcss")).find do |f|
18+
Gem::Platform.match(File.basename(File.dirname(f)))
1119
end
20+
if exe_path.nil?
21+
STDERR.puts(<<~ERRMSG)
22+
ERROR: Cannot find the tailwindcss executable for #{::Gem::Platform.local} in #{__dir__}
23+
If you're using bundler, please make sure you're on the latest bundler version:
24+
25+
gem install bundler
26+
bundle update --bundler
27+
28+
Then make sure your lock file includes this platform by running:
29+
30+
bundle lock --add-platform #{::Gem::Platform.local}
31+
bundle install
1232
13-
exe_path = File.join(platform_dir, "tailwindcss")
14-
if !File.exist?(exe_path)
15-
raise "Cannot find the tailwindcss executable in #{__dir__} (2)"
33+
See `bundle lock --help` output for details.
34+
ERRMSG
35+
exit 1
1636
end
1737

1838
command = Shellwords.join([exe_path, ARGV].flatten)

Diff for: rakelib/package.rake

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ Tailwindcss::Upstream::NATIVE_PLATFORMS.each do |platform, filename|
7777

7878
# modify a copy of the gemspec to include the native executable
7979
gemspec.platform = platform
80-
gemspec.executables << "tailwindcss"
8180
gemspec.files += [exepath, "LICENSE-DEPENDENCIES"]
8281

8382
# create a package task

Diff for: tailwindcss-rails.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Gem::Specification.new do |spec|
1616

1717
spec.files = Dir["{app,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
1818
spec.bindir = "exe"
19+
spec.executables << "tailwindcss"
1920

2021
spec.add_dependency "railties", ">= 6.0.0"
2122
end

0 commit comments

Comments
 (0)