@@ -2,17 +2,23 @@ import { type Stats } from 'fs'
22import { stat } from 'fs/promises'
33import { basename , resolve } from 'path'
44
5- import { type NetlifyConfig , runCoreSteps } from '@netlify/build'
6- import { type OptionValues } from 'commander'
5+ import { type NetlifyConfig , type OnPostBuild , runCoreSteps } from '@netlify/build'
76import inquirer from 'inquirer'
87import isEmpty from 'lodash/isEmpty.js'
98import isObject from 'lodash/isObject.js'
109import { parseAllHeaders } from '@netlify/headers-parser'
1110import { parseAllRedirects } from '@netlify/redirect-parser'
11+ import type { NetlifyAPI } from 'netlify'
1212import prettyjson from 'prettyjson'
1313
1414import { cancelDeploy } from '../../lib/api.js'
15- import { type CachedConfig , getRunBuildOptions , runBuild } from '../../lib/build.js'
15+ import {
16+ type CachedConfig ,
17+ type DefaultConfig ,
18+ type PatchedHandlerType ,
19+ getRunBuildOptions ,
20+ runBuild ,
21+ } from '../../lib/build.js'
1622import { getBootstrapURL } from '../../lib/edge-functions/bootstrap.js'
1723import { featureFlags as edgeFunctionsFeatureFlags } from '../../lib/edge-functions/consts.js'
1824import { normalizeFunctionsConfig } from '../../lib/functions/config.js'
@@ -42,9 +48,19 @@ import { link } from '../link/link.js'
4248import { sitesCreate } from '../sites/sites-create.js'
4349import type { $TSFixMe } from '../types.js'
4450import { SiteInfo } from '../../utils/types.js'
51+ import type { DeployOptionValues } from './option_values.js'
4552
46- // @ts -expect-error TS(7031) FIXME: Binding element 'api' implicitly has an 'any' type... Remove this comment to see the full error message
47- const triggerDeploy = async ( { api, options, siteData, siteId } ) => {
53+ const triggerDeploy = async ( {
54+ api,
55+ options,
56+ siteData,
57+ siteId,
58+ } : {
59+ api : NetlifyAPI
60+ options : DeployOptionValues
61+ siteData : { name : string }
62+ siteId : string
63+ } ) => {
4864 try {
4965 const siteBuild = await api . createSiteBuild ( { siteId } )
5066 if ( options . json ) {
@@ -80,7 +96,7 @@ const getDeployFolder = async ({
8096} : {
8197 command : BaseCommand
8298 config : $TSFixMe
83- options : OptionValues
99+ options : DeployOptionValues
84100 site : $TSFixMe
85101 siteData : $TSFixMe
86102} ) : Promise < string > => {
@@ -150,7 +166,7 @@ const getFunctionsFolder = ({
150166 workingDir,
151167} : {
152168 config : $TSFixMe
153- options : OptionValues
169+ options : DeployOptionValues
154170 site : $TSFixMe
155171 siteData : $TSFixMe
156172 /** The process working directory where the build command is executed */
@@ -347,7 +363,7 @@ const uploadDeployBlobs = async ({
347363} : {
348364 cachedConfig : CachedConfig
349365 deployId : string
350- options : OptionValues
366+ options : DeployOptionValues
351367 packagePath ?: string
352368 silent : boolean
353369 siteId : string
@@ -540,18 +556,21 @@ const runDeploy = async ({
540556 }
541557}
542558
543- /**
544- *
545- * @param {object } config
546- * @param {* } config.cachedConfig
547- * @param {string } [config.packagePath]
548- * @param {* } config.deployHandler
549- * @param {string } config.currentDir
550- * @param {import('commander').OptionValues } config.options The options of the command
551- * @returns
552- */
553- // @ts -expect-error TS(7031) FIXME: Binding element 'cachedConfig' implicitly has an '... Remove this comment to see the full error message
554- const handleBuild = async ( { cachedConfig, currentDir, defaultConfig, deployHandler, options, packagePath } ) => {
559+ const handleBuild = async ( {
560+ cachedConfig,
561+ currentDir,
562+ defaultConfig,
563+ deployHandler,
564+ options,
565+ packagePath,
566+ } : {
567+ cachedConfig : CachedConfig
568+ currentDir : string
569+ defaultConfig ?: DefaultConfig | undefined
570+ deployHandler ?: PatchedHandlerType < OnPostBuild > | undefined
571+ options : DeployOptionValues
572+ packagePath : string | undefined
573+ } ) => {
555574 if ( ! options . build ) {
556575 return { }
557576 }
@@ -782,7 +801,7 @@ const prepAndRunDeploy = async ({
782801 return results
783802}
784803
785- export const deploy = async ( options : OptionValues , command : BaseCommand ) => {
804+ export const deploy = async ( options : DeployOptionValues , command : BaseCommand ) => {
786805 const { workingDir } = command
787806 const { api, site, siteInfo } = command . netlify
788807 const alias = options . alias || options . branch
@@ -834,6 +853,12 @@ export const deploy = async (options: OptionValues, command: BaseCommand) => {
834853 }
835854 }
836855
856+ if ( ! siteId ) {
857+ return logAndThrowError (
858+ "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." ,
859+ )
860+ }
861+
837862 // This is the best I could come up with to make TS happy with the complexities above.
838863 const siteData = initialSiteData ?? newSiteData
839864
0 commit comments