Skip to content

Commit

Permalink
deps: replace inquirer with enquirer (GoogleChrome#12305)
Browse files Browse the repository at this point in the history
  • Loading branch information
takenspc committed Mar 31, 2021
1 parent 915d1ac commit 7504bbd
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 34 deletions.
28 changes: 12 additions & 16 deletions lighthouse-cli/sentry-prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

const Configstore = require('configstore');
const inquirer = require('inquirer');
const {Confirm} = require('enquirer');

const log = require('lighthouse-logger');

Expand All @@ -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,
]);
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
19 changes: 19 additions & 0 deletions types/enquirer/index.d.ts
Original file line number Diff line number Diff line change
@@ -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<boolean>;
close: () => Promise<void>
}
}
29 changes: 13 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 7504bbd

Please sign in to comment.