Skip to content

Commit d75643f

Browse files
committed
chore: Remove all deprecated code
BREAKING CHANGE: Removed all deprecated APIs: - Removed `list` prompt alias (use `select` instead) - Removed `helpMode` theme property (use `theme.style.keysHelpTip` instead) - Removed `instructions` config property (use `theme.style.keysHelpTip` instead) - Removed `cancel()` method on prompt return types (use AbortSignal instead) This removes 9 deprecated items across 6 packages: - packages/inquirer: Removed `list` alias - packages/search: Removed `helpMode` and `instructions` - packages/checkbox: Removed `helpMode` and `instructions` - packages/select: Removed `helpMode` and `instructions` - packages/type: Removed `cancel()` method - packages/testing: Removed `cancel()` method Also updated tests to use new APIs and removed deprecated feature references from documentation.
1 parent caf53b9 commit d75643f

File tree

14 files changed

+85
-403
lines changed

14 files changed

+85
-403
lines changed

packages/checkbox/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ type Theme = {
166166

167167
This function allows you to customize the keyboard shortcuts help tip displayed below the prompt. It receives an array of key-action pairs and should return a formatted string. You can also hook here to localize the labels to different languages.
168168

169-
It can also returns `undefined` to hide the help tip entirely. This is the replacement for the deprecated theme option `helpMode: 'never'`.
169+
It can also returns `undefined` to hide the help tip entirely.
170170

171171
```js
172172
theme: {

packages/checkbox/checkbox.test.ts

Lines changed: 25 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -616,56 +616,6 @@ describe('checkbox prompt', () => {
616616
await expect(answer).resolves.not.toContain(unselect);
617617
});
618618

619-
it('allow disabling help tip', async () => {
620-
const { answer, events, getScreen } = await render(checkbox, {
621-
message: 'Select a number',
622-
choices: numberedChoices,
623-
instructions: false,
624-
});
625-
626-
expect(getScreen()).toMatchInlineSnapshot(`
627-
"? Select a number
628-
❯◯ 1
629-
◯ 2
630-
◯ 3
631-
◯ 4
632-
◯ 5
633-
◯ 6
634-
◯ 7"
635-
`);
636-
637-
events.keypress('enter');
638-
await expect(answer).resolves.toEqual([]);
639-
expect(getScreen()).toMatchInlineSnapshot('"✔ Select a number"');
640-
});
641-
642-
it('allow customizing help tip', async () => {
643-
const { answer, events, getScreen } = await render(checkbox, {
644-
message: 'Select a number',
645-
choices: numberedChoices,
646-
instructions:
647-
' (Pulse <space> para seleccionar, <a> para alternar todos, <i> para invertir selección, y <enter> para continuar)',
648-
});
649-
650-
expect(getScreen()).toMatchInlineSnapshot(`
651-
"? Select a number
652-
❯◯ 1
653-
◯ 2
654-
◯ 3
655-
◯ 4
656-
◯ 5
657-
◯ 6
658-
◯ 7
659-
660-
(Pulse <space> para seleccionar, <a> para alternar todos, <i> para invertir
661-
selección, y <enter> para continuar)"
662-
`);
663-
664-
events.keypress('enter');
665-
await expect(answer).resolves.toEqual([]);
666-
expect(getScreen()).toMatchInlineSnapshot('"✔ Select a number"');
667-
});
668-
669619
it('throws if all choices are disabled', async () => {
670620
const { answer } = await render(checkbox, {
671621
message: 'Select a number',
@@ -969,14 +919,13 @@ describe('checkbox prompt', () => {
969919
});
970920
});
971921

972-
describe('theme: helpMode', () => {
922+
describe('theme: keysHelpTip', () => {
973923
const scrollTip = '↑↓ navigate • space select • a all • i invert • ⏎ submit';
974924

975-
it('helpMode: auto', async () => {
925+
it('keysHelpTip: show help by default', async () => {
976926
const { answer, events, getScreen } = await render(checkbox, {
977927
message: 'Select a number',
978928
choices: numberedChoices,
979-
theme: { helpMode: 'auto' },
980929
});
981930

982931
expect(getScreen()).toMatchInlineSnapshot(`
@@ -994,45 +943,21 @@ describe('checkbox prompt', () => {
994943
expect(getScreen()).toContain(scrollTip);
995944

996945
events.keypress('down');
997-
expect(getScreen()).toMatchInlineSnapshot(`
998-
"? Select a number
999-
◯ 1
1000-
❯◯ 2
1001-
◯ 3
1002-
◯ 4
1003-
◯ 5
1004-
◯ 6
1005-
◯ 7
1006-
1007-
↑↓ navigate • space select • a all • i invert • ⏎ submit"
1008-
`);
1009-
expect(getScreen()).toContain(scrollTip);
1010-
1011946
events.keypress('space');
1012-
expect(getScreen()).toMatchInlineSnapshot(`
1013-
"? Select a number
1014-
◯ 1
1015-
❯◉ 2
1016-
◯ 3
1017-
◯ 4
1018-
◯ 5
1019-
◯ 6
1020-
◯ 7
1021-
1022-
↑↓ navigate • space select • a all • i invert • ⏎ submit"
1023-
`);
1024-
expect(getScreen()).toContain(scrollTip);
1025-
1026947
events.keypress('enter');
1027948
await expect(answer).resolves.toEqual([2]);
1028949
expect(getScreen()).toMatchInlineSnapshot(`"✔ Select a number 2"`);
1029950
});
1030951

1031-
it('helpMode: always', async () => {
952+
it('keysHelpTip: hide help when returning undefined', async () => {
1032953
const { answer, events, getScreen } = await render(checkbox, {
1033954
message: 'Select a number',
1034955
choices: numberedChoices,
1035-
theme: { helpMode: 'always' },
956+
theme: {
957+
style: {
958+
keysHelpTip: () => undefined,
959+
},
960+
},
1036961
});
1037962

1038963
expect(getScreen()).toMatchInlineSnapshot(`
@@ -1043,11 +968,9 @@ describe('checkbox prompt', () => {
1043968
◯ 4
1044969
◯ 5
1045970
◯ 6
1046-
◯ 7
1047-
1048-
↑↓ navigate • space select • a all • i invert • ⏎ submit"
971+
◯ 7"
1049972
`);
1050-
expect(getScreen()).toContain(scrollTip);
973+
expect(getScreen()).not.toContain(scrollTip);
1051974

1052975
events.keypress('down');
1053976
expect(getScreen()).toMatchInlineSnapshot(`
@@ -1058,11 +981,9 @@ describe('checkbox prompt', () => {
1058981
◯ 4
1059982
◯ 5
1060983
◯ 6
1061-
◯ 7
1062-
1063-
↑↓ navigate • space select • a all • i invert • ⏎ submit"
984+
◯ 7"
1064985
`);
1065-
expect(getScreen()).toContain(scrollTip);
986+
expect(getScreen()).not.toContain(scrollTip);
1066987

1067988
events.keypress('space');
1068989
expect(getScreen()).toMatchInlineSnapshot(`
@@ -1073,22 +994,25 @@ describe('checkbox prompt', () => {
1073994
◯ 4
1074995
◯ 5
1075996
◯ 6
1076-
◯ 7
1077-
1078-
↑↓ navigate • space select • a all • i invert • ⏎ submit"
997+
◯ 7"
1079998
`);
1080-
expect(getScreen()).toContain(scrollTip);
999+
expect(getScreen()).not.toContain(scrollTip);
10811000

10821001
events.keypress('enter');
10831002
await expect(answer).resolves.toEqual([2]);
10841003
expect(getScreen()).toMatchInlineSnapshot(`"✔ Select a number 2"`);
10851004
});
10861005

1087-
it('helpMode: never', async () => {
1006+
it('keysHelpTip: custom help text', async () => {
1007+
const customHelpText = 'Pulse <space> para seleccionar, y <enter> para continuar';
10881008
const { answer, events, getScreen } = await render(checkbox, {
10891009
message: 'Select a number',
10901010
choices: numberedChoices,
1091-
theme: { helpMode: 'never' },
1011+
theme: {
1012+
style: {
1013+
keysHelpTip: () => customHelpText,
1014+
},
1015+
},
10921016
});
10931017

10941018
expect(getScreen()).toMatchInlineSnapshot(`
@@ -1099,36 +1023,14 @@ describe('checkbox prompt', () => {
10991023
◯ 4
11001024
◯ 5
11011025
◯ 6
1102-
◯ 7"
1103-
`);
1104-
expect(getScreen()).not.toContain(scrollTip);
1026+
◯ 7
11051027
1106-
events.keypress('down');
1107-
expect(getScreen()).toMatchInlineSnapshot(`
1108-
"? Select a number
1109-
◯ 1
1110-
❯◯ 2
1111-
◯ 3
1112-
◯ 4
1113-
◯ 5
1114-
◯ 6
1115-
◯ 7"
1028+
Pulse <space> para seleccionar, y <enter> para continuar"
11161029
`);
1117-
expect(getScreen()).not.toContain(scrollTip);
1030+
expect(getScreen()).toContain(customHelpText);
11181031

1032+
events.keypress('down');
11191033
events.keypress('space');
1120-
expect(getScreen()).toMatchInlineSnapshot(`
1121-
"? Select a number
1122-
◯ 1
1123-
❯◉ 2
1124-
◯ 3
1125-
◯ 4
1126-
◯ 5
1127-
◯ 6
1128-
◯ 7"
1129-
`);
1130-
expect(getScreen()).not.toContain(scrollTip);
1131-
11321034
events.keypress('enter');
11331035
await expect(answer).resolves.toEqual([2]);
11341036
expect(getScreen()).toMatchInlineSnapshot(`"✔ Select a number 2"`);

packages/checkbox/src/index.ts

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ type CheckboxTheme = {
3737
description: (text: string) => string;
3838
keysHelpTip: (keys: [key: string, action: string][]) => string | undefined;
3939
};
40-
/** @deprecated Use theme.style.keysHelpTip instead */
41-
helpMode: 'always' | 'never' | 'auto';
4240
keybindings: ReadonlyArray<Keybinding>;
4341
};
4442

@@ -63,7 +61,6 @@ const checkboxTheme: CheckboxTheme = {
6361
.map(([key, action]) => `${styleText('bold', key)} ${styleText('dim', action)}`)
6462
.join(styleText('dim', ' • ')),
6563
},
66-
helpMode: 'always',
6764
keybindings: [],
6865
};
6966

@@ -97,8 +94,6 @@ type CheckboxConfig<
9794
message: string;
9895
prefix?: string;
9996
pageSize?: number;
100-
/** @deprecated Use theme.style.keysHelpTip instead */
101-
instructions?: string | boolean;
10297
choices: ChoicesObject extends ReadonlyArray<string | Separator>
10398
? ChoicesObject
10499
: ReadonlyArray<Choice<Value> | Separator>;
@@ -168,14 +163,7 @@ function normalizeChoices<Value>(
168163

169164
export default createPrompt(
170165
<Value>(config: CheckboxConfig<Value>, done: (value: Array<Value>) => void) => {
171-
const {
172-
// eslint-disable-next-line @typescript-eslint/no-deprecated
173-
instructions,
174-
pageSize = 7,
175-
loop = true,
176-
required,
177-
validate = () => true,
178-
} = config;
166+
const { pageSize = 7, loop = true, required, validate = () => true } = config;
179167
const shortcuts = { all: 'a', invert: 'i', ...config.shortcuts };
180168
const theme = makeTheme<CheckboxTheme>(checkboxTheme, config.theme);
181169
const { keybindings } = theme;
@@ -294,23 +282,15 @@ export default createPrompt(
294282
return [prefix, message, answer].filter(Boolean).join(' ');
295283
}
296284

297-
let helpLine: string | undefined;
298-
// eslint-disable-next-line @typescript-eslint/no-deprecated
299-
if (theme.helpMode !== 'never' && instructions !== false) {
300-
if (typeof instructions === 'string') {
301-
helpLine = instructions;
302-
} else {
303-
const keys: [string, string][] = [
304-
['↑↓', 'navigate'],
305-
['space', 'select'],
306-
];
307-
if (shortcuts.all) keys.push([shortcuts.all, 'all']);
308-
if (shortcuts.invert) keys.push([shortcuts.invert, 'invert']);
309-
keys.push(['⏎', 'submit']);
310-
311-
helpLine = theme.style.keysHelpTip(keys);
312-
}
313-
}
285+
const keys: [string, string][] = [
286+
['↑↓', 'navigate'],
287+
['space', 'select'],
288+
];
289+
if (shortcuts.all) keys.push([shortcuts.all, 'all']);
290+
if (shortcuts.invert) keys.push([shortcuts.invert, 'invert']);
291+
keys.push(['⏎', 'submit']);
292+
293+
const helpLine = theme.style.keysHelpTip(keys);
314294

315295
const lines = [
316296
[prefix, message].filter(Boolean).join(' '),

packages/core/core.test.ts

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ import {
1616
isSpaceKey,
1717
Separator,
1818
AbortPromptError,
19-
CancelPromptError,
2019
ValidationError,
2120
HookError,
2221
type KeypressEvent,
2322
makeTheme,
2423
type Status,
2524
} from './src/index.ts';
26-
import { cursorHide, cursorShow, eraseLines } from '@inquirer/ansi';
25+
import { cursorShow, eraseLines } from '@inquirer/ansi';
2726

2827
describe('createPrompt()', () => {
2928
it('onKeypress: allow to implement custom behavior on keypress', async () => {
@@ -463,34 +462,6 @@ describe('createPrompt()', () => {
463462
await expect(answer).resolves.toEqual('');
464463
});
465464

466-
it('allow cancelling the prompt', async () => {
467-
const Prompt = (config: { message: string }, done: (value: string) => void) => {
468-
useKeypress((key: KeypressEvent) => {
469-
if (isEnterKey(key)) {
470-
done('done');
471-
}
472-
});
473-
474-
return `${config.message} ${cursorHide}`;
475-
};
476-
477-
const prompt = createPrompt(Prompt);
478-
const { answer, events, getFullOutput } = await render(prompt, {
479-
message: 'Question',
480-
});
481-
482-
// eslint-disable-next-line @typescript-eslint/no-deprecated
483-
answer.cancel();
484-
events.keypress('enter');
485-
486-
await expect(answer).rejects.toThrow(CancelPromptError);
487-
488-
const output = getFullOutput();
489-
expect(output).toContain(cursorHide);
490-
expect(output).toContain(cursorShow);
491-
expect(output.lastIndexOf(cursorHide)).toBeLessThan(output.lastIndexOf(cursorShow));
492-
});
493-
494465
it('allow cleaning the prompt after completion', async () => {
495466
const Prompt = (config: { message: string }, done: (value: string) => void) => {
496467
useKeypress((key: KeypressEvent) => {
@@ -586,30 +557,6 @@ describe('createPrompt()', () => {
586557
});
587558
});
588559

589-
it('allow cancelling the prompt multiple times', async () => {
590-
const Prompt = (config: { message: string }, done: (value: string) => void) => {
591-
useKeypress((key: KeypressEvent) => {
592-
if (isEnterKey(key)) {
593-
done('done');
594-
}
595-
});
596-
597-
return config.message;
598-
};
599-
600-
const prompt = createPrompt(Prompt);
601-
const { answer, events } = await render(prompt, { message: 'Question' });
602-
603-
// eslint-disable-next-line @typescript-eslint/no-deprecated
604-
answer.cancel();
605-
606-
// eslint-disable-next-line @typescript-eslint/no-deprecated
607-
answer.cancel();
608-
events.keypress('enter');
609-
610-
await expect(answer).rejects.toThrow(CancelPromptError);
611-
});
612-
613560
it('allow aborting the prompt using signals', async () => {
614561
const Prompt = (config: { message: string }, done: (value: string) => void) => {
615562
useKeypress((key: KeypressEvent) => {

0 commit comments

Comments
 (0)