Skip to content

Commit

Permalink
Fix Corepack install failure by activating local package manager fall…
Browse files Browse the repository at this point in the history
…back (#11484)
  • Loading branch information
kbukum1 authored Feb 4, 2025
1 parent 605f4a7 commit 3508888
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions npm_and_yarn/lib/dependabot/npm_and_yarn/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ def self.install(name, version, env: {})
# Attempt to activate the local version of the package manager
sig { params(name: String).void }
def self.fallback_to_local_version(name)
return "Corepack does not support #{name}" unless corepack_supported_package_manager?(name)

Dependabot.logger.info("Falling back to activate the currently installed version of #{name}.")

# Fetch the currently installed version directly from the environment
Expand Down
13 changes: 9 additions & 4 deletions npm_and_yarn/lib/dependabot/npm_and_yarn/package_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,15 @@ def install(name, version)

Dependabot.logger.info("Installing \"#{name}@#{version}\"")

SharedHelpers.run_shell_command(
"corepack install #{name}@#{version} --global --cache-only",
fingerprint: "corepack install <name>@<version> --global --cache-only"
)
begin
SharedHelpers.run_shell_command(
"corepack install #{name}@#{version} --global --cache-only",
fingerprint: "corepack install <name>@<version> --global --cache-only"
)
rescue SharedHelpers::HelperSubprocessFailed => e
Dependabot.logger.error("Error installing #{name}@#{version}: #{e.message}")
Helpers.fallback_to_local_version(name)
end
end

sig { params(name: T.nilable(String)).returns(String) }
Expand Down

0 comments on commit 3508888

Please sign in to comment.