rails / cssbundling-rails

Bundle and process CSS in Rails with Tailwind, PostCSS, and Sass via Node.js.
MIT License
563 stars 83 forks source link

Generating a Rails 7.1.0.beta1 app with bootstrap throws an error #133

Closed joshrickard closed 9 months ago

joshrickard commented 9 months ago

Steps to reproduce

Generating a Rails app with 7.1.0.beta1 using bootstrap throws an error.

This seems to be related to Procfile.dev not existing when cssbundling-rails tries to update the file. Not entirely sure if this belongs here or in the cssbundling-rails repo.

rails --version
Rails 7.1.0.beta1

Minimal reproduction case:

rails new blog -c bootstrap

      create
      create  README.md
      create  Rakefile
      create  .node-version
      create  .ruby-version
      create  config.ru
      create  .gitignore
      create  .gitattributes
      create  Gemfile
         run  git init -b main from "."
Initialized empty Git repository in /Users/josh/dev/blog/.git/
      create  app
      create  app/assets/config/manifest.js
      create  app/assets/stylesheets/application.css
      create  app/channels/application_cable/channel.rb
      create  app/channels/application_cable/connection.rb
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/jobs/application_job.rb
      create  app/mailers/application_mailer.rb
      create  app/models/application_record.rb
      create  app/views/layouts/application.html.erb
      create  app/views/layouts/mailer.html.erb
      create  app/views/layouts/mailer.text.erb
      create  app/assets/images
      create  app/assets/images/.keep
      create  app/controllers/concerns/.keep
      create  app/models/concerns/.keep
      create  bin
      create  bin/rails
      create  bin/rake
      create  bin/setup
      create  Dockerfile
      create  .dockerignore
      create  bin/docker-entrypoint
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/cable.yml
      create  config/puma.rb
      create  config/storage.yml
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/assets.rb
      create  config/initializers/content_security_policy.rb
      create  config/initializers/cors.rb
      create  config/initializers/filter_parameter_logging.rb
      create  config/initializers/inflections.rb
      create  config/initializers/new_framework_defaults_7_1.rb
      create  config/initializers/permissions_policy.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/master.key
      append  .gitignore
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  lib
      create  lib/tasks
      create  lib/tasks/.keep
      create  lib/assets
      create  lib/assets/.keep
      create  log
      create  log/.keep
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/apple-touch-icon-precomposed.png
      create  public/apple-touch-icon.png
      create  public/favicon.ico
      create  public/robots.txt
      create  tmp
      create  tmp/.keep
      create  tmp/pids
      create  tmp/pids/.keep
      create  tmp/cache
      create  tmp/cache/assets
      create  vendor
      create  vendor/.keep
      create  test/fixtures/files
      create  test/fixtures/files/.keep
      create  test/controllers
      create  test/controllers/.keep
      create  test/mailers
      create  test/mailers/.keep
      create  test/models
      create  test/models/.keep
      create  test/helpers
      create  test/helpers/.keep
      create  test/integration
      create  test/integration/.keep
      create  test/channels/application_cable/connection_test.rb
      create  test/test_helper.rb
      create  test/system
      create  test/system/.keep
      create  test/application_system_test_case.rb
      create  storage
      create  storage/.keep
      create  tmp/storage
      create  tmp/storage/.keep
      remove  config/initializers/cors.rb
      remove  config/initializers/new_framework_defaults_7_1.rb
         run  bundle install
Fetching gem metadata from https://rubygems.org/...........
Resolving dependencies...
Bundle complete! 16 Gemfile dependencies, 84 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
         run  bundle lock --add-platform=x86_64-linux
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Writing lockfile to /Users/josh/dev/blog/Gemfile.lock
         run  bundle lock --add-platform=aarch64-linux
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Writing lockfile to /Users/josh/dev/blog/Gemfile.lock
         run  bundle binstubs bundler
       rails  importmap:install
       apply  /Users/josh/.rvm/gems/ruby-3.2.2/gems/importmap-rails-1.2.1/lib/install/install.rb
  Add Importmap include tags in application layout
      insert    app/views/layouts/application.html.erb
  Create application.js module as entrypoint
      create    app/javascript/application.js
  Use vendor/javascript for downloaded pins
      create    vendor/javascript
      create    vendor/javascript/.keep
  Ensure JavaScript files are in the Sprocket manifest
      append    app/assets/config/manifest.js
  Configure importmap paths in config/importmap.rb
      create    config/importmap.rb
  Copying binstub
      create    bin/importmap
         run  bundle install
