From 398175f0b3fa932018624a7362b4204e950eb71a Mon Sep 17 00:00:00 2001 From: Paulo Castro Date: Fri, 24 Dec 2021 14:45:12 +0000 Subject: [PATCH 1/2] Update balena-sdk to v16.8.1 Update balena-sdk from 16.8.0 to 16.8.1 Change-type: patch --- npm-shrinkwrap.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 1a60f72f..c915b533 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -3955,9 +3955,9 @@ } }, "balena-sdk": { - "version": "16.8.0", - "resolved": "https://registry.npmjs.org/balena-sdk/-/balena-sdk-16.8.0.tgz", - "integrity": "sha512-kch7hhB9PksFsyVOAFyylsQMlv976V11DOwhb41w2JykVKjR9KSNFBfy1wYwYY1Wcp8PWXvj9WxtB0Sd/SW9bQ==", + "version": "16.8.1", + "resolved": "https://registry.npmjs.org/balena-sdk/-/balena-sdk-16.8.1.tgz", + "integrity": "sha512-fSYo/aOGVRj0PhIRla8GRuLhyIecvri8kFFbDu0faUgDDUHfidyfIIUzuTggOc7XKr20WazvjfI4M2uVAqMKww==", "requires": { "@balena/es-version": "^1.0.0", "@types/json-schema": "^7.0.9", diff --git a/package.json b/package.json index cac9f171..319b3907 100644 --- a/package.json +++ b/package.json @@ -208,7 +208,7 @@ "balena-image-manager": "^7.1.1", "balena-preload": "^11.0.0", "balena-release": "^3.2.0", - "balena-sdk": "^16.8.0", + "balena-sdk": "^16.8.1", "balena-semver": "^2.3.0", "balena-settings-client": "^4.0.7", "balena-settings-storage": "^7.0.0", From b2d932afabb9c1ca131c0839397d0492f2f1a272 Mon Sep 17 00:00:00 2001 From: Paulo Castro Date: Fri, 24 Dec 2021 15:02:59 +0000 Subject: [PATCH 2/2] os versions, os download: Replace deprecated version fields Replace deprecated `rawVersion` and `formattedVersion` fields and use alternative overload of `getAvailableOsVersions`. As a result, the word 'recommended' is no longer printed next to any OS versions. Change-type: patch --- lib/commands/os/versions.ts | 8 ++++--- lib/utils/cloud.ts | 44 ++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/commands/os/versions.ts b/lib/commands/os/versions.ts index 6e3a42ac..9130e372 100644 --- a/lib/commands/os/versions.ts +++ b/lib/commands/os/versions.ts @@ -65,9 +65,11 @@ export default class OsVersionsCmd extends Command { OsVersionsCmd, ); - const { getFormattedOsVersions } = await import('../../utils/cloud'); - const vs = await getFormattedOsVersions(params.type, !!options.esr); + const { formatOsVersion, getOsVersions } = await import( + '../../utils/cloud' + ); + const vs = await getOsVersions(params.type, !!options.esr); - console.log(vs.map((v) => v.formattedVersion).join('\n')); + console.log(vs.map((v) => formatOsVersion(v)).join('\n')); } } diff --git a/lib/utils/cloud.ts b/lib/utils/cloud.ts index c4111c9d..540a258b 100644 --- a/lib/utils/cloud.ts +++ b/lib/utils/cloud.ts @@ -225,53 +225,45 @@ async function selectOSVersionFromMenu( deviceType: string, esr: boolean, ): Promise { - const vs = await getFormattedOsVersions(deviceType, esr); + const vs = await getOsVersions(deviceType, esr); const choices = vs.map((v) => ({ - value: v.rawVersion, - name: v.formattedVersion, + value: v.raw_version, + name: formatOsVersion(v), })); return getCliForm().ask({ message: 'Select the OS version:', type: 'list', choices, - default: (vs.find((v) => v.isRecommended) ?? vs[0])?.rawVersion, + default: vs[0]?.raw_version, }); } /** - * Return the output of sdk.models.hostapp.getAvailableOsVersions(), filtered - * regarding ESR or non-ESR versions, and having the `formattedVersion` field - * reformatted for compatibility with the pre-existing output format of the - * `os versions` and `os download` commands. + * Return the output of sdk.models.os.getAvailableOsVersions(), resolving + * device type aliases and filtering with regard to ESR versions. */ -export async function getFormattedOsVersions( +export async function getOsVersions( deviceType: string, esr: boolean, ): Promise { const sdk = getBalenaSdk(); let slug = deviceType; - let versionsByDT: SDK.OsVersionsByDeviceType = - await sdk.models.os.getAvailableOsVersions([slug]); + let versions: SDK.OsVersion[] = await sdk.models.os.getAvailableOsVersions( + slug, + ); // if slug is an alias, fetch the real slug - if (!versionsByDT[slug]?.length) { + if (!versions.length) { // unaliasDeviceType() produces a nice error msg if slug is invalid slug = await unaliasDeviceType(sdk, slug); if (slug !== deviceType) { - versionsByDT = await sdk.models.os.getAvailableOsVersions([slug]); + versions = await sdk.models.os.getAvailableOsVersions(slug); } } - const versions: SDK.OsVersion[] = (versionsByDT[slug] || []) - .filter((v: SDK.OsVersion) => v.osType === (esr ? 'esr' : 'default')) - .map((v: SDK.OsVersion) => { - const i = v.formattedVersion.indexOf(' '); - v.formattedVersion = - i < 0 - ? `v${v.rawVersion}` - : `v${v.rawVersion}${v.formattedVersion.substring(i)}`; - return v; - }); + versions = versions.filter( + (v: SDK.OsVersion) => v.osType === (esr ? 'esr' : 'default'), + ); if (!versions.length) { const vType = esr ? 'ESR versions' : 'versions'; throw new ExpectedError( @@ -280,3 +272,9 @@ export async function getFormattedOsVersions( } return versions; } + +export function formatOsVersion(osVersion: SDK.OsVersion): string { + return osVersion.line + ? `v${osVersion.raw_version} (${osVersion.line})` + : `v${osVersion.raw_version}`; +}