From 0d480d46bc0044f03847634182ef59b98fe30d97 Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Mon, 8 Jun 2026 23:27:25 -0600 Subject: [PATCH] Fix blank project name prompt submit --- .changeset/quick-humans-sort.md | 5 +++++ packages/cli/src/ui-prompts.ts | 10 +++++++--- packages/cli/tests/ui-prompts.test.ts | 17 ++++++++++++++++- 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 .changeset/quick-humans-sort.md diff --git a/.changeset/quick-humans-sort.md b/.changeset/quick-humans-sort.md new file mode 100644 index 00000000..ef323ebb --- /dev/null +++ b/.changeset/quick-humans-sort.md @@ -0,0 +1,5 @@ +--- +'@tanstack/cli': patch +--- + +Fix blank project name submissions in interactive create prompts. diff --git a/packages/cli/src/ui-prompts.ts b/packages/cli/src/ui-prompts.ts index a4c6032c..e62af4ce 100644 --- a/packages/cli/src/ui-prompts.ts +++ b/packages/cli/src/ui-prompts.ts @@ -67,12 +67,16 @@ export async function selectInstall(): Promise { export async function getProjectName(): Promise { const value = await text({ message: 'Project name (leave empty to use current directory)', + // Clack prints `undefined` on blank submit when placeholder is omitted. + placeholder: '', validate(value) { - if (isCurrentDirectoryProjectNameInput(value)) { + const projectName = value ?? '' + + if (isCurrentDirectoryProjectNameInput(projectName)) { return } - const { valid, error } = validateProjectName(value) + const { valid, error } = validateProjectName(projectName) if (!valid) { return error } @@ -84,7 +88,7 @@ export async function getProjectName(): Promise { process.exit(0) } - return value.trim() + return (value ?? '').trim() } export async function selectPackageManager(): Promise { diff --git a/packages/cli/tests/ui-prompts.test.ts b/packages/cli/tests/ui-prompts.test.ts index 5e1b9857..6d34174b 100644 --- a/packages/cli/tests/ui-prompts.test.ts +++ b/packages/cli/tests/ui-prompts.test.ts @@ -43,11 +43,26 @@ describe('getProjectName', () => { expect(textOptions.message).toBe( 'Project name (leave empty to use current directory)', ) - expect(textOptions.placeholder).toBeUndefined() + expect(textOptions.placeholder).toBe('') expect(textOptions.validate?.('')).toBeUndefined() expect(textOptions.validate?.('.')).toBeUndefined() }) + it('should handle undefined project name values as current directory creation', async () => { + const textSpy = vi + .spyOn(clack, 'text') + .mockImplementation(async () => undefined as unknown as string) + vi.spyOn(clack, 'isCancel').mockImplementation(() => false) + + const projectName = await getProjectName() + const textOptions = textSpy.mock.calls[0]![0] as { + validate?: (value?: string) => string | undefined + } + + expect(projectName).toBe('') + expect(textOptions.validate?.(undefined)).toBeUndefined() + }) + it('should exit on cancel', async () => { vi.spyOn(clack, 'text').mockImplementation(async () => 'Cancelled') vi.spyOn(clack, 'isCancel').mockImplementation(() => true)