Skip to content

fix: mark siteInfo.published_deploy as optional #7185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions eslint_temporary_suppressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,6 @@ export default [
'@typescript-eslint/no-unnecessary-condition': 'off',
},
},
{
files: ['src/commands/functions/functions-list.ts'],
rules: {
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
},
},
{
files: ['src/commands/functions/functions-serve.ts'],
rules: {
Expand Down Expand Up @@ -431,14 +424,6 @@ export default [
'@typescript-eslint/no-unsafe-member-access': 'off',
},
},
{
files: ['src/commands/status/status.ts'],
rules: {
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
},
},
{
files: ['src/commands/switch/switch.ts'],
rules: {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ export const deploy = async (options: OptionValues, command: BaseCommand) => {
return triggerDeploy({ api, options, siteData, siteId })
}

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

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

Expand Down
12 changes: 5 additions & 7 deletions src/commands/functions/functions-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,29 @@ const normalizeFunction = function (
export const functionsList = async (options: OptionValues, command: BaseCommand) => {
const { config, relConfigFilePath, siteInfo } = command.netlify

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

const functionsDir = getFunctionsDir({ options, config })

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

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

if (normalizedFunctions.length === 0) {
log(`No functions found in ${functionsDir}`)
exit()
return exit()
}

if (options.json) {
logJson(normalizedFunctions)
exit()
return exit()
}

// Make table
Expand Down
35 changes: 22 additions & 13 deletions src/commands/status/status.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
import clean from 'clean-deep'
import { OptionValues } from 'commander'
import type { OptionValues } from 'commander'
import prettyjson from 'prettyjson'

import { chalk, logAndThrowError, exit, getToken, log, logJson, warn, APIError } from '../../utils/command-helpers.js'
import BaseCommand from '../base-command.js'
import {
chalk,
logAndThrowError,
exit,
getToken,
log,
logJson,
warn,
type APIError,
} from '../../utils/command-helpers.js'
import type BaseCommand from '../base-command.js'

export const status = async (options: OptionValues, command: BaseCommand) => {
const { accounts, api, globalConfig, site, siteInfo } = command.netlify
const current = globalConfig.get('userId')
const currentUserId = globalConfig.get('userId') as string | undefined
const [accessToken] = await getToken()

if (!accessToken) {
log(`Not logged in. Please log in to see site status.`)
log()
log('Login with "netlify login" command')
exit()
return exit()
}

const siteId = site.id
Expand All @@ -37,16 +46,21 @@ export const status = async (options: OptionValues, command: BaseCommand) => {
}
}

const ghuser = command.netlify.globalConfig.get(`users.${current}.auth.github.user`)
const ghuser =
currentUserId != null
? (globalConfig.get(`users.${currentUserId}.auth.github.user`) as string | undefined)
: undefined
const accountData = {
Name: user.full_name,
Email: user.email,
GitHub: ghuser,
Teams: accounts.map(({ name }) => name),
}

// @ts-expect-error
const cleanAccountData = clean(accountData)
const cleanAccountData =
// TODO(serhalp) `deep-clean` type declaration is invalid (this is obscured by `skipLibCheck`). Open a PR or use
// another lib.
(clean as unknown as <T extends Record<string | number | symbol, unknown>>(obj: T) => Partial<T>)(accountData)

log(prettyjson.render(cleanAccountData))

Expand All @@ -55,11 +69,6 @@ export const status = async (options: OptionValues, command: BaseCommand) => {
return logAndThrowError(`You don't appear to be in a folder that is linked to a site`)
}

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- XXX(serhalp): fixed in stacked PR.
if (!siteInfo) {
return logAndThrowError(`No site info found for site ${siteId}`)
}

// Json only logs out if --json flag is passed
if (options.json) {
logJson({
Expand Down
3 changes: 1 addition & 2 deletions src/recipes/blobs-migrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ export const run = async ({ args, command }: Options) => {
const { api, siteInfo } = command.netlify
const clientOptions = {
apiURL: `${api.scheme}://${api.host}`,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- XXX(serhalp): fixed in stacked PR.
siteID: siteInfo.id ?? '',
siteID: siteInfo.id,
token: api.accessToken ?? '',
}

Expand Down
62 changes: 32 additions & 30 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,36 +129,38 @@ export interface SiteInfo {
}
skip: boolean
}
published_deploy: {
admin_url: string
branch: string
build_id: string
commit_ref: string
commit_url: string
context: string
created_at: string
deploy_ssl_url: string
deploy_url: string
draft: boolean
error_message: string
id: string
locked: boolean
name: string
published_at: string
required: string[]
required_functions: string[]
review_id: number
review_url: string
screenshot_url: string
site_id: string
skipped: boolean
ssl_url: string
state: string
title: string
updated_at: string
url: string
user_id: string
}
published_deploy:
| {
admin_url: string
branch: string
build_id: string
commit_ref: string
commit_url: string
context: string
created_at: string
deploy_ssl_url: string
deploy_url: string
draft: boolean
error_message: string
id: string
locked: boolean
name: string
published_at: string
required: string[]
required_functions: string[]
review_id: number
review_url: string
screenshot_url: string
site_id: string
skipped: boolean
ssl_url: string
state: string
title: string
updated_at: string
url: string
user_id: string
}
| undefined
screenshot_url: string
session_id: string
ssl: boolean
Expand Down
Loading