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
--skip generator options reduce included gems #24997
Conversation
Before this commit, every generated Rails app always included all the component gems of Rails (`activerecord`, `actionmailer`, etc.), whether or not those components were explicitly skipped (e.g.: with `--skip-active-record`). After this commit, using `--skip-active-record`, `--skip-action-mailer` or `--skip-action-cable` when generating a Rails app/plugin also has an effect on the Gemfile. Rather than having a single, "include-all" `gem rails` line, the Gemfile will have the specific Rails component listed and commented out if specified. For instance, `rails new app_name --skip-active-record` will generate a Gemfile that looks like this: > # gem 'rails', '>= 5.1.0.alpha', '< 5.2' > gem 'actioncable', '>= 5.1.0.alpha', '< 5.2' > gem 'actionmailer', '>= 5.1.0.alpha', '< 5.2' > gem 'activejob', '>= 5.1.0.alpha', '< 5.2' > gem 'activemodel', '>= 5.1.0.alpha', '< 5.2' > # gem 'activerecord', '>= 5.1.0.alpha', '< 5.2' > gem 'railties', '>= 5.1.0.alpha', '< 5.2' As a result, the `activerecord` gem and its dependencies won't be bundled.
This works for me. If you're calling skip yourself, you're already off the beaten path. Compass and backpack required! |
Thanks! Then I'll work on improving the code itself. When talking with @matthewd about this at RailsConf, we were wondering whether this change would need a deprecation policy. It's a little "meta" because we are changing the generator, but theoretically anyone using So in case gems depend on the Rails generator for other behavior, this would be a breaking change. Another option is to add separate options, for instance |
On a separate note (and eventually in a separate PR), would you be okay if I changed the API interface of the class GemfileEntry < Struct.new(:name, :version, :comment, :options, :commented_out) and its methods accept parameters like: def self.github(name, github, branch = nil, comment = nil) and the resulting code is verbose and full of duplication (see my code change in this PR). Maybe we could start using optional parameters, and the entire class would be more readable. Let me know… it's a separate conversation and it's another possible breaking change, so I would understand if we want to keep it as it is. |
No deprecation needed since it only affects new applications. On Thu, May 12, 2016 at 6:28 PM, Claudio B. notifications@github.com
|
My concern wasn't about deprecation, but the fact that |
@matthewd oops, sorry, I forgot! 😅 You are right,
If you generate your own app skipping some gems, it will be your responsibility to |
I think if you're off in custom land, then that's the choice you make. On Thu, May 12, 2016 at 6:45 PM, Matthew Draper notifications@github.com
|
@claudiob Will |
@prathamesh-sonpatki I ran In short, if you create a Rails app with require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
# require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"
require "rails/test_unit/railtie" but then, if you run require 'rails/all' In short, it looks like |
I'm 👍 for having Side note: I remember @sgrif talking (on 🚲 🏠) about having optional dependencies with Rubygems be a thing -- that would be super helpful here 😞 |
I feel like this is the wrong place to make the change, essentially rubygems and bundler need the change first. In particular, gemspec should allow for optional opt-in and optional opt-out dependencies, these issues are pretty huge in our ecosystem. For example, active_record has optional opt-in dependencies on particular versions of the Similarly the rails meta gem has optional opt-out dependencies on various bits that make up rails. I feel that within the current constraints this change does not really help much... what I want is this in my gemfile.
That way, cc @indirect |
@SamSaffron That would be great! I agree with everything you said 😁 |
+1 for closing this. The benefits (reducing gem install count by ~10%) don't outweigh the costs of making maintaining a modular Rails application more difficult (breaking I have a number of modular Rails apps inside of test suites (for testing how a gem works with Rails, etc), and I always use |
(Note: this PR stems from a Basecamp chat where @rafaelfranca said "yes, I'd love to --skip-* change the gemfile instead of not loading the railtie", @SamSaffron expressed some concerns and @matthewd suggested a possible implementation. This PR needs a CHANGELOG and a deprecation policy… but I'd like to know if the team agrees with the concept behind this PR before going any further)
Before this commit, every generated Rails app always included all the component gems of Rails (
activerecord
,actionmailer
, etc.), whether or not those components were explicitly skipped (e.g.: with--skip-active-record
).After this commit, using
--skip-active-record
,--skip-action-mailer
or--skip-action-cable
when generating a Rails app/plugin also affects the Gemfile.Rather than having a single, "include-all"
gem rails
line, the Gemfile will have the specific Rails component listed and commented out if specified.For instance,
rails new app_name --skip-active-record
will generate a Gemfile that looks like this:As a result, the
activerecord
gem and its dependencies won't be bundled.As of 6007e58, the number of gems bundled by
rails new
is 61.The benefit of this commit is that the number of bundled gems is reduced to:
--skip-active-record
(arel
andsqlite3
are not installed)--skip-action-cable
(nio4r
,websocket-driver
andwebsocket-extensions
are not installed)--skip-action-mailer
(mail
,mime-types
andmime-types-data
are not installed)This PR honors the spirit of Rails as a "modular framework" that allows users to cherry-pick the components that are required for each application. Removing unnecessary gems keeps the size of the application small and reduces the number of possible third-party issues.