@@ -377,7 +377,6 @@ const displayScriptList = (installScripts, log) => {
377377
378378 log . log ( ` ${ continueOption } . Continue to regular installation` ) ;
379379 log . log ( ` ${ exitOption } . Exit installation` ) ;
380- log . log ( ` e. Edit selected script before running` ) ;
381380} ;
382381
383382const handleSingleScript = async ( script , log , yesFlag = false ) => {
@@ -431,51 +430,54 @@ const handleMultipleScripts = async (installScripts, log, yesFlag = false) => {
431430 } ) ;
432431
433432 const choice = await new Promise ( ( resolve ) => {
434- rli . question ( `${ colors . fg . yellow } Preview install script (1-${ EXIT_OPTION } ) or 'e' to edit :${ colors . reset } ` , ( ans ) => {
433+ rli . question ( `${ colors . fg . yellow } Select install script (1-${ EXIT_OPTION } ):${ colors . reset } ` , ( ans ) => {
435434 rli . close ( ) ;
436435 resolve ( ans . trim ( ) . toLowerCase ( ) ) ;
437436 } ) ;
438437 } ) ;
439438
440- if ( choice === 'e' ) {
441- const scriptChoice = await promptChoice (
442- `Which script would you like to edit? (1-${ installScripts . length } ): ` ,
443- installScripts . length ,
444- yesFlag
445- ) ;
446- const scriptToEdit = installScripts [ scriptChoice - 1 ] ;
447- const editedScript = await editScriptInEditor ( scriptToEdit ) ;
448- displayScriptPreview ( editedScript , log ) ;
449-
450- const shouldRun = await confirm (
451- "Run this edited install script (y) or choose a different one (n)?" ,
452- "y" ,
453- yesFlag
454- ) ;
455-
456- if ( shouldRun ) return editedScript ;
457- // Continue loop if user chooses 'n'
458- } else {
459- const numericChoice = parseInt ( choice ) ;
460- if ( numericChoice <= installScripts . length ) {
461- const script = installScripts [ numericChoice - 1 ] ;
462- displayScriptPreview ( script , log ) ;
439+ const numericChoice = parseInt ( choice ) ;
463440
464- const shouldRun = await confirm (
465- "Run this install script (y) or choose a different one (n)?" ,
466- "y" ,
467- yesFlag
468- ) ;
441+ if ( isNaN ( numericChoice ) ) {
442+ console . log ( `${ colors . fg . red } Invalid choice. Please enter a number.${ colors . reset } ` ) ;
443+ continue ;
444+ }
469445
470- if ( shouldRun ) return script ;
471- // Continue loop if user chooses 'n'
472- } else if ( numericChoice === CONTINUE_OPTION ) {
473- return null ; // Continue to regular installation
474- } else if ( numericChoice === EXIT_OPTION ) {
475- throw new Error ( "Installation aborted by user" ) ;
476- } else {
477- console . log ( `${ colors . fg . red } Invalid choice. Please try again.${ colors . reset } ` ) ;
446+ if ( numericChoice === CONTINUE_OPTION ) {
447+ return null ; // Continue to regular installation
448+ } else if ( numericChoice === EXIT_OPTION ) {
449+ throw new Error ( "Installation aborted by user" ) ;
450+ } else if ( numericChoice > 0 && numericChoice <= installScripts . length ) {
451+ let script = installScripts [ numericChoice - 1 ] ;
452+ displayScriptPreview ( script , log ) ;
453+
454+ let actionLoop = true ;
455+ while ( actionLoop ) {
456+ const rliAction = readline . createInterface ( {
457+ input : process . stdin ,
458+ output : process . stdout ,
459+ } ) ;
460+
461+ const action = await new Promise ( ( resolve ) => {
462+ rliAction . question ( `${ colors . fg . yellow } Run (y), Edit (e), or Select Different (n)?${ colors . reset } ` , ( ans ) => {
463+ rliAction . close ( ) ;
464+ resolve ( ans . trim ( ) . toLowerCase ( ) ) ;
465+ } ) ;
466+ } ) ;
467+
468+ if ( action === 'y' || action === 'yes' ) {
469+ return script ;
470+ } else if ( action === 'n' || action === 'no' ) {
471+ actionLoop = false ;
472+ } else if ( action === 'e' ) {
473+ script = await editScriptInEditor ( script ) ;
474+ displayScriptPreview ( script , log ) ;
475+ } else {
476+ // Optional: Handle invalid input if needed, strictly asking for y/e/n
477+ }
478478 }
479+ } else {
480+ console . log ( `${ colors . fg . red } Invalid choice. Please try again.${ colors . reset } ` ) ;
479481 }
480482 }
481483} ;
@@ -506,6 +508,7 @@ const handleGitHubSource = async (source, platformInfo, capabilities, log, yesFl
506508 const previousInstallation = getInstallation ( source . repo ) ;
507509 const preferredMethod = previousInstallation ?. installation ?. preferredMethod ;
508510 const previousAssetPattern = previousInstallation ?. installation ?. selectedAssetPattern ;
511+ const storedScript = previousInstallation ?. installation ?. script ;
509512
510513 if ( isUpdate && preferredMethod ) {
511514 log . debug ( `Previous installation used method: ${ preferredMethod } ` ) ;
@@ -538,21 +541,36 @@ const handleGitHubSource = async (source, platformInfo, capabilities, log, yesFl
538541 }
539542
540543 const selected = selectBestAsset ( assets , platformInfo , capabilities ) ;
541- const binaryScore = selected ? ( selected . points || 10 ) : 0 ;
544+ // Boost binary score significantly if we found a compatible binary
545+ // This ensures we prioritize direct binary downloads over install scripts unless strict overrides exist
546+ const binaryScore = selected ? ( selected . points || 10 ) + 100 : 0 ;
542547
543548 const skipScriptDetection = isUpdate && preferredMethod &&
544549 ! [ "script" , "installer_script" ] . includes ( preferredMethod ) ;
545550
546551 let installScripts = [ ] ;
547- if ( ! skipScriptDetection ) {
552+ if ( isUpdate && preferredMethod === "script" && storedScript ) {
553+ log . debug ( "Using stored install script from previous installation" ) ;
554+ installScripts = [
555+ {
556+ code : storedScript ,
557+ source : "stored script" ,
558+ score : 1000 ,
559+ } ,
560+ ] ;
561+ } else if ( ! skipScriptDetection ) {
548562 installScripts = await findInstallScripts (
549563 source . owner ,
550564 source . repo ,
551565 body ,
552566 ) ;
553- log . debug ( `Found ${ installScripts . length } platform-compatible install scripts` ) ;
567+ log . debug (
568+ `Found ${ installScripts . length } platform-compatible install scripts` ,
569+ ) ;
554570 } else {
555- log . debug ( `Skipping script detection - previous install used: ${ preferredMethod } ` ) ;
571+ log . debug (
572+ `Skipping script detection - previous install used: ${ preferredMethod } ` ,
573+ ) ;
556574 }
557575
558576 const installerScript = assets . find ( ( i ) => i . name . includes ( "installer.sh" ) ) ;
@@ -608,6 +626,7 @@ const handleGitHubSource = async (source, platformInfo, capabilities, log, yesFl
608626 const selectedScript = await selectInstallScript ( installScripts , log , yesFlag ) ;
609627
610628 if ( selectedScript ) {
629+ const processedCode = processInstallSnippetReplacements ( selectedScript . code ) ;
611630 executeInstallScript ( selectedScript , log ) ;
612631
613632 const installRecord = createInstallationRecord (
@@ -617,6 +636,7 @@ const handleGitHubSource = async (source, platformInfo, capabilities, log, yesFl
617636 name : source . repo ,
618637 installMethod : "script" ,
619638 preferredMethod : "script" ,
639+ script : processedCode ,
620640 version : tag ,
621641 commit : commit ,
622642 prerelease : prerelease ,
0 commit comments