Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Merge #7193
Browse files Browse the repository at this point in the history
7193: More `require_relative` r=deivid-rodriguez a=deivid-rodriguez

This is a follow up to #7062 and #7100, migrating the last missing internal requires to use `require_relative`. I thought I had migrated everything already, but I had not.

As a note, I'm migrating thor's code here. I will open a PR to upstream's thor to incorporate this changes, but thor is still stuck with 1.8 support, so we have to wait a bit. Given the very low activity thor has, it's fine to make the changes here first, and wait until we can incorporate them upstream.
 
### What was the end-user problem that led to this PR?

The problem was that sometimes we can end up requiring the default version of bundler, instead of the current copy that's being run, and that's dangerous and can cause version mismatch issues.

### What is your fix for the problem, implemented in this PR?

My fix is to always use `require_relative` for internal requires.

Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
  • Loading branch information
bundlerbot and deivid-rodriguez committed Jun 10, 2019
2 parents ac832fe + d9d2bf6 commit aa2a882
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 39 deletions.
6 changes: 3 additions & 3 deletions exe/bundle
Expand Up @@ -7,7 +7,7 @@ Signal.trap("INT") do
exit 1
end

require "bundler"
require_relative "../lib/bundler"
# Check if an older version of bundler is installed
$LOAD_PATH.each do |path|
next unless path =~ %r{/bundler-0\.(\d+)} && $1.to_i < 9
Expand All @@ -18,9 +18,9 @@ $LOAD_PATH.each do |path|
abort(err)
end

require "bundler/friendly_errors"
require_relative "../lib/bundler/friendly_errors"
Bundler.with_friendly_errors do
require "bundler/cli"
require_relative "../lib/bundler/cli"

# Allow any command to use --help flag to show help for that command
help_flags = %w[--help -h]
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler.rb
Expand Up @@ -564,7 +564,7 @@ def reset_rubygems!
private

def eval_yaml_gemspec(path, contents)
Kernel.send(:require, "bundler/psyched_yaml")
require_relative "bundler/psyched_yaml"

# If the YAML is invalid, Syck raises an ArgumentError, and Psych
# raises a Psych::SyntaxError. See psyched_yaml.rb for more info.
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/vendor/thor/lib/thor.rb
@@ -1,5 +1,5 @@
require "set"
require "bundler/vendor/thor/lib/thor/base"
require_relative "thor/base"

class Bundler::Thor
class << self
Expand Down
14 changes: 7 additions & 7 deletions lib/bundler/vendor/thor/lib/thor/actions.rb
@@ -1,11 +1,11 @@
require "uri"
require "bundler/vendor/thor/lib/thor/core_ext/io_binary_read"
require "bundler/vendor/thor/lib/thor/actions/create_file"
require "bundler/vendor/thor/lib/thor/actions/create_link"
require "bundler/vendor/thor/lib/thor/actions/directory"
require "bundler/vendor/thor/lib/thor/actions/empty_directory"
require "bundler/vendor/thor/lib/thor/actions/file_manipulation"
require "bundler/vendor/thor/lib/thor/actions/inject_into_file"
require_relative "core_ext/io_binary_read"
require_relative "actions/create_file"
require_relative "actions/create_link"
require_relative "actions/directory"
require_relative "actions/empty_directory"
require_relative "actions/file_manipulation"
require_relative "actions/inject_into_file"

class Bundler::Thor
module Actions
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/vendor/thor/lib/thor/actions/create_file.rb
@@ -1,4 +1,4 @@
require "bundler/vendor/thor/lib/thor/actions/empty_directory"
require_relative "empty_directory"

class Bundler::Thor
module Actions
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
@@ -1,4 +1,4 @@
require "bundler/vendor/thor/lib/thor/actions/create_file"
require_relative "create_file"

class Bundler::Thor
module Actions
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/vendor/thor/lib/thor/actions/directory.rb
@@ -1,4 +1,4 @@
require "bundler/vendor/thor/lib/thor/actions/empty_directory"
require_relative "empty_directory"

