Skip to content

Commit 47dd3d6

Browse files
authored
[engsys] Fix min-max version script error due to npm breaking change (Azure#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.
1 parent 83e13d8 commit 47dd3d6

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

eng/tools/dependency-testing/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,16 @@ async function findAppropriateVersion(package, packageJsonDepVersion, repoRoot,
185185
if (isUtility) {
186186
return packageJsonDepVersion;
187187
}
188-
let allNPMVersions = await getVersions(package);
189-
if (allNPMVersions) {
188+
let allNPMVersionsString = await getVersions(package);
189+
if (allNPMVersionsString) {
190+
let allVersions = JSON.parse(allNPMVersionsString);
191+
if (typeof allVersions === "string") {
192+
allVersions = [ allVersions ];
193+
}
190194
console.log(versionType);
191195
if (versionType === "min") {
192196
let minVersion = await semver.minSatisfying(
193-
JSON.parse(allNPMVersions),
197+
allVersions,
194198
packageJsonDepVersion
195199
);
196200
if (minVersion) {
@@ -207,7 +211,7 @@ async function findAppropriateVersion(package, packageJsonDepVersion, repoRoot,
207211
} else if (versionType === "max") {
208212
console.log("calling semver max satisfying");
209213
let maxVersion = await semver.maxSatisfying(
210-
JSON.parse(allNPMVersions),
214+
allVersions,
211215
packageJsonDepVersion
212216
);
213217
if (maxVersion) {

0 commit comments

Comments
 (0)