Skip to content

Commit

Permalink
update dependency files finding
Browse files Browse the repository at this point in the history
  • Loading branch information
kbukum1 committed Oct 29, 2024
1 parent 0eca38f commit 741aa65
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions npm_and_yarn/lib/dependabot/npm_and_yarn/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def ecosystem
)
end

private

sig { returns(PackageManagerHelper) }
def package_manager_helper
@package_manager_helper ||= T.let(
Expand All @@ -108,8 +110,6 @@ def lockfiles
}
end

private

sig { returns(T.untyped) }
def parsed_package_json
JSON.parse(T.must(package_json.content))
Expand All @@ -119,33 +119,39 @@ def parsed_package_json

sig { returns(Dependabot::DependencyFile) }
def package_json
@package_json ||= T.let(T.must(get_original_file("package.json")), T.nilable(Dependabot::DependencyFile))
# Declare the instance variable with T.let and the correct type
@package_json ||= T.let(
T.must(dependency_files.find { |f| f.name == "package.json" }),
T.nilable(Dependabot::DependencyFile)
)
end

sig { returns(T.nilable(Dependabot::DependencyFile)) }
def shrinkwrap
@shrinkwrap ||= T.let(
get_original_file("npm-shrinkwrap.json") || get_original_file("package-lock.json"),
T.nilable(Dependabot::DependencyFile)
)
@shrinkwrap ||= T.let(dependency_files.find do |f|
f.name == "npm-shrinkwrap.json"
end, T.nilable(Dependabot::DependencyFile))
end

sig { returns(T.nilable(Dependabot::DependencyFile)) }
def package_lock
@package_lock ||= T.let(
get_original_file("package-lock.json") || get_original_file("npm-shrinkwrap.json"),
T.nilable(Dependabot::DependencyFile)
)
@package_lock ||= T.let(dependency_files.find do |f|
f.name == "package-lock.json"
end, T.nilable(Dependabot::DependencyFile))
end

sig { returns(T.nilable(Dependabot::DependencyFile)) }
def yarn_lock
@yarn_lock ||= T.let(get_original_file("yarn.lock"), T.nilable(Dependabot::DependencyFile))
@yarn_lock ||= T.let(dependency_files.find do |f|
f.name == "yarn.lock"
end, T.nilable(Dependabot::DependencyFile))
end

sig { returns(T.nilable(Dependabot::DependencyFile)) }
def pnpm_lock
@pnpm_lock ||= T.let(get_original_file("pnpm-lock.yaml"), T.nilable(Dependabot::DependencyFile))
@pnpm_lock ||= T.let(dependency_files.find do |f|
f.name == "pnpm-lock.yaml"
end, T.nilable(Dependabot::DependencyFile))
end

sig { returns(Dependabot::FileParsers::Base::DependencySet) }
Expand Down

0 comments on commit 741aa65

Please sign in to comment.