Skip to content

Commit 94933af

Browse files
authored
fix(snippets): update nvm instructions (nodejs#7467)
* fix: don’t hardcode 3000; use the actual port * download: fix nvm instructions (nodejs#7434)
1 parent c474e82 commit 94933af

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

apps/site/next-data/downloadSnippets.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import {
88
import { availableLocaleCodes } from '@/next.locales.mjs';
99
import type { DownloadSnippet } from '@/types';
1010

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

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

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

apps/site/next-data/generators/downloadSnippets.mjs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { availableLocaleCodes } from '../../next.locales.mjs';
1111
* This method is used to generate the Node.js Website Download Snippets
1212
* for self-consumption during RSC and Static Builds
1313
*/
14-
const generateDownloadSnippets = async () => {
14+
export default async function generateDownloadSnippets() {
1515
/**
1616
* This generates all the Download Snippets for each available Locale
1717
*
@@ -39,6 +39,4 @@ const generateDownloadSnippets = async () => {
3939
});
4040

4141
return new Map(await Promise.all(downloadSnippets));
42-
};
43-
44-
export default generateDownloadSnippets;
42+
}

apps/site/next.constants.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export const NEXT_DATA_URL = process.env.NEXT_PUBLIC_DATA_URL
9898
? process.env.NEXT_PUBLIC_DATA_URL
9999
: VERCEL_ENV
100100
? `${BASE_URL}${BASE_PATH}/en/next-data/`
101-
: `http://localhost:3000/en/next-data/`;
101+
: `http://localhost:${process.env.PORT ?? 3000}/en/next-data/`;
102102

103103
/**
104104
* This ReGeX is used to remove the `index.md(x)` suffix of a name and to remove

apps/site/snippets/en/download/nvm.bash

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Download and install nvm:
22
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
33

4+
# in lieu of restarting the shell
5+
\. "$HOME/.nvm/nvm.sh"
6+
47
# Download and install Node.js:
58
nvm install ${props.release.major}
69

0 commit comments

Comments
 (0)