From 7504bbd36d5c768de0b1cde5555a4d9c7dec5fbe Mon Sep 17 00:00:00 2001 From: Takeshi Kurosawa Date: Mon, 29 Mar 2021 15:18:42 +0900 Subject: [PATCH] deps: replace inquirer with enquirer (#12305) --- lighthouse-cli/sentry-prompt.js | 28 ++++++++++++---------------- package.json | 3 +-- types/enquirer/index.d.ts | 19 +++++++++++++++++++ yarn.lock | 29 +++++++++++++---------------- 4 files changed, 45 insertions(+), 34 deletions(-) create mode 100644 types/enquirer/index.d.ts diff --git a/lighthouse-cli/sentry-prompt.js b/lighthouse-cli/sentry-prompt.js index 131e8f80bad4..22d0bfeb682f 100644 --- a/lighthouse-cli/sentry-prompt.js +++ b/lighthouse-cli/sentry-prompt.js @@ -6,7 +6,7 @@ 'use strict'; const Configstore = require('configstore'); -const inquirer = require('inquirer'); +const {Confirm} = require('enquirer'); const log = require('lighthouse-logger'); @@ -29,29 +29,25 @@ function prompt() { /** @type {NodeJS.Timer|undefined} */ let timeout; - const prompt = inquirer.prompt([ - { - type: 'confirm', - name: 'isErrorReportingEnabled', - default: false, - message: MESSAGE, - }, - ]); + const prompt = new Confirm({ + name: 'isErrorReportingEnabled', + initial: false, + message: MESSAGE, + }); const timeoutPromise = new Promise((resolve) => { timeout = setTimeout(() => { - // @ts-expect-error Promise returned by prompt is decorated with `ui` - prompt.ui.close(); - process.stdout.write('\n'); - log.warn('CLI', 'No response to error logging preference, errors will not be reported.'); - resolve(false); + prompt.close().then(() => { + log.warn('CLI', 'No response to error logging preference, errors will not be reported.'); + resolve(false); + }); }, MAXIMUM_WAIT_TIME); }); return Promise.race([ - prompt.then(result => { + prompt.run().then(result => { clearTimeout(/** @type {NodeJS.Timer} */ (timeout)); - return result.isErrorReportingEnabled; + return result; }), timeoutPromise, ]); diff --git a/package.json b/package.json index ee721c68d79b..873f3731fc0d 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,6 @@ "@types/exorcist": "^0.4.5", "@types/gh-pages": "^2.0.0", "@types/google.analytics": "0.0.39", - "@types/inquirer": "^7.3.1", "@types/jest": "^24.0.9", "@types/jpeg-js": "^0.3.0", "@types/lodash.clonedeep": "^4.5.6", @@ -164,8 +163,8 @@ "csp_evaluator": "^1.0.1", "cssstyle": "1.2.1", "details-element-polyfill": "^2.4.0", + "enquirer": "^2.3.6", "http-link-header": "^0.8.0", - "inquirer": "^7.3.3", "intl": "^1.2.5", "intl-messageformat": "^4.4.0", "intl-pluralrules": "^1.0.3", diff --git a/types/enquirer/index.d.ts b/types/enquirer/index.d.ts new file mode 100644 index 000000000000..5a565de3216a --- /dev/null +++ b/types/enquirer/index.d.ts @@ -0,0 +1,19 @@ +/** + * @license Copyright 2020 The Lighthouse Authors. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + */ + +declare module 'enquirer' { + interface ConfirmOption { + name: string | (() => string); + message: string | (() => string); + initial?: boolean | (() => boolean); + } + + class Confirm extends NodeJS.EventEmitter { + constructor(option: ConfirmOption); + run: () => Promise; + close: () => Promise + } +} diff --git a/yarn.lock b/yarn.lock index d050686ea7e1..243ad9b6a0b0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -546,14 +546,6 @@ resolved "https://registry.yarnpkg.com/@types/google.analytics/-/google.analytics-0.0.39.tgz#19a952003dbf3c7373d655a5c3203b4726b8b802" integrity sha512-AwVtVYACQg26MJz+752H6uskn53BR7eilCOHksUGkzobZNKc7O3RFTJrbD3yKAluXy6favVdynnr9btijjcakQ== -"@types/inquirer@^7.3.1": - version "7.3.1" - resolved "https://registry.yarnpkg.com/@types/inquirer/-/inquirer-7.3.1.tgz#1f231224e7df11ccfaf4cf9acbcc3b935fea292d" - integrity sha512-osD38QVIfcdgsPCT0V3lD7eH0OFurX71Jft18bZrsVQWVRt6TuxRzlr0GJLrxoHZR2V5ph7/qP8se/dcnI7o0g== - dependencies: - "@types/through" "*" - rxjs "^6.4.0" - "@types/insert-module-globals@*": version "7.0.0" resolved "https://registry.yarnpkg.com/@types/insert-module-globals/-/insert-module-globals-7.0.0.tgz#8d158de4a6384e8daa13b3d63eebab6d5f67777d" @@ -925,6 +917,11 @@ ansi-align@^3.0.0: dependencies: string-width "^3.0.0" +ansi-colors@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348" + integrity sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA== + ansi-escapes@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.0.0.tgz#ec3e8b4e9f8064fc02c3ac9b65f1c275bda8ef92" @@ -2722,6 +2719,13 @@ end-of-stream@^1.0.0, end-of-stream@^1.1.0: dependencies: once "^1.4.0" +enquirer@^2.3.6: + version "2.3.6" + resolved "https://registry.yarnpkg.com/enquirer/-/enquirer-2.3.6.tgz#2a7fe5dd634a1e4125a975ec994ff5456dc3734d" + integrity sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg== + dependencies: + ansi-colors "^4.1.1" + error-ex@^1.2.0, error-ex@^1.3.1: version "1.3.2" resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.2.tgz#b4ac40648107fdcdcfae242f428bea8a14d4f1bf" @@ -3963,7 +3967,7 @@ inquirer@^3.0.6: strip-ansi "^4.0.0" through "^2.3.6" -inquirer@^7.1.0, inquirer@^7.3.3: +inquirer@^7.1.0: version "7.3.3" resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-7.3.3.tgz#04d176b2af04afc157a83fd7c100e98ee0aad003" integrity sha512-JG3eIAj5V9CwcGvuOmoo6LB9kbAYT8HXffUl6memuszlwDC/qvFAJw49XJ5NROSFNPxp3iQg1GqkFhaY/CR0IA== @@ -6935,13 +6939,6 @@ rx-lite@*, rx-lite@^4.0.8: resolved "https://registry.yarnpkg.com/rx-lite/-/rx-lite-4.0.8.tgz#0b1e11af8bc44836f04a6407e92da42467b79444" integrity sha1-Cx4Rr4vESDbwSmQH6S2kJGe3lEQ= -rxjs@^6.4.0: - version "6.6.3" - resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.6.3.tgz#8ca84635c4daa900c0d3967a6ee7ac60271ee552" - integrity sha512-trsQc+xYYXZ3urjOiJOuCOa5N3jAZ3eiSpQB5hIT8zGlL2QfnHLJ2r7GMkBGuIausdJN1OneaI6gQlsqNHHmZQ== - dependencies: - tslib "^1.9.0" - rxjs@^6.6.0: version "6.6.0" resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.6.0.tgz#af2901eedf02e3a83ffa7f886240ff9018bbec84"