gem_bench 2.0.4 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +178 -7
- data/LICENSE.md +11 -0
- data/README.md +410 -347
- data/lib/gem_bench/gemfile_line_tokenizer.rb +9 -9
- data/lib/gem_bench/jersey.rb +4 -4
- data/lib/gem_bench/player.rb +1 -1
- data/lib/gem_bench/scout.rb +1 -1
- data/lib/gem_bench/strict_version_gem.rb +1 -1
- data/lib/gem_bench/strict_version_requirement.rb +0 -0
- data/lib/gem_bench/team.rb +24 -16
- data/lib/gem_bench/version.rb +7 -2
- data/lib/gem_bench.rb +6 -6
- data/sig/gem_bench.rbs +6 -0
- data.tar.gz.sig +0 -0
- metadata +145 -99
- metadata.gz.sig +0 -0
- data/CODE_OF_CONDUCT.md +0 -133
- data/CONTRIBUTING.md +0 -60
- data/LICENSE.txt +0 -21
- data/SECURITY.md +0 -14
|
@@ -6,9 +6,9 @@ module GemBench
|
|
|
6
6
|
class GemfileLineTokenizer
|
|
7
7
|
GEM_REGEX = /\A\s*gem\s+([^#]*).*\Z/.freeze # run against gem lines like: "gem 'aftership', # Ruby SDK of AfterShip API."
|
|
8
8
|
# HEREDOC support? (?<op_heredoc><<[~-]?[A-Z0-9_]+\.?[a-z0-9_]+)
|
|
9
|
-
OP_QUO_REG_PROC = lambda { |idx = nil| /((?<op_quo#{idx}>['"]{1})|(?<op_pct_q#{idx}>%[Qq]?[
|
|
9
|
+
OP_QUO_REG_PROC = lambda { |idx = nil| /((?<op_quo#{idx}>['"]{1})|(?<op_pct_q#{idx}>%[Qq]?[(\[{]{1})|(?<op_heredoc><<[~-]?[A-Z0-9_]+\.?[a-z0-9_]+))/x }
|
|
10
10
|
# No close for the heredoc, as it will be on a different line...
|
|
11
|
-
CL_QUO_REG_PROC = lambda { |idx = nil| /((?<cl_quo#{idx}>['"])|(?<cl_pct_q#{idx}>[
|
|
11
|
+
CL_QUO_REG_PROC = lambda { |idx = nil| /((?<cl_quo#{idx}>['"])|(?<cl_pct_q#{idx}>[)\]}]{1}))/x }
|
|
12
12
|
GEM_NAME_REGEX = /\A\s*gem\s+#{OP_QUO_REG_PROC.call.source}(?<name>[^'")]*)#{CL_QUO_REG_PROC.call.source}?.*\Z/.freeze # run against gem lines like: "gem 'aftership', # Ruby SDK of AfterShip API."
|
|
13
13
|
VERSION_CONSTRAINT = /#{OP_QUO_REG_PROC.call.source}(?<version>[^'")]*)#{CL_QUO_REG_PROC.call.source}/.freeze
|
|
14
14
|
GEMFILE_HASH_CONFIG_KEY_REGEX_PROC = lambda { |key|
|
|
@@ -59,7 +59,7 @@ module GemBench
|
|
|
59
59
|
pct_q: true,
|
|
60
60
|
# We could try to support HEREDOC via parsing the lines following in all_lines, but... ugh.
|
|
61
61
|
heredoc: false,
|
|
62
|
-
unknown: false
|
|
62
|
+
unknown: false
|
|
63
63
|
}.freeze
|
|
64
64
|
attr_reader :line
|
|
65
65
|
attr_reader :relevant_lines, :is_gem, :all_lines, :index, :tokens, :version_type, :name, :parse_success, :valid
|
|
@@ -170,7 +170,7 @@ module GemBench
|
|
|
170
170
|
enhance_version(
|
|
171
171
|
line.match(VERSION_PATH),
|
|
172
172
|
:path,
|
|
173
|
-
:path
|
|
173
|
+
:path
|
|
174
174
|
)
|
|
175
175
|
end
|
|
176
176
|
|
|
@@ -182,7 +182,7 @@ module GemBench
|
|
|
182
182
|
enhance_version(
|
|
183
183
|
line.match(VERSION_GIT),
|
|
184
184
|
:git,
|
|
185
|
-
:git
|
|
185
|
+
:git
|
|
186
186
|
)
|
|
187
187
|
end
|
|
188
188
|
|
|
@@ -209,7 +209,7 @@ module GemBench
|
|
|
209
209
|
enhance_version(
|
|
210
210
|
line.match(matcher),
|
|
211
211
|
:github,
|
|
212
|
-
:github
|
|
212
|
+
:github
|
|
213
213
|
)
|
|
214
214
|
end
|
|
215
215
|
|
|
@@ -224,7 +224,7 @@ module GemBench
|
|
|
224
224
|
enhance_version(
|
|
225
225
|
line.match(VERSION_GIT_REF),
|
|
226
226
|
:ref,
|
|
227
|
-
:git_ref
|
|
227
|
+
:git_ref
|
|
228
228
|
)
|
|
229
229
|
end
|
|
230
230
|
|
|
@@ -236,7 +236,7 @@ module GemBench
|
|
|
236
236
|
enhance_version(
|
|
237
237
|
line.match(VERSION_GIT_TAG),
|
|
238
238
|
:tag,
|
|
239
|
-
:git_tag
|
|
239
|
+
:git_tag
|
|
240
240
|
)
|
|
241
241
|
end
|
|
242
242
|
|
|
@@ -248,7 +248,7 @@ module GemBench
|
|
|
248
248
|
enhance_version(
|
|
249
249
|
line.match(VERSION_GIT_BRANCH),
|
|
250
250
|
:branch,
|
|
251
|
-
:git_branch
|
|
251
|
+
:git_branch
|
|
252
252
|
)
|
|
253
253
|
end
|
|
254
254
|
|
data/lib/gem_bench/jersey.rb
CHANGED
|
@@ -136,10 +136,10 @@ module GemBench
|
|
|
136
136
|
end
|
|
137
137
|
files.each do |filepath|
|
|
138
138
|
# But files required here may not load their own internal files properly if they are still using `require`.
|
|
139
|
-
# Since Ruby
|
|
140
|
-
# and require for external files and dependencies.
|
|
141
|
-
# Ref: https://github.com/
|
|
142
|
-
# We *can* use `require` *here*, because filepath here is an absolute paths
|
|
139
|
+
# Since Ruby 1.9.2, best practice for ruby libraries is to use require_relative for internal files,
|
|
140
|
+
# and require for external files and dependencies, generally, and oversimplified.
|
|
141
|
+
# Ref: https://github.com/rubocop/rubocop/issues/8748#issuecomment-2363327346
|
|
142
|
+
# However, We *can* use `require` *here*, because filepath here is an absolute paths
|
|
143
143
|
require filepath
|
|
144
144
|
end
|
|
145
145
|
|
data/lib/gem_bench/player.rb
CHANGED
data/lib/gem_bench/scout.rb
CHANGED
|
@@ -6,7 +6,7 @@ module GemBench
|
|
|
6
6
|
attr_reader :gem_paths, :gemfile_path, :gemfile_lines, :gemfile_trash, :loaded_gems
|
|
7
7
|
|
|
8
8
|
def initialize(check_gemfile: nil, **options)
|
|
9
|
-
@check_gemfile = check_gemfile.nil?
|
|
9
|
+
@check_gemfile = check_gemfile.nil? || check_gemfile
|
|
10
10
|
@gemfile_path = options.fetch(:gemfile_path, "#{Dir.pwd}/Gemfile")
|
|
11
11
|
gem_lookup_paths_from_bundler
|
|
12
12
|
gem_lines_from_gemfile
|
|
File without changes
|
data/lib/gem_bench/team.rb
CHANGED
|
@@ -6,6 +6,13 @@ module GemBench
|
|
|
6
6
|
# - if you are in a rails console, and want to evaluate the Gemfile of the Rails app, that's great!
|
|
7
7
|
# - if you are in a context with no Gemfile loaded, or a different Gemfile loaded than the one you want to evaluate,
|
|
8
8
|
# this class may not give sensible results. This is because it checks loaded gems via RubyGems and Bundler.
|
|
9
|
+
#
|
|
10
|
+
# Terminology:
|
|
11
|
+
#
|
|
12
|
+
# starter: a gem that needs to be loaded when bundler normally loads gems
|
|
13
|
+
#
|
|
14
|
+
# bencher: a gem that can, or should, have require: false to delay loading until after bootstrap
|
|
15
|
+
#
|
|
9
16
|
class Team
|
|
10
17
|
EXCLUDE = %w[
|
|
11
18
|
bundler
|
|
@@ -29,6 +36,7 @@ module GemBench
|
|
|
29
36
|
]
|
|
30
37
|
# A comment preceding the require: false anywhere on the line should not be considered an active require: false
|
|
31
38
|
extend Forwardable
|
|
39
|
+
|
|
32
40
|
def_delegators :@scout, :gem_paths, :gemfile_path, :check_gemfile?, :loaded_gems
|
|
33
41
|
attr_reader :scout, :look_for_regex
|
|
34
42
|
attr_accessor :all,
|
|
@@ -49,12 +57,12 @@ module GemBench
|
|
|
49
57
|
@benching = @check_type == :bench
|
|
50
58
|
@scout = GemBench::Scout.new(
|
|
51
59
|
check_gemfile: options.fetch(:check_gemfile, benching?),
|
|
52
|
-
gemfile_path: options.fetch(:gemfile_path, "#{Dir.pwd}/Gemfile")
|
|
60
|
+
gemfile_path: options.fetch(:gemfile_path, "#{Dir.pwd}/Gemfile")
|
|
53
61
|
)
|
|
54
62
|
@exclude_file_pattern_regex_proc = options[:exclude_file_pattern_regex_proc].respond_to?(:call) ? options[:exclude_file_pattern_regex_proc] : GemBench::EXCLUDE_FILE_PATTERN_REGEX_PROC
|
|
55
63
|
# Among the loaded gems there may be some that did not need to be.
|
|
56
|
-
|
|
57
|
-
exclusions = " + #{excluded.length} loaded gems which GemBench is configured to ignore.\n" if
|
|
64
|
+
exclude!
|
|
65
|
+
exclusions = " + #{excluded.length} loaded gems which GemBench is configured to ignore.\n" if excluded.any?
|
|
58
66
|
@starters = []
|
|
59
67
|
@benchers = []
|
|
60
68
|
@current_gemfile_suggestions = []
|
|
@@ -70,11 +78,9 @@ module GemBench
|
|
|
70
78
|
false
|
|
71
79
|
end
|
|
72
80
|
puts "[GemBench] Will search for gems in #{gem_paths.inspect}\n#{if benching?
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
end}#{bad_ideas ? "[GemBench] Will show bad ideas. Be Careful.\n" : ""}[GemBench] Detected #{all.length} loaded gems#{exclusions}"
|
|
77
|
-
compare_gemfile if benching? && @scout.check_gemfile?
|
|
81
|
+
check_gemfile? ? "[GemBench] Will check Gemfile at #{gemfile_path}.\n" : "[GemBench] No Gemfile found.\n"
|
|
82
|
+
end}#{"[GemBench] Will show bad ideas. Be Careful.\n" if bad_ideas}[GemBench] Detected #{all.length} loaded gems#{exclusions}"
|
|
83
|
+
compare_gemfile if benching? && check_gemfile?
|
|
78
84
|
self.print if verbose
|
|
79
85
|
end
|
|
80
86
|
|
|
@@ -82,6 +88,7 @@ module GemBench
|
|
|
82
88
|
starters.map { |starter| starter.to_s(format) }
|
|
83
89
|
end
|
|
84
90
|
|
|
91
|
+
# @return void
|
|
85
92
|
def print
|
|
86
93
|
string = ""
|
|
87
94
|
if all.empty?
|
|
@@ -92,7 +99,7 @@ module GemBench
|
|
|
92
99
|
else
|
|
93
100
|
"[GemBench] Found no gems containing #{look_for_regex} in Ruby code.\n"
|
|
94
101
|
end
|
|
95
|
-
|
|
102
|
+
else
|
|
96
103
|
string << "\n#{GemBench::USAGE}" unless check_gemfile?
|
|
97
104
|
string << if benching?
|
|
98
105
|
"[GemBench] We found a Rails::Railtie or Rails::Engine in the following files. However, it is possible that there are false positives, so you may want to verify that this is the case.\n\n"
|
|
@@ -116,18 +123,15 @@ module GemBench
|
|
|
116
123
|
starters.each_with_index do |starter, index|
|
|
117
124
|
string << "#{starter.info(index + 1)}\n"
|
|
118
125
|
end
|
|
119
|
-
if extra_verbose? && !benching? && benchers.
|
|
126
|
+
if extra_verbose? && !benching? && benchers.any?
|
|
120
127
|
string << "[GemBench] #{benchers.length} out of #{all.length} evaluated gems did not contain #{look_for_regex}. They are:\n"
|
|
121
128
|
benchers.each_with_index do |bencher, index|
|
|
122
129
|
string << "#{bencher.info(index + 1)}\n"
|
|
123
130
|
end
|
|
124
131
|
end
|
|
125
|
-
else
|
|
126
|
-
string << "[GemBench] Congrats! All gems appear clean.\n"
|
|
127
|
-
string << "\n#{GemBench::USAGE}" unless check_gemfile?
|
|
128
132
|
end
|
|
129
133
|
if check_gemfile? && benching?
|
|
130
|
-
if current_gemfile_suggestions.
|
|
134
|
+
if current_gemfile_suggestions.any?
|
|
131
135
|
string << "[GemBench] Evaluated #{all.length} gems and Gemfile at #{gemfile_path}.\n[GemBench] Here are #{current_gemfile_suggestions.length} suggestions for improvement:\n"
|
|
132
136
|
current_gemfile_suggestions.each_with_index do |player, index|
|
|
133
137
|
string << "#{player.suggest(index + 1)}\n"
|
|
@@ -159,7 +163,7 @@ module GemBench
|
|
|
159
163
|
|
|
160
164
|
def prepare_bad_ideas
|
|
161
165
|
string = ""
|
|
162
|
-
if benchers.
|
|
166
|
+
if benchers.any?
|
|
163
167
|
gemfile_instruction = check_gemfile? ? "" : "To safely evaluate a Gemfile:\n\t1. Make sure you are in the root of a project with a Gemfile\n\t2. Make sure the gem is actually a dependency in the Gemfile\n"
|
|
164
168
|
string << "[GemBench] Evaluated #{all.length} loaded gems and found #{benchers.length} which may be able to skip boot loading (require: false).\n*** => WARNING <= ***: Be careful adding non-primary dependencies to your Gemfile as it is generally a bad idea.\n#{gemfile_instruction}"
|
|
165
169
|
benchers.each_with_index do |player, index|
|
|
@@ -194,7 +198,7 @@ module GemBench
|
|
|
194
198
|
player = GemBench::Player.new({
|
|
195
199
|
name: player_data[0],
|
|
196
200
|
version: player_data[1],
|
|
197
|
-
exclude_file_pattern: exclude_file_pattern
|
|
201
|
+
exclude_file_pattern: exclude_file_pattern
|
|
198
202
|
})
|
|
199
203
|
check(player)
|
|
200
204
|
add_to_roster(player)
|
|
@@ -223,6 +227,10 @@ module GemBench
|
|
|
223
227
|
|
|
224
228
|
private
|
|
225
229
|
|
|
230
|
+
def exclude!
|
|
231
|
+
self.excluded, self.all = loaded_gems.partition { |x| EXCLUDE.include?(x[0]) }
|
|
232
|
+
end
|
|
233
|
+
|
|
226
234
|
def extra_verbose?
|
|
227
235
|
verbose == "extra"
|
|
228
236
|
end
|
data/lib/gem_bench/version.rb
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module GemBench
|
|
2
|
-
# Version
|
|
4
|
+
# Version namespace for this gem.
|
|
3
5
|
module Version
|
|
4
|
-
|
|
6
|
+
# Current gem version.
|
|
7
|
+
VERSION = "2.0.6"
|
|
5
8
|
end
|
|
9
|
+
# Current gem version exposed at the traditional constant location.
|
|
10
|
+
VERSION = Version::VERSION # Traditional Constant Location
|
|
6
11
|
end
|
data/lib/gem_bench.rb
CHANGED
|
@@ -3,13 +3,13 @@ require "version_gem"
|
|
|
3
3
|
require "bundler" # This gem utilizes bundler as a tool.
|
|
4
4
|
|
|
5
5
|
# this library
|
|
6
|
-
require_relative "gem_bench/version"
|
|
7
6
|
require_relative "gem_bench/scout"
|
|
8
7
|
require_relative "gem_bench/player"
|
|
9
8
|
require_relative "gem_bench/team"
|
|
10
9
|
require_relative "gem_bench/gemfile_line_tokenizer"
|
|
11
10
|
require_relative "gem_bench/strict_version_gem"
|
|
12
11
|
require_relative "gem_bench/strict_version_requirement"
|
|
12
|
+
require_relative "gem_bench/version"
|
|
13
13
|
|
|
14
14
|
module GemBench
|
|
15
15
|
USAGE = "[GemBench] Usage: Require another gem in this session to evaluate it.\n\tExample:\n\t\trequire 'rails'\n\t\tGemBench.check({verbose: true})\n"
|
|
@@ -22,13 +22,13 @@ module GemBench
|
|
|
22
22
|
DO_NOT_SCAN = []
|
|
23
23
|
PLAYER_STATES = {
|
|
24
24
|
starter: :starter,
|
|
25
|
-
bench: :bench
|
|
25
|
+
bench: :bench
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
class << self
|
|
29
29
|
def check(verbose: false, gemfile_path: nil)
|
|
30
30
|
options = {
|
|
31
|
-
verbose: verbose
|
|
31
|
+
verbose: verbose
|
|
32
32
|
}
|
|
33
33
|
options[:gemfile_path] = gemfile_path if gemfile_path
|
|
34
34
|
GemBench::Team.new(**options)
|
|
@@ -36,7 +36,7 @@ module GemBench
|
|
|
36
36
|
|
|
37
37
|
def versions_present?(verbose: false, gemfile_path: nil)
|
|
38
38
|
options = {
|
|
39
|
-
verbose: verbose
|
|
39
|
+
verbose: verbose
|
|
40
40
|
}
|
|
41
41
|
options[:gemfile_path] = gemfile_path if gemfile_path
|
|
42
42
|
GemBench::StrictVersionRequirement.new(**options).versions_present?
|
|
@@ -44,7 +44,7 @@ module GemBench
|
|
|
44
44
|
|
|
45
45
|
def list_missing_version_constraints(verbose: false, gemfile_path: nil)
|
|
46
46
|
options = {
|
|
47
|
-
verbose: verbose
|
|
47
|
+
verbose: verbose
|
|
48
48
|
}
|
|
49
49
|
options[:gemfile_path] = gemfile_path if gemfile_path
|
|
50
50
|
GemBench::StrictVersionRequirement.new(**options).list_missing_version_constraints
|
|
@@ -57,7 +57,7 @@ module GemBench
|
|
|
57
57
|
options = {
|
|
58
58
|
verbose: verbose,
|
|
59
59
|
look_for_regex: look_for_regex,
|
|
60
|
-
exclude_file_pattern_regex_proc: exclude_file_pattern_regex_proc
|
|
60
|
+
exclude_file_pattern_regex_proc: exclude_file_pattern_regex_proc
|
|
61
61
|
}
|
|
62
62
|
options[:gemfile_path] = gemfile_path if gemfile_path
|
|
63
63
|
GemBench::Team.new(**options)
|
data/sig/gem_bench.rbs
ADDED
data.tar.gz.sig
CHANGED
|
Binary file
|