diff --git a/Gemfile b/Gemfile index 1487b97..38f79ad 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } # Specify your gem's dependencies in importmap-rails.gemspec. gemspec -rails_version = ENV["RAILS_VERSION"] || "6.1.0" +rails_version = ENV["RAILS_VERSION"] || "8.0.1" gem "rails", "~> #{rails_version}" gem "sqlite3" diff --git a/Gemfile.lock b/Gemfile.lock index 29b8821..7da5085 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,73 +1,88 @@ PATH remote: . specs: - cssbundling-rails (1.4.2) + cssbundling-rails (1.4.3) railties (>= 6.0.0) GEM remote: https://rubygems.org/ specs: - actioncable (6.1.7.8) - actionpack (= 6.1.7.8) - activesupport (= 6.1.7.8) + actioncable (8.0.1) + actionpack (= 8.0.1) + activesupport (= 8.0.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.1.7.8) - actionpack (= 6.1.7.8) - activejob (= 6.1.7.8) - activerecord (= 6.1.7.8) - activestorage (= 6.1.7.8) - activesupport (= 6.1.7.8) - mail (>= 2.7.1) - actionmailer (6.1.7.8) - actionpack (= 6.1.7.8) - actionview (= 6.1.7.8) - activejob (= 6.1.7.8) - activesupport (= 6.1.7.8) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (6.1.7.8) - actionview (= 6.1.7.8) - activesupport (= 6.1.7.8) - rack (~> 2.0, >= 2.0.9) + zeitwerk (~> 2.6) + actionmailbox (8.0.1) + actionpack (= 8.0.1) + activejob (= 8.0.1) + activerecord (= 8.0.1) + activestorage (= 8.0.1) + activesupport (= 8.0.1) + mail (>= 2.8.0) + actionmailer (8.0.1) + actionpack (= 8.0.1) + actionview (= 8.0.1) + activejob (= 8.0.1) + activesupport (= 8.0.1) + mail (>= 2.8.0) + rails-dom-testing (~> 2.2) + actionpack (8.0.1) + actionview (= 8.0.1) + activesupport (= 8.0.1) + nokogiri (>= 1.8.5) + rack (>= 2.2.4) + rack-session (>= 1.0.1) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.1.7.8) - actionpack (= 6.1.7.8) - activerecord (= 6.1.7.8) - activestorage (= 6.1.7.8) - activesupport (= 6.1.7.8) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + useragent (~> 0.16) + actiontext (8.0.1) + actionpack (= 8.0.1) + activerecord (= 8.0.1) + activestorage (= 8.0.1) + activesupport (= 8.0.1) + globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (6.1.7.8) - activesupport (= 6.1.7.8) + actionview (8.0.1) + activesupport (= 8.0.1) builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.1.7.8) - activesupport (= 6.1.7.8) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (8.0.1) + activesupport (= 8.0.1) globalid (>= 0.3.6) - activemodel (6.1.7.8) - activesupport (= 6.1.7.8) - activerecord (6.1.7.8) - activemodel (= 6.1.7.8) - activesupport (= 6.1.7.8) - activestorage (6.1.7.8) - actionpack (= 6.1.7.8) - activejob (= 6.1.7.8) - activerecord (= 6.1.7.8) - activesupport (= 6.1.7.8) + activemodel (8.0.1) + activesupport (= 8.0.1) + activerecord (8.0.1) + activemodel (= 8.0.1) + activesupport (= 8.0.1) + timeout (>= 0.4.0) + activestorage (8.0.1) + actionpack (= 8.0.1) + activejob (= 8.0.1) + activerecord (= 8.0.1) + activesupport (= 8.0.1) marcel (~> 1.0) - mini_mime (>= 1.1.0) - activesupport (6.1.7.8) - concurrent-ruby (~> 1.0, >= 1.0.2) + activesupport (8.0.1) + base64 + benchmark (>= 0.3) + bigdecimal + concurrent-ruby (~> 1.0, >= 1.3.1) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) + logger (>= 1.4.2) minitest (>= 5.1) - tzinfo (~> 2.0) - zeitwerk (~> 2.3) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + uri (>= 0.13.1) addressable (2.8.7) public_suffix (>= 2.0.2, < 7.0) + base64 (0.2.0) + benchmark (0.4.0) + bigdecimal (3.1.9) builder (3.3.0) byebug (11.1.3) capybara (3.40.0) @@ -79,15 +94,23 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - concurrent-ruby (1.3.3) + concurrent-ruby (1.3.5) + connection_pool (2.5.0) crass (1.0.6) - date (3.3.4) - erubi (1.13.0) + date (3.4.1) + drb (2.2.1) + erubi (1.13.1) globalid (1.2.1) activesupport (>= 6.1) - i18n (1.14.5) + i18n (1.14.7) concurrent-ruby (~> 1.0) - loofah (2.22.0) + io-console (0.8.0) + irb (1.15.1) + pp (>= 0.6.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + logger (1.6.6) + loofah (2.24.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) @@ -97,117 +120,140 @@ GEM net-smtp marcel (1.0.4) matrix (0.4.2) - method_source (1.1.0) mini_mime (1.1.5) - minitest (5.24.1) - net-imap (0.4.14) + minitest (5.25.4) + net-imap (0.5.6) date net-protocol net-pop (0.1.2) net-protocol net-protocol (0.2.2) timeout - net-smtp (0.5.0) + net-smtp (0.5.1) net-protocol - nio4r (2.7.3) - nokogiri (1.16.7-aarch64-linux) + nio4r (2.7.4) + nokogiri (1.18.3-aarch64-linux-gnu) + racc (~> 1.4) + nokogiri (1.18.3-aarch64-linux-musl) + racc (~> 1.4) + nokogiri (1.18.3-arm-linux-gnu) + racc (~> 1.4) + nokogiri (1.18.3-arm-linux-musl) + racc (~> 1.4) + nokogiri (1.18.3-arm64-darwin) racc (~> 1.4) - nokogiri (1.16.7-arm64-darwin) + nokogiri (1.18.3-x86_64-darwin) racc (~> 1.4) - nokogiri (1.16.7-x86_64-darwin) + nokogiri (1.18.3-x86_64-linux-gnu) racc (~> 1.4) - nokogiri (1.16.7-x86_64-linux) + nokogiri (1.18.3-x86_64-linux-musl) racc (~> 1.4) + pp (0.6.2) + prettyprint + prettyprint (0.2.0) + psych (5.2.3) + date + stringio public_suffix (6.0.1) - racc (1.8.0) - rack (2.2.9) - rack-test (2.1.0) + racc (1.8.1) + rack (3.1.10) + rack-session (2.1.0) + base64 (>= 0.1.0) + rack (>= 3.0.0) + rack-test (2.2.0) rack (>= 1.3) - rails (6.1.7.8) - actioncable (= 6.1.7.8) - actionmailbox (= 6.1.7.8) - actionmailer (= 6.1.7.8) - actionpack (= 6.1.7.8) - actiontext (= 6.1.7.8) - actionview (= 6.1.7.8) - activejob (= 6.1.7.8) - activemodel (= 6.1.7.8) - activerecord (= 6.1.7.8) - activestorage (= 6.1.7.8) - activesupport (= 6.1.7.8) + rackup (2.2.1) + rack (>= 3) + rails (8.0.1) + actioncable (= 8.0.1) + actionmailbox (= 8.0.1) + actionmailer (= 8.0.1) + actionpack (= 8.0.1) + actiontext (= 8.0.1) + actionview (= 8.0.1) + activejob (= 8.0.1) + activemodel (= 8.0.1) + activerecord (= 8.0.1) + activestorage (= 8.0.1) + activesupport (= 8.0.1) bundler (>= 1.15.0) - railties (= 6.1.7.8) - sprockets-rails (>= 2.0.0) + railties (= 8.0.1) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.6.0) + rails-html-sanitizer (1.6.2) loofah (~> 2.21) - nokogiri (~> 1.14) - railties (6.1.7.8) - actionpack (= 6.1.7.8) - activesupport (= 6.1.7.8) - method_source + nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) + railties (8.0.1) + actionpack (= 8.0.1) + activesupport (= 8.0.1) + irb (~> 1.13) + rackup (>= 1.0.0) rake (>= 12.2) - thor (~> 1.0) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) rake (13.2.1) - regexp_parser (2.9.2) - rexml (3.3.2) - strscan - rubyzip (2.3.2) + rdoc (6.12.0) + psych (>= 4.0.0) + regexp_parser (2.10.0) + reline (0.6.0) + io-console (~> 0.5) + rexml (3.4.1) + rubyzip (2.4.1) + securerandom (0.4.1) selenium-webdriver (4.10.0) rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) - sprockets (4.2.1) - concurrent-ruby (~> 1.0) - rack (>= 2.2.4, < 4) - sprockets-rails (3.5.1) - actionpack (>= 6.1) - activesupport (>= 6.1) - sprockets (>= 3.0.0) - sqlite3 (2.0.2-aarch64-linux-gnu) - sqlite3 (2.0.2-arm64-darwin) - sqlite3 (2.0.2-x86_64-darwin) - sqlite3 (2.0.2-x86_64-linux-gnu) - stimulus-rails (1.3.3) - railties (>= 6.0.0) - strscan (3.1.0) - thor (1.3.1) - timeout (0.4.1) - turbo-rails (2.0.6) - actionpack (>= 6.0.0) - activejob (>= 6.0.0) + sqlite3 (2.6.0-aarch64-linux-gnu) + sqlite3 (2.6.0-aarch64-linux-musl) + sqlite3 (2.6.0-arm-linux-gnu) + sqlite3 (2.6.0-arm-linux-musl) + sqlite3 (2.6.0-arm64-darwin) + sqlite3 (2.6.0-x86_64-darwin) + sqlite3 (2.6.0-x86_64-linux-gnu) + sqlite3 (2.6.0-x86_64-linux-musl) + stimulus-rails (1.3.4) railties (>= 6.0.0) + stringio (3.1.5) + thor (1.3.2) + timeout (0.4.3) + turbo-rails (2.0.13) + actionpack (>= 7.1.0) + railties (>= 7.1.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) + uri (1.0.3) + useragent (0.16.11) webdrivers (5.3.1) nokogiri (~> 1.6) rubyzip (>= 1.3.0) selenium-webdriver (~> 4.0, < 4.11) websocket (1.2.11) - websocket-driver (0.7.6) + websocket-driver (0.7.7) + base64 websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.16) + zeitwerk (2.7.2) PLATFORMS - aarch64-linux - arm64-darwin-20 - arm64-darwin-21 - arm64-darwin-22 - x86_64-darwin-20 - x86_64-darwin-21 - x86_64-linux + aarch64-linux-gnu + aarch64-linux-musl + arm-linux-gnu + arm-linux-musl + arm64-darwin + x86_64-darwin + x86_64-linux-gnu + x86_64-linux-musl DEPENDENCIES byebug capybara cssbundling-rails! - rails (~> 6.1.0) + rails (~> 8.0.1) rexml selenium-webdriver sqlite3 @@ -216,4 +262,4 @@ DEPENDENCIES webdrivers BUNDLED WITH - 2.2.33 + 2.6.2 diff --git a/README.md b/README.md index 5413d03..40d04be 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Some CSS packages use new CSS features that are not supported by the default Sas ### Why do I get `application.css not in asset pipeline` in production? -A common issue is that your repository does not contain the output directory used by the build commands. You must have `app/assets/builds` available. Add the directory with a `.gitkeep` file, and you'll ensure it's available in production. +A common issue is that your repository does not contain the output directory used by the build commands. You must have `app/assets/builds` available. Add the directory with a `.keep` file, and you'll ensure it's available in production. ### How do I avoid `ActionView::Template::Error: Error: Function rgb is missing argument $green`? diff --git a/lib/cssbundling/version.rb b/lib/cssbundling/version.rb index d46c887..7524952 100644 --- a/lib/cssbundling/version.rb +++ b/lib/cssbundling/version.rb @@ -1,3 +1,3 @@ module Cssbundling - VERSION = "1.4.2" + VERSION = "1.4.3" end diff --git a/lib/install/bootstrap/install.rb b/lib/install/bootstrap/install.rb index abf8e1d..f712775 100644 --- a/lib/install/bootstrap/install.rb +++ b/lib/install/bootstrap/install.rb @@ -23,15 +23,15 @@ if Rails.root.join("config/importmap.rb").exist? say "Pin Bootstrap" - append_to_file "config/importmap.rb", %(pin "bootstrap", to: "bootstrap.min.js"\n) + append_to_file "config/importmap.rb", %(pin "bootstrap", to: "bootstrap.bundle.min.js"\n) - inject_into_file "config/initializers/assets.rb", after: /.*Rails.application.config.assets.paths.*\n/ do + inject_into_file "config/initializers/assets.rb", after: /.*\/bootstrap-icons\/font.*\n/ do <<~RUBY Rails.application.config.assets.paths << Rails.root.join("node_modules/bootstrap/dist/js") RUBY end - append_to_file "config/initializers/assets.rb", %(Rails.application.config.assets.precompile << "bootstrap.min.js") + append_to_file "config/initializers/assets.rb", %(Rails.application.config.assets.precompile << "bootstrap.bundle.min.js") end add_package_json_script("build:css:compile", "sass ./app/assets/stylesheets/application.bootstrap.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules") diff --git a/lib/install/helpers.rb b/lib/install/helpers.rb index a2b9e6a..cf5b612 100644 --- a/lib/install/helpers.rb +++ b/lib/install/helpers.rb @@ -14,7 +14,9 @@ def bundler_x_cmd end def using_bun? - File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock')) + tool_exists?('bun') && (File.exist?('bun.lockb') || + File.exist?('bun.lock') || + File.exist?('yarn.lock')) end def tool_exists?(tool) diff --git a/lib/install/install.rb b/lib/install/install.rb index 0e9129f..4e195ce 100644 --- a/lib/install/install.rb +++ b/lib/install/install.rb @@ -20,21 +20,23 @@ say "Remove app/assets/stylesheets/application.css so build output can take over" remove_file "app/assets/stylesheets/application.css" -if (app_layout_path = Rails.root.join("app/views/layouts/application.html.erb")).exist? - say "Add stylesheet link tag in application layout" - insert_into_file( - app_layout_path.to_s, - defined?(Turbo) ? - %(\n <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>) : - %(\n <%= stylesheet_link_tag "application" %>), - before: /\s*<\/head>/ - ) -else - say "Default application.html.erb is missing!", :red - if defined?(Turbo) - say %( Add <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> within the tag in your custom layout.) +if Rails::VERSION::MAJOR < 8 + if (app_layout_path = Rails.root.join("app/views/layouts/application.html.erb")).exist? + say "Add stylesheet link tag in application layout" + insert_into_file( + app_layout_path.to_s, + defined?(Turbo) ? + %(\n <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>) : + %(\n <%= stylesheet_link_tag "application" %>), + before: /\s*<\/head>/ + ) else - say %( Add <%= stylesheet_link_tag "application" %> within the tag in your custom layout.) + say "Default application.html.erb is missing!", :red + if defined?(Turbo) + say %( Add <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> within the tag in your custom layout.) + else + say %( Add <%= stylesheet_link_tag "application" %> within the tag in your custom layout.) + end end end diff --git a/lib/tasks/cssbundling/build.rake b/lib/tasks/cssbundling/build.rake index 8410147..ddce5ab 100644 --- a/lib/tasks/cssbundling/build.rake +++ b/lib/tasks/cssbundling/build.rake @@ -1,5 +1,5 @@ namespace :css do - desc "Install JavaScript dependencies" + desc "Install CSS dependencies" task :install do command = Cssbundling::Tasks.install_command unless system(command) @@ -21,42 +21,42 @@ module Cssbundling module Tasks extend self + LOCK_FILES = { + bun: %w[bun.lockb bun.lock yarn.lock], + yarn: %w[yarn.lock], + pnpm: %w[pnpm-lock.yaml], + npm: %w[package-lock.json] + } + def install_command - case tool - when :bun then "bun install" - when :yarn then "yarn install" - when :pnpm then "pnpm install" - when :npm then "npm install" + case + when using_tool?(:bun) then "bun install" + when using_tool?(:yarn) then "yarn install" + when using_tool?(:pnpm) then "pnpm install" + when using_tool?(:npm) then "npm install" else raise "cssbundling-rails: No suitable tool found for installing JavaScript dependencies" end end def build_command - case tool - when :bun then "bun run build:css" - when :yarn then "yarn build:css" - when :pnpm then "pnpm build:css" - when :npm then "npm run build:css" + case + when using_tool?(:bun) then "bun run build:css" + when using_tool?(:yarn) then "yarn build:css" + when using_tool?(:pnpm) then "pnpm build:css" + when using_tool?(:npm) then "npm run build:css" else raise "cssbundling-rails: No suitable tool found for building CSS" end end - def tool - case - when File.exist?('bun.lockb') then :bun - when File.exist?('yarn.lock') then :yarn - when File.exist?('pnpm-lock.yaml') then :pnpm - when File.exist?('package-lock.json') then :npm - when tool_exists?('bun') then :bun - when tool_exists?('yarn') then :yarn - when tool_exists?('pnpm') then :pnpm - when tool_exists?('npm') then :npm - end - end + private def tool_exists?(tool) system "command -v #{tool} > /dev/null" end + + def using_tool?(tool) + tool_exists?(tool) && LOCK_FILES[tool].any? { |file| File.exist?(file) } + end end end