diff --git a/lib/common/commands/proxy/proxy-set.ts b/lib/common/commands/proxy/proxy-set.ts index a756754495..ee9b1f8a38 100644 --- a/lib/common/commands/proxy/proxy-set.ts +++ b/lib/common/commands/proxy/proxy-set.ts @@ -4,7 +4,6 @@ import { ProxyCommandBase } from "./proxy-base"; import { HttpProtocolToPort } from "../../constants"; import { parse } from "url"; import { platform, EOL } from "os"; -import * as prompt from "inquirer"; import { IOptions } from "../../../declarations"; import { IErrors, @@ -12,6 +11,7 @@ import { IAnalyticsService, IProxyService, IProxyLibSettings, + IPrompterQuestion, } from "../../declarations"; import { IInjector } from "../../definitions/yok"; import { injector } from "../../yok"; @@ -165,9 +165,9 @@ export class ProxySetCommand extends ProxyCommandBase { private async getPortFromUserInput(): Promise { const schemaName = "port"; - const schema: prompt.Question = { + const schema: IPrompterQuestion = { message: "Port", - type: "input", + type: "text", name: schemaName, validate: (value: any) => { return !value || !this.isValidPort(value) diff --git a/lib/common/declarations.d.ts b/lib/common/declarations.d.ts index 2fcdb7caab..87568dbbda 100644 --- a/lib/common/declarations.d.ts +++ b/lib/common/declarations.d.ts @@ -5,6 +5,7 @@ import { IGoogleAnalyticsData, } from "./definitions/google-analytics"; import * as child_process from "child_process"; +import { Answers } from "prompts"; // tslint:disable-next-line:interface-name interface Object { @@ -829,6 +830,22 @@ interface IPrompterOptions extends IAllowEmpty { defaultAction?: () => string; } +interface IPrompterAnswers extends Record {} + +interface IPrompterQuestion = Answers> { + type?: string; + name?: string; + message?: string; + default?: any; + prefix?: string; + suffix?: string; + filter?(input: any, answers: T): any; + validate?( + input: any, + answers?: T + ): boolean | string | Promise; +} + interface IAnalyticsSettingsService { canDoRequest(): Promise; getUserId(): Promise; diff --git a/lib/common/prompter.ts b/lib/common/prompter.ts index dd287e511f..71c7b28fcd 100644 --- a/lib/common/prompter.ts +++ b/lib/common/prompter.ts @@ -1,14 +1,18 @@ -import * as prompt from "inquirer"; +import * as prompt from "prompts"; import * as helpers from "./helpers"; import * as readline from "readline"; import { ReadStream } from "tty"; -import { IAllowEmpty, IPrompterOptions } from "./declarations"; +import { + IAllowEmpty, + IPrompterAnswers, + IPrompterOptions, + IPrompterQuestion, +} from "./declarations"; import { injector } from "./yok"; const MuteStream = require("mute-stream"); import * as _ from "lodash"; export class Prompter implements IPrompter { - private descriptionSeparator = "|"; private ctrlcReader: readline.ReadLine; private muteStreamInstance: any = null; @@ -18,12 +22,7 @@ export class Prompter implements IPrompter { } } - public async get(questions: prompt.Question[]): Promise { - _.each(questions, (q) => { - q.filter = (selection: string) => { - return selection.split(this.descriptionSeparator)[0].trim(); - }; - }); + public async get(questions: IPrompterQuestion[]): Promise { try { this.muteStdout(); @@ -55,7 +54,7 @@ export class Prompter implements IPrompter { message: string, options?: IAllowEmpty ): Promise { - const schema: prompt.Question = { + const schema: IPrompterQuestion = { message, type: "password", name: "password", @@ -73,9 +72,9 @@ export class Prompter implements IPrompter { message: string, options?: IPrompterOptions ): Promise { - const schema: prompt.Question = { + const schema: IPrompterQuestion = { message, - type: "input", + type: "text", name: "inputString", validate: (value: any) => { const doesNotAllowEmpty = @@ -95,9 +94,9 @@ export class Prompter implements IPrompter { promptMessage: string, choices: string[] ): Promise { - const schema: prompt.Answers = { + const schema: IPrompterAnswers = { message: promptMessage, - type: "list", + type: "select", name: "userAnswer", choices, }; @@ -110,21 +109,17 @@ export class Prompter implements IPrompter { promptMessage: string, choices: { key: string; description: string }[] ): Promise { - const longestKeyLength = choices.concat().sort(function (a, b) { - return b.key.length - a.key.length; - })[0].key.length; const inquirerChoices = choices.map((choice) => { return { - name: `${_.padEnd(choice.key, longestKeyLength)} ${ - choice.description ? this.descriptionSeparator : "" - } ${choice.description}`, - short: choice.key, + title: choice.key, + value: choice.key, + description: choice.description, }; }); const schema: any = { message: promptMessage, - type: "list", + type: "select", name: "userAnswer", choices: inquirerChoices, }; diff --git a/lib/definitions/prompter.d.ts b/lib/definitions/prompter.d.ts index 77a9e7890a..d1f731c329 100644 --- a/lib/definitions/prompter.d.ts +++ b/lib/definitions/prompter.d.ts @@ -1,13 +1,13 @@ -import * as prompt from "inquirer"; import { IPrompterOptions, IAllowEmpty, IDisposable, + IPrompterQuestion, } from "../common/declarations"; declare global { interface IPrompter extends IDisposable { - get(schemas: prompt.Question[]): Promise; + get(schemas: IPrompterQuestion[]): Promise; getPassword(prompt: string, options?: IAllowEmpty): Promise; getString(prompt: string, options?: IPrompterOptions): Promise; promptForChoice(promptMessage: string, choices: string[]): Promise; diff --git a/package-lock.json b/package-lock.json index 7036598346..f472045404 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4668,16 +4668,6 @@ "@types/node": "*" } }, - "@types/inquirer": { - "version": "7.3.0", - "resolved": "https://registry.npmjs.org/@types/inquirer/-/inquirer-7.3.0.tgz", - "integrity": "sha512-wcPs5jTrZYQBzzPlvUEzBcptzO4We2sijSvkBq8oAKRMJoH8PvrmP6QQnxLB5RScNUmRfujxA+ngxD4gk4xe7Q==", - "dev": true, - "requires": { - "@types/through": "*", - "rxjs": "^6.4.0" - } - }, "@types/istextorbinary": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@types/istextorbinary/-/istextorbinary-2.3.0.tgz", @@ -4806,6 +4796,15 @@ "integrity": "sha512-hiYA88aHiEIgDmeKlsyVsuQdcFn3Z2VuFd/Xm/HCnGnPD8UFU5BM128uzzRVVGEzKDKYUrRsRH9S2o+NUy/3IA==", "dev": true }, + "@types/prompts": { + "version": "2.0.9", + "resolved": "https://registry.npmjs.org/@types/prompts/-/prompts-2.0.9.tgz", + "integrity": "sha512-TORZP+FSjTYMWwKadftmqEn6bziN5RnfygehByGsjxoK5ydnClddtv6GikGWPvCm24oI+YBwck5WDxIIyNxUrA==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/proper-lockfile": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/@types/proper-lockfile/-/proper-lockfile-4.1.1.tgz", @@ -4904,15 +4903,6 @@ "@types/node": "*" } }, - "@types/through": { - "version": "0.0.30", - "resolved": "https://registry.npmjs.org/@types/through/-/through-0.0.30.tgz", - "integrity": "sha512-FvnCJljyxhPM3gkRgWmxmDZyAQSiBQQWLI0A0VFL0K7W1oRUrPJSqNO0NvTnLkBcotdlp3lKvaT0JrnyRDkzOg==", - "dev": true, - "requires": { - "@types/node": "*" - } - }, "@types/tough-cookie": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.0.tgz", @@ -5038,6 +5028,7 @@ "version": "4.3.1", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.1.tgz", "integrity": "sha512-JWF7ocqNrp8u9oqpgV+wH5ftbt+cfvv+PTjOvKLT3AdYly/LmORARfEVT1iyjwN+4MqE5UmVKoAdIBqeoCHgLA==", + "dev": true, "requires": { "type-fest": "^0.11.0" } @@ -5725,11 +5716,6 @@ "supports-color": "^7.1.0" } }, - "chardet": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz", - "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==" - }, "check-error": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", @@ -5834,11 +5820,6 @@ "string-width": "^4.2.0" } }, - "cli-width": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-3.0.0.tgz", - "integrity": "sha512-FxqpkPPwu1HjuN93Omfm4h8uIanXofW0RxVEW3k5RKx+mJJYSthzNhp32Kzxxy3YAEZ/Dc/EWN1vZRY0+kOhbw==" - }, "cliui": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/cliui/-/cliui-3.2.0.tgz", @@ -7078,16 +7059,6 @@ } } }, - "external-editor": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.1.0.tgz", - "integrity": "sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew==", - "requires": { - "chardet": "^0.7.0", - "iconv-lite": "^0.4.24", - "tmp": "^0.0.33" - } - }, "extglob": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/extglob/-/extglob-2.0.4.tgz", @@ -7212,6 +7183,7 @@ "version": "3.2.0", "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", "integrity": "sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg==", + "dev": true, "requires": { "escape-string-regexp": "^1.0.5" } @@ -9016,26 +8988,6 @@ "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==" }, - "inquirer": { - "version": "7.3.3", - "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-7.3.3.tgz", - "integrity": "sha512-JG3eIAj5V9CwcGvuOmoo6LB9kbAYT8HXffUl6memuszlwDC/qvFAJw49XJ5NROSFNPxp3iQg1GqkFhaY/CR0IA==", - "requires": { - "ansi-escapes": "^4.2.1", - "chalk": "^4.1.0", - "cli-cursor": "^3.1.0", - "cli-width": "^3.0.0", - "external-editor": "^3.0.3", - "figures": "^3.0.0", - "lodash": "^4.17.19", - "mute-stream": "0.0.8", - "run-async": "^2.4.0", - "rxjs": "^6.6.0", - "string-width": "^4.1.0", - "strip-ansi": "^6.0.0", - "through": "^2.3.6" - } - }, "int64-buffer": { "version": "0.1.10", "resolved": "https://registry.npmjs.org/int64-buffer/-/int64-buffer-0.1.10.tgz", @@ -9816,6 +9768,11 @@ "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==", "dev": true }, + "kleur": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", + "integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==" + }, "latest-version": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/latest-version/-/latest-version-5.1.0.tgz", @@ -12301,6 +12258,15 @@ "iterate-value": "^1.0.0" } }, + "prompts": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.0.tgz", + "integrity": "sha512-awZAKrk3vN6CroQukBL+R9051a4R3zCZBlJm/HBfrSZ8iTpYix3VX1vU4mveiLpiwmOJT4wokTF9m6HUk4KqWQ==", + "requires": { + "kleur": "^3.0.3", + "sisteransi": "^1.0.5" + } + }, "proper-lockfile": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/proper-lockfile/-/proper-lockfile-4.1.1.tgz", @@ -12744,11 +12710,6 @@ "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.1.4.tgz", "integrity": "sha512-5C9HXdzK8EAqN7JDif30jqsBzavB7wLpaubisuQIGHWf2gUXSpzy6ArX/+Da8RjFpagWsCn+pIgxTMAmKw9Zug==" }, - "run-async": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz", - "integrity": "sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ==" - }, "run-parallel": { "version": "1.1.9", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.1.9.tgz", @@ -12758,6 +12719,7 @@ "version": "6.6.2", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.2.tgz", "integrity": "sha512-BHdBMVoWC2sL26w//BCu3YzKT4s2jip/WhwsGEDmeKYBhKDZeYezVUnHatYB7L85v5xs0BAQmg6BEYJEKxBabg==", + "dev": true, "requires": { "tslib": "^1.9.0" } @@ -13004,6 +12966,11 @@ } } }, + "sisteransi": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", + "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==" + }, "slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -13613,7 +13580,8 @@ "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", - "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=" + "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", + "dev": true }, "through2": { "version": "3.0.2", @@ -13665,14 +13633,6 @@ "resolved": "https://registry.npmjs.org/tinycolor2/-/tinycolor2-1.4.1.tgz", "integrity": "sha1-9PrTM0R7wLB9TcjpIJ2POaisd+g=" }, - "tmp": { - "version": "0.0.33", - "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", - "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", - "requires": { - "os-tmpdir": "~1.0.2" - } - }, "to-object-path": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/to-object-path/-/to-object-path-0.3.0.tgz", @@ -13918,7 +13878,8 @@ "type-fest": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.11.0.tgz", - "integrity": "sha512-OdjXJxnCN1AvyLSzeKIgXTXxV+99ZuXl3Hpo9XpJAv9MBcHrrJOQ5kV7ypXOuQie+AmWG25hLbiKdwYTifzcfQ==" + "integrity": "sha512-OdjXJxnCN1AvyLSzeKIgXTXxV+99ZuXl3Hpo9XpJAv9MBcHrrJOQ5kV7ypXOuQie+AmWG25hLbiKdwYTifzcfQ==", + "dev": true }, "typescript": { "version": "3.9.7", diff --git a/package.json b/package.json index 914692df5a..1c72c352be 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,6 @@ "email-validator": "2.0.4", "esprima": "4.0.1", "glob": "7.1.6", - "inquirer": "7.3.3", "ios-device-lib": "0.8.0-rc.1", "ios-mobileprovision-finder": "1.0.11", "ios-sim-portable": "4.2.1", @@ -94,6 +93,7 @@ "plist": "3.0.1", "plist-merge-patch": "0.1.1", "prettier": "2.1.1", + "prompts": "2.4.0", "proper-lockfile": "4.1.1", "proxy-lib": "0.4.0", "qr-image": "3.2.0", @@ -128,7 +128,6 @@ "@types/convert-source-map": "^1.5.1", "@types/form-data": "2.5.0", "@types/glob": "^7.1.3", - "@types/inquirer": "7.3.0", "@types/istextorbinary": "^2.3.0", "@types/lodash": "4.14.158", "@types/minimatch": "^3.0.3", @@ -136,6 +135,7 @@ "@types/ora": "3.2.0", "@types/pacote": "^11.1.0", "@types/prettier": "2.1.0", + "@types/prompts": "2.0.9", "@types/proper-lockfile": "4.1.1", "@types/qr-image": "3.2.3", "@types/request": "2.48.5", diff --git a/test/stubs.ts b/test/stubs.ts index 7293c81f37..0448912cf3 100644 --- a/test/stubs.ts +++ b/test/stubs.ts @@ -5,7 +5,6 @@ import * as chai from "chai"; import { EventEmitter } from "events"; import { join } from "path"; import * as constants from "./../lib/constants"; -import * as prompt from "inquirer"; import { Yok } from "./../lib/common/yok"; import { HostInfo } from "./../lib/common/host-info"; import { DevicePlatformsConstants } from "./../lib/common/mobile/device-platforms-constants"; @@ -67,6 +66,7 @@ import { IAnalyticsService, IProxySettings, Server, + IPrompterQuestion, } from "../lib/common/declarations"; import { IAndroidPluginBuildService, @@ -940,7 +940,7 @@ export class PrompterStub implements IPrompter { } } - async get(schemas: prompt.Question[]): Promise { + async get(schemas: IPrompterQuestion[]): Promise { throw unreachable(); }