class Bundler::Thor
module Actions
Expand Down
@@ -1,4 +1,4 @@
require "bundler/vendor/thor/lib/thor/actions/empty_directory"
require_relative "empty_directory"

class Bundler::Thor
module Actions
Expand Down
18 changes: 9 additions & 9 deletions lib/bundler/vendor/thor/lib/thor/base.rb
@@ -1,12 +1,12 @@
require "bundler/vendor/thor/lib/thor/command"
require "bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access"
require "bundler/vendor/thor/lib/thor/core_ext/ordered_hash"
require "bundler/vendor/thor/lib/thor/error"
require "bundler/vendor/thor/lib/thor/invocation"
require "bundler/vendor/thor/lib/thor/parser"
require "bundler/vendor/thor/lib/thor/shell"
require "bundler/vendor/thor/lib/thor/line_editor"
require "bundler/vendor/thor/lib/thor/util"
require_relative "command"
require_relative "core_ext/hash_with_indifferent_access"
require_relative "core_ext/ordered_hash"
require_relative "error"
require_relative "invocation"
require_relative "parser"
require_relative "shell"
require_relative "line_editor"
require_relative "util"

class Bundler::Thor
autoload :Actions, File.expand_path("actions", __dir__)
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/vendor/thor/lib/thor/group.rb
@@ -1,4 +1,4 @@
require "bundler/vendor/thor/lib/thor/base"
require_relative "base"

# Bundler::Thor has a special class called Bundler::Thor::Group. The main difference to Bundler::Thor class
# is that it invokes all commands at once. It also include some methods that allows
Expand Down
4 changes: 2 additions & 2 deletions lib/bundler/vendor/thor/lib/thor/line_editor.rb
@@ -1,5 +1,5 @@
require "bundler/vendor/thor/lib/thor/line_editor/basic"
require "bundler/vendor/thor/lib/thor/line_editor/readline"
require_relative "line_editor/basic"
require_relative "line_editor/readline"

class Bundler::Thor
module LineEditor
Expand Down
8 changes: 4 additions & 4 deletions lib/bundler/vendor/thor/lib/thor/parser.rb
@@ -1,4 +1,4 @@
require "bundler/vendor/thor/lib/thor/parser/argument"
require "bundler/vendor/thor/lib/thor/parser/arguments"
require "bundler/vendor/thor/lib/thor/parser/option"
require "bundler/vendor/thor/lib/thor/parser/options"
require_relative "parser/argument"
require_relative "parser/arguments"
require_relative "parser/option"
require_relative "parser/options"
8 changes: 4 additions & 4 deletions lib/bundler/vendor/thor/lib/thor/runner.rb
@@ -1,6 +1,6 @@
require "bundler/vendor/thor/lib/thor"
require "bundler/vendor/thor/lib/thor/group"
require "bundler/vendor/thor/lib/thor/core_ext/io_binary_read"
require_relative "../thor"
require_relative "group"
require_relative "core_ext/io_binary_read"

require "yaml"
require "digest/md5"
Expand Down Expand Up @@ -111,7 +111,7 @@ def install(name) # rubocop:disable MethodLength

desc "version", "Show Bundler::Thor version"
def version
require "bundler/vendor/thor/lib/thor/version"
require_relative "version"
say "Bundler::Thor #{Bundler::Thor::VERSION}"
end

Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/vendor/thor/lib/thor/shell/color.rb
@@ -1,4 +1,4 @@
require "bundler/vendor/thor/lib/thor/shell/basic"
require_relative "basic"

class Bundler::Thor
module Shell
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/vendor/thor/lib/thor/shell/html.rb
@@ -1,4 +1,4 @@
require "bundler/vendor/thor/lib/thor/shell/basic"
require_relative "basic"

class Bundler::Thor
module Shell
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/vendored_thor.rb
Expand Up @@ -2,7 +2,7 @@

module Bundler
def self.require_thor_actions
Kernel.send(:require, "bundler/vendor/thor/lib/thor/actions")
require_relative "vendor/thor/lib/thor/actions"
end
end
require_relative "vendor/thor/lib/thor"

0 comments on commit aa2a882

Please sign in to comment.