Bundle complete! 16 Gemfile dependencies, 84 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
         run  bundle lock --add-platform=x86_64-linux
Writing lockfile to /Users/josh/dev/blog/Gemfile.lock
         run  bundle lock --add-platform=aarch64-linux
Writing lockfile to /Users/josh/dev/blog/Gemfile.lock
       rails  turbo:install stimulus:install
       apply  /Users/josh/.rvm/gems/ruby-3.2.2/gems/turbo-rails-1.4.0/lib/install/turbo_with_importmap.rb
  Import Turbo
      append    app/javascript/application.js
  Pin Turbo
      append    config/importmap.rb
         run  bundle install
Bundle complete! 16 Gemfile dependencies, 84 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
         run  bundle lock --add-platform=x86_64-linux
Writing lockfile to /Users/josh/dev/blog/Gemfile.lock
         run  bundle lock --add-platform=aarch64-linux
Writing lockfile to /Users/josh/dev/blog/Gemfile.lock
       apply  /Users/josh/.rvm/gems/ruby-3.2.2/gems/turbo-rails-1.4.0/lib/install/turbo_needs_redis.rb
  Enable redis in bundle
        gsub    Gemfile
         run    bundle install
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Bundle complete! 17 Gemfile dependencies, 86 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
         run    bundle lock --add-platform=x86_64-linux
Writing lockfile to /Users/josh/dev/blog/Gemfile.lock
         run    bundle lock --add-platform=aarch64-linux
Writing lockfile to /Users/josh/dev/blog/Gemfile.lock
  Switch development cable to use redis
        gsub    config/cable.yml
         run  bundle install
Bundle complete! 17 Gemfile dependencies, 86 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
         run  bundle lock --add-platform=x86_64-linux
Writing lockfile to /Users/josh/dev/blog/Gemfile.lock
         run  bundle lock --add-platform=aarch64-linux
Writing lockfile to /Users/josh/dev/blog/Gemfile.lock
       apply  /Users/josh/.rvm/gems/ruby-3.2.2/gems/stimulus-rails-1.2.2/lib/install/stimulus_with_importmap.rb
  Create controllers directory
      create    app/javascript/controllers
      create    app/javascript/controllers/index.js
      create    app/javascript/controllers/application.js
      create    app/javascript/controllers/hello_controller.js
  Import Stimulus controllers
      append    app/javascript/application.js
  Pin Stimulus
  Appending: pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true"
      append    config/importmap.rb
  Appending: pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
      append    config/importmap.rb
  Pin all controllers
  Appending: pin_all_from "app/javascript/controllers", under: "controllers"
      append    config/importmap.rb
         run  bundle install
Bundle complete! 17 Gemfile dependencies, 86 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
         run  bundle lock --add-platform=x86_64-linux
Writing lockfile to /Users/josh/dev/blog/Gemfile.lock
         run  bundle lock --add-platform=aarch64-linux
Writing lockfile to /Users/josh/dev/blog/Gemfile.lock
       rails  css:install:bootstrap
       apply  /Users/josh/.rvm/gems/ruby-3.2.2/gems/cssbundling-rails-1.3.1/lib/install/install.rb
  Build into app/assets/builds
      create    app/assets/builds
      create    app/assets/builds/.keep
      append    app/assets/config/manifest.js
  Stop linking stylesheets automatically
        gsub    app/assets/config/manifest.js
      append    .gitignore
      append    .gitignore
  Remove app/assets/stylesheets/application.css so build output can take over
      remove    app/assets/stylesheets/application.css
  Add stylesheet link tag in application layout
File unchanged! Either the supplied flag value not found or the content has already been inserted!    app/views/layouts/application.html.erb
  Add default package.json
      create    package.json
  Add default Procfile.dev
