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

Refactor/poc/migrate to enquirer #6752

Draft
wants to merge 3 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
56 changes: 56 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"decache": "4.6.2",
"dot-prop": "9.0.0",
"dotenv": "16.4.5",
"enquirer": "^2.4.1",
"env-paths": "3.0.0",
"envinfo": "7.13.0",
"etag": "1.8.1",
Expand Down
36 changes: 20 additions & 16 deletions src/commands/addons/addons-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OptionValues } from 'commander'
import inquirer from 'inquirer'
import Enquirer from 'enquirer'
import isEmpty from 'lodash/isEmpty.js'

import compare from '../../utils/addons/compare.js'
Expand Down Expand Up @@ -88,14 +88,15 @@ export const addonsConfig = async (addonName: string, options: OptionValues, com
return false
}

const updatePrompt = await inquirer.prompt([
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const updatePrompt = await Enquirer.prompt<any>([
{
type: 'confirm',
name: 'updateNow',
message: `Do you want to update config values?`,
default: false,
},
])
type: 'confirm',
name: 'updateNow',
message: `Do you want to update config values?`,
initial: false,
},
])
if (!updatePrompt.updateNow) {
log('Sounds good! Exiting configuration...')
return false
Expand All @@ -111,7 +112,9 @@ export const addonsConfig = async (addonName: string, options: OptionValues, com
config: manifest.config,
configValues: currentConfig,
})
const userInput = await inquirer.prompt(prompts)
// TODO: Fix type argument
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const userInput = await Enquirer.prompt<any>(prompts as any)
// Merge user input with the flags specified
const newConfig = updateConfigValues(manifest.config, currentConfig, userInput)

Expand All @@ -134,14 +137,15 @@ export const addonsConfig = async (addonName: string, options: OptionValues, com
})
log()

const confirmPrompt = await inquirer.prompt([
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const confirmPrompt = await Enquirer.prompt<any>([
{
type: 'confirm',
name: 'confirmChange',
message: `Do you want to publish the updated "${addonName} add-on" settings for ${chalk.cyan(siteData.name)}?`,
default: false,
},
])
type: 'confirm',
name: 'confirmChange',
message: `Do you want to publish the updated "${addonName} add-on" settings for ${chalk.cyan(siteData.name)}?`,
initial: false,
},
])

if (!confirmPrompt.confirmChange) {
log('Canceling changes... You are good to go!')
Expand Down
5 changes: 3 additions & 2 deletions src/commands/addons/addons-create.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OptionValues } from 'commander'
import inquirer from 'inquirer'
import Enquirer from 'enquirer'
import isEmpty from 'lodash/isEmpty.js'

import { ADDON_VALIDATION, prepareAddonCommand } from '../../utils/addons/prepare.js'
Expand Down Expand Up @@ -89,7 +89,8 @@ export const addonsCreate = async (addonName: string, options: OptionValues, com
configValues: rawFlags,
})

const userInput = await inquirer.prompt(prompts)
// TODO: fix argument
const userInput = await Enquirer.prompt<any>(prompts as any)
// Merge user input with the flags specified
configValues = updateConfigValues(manifest.config, rawFlags, userInput)
const missingRequiredValues = missingConfigValues(required, configValues)
Expand Down
6 changes: 3 additions & 3 deletions src/commands/addons/addons-delete.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OptionValues } from 'commander'
import inquirer from 'inquirer'
import Enquirer from 'enquirer'

