Open
Conversation
Bundler override hooks into methods which are called by `Kernel#require` (or more precisely: all the magic build on top of it) sooner or later. To install the plugin "atomically", i.e. without any call to `require`, avoids to run into only half-installed code (see below for details). To require the friendly error earlier keeps it out of "install". Details: `dependency_patch.rb` already auto-installs itself into the modules `Bundler` and `Gem` (at the end of the source file). Which activates the code already for whatever `Bundler` and `Gem` already use these methods for. Unfortunately, the implementation of `DependencyPatch` accesses methods of `Bundler::Override` (e.g., `.override?`), but these methods are NOT (yet) defined. Alternatives: A) Don't require `bundler/friendly_errors`. This is not actually plugin's business. B) Don't (auto-)install too early. To define all code first, and only afterwards wire the modules into `Bundler` and `Gem`, keeps trouble away. C) Define all of `Bundler::Override` first, to have it there "if needed", and only afterwards run `require_relative` of `bundler/override/*`.*). I.e., move all `require_relative` down (see next commit, doesn't hurt). *) Where `Dsl` is likely not a troublemaker, because DSL methods are hopefully not involved into code loading via `require`. Piggy-backed: removes `.rb` from the argument of `require`.
See alternative C) of the parent commit. It is now impossible to have (own plugin) code code that calls from `Bundler::Override` "too early".
Instead, the code is wired into `Bundler` and `Gem` only after all code of `Bundler::Override` has been sourced.
Keeps "load all lib" more simple. Note: Actually, the two workhorses of the plugin are `DslPatch` and `DependencyPatch`. `Bundler::Override` itself is only a registry shared by both. To `require_relative "../override"` from each `bundler/override/*.rb` would express the actual dependency more precisely. But to require the shared code early and once is also good.
90248f0 to
a7634eb
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Looks like to eat own dogfood while producing it is a bit questionable. The following
Gemfilecreates a
NoMethodErrorforBundler::Override.override?(for abundle exec rspeccall):This PR moves the "responsible"
requireout of the way. Plus it restructures the code to separate "compile code" from "wire intoGemandBundler".Full backtrace
This
Gemfilecode already helps to load the plugin successfully (predefines the method accessed byrequire):