bin/rails aborted!
Rails::Generators::Error: The template [/Users/josh/.rvm/gems/ruby-3.2.2/gems/cssbundling-rails-1.3.1/lib/install/install.rb] could not be loaded. Error: Could not find "/Users/josh/.rvm/gems/ruby-3.2.2/gems/cssbundling-rails-1.3.1/lib/install/Procfile_for_node" in any of your source paths. Your current source paths are:
/Users/josh/.rvm/gems/ruby-3.2.2/gems/railties-7.1.0.beta1/lib/rails/generators/rails/app/templates

Caused by:
Thor::Error: Could not find "/Users/josh/.rvm/gems/ruby-3.2.2/gems/cssbundling-rails-1.3.1/lib/install/Procfile_for_node" in any of your source paths. Your current source paths are:
/Users/josh/.rvm/gems/ruby-3.2.2/gems/railties-7.1.0.beta1/lib/rails/generators/rails/app/templates

Tasks: TOP => app:template
(See full trace by running task with --trace)
       apply  /Users/josh/.rvm/gems/ruby-3.2.2/gems/cssbundling-rails-1.3.1/lib/install/bootstrap/install.rb
  Install Bootstrap with Bootstrap Icons, Popperjs/core and Autoprefixer
      create    app/assets/stylesheets/application.bootstrap.scss
         run    yarn add sass bootstrap bootstrap-icons @popperjs/core postcss postcss-cli autoprefixer nodemon from "."
