-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add option to configure zeitwerk in new gems #8198
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
Open
jorgemanrubia
wants to merge
1
commit into
ruby:master
Choose a base branch
from
jorgemanrubia:configure-zeitwerk
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,9 +1,25 @@ | ||||||
| # frozen_string_literal: true | ||||||
|
|
||||||
| <%- unless config[:zeitwerk] -%> | ||||||
| require_relative "<%= File.basename(config[:namespaced_path]) %>/version" | ||||||
| <%- end -%> | ||||||
| <%- if config[:ext] -%> | ||||||
jorgemanrubia marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| require_relative "<%= File.basename(config[:namespaced_path]) %>/<%= config[:underscored_name] %>" | ||||||
| <%- end -%> | ||||||
| <%- if config[:zeitwerk] -%> | ||||||
| require "zeitwerk" | ||||||
| <%- if config[:name].include?("-") -%> | ||||||
| loader = Zeitwerk::Loader.for_gem_extension(<%= config[:constant_array][0..-2].join("::") %>) | ||||||
| <%- else -%> | ||||||
| loader = Zeitwerk::Loader.for_gem | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I always wondered why the local var. Any drawbacks in doing
Suggested change
|
||||||
| <%- end -%> | ||||||
| loader.setup | ||||||
|
|
||||||
| # Client code may eager load the gem, make sure that works. | ||||||
| # If some files or directories should never be eager loaded, | ||||||
| # please configure eager load exceptions in the loader. | ||||||
| loader.eager_load if ENV.key?('CI') | ||||||
| <%- end -%> | ||||||
|
|
||||||
| <%- config[:constant_array].each_with_index do |c, i| -%> | ||||||
| <%= " " * i %>module <%= c %> | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we ask for this, which would set a
BUNDLE_GEM__ZEITWERKconfig setting that will be remembered acrossbundle gemcalls?Maybe
:zeitwerkis one of those options like:exethat could be left as one-off options. While one may want zeitwerk sometimes (or often), I don't know if it is a setting that should be remembered as if you are doing a very simple gem with 2-3 files, it's easy enough to require manually and one might want to forego zeitwerk to avoid a third-party dependency in their gem. But because they could have enabled zeitwerk before, zeitwerk would be enabled for their new small gem too. I guess in this case one could always provide--no-zeitwerk, so maybe this is fine as-is.Just thought I would comment in case anyone has opinions on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeromedalbert I went with the same approach it uses for the CoC or the MIT license, which results in question +
--zeitwerk/--no-zeitwerkoption + memorized answer in~/.bundle/config. I personally think it's fine and consistent but happy to change it if you want me to.