Skip to content

Commit

Permalink
download: fix nvm instructions (#7434)
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Feb 3, 2025
1 parent 31f7b03 commit a55d025
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
22 changes: 11 additions & 11 deletions apps/site/next-data/downloadSnippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import {
import { availableLocaleCodes } from '@/next.locales.mjs';
import type { DownloadSnippet } from '@/types';

const getDownloadSnippets = (lang: string): Promise<Array<DownloadSnippet>> => {
export default async function getDownloadSnippets(
lang: string
): Promise<Array<DownloadSnippet>> {
// Prevents attempting to retrieve data for an unsupported language as both the generator
// and the API endpoint will simply return 404. And we want to prevent a 404 response.
if (availableLocaleCodes.includes(lang) === false) {
return Promise.resolve([]);
if (!availableLocaleCodes.includes(lang)) {
return [];
}

const IS_NOT_VERCEL_RUNTIME_ENV =
Expand All @@ -24,9 +26,10 @@ const getDownloadSnippets = (lang: string): Promise<Array<DownloadSnippet>> => {
// the data directly within the current thread, which will anyways be loaded only once
// We use lazy-imports to prevent `provideBlogData` from executing on import
if (ENABLE_STATIC_EXPORT || IS_NOT_VERCEL_RUNTIME_ENV) {
return import('@/next-data/providers/downloadSnippets').then(
({ default: provideDownloadSnippets }) => provideDownloadSnippets(lang)!
const { default: provideDownloadSnippets } = await import(
'@/next-data/providers/downloadSnippets'
);
return provideDownloadSnippets(lang)!;
}

// Applies the language to the URL, since this content is actually localized
Expand All @@ -41,9 +44,6 @@ const getDownloadSnippets = (lang: string): Promise<Array<DownloadSnippet>> => {
// outdated information being shown to the user.
// Note: We do manual JSON.parse after response.text() to prevent React from throwing an Error
// that does not provide a clear stack trace of which request is failing and what the JSON.parse error is
return fetch(fetchURL)
.then(response => response.text())
.then(JSON.parse);
};

export default getDownloadSnippets;
const response = await fetch(fetchURL);
return JSON.parse(await response.text());
}
6 changes: 2 additions & 4 deletions apps/site/next-data/generators/downloadSnippets.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { availableLocaleCodes } from '../../next.locales.mjs';
* This method is used to generate the Node.js Website Download Snippets
* for self-consumption during RSC and Static Builds
*/
const generateDownloadSnippets = async () => {
export default async function generateDownloadSnippets() {
/**
* This generates all the Download Snippets for each available Locale
*
Expand Down Expand Up @@ -39,6 +39,4 @@ const generateDownloadSnippets = async () => {
});

return new Map(await Promise.all(downloadSnippets));
};

export default generateDownloadSnippets;
}
3 changes: 3 additions & 0 deletions apps/site/snippets/en/download/nvm.bash
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Download and install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash

# in lieu of restarting the shell
\. "$HOME/.nvm/nvm.sh"

# Download and install Node.js:
nvm install ${props.release.major}

Expand Down

0 comments on commit a55d025

Please sign in to comment.