yarn add v1.22.17
info No lockfile found.
[1/4] πŸ”  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] πŸ”—  Linking dependencies...
[4/4] πŸ”¨  Building fresh packages...
success Saved lockfile.
success Saved 94 new dependencies.
info Direct dependencies
β”œβ”€ @popperjs/core@2.11.8
β”œβ”€ autoprefixer@10.4.15
β”œβ”€ bootstrap-icons@1.11.0
β”œβ”€ bootstrap@5.3.1
β”œβ”€ nodemon@3.0.1
β”œβ”€ postcss-cli@10.1.0
β”œβ”€ postcss@8.4.29
└─ sass@1.66.1
info All dependencies
β”œβ”€ @nodelib/fs.scandir@2.1.5
β”œβ”€ @nodelib/fs.stat@2.0.5
β”œβ”€ @nodelib/fs.walk@1.2.8
β”œβ”€ @popperjs/core@2.11.8
β”œβ”€ abbrev@1.1.1
β”œβ”€ ansi-regex@5.0.1
β”œβ”€ ansi-styles@4.3.0
β”œβ”€ anymatch@3.1.3
β”œβ”€ autoprefixer@10.4.15
β”œβ”€ balanced-match@1.0.2
β”œβ”€ binary-extensions@2.2.0
β”œβ”€ bootstrap-icons@1.11.0
β”œβ”€ bootstrap@5.3.1
β”œβ”€ brace-expansion@1.1.11
β”œβ”€ braces@3.0.2
β”œβ”€ browserslist@4.21.10
β”œβ”€ caniuse-lite@1.0.30001534
β”œβ”€ chokidar@3.5.3
β”œβ”€ cliui@8.0.1
β”œβ”€ color-convert@2.0.1
β”œβ”€ color-name@1.1.4
β”œβ”€ concat-map@0.0.1
β”œβ”€ debug@3.2.7
β”œβ”€ dependency-graph@0.11.0
β”œβ”€ dir-glob@3.0.1
β”œβ”€ electron-to-chromium@1.4.520
β”œβ”€ emoji-regex@8.0.0
β”œβ”€ fast-glob@3.3.1
β”œβ”€ fastq@1.15.0
β”œβ”€ fill-range@7.0.1
β”œβ”€ fraction.js@4.3.6
β”œβ”€ fs-extra@11.1.1
β”œβ”€ fsevents@2.3.3
β”œβ”€ get-caller-file@2.0.5
β”œβ”€ get-stdin@9.0.0
β”œβ”€ glob-parent@5.1.2
β”œβ”€ globby@13.2.2
β”œβ”€ graceful-fs@4.2.11
β”œβ”€ has-flag@3.0.0
β”œβ”€ ignore-by-default@1.0.1
β”œβ”€ ignore@5.2.4
β”œβ”€ immutable@4.3.4
β”œβ”€ is-binary-path@2.1.0
β”œβ”€ is-extglob@2.1.1
β”œβ”€ is-fullwidth-code-point@3.0.0
β”œβ”€ is-glob@4.0.3
β”œβ”€ is-number@7.0.0
β”œβ”€ jsonfile@6.1.0
β”œβ”€ lilconfig@2.1.0
β”œβ”€ lru-cache@6.0.0
β”œβ”€ merge2@1.4.1
β”œβ”€ micromatch@4.0.5
β”œβ”€ minimatch@3.1.2
β”œβ”€ ms@2.1.3
β”œβ”€ nanoid@3.3.6
β”œβ”€ node-releases@2.0.13
β”œβ”€ nodemon@3.0.1
β”œβ”€ nopt@1.0.10
β”œβ”€ normalize-path@3.0.0
β”œβ”€ normalize-range@0.1.2
β”œβ”€ path-type@4.0.0
β”œβ”€ picomatch@2.3.1
β”œβ”€ pify@2.3.0
β”œβ”€ postcss-cli@10.1.0
β”œβ”€ postcss-load-config@4.0.1
β”œβ”€ postcss-reporter@7.0.5
β”œβ”€ postcss-value-parser@4.2.0
β”œβ”€ postcss@8.4.29
β”œβ”€ pretty-hrtime@1.0.3
β”œβ”€ pstree.remy@1.1.8
β”œβ”€ queue-microtask@1.2.3
β”œβ”€ read-cache@1.0.0
β”œβ”€ readdirp@3.6.0
β”œβ”€ require-directory@2.1.1
β”œβ”€ reusify@1.0.4
β”œβ”€ run-parallel@1.2.0
β”œβ”€ sass@1.66.1
β”œβ”€ simple-update-notifier@2.0.0
β”œβ”€ slash@5.1.0
β”œβ”€ source-map-js@1.0.2
β”œβ”€ string-width@4.2.3
β”œβ”€ strip-ansi@6.0.1
β”œβ”€ supports-color@5.5.0
β”œβ”€ thenby@1.3.4
β”œβ”€ to-regex-range@5.0.1
β”œβ”€ touch@3.1.0
β”œβ”€ undefsafe@2.0.5
β”œβ”€ update-browserslist-db@1.0.11
β”œβ”€ wrap-ansi@7.0.0
β”œβ”€ y18n@5.0.8
β”œβ”€ yallist@4.0.0
β”œβ”€ yaml@2.3.2
β”œβ”€ yargs-parser@21.1.1
└─ yargs@17.7.2
✨  Done in 3.06s.
      insert    config/initializers/assets.rb
  Appending Bootstrap JavaScript import to default entry point
      append    app/javascript/application.js
  Add build:css:compile script
         run    npm pkg set scripts.build:css:compile="sass ./app/assets/stylesheets/application.bootstrap.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules" from "."
         run    yarn build:css:compile from "."
