Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(snippets): update nvm instructions #7467

Merged
merged 2 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
2 changes: 1 addition & 1 deletion apps/site/next.constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
Loading