Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/password-empty-submit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clack/core": patch
---

Fix `password` prompt resolving to `undefined` on empty submit. It now normalizes an empty submission to `""`, matching the `text` prompt behavior and the documented `Promise<string | symbol>` return type.
5 changes: 5 additions & 0 deletions packages/core/src/prompts/password.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@ export default class PasswordPrompt extends Prompt<string> {
this.on('userInput', (input) => {
this._setValue(input);
});
this.on('finalize', () => {
if (this.value === undefined) {
this.value = '';
}
});
}
}
12 changes: 12 additions & 0 deletions packages/core/test/prompts/password.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ describe('PasswordPrompt', () => {
expect(output.buffer).to.deep.equal([cursor.hide, 'foo']);
});

test('returns empty string on empty submit', async () => {
const instance = new PasswordPrompt({
input,
output,
render: () => 'foo',
});
const resultPromise = instance.prompt();
input.emit('keypress', '', { name: 'return' });
const result = await resultPromise;
expect(result).to.equal('');
});

describe('cursor', () => {
test('can get cursor', () => {
const instance = new PasswordPrompt({
Expand Down
Loading