Skip to content

refactor(deploy): improve types to avoid extraneous runtime check #7220

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 3 commits into from
Apr 23, 2025
Merged
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
36 changes: 16 additions & 20 deletions src/commands/deploy/deploy.ts
Original file line number Diff line number Diff line change
@@ -811,21 +811,21 @@ export const deploy = async (options: DeployOptionValues, command: BaseCommand)

await command.authenticate(options.auth)

let siteId = site.id || options.site

let initialSiteData: SiteInfo | undefined
let newSiteData!: SiteInfo
if (siteId && !isEmpty(siteInfo)) {

const hasSiteData = (site.id || options.site) && !isEmpty(siteInfo)

if (hasSiteData) {
initialSiteData = siteInfo
siteId = initialSiteData.id
} else {
log("This folder isn't linked to a site yet")
const NEW_SITE = '+ Create & configure a new site'
const EXISTING_SITE = 'Link this directory to an existing site'

const initializeOpts = [EXISTING_SITE, NEW_SITE]
const initializeOpts = [EXISTING_SITE, NEW_SITE] as const

const { initChoice } = await inquirer.prompt([
const { initChoice } = await inquirer.prompt<{ initChoice: typeof initializeOpts[number] }>([
{
type: 'list',
name: 'initChoice',
@@ -834,25 +834,21 @@ export const deploy = async (options: DeployOptionValues, command: BaseCommand)
},
])
// create site or search for one
if (initChoice === NEW_SITE) {
newSiteData = await sitesCreate({}, command)
site.id = newSiteData.id
siteId = site.id
} else if (initChoice === EXISTING_SITE) {
newSiteData = await link({}, command)
site.id = newSiteData?.id
siteId = site.id
switch (initChoice) {
case NEW_SITE:
newSiteData = await sitesCreate({}, command)
site.id = newSiteData.id
break
case EXISTING_SITE:
newSiteData = await link({}, command)
site.id = newSiteData.id
break
}
}

if (!siteId) {
return logAndThrowError(
"Unable to determine which site to deploy to. Make sure you've run 'netlify link' or that you're specifying your desired site using the '--site' option.",
)
}

// This is the best I could come up with to make TS happy with the complexities above.
const siteData = initialSiteData ?? newSiteData
const siteId = siteData.id

if (options.trigger) {
return triggerDeploy({ api, options, siteData, siteId })