Skip to content

Commit 1548333

Browse files
committed
refactor: update inquirer to version 9.0.6
Update the mentioned package. (cherry picked from commit a0f8fac)
1 parent 19191e3 commit 1548333

File tree

13 files changed

+142
-37
lines changed

13 files changed

+142
-37
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
"@types/express": "^4.16.0",
100100
"@types/http-proxy": "^1.17.4",
101101
"@types/ini": "^1.3.31",
102-
"@types/inquirer": "^8.0.0",
102+
"@types/inquirer": "^9.0.6",
103103
"@types/jasmine": "~5.1.0",
104104
"@types/karma": "^6.3.0",
105105
"@types/less": "^3.0.3",
@@ -150,7 +150,7 @@
150150
"https-proxy-agent": "7.0.2",
151151
"husky": "8.0.3",
152152
"ini": "4.1.1",
153-
"inquirer": "8.2.6",
153+
"inquirer": "9.2.11",
154154
"jasmine": "^5.0.0",
155155
"jasmine-core": "~5.1.0",
156156
"jasmine-spec-reporter": "~7.0.0",

packages/angular/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@yarnpkg/lockfile": "1.1.0",
3030
"ansi-colors": "4.1.3",
3131
"ini": "4.1.1",
32-
"inquirer": "8.2.6",
32+
"inquirer": "9.2.11",
3333
"jsonc-parser": "3.2.0",
3434
"npm-package-arg": "11.0.1",
3535
"npm-pick-manifest": "9.0.0",

packages/angular/cli/src/analytics/analytics.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type { CommandContext } from '../command-builder/command-module';
1212
import { colors } from '../utilities/color';
1313
import { getWorkspace } from '../utilities/config';
1414
import { analyticsDisabled } from '../utilities/environment-options';
15+
import { loadEsmModule } from '../utilities/load-esm';
1516
import { isTTY } from '../utilities/tty';
1617

1718
/* eslint-disable no-console */
@@ -74,8 +75,8 @@ export async function promptAnalytics(
7475
}
7576

