Skip to content

Commit

Permalink
fix(@angular/cli): handle packages with no version
Browse files Browse the repository at this point in the history
In some cases pacote will return undefined as `version` which resulted in `Cannot convert undefined or null to object`.

Closes #26337

(cherry picked from commit bec9458)
  • Loading branch information
alan-agius4 committed Nov 15, 2023
1 parent 5623c19 commit 5267e60
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/angular/cli/src/utilities/package-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ export async function fetchPackageMetadata(
...(registry ? { registry } : {}),
});

if (!response.versions) {
// While pacote type declares that versions cannot be undefined this is not the case.
response.versions = {};
}

// Normalize the response
const metadata: PackageMetadata = {
...response,
Expand Down Expand Up @@ -312,6 +317,13 @@ export async function getNpmPackageJson(
fullMetadata: true,
...npmrc,
...(registry ? { registry } : {}),
}).then((response) => {
// While pacote type declares that versions cannot be undefined this is not the case.
if (!response.versions) {
response.versions = {};
}

return response;
});

npmPackageJsonCache.set(packageName, response);
Expand Down

0 comments on commit 5267e60

Please sign in to comment.