@@ -5,11 +5,23 @@ import type { NodeRelease } from '@/types';
5
5
import type { PackageManager } from '@/types/release' ;
6
6
import type { UserOS } from '@/types/userOS' ;
7
7
8
- export const getNodeDownloadSnippet = (
8
+ const latestVersion = fetch ( 'https://latest.nvm.sh' , { redirect : 'manual' } )
9
+ . then ( ( { headers } ) => {
10
+ const url = headers . get ( 'location' ) ;
11
+ if ( ! url ) { throw null ; }
12
+ return fetch ( url , { redirect : 'manual' } ) ;
13
+ } )
14
+ . then ( x => {
15
+ const url = x . headers . get ( 'location' ) ;
16
+ return url ?. slice ( url ?. lastIndexOf ( '/' ) ) ;
17
+ } )
18
+ . catch ( ( ) => 'v0.40.1' ) ;
19
+
20
+ export async function getNodeDownloadSnippet (
9
21
release : NodeRelease ,
10
22
os : UserOS ,
11
23
t : ( key : string , values ?: TranslationValues ) => string
12
- ) => {
24
+ ) {
13
25
const snippets : Record < PackageManager , string > = {
14
26
NVM : '' ,
15
27
FNM : '' ,
@@ -37,9 +49,10 @@ export const getNodeDownloadSnippet = (
37
49
}
38
50
39
51
if ( os === 'MAC' || os === 'LINUX' ) {
52
+
40
53
snippets . NVM = dedent `
41
54
# ${ t ( 'layouts.download.codeBox.installsNvm' ) }
42
- curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0 /install.sh | bash
55
+ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/${ await latestVersion } /install.sh | bash
43
56
44
57
# ${ t ( 'layouts.download.codeBox.downloadAndInstallNodejsRestartTerminal' ) }
45
58
nvm install ${ release . major }
0 commit comments