From 9eb8dc0133baaba61d213448122dbb2a7a9609a2 Mon Sep 17 00:00:00 2001 From: Lukas Holzer Date: Wed, 20 Dec 2023 16:22:39 +0100 Subject: [PATCH] refactor: refactor typescript types from build-info and related parts (#6269) --- src/commands/functions/functions-create.ts | 4 - src/commands/lm/lm-setup.ts | 2 - src/commands/main.ts | 2 - src/commands/sites/sites-create-template.ts | 5 +- src/lib/exec-fetcher.ts | 2 - src/lib/functions/local-proxy.ts | 4 +- src/lib/functions/runtimes/go/index.ts | 3 - .../runtimes/js/builders/netlify-lambda.ts | 2 - src/lib/functions/runtimes/rust/index.ts | 2 - src/utils/banner.ts | 5 +- src/utils/build-info.ts | 84 ++++++++----------- src/utils/execa.ts | 7 +- src/utils/feature-flags.ts | 9 +- src/utils/init/utils.ts | 17 ++-- src/utils/live-tunnel.ts | 2 - src/utils/lm/requirements.ts | 5 -- src/utils/sites/utils.ts | 3 +- src/utils/telemetry/report-error.ts | 2 - src/utils/telemetry/telemetry.ts | 31 ++----- 19 files changed, 57 insertions(+), 134 deletions(-) diff --git a/src/commands/functions/functions-create.ts b/src/commands/functions/functions-create.ts index 709e34bfda7..d452d063886 100644 --- a/src/commands/functions/functions-create.ts +++ b/src/commands/functions/functions-create.ts @@ -21,7 +21,6 @@ import { fileExistsAsync } from '../../lib/fs.js' import { getAddons, getCurrentAddon, getSiteData } from '../../utils/addons/prepare.js' import { NETLIFYDEVERR, NETLIFYDEVLOG, NETLIFYDEVWARN, chalk, error, log } from '../../utils/command-helpers.js' import { getDotEnvVariables, injectEnvVariables } from '../../utils/dev.js' -// @ts-expect-error TS(7034) FIXME: Variable 'execa' implicitly has type 'any' in some... Remove this comment to see the full error message import execa from '../../utils/execa.js' import { readRepoURL, validateRepoURL } from '../../utils/read-repo-url.js' import BaseCommand from '../base-command.js' @@ -441,7 +440,6 @@ const installDeps = async ({ functionPackageJson, functionPath, functionsDir }) // of keeping that file in the function directory and running `npm install` // from there. if (!sitePackageJson) { - // @ts-expect-error TS(7005) FIXME: Variable 'execa' implicitly has an 'any' type. await execa('npm', ['i', ...npmInstallFlags], { cwd: functionPath }) return @@ -453,12 +451,10 @@ const installDeps = async ({ functionPackageJson, functionPath, functionsDir }) const npmInstallPath = path.dirname(sitePackageJson) if (dependencies.length !== 0) { - // @ts-expect-error TS(7005) FIXME: Variable 'execa' implicitly has an 'any' type. await execa('npm', ['i', ...dependencies, '--save', ...npmInstallFlags], { cwd: npmInstallPath }) } if (devDependencies.length !== 0) { - // @ts-expect-error TS(7005) FIXME: Variable 'execa' implicitly has an 'any' type. await execa('npm', ['i', ...devDependencies, '--save-dev', ...npmInstallFlags], { cwd: npmInstallPath }) } diff --git a/src/commands/lm/lm-setup.ts b/src/commands/lm/lm-setup.ts index 4d4b054bf7b..409b0fad854 100644 --- a/src/commands/lm/lm-setup.ts +++ b/src/commands/lm/lm-setup.ts @@ -2,7 +2,6 @@ import { OptionValues } from 'commander' import { Listr } from 'listr2' import { error } from '../../utils/command-helpers.js' -// @ts-expect-error TS(7034) FIXME: Variable 'execa' implicitly has type 'any' in some... Remove this comment to see the full error message import execa from '../../utils/execa.js' import { installPlatform } from '../../utils/lm/install.js' import { checkHelperVersion } from '../../utils/lm/requirements.js' @@ -53,7 +52,6 @@ const configureLFSURL = async function (siteId, api) { const siteInfo = await api.getSite({ siteId }) const url = `https://${siteInfo.id_domain}/.netlify/large-media` - // @ts-expect-error TS(7005) FIXME: Variable 'execa' implicitly has an 'any' type. return execa('git', ['config', '-f', '.lfsconfig', 'lfs.url', url]) } diff --git a/src/commands/main.ts b/src/commands/main.ts index bbc864ab23b..c475ed6e2ef 100644 --- a/src/commands/main.ts +++ b/src/commands/main.ts @@ -7,7 +7,6 @@ import { closest } from 'fastest-levenshtein' import inquirer from 'inquirer' import { BANG, chalk, error, exit, log, NETLIFY_CYAN, USER_AGENT, warn } from '../utils/command-helpers.js' -// @ts-expect-error TS(7034) FIXME: Variable 'execa' implicitly has type 'any' in some... Remove this comment to see the full error message import execa from '../utils/execa.js' import getGlobalConfig from '../utils/get-global-config.js' import getPackageJson from '../utils/get-package-json.js' @@ -177,7 +176,6 @@ const mainCommand = async function (options, command) { error(`Run ${NETLIFY_CYAN(`${command.name()} help`)} for a list of available commands.`) } - // @ts-expect-error TS(7005) FIXME: Variable 'execa' implicitly has an 'any' type. await execa(process.argv[0], [process.argv[1], suggestion], { stdio: 'inherit' }) } diff --git a/src/commands/sites/sites-create-template.ts b/src/commands/sites/sites-create-template.ts index 69b481a20e7..19d693436b3 100644 --- a/src/commands/sites/sites-create-template.ts +++ b/src/commands/sites/sites-create-template.ts @@ -6,7 +6,6 @@ import parseGitHubUrl from 'parse-github-url' import { render } from 'prettyjson' import { chalk, error, getTerminalLink, log, logJson, warn } from '../../utils/command-helpers.js' -// @ts-expect-error TS(7034) FIXME: Variable 'execa' implicitly has type 'any' in some... Remove this comment to see the full error message import execa from '../../utils/execa.js' import getRepoData from '../../utils/get-repo-data.js' import { getGitHubToken } from '../../utils/init/config-github.js' @@ -117,7 +116,7 @@ export const sitesCreateTemplate = async (repository: string, options: OptionVal const { name: nameFlag } = options let site - let repoResp + let repoResp: Awaited> // Allow the user to reenter site name if selected one isn't available // @ts-expect-error TS(7006) FIXME: Parameter 'name' implicitly has an 'any' type. @@ -207,9 +206,7 @@ export const sitesCreateTemplate = async (repository: string, options: OptionVal }) if (cloneConfirm) { log() - // @ts-expect-error TS(7005) FIXME: Variable 'execa' implicitly has an 'any' type. await execa('git', ['clone', repoResp.clone_url, `${repoResp.name}`]) - // @ts-expect-error TS(2532) FIXME: Object is possibly 'undefined'. log(`🚀 Repository cloned successfully. You can find it under the ${chalk.magenta(repoResp.name)} folder`) } diff --git a/src/lib/exec-fetcher.ts b/src/lib/exec-fetcher.ts index a4059145cb4..7461173c07b 100644 --- a/src/lib/exec-fetcher.ts +++ b/src/lib/exec-fetcher.ts @@ -6,7 +6,6 @@ import { fetchLatest, fetchVersion, newerVersion, updateAvailable } from 'gh-rel import isExe from 'isexe' import { NETLIFYDEVWARN, error, getTerminalLink, log } from '../utils/command-helpers.js' -// @ts-expect-error TS(7034) FIXME: Variable 'execa' implicitly has type 'any' in some... Remove this comment to see the full error message import execa from '../utils/execa.js' const isWindows = () => process.platform === 'win32' @@ -58,7 +57,6 @@ export const shouldFetchLatestVersion = async ({ return true } - // @ts-expect-error TS(7005) FIXME: Variable 'execa' implicitly has an 'any' type. const { stdout } = await execa(execPath, execArgs) if (!stdout) { diff --git a/src/lib/functions/local-proxy.ts b/src/lib/functions/local-proxy.ts index 8a00c1d1355..927ff767ae3 100644 --- a/src/lib/functions/local-proxy.ts +++ b/src/lib/functions/local-proxy.ts @@ -3,7 +3,6 @@ import { stdout } from 'process' // @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module '@net... Remove this comment to see the full error message import { getBinaryPath as getFunctionsProxyPath } from '@netlify/local-functions-proxy' -// @ts-expect-error TS(7034) FIXME: Variable 'execa' implicitly has type 'any' in some... Remove this comment to see the full error message import execa from '../../utils/execa.js' // @ts-expect-error TS(7031) FIXME: Binding element 'binaryPath' implicitly has an 'an... Remove this comment to see the full error message @@ -39,10 +38,9 @@ export const runFunctionsProxy = ({ binaryPath, context, directory, event, name, '--timeout', `${timeout}s`, ] - // @ts-expect-error TS(7005) FIXME: Variable 'execa' implicitly has an 'any' type. const proxyProcess = execa(functionsProxyPath, parameters) - proxyProcess.stderr.pipe(stdout) + proxyProcess.stderr?.pipe(stdout) return proxyProcess } diff --git a/src/lib/functions/runtimes/go/index.ts b/src/lib/functions/runtimes/go/index.ts index f654c4f5ff3..08a2549ea8a 100644 --- a/src/lib/functions/runtimes/go/index.ts +++ b/src/lib/functions/runtimes/go/index.ts @@ -3,7 +3,6 @@ import { platform } from 'process' import { temporaryFile } from 'tempy' -// @ts-expect-error TS(7034) FIXME: Variable 'execa' implicitly has type 'any' in some... Remove this comment to see the full error message import execa from '../../../../utils/execa.js' import { runFunctionsProxy } from '../../local-proxy.js' @@ -14,7 +13,6 @@ export const name = 'go' // @ts-expect-error TS(7031) FIXME: Binding element 'binaryPath' implicitly has an 'an... Remove this comment to see the full error message const build = async ({ binaryPath, functionDirectory }) => { try { - // @ts-expect-error TS(7005) FIXME: Variable 'execa' implicitly has an 'any' type. await execa('go', ['build', '-o', binaryPath], { cwd: functionDirectory }) return { binaryPath, srcFiles: [functionDirectory] } @@ -34,7 +32,6 @@ const build = async ({ binaryPath, functionDirectory }) => { // @ts-expect-error TS(7031) FIXME: Binding element 'cwd' implicitly has an 'any' type... Remove this comment to see the full error message const checkGoInstallation = async ({ cwd }) => { try { - // @ts-expect-error TS(7005) FIXME: Variable 'execa' implicitly has an 'any' type. await execa('go', ['version'], { cwd }) return true diff --git a/src/lib/functions/runtimes/js/builders/netlify-lambda.ts b/src/lib/functions/runtimes/js/builders/netlify-lambda.ts index db0634dd7de..536d7f15fd2 100644 --- a/src/lib/functions/runtimes/js/builders/netlify-lambda.ts +++ b/src/lib/functions/runtimes/js/builders/netlify-lambda.ts @@ -3,7 +3,6 @@ import { resolve } from 'path' import { program } from 'commander' -// @ts-expect-error TS(7034) FIXME: Variable 'execa' implicitly has type 'any' in some... Remove this comment to see the full error message import execa from '../../../../../utils/execa.js' import { fileExistsAsync } from '../../../../fs.js' import { memoizedBuild } from '../../../memoized-build.js' @@ -36,7 +35,6 @@ export const detectNetlifyLambda = async function ({ packageJson } = {}) { const srcFiles = [resolve(functionDirectories[0])] const yarnExists = await fileExistsAsync('yarn.lock') - // @ts-expect-error TS(7005) FIXME: Variable 'execa' implicitly has an 'any' type. const buildCommand = () => execa(yarnExists ? 'yarn' : 'npm', ['run', key]) return { diff --git a/src/lib/functions/runtimes/rust/index.ts b/src/lib/functions/runtimes/rust/index.ts index 940e5cbe00d..55cfb25fe0a 100644 --- a/src/lib/functions/runtimes/rust/index.ts +++ b/src/lib/functions/runtimes/rust/index.ts @@ -5,7 +5,6 @@ import { platform } from 'process' import { findUp } from 'find-up' import toml from 'toml' -// @ts-expect-error TS(7034) FIXME: Variable 'execa' implicitly has type 'any' in some... Remove this comment to see the full error message import execa from '../../../../utils/execa.js' import { SERVE_FUNCTIONS_FOLDER } from '../../../../utils/functions/functions.js' import { getPathInProject } from '../../../settings.js' @@ -24,7 +23,6 @@ const build = async ({ func }) => { const binaryName = `${crateName}${isWindows ? '.exe' : ''}` const binaryPath = join(targetDirectory, 'debug', binaryName) - // @ts-expect-error TS(7005) FIXME: Variable 'execa' implicitly has an 'any' type. await execa('cargo', ['build', '--target-dir', targetDirectory], { cwd: functionDirectory, }) diff --git a/src/utils/banner.ts b/src/utils/banner.ts index 5085f46f385..bd8e735b084 100644 --- a/src/utils/banner.ts +++ b/src/utils/banner.ts @@ -2,9 +2,8 @@ import boxen from 'boxen' import { chalk, log, NETLIFYDEVLOG } from './command-helpers.js' -// @ts-expect-error TS(7031) FIXME: Binding element 'url' implicitly has an 'any' type... Remove this comment to see the full error message -export const printBanner = ({ url }) => { - const banner = chalk.bold(`${NETLIFYDEVLOG} Server now ready on ${url}`) +export const printBanner = (options: { url: string }): void => { + const banner = chalk.bold(`${NETLIFYDEVLOG} Server now ready on ${options.url}`) log( boxen(banner, { diff --git a/src/utils/build-info.ts b/src/utils/build-info.ts index 870a874e45d..ae2dd8fb548 100644 --- a/src/utils/build-info.ts +++ b/src/utils/build-info.ts @@ -1,16 +1,18 @@ +import { Settings } from '@netlify/build-info' import fuzzy from 'fuzzy' import inquirer from 'inquirer' +import BaseCommand from '../commands/base-command.js' + import { chalk, log } from './command-helpers.js' /** * Filters the inquirer settings based on the input - * @param {ReturnType} scriptInquirerOptions - * @param {string} input */ -// @ts-expect-error TS(7006) FIXME: Parameter 'scriptInquirerOptions' implicitly has a... Remove this comment to see the full error message -const filterSettings = function (scriptInquirerOptions, input) { - // @ts-expect-error TS(7006) FIXME: Parameter 'scriptInquirerOption' implicitly has an... Remove this comment to see the full error message +const filterSettings = function ( + scriptInquirerOptions: ReturnType, + input: string, +) { const filterOptions = scriptInquirerOptions.map((scriptInquirerOption) => scriptInquirerOption.name) // TODO: remove once https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1394 is fixed // eslint-disable-next-line unicorn/no-array-method-this-argument @@ -18,19 +20,13 @@ const filterSettings = function (scriptInquirerOptions, input) { const filteredSettingNames = new Set( filteredSettings.map((filteredSetting) => (input ? filteredSetting.string : filteredSetting)), ) - // @ts-expect-error TS(7006) FIXME: Parameter 't' implicitly has an 'any' type. return scriptInquirerOptions.filter((t) => filteredSettingNames.has(t.name)) } -/** @typedef {import('@netlify/build-info').Settings} Settings */ - /** - * @param {Settings[]} settings - * @param {'dev' | 'build'} type The type of command (dev or build) + * Formats the settings to present it as an array for the inquirer input so that it can choose one */ -// @ts-expect-error TS(7006) FIXME: Parameter 'settings' implicitly has an 'any' type. -const formatSettingsArrForInquirer = function (settings, type = 'dev') { - // @ts-expect-error TS(7006) FIXME: Parameter 'setting' implicitly has an 'any' type. +const formatSettingsArrForInquirer = function (settings: Settings[], type = 'dev') { return settings.map((setting) => { const cmd = type === 'dev' ? setting.devCommand : setting.buildCommand return { @@ -42,14 +38,31 @@ const formatSettingsArrForInquirer = function (settings, type = 'dev') { } /** - * Uses @netlify/build-info to detect the dev settings and port based on the framework + * Detects and filters the build setting for a project and a command + */ +export async function detectBuildSettings(command: BaseCommand): Promise { + const { project, workspacePackage } = command + const buildSettings = await project.getBuildSettings(project.workspace ? workspacePackage : '') + return buildSettings + .filter((setting) => { + if (project.workspace && project.relativeBaseDirectory && setting.packagePath) { + return project.relativeBaseDirectory.startsWith(setting.packagePath) + } + return true + }) + .filter((setting) => setting.devCommand) +} + +/** + * Uses `@netlify/build-info` to detect the dev settings and port based on the framework * and the build system that is used. - * @param {import('../commands/base-command.js').default} command - * @param {'dev' | 'build'} type The type of command (dev or build) - * @returns {Promise} + * @param command The base command + * @param type The type of command (dev or build) */ -// @ts-expect-error TS(7006) FIXME: Parameter 'command' implicitly has an 'any' type. -export const detectFrameworkSettings = async (command, type = 'dev') => { +export const detectFrameworkSettings = async ( + command: BaseCommand, + type: 'dev' | 'build' = 'dev', +): Promise => { const { relConfigFilePath } = command.netlify const settings = await detectBuildSettings(command) if (settings.length === 1) { @@ -57,16 +70,14 @@ export const detectFrameworkSettings = async (command, type = 'dev') => { } if (settings.length > 1) { - /** multiple matching detectors, make the user choose */ + // multiple matching detectors, make the user choose const scriptInquirerOptions = formatSettingsArrForInquirer(settings, type) - /** @type {{chosenSettings: Settings}} */ - const { chosenSettings } = await inquirer.prompt({ + const { chosenSettings } = await inquirer.prompt<{ chosenSettings: Settings }>({ name: 'chosenSettings', message: `Multiple possible ${type} commands found`, - // @ts-expect-error TS(2769) FIXME: No overload matches this call. + // @ts-expect-error is not known by the types as it uses the autocomplete plugin type: 'autocomplete', - // @ts-expect-error TS(7006) FIXME: Parameter '_' implicitly has an 'any' type. - source(/** @type {string} */ _, input = '') { + source(_: string, input = '') { if (!input) return scriptInquirerOptions // only show filtered results return filterSettings(scriptInquirerOptions, input) @@ -86,26 +97,3 @@ command = "${chosenSettings.devCommand}" return chosenSettings } } - -/** - * Detects and filters the build setting for a project and a command - * @param {import('../commands/base-command.js').default} command - */ -// @ts-expect-error TS(7006) FIXME: Parameter 'command' implicitly has an 'any' type. -export const detectBuildSettings = async (command) => { - const { project, workspacePackage } = command - const buildSettings = await project.getBuildSettings(project.workspace ? workspacePackage : '') - return ( - buildSettings - // @ts-expect-error TS(7006) FIXME: Parameter 'setting' implicitly has an 'any' type. - .filter((setting) => { - if (project.workspace && project.relativeBaseDirectory && setting.packagePath) { - return project.relativeBaseDirectory.startsWith(setting.packagePath) - } - - return true - }) - // @ts-expect-error TS(7006) FIXME: Parameter 'setting' implicitly has an 'any' type. - .filter((setting) => setting.devCommand) - ) -} diff --git a/src/utils/execa.ts b/src/utils/execa.ts index 6a04a3aaa12..4c901559698 100644 --- a/src/utils/execa.ts +++ b/src/utils/execa.ts @@ -4,13 +4,10 @@ import execaLib from 'execa' // This is a thin layer on top of `execa` that allows consumers to provide an // alternative path to the module location, making it easier to mock its logic -// in tests (see `tests/utils/mock-execa.js`). +// in tests (see `tests/utils/moc -/** - * @type {import('execa')} - */ // eslint-disable-next-line import/no-mutable-exports -let execa +let execa: typeof execaLib if (env.NETLIFY_CLI_EXECA_PATH) { const execaMock = await import(env.NETLIFY_CLI_EXECA_PATH) diff --git a/src/utils/feature-flags.ts b/src/utils/feature-flags.ts index 257208bcd86..ebac454f42f 100644 --- a/src/utils/feature-flags.ts +++ b/src/utils/feature-flags.ts @@ -7,14 +7,9 @@ * Instead, we return that the feature flag is enabled if it isn't * specifically set to false in the response * @param {*} siteInfo - * @param {string} flagName * * @returns {boolean} */ // @ts-expect-error TS(7006) FIXME: Parameter 'flagName' implicitly has an 'any' type. -export const isFeatureFlagEnabled = (flagName, siteInfo) => { - if (siteInfo.feature_flags && siteInfo.feature_flags[flagName] !== false) { - return true - } - return false -} +export const isFeatureFlagEnabled = (flagName: string, siteInfo): boolean => + Boolean(siteInfo.feature_flags && siteInfo.feature_flags[flagName] !== false) diff --git a/src/utils/init/utils.ts b/src/utils/init/utils.ts index f349693f0d6..ecbe67a5671 100644 --- a/src/utils/init/utils.ts +++ b/src/utils/init/utils.ts @@ -7,6 +7,7 @@ import cleanDeep from 'clean-deep' import inquirer from 'inquirer' import BaseCommand from '../../commands/base-command.js' +import { $TSFixMe } from '../../commands/types.js' import { fileExistsAsync } from '../../lib/fs.js' import { normalizeBackslash } from '../../lib/path.js' import { detectBuildSettings } from '../build-info.js' @@ -41,9 +42,8 @@ export const getPluginsToAutoInstall = ( [] as string[], ) } -/** - */ -const normalizeSettings = (settings: Settings, config: NetlifyConfig, command: BaseCommand) => { + +const normalizeSettings = (settings: Partial, config: NetlifyConfig, command: BaseCommand) => { const plugins = getPluginsToAutoInstall(command, settings.plugins_from_config_file, settings.plugins_recommended) const recommendedPlugins = getRecommendPlugins(plugins, config) @@ -94,18 +94,11 @@ const getPromptInputs = ({ defaultBaseDir, defaultBuildCmd, defaultBuildDir }) = return inputs.filter(Boolean) } -/** - * @param {object} param0 - * @param {*} param0.config - * @param {import('../../commands/base-command.js').default} param0.command - */ -// @ts-expect-error TS(7031) FIXME: Binding element 'command' implicitly has an 'any' ... Remove this comment to see the full error message -export const getBuildSettings = async ({ command, config }) => { +export const getBuildSettings = async ({ command, config }: { command: BaseCommand; config: $TSFixMe }) => { const settings = await detectBuildSettings(command) // TODO: add prompt for asking to choose the build command - /** @type {Partial} */ // eslint-disable-next-line unicorn/explicit-length-check - const setting = settings.length > 0 ? settings[0] : {} + const setting: Partial = settings.length > 0 ? settings[0] : {} const { defaultBaseDir, defaultBuildCmd, defaultBuildDir, defaultFunctionsDir, recommendedPlugins } = await normalizeSettings(setting, config, command) diff --git a/src/utils/live-tunnel.ts b/src/utils/live-tunnel.ts index 75589e960d0..08c55d757f5 100644 --- a/src/utils/live-tunnel.ts +++ b/src/utils/live-tunnel.ts @@ -9,7 +9,6 @@ import { fetchLatestVersion, shouldFetchLatestVersion } from '../lib/exec-fetche import { getPathInHome } from '../lib/settings.js' import { NETLIFYDEVERR, NETLIFYDEVLOG, chalk, log } from './command-helpers.js' -// @ts-expect-error TS(7034) FIXME: Variable 'execa' implicitly has type 'any' in some... Remove this comment to see the full error message import execa from './execa.js' const PACKAGE_NAME = 'live-tunnel-client' @@ -62,7 +61,6 @@ const connectTunnel = function ({ localPort, netlifyApiToken, session }) { log(execPath, args) } - // @ts-expect-error TS(7005) FIXME: Variable 'execa' implicitly has an 'any' type. const ps = execa(execPath, args, { stdio: 'inherit' }) // @ts-expect-error TS(7006) FIXME: Parameter 'code' implicitly has an 'any' type. ps.on('close', (code) => process.exit(code)) diff --git a/src/utils/lm/requirements.ts b/src/utils/lm/requirements.ts index ace07556bf5..089d1cd2bd2 100644 --- a/src/utils/lm/requirements.ts +++ b/src/utils/lm/requirements.ts @@ -1,11 +1,9 @@ import semver from 'semver' -// @ts-expect-error TS(7034) FIXME: Variable 'execa' implicitly has type 'any' in some... Remove this comment to see the full error message import execa from '../execa.js' export const checkLFSFilters = async function () { try { - // @ts-expect-error TS(7005) FIXME: Variable 'execa' implicitly has an 'any' type. const { stdout } = await execa('git', ['config', '--get-regexp', 'filter.lfs']) return stdout.length !== 0 } catch { @@ -15,7 +13,6 @@ export const checkLFSFilters = async function () { const getHelperVersion = async function () { try { - // @ts-expect-error TS(7005) FIXME: Variable 'execa' implicitly has an 'any' type. const { stdout } = await execa('git-credential-netlify', ['version']) return stdout } catch { @@ -36,7 +33,6 @@ export const checkHelperVersion = async function () { export const checkGitVersion = async function () { try { - // @ts-expect-error TS(7005) FIXME: Variable 'execa' implicitly has an 'any' type. const { stdout } = await execa('git', ['--version']) return stdout.split(' ').pop() } catch { @@ -46,7 +42,6 @@ export const checkGitVersion = async function () { const getLFSVersion = async function () { try { - // @ts-expect-error TS(7005) FIXME: Variable 'execa' implicitly has an 'any' type. const { stdout } = await execa('git-lfs', ['version']) return stdout } catch { diff --git a/src/utils/sites/utils.ts b/src/utils/sites/utils.ts index a4e7fa1b9a4..182254d7a9d 100644 --- a/src/utils/sites/utils.ts +++ b/src/utils/sites/utils.ts @@ -45,8 +45,7 @@ export const validateTemplate = async ({ ghToken, templateName }) => { return { exists: true, isTemplate: data.is_template } } -// @ts-expect-error TS(7006) FIXME: Parameter 'templateName' implicitly has an 'any' t... Remove this comment to see the full error message -export const createRepo = async (templateName, ghToken, siteName) => { +export const createRepo = async (templateName: string, ghToken: string, siteName: string) => { const resp = await fetch(`https://api.github.com/repos/${templateName}/generate`, { method: 'POST', headers: { diff --git a/src/utils/telemetry/report-error.ts b/src/utils/telemetry/report-error.ts index 1508b17f840..18d2341ebe6 100644 --- a/src/utils/telemetry/report-error.ts +++ b/src/utils/telemetry/report-error.ts @@ -5,7 +5,6 @@ import { fileURLToPath } from 'url' import { isCI } from 'ci-info' -// @ts-expect-error TS(7034) FIXME: Variable 'execa' implicitly has type 'any' in some... Remove this comment to see the full error message import execa from '../execa.js' import getGlobalConfig from '../get-global-config.js' @@ -55,7 +54,6 @@ export const reportError = async function (error, config = {}) { // spawn detached child process to handle send and wait for the http request to finish // otherwise it can get canceled - // @ts-expect-error TS(7005) FIXME: Variable 'execa' implicitly has an 'any' type. await execa(process.execPath, [join(dirPath, 'request.js'), options], { detached: true, stdio: 'ignore', diff --git a/src/utils/telemetry/telemetry.ts b/src/utils/telemetry/telemetry.ts index 5813ad49d9f..0db710dcbe1 100644 --- a/src/utils/telemetry/telemetry.ts +++ b/src/utils/telemetry/telemetry.ts @@ -4,7 +4,6 @@ import { fileURLToPath } from 'url' import { isCI } from 'ci-info' -// @ts-expect-error TS(7034) FIXME: Variable 'execa' implicitly has type 'any' in some... Remove this comment to see the full error message import execa from '../execa.js' import getGlobalConfig from '../get-global-config.js' @@ -13,28 +12,21 @@ import isValidEventName from './validation.js' const dirPath = dirname(fileURLToPath(import.meta.url)) -/** - * @param {'track' | 'identify'} type - * @param {object} payload - */ -// @ts-expect-error TS(7006) FIXME: Parameter 'type' implicitly has an 'any' type. -function send(type, payload) { +function send(type: 'track' | 'identify', payload: object) { const requestFile = join(dirPath, 'request.js') const options = JSON.stringify({ data: payload, type, }) - const args = /** @type {const} */ [process.execPath, [requestFile, options]] + const args = [process.execPath, [requestFile, options]] as const if (process.env.NETLIFY_TEST_TELEMETRY_WAIT === 'true') { - // @ts-expect-error TS(7005) FIXME: Variable 'execa' implicitly has an 'any' type. return execa(...args, { stdio: 'inherit', }) } // spawn detached child process to handle send - // @ts-expect-error TS(7005) FIXME: Variable 'execa' implicitly has an 'any' type. execa(...args, { detached: true, stdio: 'ignore', @@ -55,11 +47,11 @@ const eventConfig = { /** * Tracks a custom event with the provided payload - * @param {string} eventName - * @param {{status?: string, duration?: number, [key: string]: unknown}} [payload] */ -// @ts-expect-error TS(7006) FIXME: Parameter 'eventName' implicitly has an 'any' type... Remove this comment to see the full error message -export async function track(eventName, payload = {}) { +export async function track( + eventName: string, + payload: { status?: string; duration?: number; [key: string]: unknown } = {}, +) { if (isCI) { return } @@ -83,7 +75,6 @@ export async function track(eventName, payload = {}) { return false } - // @ts-expect-error TS(2339) FIXME: Property 'duration' does not exist on type '{}'. const { duration, status, ...properties } = payload const defaultData = { event: eventName, @@ -97,15 +88,7 @@ export async function track(eventName, payload = {}) { return send('track', defaultData) } -/** - * @param {object} payload - * @param {string} payload.name - * @param {string} payload.email - * @param {string} payload.userId - * @returns - */ -// @ts-expect-error TS(7006) FIXME: Parameter 'payload' implicitly has an 'any' type. -export async function identify(payload) { +export async function identify(payload: { name: string; email: string; userId: string }) { if (isCI) { return }