From e2c22de81667fe991e9d754c83dd8a18c08c3496 Mon Sep 17 00:00:00 2001 From: dipesh Date: Mon, 8 Jun 2026 22:07:34 -0400 Subject: [PATCH] Fix empty project name prompt crash --- .changeset/project-name-undefined-input.md | 5 +++++ packages/cli/src/ui-prompts.ts | 2 +- packages/cli/src/utils.ts | 4 ++-- packages/cli/tests/ui-prompts.test.ts | 9 +++++++++ 4 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 .changeset/project-name-undefined-input.md diff --git a/.changeset/project-name-undefined-input.md b/.changeset/project-name-undefined-input.md new file mode 100644 index 00000000..ce66963f --- /dev/null +++ b/.changeset/project-name-undefined-input.md @@ -0,0 +1,5 @@ +--- +"@tanstack/cli": patch +--- + +Handle empty interactive project name input without crashing. diff --git a/packages/cli/src/ui-prompts.ts b/packages/cli/src/ui-prompts.ts index a4c6032c..71c1dbe5 100644 --- a/packages/cli/src/ui-prompts.ts +++ b/packages/cli/src/ui-prompts.ts @@ -84,7 +84,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/src/utils.ts b/packages/cli/src/utils.ts index ab36e87d..f5945bba 100644 --- a/packages/cli/src/utils.ts +++ b/packages/cli/src/utils.ts @@ -26,8 +26,8 @@ export function getCurrentDirectoryPackageName(): string { return getDirectoryPackageName(process.cwd()) } -export function isCurrentDirectoryProjectNameInput(name: string): boolean { - const normalized = name.trim() +export function isCurrentDirectoryProjectNameInput(name?: string): boolean { + const normalized = name?.trim() ?? '' return normalized === '' || normalized === '.' } diff --git a/packages/cli/tests/ui-prompts.test.ts b/packages/cli/tests/ui-prompts.test.ts index 5e1b9857..14756d7d 100644 --- a/packages/cli/tests/ui-prompts.test.ts +++ b/packages/cli/tests/ui-prompts.test.ts @@ -48,6 +48,15 @@ describe('getProjectName', () => { expect(textOptions.validate?.('.')).toBeUndefined() }) + it('should treat undefined text input as the current directory', async () => { + vi.spyOn(clack, 'text').mockImplementation(async () => undefined) + vi.spyOn(clack, 'isCancel').mockImplementation(() => false) + + const projectName = await getProjectName() + + expect(projectName).toBe('') + }) + it('should exit on cancel', async () => { vi.spyOn(clack, 'text').mockImplementation(async () => 'Cancelled') vi.spyOn(clack, 'isCancel').mockImplementation(() => true)