@@ -7,6 +7,11 @@ import { supportsBackgroundFunctions } from '../lib/account.js'
77
88import { NETLIFYDEVLOG , chalk , error , log , warn , APIError } from './command-helpers.js'
99import { 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'
1015
1116// Possible sources of environment variables. For the purpose of printing log messages only. Order does not matter.
1217const ENV_VAR_SOURCES = {
@@ -39,15 +44,13 @@ const ENV_VAR_SOURCES = {
3944const ERROR_CALL_TO_ACTION =
4045 "Double-check your login status with 'netlify status' or contact support with details of your error."
4146
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 => {
4448 if ( isEmpty ( siteInfo ) ) {
4549 error ( `Failed retrieving site information for site ${ chalk . yellow ( site . id ) } . ${ ERROR_CALL_TO_ACTION } ` )
4650 }
4751}
4852
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 } ) => {
5154 try {
5255 const accounts = await api . listAccountsForUser ( )
5356 return accounts
@@ -56,9 +59,9 @@ const getAccounts = async ({ api }) => {
5659 }
5760}
5861
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 } ) => {
6163 try {
64+ // @ts -expect-error(serhalp) One of three types is incorrect here (is `site.id` optional?). Dig and fix.
6265 const addons = await api . listServiceInstancesForSite ( { siteId : site . id } )
6366 return addons
6467 } catch ( error_ ) {
@@ -70,20 +73,17 @@ const getAddons = async ({ api, site }) => {
7073 }
7174}
7275
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 } ) => {
7578 const urls = Object . fromEntries (
76- // @ts -expect-error TS(7006) FIXME: Parameter 'addon' implicitly has an 'any' type.
7779 addons . map ( ( addon ) => [ addon . service_slug , `${ siteInfo . ssl_url } ${ addon . service_path } ` ] ) ,
7880 )
79- // @ts -expect-error TS(7006) FIXME: Parameter 'addon' implicitly has an 'any' type.
8081 const env = Object . assign ( { } , ...addons . map ( ( addon ) => addon . env ) )
8182 return { urls, env }
8283}
8384
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 } ) => {
8787 const siteAccount = accounts . find ( ( account ) => account . slug === siteInfo . account_slug )
8888 if ( ! siteAccount ) {
8989 warn ( `Could not find account for site '${ siteInfo . name } ' with account slug '${ siteInfo . account_slug } '` )
@@ -98,17 +98,17 @@ const SYNCHRONOUS_FUNCTION_TIMEOUT = 30
9898// default 15 minutes for background functions
9999const BACKGROUND_FUNCTION_TIMEOUT = 900
100100
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+ } ) => {
112112 if ( site . id && ! offline ) {
113113 validateSiteInfo ( { site, siteInfo } )
114114 const [ accounts , addons ] = await Promise . all ( [ getAccounts ( { api } ) , getAddons ( { api, site } ) ] )
@@ -142,22 +142,22 @@ export const getSiteInformation = async ({ api, offline, site, siteInfo }) => {
142142 }
143143}
144144
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 ] ?? { }
149147
150148 return printFn ( name )
151149}
152150
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 } > > => {
159160 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
161161 dotEnvFiles . forEach ( ( { env : fileEnv , file } ) => {
162162 const newSourceName = `${ file } file`
163163
@@ -169,6 +169,7 @@ export const getDotEnvVariables = async ({ devConfig, env, site }) => {
169169 }
170170
171171 env [ key ] = {
172+ // @ts -expect-error(serhalp) Something isn't right with these types but it's a can of worms.
172173 sources,
173174 value : fileEnv [ key ] ,
174175 }
@@ -180,20 +181,14 @@ export const getDotEnvVariables = async ({ devConfig, env, site }) => {
180181
181182/**
182183 * 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 }
185184 */
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 => {
188186 for ( const [ key , variable ] of Object . entries ( env ) ) {
189187 const existsInProcess = process . env [ key ] !== undefined
190- // @ts -expect-error TS(2571) FIXME: Object is of type 'unknown'.
191188 const [ usedSource , ...overriddenSources ] = existsInProcess ? [ 'process' , ...variable . sources ] : variable . sources
192189 const usedSourceName = getEnvSourceName ( usedSource )
193- // @ts -expect-error TS(2571) FIXME: Object is of type 'unknown'.
194190 const isInternal = variable . sources . includes ( 'internal' )
195191
196- // @ts -expect-error TS(7006) FIXME: Parameter 'source' implicitly has an 'any' type.
197192 overriddenSources . forEach ( ( source ) => {
198193 const sourceName = getEnvSourceName ( source )
199194
@@ -212,7 +207,6 @@ export const injectEnvVariables = (env) => {
212207 log ( `${ NETLIFYDEVLOG } Injected ${ usedSourceName } env var: ${ chalk . yellow ( key ) } ` )
213208 }
214209
215- // @ts -expect-error TS(2571) FIXME: Object is of type 'unknown'.
216210 process . env [ key ] = variable . value
217211 }
218212 }
@@ -234,8 +228,7 @@ export const acquirePort = async ({
234228 return acquiredPort
235229}
236230
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 ) => {
239232 const signals = [ 'SIGINT' , 'SIGTERM' , 'SIGQUIT' , 'SIGHUP' , 'exit' ]
240233 signals . forEach ( ( signal ) => {
241234 process . on ( signal , fn )
0 commit comments