Add gem extensions - #2711
Conversation
| # Extensions are loaded before the bundle is required so that they can patch the gems | ||
| # they apply to as those gems are being loaded. | ||
| ::Gem.find_files("tapioca/gem/extensions/*.rb").each do |extension| | ||
| require File.expand_path(extension) |
There was a problem hiding this comment.
I wonder if we should also allow project-local files to be loaded as extensions?
There was a problem hiding this comment.
Oh wait that's what prerequire is for right? I wonder if we should merge both concepts 🤔
There was a problem hiding this comment.
I agree that it ends up being the same concept, but with different names. I'm not sure how we should approach it though.
Simply removing prerequire and turning it into gem extensions would be a breaking change. We could also support both for some time or accept the distinct names for a bit until we're ready to make a breaking change.
WDYT?
There was a problem hiding this comment.
I think we should make the gem extensions behave the same way than DSL ones and allow both project local and gem provided extensions.
Once we have this we can start deprecating prerequire saying to switch to the new gem extension feature.
c98e587 to
4887b5a
Compare
|
|
||
| # Extensions are loaded before the bundle is required so that they can patch the gems | ||
| # they apply to as those gems are being loaded. | ||
| ::Gem.find_files("tapioca/gem/extensions/*.rb").each do |extension| |
There was a problem hiding this comment.
Should we skip extensions from excluded gems here? Right now an excluded gem can still run code during tapioca gem if it ships lib/tapioca/gem/extensions/*.rb, because we scan and require the extension before require_bundle has a chance to honor the exclude. That weakens --exclude as the side-effect escape hatch.
Maybe we can resolve the extension path back to its Gemfile::GemSpec and skip it when the owning gem is excluded.
| # Extensions are loaded before the bundle is required so that they can patch the gems | ||
| # they apply to as those gems are being loaded. | ||
| ::Gem.find_files("tapioca/gem/extensions/*.rb").each do |extension| | ||
| require File.expand_path(extension) |
There was a problem hiding this comment.
I think we should make the gem extensions behave the same way than DSL ones and allow both project local and gem provided extensions.
Once we have this we can start deprecating prerequire saying to switch to the new gem extension feature.
Motivation
Similar to DSL extensions, it is useful to be able to patch certain behaviour to ensure accurate gem RBI generation. Gems can expose extensions that get required ahead of time, ensuring that they patch with Tapioca compatibility in mind.
The README and test included provide an example we hit recently that can be easily fixed with an extension.
Implementation
Very similar to DSL extensions. We use
Gem.find_filesto detect gem extensions contributed by gems and load them ahead of time, before generation starts.Tests
Added a test.