@@ -5,11 +5,23 @@ import type { NodeRelease } from '@/types';
55import type { PackageManager } from '@/types/release' ;
66import type { UserOS } from '@/types/userOS' ;
77
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 (
921 release : NodeRelease ,
1022 os : UserOS ,
1123 t : ( key : string , values ?: TranslationValues ) => string
12- ) => {
24+ ) {
1325 const snippets : Record < PackageManager , string > = {
1426 NVM : '' ,
1527 FNM : '' ,
@@ -37,9 +49,10 @@ export const getNodeDownloadSnippet = (
3749 }
3850
3951 if ( os === 'MAC' || os === 'LINUX' ) {
52+
4053 snippets . NVM = dedent `
4154 # ${ 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
4356
4457 # ${ t ( 'layouts.download.codeBox.downloadAndInstallNodejsRestartTerminal' ) }
4558 nvm install ${ release . major }
0 commit comments