Skip to content
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

fix(types): fix several suppressed type errors in src/utils #7068

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion src/commands/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ export default class BaseCommand extends Command {
const authLink = `${webUI}/authorize?response_type=ticket&ticket=${ticket.id}`

log(`Opening ${authLink}`)
// @ts-expect-error TS(2345) FIXME: Argument of type '{ url: string; }' is not assigna... Remove this comment to see the full error message
await openBrowser({ url: authLink })

const accessToken = await pollForToken({
Expand Down
30 changes: 11 additions & 19 deletions src/commands/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,24 +207,14 @@
return { deployFolderStat, functionsFolderStat }
}

/**
* @param {object} config
* @param {string} config.deployFolder
* @param {*} config.site
* @returns
*/
// @ts-expect-error TS(7031) FIXME: Binding element 'deployFolder' implicitly has an '... Remove this comment to see the full error message
const getDeployFilesFilter = ({ deployFolder, site }) => {
const getDeployFilesFilter = ({ deployFolder, site }: { deployFolder: string; site: { root: string } }) => {
// site.root === deployFolder can happen when users run `netlify deploy --dir .`
// in that specific case we don't want to publish the repo node_modules
// when site.root !== deployFolder the behaviour matches our buildbot
const skipNodeModules = site.root === deployFolder

/**
* @param {string} filename
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'filename' implicitly has an 'any' type.
return (filename) => {
return (filename: string) => {
// TODO(serhalp) Per types, this should not be possible. Confirm and remove this check.
if (filename == null) {
return false
}
Expand Down Expand Up @@ -269,16 +259,20 @@
log('Deploying to main site URL...')
}

// @ts-expect-error TS(7006) FIXME: Parameter 'actual' implicitly has an 'any' type.
const hasErrorMessage = (actual, expected) => {
const hasErrorMessage = (actual: unknown, expected: string): boolean => {
if (typeof actual === 'string') {
return actual.includes(expected)
}
return false
}

// @ts-expect-error TS(7031) FIXME: Binding element 'error_' implicitly has an 'any' t... Remove this comment to see the full error message
const reportDeployError = ({ error_, failAndExit }) => {
const reportDeployError = ({
error_,
failAndExit,
}: {
error_: (Error & { json?: Record<string, unknown>; status?: number }) | any
failAndExit: (errorOrMessage: Error | string) => void
}) => {
switch (true) {
case error_.name === 'JSONHTTPError': {
const message = error_?.json?.message ?? ''
Expand Down Expand Up @@ -488,8 +482,7 @@

const { headers } = await parseAllHeaders({
configHeaders: config.headers,
// @ts-expect-error TS(2322) FIXME: Type 'string' is not assignable to type 'never'.
headersFiles: [headersPath],

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Unit (macOS-latest, 22.x)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / verify-docs

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Unit (ubuntu-latest, 22.x)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Unit (macOS-latest, 18.14.0)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Unit (ubuntu-latest, 18.14.0)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / E2E (ubuntu-latest, *)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / E2E (ubuntu-latest, 18.14.0)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 22, 1/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 22, 2/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 22, 4/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 20.12.2, 4/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 20.12.2, 4/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 18.17.0, 4/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 20.12.2, 3/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 18.17.0, 1/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 22, 4/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 20.12.2, 3/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 22, 3/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 18.17.0, 3/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 22, 3/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 20.12.2, 2/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 20.12.2, 1/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 22, 1/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 18.17.0, 2/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / E2E (macOS-latest, 18.14.0)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 20.12.2, 1/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / E2E (macOS-latest, *)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 22, 2/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 20.12.2, 2/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Unit (windows-latest, 18.14.0)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (windows-latest, 20.12.2, 3/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (windows-latest, 20.12.2, 2/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / E2E Windows tests (windows-latest, 18.14.0)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (windows-latest, 20.12.2, 1/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / E2E Windows tests (windows-latest, 20.12.2)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration (windows-latest, 20.12.2, 4/4)

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / Integration test windows latest node23 specific

Type 'string' is not assignable to type 'never'.

Check failure on line 485 in src/commands/deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / E2E Windows tests (windows-latest, 22)

Type 'string' is not assignable to type 'never'.
minimal: true,
})

Expand Down Expand Up @@ -906,7 +899,6 @@

if (options.open) {
const urlToOpen = deployToProduction ? results.siteUrl : results.deployUrl
// @ts-expect-error TS(2345) FIXME: Argument of type '{ url: any; }' is not assignable... Remove this comment to see the full error message
await openBrowser({ url: urlToOpen })
exit()
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/functions/functions-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ const handleAddonDidInstall = async ({ addonCreated, addonDidInstall, command, f
return
}

await injectEnvVariables({
injectEnvVariables({
devConfig: { ...config.dev },
env: command.netlify.cachedConfig.env,
site: command.netlify.site,
Expand Down
1 change: 0 additions & 1 deletion src/commands/open/open-admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const openAdmin = async (options: OptionValues, command: BaseCommand) =>
log(`Opening "${siteInfo.name}" site admin UI:`)
log(`> ${siteInfo.admin_url}`)

// @ts-expect-error TS(2345) FIXME: Argument of type '{ url: any; }' is not assignable... Remove this comment to see the full error message
await openBrowser({ url: siteInfo.admin_url })
exit()
}
1 change: 0 additions & 1 deletion src/commands/open/open-site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const openSite = async (options: OptionValues, command: BaseCommand) => {
log(`Opening "${siteInfo.name}" site url:`)
log(`> ${url}`)

// @ts-expect-error TS(2345) FIXME: Argument of type '{ url: any; }' is not assignable... Remove this comment to see the full error message
await openBrowser({ url })
exit()
}
4 changes: 2 additions & 2 deletions src/commands/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { NetlifyAPI } from 'netlify'
import type { FrameworksAPIPaths } from "../utils/frameworks-api.ts";
import type StateConfig from '../utils/state-config.js'
import type { Account } from "../utils/types.ts";
import type { CachedConfig } from "../utils/build.js"
import type { CachedConfig } from "../lib/build.js"

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type $TSFixMe = any;
Expand All @@ -15,7 +15,7 @@ export type NetlifySite = {
configPath?: string
siteId?: string
get id(): string | undefined
set id(id: string): void
set id(id: string)
}

type PatchedConfig = NetlifyTOML & Pick<NetlifyConfig, 'images'> & {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/functions/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ interface GetFunctionsServerOptions {
functionsRegistry: FunctionsRegistry
siteUrl: string
siteInfo?: $TSFixMe
accountId: string
accountId?: string | undefined
geoCountry: string
offline: boolean
state: $TSFixMe
Expand Down
83 changes: 38 additions & 45 deletions src/utils/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { supportsBackgroundFunctions } from '../lib/account.js'

import { NETLIFYDEVLOG, chalk, error, log, warn, APIError } from './command-helpers.js'
import { loadDotEnvFiles } from './dot-env.js'
import type { NetlifyAPI } from 'netlify'
import type { SiteInfo } from './types.js'
import { CachedConfig } from '../lib/build.js'
import { NetlifySite } from '../commands/types.js'
import { DevConfig } from '../commands/dev/types.js'

// Possible sources of environment variables. For the purpose of printing log messages only. Order does not matter.
const ENV_VAR_SOURCES = {
Expand Down Expand Up @@ -39,15 +44,13 @@ const ENV_VAR_SOURCES = {
const ERROR_CALL_TO_ACTION =
"Double-check your login status with 'netlify status' or contact support with details of your error."

// @ts-expect-error TS(7031) FIXME: Binding element 'site' implicitly has an 'any' typ... Remove this comment to see the full error message
const validateSiteInfo = ({ site, siteInfo }) => {
const validateSiteInfo = ({ site, siteInfo }: { site: NetlifySite; siteInfo: SiteInfo }): void => {
if (isEmpty(siteInfo)) {
error(`Failed retrieving site information for site ${chalk.yellow(site.id)}. ${ERROR_CALL_TO_ACTION}`)
}
}

// @ts-expect-error TS(7031) FIXME: Binding element 'api' implicitly has an 'any' type... Remove this comment to see the full error message
const getAccounts = async ({ api }) => {
const getAccounts = async ({ api }: { api: NetlifyAPI }) => {
try {
const accounts = await api.listAccountsForUser()
return accounts
Expand All @@ -56,9 +59,9 @@ const getAccounts = async ({ api }) => {
}
}

// @ts-expect-error TS(7031) FIXME: Binding element 'api' implicitly has an 'any' type... Remove this comment to see the full error message
const getAddons = async ({ api, site }) => {
const getAddons = async ({ api, site }: { api: NetlifyAPI; site: NetlifySite }) => {
try {
// @ts-expect-error(serhalp) One of three types is incorrect here (is `site.id` optional?). Dig and fix.
const addons = await api.listServiceInstancesForSite({ siteId: site.id })
return addons
} catch (error_) {
Expand All @@ -70,20 +73,17 @@ const getAddons = async ({ api, site }) => {
}
}

// @ts-expect-error TS(7031) FIXME: Binding element 'addons' implicitly has an 'any' t... Remove this comment to see the full error message
const getAddonsInformation = ({ addons, siteInfo }) => {
type Addons = Awaited<ReturnType<NetlifyAPI['listServiceInstancesForSite']>>
const getAddonsInformation = ({ addons, siteInfo }: { addons: Addons; siteInfo: SiteInfo }) => {
const urls = Object.fromEntries(
// @ts-expect-error TS(7006) FIXME: Parameter 'addon' implicitly has an 'any' type.
addons.map((addon) => [addon.service_slug, `${siteInfo.ssl_url}${addon.service_path}`]),
)
// @ts-expect-error TS(7006) FIXME: Parameter 'addon' implicitly has an 'any' type.
const env = Object.assign({}, ...addons.map((addon) => addon.env))
return { urls, env }
}

// @ts-expect-error TS(7031) FIXME: Binding element 'accounts' implicitly has an 'any'... Remove this comment to see the full error message
const getSiteAccount = ({ accounts, siteInfo }) => {
// @ts-expect-error TS(7006) FIXME: Parameter 'account' implicitly has an 'any' type.
type Accounts = Awaited<ReturnType<NetlifyAPI['listAccountsForUser']>>
const getSiteAccount = ({ accounts, siteInfo }: { accounts: Accounts; siteInfo: SiteInfo }) => {
const siteAccount = accounts.find((account) => account.slug === siteInfo.account_slug)
if (!siteAccount) {
warn(`Could not find account for site '${siteInfo.name}' with account slug '${siteInfo.account_slug}'`)
Expand All @@ -98,17 +98,17 @@ const SYNCHRONOUS_FUNCTION_TIMEOUT = 30
// default 15 minutes for background functions
const BACKGROUND_FUNCTION_TIMEOUT = 900

/**
*
* @param {object} config
* @param {boolean} config.offline
* @param {*} config.api
* @param {*} config.site
* @param {*} config.siteInfo
* @returns
*/
// @ts-expect-error TS(7031) FIXME: Binding element 'api' implicitly has an 'any' type... Remove this comment to see the full error message
export const getSiteInformation = async ({ api, offline, site, siteInfo }) => {
export const getSiteInformation = async ({
api,
offline,
site,
siteInfo,
}: {
api: NetlifyAPI
offline: boolean
site: NetlifySite
siteInfo: SiteInfo
}) => {
if (site.id && !offline) {
validateSiteInfo({ site, siteInfo })
const [accounts, addons] = await Promise.all([getAccounts({ api }), getAddons({ api, site })])
Expand Down Expand Up @@ -142,22 +142,22 @@ export const getSiteInformation = async ({ api, offline, site, siteInfo }) => {
}
}

// @ts-expect-error TS(7006) FIXME: Parameter 'source' implicitly has an 'any' type.
const getEnvSourceName = (source) => {
// @ts-expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
const { name = source, printFn = chalk.green } = ENV_VAR_SOURCES[source] || {}
const getEnvSourceName = (source: string) => {
const { name = source, printFn = chalk.green } = ENV_VAR_SOURCES[source] ?? {}

return printFn(name)
}

/**
* @param {{devConfig: any, env: Record<string, { sources: string[], value: string}>, site: any}} param0
* @returns {Promise<Record<string, { sources: string[], value: string}>>}
*/
// @ts-expect-error TS(7031) FIXME: Binding element 'devConfig' implicitly has an 'any... Remove this comment to see the full error message
export const getDotEnvVariables = async ({ devConfig, env, site }) => {
export const getDotEnvVariables = async ({
devConfig,
env,
site,
}: {
devConfig: DevConfig
env: CachedConfig['env']
site: NetlifySite
}): Promise<Record<string, { sources: string[]; value: string }>> => {
const dotEnvFiles = await loadDotEnvFiles({ envFiles: devConfig.envFiles, projectDir: site.root })
// @ts-expect-error TS(2339) FIXME: Property 'env' does not exist on type '{ warning: ... Remove this comment to see the full error message
dotEnvFiles.forEach(({ env: fileEnv, file }) => {
const newSourceName = `${file} file`

Expand All @@ -169,6 +169,7 @@ export const getDotEnvVariables = async ({ devConfig, env, site }) => {
}

env[key] = {
// @ts-expect-error(serhalp) Something isn't right with these types but it's a can of worms.
sources,
value: fileEnv[key],
}
Expand All @@ -180,20 +181,14 @@ export const getDotEnvVariables = async ({ devConfig, env, site }) => {

/**
* Takes a set of environment variables in the format provided by @netlify/config and injects them into `process.env`
* @param {Record<string, { sources: string[], value: string}>} env
* @return {void}
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'env' implicitly has an 'any' type.
export const injectEnvVariables = (env) => {
export const injectEnvVariables = (env: Record<string, { sources: string[]; value: string }>): void => {
for (const [key, variable] of Object.entries(env)) {
const existsInProcess = process.env[key] !== undefined
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
const [usedSource, ...overriddenSources] = existsInProcess ? ['process', ...variable.sources] : variable.sources
const usedSourceName = getEnvSourceName(usedSource)
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
const isInternal = variable.sources.includes('internal')

// @ts-expect-error TS(7006) FIXME: Parameter 'source' implicitly has an 'any' type.
overriddenSources.forEach((source) => {
const sourceName = getEnvSourceName(source)

Expand All @@ -212,7 +207,6 @@ export const injectEnvVariables = (env) => {
log(`${NETLIFYDEVLOG} Injected ${usedSourceName} env var: ${chalk.yellow(key)}`)
}

// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
process.env[key] = variable.value
}
}
Expand All @@ -234,8 +228,7 @@ export const acquirePort = async ({
return acquiredPort
}

// @ts-expect-error TS(7006) FIXME: Parameter 'fn' implicitly has an 'any' type.
export const processOnExit = (fn) => {
export const processOnExit = (fn: (...args: unknown[]) => void) => {
const signals = ['SIGINT', 'SIGTERM', 'SIGQUIT', 'SIGHUP', 'exit']
signals.forEach((signal) => {
process.on(signal, fn)
Expand Down
50 changes: 32 additions & 18 deletions src/utils/dot-env.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,58 @@
import { readFile } from 'fs/promises'
import path from 'path'

import dotenv from 'dotenv'
import dotenv, { type DotenvParseOutput } from 'dotenv'

import { isFileAsync } from '../lib/fs.js'

import { warn } from './command-helpers.js'

// @ts-expect-error TS(7031) FIXME: Binding element 'envFiles' implicitly has an 'any'... Remove this comment to see the full error message
export const loadDotEnvFiles = async function ({ envFiles, projectDir }) {
const response = await tryLoadDotEnvFiles({ projectDir, dotenvFiles: envFiles })
interface LoadedDotEnvFile {
file: string
env: DotenvParseOutput
}

export const loadDotEnvFiles = async function ({
envFiles,
projectDir,
}: {
envFiles?: string[]
projectDir?: string
}): Promise<LoadedDotEnvFile[]> {
const loadedDotEnvFiles = await tryLoadDotEnvFiles({ projectDir, dotenvFiles: envFiles })

// @ts-expect-error TS(2532) FIXME: Object is possibly 'undefined'.
const filesWithWarning = response.filter((el) => el.warning)
filesWithWarning.forEach((el) => {
// @ts-expect-error TS(2532) FIXME: Object is possibly 'undefined'.
warn(el.warning)
})
loadedDotEnvFiles
.filter((el): el is { warning: string } => 'warning' in el)
.forEach((el) => {
warn(el.warning)
})

// @ts-expect-error TS(2532) FIXME: Object is possibly 'undefined'.
return response.filter((el) => el.file && el.env)
return loadedDotEnvFiles.filter((el): el is LoadedDotEnvFile => 'file' in el && 'env' in el)
}

// in the user configuration, the order is highest to lowest
const defaultEnvFiles = ['.env.development.local', '.env.local', '.env.development', '.env']

// @ts-expect-error TS(7031) FIXME: Binding element 'projectDir' implicitly has an 'an... Remove this comment to see the full error message
export const tryLoadDotEnvFiles = async ({ dotenvFiles = defaultEnvFiles, projectDir }) => {
export const tryLoadDotEnvFiles = async ({
dotenvFiles = defaultEnvFiles,
projectDir,
}: {
dotenvFiles?: string[]
projectDir?: string
}): Promise<Array<LoadedDotEnvFile | { warning: string }>> => {
const results = await Promise.all(
dotenvFiles.map(async (file) => {
const filepath = path.resolve(projectDir, file)
const filepath = path.resolve(projectDir ?? '', file)
try {
const isFile = await isFileAsync(filepath)
if (!isFile) {
return
}
} catch (error) {
return {
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
warning: `Failed reading env variables from file: ${filepath}: ${error.message}`,
warning: `Failed reading env variables from file: ${filepath}: ${
error instanceof Error ? error.message : error?.toString()
}`,
}
}
const content = await readFile(filepath, 'utf-8')
Expand All @@ -48,5 +62,5 @@ export const tryLoadDotEnvFiles = async ({ dotenvFiles = defaultEnvFiles, projec
)

// we return in order of lowest to highest priority
return results.filter(Boolean).reverse()
return results.filter((result): result is LoadedDotEnvFile => result != null).reverse()
}
1 change: 0 additions & 1 deletion src/utils/gh-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export const authWithNetlify = async () => {
})
const url = `${webUI}/cli?${urlParams.toString()}`

// @ts-expect-error TS(2345) FIXME: Argument of type '{ url: string; }' is not assigna... Remove this comment to see the full error message
await openBrowser({ url })

return deferredPromise
Expand Down
Loading
Loading