-
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
Fix Dependency File Detection for npm, pnpm, yarn, and bun #11367
Fix Dependency File Detection for npm, pnpm, yarn, and bun #11367
Conversation
da20815
to
370aa3a
Compare
@@ -143,56 +143,56 @@ def package_json | |||
sig { returns(T.nilable(Dependabot::DependencyFile)) } | |||
def shrinkwrap | |||
@shrinkwrap ||= T.let(dependency_files.find do |f| | |||
f.name == NpmPackageManager::SHRINKWRAP_LOCKFILE_NAME | |||
f.name.end_with?(NpmPackageManager::SHRINKWRAP_LOCKFILE_NAME) |
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.
do we want to check for case insensitivity?
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.
I think we are good for case sensitivity. Let me check but file_fetcher is working fine by using case sensitivite namings.
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.
Maybe we can. I can see in file fetcher we are doing following to set name. It may not be small letters.
DependencyFile.new(
name: Pathname.new(filename).cleanpath.to_path,
directory: directory,
type: type,
content: content,
symlink_target: symlink_target,
support_file: in_submodule?(path)
)
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.
Normally we only have problem with lock files where we have following if we can't find file from the directory.
sig { params(filename: String).returns(T.nilable(DependencyFile)) }
def fetch_file_from_parent_directories(filename)
(1..directory.split("/").count).each do |i|
file = fetch_file_with_support(("../" * i) + filename)
return file if file
end
nil
end
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.
can we test and see if it works with PNPM-LOCK.json for example?
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.
Let me try.
const delim = '-----END CERTIFICATE-----' | ||
return raw.replace(/\r\n/g, '\n').split(delim) | ||
.filter(section => section.trim()) | ||
.map(section => section.trimStart() + delim) | ||
} |
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.
The IDE's automatic formatter is adjusting the code indentation to a tabSize of 2 instead of 4, which deviates from our standard indentation style.
@@ -195,7 +195,6 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q | |||
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= | |||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= | |||
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= | |||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= |
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.
Just removed the library because it was causing the following error in go specs
expected "go: github.com/jenkins-x/[email protected] requires\n\tk8s.io/[email protected] requires\n\tcloud.google.com/[email protected] requires\n\[email protected]: unrecognized import path \"go.opencensus.io\": https fetch: Get \"https://go.opencensus.io/?go-get=1\": tls: failed to verify certificate: x509: certificate has expired or is not yet valid: current time 2025-01-22T00:44:17Z is after 2025-01-21T03:43:04Z" to include "go.mod has post-v1 module path"
Diff:
@@ -1,4 +1,7 @@
-go.mod has post-v1 module path
+go: github.com/jenkins-x/[email protected] requires
+ k8s.io/[email protected] requires
+ cloud.google.com/[email protected] requires
+ [email protected]: unrecognized import path "go.opencensus.io": https fetch: Get "https://go.opencensus.io/?go-get=1": tls: failed to verify certificate: x509: certificate has expired or is not yet valid: current time 2025-01-22T00:44:17Z is after 2025-01-21T03:43:04Z
# ./spec/dependabot/go_modules/file_updater/go_mod_updater_spec.rb:558:in `block (4 levels) in <top (required)>'
# /home/dependabot/common/spec/spec_helper.rb:66:in `block (2 levels) in <top (required)>'
# /home/dependabot/dependabot-updater/vendor/ruby/3.3.0/gems/webmock-3.24.0/lib/webmock/rspec.rb:39:in `block (2 levels) in <top (required)>'
af13c47
to
38993e3
Compare
Since the go_modules specs focuses on path validation for |
What are you trying to accomplish?
This PR fixes an issue with detecting dependency files in workspaces when file names include parent directories or relative paths (e.g.,
./../pnpm-lock.yaml
). The previous logic relied solely on exact name matches (==
), which caused package manager detection to fail when no lock file was found.The updated logic uses both
==
andend_with?
checks to improve robustness and ensure compatibility with various file naming conventions.Anything you want to highlight for special attention from reviewers?
npm
,pnpm
,yarn
, andbun
.How will you know you've accomplished your goal?
npm
,pnpm
,yarn
, andbun
).Checklist