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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a041422eb6d86e13e5b062fe2d7bd309b282523f2804a9470d21754279ca18f
4
- data.tar.gz: 84f4a87d5d2a5ba647f59fa98cca6cd7d505bcdfc403efa4445d6cf70f2db6b7
3
+ metadata.gz: 66d53289a79dd7b950987a512f6876f60f415862ab169c2b3fe935a4199b25c3
4
+ data.tar.gz: 130b1e1a7d84163bea7fa95802639e1078bb53c1176f1d7482c0168ff752e37e
5
5
  SHA512:
6
- metadata.gz: 3bf9ea8589a762991695b6bae03d49f0af821fdc2a5db82fdcfdea17ef0cb8750458063cb3ccb5e3cff650ea5212ec194ff7280ddca0a2c29906983d0d3d7c58
7
- data.tar.gz: 993b1a9bd53a7e6b34f460689f22717882ed764e11d4f73796fe0d883f2dbf46dc44b2d3f3062f292cba24701bd40e680d3de748e9c94c935dc5b206ce8d5a57
6
+ metadata.gz: 882690eb56bbbd2bd001703277cd499ddd2e13ce3376470ae5ff1f657a23425a86112acd6bb2d3fa54e9ad92d1c6ccb1adfcca1742ec0a7b821b519cf77c305f
7
+ data.tar.gz: 7f3dcd1216f8747c1f36bc4627017eebf94f7eb1f668eb8e923e56ed3975958861bf48ceb605004e7f368216de638e2a2065f100c8a52c422417ac6ef0c68063
@@ -1,41 +1,50 @@
1
- module Bundler
2
- module Stats
3
- class Remover
4
- def initialize(tree, top_level)
5
- @tree = tree
6
- @top_level = top_level
7
- end
8
-
9
- def potential_removals(target)
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
- # TODO: woo naive algorithm
17
- # TODO: circular dependencies would be an issue here
18
- # TODO: also probably use something like transitive_dependencies
19
- # to leverage the abilities in tree...
20
- def still_used?(target, deleted: nil)
21
- modified_tree = @tree.tree.clone
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
- deps_to_check = (@top_level - [Gem::Dependency.new(deleted)])
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
- while !deps_to_check.empty? do
27
- candidate = deps_to_check.pop.name
26
+ deps_to_check = (@top_level - [Gem::Dependency.new(deleted)])
28
27
 
29
- next if candidate == deleted
30
- next if candidate == "bundler"
31
- return true if candidate == target
28
+ while !deps_to_check.empty? do
29
+ candidate = deps_to_check.pop.name
32
30
 
33
- deps_to_check += modified_tree[candidate].dependencies
34
- end
31
+ next if candidate == deleted
32
+ next if candidate == "bundler"
33
+ return true if candidate == target
35
34
 
36
- false
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
@@ -1,6 +1,5 @@
1
1
  module Bundler
2
2
  module Stats
3
- # bundler-stats version
4
- VERSION = '1.3.1'
3
+ VERSION = '1.3.2'
5
4
  end
6
5
  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.1
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-05 00:00:00.000000000 Z
11
+ date: 2019-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler