diff --git a/npm_and_yarn/lib/dependabot/npm_and_yarn/file_parser.rb b/npm_and_yarn/lib/dependabot/npm_and_yarn/file_parser.rb index 7f42984598a..2873648c01d 100644 --- a/npm_and_yarn/lib/dependabot/npm_and_yarn/file_parser.rb +++ b/npm_and_yarn/lib/dependabot/npm_and_yarn/file_parser.rb @@ -89,6 +89,8 @@ def ecosystem ) end + private + sig { returns(PackageManagerHelper) } def package_manager_helper @package_manager_helper ||= T.let( @@ -108,8 +110,6 @@ def lockfiles } end - private - sig { returns(T.untyped) } def parsed_package_json JSON.parse(T.must(package_json.content)) @@ -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) }