@@ -7,6 +7,11 @@ import { supportsBackgroundFunctions } from '../lib/account.js'
7
7
8
8
import { NETLIFYDEVLOG , chalk , error , log , warn , APIError } from './command-helpers.js'
9
9
import { loadDotEnvFiles } from './dot-env.js'
10
+ import type { NetlifyAPI } from 'netlify'
11
+ import type { SiteInfo } from './types.js'
12
+ import { CachedConfig } from '../lib/build.js'
13
+ import { NetlifySite } from '../commands/types.js'
14
+ import { DevConfig } from '../commands/dev/types.js'
10
15
11
16
// Possible sources of environment variables. For the purpose of printing log messages only. Order does not matter.
12
17
const ENV_VAR_SOURCES = {
@@ -39,15 +44,13 @@ const ENV_VAR_SOURCES = {
39
44
const ERROR_CALL_TO_ACTION =
40
45
"Double-check your login status with 'netlify status' or contact support with details of your error."
41
46
42
- // @ts -expect-error TS(7031) FIXME: Binding element 'site' implicitly has an 'any' typ... Remove this comment to see the full error message
43
- const validateSiteInfo = ( { site, siteInfo } ) => {
47
+ const validateSiteInfo = ( { site, siteInfo } : { site : NetlifySite ; siteInfo : SiteInfo } ) : void => {
44
48
if ( isEmpty ( siteInfo ) ) {
45
49
error ( `Failed retrieving site information for site ${ chalk . yellow ( site . id ) } . ${ ERROR_CALL_TO_ACTION } ` )
46
50
}
47
51
}
48
52
49
- // @ts -expect-error TS(7031) FIXME: Binding element 'api' implicitly has an 'any' type... Remove this comment to see the full error message
50
- const getAccounts = async ( { api } ) => {
53
+ const getAccounts = async ( { api } : { api : NetlifyAPI } ) => {
51
54
try {
52
55
const accounts = await api . listAccountsForUser ( )
53
56
return accounts
@@ -56,9 +59,9 @@ const getAccounts = async ({ api }) => {
56
59
}
57
60
}
58
61
59
- // @ts -expect-error TS(7031) FIXME: Binding element 'api' implicitly has an 'any' type... Remove this comment to see the full error message
60
- const getAddons = async ( { api, site } ) => {
62
+ const getAddons = async ( { api, site } : { api : NetlifyAPI ; site : NetlifySite } ) => {
61
63
try {
64
+ // @ts -expect-error(serhalp) One of three types is incorrect here (is `site.id` optional?). Dig and fix.
62
65
const addons = await api . listServiceInstancesForSite ( { siteId : site . id } )
63
66
return addons
64
67
} catch ( error_ ) {
@@ -70,20 +73,17 @@ const getAddons = async ({ api, site }) => {
70
73
}
71
74
}
72
75
73
- // @ts -expect-error TS(7031) FIXME: Binding element 'addons' implicitly has an 'any' t... Remove this comment to see the full error message
74
- const getAddonsInformation = ( { addons, siteInfo } ) => {
76
+ type Addons = Awaited < ReturnType < NetlifyAPI [ 'listServiceInstancesForSite' ] > >
77
+ const getAddonsInformation = ( { addons, siteInfo } : { addons : Addons ; siteInfo : SiteInfo } ) => {
75
78
const urls = Object . fromEntries (
76
- // @ts -expect-error TS(7006) FIXME: Parameter 'addon' implicitly has an 'any' type.
77
79
addons . map ( ( addon ) => [ addon . service_slug , `${ siteInfo . ssl_url } ${ addon . service_path } ` ] ) ,
78
80
)
79
- // @ts -expect-error TS(7006) FIXME: Parameter 'addon' implicitly has an 'any' type.
80
81
const env = Object . assign ( { } , ...addons . map ( ( addon ) => addon . env ) )
81
82
return { urls, env }
82
83
}
83
84
84
- // @ts -expect-error TS(7031) FIXME: Binding element 'accounts' implicitly has an 'any'... Remove this comment to see the full error message
85
- const getSiteAccount = ( { accounts, siteInfo } ) => {
86
- // @ts -expect-error TS(7006) FIXME: Parameter 'account' implicitly has an 'any' type.
85
+ type Accounts = Awaited < ReturnType < NetlifyAPI [ 'listAccountsForUser' ] > >
86
+ const getSiteAccount = ( { accounts, siteInfo } : { accounts : Accounts ; siteInfo : SiteInfo } ) => {
87
87
const siteAccount = accounts . find ( ( account ) => account . slug === siteInfo . account_slug )
88
88
if ( ! siteAccount ) {
89
89
warn ( `Could not find account for site '${ siteInfo . name } ' with account slug '${ siteInfo . account_slug } '` )
@@ -98,17 +98,17 @@ const SYNCHRONOUS_FUNCTION_TIMEOUT = 30
98
98
// default 15 minutes for background functions
99
99
const BACKGROUND_FUNCTION_TIMEOUT = 900
100
100
101
- /**
102
- *
103
- * @param { object } config
104
- * @param { boolean } config.offline
105
- * @param { * } config.api
106
- * @param { * } config.site
107
- * @param { * } config.siteInfo
108
- * @returns
109
- */
110
- // @ts -expect-error TS(7031) FIXME: Binding element 'api' implicitly has an 'any' type... Remove this comment to see the full error message
111
- export const getSiteInformation = async ( { api , offline , site , siteInfo } ) => {
101
+ export const getSiteInformation = async ( {
102
+ api ,
103
+ offline ,
104
+ site ,
105
+ siteInfo ,
106
+ } : {
107
+ api : NetlifyAPI
108
+ offline : boolean
109
+ site : NetlifySite
110
+ siteInfo : SiteInfo
111
+ } ) => {
112
112
if ( site . id && ! offline ) {
113
113
validateSiteInfo ( { site, siteInfo } )
114
114
const [ accounts , addons ] = await Promise . all ( [ getAccounts ( { api } ) , getAddons ( { api, site } ) ] )
@@ -142,22 +142,22 @@ export const getSiteInformation = async ({ api, offline, site, siteInfo }) => {
142
142
}
143
143
}
144
144
145
- // @ts -expect-error TS(7006) FIXME: Parameter 'source' implicitly has an 'any' type.
146
- const getEnvSourceName = ( source ) => {
147
- // @ts -expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
148
- const { name = source , printFn = chalk . green } = ENV_VAR_SOURCES [ source ] || { }
145
+ const getEnvSourceName = ( source : string ) => {
146
+ const { name = source , printFn = chalk . green } = ENV_VAR_SOURCES [ source ] ?? { }
149
147
150
148
return printFn ( name )
151
149
}
152
150
153
- /**
154
- * @param {{devConfig: any, env: Record<string, { sources: string[], value: string}>, site: any} } param0
155
- * @returns {Promise<Record<string, { sources: string[], value: string}>> }
156
- */
157
- // @ts -expect-error TS(7031) FIXME: Binding element 'devConfig' implicitly has an 'any... Remove this comment to see the full error message
158
- export const getDotEnvVariables = async ( { devConfig, env, site } ) => {
151
+ export const getDotEnvVariables = async ( {
152
+ devConfig,
153
+ env,
154
+ site,
155
+ } : {
156
+ devConfig : DevConfig
157
+ env : CachedConfig [ 'env' ]
158
+ site : NetlifySite
159
+ } ) : Promise < Record < string , { sources : string [ ] ; value : string } > > => {
159
160
const dotEnvFiles = await loadDotEnvFiles ( { envFiles : devConfig . envFiles , projectDir : site . root } )
160
- // @ts -expect-error TS(2339) FIXME: Property 'env' does not exist on type '{ warning: ... Remove this comment to see the full error message
161
161
dotEnvFiles . forEach ( ( { env : fileEnv , file } ) => {
162
162
const newSourceName = `${ file } file`
163
163
@@ -169,6 +169,7 @@ export const getDotEnvVariables = async ({ devConfig, env, site }) => {
169
169
}
170
170
171
171
env [ key ] = {
172
+ // @ts -expect-error(serhalp) Something isn't right with these types but it's a can of worms.
172
173
sources,
173
174
value : fileEnv [ key ] ,
174
175
}
@@ -180,20 +181,14 @@ export const getDotEnvVariables = async ({ devConfig, env, site }) => {
180
181
181
182
/**
182
183
* Takes a set of environment variables in the format provided by @netlify/config and injects them into `process.env`
183
- * @param {Record<string, { sources: string[], value: string}> } env
184
- * @return {void }
185
184
*/
186
- // @ts -expect-error TS(7006) FIXME: Parameter 'env' implicitly has an 'any' type.
187
- export const injectEnvVariables = ( env ) => {
185
+ export const injectEnvVariables = ( env : Record < string , { sources : string [ ] ; value : string } > ) : void => {
188
186
for ( const [ key , variable ] of Object . entries ( env ) ) {
189
187
const existsInProcess = process . env [ key ] !== undefined
190
- // @ts -expect-error TS(2571) FIXME: Object is of type 'unknown'.
191
188
const [ usedSource , ...overriddenSources ] = existsInProcess ? [ 'process' , ...variable . sources ] : variable . sources
192
189
const usedSourceName = getEnvSourceName ( usedSource )
193
- // @ts -expect-error TS(2571) FIXME: Object is of type 'unknown'.
194
190
const isInternal = variable . sources . includes ( 'internal' )
195
191
196
- // @ts -expect-error TS(7006) FIXME: Parameter 'source' implicitly has an 'any' type.
197
192
overriddenSources . forEach ( ( source ) => {
198
193
const sourceName = getEnvSourceName ( source )
199
194
@@ -212,7 +207,6 @@ export const injectEnvVariables = (env) => {
212
207
log ( `${ NETLIFYDEVLOG } Injected ${ usedSourceName } env var: ${ chalk . yellow ( key ) } ` )
213
208
}
214
209
215
- // @ts -expect-error TS(2571) FIXME: Object is of type 'unknown'.
216
210
process . env [ key ] = variable . value
217
211
}
218
212
}
@@ -234,8 +228,7 @@ export const acquirePort = async ({
234
228
return acquiredPort
235
229
}
236
230
237
- // @ts -expect-error TS(7006) FIXME: Parameter 'fn' implicitly has an 'any' type.
238
- export const processOnExit = ( fn ) => {
231
+ export const processOnExit = ( fn : ( ...args : unknown [ ] ) => void ) => {
239
232
const signals = [ 'SIGINT' , 'SIGTERM' , 'SIGQUIT' , 'SIGHUP' , 'exit' ]
240
233
signals . forEach ( ( signal ) => {
241
234
process . on ( signal , fn )
0 commit comments