Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleans up feature flag for dynamic version selector #10706

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 17 additions & 28 deletions npm_and_yarn/lib/dependabot/npm_and_yarn/package_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,24 @@ 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)

if Dependabot::Experiments.enabled?(:enable_pnpm_yarn_dynamic_engine)
unless @package_manager&.start_with?("#{name}@") || (@package_manager&.==name.to_s) || @package_manager.nil?
return
end

unless @package_manager&.start_with?("#{name}@") || (@package_manager&.==name.to_s) || @package_manager.nil?
return
end
if @engines && @package_manager.nil?
# if "packageManager" doesn't exists in manifest file,
# we check if we can extract "engines" information
version = check_engine_version(name)

if @engines && @package_manager.nil?
# if "packageManager" doesn't exists in manifest file,
# we check if we can extract "engines" information
Dependabot.logger.info("No \"packageManager\" info found for \"#{name}\"")
version = check_engine_version(name)

elsif @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
Dependabot.logger.info("Found \"packageManager\" : \"#{@package_manager}\"")
version = check_engine_version(name) if @engines

elsif @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}\". Skipped checking \"engines\".")
end
else
return unless @package_manager.nil? || @package_manager&.start_with?("#{name}@")
elsif @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&.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}\". Skipped checking \"engines\".")
end

version ||= requested_version(name)
Expand Down Expand Up @@ -103,7 +96,6 @@ def guessed_version(name)
lockfile = @lockfiles[name.to_sym]
return unless lockfile

Dependabot.logger.info("Estimating version")
Helpers.send(:"#{name}_version_numeric", lockfile)
end

Expand All @@ -112,10 +104,7 @@ def check_engine_version(name)
version_selector = VersionSelector.new
engine_versions = version_selector.setup(@package_json, name)

if engine_versions.empty?
Dependabot.logger.info("No relevant (engines) info for \"#{name}\"")
return
end
return if engine_versions.empty?

version = engine_versions[name]
Dependabot.logger.info("Returned (engines) info \"#{name}\" : \"#{version}\"")
Expand Down
11 changes: 1 addition & 10 deletions npm_and_yarn/lib/dependabot/npm_and_yarn/version_selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@ class VersionSelector
def setup(manifest_json, name)
engine_versions = manifest_json["engines"]

if engine_versions.nil?
Dependabot.logger.info("No info (engines) found")
return {}
end

# logs entries for analysis purposes
log = engine_versions.select do |engine, _value|
engine.to_s.match(name)
end
Dependabot.logger.info("Found engine info #{log}") unless log.empty?
return {} if engine_versions.nil?

# Only keep matching specs versions i.e. "20.21.2", "7.1.2",
# Additional specs can be added later
Expand Down
Loading