@@ -337,31 +337,41 @@ export async function parseOptionsAndRunCLI(argsToParse: string[]) {
337337 args [ 'wordpressInstallMode' ] = 'do-not-attempt-installing' ;
338338 }
339339
340- if ( args . wp !== undefined && ! isValidWordPressSlug ( args . wp ) ) {
340+ if (
341+ args [ 'wp' ] !== undefined &&
342+ typeof args [ 'wp' ] === 'string' &&
343+ ! isValidWordPressSlug ( args [ 'wp' ] )
344+ ) {
341345 try {
342346 // Check if is valid URL
343- new URL ( args . wp ) ;
347+ new URL ( args [ 'wp' ] ) ;
344348 } catch {
345349 throw new Error (
346350 'Unrecognized WordPress version. Please use "latest", a URL, or a numeric version such as "6.2", "6.0.1", "6.2-beta1", or "6.2-RC1"'
347351 ) ;
348352 }
349353 }
350354
351- if ( args [ 'site-url' ] !== undefined && args [ 'site-url' ] !== '' ) {
355+ const siteUrlArg = args [ 'site-url' ] ;
356+ if (
357+ typeof siteUrlArg === 'string' &&
358+ siteUrlArg . trim ( ) !== ''
359+ ) {
352360 try {
353- new URL ( args [ 'site-url' ] ) ;
361+ new URL ( siteUrlArg ) ;
354362 } catch {
355363 throw new Error (
356- `Invalid site-url "${ args [ 'site-url' ] } ". Please provide a valid URL (e.g., http://localhost:8080 or https://example.com)`
364+ `Invalid site-url "${ siteUrlArg } ". Please provide a valid URL (e.g., http://localhost:8080 or https://example.com)`
357365 ) ;
358366 }
359367 }
360368
361369 if ( args [ 'auto-mount' ] ) {
362370 let autoMountIsDir = false ;
363371 try {
364- const autoMountStats = fs . statSync ( args [ 'auto-mount' ] ) ;
372+ const autoMountStats = fs . statSync (
373+ args [ 'auto-mount' ] as string
374+ ) ;
365375 autoMountIsDir = autoMountStats . isDirectory ( ) ;
366376 } catch {
367377 autoMountIsDir = false ;
@@ -381,7 +391,11 @@ export async function parseOptionsAndRunCLI(argsToParse: string[]) {
381391 'The --experimental-multi-worker flag is only supported when running the server command.'
382392 ) ;
383393 }
384- if ( args [ 'experimental-multi-worker' ] <= 1 ) {
394+ if (
395+ args [ 'experimental-multi-worker' ] !== undefined &&
396+ typeof args [ 'experimental-multi-worker' ] === 'number' &&
397+ args [ 'experimental-multi-worker' ] <= 1
398+ ) {
385399 throw new Error (
386400 'The --experimental-multi-worker flag must be a positive integer greater than 1.'
387401 ) ;
@@ -453,10 +467,13 @@ export async function parseOptionsAndRunCLI(argsToParse: string[]) {
453467 const cliArgs = {
454468 ...args ,
455469 command,
456- mount : [ ...( args . mount || [ ] ) , ...( args [ 'mount-dir' ] || [ ] ) ] ,
470+ mount : [
471+ ...( ( args [ 'mount' ] as Mount [ ] ) || [ ] ) ,
472+ ...( ( args [ 'mount-dir' ] as Mount [ ] ) || [ ] ) ,
473+ ] ,
457474 'mount-before-install' : [
458- ...( args [ 'mount-before-install' ] || [ ] ) ,
459- ...( args [ 'mount-dir-before-install' ] || [ ] ) ,
475+ ...( ( args [ 'mount-before-install' ] as Mount [ ] ) || [ ] ) ,
476+ ...( ( args [ 'mount-dir-before-install' ] as Mount [ ] ) || [ ] ) ,
460477 ] ,
461478 } as RunCLIArgs ;
462479
0 commit comments