Skip to content

Commit

Permalink
Fixes Yarn Dependabot::SharedHelpers::HelperSubprocessFailed issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sachin-sandhu authored Aug 31, 2024
1 parent 7835cbd commit dc7b8d2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
7 changes: 5 additions & 2 deletions npm_and_yarn/lib/dependabot/npm_and_yarn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ module NpmAndYarn
PACKAGE_NOT_FOUND_PACKAGE_NAME_CAPTURE_SPLIT_REGEX = /(?<=\w)\@/

YARN_PACKAGE_NOT_FOUND_CODE = /npm package "(?<dep>.*)" does not exist under owner "(?<regis>.*)"/
YARN_PACKAGE_NOT_FOUND_CODE_1 = /Couldn't find package "[^@].*(?<dep>.*)" on the "(?<regis>.*)" registry./
YARN_PACKAGE_NOT_FOUND_CODE_2 = /Couldn't find package "[^@].*(?<dep>.*)" required by "(?<pkg>.*)" on the "(?<regis>.*)" registry./ # rubocop:disable Layout/LineLength

YN0035 = T.let({
PACKAGE_NOT_FOUND: %r{(?<package_req>@[\w-]+\/[\w-]+@\S+): Package not found},
Expand Down Expand Up @@ -529,9 +531,10 @@ def self.sanitize_resolvability_message(error_message, dependencies, yarn_lock)
matchfn: nil
},
{
patterns: [YARN_PACKAGE_NOT_FOUND_CODE],
patterns: [YARN_PACKAGE_NOT_FOUND_CODE, YARN_PACKAGE_NOT_FOUND_CODE_1, YARN_PACKAGE_NOT_FOUND_CODE_2],
handler: lambda { |message, _error, _params|
msg = message.match(YARN_PACKAGE_NOT_FOUND_CODE)
msg = message.match(YARN_PACKAGE_NOT_FOUND_CODE) || message.match(YARN_PACKAGE_NOT_FOUND_CODE_1) ||
message.match(YARN_PACKAGE_NOT_FOUND_CODE_2)

Dependabot::DependencyFileNotResolvable.new(msg)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,31 @@
end
end

context "when the error message contains variation of Couldn't find package error" do
let(:error_message) do
"Couldn't find package \"source-map-explorer\" on the \"npm\" registry."
end

it "raises the corresponding error class with the correct message" do
expect { error_handler.handle_group_patterns(error, usage_error_message, { yarn_lock: yarn_lock }) }
.to raise_error(Dependabot::DependencyFileNotResolvable,
"Couldn't find package \"source-map-explorer\" on the \"npm\" registry.")
end
end

context "when the error message contains variation of Couldn't find package error" do
let(:error_message) do
"Couldn't find package \"dl-core-js@^1.0.0\" required by \"[email protected]\" on the \"npm\" registry."
end

it "raises the corresponding error class with the correct message" do
expect { error_handler.handle_group_patterns(error, usage_error_message, { yarn_lock: yarn_lock }) }
.to raise_error(Dependabot::DependencyFileNotResolvable,
"Couldn't find package \"dl-core-js@^1.0.0\" required" \
" by \"[email protected]\" on the \"npm\" registry.")
end
end

context "when the error message contains YARNRC_ENV_NOT_FOUND" do
let(:error_message) do
"Usage Error: Environment variable not found (GITHUB_TOKEN) in /home/dependabot/dependabot-" \
Expand Down

0 comments on commit dc7b8d2

Please sign in to comment.