From 9f9bafcd38d30dd6709ccef4e83e3917b1df87ed Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Mon, 10 Jun 2024 14:02:55 -0600 Subject: [PATCH] feat: show channel in --available table --- src/commands/update.ts | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/commands/update.ts b/src/commands/update.ts index f67a9b37..88a20807 100644 --- a/src/commands/update.ts +++ b/src/commands/update.ts @@ -1,5 +1,6 @@ import select from '@inquirer/select' import {Args, Command, Flags, ux} from '@oclif/core' +import {got} from 'got' import {basename} from 'node:path' import {sort} from 'semver' import TtyTable from 'tty-table' @@ -57,18 +58,41 @@ export default class UpdateCommand extends Command { const {args, flags} = await this.parse(UpdateCommand) const updater = new Updater(this.config) if (flags.available) { - const [index, localVersions] = await Promise.all([updater.fetchVersionIndex(), updater.findLocalVersions()]) + const [index, localVersions, distTags] = await Promise.all([ + updater.fetchVersionIndex(), + updater.findLocalVersions(), + this.config.pjson.oclif.update?.disableNpmLookup + ? Promise.resolve() + : got + .get(`${this.config.npmRegistry ?? 'https://registry.npmjs.org'}/${this.config.pjson.name}`) + .json<{ + 'dist-tags': Record + }>() + .then((r) => r['dist-tags']), + ]) + + const headers = [ + {align: 'left', value: 'Location'}, + {align: 'left', value: 'Version'}, + ] + + if (distTags) { + headers.push({align: 'left', value: 'Channel'}) + } + + const invertedDistTags = Object.fromEntries(Object.entries(distTags ?? {}).map(([k, v]) => [v, k])) // eslint-disable-next-line new-cap const t = TtyTable( - [ - {align: 'left', value: 'Location'}, - {align: 'left', value: 'Version'}, - ], + headers, sort(Object.keys(index)) .reverse() .map((version) => { const location = localVersions.find((l) => basename(l).startsWith(version)) || index[version] + if (invertedDistTags) { + return [location, version, invertedDistTags[version] ?? ''] + } + return [location, version] }), {compact: true},