Skip to content

Commit

Permalink
feat: remove extra run of .getSite as it happens in base-command (#6181)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahetter authored Nov 16, 2023
1 parent f1b4f05 commit 7ab484b
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions src/commands/status/status.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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'.
Expand Down Expand Up @@ -68,35 +69,21 @@ 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
if (options.json) {
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,
},
})
}
Expand All @@ -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()
Expand Down

2 comments on commit 7ab484b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,396
  • Package size: 404 MB

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,396
  • Package size: 404 MB

Please sign in to comment.