bundler-stats 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bundler/stats/remover.rb +40 -31
- data/lib/bundler/stats/version.rb +1 -2
- data/spec/lib/bundler/stats/remover_spec.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66d53289a79dd7b950987a512f6876f60f415862ab169c2b3fe935a4199b25c3
|
4
|
+
data.tar.gz: 130b1e1a7d84163bea7fa95802639e1078bb53c1176f1d7482c0168ff752e37e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 882690eb56bbbd2bd001703277cd499ddd2e13ce3376470ae5ff1f657a23425a86112acd6bb2d3fa54e9ad92d1c6ccb1adfcca1742ec0a7b821b519cf77c305f
|
7
|
+
data.tar.gz: 7f3dcd1216f8747c1f36bc4627017eebf94f7eb1f668eb8e923e56ed3975958861bf48ceb605004e7f368216de638e2a2065f100c8a52c422417ac6ef0c68063
|
@@ -1,41 +1,50 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
candidates = @tree.transitive_dependencies(target)
|
11
|
-
candidates.reject do |candidate|
|
12
|
-
still_used?(candidate.name, deleted: target)
|
13
|
-
end
|
14
|
-
end
|
1
|
+
class Bundler::Stats::Remover
|
2
|
+
ERR_MESSAGE = "Trying to check whether `%s` can be removed, but was unable " \
|
3
|
+
"to resolve whether it is used by `%s`. It may not be in your Gemfile.lock. " \
|
4
|
+
"This often happens when a dependency isn't installed on your platform."
|
5
|
+
|
6
|
+
def initialize(tree, top_level)
|
7
|
+
@tree = tree
|
8
|
+
@top_level = top_level
|
9
|
+
end
|
15
10
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
modified_tree.delete(deleted)
|
11
|
+
def potential_removals(target)
|
12
|
+
candidates = @tree.transitive_dependencies(target)
|
13
|
+
candidates.reject do |candidate|
|
14
|
+
still_used?(candidate.name, deleted: target)
|
15
|
+
end
|
16
|
+
end
|
23
17
|
|
24
|
-
|
18
|
+
# TODO: woo naive algorithm
|
19
|
+
# TODO: circular dependencies would be an issue here
|
20
|
+
# TODO: also probably use something like transitive_dependencies
|
21
|
+
# to leverage the abilities in tree...
|
22
|
+
def still_used?(target, deleted: nil)
|
23
|
+
modified_tree = @tree.tree.clone
|
24
|
+
modified_tree.delete(deleted)
|
25
25
|
|
26
|
-
|
27
|
-
candidate = deps_to_check.pop.name
|
26
|
+
deps_to_check = (@top_level - [Gem::Dependency.new(deleted)])
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
return true if candidate == target
|
28
|
+
while !deps_to_check.empty? do
|
29
|
+
candidate = deps_to_check.pop.name
|
32
30
|
|
33
|
-
|
34
|
-
|
31
|
+
next if candidate == deleted
|
32
|
+
next if candidate == "bundler"
|
33
|
+
return true if candidate == target
|
35
34
|
|
36
|
-
|
35
|
+
if modified_tree[candidate].nil?
|
36
|
+
warn(ERR_MESSAGE % [target, candidate])
|
37
|
+
else
|
38
|
+
deps_to_check += modified_tree[candidate].dependencies
|
37
39
|
end
|
38
40
|
end
|
41
|
+
|
42
|
+
false
|
39
43
|
end
|
40
|
-
end
|
41
44
|
|
45
|
+
private
|
46
|
+
|
47
|
+
def warn(str)
|
48
|
+
STDERR.puts(str)
|
49
|
+
end
|
50
|
+
end
|
@@ -102,5 +102,15 @@ describe Bundler::Stats::Remover do
|
|
102
102
|
|
103
103
|
expect(target).to be_falsy
|
104
104
|
end
|
105
|
+
|
106
|
+
it "raises an error if the top level dependency isn't in the lockfile" do
|
107
|
+
top_level << dep("tzinfo")
|
108
|
+
remover = subject.new(tree, top_level)
|
109
|
+
allow(remover).to receive(:warn)
|
110
|
+
|
111
|
+
remover.still_used?("actionview", deleted: "rails")
|
112
|
+
|
113
|
+
expect(remover).to have_received(:warn)
|
114
|
+
end
|
105
115
|
end
|
106
116
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bundler-stats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Mastey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|