-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Set Default npm
Version to 10 Under enable_corepack_for_npm_and_yarn Feature Flag
#10985
Changes from all commits
12814b4
08551eb
bd522e3
295d269
42ce2f4
5d1bb41
759c24e
59d2cfe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ module Helpers | |
/^.*(?<error>The "yarn-path" option has been set \(in [^)]+\), but the specified location doesn't exist)/ | ||
|
||
# NPM Version Constants | ||
NPM_V10 = 10 | ||
NPM_V8 = 8 | ||
NPM_V6 = 6 | ||
NPM_DEFAULT_VERSION = NPM_V8 | ||
|
@@ -40,6 +41,10 @@ module Helpers | |
# Otherwise, we are going to use old versionining npm 6 | ||
sig { params(lockfile: T.nilable(DependencyFile)).returns(Integer) } | ||
def self.npm_version_numeric(lockfile) | ||
if Dependabot::Experiments.enabled?(:enable_corepack_for_npm_and_yarn) | ||
return npm_version_numeric_latest(lockfile) | ||
end | ||
|
||
fallback_version_npm8 = Dependabot::Experiments.enabled?(:npm_fallback_version_above_v6) | ||
|
||
return npm_version_numeric_npm8_or_higher(lockfile) if fallback_version_npm8 | ||
|
@@ -91,6 +96,36 @@ def self.npm_version_numeric_npm8_or_higher(lockfile) | |
NPM_DEFAULT_VERSION # Fallback to default npm version if parsing fails | ||
end | ||
|
||
# rubocop:disable Metrics/PerceivedComplexity | ||
sig { params(lockfile: T.nilable(DependencyFile)).returns(Integer) } | ||
def self.npm_version_numeric_latest(lockfile) | ||
lockfile_content = lockfile&.content | ||
|
||
# Return npm 10 as the default if the lockfile is missing or empty | ||
return NPM_V10 if lockfile_content.nil? || lockfile_content.strip.empty? | ||
|
||
# Parse the lockfile content to extract the `lockfileVersion` | ||
parsed_lockfile = JSON.parse(lockfile_content) | ||
lockfile_version = parsed_lockfile["lockfileVersion"]&.to_i | ||
|
||
# Determine the appropriate npm version based on `lockfileVersion` | ||
if lockfile_version.nil? | ||
NPM_V10 # Use npm 10 if `lockfileVersion` is missing or nil | ||
elsif lockfile_version >= 3 | ||
NPM_V10 # Use npm 10 for lockfileVersion 3 or higher | ||
elsif lockfile_version >= 2 | ||
NPM_V8 # Use npm 8 for lockfileVersion 2 | ||
elsif lockfile_version >= 1 | ||
# Use npm 8 if the fallback version flag is enabled, otherwise use npm 6 | ||
Dependabot::Experiments.enabled?(:npm_fallback_version_above_v6) ? NPM_V8 : NPM_V6 | ||
else | ||
NPM_V10 # Default to npm 10 for unexpected or unsupported versions | ||
end | ||
rescue JSON::ParserError | ||
NPM_V8 # Fallback to npm 8 if the lockfile content cannot be parsed | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review Tip:
In all other scenarios, we default to npm There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kbukum1 : There is a bug in the logic for determining the appropriate npm version based on lockfile_version: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the logic is correct. Ignore me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am checking it but it seems to be npm 8? Are we looking in different place? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
# rubocop:enable Metrics/PerceivedComplexity | ||
|
||
sig { params(yarn_lock: T.nilable(DependencyFile)).returns(Integer) } | ||
def self.yarn_version_numeric(yarn_lock) | ||
lockfile_content = yarn_lock&.content | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1089,7 +1089,7 @@ | |
let(:previous_requirements) { requirements } | ||
|
||
it "raises a helpful error" do | ||
expect { updated_npm_lock_content }.to raise_error(Dependabot::DependencyFileNotResolvable) | ||
expect { updated_npm_lock_content }.to raise_error(Dependabot::InconsistentRegistryResponse) | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error being thrown has changed because the Example lockfile: {
"name": "DependencyNotFound",
"version": "0.36.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "DependencyNotFound",
"version": "0.36.1",
"license": "MIT",
"dependencies": {},
"devDependencies": {
"eslint": "^9.5.0"
},
"engines": {
"node": ">=12"
}
}
}
} |
||
end | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to define these constants here as integers and in npm_and_yarn/lib/dependabot/npm_and_yarn/package_manager.rb as strings? Could they be defined in one location and business logic makes the necessary conversion of number<->string as needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventually, we’ll need to refactor this to define all versions as strings instead of integers. However, this cleanup will take place after we finish removing all feature flags related to versioning and deprecate the old ecosystem metrics collection. For now, the specs require the method to return an integer, and this change is outside the scope of the current issue.