11import clean from 'clean-deep'
2- import { OptionValues } from 'commander'
2+ import type { OptionValues } from 'commander'
33import prettyjson from 'prettyjson'
44
5- import { chalk , logAndThrowError , exit , getToken , log , logJson , warn , APIError } from '../../utils/command-helpers.js'
6- import BaseCommand from '../base-command.js'
5+ import {
6+ chalk ,
7+ logAndThrowError ,
8+ exit ,
9+ getToken ,
10+ log ,
11+ logJson ,
12+ warn ,
13+ type APIError ,
14+ } from '../../utils/command-helpers.js'
15+ import type BaseCommand from '../base-command.js'
716
817export const status = async ( options : OptionValues , command : BaseCommand ) => {
918 const { accounts, api, globalConfig, site, siteInfo } = command . netlify
10- const current = globalConfig . get ( 'userId' )
19+ const currentUserId = globalConfig . get ( 'userId' ) as string | undefined
1120 const [ accessToken ] = await getToken ( )
1221
1322 if ( ! accessToken ) {
1423 log ( `Not logged in. Please log in to see site status.` )
1524 log ( )
1625 log ( 'Login with "netlify login" command' )
17- exit ( )
26+ return exit ( )
1827 }
1928
2029 const siteId = site . id
@@ -37,16 +46,21 @@ export const status = async (options: OptionValues, command: BaseCommand) => {
3746 }
3847 }
3948
40- const ghuser = command . netlify . globalConfig . get ( `users.${ current } .auth.github.user` )
49+ const ghuser =
50+ currentUserId != null
51+ ? ( globalConfig . get ( `users.${ currentUserId } .auth.github.user` ) as string | undefined )
52+ : undefined
4153 const accountData = {
4254 Name : user . full_name ,
4355 Email : user . email ,
4456 GitHub : ghuser ,
4557 Teams : accounts . map ( ( { name } ) => name ) ,
4658 }
4759
48- // @ts -expect-error
49- const cleanAccountData = clean ( accountData )
60+ const cleanAccountData =
61+ // TODO(serhalp) `deep-clean` type declaration is invalid (this is obscured by `skipLibCheck`). Open a PR or use
62+ // another lib.
63+ ( clean as unknown as < T extends Record < string | number | symbol , unknown > > ( obj : T ) => Partial < T > ) ( accountData )
5064
5165 log ( prettyjson . render ( cleanAccountData ) )
5266
@@ -55,11 +69,6 @@ export const status = async (options: OptionValues, command: BaseCommand) => {
5569 return logAndThrowError ( `You don't appear to be in a folder that is linked to a site` )
5670 }
5771
58- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- XXX(serhalp): fixed in stacked PR.
59- if ( ! siteInfo ) {
60- return logAndThrowError ( `No site info found for site ${ siteId } ` )
61- }
62-
6372 // Json only logs out if --json flag is passed
6473 if ( options . json ) {
6574 logJson ( {
0 commit comments