From a9dff8ddf31456c86d2c12674f045e31b0eabc65 Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Thu, 16 Nov 2023 17:21:05 -0500 Subject: [PATCH] feat: remove extra run of .getSite as it happens in base-command --- src/commands/status/status.mts | 39 ++++++++++++---------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/src/commands/status/status.mts b/src/commands/status/status.mts index 3aae4e470f1..500eb5af9dd 100644 --- a/src/commands/status/status.mts +++ b/src/commands/status/status.mts @@ -12,7 +12,7 @@ import { createStatusHooksCommand } from './status-hooks.mjs' */ // @ts-expect-error TS(7006) FIXME: Parameter 'options' implicitly has an 'any' type. const status = async (options, command) => { - const { api, globalConfig, site } = command.netlify + const { api, globalConfig, site, siteInfo } = command.netlify const current = globalConfig.get('userId') // @ts-expect-error TS(2554) FIXME: Expected 1 arguments, but got 0. const [accessToken] = await getToken() @@ -34,6 +34,7 @@ const status = async (options, command) => { let user try { + // eslint-disable-next-line @typescript-eslint/no-extra-semi ;[accounts, user] = await Promise.all([api.listAccountsForUser(), api.getCurrentUser()]) } catch (error_) { // @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'. @@ -68,23 +69,9 @@ const status = async (options, command) => { warn('Did you run `netlify link` yet?') error(`You don't appear to be in a folder that is linked to a site`) } - let siteData - try { - siteData = await api.getSite({ siteId }) - } catch (error_) { - // unauthorized - // @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'. - if (error_.status === 401) { - warn(`Log in with a different account or re-link to a site you have permission for`) - error(`Not authorized to view the currently linked site (${siteId})`) - } - // missing - // @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'. - if (error_.status === 404) { - error(`The site this folder is linked to can't be found`) - } - // @ts-expect-error TS(2345) FIXME: Argument of type 'unknown' is not assignable to pa... Remove this comment to see the full error message - error(error_) + + if (!siteInfo) { + error(`No site info found for site ${siteId}`) } // Json only logs out if --json flag is passed @@ -92,11 +79,11 @@ const status = async (options, command) => { logJson({ account: cleanAccountData, siteData: { - 'site-name': `${siteData.name}`, + 'site-name': `${siteInfo.name}`, 'config-path': site.configPath, - 'admin-url': siteData.admin_url, - 'site-url': siteData.ssl_url || siteData.url, - 'site-id': siteData.id, + 'admin-url': siteInfo.admin_url, + 'site-url': siteInfo.ssl_url || siteInfo.url, + 'site-id': siteInfo.id, }, }) } @@ -106,11 +93,11 @@ const status = async (options, command) => { ────────────────────┘`) log( prettyjson.render({ - 'Current site': `${siteData.name}`, + 'Current site': `${siteInfo.name}`, 'Netlify TOML': site.configPath, - 'Admin URL': chalk.magentaBright(siteData.admin_url), - 'Site URL': chalk.cyanBright(siteData.ssl_url || siteData.url), - 'Site Id': chalk.yellowBright(siteData.id), + 'Admin URL': chalk.magentaBright(siteInfo.admin_url), + 'Site URL': chalk.cyanBright(siteInfo.ssl_url || siteInfo.url), + 'Site Id': chalk.yellowBright(siteInfo.id), }), ) log()