Skip to content

error messages on unsupported platforms or when bundler platforms aren't correct #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .github/workflows/gem-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
strategy:
fail-fast: false
matrix:
platform: ["x64-mingw32", "x86_64-darwin", "x86_64-linux"]
platform: ["ruby", "x64-mingw32", "x86_64-darwin", "x86_64-linux"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -21,6 +21,20 @@ jobs:
path: pkg
retention-days: 1

vanilla-install:
needs: ["package"]
runs-on: ubuntu-latest
steps:
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.0"
- uses: actions/download-artifact@v2
with:
name: gem-ruby
path: pkg
- run: "gem install pkg/tailwindcss-rails-*.gem"
- run: "tailwindcss 2>&1 | fgrep 'ERROR: Cannot find the tailwindcss executable'"

linux-install:
needs: ["package"]
runs-on: ubuntu-latest
Expand Down
36 changes: 28 additions & 8 deletions exe/tailwindcss
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,37 @@
# because rubygems shims assume a gem's executables are Ruby

require "shellwords"
require "tailwindcss/upstream"

platform_dir = Dir.glob(File.join(__dir__, "*")).select do |f|
File.directory?(f) && Gem::Platform.match(File.basename(f))
end.first
if platform_dir.nil?
raise "Cannot find the tailwindcss executable in #{__dir__} (1)"
supported_platforms = Tailwindcss::Upstream::NATIVE_PLATFORMS.keys

if supported_platforms.none? { |supported_platform| Gem::Platform.match(supported_platform) }
STDERR.puts(<<~ERRMSG)
ERROR: tailwindcss-rails does not support the #{::Gem::Platform.local} platform
Please install tailwindcss following instructions at https://tailwindcss.com/docs/installation
ERRMSG
exit 1
end

exe_path = Dir.glob(File.join(__dir__, "*", "tailwindcss")).find do |f|
Gem::Platform.match(File.basename(File.dirname(f)))
end
if exe_path.nil?
STDERR.puts(<<~ERRMSG)
ERROR: Cannot find the tailwindcss executable for #{::Gem::Platform.local} in #{__dir__}
If you're using bundler, please make sure you're on the latest bundler version:

gem install bundler
bundle update --bundler

Then make sure your lock file includes this platform by running:

bundle lock --add-platform #{::Gem::Platform.local}
bundle install

exe_path = File.join(platform_dir, "tailwindcss")
if !File.exist?(exe_path)
raise "Cannot find the tailwindcss executable in #{__dir__} (2)"
See `bundle lock --help` output for details.
ERRMSG
exit 1
end

command = Shellwords.join([exe_path, ARGV].flatten)
Expand Down
1 change: 1 addition & 0 deletions lib/tailwindcss-rails.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Tailwindcss
end

require "tailwindcss/upstream"
require "tailwindcss/version"
require "tailwindcss/engine"
14 changes: 14 additions & 0 deletions lib/tailwindcss/upstream.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Tailwindcss
# constants describing the upstream tailwindcss project
module Upstream
VERSION = "v3.0.5"

# rubygems platform name => upstream release filename
NATIVE_PLATFORMS = {
"arm64-darwin" => "tailwindcss-macos-arm64",
"x64-mingw32" => "tailwindcss-windows-x64.exe",
"x86_64-darwin" => "tailwindcss-macos-x64",
"x86_64-linux" => "tailwindcss-linux-x64",
}
end
end
20 changes: 5 additions & 15 deletions rakelib/package.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#
# TL;DR: run "rake package"
#
# The native platform gems (defined by TAILWINDCSS_NATIVE_PLATFORMS below) will each contain two
# files in addition to what the vanilla ruby gem contains:
# The native platform gems (defined by Tailwindcss::Upstream::NATIVE_PLATFORMS) will each contain
# two files in addition to what the vanilla ruby gem contains:
#
# exe/
# ├── tailwindcss # generic ruby script to find and run the binary
Expand Down Expand Up @@ -56,19 +56,10 @@
#
require "rubygems/package_task"
require "open-uri"

TAILWINDCSS_VERSION = "v3.0.5" # string used to generate the download URL

# rubygems platform name => upstream release filename
TAILWINDCSS_NATIVE_PLATFORMS = {
"arm64-darwin" => "tailwindcss-macos-arm64",
"x64-mingw32" => "tailwindcss-windows-x64.exe",
"x86_64-darwin" => "tailwindcss-macos-x64",
"x86_64-linux" => "tailwindcss-linux-x64",
}
require_relative "../lib/tailwindcss/upstream"

def tailwindcss_download_url(filename)
"https://github.com/tailwindlabs/tailwindcss/releases/download/#{TAILWINDCSS_VERSION}/#{filename}"
"https://github.com/tailwindlabs/tailwindcss/releases/download/#{Tailwindcss::Upstream::VERSION}/#{filename}"
end

TAILWINDCSS_RAILS_GEMSPEC = Bundler.load_gemspec("tailwindcss-rails.gemspec")
Expand All @@ -78,15 +69,14 @@ desc "Build the ruby gem"
task "gem:ruby" => [gem_path]

exepaths = []
TAILWINDCSS_NATIVE_PLATFORMS.each do |platform, filename|
Tailwindcss::Upstream::NATIVE_PLATFORMS.each do |platform, filename|
TAILWINDCSS_RAILS_GEMSPEC.dup.tap do |gemspec|
exedir = File.join(gemspec.bindir, platform) # "exe/x86_64-linux"
exepath = File.join(exedir, "tailwindcss") # "exe/x86_64-linux/tailwindcss"
exepaths << exepath

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

# create a package task
Expand Down
1 change: 1 addition & 0 deletions tailwindcss-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Gem::Specification.new do |spec|

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

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