2
2
import 'zx/globals' ;
3
3
import { getInstalledSolanaVersion , getSolanaVersion } from './utils.mjs' ;
4
4
5
- const installedVersion = await getInstalledSolanaVersion ( ) ;
6
5
const 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 ( ) ;
15
7
16
8
const installPath = path . join (
17
9
os . homedir ( ) ,
@@ -29,28 +21,54 @@ const releasePath = path.join(
29
21
const activeReleasePath = path . join ( installPath , 'active_release' ) ;
30
22
const hasRelease = await fs . exists ( releasePath ) ;
31
23
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 ) {
33
36
await $ `rm -f "${ activeReleasePath } "` ;
34
37
await $ `ln -s "${ releasePath } " "${ activeReleasePath } "` ;
35
38
echo (
36
39
chalk . green ( '[ SUCCESS ]' ) ,
37
40
`Successfully switched from Solana version ${ installedVersion } to ${ expectedVersion } to match the project's requirements.`
38
41
) ;
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 ) ;
40
48
}
41
49
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
+ }
51
61
}
52
62
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