@@ -338,31 +338,41 @@ export async function parseOptionsAndRunCLI(argsToParse: string[]) {
338338 args [ 'wordpressInstallMode' ] = 'do-not-attempt-installing' ;
339339 }
340340
341- if ( args . wp !== undefined && ! isValidWordPressSlug ( args . wp ) ) {
341+ if (
342+ args [ 'wp' ] !== undefined &&
343+ typeof args [ 'wp' ] === 'string' &&
344+ ! isValidWordPressSlug ( args [ 'wp' ] )
345+ ) {
342346 try {
343347 // Check if is valid URL
344- new URL ( args . wp ) ;
348+ new URL ( args [ 'wp' ] ) ;
345349 } catch {
346350 throw new Error (
347351 '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"'
348352 ) ;
349353 }
350354 }
351355
352- if ( args [ 'site-url' ] !== undefined && args [ 'site-url' ] !== '' ) {
356+ const siteUrlArg = args [ 'site-url' ] ;
357+ if (
358+ typeof siteUrlArg === 'string' &&
359+ siteUrlArg . trim ( ) !== ''
360+ ) {
353361 try {
354- new URL ( args [ 'site-url' ] ) ;
362+ new URL ( siteUrlArg ) ;
355363 } catch {
356364 throw new Error (
357- `Invalid site-url "${ args [ 'site-url' ] } ". Please provide a valid URL (e.g., http://localhost:8080 or https://example.com)`
365+ `Invalid site-url "${ siteUrlArg } ". Please provide a valid URL (e.g., http://localhost:8080 or https://example.com)`
358366 ) ;
359367 }
360368 }
361369
362370 if ( args [ 'auto-mount' ] ) {
363371 let autoMountIsDir = false ;
364372 try {
365- const autoMountStats = fs . statSync ( args [ 'auto-mount' ] ) ;
373+ const autoMountStats = fs . statSync (
374+ args [ 'auto-mount' ] as string
375+ ) ;
366376 autoMountIsDir = autoMountStats . isDirectory ( ) ;
367377 } catch {
368378 autoMountIsDir = false ;
@@ -382,7 +392,11 @@ export async function parseOptionsAndRunCLI(argsToParse: string[]) {
382392 'The --experimental-multi-worker flag is only supported when running the server command.'
383393 ) ;
384394 }
385- if ( args [ 'experimental-multi-worker' ] <= 1 ) {
395+ if (
396+ args [ 'experimental-multi-worker' ] !== undefined &&
397+ typeof args [ 'experimental-multi-worker' ] === 'number' &&
398+ args [ 'experimental-multi-worker' ] <= 1
399+ ) {
386400 throw new Error (
387401 'The --experimental-multi-worker flag must be a positive integer greater than 1.'
388402 ) ;
@@ -454,10 +468,13 @@ export async function parseOptionsAndRunCLI(argsToParse: string[]) {
454468 const cliArgs = {
455469 ...args ,
456470 command,
457- mount : [ ...( args . mount || [ ] ) , ...( args [ 'mount-dir' ] || [ ] ) ] ,
471+ mount : [
472+ ...( ( args [ 'mount' ] as Mount [ ] ) || [ ] ) ,
473+ ...( ( args [ 'mount-dir' ] as Mount [ ] ) || [ ] ) ,
474+ ] ,
458475 'mount-before-install' : [
459- ...( args [ 'mount-before-install' ] || [ ] ) ,
460- ...( args [ 'mount-dir-before-install' ] || [ ] ) ,
476+ ...( ( args [ 'mount-before-install' ] as Mount [ ] ) || [ ] ) ,
477+ ...( ( args [ 'mount-dir-before-install' ] as Mount [ ] ) || [ ] ) ,
461478 ] ,
462479 } as RunCLIArgs ;
463480
0 commit comments