yarn run v1.22.17
$ sass ./app/assets/stylesheets/application.bootstrap.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules
Deprecation Warning: Passing percentage units to the global abs() function is deprecated.
In the future, this will emit a CSS abs() function to be resolved by the browser.
To preserve current behavior: math.abs(100%)
To emit a CSS abs() now: abs(#{100%})
More info: https://sass-lang.com/d/abs-percent

   β•·
57 β”‚   $dividend: abs($dividend);
   β”‚              ^^^^^^^^^^^^^^
   β•΅
    node_modules/bootstrap/scss/vendor/_rfs.scss 57:14         divide()
    node_modules/bootstrap/scss/mixins/_grid.scss 59:12        row-cols()
    node_modules/bootstrap/scss/mixins/_grid.scss 85:13        @content
    node_modules/bootstrap/scss/mixins/_breakpoints.scss 68:5  media-breakpoint-up()
    node_modules/bootstrap/scss/mixins/_grid.scss 72:5         make-grid-columns()
    node_modules/bootstrap/scss/_grid.scss 38:3                @import
    bootstrap/scss/bootstrap.scss 20:9                         @import
    app/assets/stylesheets/application.bootstrap.scss 1:9      root stylesheet

✨  Done in 1.42s.
  Add build:css:prefix script
         run    npm pkg set scripts.build:css:prefix="postcss ./app/assets/builds/application.css --use=autoprefixer --output=./app/assets/builds/application.css" from "."
         run    yarn build:css:prefix from "."
yarn run v1.22.17
$ postcss ./app/assets/builds/application.css --use=autoprefixer --output=./app/assets/builds/application.css
✨  Done in 0.62s.
  Add build:css script
         run    npm pkg set scripts.build:css="yarn build:css:compile && yarn build:css:prefix" from "."
         run    yarn build:css from "."
yarn run v1.22.17
$ yarn build:css:compile && yarn build:css:prefix
$ sass ./app/assets/stylesheets/application.bootstrap.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules
Deprecation Warning: Passing percentage units to the global abs() function is deprecated.
In the future, this will emit a CSS abs() function to be resolved by the browser.
To preserve current behavior: math.abs(100%)
To emit a CSS abs() now: abs(#{100%})
More info: https://sass-lang.com/d/abs-percent

   β•·
57 β”‚   $dividend: abs($dividend);
   β”‚              ^^^^^^^^^^^^^^
   β•΅
    node_modules/bootstrap/scss/vendor/_rfs.scss 57:14         divide()
    node_modules/bootstrap/scss/mixins/_grid.scss 59:12        row-cols()
    node_modules/bootstrap/scss/mixins/_grid.scss 85:13        @content
    node_modules/bootstrap/scss/mixins/_breakpoints.scss 68:5  media-breakpoint-up()
    node_modules/bootstrap/scss/mixins/_grid.scss 72:5         make-grid-columns()
    node_modules/bootstrap/scss/_grid.scss 38:3                @import
    bootstrap/scss/bootstrap.scss 20:9                         @import
    app/assets/stylesheets/application.bootstrap.scss 1:9      root stylesheet

$ postcss ./app/assets/builds/application.css --use=autoprefixer --output=./app/assets/builds/application.css
✨  Done in 1.76s.
  Add watch:css script
         run    npm pkg set scripts.watch:css="nodemon --watch ./app/assets/stylesheets/ --ext scss --exec "yarn build:css"" from "."
npm ERR! code EUSAGE
npm ERR!
npm ERR! npm pkg set expects a key=value pair of args.
npm ERR!
npm ERR! Manages your package.json
npm ERR!
npm ERR! Usage:
npm ERR! npm pkg set <key>=<value> [<key>=<value> ...]
npm ERR! npm pkg get [<key> [<key> ...]]
npm ERR! npm pkg delete <key> [<key> ...]
npm ERR! npm pkg set [<array>[<index>].<key>=<value> ...]
npm ERR! npm pkg set [<array>[].<key>=<value> ...]
npm ERR! npm pkg fix
npm ERR!
npm ERR! Options:
npm ERR! [-f|--force] [--json]
npm ERR! [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
npm ERR! [-ws|--workspaces]
npm ERR!
npm ERR! Run "npm help pkg" for more info

npm ERR! A complete log of this run can be found in: /Users/josh/.npm/_logs/2023-09-13T21_31_54_674Z-debug-0.log
        gsub    Procfile.dev
bin/rails aborted!
Rails::Generators::Error: The template [/Users/josh/.rvm/gems/ruby-3.2.2/gems/cssbundling-rails-1.3.1/lib/install/bootstrap/install.rb] could not be loaded. Error: No such file or directory @ rb_sysopen - /Users/josh/dev/blog/Procfile.dev

Caused by:
Errno::ENOENT: No such file or directory @ rb_sysopen - /Users/josh/dev/blog/Procfile.dev

Tasks: TOP => app:template
(See full trace by running task with --trace)

Expected behavior

Rails app is successfully generated.

Actual behavior

An error is thrown.

System configuration

Rails version: 7.1.0.beta1 Ruby version: 3.2.2

rmacklin commented 9 months ago

Seems related to https://github.com/rails/cssbundling-rails/pull/130 - cc @terracatta

terracatta commented 9 months ago

Will take a look! Thanks for reporting