Skip to content

Commit b247d8c

Browse files
authored
fix: numerous fixes regarding package manager page (#6638)
* fix: numerous fixes regarding package manager page * fix: lts choco
1 parent de12484 commit b247d8c

File tree

6 files changed

+45
-92
lines changed

6 files changed

+45
-92
lines changed

components/Downloads/Release/OperatingSystemDropdown.tsx

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client';
2+
23
import { useTranslations } from 'next-intl';
3-
import { useContext, useEffect, useMemo } from 'react';
4+
import { useContext, useEffect } from 'react';
45
import type { FC } from 'react';
56

67
import Select from '@/components/Common/Select';
@@ -22,54 +23,36 @@ const OperatingSystemDropdown: FC<OperatingSystemDropdownProps> = ({
2223
exclude = [],
2324
}) => {
2425
const { os: userOS } = useDetectOS();
25-
const { platform, os, setOS } = useContext(ReleaseContext);
26+
const { os, setOS } = useContext(ReleaseContext);
2627
const t = useTranslations();
2728

2829
// we shouldn't react when "actions" change
2930
// eslint-disable-next-line react-hooks/exhaustive-deps
3031
useEffect(() => setOS(userOS), [userOS]);
3132

32-
// @TODO: We should have a proper utility that gives
33-
// disabled OSs, Platforms, based on specific criteria
34-
// this can be an optimisation for the future
35-
// to remove this logic from this component
36-
const disabledItems = useMemo(() => {
37-
const disabledItems = exclude;
38-
39-
if (platform === 'BREW') {
40-
disabledItems.push('WIN');
41-
}
42-
43-
if (platform === 'DOCKER') {
44-
disabledItems.push('LINUX');
45-
}
46-
47-
return disabledItems;
48-
}, [exclude, platform]);
49-
5033
// @TODO: We should have a proper utility that gives
5134
// disabled OSs, Platforms, based on specific criteria
5235
// this can be an optimisation for the future
5336
// to remove this logic from this component
5437
useEffect(() => {
55-
const currentOSExcluded = disabledItems.includes(os);
38+
const currentOSExcluded = exclude.includes(os);
5639

5740
const nonExcludedOS = operatingSystemItems
5841
.map(({ value }) => value)
59-
.find(os => !disabledItems.includes(os));
42+
.find(os => !exclude.includes(os));
6043

6144
if (currentOSExcluded && nonExcludedOS) {
6245
setOS(nonExcludedOS);
6346
}
6447
// we shouldn't react when "actions" change
6548
// eslint-disable-next-line react-hooks/exhaustive-deps
66-
}, [os, disabledItems]);
49+
}, [os, exclude]);
6750