import { ADDON_VALIDATION, prepareAddonCommand } from '../../utils/addons/prepare.js'
import { error, exit, log } from '../../utils/command-helpers.js'
Expand All @@ -12,11 +12,11 @@ export const addonsDelete = async (addonName: string, options: OptionValues, com
validation: ADDON_VALIDATION.EXISTS,
})
if (!options.force && !options.f) {
const { wantsToDelete } = await inquirer.prompt({
const { wantsToDelete } = await Enquirer.prompt<any>({
type: 'confirm',
name: 'wantsToDelete',
message: `Are you sure you want to delete the ${addonName} add-on? (to skip this prompt, pass a --force flag)`,
default: false,
initial: false,
})
if (!wantsToDelete) {
exit()
Expand Down
25 changes: 12 additions & 13 deletions src/commands/base-command.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { isCI } from 'ci-info'

import { existsSync } from 'fs'
import { join, relative, resolve } from 'path'
import process from 'process'
Expand All @@ -8,13 +6,12 @@ import { format } from 'util'
import { DefaultLogger, Project } from '@netlify/build-info'
import { NodeFS, NoopLogger } from '@netlify/build-info/node'
import { resolveConfig } from '@netlify/config'
import { isCI } from 'ci-info'
import { Command, Help, Option } from 'commander'
// @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'debu... Remove this comment to see the full error message
import debug from 'debug'
import Enquirer from 'enquirer'
import { findUp } from 'find-up'
import inquirer from 'inquirer'
// @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'inqu... Remove this comment to see the full error message
import inquirerAutocompletePrompt from 'inquirer-autocomplete-prompt'
import merge from 'lodash/merge.js'
import { NetlifyAPI } from 'netlify'

Expand All @@ -27,11 +24,11 @@ import {
exit,
getToken,
log,
version,
normalizeConfig,
padLeft,
pollForToken,
sortOptions,
version,
warn,
} from '../utils/command-helpers.js'
import { FeatureFlags } from '../utils/feature-flags.js'
Expand All @@ -49,8 +46,6 @@ type Analytics = {
payload?: Record<string, unknown>
}

// load the autocomplete plugin
inquirer.registerPrompt('autocomplete', inquirerAutocompletePrompt)
/** Netlify CLI client id. Lives in [email protected] */
// TODO: setup client for multiple environments
const CLIENT_ID = 'd6f37de6614df7ae58664cfca524744d73807a377f5ee71f1a254f78412e3750'
Expand Down Expand Up @@ -121,14 +116,15 @@ async function selectWorkspace(project: Project, filter?: string): Promise<strin
)
}

const { result } = await inquirer.prompt({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const { result } = await Enquirer.prompt<any>({
name: 'result',
// @ts-expect-error TS(2769) FIXME: No overload matches this call.
type: 'autocomplete',
message: 'Select the site you want to work with',
// @ts-expect-error TS(7006) FIXME: Parameter '_' implicitly has an 'any' type.
source: (/** @type {string} */ _, input = '') =>
(project.workspace?.packages || [])
// @ts-expect-error Add enquirer types
// eslint-disable-next-line default-param-last, @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
suggest: (input = '', _choices: any) =>
(project.workspace?.packages || [])
.filter((pkg) => pkg.path.includes(input))
.map((pkg) => ({
name: `${pkg.name ? `${chalk.bold(pkg.name)} ` : ''}${pkg.path} ${chalk.dim(
Expand Down Expand Up @@ -270,6 +266,7 @@ export default class BaseCommand extends Command {
return (
parentCommand?.commands
.filter((cmd) => {
// eslint-disable-next-line no-underscore-dangle, @typescript-eslint/no-explicit-any
if ((cmd as any)._hidden) return false
// the root command
if (this.name() === 'netlify') {
Expand Down Expand Up @@ -353,8 +350,10 @@ export default class BaseCommand extends Command {
// Aliases

// @ts-expect-error TS(2551) FIXME: Property '_aliases' does not exist on type 'Comman... Remove this comment to see the full error message
// eslint-disable-next-line no-underscore-dangle
if (command._aliases.length !== 0) {
// @ts-expect-error TS(2551) FIXME: Property '_aliases' does not exist on type 'Comman... Remove this comment to see the full error message
// eslint-disable-next-line no-underscore-dangle
const aliases = command._aliases.map((alias) => formatItem(`${parentCommand.name()} ${alias}`, null, true))
output = [...output, chalk.bold('ALIASES'), formatHelpList(aliases), '']
}
Expand Down
31 changes: 17 additions & 14 deletions src/commands/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { basename, resolve } from 'path'

import { runCoreSteps } from '@netlify/build'
import { OptionValues } from 'commander'
import inquirer from 'inquirer'
import Enquirer from 'enquirer'
import isEmpty from 'lodash/isEmpty.js'
import isObject from 'lodash/isObject.js'
import { parseAllHeaders } from 'netlify-headers-parser'
Expand Down Expand Up @@ -98,13 +98,13 @@ const getDeployFolder = async ({

if (!deployFolder) {
log('Please provide a publish directory (e.g. "public" or "dist" or "."):')
const { promptPath } = await inquirer.prompt([
const { promptPath } = await Enquirer.prompt<any>([
{
type: 'input',
name: 'promptPath',
message: 'Publish directory',
default: '.',
filter: (input) => resolve(command.workingDir, input),
initial: '.',
result: (input) => resolve(command.workingDir, input),
},
])
deployFolder = promptPath as string
Expand Down Expand Up @@ -255,12 +255,12 @@ const SYNC_FILE_LIMIT = 1e2
const prepareProductionDeploy = async ({ api, siteData }) => {
if (isObject(siteData.published_deploy) && siteData.published_deploy.locked) {
log(`\n${NETLIFYDEVERR} Deployments are "locked" for production context of this site\n`)
const { unlockChoice } = await inquirer.prompt([
const { unlockChoice } = await Enquirer.prompt<any>([
{
type: 'confirm',
name: 'unlockChoice',
message: 'Would you like to "unlock" deployments for production context to proceed?',
default: false,
initial: false,
},
])
if (!unlockChoice) exit(0)
Expand Down Expand Up @@ -364,7 +364,8 @@ const uploadDeployBlobs = async ({
silent: boolean
siteId: string
}) => {
const statusCb = silent ? () => {} : deployProgressCb()
// eslint-disable-next-line @typescript-eslint/no-empty-function, unicorn/empty-brace-spaces
const statusCb = silent ? () => { } : deployProgressCb()

statusCb({
type: 'blobs-uploading',
Expand Down Expand Up @@ -508,6 +509,7 @@ const runDeploy = async ({
fnDir: functionDirectories,
functionsConfig,

// eslint-disable-next-line @typescript-eslint/no-empty-function
statusCb: silent ? () => {} : deployProgressCb(),
deployTimeout,
syncFileLimit: SYNC_FILE_LIMIT,
Expand Down Expand Up @@ -589,6 +591,7 @@ const bundleEdgeFunctions = async (options, command: BaseCommand) => {
// eslint-disable-next-line n/prefer-global/process, unicorn/prefer-set-has
const argv = process.argv.slice(2)
const statusCb =
// eslint-disable-next-line @typescript-eslint/no-empty-function
options.silent || argv.includes('--json') || argv.includes('--silent') ? () => {} : deployProgressCb()

statusCb({
Expand Down Expand Up @@ -811,14 +814,14 @@ export const deploy = async (options: OptionValues, command: BaseCommand) => {

const initializeOpts = [EXISTING_SITE, NEW_SITE]

const { initChoice } = await inquirer.prompt([
const { initChoice } = await Enquirer.prompt<any>([
{
type: 'list',
name: 'initChoice',
message: 'What would you like to do?',
choices: initializeOpts,
},
])
type: 'select',
name: 'initChoice',
message: 'What would you like to do?',
choices: initializeOpts,
},
])
// create site or search for one
if (initChoice === NEW_SITE) {
// @ts-expect-error TS(2322) FIXME: Type 'undefined' is not assignable to type '{}'.
Expand Down
Loading
Loading