diff --git a/apps/site/next-data/downloadSnippets.ts b/apps/site/next-data/downloadSnippets.ts index 909eaf725c365..6fd143852204a 100644 --- a/apps/site/next-data/downloadSnippets.ts +++ b/apps/site/next-data/downloadSnippets.ts @@ -8,11 +8,13 @@ import { import { availableLocaleCodes } from '@/next.locales.mjs'; import type { DownloadSnippet } from '@/types'; -const getDownloadSnippets = (lang: string): Promise> => { +export default async function getDownloadSnippets( + lang: string +): Promise> { // 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 = @@ -24,9 +26,10 @@ const getDownloadSnippets = (lang: string): Promise> => { // 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 @@ -41,9 +44,6 @@ const getDownloadSnippets = (lang: string): Promise> => { // 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()); +} diff --git a/apps/site/next-data/generators/downloadSnippets.mjs b/apps/site/next-data/generators/downloadSnippets.mjs index dcd3d995e3736..e8b2559b87f76 100644 --- a/apps/site/next-data/generators/downloadSnippets.mjs +++ b/apps/site/next-data/generators/downloadSnippets.mjs @@ -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 * @@ -39,6 +39,4 @@ const generateDownloadSnippets = async () => { }); return new Map(await Promise.all(downloadSnippets)); -}; - -export default generateDownloadSnippets; +} diff --git a/apps/site/next.constants.mjs b/apps/site/next.constants.mjs index a371029829248..cf310a9b3452a 100644 --- a/apps/site/next.constants.mjs +++ b/apps/site/next.constants.mjs @@ -98,7 +98,7 @@ export const NEXT_DATA_URL = process.env.NEXT_PUBLIC_DATA_URL ? process.env.NEXT_PUBLIC_DATA_URL : VERCEL_ENV ? `${BASE_URL}${BASE_PATH}/en/next-data/` - : `http://localhost:3000/en/next-data/`; + : `http://localhost:${process.env.PORT ?? 3000}/en/next-data/`; /** * This ReGeX is used to remove the `index.md(x)` suffix of a name and to remove diff --git a/apps/site/snippets/en/download/nvm.bash b/apps/site/snippets/en/download/nvm.bash index f2d3d4798f296..33db32e10fcd9 100644 --- a/apps/site/snippets/en/download/nvm.bash +++ b/apps/site/snippets/en/download/nvm.bash @@ -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}