@@ -2,17 +2,23 @@ import { type Stats } from 'fs'
2
2
import { stat } from 'fs/promises'
3
3
import { basename , resolve } from 'path'
4
4
5
- import { type NetlifyConfig , runCoreSteps } from '@netlify/build'
6
- import { type OptionValues } from 'commander'
5
+ import { type NetlifyConfig , type OnPostBuild , runCoreSteps } from '@netlify/build'
7
6
import inquirer from 'inquirer'
8
7
import isEmpty from 'lodash/isEmpty.js'
9
8
import isObject from 'lodash/isObject.js'
10
9
import { parseAllHeaders } from '@netlify/headers-parser'
11
10
import { parseAllRedirects } from '@netlify/redirect-parser'
11
+ import type { NetlifyAPI } from 'netlify'
12
12
import prettyjson from 'prettyjson'
13
13
14
14
import { 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'
16
22
import { getBootstrapURL } from '../../lib/edge-functions/bootstrap.js'
17
23
import { featureFlags as edgeFunctionsFeatureFlags } from '../../lib/edge-functions/consts.js'
18
24
import { normalizeFunctionsConfig } from '../../lib/functions/config.js'
@@ -42,9 +48,19 @@ import { link } from '../link/link.js'
42
48
import { sitesCreate } from '../sites/sites-create.js'
43
49
import type { $TSFixMe } from '../types.js'
44
50
import { SiteInfo } from '../../utils/types.js'
51
+ import type { DeployOptionValues } from './option_values.js'
45
52
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
+ } ) => {
48
64
try {
49
65
const siteBuild = await api . createSiteBuild ( { siteId } )
50
66
if ( options . json ) {
@@ -80,7 +96,7 @@ const getDeployFolder = async ({
80
96
} : {
81
97
command : BaseCommand
82
98
config : $TSFixMe
83
- options : OptionValues
99
+ options : DeployOptionValues
84
100
site : $TSFixMe
85
101
siteData : $TSFixMe
86
102
} ) : Promise < string > => {
@@ -150,7 +166,7 @@ const getFunctionsFolder = ({
150
166
workingDir,
151
167
} : {
152
168
config : $TSFixMe
153
- options : OptionValues
169
+ options : DeployOptionValues
154
170
site : $TSFixMe
155
171
siteData : $TSFixMe
156
172
/** The process working directory where the build command is executed */
@@ -347,7 +363,7 @@ const uploadDeployBlobs = async ({
347
363
} : {
348
364
cachedConfig : CachedConfig
349
365
deployId : string
350
- options : OptionValues
366
+ options : DeployOptionValues
351
367
packagePath ?: string
352
368
silent : boolean
353
369
siteId : string
@@ -540,18 +556,21 @@ const runDeploy = async ({
540
556
}
541
557
}
542
558
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
+ } ) => {
555
574
if ( ! options . build ) {
556
575
return { }
557
576
}
@@ -782,7 +801,7 @@ const prepAndRunDeploy = async ({
782
801
return results
783
802
}
784
803
785
- export const deploy = async ( options : OptionValues , command : BaseCommand ) => {
804
+ export const deploy = async ( options : DeployOptionValues , command : BaseCommand ) => {
786
805
const { workingDir } = command
787
806
const { api, site, siteInfo } = command . netlify
788
807
const alias = options . alias || options . branch
@@ -834,6 +853,12 @@ export const deploy = async (options: OptionValues, command: BaseCommand) => {
834
853
}
835
854
}
836
855
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
+
837
862
// This is the best I could come up with to make TS happy with the complexities above.
838
863
const siteData = initialSiteData ?? newSiteData
839
864
0 commit comments