@@ -433,16 +433,35 @@ export function prettyPuppeteerInstallGuidance(
433433 // ignore expansion errors
434434 }
435435
436- // Inject --path "<cacheDir>" into Puppeteer install commands if not present
436+ // Normalize browser subdir for our binaries layout (shared across installers)
437+ let browserNorm = ''
438+
439+ if ( browser === 'chromium-based' ) browserNorm = 'chromium'
440+ if ( browser === 'gecko-based' ) browserNorm = 'firefox'
441+ if (
442+ browser === 'chrome' ||
443+ browser === 'chromium' ||
444+ browser === 'firefox' ||
445+ browser === 'edge'
446+ ) {
447+ browserNorm = browser
448+ }
449+ // default to chrome for unknown
450+ browserNorm = 'chromium'
451+
452+ const finalCachePath =
453+ browserNorm && cacheDir ? path . join ( cacheDir , browserNorm ) : cacheDir
454+
455+ // Inject install destinations for Puppeteer/Playwright to land in our cache
437456 try {
438- if ( cacheDir && cacheDir . trim ( ) . length > 0 ) {
457+ if ( finalCachePath && finalCachePath . trim ( ) . length > 0 ) {
439458 const lines = cleaned . split ( / \r ? \n / )
440459 // Puppeteer path injection
441460 const idx = lines . findIndex ( ( l ) =>
442461 / n p x \s + @ p u p p e t e e r \/ b r o w s e r s \s + i n s t a l l \s + / i. test ( l )
443462 )
444463 if ( idx !== - 1 && ! / - - p a t h \s + / i. test ( lines [ idx ] ) ) {
445- lines [ idx ] = `${ lines [ idx ] . trim ( ) } --path "${ cacheDir } "`
464+ lines [ idx ] = `${ lines [ idx ] . trim ( ) } --path "${ finalCachePath } "`
446465 cleaned = lines . join ( '\n' )
447466 }
448467 // Playwright custom install dir via PLAYWRIGHT_BROWSERS_PATH
@@ -452,32 +471,12 @@ export function prettyPuppeteerInstallGuidance(
452471 )
453472
454473 if ( pwIdx !== - 1 ) {
455- // Normalize browser subdir for our binaries layout
456- const browserNorm = ( ( ) => {
457- const b = String ( browser || '' ) . toLowerCase ( )
458- if ( b === 'chromium-based' ) return 'chromium'
459- if ( b === 'gecko-based' ) return 'firefox'
460- if (
461- b === 'chrome' ||
462- b === 'chromium' ||
463- b === 'firefox' ||
464- b === 'edge'
465- )
466- return b
467- // default to chrome for unknown
468- return 'chrome'
469- } ) ( )
470- const finalPath =
471- browserNorm && cacheDir
472- ? path . join ( cacheDir , browserNorm )
473- : cacheDir
474-
475- if ( finalPath && finalPath . trim ( ) . length > 0 ) {
474+ if ( finalCachePath && finalCachePath . trim ( ) . length > 0 ) {
476475 const cmd = lines [ pwIdx ] . trim ( )
477476 const withEnv =
478477 process . platform === 'win32'
479- ? `set PLAYWRIGHT_BROWSERS_PATH="${ finalPath } " && ${ cmd } `
480- : `PLAYWRIGHT_BROWSERS_PATH="${ finalPath } " ${ cmd } `
478+ ? `set PLAYWRIGHT_BROWSERS_PATH="${ finalCachePath } " && ${ cmd } `
479+ : `PLAYWRIGHT_BROWSERS_PATH="${ finalCachePath } " ${ cmd } `
481480 lines [ pwIdx ] = withEnv
482481 cleaned = lines . join ( '\n' )
483482 }
@@ -491,8 +490,8 @@ export function prettyPuppeteerInstallGuidance(
491490 }
492491
493492 body . push ( cleaned )
494- if ( cacheDir ) {
495- body . push ( `${ dim ( 'INSTALL PATH' ) } ${ colors . underline ( cacheDir ) } ` )
493+ if ( finalCachePath ) {
494+ body . push ( `${ dim ( 'INSTALL PATH' ) } ${ colors . underline ( finalCachePath ) } ` )
496495 }
497496 return body . join ( '\n' ) + '\n'
498497}
0 commit comments