From 9108d5385482183cef175de21afe360242e8da39 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Sun, 19 Dec 2021 14:26:13 -0500 Subject: [PATCH 1/2] prefactor: expose constants related to upstream tailwindcss MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The following constants have been moved from rakelib/package.rake into lib/tailwindcss/upstream.rb to be accessible from within the installed gem: - TAILWINDCSS_VERSION → Tailwindcss::Upstream::VERSION - TAILWINDCSS_NATIVE_PLATFORMS -> Tailwindcss::Upstream::NATIVE_PLATFORMS --- lib/tailwindcss-rails.rb | 1 + lib/tailwindcss/upstream.rb | 14 ++++++++++++++ rakelib/package.rake | 19 +++++-------------- 3 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 lib/tailwindcss/upstream.rb diff --git a/lib/tailwindcss-rails.rb b/lib/tailwindcss-rails.rb index 4a1b4570..198aac3d 100644 --- a/lib/tailwindcss-rails.rb +++ b/lib/tailwindcss-rails.rb @@ -1,5 +1,6 @@ module Tailwindcss end +require "tailwindcss/upstream" require "tailwindcss/version" require "tailwindcss/engine" diff --git a/lib/tailwindcss/upstream.rb b/lib/tailwindcss/upstream.rb new file mode 100644 index 00000000..31999dfb --- /dev/null +++ b/lib/tailwindcss/upstream.rb @@ -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 diff --git a/rakelib/package.rake b/rakelib/package.rake index 1254053f..fdb43339 100644 --- a/rakelib/package.rake +++ b/rakelib/package.rake @@ -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 @@ -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") @@ -78,7 +69,7 @@ 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" From d73218c51f065ea6a09f836e1671c9bf983d4dab Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Sun, 19 Dec 2021 14:56:52 -0500 Subject: [PATCH 2/2] fix: provide more helpful error messages See #101 and comments in #96 for examples of what's confusing users. --- .github/workflows/gem-install.yml | 16 +++++++++++++- exe/tailwindcss | 36 ++++++++++++++++++++++++------- rakelib/package.rake | 1 - tailwindcss-rails.gemspec | 1 + 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/.github/workflows/gem-install.yml b/.github/workflows/gem-install.yml index 0ffd5a0b..a4a2f500 100644 --- a/.github/workflows/gem-install.yml +++ b/.github/workflows/gem-install.yml @@ -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 @@ -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 diff --git a/exe/tailwindcss b/exe/tailwindcss index 6e0fcf69..f7495e4b 100755 --- a/exe/tailwindcss +++ b/exe/tailwindcss @@ -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) diff --git a/rakelib/package.rake b/rakelib/package.rake index fdb43339..3ab66623 100644 --- a/rakelib/package.rake +++ b/rakelib/package.rake @@ -77,7 +77,6 @@ Tailwindcss::Upstream::NATIVE_PLATFORMS.each do |platform, filename| # 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 diff --git a/tailwindcss-rails.gemspec b/tailwindcss-rails.gemspec index 55858d7c..672c9885 100644 --- a/tailwindcss-rails.gemspec +++ b/tailwindcss-rails.gemspec @@ -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