Skip to content

Commit 3e2876d

Browse files
fix: avoid duplicate env-var prompt & duplicate choice list
1 parent 13a6460 commit 3e2876d

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/adapters/base-class.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,31 @@ describe('BaseClass', () => {
406406
expect(printAllVariablesMock).toHaveBeenCalled();
407407
expect(baseClass.envVariables).toEqual(expectedEnv);
408408
});
409+
410+
it('should pass deduplicated choices to ux.inquire when variablePreparationTypeOptions contains duplicates', async () => {
411+
const opts = config.variablePreparationTypeOptions;
412+
const withDuplicates = [...opts, opts[0], opts[1]];
413+
baseClass = new BaseClass({
414+
log: logMock,
415+
exit: exitMock,
416+
config: {
417+
variablePreparationTypeOptions: withDuplicates,
418+
},
419+
} as any);
420+
421+
jest.spyOn(baseClass, 'importEnvFromStack').mockResolvedValueOnce();
422+
(ux.inquire as jest.Mock).mockResolvedValueOnce(['Import variables from a stack']);
423+
424+
await baseClass.handleEnvImportFlow();
425+
426+
expect(ux.inquire).toHaveBeenCalledWith(
427+
expect.objectContaining({
428+
type: 'checkbox',
429+
name: 'variablePreparationType',
430+
choices: opts,
431+
}),
432+
);
433+
});
409434
});
410435

411436
describe('importVariableFromLocalConfig', () => {

src/adapters/base-class.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,13 +514,15 @@ export default class BaseClass {
514514
* @memberof BaseClass
515515
*/
516516
async handleEnvImportFlow(): Promise<void> {
517+
const rawChoices = this.config.variablePreparationTypeOptions;
518+
const choiceList = Array.isArray(rawChoices) ? Array.from(new Set(rawChoices)) : rawChoices;
519+
517520
let variablePreparationType: string | string[] =
518521
this.config.variableType ||
519522
(await ux.inquire({
520523
type: 'checkbox',
521524
name: 'variablePreparationType',
522-
default: this.config.framework,
523-
choices: this.config.variablePreparationTypeOptions,
525+
choices: choiceList,
524526
message: 'Import variables from a stack and/or manually add custom variables to the list',
525527
}));
526528

src/base-command.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
6262
this.args = args as Args<T>;
6363

6464
ux.registerSearchPlugin();
65+
if (process.stdin.isTTY && typeof process.stdin.setMaxListeners === 'function') {
66+
process.stdin.setMaxListeners(20);
67+
}
6568
this.$event = new EventEmitter();
6669

6770
await this.prepareConfig();

0 commit comments

Comments
 (0)