6851
return (
6952
<Select
7053
values={formatDropdownItems({
7154
items: operatingSystemItems,
72-
disabledItems,
55+
disabledItems: exclude,
7356
icons: {
7457
WIN: <Microsoft width={16} height={16} />,
7558
MAC: <Apple width={16} height={16} />,

components/Downloads/Release/PlatformDropdown.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ const PlatformDropdown: FC = () => {
2929
disabledItems.push('BREW', 'NVM');
3030
}
3131

32-
if (os === 'LINUX') {
33-
disabledItems.push('DOCKER', 'CHOCO');
34-
}
35-
36-
if (os === 'MAC') {
32+
if (os === 'LINUX' || os === 'MAC') {
3733
disabledItems.push('CHOCO');
3834
}
3935

components/Downloads/Release/ReleaseCodeBox.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,18 @@ const ReleaseCodeBox: FC = () => {
3333
}, [release.versionWithPrefix, os, platform]);
3434

3535
const codeLanguage = os === 'WIN' ? 'PowerShell' : 'Bash';
36+
3637
return (
37-
<div className="mb-2 mt-6 flex min-h-80 flex-col gap-2">
38+
<div className="mb-2 mt-6 flex flex-col gap-2">
3839
{code && (
3940
<CodeBox language={codeLanguage}>
4041
<code dangerouslySetInnerHTML={{ __html: code }} />
4142
</CodeBox>
4243
)}
4344

4445
<span className="text-center text-xs text-neutral-800 dark:text-neutral-200">
46+
<b>{t('layouts.download.codeBox.managerInstalled')}</b>
47+
<br />
4548
{t('layouts.download.codeBox.communityWarning')}
4649
</span>
4750
</div>

i18n/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@
284284
"platform": "Platform"
285285
},
286286
"codeBox": {
287+
"managerInstalled": "Please ensure you have the right package manager installed before running a script.",
287288
"communityWarning": "Package managers and their installation scripts are not maintained by the Node.js project."
288289
}
289290
}

pages/en/download/package-manager/current.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ subtitle: Download Node.js the way you want.
55
---
66

77
<section>
8-
Install Node.js <Release.VersionDropdown /> on <Release.OperatingSystemDropdown exclude={["AIX"]} /> using <Release.PlatformDropdown />
8+
Install Node.js <Release.VersionDropdown /> on <Release.OperatingSystemDropdown exclude={["AIX"]} /> using <Release.PlatformDropdown />
99

1010
<Release.ReleaseCodeBox />
1111
</section>

util/getNodeDownloadSnippet.ts

Lines changed: 31 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,9 @@ export const getNodeDownloadSnippet = (release: NodeRelease, os: UserOS) => {
1212
CHOCO: '',
1313
};
1414

15-
if (os === 'LINUX' || os === 'MAC') {
16-
snippets.NVM = dedent`
17-
# installs NVM (Node Version Manager)
18-
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
19-
20-
# download and install Node.js
21-
nvm install ${release.major}
22-
23-
# verifies the right Node.js version is in the environment
24-
node -v # should print \`${release.versionWithPrefix}\`
25-
26-
# verifies the right NPM version is in the environment
27-
npm -v # should print \`${release.npm}\``;
28-
29-
snippets.BREW = dedent`
30-
# download and installs Homebrew (macOS/Linux Package Manager)
31-
curl -o- https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh | bash
32-
33-
# download and install Node.js
34-
brew install node@${release.major}
35-
36-
# verifies the right Node.js version is in the environment
37-
node -v # should print \`${release.versionWithPrefix}\`
38-
39-
# verifies the right NPM version is in the environment
40-
npm -v # should print \`${release.npm}\``;
41-
}
42-
43-
if (os === 'MAC') {
44-
snippets.DOCKER = dedent`
45-
# installs Homebrew (macOS/Linux Package Manager)
46-
curl -o- https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh | bash
47-
48-
# installs Docker Desktop
49-
brew install docker --cask
50-
15+
switch (true) {
16+
case os === 'WIN' || os === 'MAC' || os === 'LINUX':
17+
snippets.DOCKER = dedent`
5118
# pulls the Node.js Docker image
5219
docker pull node:${release.major}-${release.major >= 4 ? 'alpine' : 'slim'}
5320
@@ -56,41 +23,44 @@ export const getNodeDownloadSnippet = (release: NodeRelease, os: UserOS) => {
5623
5724
# verifies the right NPM version is in the environment
5825
docker run node:${release.major}-${release.major >= 4 ? 'alpine' : 'slim'} npm -v # should print \`${release.npm}\``;
59-
}
26+
// eslint-disable-next-line no-fallthrough
27+
case os === 'MAC' || os === 'LINUX':
28+
snippets.NVM = dedent`
29+
# installs NVM (Node Version Manager)
30+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
6031
61-
if (os === 'WIN') {
62-
snippets.CHOCO = dedent`
63-
# installs Chocolatey (Windows Package Manager)
64-
Set-ExecutionPolicy Bypass -Scope Process -Force;
65-
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;
66-
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'));
32+
# download and install Node.js
33+
nvm install ${release.major}
6734
68-
# download and install Node.js
69-
choco install nodejs --version="${release.version}"
35+
# verifies the right Node.js version is in the environment
36+
node -v # should print \`${release.versionWithPrefix}\`
7037
71-
# verifies the right Node.js version is in the environment
72-
node -v # should print \`${release.versionWithPrefix}\`
38+
# verifies the right NPM version is in the environment
39+
npm -v # should print \`${release.npm}\``;
7340

74-
# verifies the right NPM version is in the environment
75-
npm -v # should print \`${release.npm}\``;
41+
snippets.BREW = dedent`
42+
# download and install Node.js
43+
brew install node@${release.major}
7644
77-
snippets.DOCKER = dedent`
78-
# installs Chocolatey (Windows Package Manager)
79-
Set-ExecutionPolicy Bypass -Scope Process -Force;
80-
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;
81-
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'));
45+
# verifies the right Node.js version is in the environment
46+
node -v # should print \`${release.versionWithPrefix}\`
8247
83-
# installs Docker Desktop
84-
choco install docker-desktop
85-
86-
# pulls the Node.js Docker image
87-
docker pull node:${release.major}-${release.major >= 4 ? 'alpine' : 'slim'}
48+
# verifies the right NPM version is in the environment
49+
npm -v # should print \`${release.npm}\``;
50+
// eslint-disable-next-line no-fallthrough
51+
case os === 'WIN':
52+
snippets.CHOCO = dedent`
53+
# download and install Node.js
54+
choco install nodejs${release.isLts ? '-lts' : ''} --version="${release.version}"
8855
8956
# verifies the right Node.js version is in the environment
90-
docker run node:${release.major}-${release.major >= 4 ? 'alpine' : 'slim'} node -v # should print \`${release.versionWithPrefix}\`
57+
node -v # should print \`${release.versionWithPrefix}\`
9158
9259
# verifies the right NPM version is in the environment
93-
docker run node:${release.major}-${release.major >= 4 ? 'alpine' : 'slim'} npm -v # should print \`${release.npm}\``;
60+
npm -v # should print \`${release.npm}\``;
61+
// eslint-disable-next-line no-fallthrough
62+
default:
63+
break;
9464
}
9565

9666
return snippets;

0 commit comments

Comments
 (0)