Skip to content

Commit

Permalink
[engsys] Fix min-max version script error due to npm breaking change (A…
Browse files Browse the repository at this point in the history
…zure#21948)

Previously `npm view <packageName> versions --json` returns an array even when
the result only contains one version.  In latest NPM version in NodeJS v16 the
result is now a string, which isn't expected by `semver` APIs.

This PR wraps the single string result with an array.
  • Loading branch information
jeremymeng authored May 20, 2022
1 parent 83e13d8 commit 47dd3d6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions eng/tools/dependency-testing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,16 @@ async function findAppropriateVersion(package, packageJsonDepVersion, repoRoot,
if (isUtility) {
return packageJsonDepVersion;
}
let allNPMVersions = await getVersions(package);
if (allNPMVersions) {
let allNPMVersionsString = await getVersions(package);
if (allNPMVersionsString) {
let allVersions = JSON.parse(allNPMVersionsString);
if (typeof allVersions === "string") {
allVersions = [ allVersions ];
}
console.log(versionType);
if (versionType === "min") {
let minVersion = await semver.minSatisfying(
JSON.parse(allNPMVersions),
allVersions,
packageJsonDepVersion
);
if (minVersion) {
Expand All @@ -207,7 +211,7 @@ async function findAppropriateVersion(package, packageJsonDepVersion, repoRoot,
} else if (versionType === "max") {
console.log("calling semver max satisfying");
let maxVersion = await semver.maxSatisfying(
JSON.parse(allNPMVersions),
allVersions,
packageJsonDepVersion
);
if (maxVersion) {
Expand Down

0 comments on commit 47dd3d6

Please sign in to comment.