Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't mutate bundler dependencies in place #433

Merged

Conversation

deivid-rodriguez
Copy link
Contributor

This is a 馃悰 bug fix, although a workaround is already in place (#430) and in my opinion it should not be reverted because it's a more bullet proof approach. So this fix is not very important, but given the amount of bundler internals Bridgetown seems to use, it might save you & us from future trouble!

Summary

It was reported to us a question about why your previous check of whether puma was present in the bundle (through Bundler.definition.specs) wouldn't work while the new one (through directly requiring it and rescuing LoadError) would work.

I investigated the root cause thanks to a helpful reproduction provided in the issue, and I found the culprit in bridgetown's plugin manager mutating the array of bundler dependencies and causing this issue as a side effect.

Plugin manager uses Bundler.require, which returns the set of dependencies bundler definition is considering for the current invocation. And those dependencies were being filtered and the ones outside of plugins' groups removed (puma is usually one of these). Bundler.definition.specs materializes the current dependencies into a set of requirable specifications. However, since some dependencies had been wiped out by the plugin manager, the corresponding specs would no longer be materialized and would be missing.

This commit fixes the problem by not mutating bundler dependencies in-place.

Context

My guess is that this might've worked in the past, but some changes in bundler made the issue surface. At some point requiring bundler/setup probably memoized the set of materialized specs, so the call to Bundler.definition.specs wouldn't be affected by any change in the underlying dependencies. I added a change in bundler to make sure the set of specs initially materialized by requiring bundler/setup is memoized, so that this kind of issue cannot reaper in other ways.

`Bundler.require` returns the set of dependencies bundler definition is
considering for the current invocation. And those dependencies were
being filtered and the ones outside of plugins' groups removed (`puma`
is usually one of these).

`Bundler.definition.specs` materializes the current dependencies into a
set of requirable specifications. However, since some dependencies had
been wiped out after the plugin manager had done its thing, the
corresponding specs would no longer be materialized and would be
missing.

This commit fixes the problem by not mutating bundler dependencies
in-place.
@jaredcwhite
Copy link
Member

Thanks @deivid-rodriguez, your explanation makes sense and is much appreciated!. And I agree keeping that other fix in place is a good call.

@jaredcwhite jaredcwhite merged commit 0b0b75f into bridgetownrb:main Oct 29, 2021
@deivid-rodriguez
Copy link
Contributor Author

Thank you, and keep up the good work, bridgetown seems very cool!

@deivid-rodriguez deivid-rodriguez deleted the dont_wipe_out_bundler_deps branch October 29, 2021 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants