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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bundler] Don't use Bundler.default_*file to find gem file and lock file #27

Merged
merged 6 commits into from
Apr 6, 2018

Conversation

jonabc
Copy link
Contributor

@jonabc jonabc commented Apr 5, 2018

Fixes #23
Fixes #24

Fixing a couple issues where ::Bundler.default_*file does not behave ideally for usage in licensed

  1. They raise errors if a gem file can't be found
    • e.g. if the licensed gem is installed globally and not run from bundler, and a gem file isn't in the configured app source path
  2. They prefer ENV["BUNDLE_GEMFILE"] over searching for a gem file in the local file hierarchy
    • can lead to a mismatch if the name of the gem file in ENV["BUNDLE_GEMFILE"] doesn't match the name of the file in the configured app source path (gems.rb vs Gemfile)
  3. licensed has a very specific usage that looks for the gem file at the app source path and does not need any of the extra search logic in Bundler::SharedHelpers::find_gemfile

The downside is that now the source has to either keep track of the possible gem file names itself or call the private Bundler::SharedHelpers::gemfile_names. This PR opts to keep track of the file names locally so that licensed doesn't take a dependency on a private method that could change without notice.

Using these methods has undesirable effects
- raises an error if a file can't be found
- `ENV["BUNDLE_GEMFILE"]` overrides file search
- potential mismatch in gem file name
# block. we shouldn't need to restore these values manually
BUNDLER_ENV_KEYS.each { |k| ENV.delete(k) }
# force bundler to use the local gem file
ENV["BUNDLE_GEMFILE"] = gemfile_path.to_s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonabc Should this ENV var be unset in the ensure block below? Otherwise this method that takes a block leaks that environment variable?

Copy link
Contributor Author

@jonabc jonabc Apr 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbussink It's not necessary and won't leak because ::Bundler.with_original_env captures and restores the full ENV object itself.

👍 to restoring the ENV var in the ensure block to be more explicit and avoid confusion though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks! Yeah, explicitly doing it is nice I think.

@@ -1,13 +1,22 @@
# frozen_string_literal: true
require "test_helper"
require "tmpdir"
require "byebug"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You left byebug in here 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️ 🙇

make some implicit functionality explicit
@jonabc jonabc merged commit 72bf333 into master Apr 6, 2018
@jonabc jonabc deleted the bundler-default-gemfile-fixes branch April 6, 2018 15:48
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.

3 participants