Skip to content

Commit

Permalink
revert back removed assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
kbukum1 committed Oct 28, 2024
1 parent c581957 commit 0eca38f
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions npm_and_yarn/lib/dependabot/npm_and_yarn/package_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ class PackageManagerHelper
def initialize(package_json, lockfiles:)
@package_json = package_json
@lockfiles = lockfiles
@manifest_package_manager = package_json["packageManager"]
@engines = package_json.fetch("engines", nil)
@package_manager_detector = PackageManagerDetector.new(@lockfiles, @package_json)
end

Expand All @@ -216,27 +218,27 @@ def setup(name)
# i.e. if { engines : "pnpm" : "6" } and { packageManager: "pnpm@6.0.2" },
# we go for the specificity mentioned in packageManager (6.0.2)

unless @package_manager_attr&.start_with?("#{name}@") ||
(@package_manager_attr&.==name.to_s) ||
@package_manager_attr.nil?
unless @manifest_package_manager&.start_with?("#{name}@") ||
(@manifest_package_manager&.==name.to_s) ||
@manifest_package_manager.nil?
return
end

if @engines && @package_manager_attr.nil?
if @engines && @manifest_package_manager.nil?
# if "packageManager" doesn't exists in manifest file,
# we check if we can extract "engines" information
version = check_engine_version(name)

elsif @package_manager_attr&.==name.to_s
elsif @manifest_package_manager&.==name.to_s
# if "packageManager" is found but no version is specified (i.e. pnpm@1.2.3),
# we check if we can get "engines" info to override default version
version = check_engine_version(name) if @engines

elsif @package_manager_attr&.start_with?("#{name}@")
elsif @manifest_package_manager&.start_with?("#{name}@")
# if "packageManager" info has version specification i.e. yarn@3.3.1
# we go with the version in "packageManager"
Dependabot.logger.info(
"Found \"packageManager\" : \"#{@package_manager_attr}\". Skipped checking \"engines\"."
"Found \"packageManager\" : \"#{@manifest_package_manager}\". Skipped checking \"engines\"."
)
end

Expand Down Expand Up @@ -291,9 +293,9 @@ def install(name, version)
end

def requested_version(name)
return unless @package_manager_attr
return unless @manifest_package_manager

match = @package_manager_attr.match(/^#{name}@(?<version>\d+.\d+.\d+)/)
match = @manifest_package_manager.match(/^#{name}@(?<version>\d+.\d+.\d+)/)
return unless match

Dependabot.logger.info("Requested version #{match['version']}")
Expand Down

0 comments on commit 0eca38f

Please sign in to comment.