22import 'zx/globals' ;
33import { getInstalledSolanaVersion , getSolanaVersion } from './utils.mjs' ;
44
5- const installedVersion = await getInstalledSolanaVersion ( ) ;
65const expectedVersion = getSolanaVersion ( ) ;
7-
8- if ( installedVersion === expectedVersion ) {
9- echo (
10- chalk . green ( '[ SUCCESS ]' ) ,
11- `The expected Solana version ${ expectedVersion } is installed.`
12- ) ;
13- process . exit ( 0 ) ;
14- }
6+ const installedVersion = await getInstalledSolanaVersion ( ) ;
157
168const installPath = path . join (
179 os . homedir ( ) ,
@@ -29,28 +21,54 @@ const releasePath = path.join(
2921const activeReleasePath = path . join ( installPath , 'active_release' ) ;
3022const hasRelease = await fs . exists ( releasePath ) ;
3123
32- if ( hasRelease ) {
24+ if ( ! installedVersion ) {
25+ echo (
26+ chalk . red ( '[ ERROR ]' ) ,
27+ `No Solana installation found. Solana ${ expectedVersion } is required for this project.`
28+ ) ;
29+ await askToInstallSolana ( expectedVersion ) ;
30+ } else if ( installedVersion === expectedVersion ) {
31+ echo (
32+ chalk . green ( '[ SUCCESS ]' ) ,
33+ `The expected Solana version ${ expectedVersion } is installed.`
34+ ) ;
35+ } else if ( hasRelease ) {
3336 await $ `rm -f "${ activeReleasePath } "` ;
3437 await $ `ln -s "${ releasePath } " "${ activeReleasePath } "` ;
3538 echo (
3639 chalk . green ( '[ SUCCESS ]' ) ,
3740 `Successfully switched from Solana version ${ installedVersion } to ${ expectedVersion } to match the project's requirements.`
3841 ) ;
39- process . exit ( 0 ) ;
42+ } else {
43+ echo (
44+ chalk . yellow ( '[ WARNING ]' ) ,
45+ `Cannot switch from Solana version ${ installedVersion } to ${ expectedVersion } because it is not installed.`
46+ ) ;
47+ await askToInstallSolana ( expectedVersion ) ;
4048}
4149
42- echo (
43- chalk . yellow ( '[ WARNING ]' ) ,
44- `Cannot switch from Solana version ${ installedVersion } to ${ expectedVersion } because it is not installed.`
45- ) ;
46-
47- const installRelease = await question ( 'Should we install it now? [y/N] ' ) ;
48- if ( installRelease === 'y' ) {
49- echo ( `Installing Solana ${ expectedVersion } ...` ) ;
50- await $ `sh -c "$(curl -sSfL https://release.solana.com/v${ expectedVersion } /install)"` ;
50+ async function askToInstallSolana ( version ) {
51+ const installRelease = await question ( 'Should we install it now? [y/N] ' ) ;
52+ if ( installRelease === 'y' ) {
53+ await installSolana ( version ) ;
54+ echo (
55+ chalk . green ( '[ SUCCESS ]' ) ,
56+ `Successfully installed Solana version ${ version } .`
57+ ) ;
58+ } else {
59+ process . exit ( 1 ) ;
60+ }
5161}
5262
53- echo (
54- chalk . green ( '[ SUCCESS ]' ) ,
55- `Successfully switched from Solana version ${ installedVersion } to ${ expectedVersion } to match the project's requirements.`
56- ) ;
63+ async function installSolana ( version ) {
64+ echo ( `Installing Solana ${ version } ...` ) ;
65+ const cutoff = '1.18.19' ;
66+ const isBeforeCutoff =
67+ ( await $ `[[ "$(printf '%s\n' "${ cutoff } " "${ version } " | sort -V | head -n1)" = "${ version } " ]] && [[ "${ cutoff } " != "${ version } " ]]` . quiet ( )
68+ . exitCode ) == 0 ;
69+ if ( isBeforeCutoff ) {
70+ await $ `sh -c "$(curl -sSfL https://release.solana.com/v${ version } /install)"` ;
71+ } else {
72+ await $ `sh -c "$(curl -sSfL https://release.anza.xyz/v${ version } /install)"` ;
73+ }
74+ }
0 commit comments