Skip to content

Commit 177fecb

Browse files
author
Angular Builds
committed
9315968 build: remove unused inquirer dependency
1 parent a6f8a89 commit 177fecb

File tree

4 files changed

+75
-93
lines changed

4 files changed

+75
-93
lines changed

bin/schematics.d.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,3 @@ export interface MainOptions {
1414
stderr?: ProcessOutput;
1515
}
1616
export declare function main({ args, stdout, stderr, }: MainOptions): Promise<0 | 1>;
17-
/**
18-
* This uses a dynamic import to load a module which may be ESM.
19-
* CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript
20-
* will currently, unconditionally downlevel dynamic import into a require call.
21-
* require calls cannot load ESM code and will result in a runtime error. To workaround
22-
* this, a Function constructor is used to prevent TypeScript from changing the dynamic import.
23-
* Once TypeScript provides support for keeping the dynamic import this workaround can
24-
* be dropped.
25-
*
26-
* @param modulePath The path of the module to load.
27-
* @returns A Promise that resolves to the dynamically imported module.
28-
*/
29-
export declare function loadEsmModule<T>(modulePath: string | URL): Promise<T>;

bin/schematics.js

Lines changed: 70 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3535
};
3636
Object.defineProperty(exports, "__esModule", { value: true });
3737
exports.main = main;
38-
exports.loadEsmModule = loadEsmModule;
3938
// symbol polyfill must go first
4039
require("symbol-observable");
4140
const node_1 = require("@angular-devkit/core/node");
@@ -84,66 +83,82 @@ function _listSchematics(workflow, collectionName, logger) {
8483
}
8584
function _createPromptProvider() {
8685
return async (definitions) => {
87-
const questions = definitions.map((definition) => {
88-
const question = {
89-
name: definition.id,
90-
message: definition.message,
91-
default: definition.default,
92-
};
93-
const validator = definition.validator;
94-
if (validator) {
95-
question.validate = (input) => validator(input);
96-
// Filter allows transformation of the value prior to validation
97-
question.filter = async (input) => {
98-
for (const type of definition.propertyTypes) {
99-
let value;
100-
switch (type) {
101-
case 'string':
102-
value = String(input);
103-
break;
104-
case 'integer':
105-
case 'number':
106-
value = Number(input);
107-
break;
108-
default:
109-
value = input;
110-
break;
111-
}
112-
// Can be a string if validation fails
113-
const isValid = (await validator(value)) === true;
114-
if (isValid) {
115-
return value;
116-
}
117-
}
118-
return input;
119-
};
120-
}
86+
let prompts;
87+
const answers = {};
88+
for (const definition of definitions) {
89+
// Only load prompt package if needed
90+
prompts ??= await Promise.resolve().then(() => __importStar(require('@inquirer/prompts')));
12191
switch (definition.type) {
12292
case 'confirmation':
123-
return { ...question, type: 'confirm' };
93+
answers[definition.id] = await prompts.confirm({
94+
message: definition.message,
95+
default: definition.default,
96+
});
97+
break;
12498
case 'list':
125-
return {
126-
...question,
127-
type: definition.multiselect ? 'checkbox' : 'list',
128-
choices: definition.items &&
129-
definition.items.map((item) => {
130-
if (typeof item == 'string') {
131-
return item;
99+
if (!definition.items?.length) {
100+
continue;
101+
}
102+
const choices = definition.items?.map((item) => {
103+
return typeof item == 'string'
104+
? {
105+
name: item,
106+
value: item,
107+
}
108+
: {
109+
name: item.label,
110+
value: item.value,
111+
};
112+
});
113+
answers[definition.id] = await (definition.multiselect ? prompts.checkbox : prompts.select)({
114+
message: definition.message,
115+
default: definition.default,
116+
choices,
117+
});
118+
break;
119+
case 'input':
120+
let finalValue;
121+
answers[definition.id] = await prompts.input({
122+
message: definition.message,
123+
default: definition.default,
124+
async validate(value) {
125+
if (definition.validator === undefined) {
126+
return true;
127+
}
128+
let lastValidation = false;
129+
for (const type of definition.propertyTypes) {
130+
let potential;
131+
switch (type) {
132+
case 'string':
133+
potential = String(value);
134+
break;
135+
case 'integer':
136+
case 'number':
137+
potential = Number(value);
138+
break;
139+
default:
140+
potential = value;
141+
break;
132142
}
133-
else {
134-
return {
135-
name: item.label,
136-
value: item.value,
137-
};
143+
lastValidation = await definition.validator(potential);
144+
// Can be a string if validation fails
145+
if (lastValidation === true) {
146+
finalValue = potential;
147+
return true;
138148
}
139-
}),
140-
};
141-
default:
142-
return { ...question, type: definition.type };
149+
}
150+
return lastValidation;
151+
},
152+
});
153+
// Use validated value if present.
154+
// This ensures the correct type is inserted into the final schema options.
155+
if (finalValue !== undefined) {
156+
answers[definition.id] = finalValue;
157+
}
158+
break;
143159
}
144-
});
145-
const { default: inquirer } = await loadEsmModule('inquirer');
146-
return inquirer.prompt(questions);
160+
}
161+
return answers;
147162
};
148163
}
149164
function findUp(names, from) {
@@ -431,23 +446,3 @@ if (require.main === module) {
431446
throw e;
432447
});
433448
}
434-
/**
435-
* Lazily compiled dynamic import loader function.
436-
*/
437-
let load;
438-
/**
439-
* This uses a dynamic import to load a module which may be ESM.
440-
* CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript
441-
* will currently, unconditionally downlevel dynamic import into a require call.
442-
* require calls cannot load ESM code and will result in a runtime error. To workaround
443-
* this, a Function constructor is used to prevent TypeScript from changing the dynamic import.
444-
* Once TypeScript provides support for keeping the dynamic import this workaround can
445-
* be dropped.
446-
*
447-
* @param modulePath The path of the module to load.
448-
* @returns A Promise that resolves to the dynamically imported module.
449-
*/
450-
function loadEsmModule(modulePath) {
451-
load ??= new Function('modulePath', `return import(modulePath);`);
452-
return load(modulePath);
453-
}

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@angular-devkit/schematics-cli",
3-
"version": "18.1.0-next.1+sha-ee9d404",
3+
"version": "18.1.0-next.1+sha-9315968",
44
"description": "Angular Schematics - CLI",
55
"homepage": "https://github.com/angular/angular-cli",
66
"bin": {
@@ -21,10 +21,10 @@
2121
],
2222
"schematics": "./collection.json",
2323
"dependencies": {
24-
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#ee9d404",
25-
"@angular-devkit/schematics": "github:angular/angular-devkit-schematics-builds#ee9d404",
24+
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#9315968",
25+
"@angular-devkit/schematics": "github:angular/angular-devkit-schematics-builds#9315968",
26+
"@inquirer/prompts": "5.0.5",
2627
"ansi-colors": "4.1.3",
27-
"inquirer": "9.2.23",
2828
"symbol-observable": "4.0.0",
2929
"yargs-parser": "21.1.1"
3030
},

uniqueId

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Fri Jun 07 2024 00:12:24 GMT+0000 (Coordinated Universal Time)
1+
Fri Jun 07 2024 13:03:38 GMT+0000 (Coordinated Universal Time)

0 commit comments

Comments
 (0)