Skip to content

Commit

Permalink
refactor(@angular-devkit/build-angular): lazy import inquirer
Browse files Browse the repository at this point in the history
`inquirer` has a number of depedencies which slow down module resolution when importing (~138ms) by lazy loading this module we remove this overhead when prompts are not needed.
  • Loading branch information
alan-agius4 authored and dgp1130 committed Mar 23, 2022
1 parent 933b3ca commit 861ec0f
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions packages/angular_devkit/build_angular/src/utils/check-port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/

import { prompt } from 'inquirer';
import * as net from 'net';
import { isTTY } from './tty';

Expand Down Expand Up @@ -36,15 +35,19 @@ export async function checkPort(port: number, host: string): Promise<number> {
return;
}

prompt({
type: 'confirm',
name: 'useDifferent',
message: `Port ${port} is already in use.\nWould you like to use a different port?`,
default: true,
}).then(
(answers) => (answers.useDifferent ? resolve(0) : reject(createInUseError(port))),
() => reject(createInUseError(port)),
);
import('inquirer')
.then(({ prompt }) =>
prompt({
type: 'confirm',
name: 'useDifferent',
message: `Port ${port} is already in use.\nWould you like to use a different port?`,
default: true,
}),
)
.then(
(answers) => (answers.useDifferent ? resolve(0) : reject(createInUseError(port))),
() => reject(createInUseError(port)),
);
})
.once('listening', () => {
server.close();
Expand Down

0 comments on commit 861ec0f

Please sign in to comment.