Skip to content

Commit 13ae34d

Browse files
committed
always show the latest version of nvm
1 parent b12daaa commit 13ae34d

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

apps/site/components/Downloads/Release/ReleaseCodeBox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const ReleaseCodeBox: FC = () => {
2222

2323
useEffect(() => {
2424
const updatedCode = getNodeDownloadSnippet(release, os, t)[platform];
25-
// Docker and NVM support downloading tags/versions by their full release number
25+
// Docker and nvm support downloading tags/versions by their full release number
2626
// but usually we should recommend users to download "major" versions
2727
// since our Download Buttons get the latest minor of a major, it does make sense
2828
// to request installation of a major via a package manager

apps/site/util/getNodeDownloadSnippet.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,23 @@ import type { NodeRelease } from '@/types';
55
import type { PackageManager } from '@/types/release';
66
import 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

Comments
 (0)