npmdc 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +6 -5
- data/lib/npmdc/checker.rb +29 -22
- data/lib/npmdc/config.rb +3 -1
- data/lib/npmdc/errors.rb +43 -1
- data/lib/npmdc/formatters/documentation.rb +3 -1
- data/lib/npmdc/formatters/progress.rb +3 -1
- data/lib/npmdc/version.rb +1 -1
- data/lib/npmdc.rb +1 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 112fb0c5efc03f50a0870591e6f3067dbe634425
|
4
|
+
data.tar.gz: d361a763ceef587dc76fe1ef4d0c15d044e400b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f381341d64a7b6742671efb6ceea4ac9ad703620dd9bdf57b51a3495d6cd299365e505f2ba14f2c5750bc09ae7c123d011305e04985ab003d525b695b9e211fa
|
7
|
+
data.tar.gz: c4b5f138919774d106b1d4fa897c7176933dc0446c1822111b037ade6ee534584707b9cbe03916e7054a341ebe3681b9d62a626b744225235eed6a0c415fc5c3
|
data/CHANGELOG.md
CHANGED
@@ -92,3 +92,14 @@ Thanks to @palkan !
|
|
92
92
|
Thanks to @sponomarev !
|
93
93
|
|
94
94
|
* Added support for environment-based configuration
|
95
|
+
|
96
|
+
|
97
|
+
### 0.4.0
|
98
|
+
|
99
|
+
* Added support for "non-version" strings defined as packages version
|
100
|
+
|
101
|
+
* Added output warnings for unprocessable cases
|
102
|
+
|
103
|
+
Thanks to @sponomarev !
|
104
|
+
|
105
|
+
* Added `abort_on_failure` option
|
data/README.md
CHANGED
@@ -37,11 +37,12 @@ Or install it yourself as:
|
|
37
37
|
|
38
38
|
```ruby
|
39
39
|
YourApp::Application.configure do
|
40
|
-
config.npmdc.path
|
41
|
-
config.npmdc.format
|
42
|
-
config.npmdc.color
|
43
|
-
config.npmdc.types
|
44
|
-
config.npmdc.environments
|
40
|
+
config.npmdc.path = "/path/to/your/frontend/code/dir" # `Rails.root` by default
|
41
|
+
config.npmdc.format = "doc" # `short`, `doc`, `progress`. `short` by default
|
42
|
+
config.npmdc.color = false # `true` by default
|
43
|
+
config.npmdc.types = ["dependencies"] # `["dependencies", "devDependencies"]` by default
|
44
|
+
config.npmdc.environments = ["development"] # `development` only by default
|
45
|
+
config.npmdc.abort_on_failure = true # 'false' by default
|
45
46
|
end
|
46
47
|
```
|
47
48
|
|
data/lib/npmdc/checker.rb
CHANGED
@@ -15,9 +15,11 @@ module Npmdc
|
|
15
15
|
def initialize(options)
|
16
16
|
@path = options.fetch('path', Npmdc.config.path)
|
17
17
|
@types = options.fetch('types', Npmdc.config.types)
|
18
|
+
@abort_on_failure = options.fetch('abort_on_failure', Npmdc.config.abort_on_failure)
|
18
19
|
@formatter = Npmdc::Formatter.(options)
|
19
20
|
@dependencies_count = 0
|
20
21
|
@missing_dependencies = Set.new
|
22
|
+
@suspicious_dependencies = Set.new
|
21
23
|
end
|
22
24
|
|
23
25
|
delegate [
|
@@ -26,30 +28,29 @@ module Npmdc
|
|
26
28
|
] => :formatter
|
27
29
|
|
28
30
|
def call
|
29
|
-
|
30
|
-
|
31
|
-
package_json_data
|
32
|
-
|
33
|
-
check_dependencies(package_json_data[dep], dep) if package_json_data[dep]
|
34
|
-
end
|
31
|
+
package_json_data = package_json(path)
|
32
|
+
@types.each do |dep|
|
33
|
+
check_dependencies(package_json_data[dep], dep) if package_json_data[dep]
|
34
|
+
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
else
|
39
|
-
success = true unless !@missing_dependencies.empty?
|
40
|
-
ensure
|
41
|
-
if !@missing_dependencies.empty?
|
42
|
-
output("Following dependencies required by your package.json file are missing or not installed properly:")
|
43
|
-
@missing_dependencies.each do |dep|
|
44
|
-
output(" * #{dep}")
|
45
|
-
end
|
46
|
-
output("\nRun `npm install` to install #{@missing_dependencies.size} missing packages.", :warn)
|
47
|
-
elsif success
|
48
|
-
output("Checked #{@dependencies_count} packages. Everything is ok.", :success)
|
49
|
-
end
|
36
|
+
if !@missing_dependencies.empty?
|
37
|
+
raise(MissedDependencyError, dependencies: @missing_dependencies)
|
50
38
|
end
|
51
39
|
|
52
|
-
|
40
|
+
result_stats = "Checked #{@dependencies_count} packages. " +
|
41
|
+
"Warnings: #{@suspicious_dependencies.count}. " +
|
42
|
+
"Errors: #{@missing_dependencies.count}. " +
|
43
|
+
"Everything is ok."
|
44
|
+
|
45
|
+
output(result_stats, :success)
|
46
|
+
|
47
|
+
true
|
48
|
+
rescue CheckerError => e
|
49
|
+
error_output(e)
|
50
|
+
|
51
|
+
exit(1) if @abort_on_failure && e.class.critical?
|
52
|
+
|
53
|
+
false
|
53
54
|
end
|
54
55
|
|
55
56
|
private
|
@@ -84,7 +85,13 @@ module Npmdc
|
|
84
85
|
|
85
86
|
deps.each_key do |dep|
|
86
87
|
@dependencies_count += 1
|
87
|
-
|
88
|
+
|
89
|
+
if SemanticRange.valid_range(deps[dep])
|
90
|
+
check_dependency(dep, deps[dep])
|
91
|
+
else
|
92
|
+
@suspicious_dependencies << "#{dep}@#{deps[dep]}"
|
93
|
+
dep_output("npmdc cannot check package '#{dep}' (#{deps[dep]})", :warn)
|
94
|
+
end
|
88
95
|
end
|
89
96
|
|
90
97
|
check_finish_output
|
data/lib/npmdc/config.rb
CHANGED
@@ -3,7 +3,8 @@ module Npmdc
|
|
3
3
|
DEPEPENDENCY_TYPES = %w(dependencies devDependencies).freeze
|
4
4
|
ENVIRONMENTS = %w(development).freeze
|
5
5
|
|
6
|
-
attr_accessor :color, :format, :output, :types, :environments
|
6
|
+
attr_accessor :color, :format, :output, :types, :environments,
|
7
|
+
:abort_on_failure
|
7
8
|
attr_writer :path
|
8
9
|
|
9
10
|
def initialize
|
@@ -12,6 +13,7 @@ module Npmdc
|
|
12
13
|
@output = STDOUT
|
13
14
|
@types = DEPEPENDENCY_TYPES
|
14
15
|
@environments = ENVIRONMENTS
|
16
|
+
@abort_on_failure = false
|
15
17
|
end
|
16
18
|
|
17
19
|
def path
|
data/lib/npmdc/errors.rb
CHANGED
@@ -14,10 +14,27 @@ module Npmdc
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
class CheckerError < Error; end
|
18
17
|
class ConfigurationError < Error; end
|
19
18
|
|
19
|
+
class CheckerError < Error
|
20
|
+
@critical = false
|
21
|
+
|
22
|
+
class << self
|
23
|
+
def critical?
|
24
|
+
@critical
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def define_critical!
|
30
|
+
@critical = true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
20
35
|
class NoNodeModulesError < CheckerError
|
36
|
+
define_critical!
|
37
|
+
|
21
38
|
def banner
|
22
39
|
path = options.fetch(:path)
|
23
40
|
[
|
@@ -28,6 +45,8 @@ module Npmdc
|
|
28
45
|
end
|
29
46
|
|
30
47
|
class WrongPathError < CheckerError
|
48
|
+
define_critical!
|
49
|
+
|
31
50
|
def banner
|
32
51
|
directory = options.fetch(:directory)
|
33
52
|
"There is no '#{directory}' directory."
|
@@ -42,12 +61,35 @@ module Npmdc
|
|
42
61
|
end
|
43
62
|
|
44
63
|
class JsonParseError < CheckerError
|
64
|
+
define_critical!
|
65
|
+
|
45
66
|
def banner
|
46
67
|
path = options.fetch(:path)
|
47
68
|
"Can't parse JSON file #{path}"
|
48
69
|
end
|
49
70
|
end
|
50
71
|
|
72
|
+
class MissedDependencyError < CheckerError
|
73
|
+
define_critical!
|
74
|
+
|
75
|
+
def banner
|
76
|
+
deps = options.fetch(:dependencies)
|
77
|
+
|
78
|
+
[
|
79
|
+
"Following dependencies required by your package.json file are"\
|
80
|
+
" missing or not installed properly:"
|
81
|
+
] + msgs(deps) <<
|
82
|
+
[
|
83
|
+
"\nRun `npm install` to install #{deps.size} missing packages.", :warn
|
84
|
+
]
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def msgs(dependencies)
|
90
|
+
dependencies.map { |d| " * #{d}"}
|
91
|
+
end
|
92
|
+
end
|
51
93
|
|
52
94
|
class UnknownFormatter < ConfigurationError
|
53
95
|
def banner
|
@@ -9,6 +9,8 @@ module Npmdc
|
|
9
9
|
@output.print color_message(".", status)
|
10
10
|
when :failure
|
11
11
|
@output.print color_message("F", status)
|
12
|
+
when :warn
|
13
|
+
@output.print color_message("W", status)
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
@@ -17,4 +19,4 @@ module Npmdc
|
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
20
|
-
end
|
22
|
+
end
|
data/lib/npmdc/version.rb
CHANGED
data/lib/npmdc.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: npmdc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emil Kashkevich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
182
|
version: '0'
|
183
183
|
requirements: []
|
184
184
|
rubyforge_project:
|
185
|
-
rubygems_version: 2.
|
185
|
+
rubygems_version: 2.5.1
|
186
186
|
signing_key:
|
187
187
|
specification_version: 4
|
188
188
|
summary: Check for missed dependencies of NPM packages.
|