protected function discoverPackageInstallers(PackageInterface $package, RepositoryManager $repo_manager) {
    $package_name = $package->getName();
    if (!isset($this->packageInstallers[$package_name])) {

      // Initialize the package cache entry to prevent loops.
      $this->packageInstallers[$package_name] = [];
      $installer_paths = &$this->packageInstallers[$package_name];

      // Calculate the installer paths for this package.
      $package_extra = $package->getExtra();
      if (isset($package_extra) && isset($package_extra['installer-paths'])) {
        foreach ($package_extra['installer-paths'] as $path => $values) {
          foreach ($values as $value) {
            $type = explode(':', $value, 2);
            if (count($type) >= 2 && $type[0] === 'type') {
              $installer_paths[$type[1]] = $path;
            }
          }
        }
      }

      $requires = $package->getRequires();
      foreach ($requires as $requirement) {
        if (static::isSystemRequirement($requirement)) {
          continue;
        }
        $required_package = $repo_manager->findPackage($requirement->getTarget(), $requirement->getConstraint());
        if ($required_package) {
          $installer_paths += $this->discoverPackageInstallers($required_package, $repo_manager);
        }
      }
    }

    return $this->packageInstallers[$package_name];
  }