File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ ' @tanstack/cli ' : patch
3+ ---
4+
5+ Fix blank project name submissions in interactive create prompts.
Original file line number Diff line number Diff line change @@ -67,12 +67,16 @@ export async function selectInstall(): Promise<boolean> {
6767export async function getProjectName ( ) : Promise < string > {
6868 const value = await text ( {
6969 message : 'Project name (leave empty to use current directory)' ,
70+ // Clack prints `undefined` on blank submit when placeholder is omitted.
71+ placeholder : '' ,
7072 validate ( value ) {
71- if ( isCurrentDirectoryProjectNameInput ( value ) ) {
73+ const projectName = value ?? ''
74+
75+ if ( isCurrentDirectoryProjectNameInput ( projectName ) ) {
7276 return
7377 }
7478
75- const { valid, error } = validateProjectName ( value )
79+ const { valid, error } = validateProjectName ( projectName )
7680 if ( ! valid ) {
7781 return error
7882 }
@@ -84,7 +88,7 @@ export async function getProjectName(): Promise<string> {
8488 process . exit ( 0 )
8589 }
8690
87- return value . trim ( )
91+ return ( value ?? '' ) . trim ( )
8892}
8993
9094export async function selectPackageManager ( ) : Promise < PackageManager > {
Original file line number Diff line number Diff line change @@ -43,11 +43,26 @@ describe('getProjectName', () => {
4343 expect ( textOptions . message ) . toBe (
4444 'Project name (leave empty to use current directory)' ,
4545 )
46- expect ( textOptions . placeholder ) . toBeUndefined ( )
46+ expect ( textOptions . placeholder ) . toBe ( '' )
4747 expect ( textOptions . validate ?.( '' ) ) . toBeUndefined ( )
4848 expect ( textOptions . validate ?.( '.' ) ) . toBeUndefined ( )
4949 } )
5050
51+ it ( 'should handle undefined project name values as current directory creation' , async ( ) => {
52+ const textSpy = vi
53+ . spyOn ( clack , 'text' )
54+ . mockImplementation ( async ( ) => undefined as unknown as string )
55+ vi . spyOn ( clack , 'isCancel' ) . mockImplementation ( ( ) => false )
56+
57+ const projectName = await getProjectName ( )
58+ const textOptions = textSpy . mock . calls [ 0 ] ! [ 0 ] as {
59+ validate ?: ( value ?: string ) => string | undefined
60+ }
61+
62+ expect ( projectName ) . toBe ( '' )
63+ expect ( textOptions . validate ?.( undefined ) ) . toBeUndefined ( )
64+ } )
65+
5166 it ( 'should exit on cancel' , async ( ) => {
5267 vi . spyOn ( clack , 'text' ) . mockImplementation ( async ( ) => 'Cancelled' )
5368 vi . spyOn ( clack , 'isCancel' ) . mockImplementation ( ( ) => true )
You can’t perform that action at this time.
0 commit comments