7677
if (force || isTTY()) {
77-
const { prompt } = await import('inquirer');
78-
const answers = await prompt<{ analytics: boolean }>([
78+
const { default: inquirer } = await loadEsmModule<typeof import('inquirer')>('inquirer');
79+
const answers = await inquirer.prompt<{ analytics: boolean }>([
7980
{
8081
type: 'confirm',
8182
name: 'analytics',

packages/angular/cli/src/command-builder/schematics-command-module.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { isPackageNameSafeForAnalytics } from '../analytics/analytics';
2020
import { EventCustomDimension } from '../analytics/analytics-parameters';
2121
import { getProjectByCwd, getSchematicDefaults } from '../utilities/config';
2222
import { assertIsError } from '../utilities/error';
23+
import { loadEsmModule } from '../utilities/load-esm';
2324
import { memoize } from '../utilities/memoize';
2425
import { isTTY } from '../utilities/tty';
2526
import {
@@ -234,9 +235,9 @@ export abstract class SchematicsCommandModule
234235
});
235236

236237
if (questions.length) {
237-
const { prompt } = await import('inquirer');
238+
const { default: inquirer } = await loadEsmModule<typeof import('inquirer')>('inquirer');
238239

239-
return prompt(questions);
240+
return inquirer.prompt(questions);
240241
} else {
241242
return {};
242243
}

packages/angular/cli/src/utilities/completion.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { getWorkspace } from '../utilities/config';
1616
import { forceAutocomplete } from '../utilities/environment-options';
1717
import { isTTY } from '../utilities/tty';
1818
import { assertIsError } from './error';
19+
import { loadEsmModule } from './load-esm';
1920

2021
/** Interface for the autocompletion configuration stored in the global workspace. */
2122
interface CompletionConfig {
@@ -180,8 +181,8 @@ async function shouldPromptForAutocompletionSetup(
180181
async function promptForAutocompletion(): Promise<boolean> {
181182
// Dynamically load `inquirer` so users don't have to pay the cost of parsing and executing it for
182183
// the 99% of builds that *don't* prompt for autocompletion.
183-
const { prompt } = await import('inquirer');
184-
const { autocomplete } = await prompt<{ autocomplete: boolean }>([
184+
const { default: inquirer } = await loadEsmModule<typeof import('inquirer')>('inquirer');
185+
const { autocomplete } = await inquirer.prompt<{ autocomplete: boolean }>([
185186
{
186187
name: 'autocomplete',
187188
type: 'confirm',
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
/**
10+
* This uses a dynamic import to load a module which may be ESM.
11+
* CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript
12+
* will currently, unconditionally downlevel dynamic import into a require call.
13+
* require calls cannot load ESM code and will result in a runtime error. To workaround
14+
* this, a Function constructor is used to prevent TypeScript from changing the dynamic import.
15+
* Once TypeScript provides support for keeping the dynamic import this workaround can
16+
* be dropped.
17+
*
18+
* @param modulePath The path of the module to load.
19+
* @returns A Promise that resolves to the dynamically imported module.
20+
*/
21+
export function loadEsmModule<T>(modulePath: string | URL): Promise<T> {
22+
return new Function('modulePath', `return import(modulePath);`)(modulePath) as Promise<T>;
23+
}

packages/angular/cli/src/utilities/prompt.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
ListQuestion,
1414
Question,
1515
} from 'inquirer';
16+
import { loadEsmModule } from './load-esm';
1617
import { isTTY } from './tty';
1718

1819
export async function askConfirmation(
@@ -32,8 +33,8 @@ export async function askConfirmation(
3233
default: defaultResponse,
3334
};
3435

35-
const { prompt } = await import('inquirer');
36-
const answers = await prompt([question]);
36+
const { default: inquirer } = await loadEsmModule<typeof import('inquirer')>('inquirer');
37+
const answers = await inquirer.prompt([question]);
3738

3839
return answers['confirmation'];
3940
}
@@ -57,8 +58,8 @@ export async function askQuestion(
5758
default: defaultResponseIndex,
5859
};
5960

60-
const { prompt } = await import('inquirer');
61-
const answers = await prompt([question]);
61+
const { default: inquirer } = await loadEsmModule<typeof import('inquirer')>('inquirer');
62+
const answers = await inquirer.prompt([question]);
6263

6364
return answers['answer'];
6465
}
@@ -80,8 +81,8 @@ export async function askChoices(
8081
choices,
8182
};
8283

83-
const { prompt } = await import('inquirer');
84-
const answers = await prompt([question]);
84+
const { default: inquirer } = await loadEsmModule<typeof import('inquirer')>('inquirer');
85+
const answers = await inquirer.prompt([question]);
8586

8687
return answers['answer'];
8788
}

packages/angular_devkit/build_angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"fast-glob": "3.3.1",
3737
"https-proxy-agent": "7.0.2",
3838
"http-proxy-middleware": "2.0.6",
39-
"inquirer": "8.2.6",
39+
"inquirer": "9.2.11",
4040
"jsonc-parser": "3.2.0",
4141
"karma-source-map-support": "1.4.0",
4242
"less": "4.2.0",

packages/angular_devkit/build_angular/src/utils/check-port.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import * as net from 'net';
10+
import { loadEsmModule } from './load-esm';
1011
import { isTTY } from './tty';
1112

1213
function createInUseError(port: number): Error {
@@ -35,8 +36,8 @@ export async function checkPort(port: number, host: string): Promise<number> {
3536
return;
3637
}
3738

38-
import('inquirer')
39-
.then(({ prompt }) =>
39+
loadEsmModule<typeof import('inquirer')>('inquirer')
40+
.then(({ default: { prompt } }) =>
4041
prompt({
4142
type: 'confirm',
4243
name: 'useDifferent',

packages/angular_devkit/build_angular/src/utils/load-esm.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import { URL } from 'url';
10-
119
/**
1210
* This uses a dynamic import to load a module which may be ESM.
1311
* CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript

0 commit comments

Comments
 (0)