private function findPackage($name, RepositoryInterface $repository)
    {
        /** @var PackageInterface[] $packages */
        $packages = $repository->findPackages($name);

        while (!empty($packages) && $packages[0] instanceof AliasPackage) {
            array_shift($packages);
        }

        if (empty($packages)) {
            return null;
        }

        return $packages[0];
    }