Skip to content

Commit 5fd9add

Browse files
authored
fix: mark siteInfo.published_deploy as optional (#7185)
1 parent 5fef8d6 commit 5fd9add

File tree

6 files changed

+61
-68
lines changed

6 files changed

+61
-68
lines changed

eslint_temporary_suppressions.js

-15
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,6 @@ export default [
243243
'@typescript-eslint/no-unnecessary-condition': 'off',
244244
},
245245
},
246-
{
247-
files: ['src/commands/functions/functions-list.ts'],
248-
rules: {
249-
'@typescript-eslint/no-unsafe-assignment': 'off',
250-
'@typescript-eslint/restrict-template-expressions': 'off',
251-
},
252-
},
253246
{
254247
files: ['src/commands/functions/functions-serve.ts'],
255248
rules: {
@@ -431,14 +424,6 @@ export default [
431424
'@typescript-eslint/no-unsafe-member-access': 'off',
432425
},
433426
},
434-
{
435-
files: ['src/commands/status/status.ts'],
436-
rules: {
437-
'@typescript-eslint/no-unsafe-assignment': 'off',
438-
'@typescript-eslint/restrict-template-expressions': 'off',
439-
'@typescript-eslint/ban-ts-comment': 'off',
440-
},
441-
},
442427
{
443428
files: ['src/commands/switch/switch.ts'],
444429
rules: {

src/commands/deploy/deploy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ export const deploy = async (options: OptionValues, command: BaseCommand) => {
841841
return triggerDeploy({ api, options, siteData, siteId })
842842
}
843843

844-
const deployToProduction = options.prod || (options.prodIfUnlocked && !siteData.published_deploy.locked)
844+
const deployToProduction = options.prod || (options.prodIfUnlocked && !(siteData.published_deploy?.locked ?? false))
845845

846846
let results = {} as Awaited<ReturnType<typeof prepAndRunDeploy>>
847847

src/commands/functions/functions-list.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,29 @@ const normalizeFunction = function (
2626
export const functionsList = async (options: OptionValues, command: BaseCommand) => {
2727
const { config, relConfigFilePath, siteInfo } = command.netlify
2828

29-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- XXX(serhalp): fixed in stacked PR.
30-
const deploy = siteInfo.published_deploy ?? {}
31-
// @ts-expect-error(serhalp) Investigate. Either dead code or a type error in the API client package.
32-
const deployedFunctions = deploy.available_functions || []
29+
// @ts-expect-error FIXME(serhalp): Investigate. This is either dead code or a type error in the API client package.
30+
const deployedFunctions = (siteInfo.published_deploy?.available_functions as DeployedFunction[] | undefined) ?? []
3331

3432
const functionsDir = getFunctionsDir({ options, config })
3533

3634
if (typeof functionsDir === 'undefined') {
3735
log('Functions directory is undefined')
3836
log(`Please verify that 'functions.directory' is set in your Netlify configuration file ${relConfigFilePath}`)
3937
log('Refer to https://ntl.fyi/file-based-build-config for more information')
40-
exit(1)
38+
return exit(1)
4139
}
4240

4341
const functions = await getFunctions(functionsDir)
4442
const normalizedFunctions = functions.map(normalizeFunction.bind(null, deployedFunctions))
4543

4644
if (normalizedFunctions.length === 0) {
4745
log(`No functions found in ${functionsDir}`)
48-
exit()
46+
return exit()
4947
}
5048

5149
if (options.json) {
5250
logJson(normalizedFunctions)
53-
exit()
51+
return exit()
5452
}
5553

5654
// Make table

src/commands/status/status.ts

+22-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
import clean from 'clean-deep'
2-
import { OptionValues } from 'commander'
2+
import type { OptionValues } from 'commander'
33
import 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

817
export 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({

src/recipes/blobs-migrate/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ export const run = async ({ args, command }: Options) => {
2323
const { api, siteInfo } = command.netlify
2424
const clientOptions = {
2525
apiURL: `${api.scheme}://${api.host}`,
26-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- XXX(serhalp): fixed in stacked PR.
27-
siteID: siteInfo.id ?? '',
26+
siteID: siteInfo.id,
2827
token: api.accessToken ?? '',
2928
}
3029

src/utils/types.ts

+32-30
Original file line numberDiff line numberDiff line change
@@ -129,36 +129,38 @@ export interface SiteInfo {
129129
}
130130
skip: boolean
131131
}
132-
published_deploy: {
133-
admin_url: string
134-
branch: string
135-
build_id: string
136-
commit_ref: string
137-
commit_url: string
138-
context: string
139-
created_at: string
140-
deploy_ssl_url: string
141-
deploy_url: string
142-
draft: boolean
143-
error_message: string
144-
id: string
145-
locked: boolean
146-
name: string
147-
published_at: string
148-
required: string[]
149-
required_functions: string[]
150-
review_id: number
151-
review_url: string
152-
screenshot_url: string
153-
site_id: string
154-
skipped: boolean
155-
ssl_url: string
156-
state: string
157-
title: string
158-
updated_at: string
159-
url: string
160-
user_id: string
161-
}
132+
published_deploy:
133+
| {
134+
admin_url: string
135+
branch: string
136+
build_id: string
137+
commit_ref: string
138+
commit_url: string
139+
context: string
140+
created_at: string
141+
deploy_ssl_url: string
142+
deploy_url: string
143+
draft: boolean
144+
error_message: string
145+
id: string
146+
locked: boolean
147+
name: string
148+
published_at: string
149+
required: string[]
150+
required_functions: string[]
151+
review_id: number
152+
review_url: string
153+
screenshot_url: string
154+
site_id: string
155+
skipped: boolean
156+
ssl_url: string
157+
state: string
158+
title: string
159+
updated_at: string
160+
url: string
161+
user_id: string
162+
}
163+
| undefined
162164
screenshot_url: string
163165
session_id: string
164166
ssl: boolean

0 commit comments

Comments
 (0)