Class: Dependabot::NpmAndYarn::FileParser
- Inherits:
-
FileParsers::Base
- Object
- FileParsers::Base
- Dependabot::NpmAndYarn::FileParser
show all
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/npm_and_yarn/file_parser.rb,
lib/dependabot/npm_and_yarn/file_parser/json_lock.rb,
lib/dependabot/npm_and_yarn/file_parser/pnpm_lock.rb,
lib/dependabot/npm_and_yarn/file_parser/yarn_lock.rb,
lib/dependabot/npm_and_yarn/file_parser/lockfile_parser.rb
Defined Under Namespace
Classes: JsonLock, LockfileParser, PnpmLock, YarnLock
Constant Summary
collapse
- DEPENDENCY_TYPES =
T.let(%w(dependencies devDependencies optionalDependencies).freeze, T::Array[String])
- GIT_URL_REGEX =
%r{
(?<git_prefix>^|^git.*?|^github:|^bitbucket:|^gitlab:|github\.com/)
(?<username>[a-z0-9-]+)/
(?<repo>[a-z0-9_.-]+)
(
(?:\#semver:(?<semver>.+))|
(?:\#(?=[\^~=<>*])(?<semver>.+))|
(?:\#(?<ref>.+))
)?$
}ix
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.each_dependency(json, &_block) ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'lib/dependabot/npm_and_yarn/file_parser.rb', line 47
def self.each_dependency(json, &_block)
DEPENDENCY_TYPES.each do |type|
deps = json[type] || {}
deps.each do |name, requirement|
yield(name, requirement, type)
end
end
end
|
Instance Method Details
#parse ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/dependabot/npm_and_yarn/file_parser.rb', line 57
def parse
dependency_set = DependencySet.new
dependency_set += manifest_dependencies
dependency_set += lockfile_dependencies
dependencies = Helpers.dependencies_with_all_versions_metadata(dependency_set)
dependencies.reject do |dep|
reqs = dep.requirements
support_reqs = reqs.select { |r| support_package_files.any? { |f| f.name == r[:file] } }
next true if support_reqs.any?
git_reqs = reqs.select { |r| r.dig(:source, :type) == "git" }
next false if git_reqs.none?
next true if git_reqs.map { |r| r.fetch(:source) }.uniq.count > 1
dep.requirements.any? { |r| r.dig(:source, :type) != "git" }
end
end
|