chore(core): fix docs release script for single version (#31060)

Fixes an issue with the docs release script when there is only one
version in a particular major version.

The `npm show [version] --json` command normally returns an array of
strings, but if there is only one version returned, it tries to be
helpful by returning a string instead. This fix normalizes that
behavior.
This commit is contained in:
Isaac Mann 2025-05-05 20:34:01 -04:00 committed by GitHub
parent 382bd6eb2c
commit 72a0ef541f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,11 +11,14 @@ const currentVersion = process.env.GITHUB_REF_NAME || '';
console.log(`Comparing ${currentVersion} to npm versions`);
const majorVersion = major(currentVersion);
const releasedVersions: string[] = JSON.parse(
let releasedVersions: string[] = JSON.parse(
execSync(`npm show nx@^${majorVersion} version --json`, {
windowsHide: false,
}).toString()
);
if (typeof releasedVersions === 'string') {
releasedVersions = [releasedVersions];
}
const latestVersion = maxSatisfying(releasedVersions, `^${majorVersion}`);