From 6d03b62b9009e2ac6cf934b3c2cd050191e44a51 Mon Sep 17 00:00:00 2001 From: Matt Cowley Date: Mon, 13 May 2024 23:29:36 +0100 Subject: [PATCH] feat(download): add fnm to package managers for all platforms (#6667) * Add fnm logo * Add fnm to download picker/snippets * Fix bad switch cascade in download snippets * List fmn first as the only cross-platform option * Revert "List fmn first as the only cross-platform option" This reverts commit 8ed81a6686dc76878d0e4689f34a3582a377c800. * Use traced vector fnm logo --- .../Downloads/Release/PlatformDropdown.tsx | 2 + components/Icons/Platform/FNM.tsx | 99 +++++++++++++++++++ types/release.ts | 2 +- util/downloadUtils.ts | 4 + util/getNodeDownloadSnippet.ts | 79 ++++++++++----- 5 files changed, 158 insertions(+), 28 deletions(-) create mode 100644 components/Icons/Platform/FNM.tsx diff --git a/components/Downloads/Release/PlatformDropdown.tsx b/components/Downloads/Release/PlatformDropdown.tsx index 7bbfd5f792fc..a4839ae966f4 100644 --- a/components/Downloads/Release/PlatformDropdown.tsx +++ b/components/Downloads/Release/PlatformDropdown.tsx @@ -6,6 +6,7 @@ import type { FC } from 'react'; import Select from '@/components/Common/Select'; import Choco from '@/components/Icons/Platform/Choco'; import Docker from '@/components/Icons/Platform/Docker'; +import FNM from '@/components/Icons/Platform/FNM'; import Homebrew from '@/components/Icons/Platform/Homebrew'; import NVM from '@/components/Icons/Platform/NVM'; import { ReleaseContext } from '@/providers/releaseProvider'; @@ -68,6 +69,7 @@ const PlatformDropdown: FC = () => { items: platformItems, icons: { NVM: , + FNM: , BREW: , DOCKER: , CHOCO: , diff --git a/components/Icons/Platform/FNM.tsx b/components/Icons/Platform/FNM.tsx new file mode 100644 index 000000000000..90407358527b --- /dev/null +++ b/components/Icons/Platform/FNM.tsx @@ -0,0 +1,99 @@ +import type { FC, SVGProps } from 'react'; + +// @todo: replace with original vector (https://github.com/Schniz/fnm/issues/798#issuecomment-2068220441) +// this is a rough tracing of the available raster image +const FNM: FC> = props => ( + + + + + + + + + + + + + + + + + + + + + + + + + + +); + +export default FNM; diff --git a/types/release.ts b/types/release.ts index e231e55a921e..b1e794e940c8 100644 --- a/types/release.ts +++ b/types/release.ts @@ -3,7 +3,7 @@ import type { ReactNode } from 'react'; import type { NodeRelease } from '@/types/releases'; import type { UserOS } from '@/types/userOS'; -export type PackageManager = 'NVM' | 'BREW' | 'DOCKER' | 'CHOCO'; +export type PackageManager = 'NVM' | 'FNM' | 'BREW' | 'DOCKER' | 'CHOCO'; export interface ReleaseState { os: UserOS; diff --git a/util/downloadUtils.ts b/util/downloadUtils.ts index de6af4173dae..76da09a2ca43 100644 --- a/util/downloadUtils.ts +++ b/util/downloadUtils.ts @@ -34,6 +34,10 @@ export const platformItems = [ label: 'NVM', value: 'NVM' as PackageManager, }, + { + label: 'fnm', + value: 'FNM' as PackageManager, + }, { label: 'Brew', value: 'BREW' as PackageManager, diff --git a/util/getNodeDownloadSnippet.ts b/util/getNodeDownloadSnippet.ts index 1fdd79a133b0..f1ea3fe3d398 100644 --- a/util/getNodeDownloadSnippet.ts +++ b/util/getNodeDownloadSnippet.ts @@ -7,14 +7,14 @@ import type { UserOS } from '@/types/userOS'; export const getNodeDownloadSnippet = (release: NodeRelease, os: UserOS) => { const snippets: Record = { NVM: '', + FNM: '', BREW: '', DOCKER: '', CHOCO: '', }; - switch (true) { - case os === 'WIN' || os === 'MAC' || os === 'LINUX': - snippets.DOCKER = dedent` + if (os === 'WIN' || os === 'MAC' || os === 'LINUX') { + snippets.DOCKER = dedent` # pulls the Node.js Docker image docker pull node:${release.major}-${release.major >= 4 ? 'alpine' : 'slim'} @@ -23,33 +23,61 @@ export const getNodeDownloadSnippet = (release: NodeRelease, os: UserOS) => { # verifies the right NPM version is in the environment docker run node:${release.major}-${release.major >= 4 ? 'alpine' : 'slim'} npm -v # should print \`${release.npm}\``; - // eslint-disable-next-line no-fallthrough - case os === 'MAC' || os === 'LINUX': - snippets.NVM = dedent` - # installs NVM (Node Version Manager) - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash + } + + if (os === 'MAC' || os === 'LINUX') { + snippets.NVM = dedent` + # installs NVM (Node Version Manager) + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash + + # download and install Node.js + nvm install ${release.major} + + # verifies the right Node.js version is in the environment + node -v # should print \`${release.versionWithPrefix}\` + + # verifies the right NPM version is in the environment + npm -v # should print \`${release.npm}\``; + + snippets.FNM = dedent` + # installs fnm (Fast Node Manager) + curl -fsSL https://fnm.vercel.app/install | bash + + # download and install Node.js + fnm use --install-if-missing ${release.major} + + # verifies the right Node.js version is in the environment + node -v # should print \`${release.versionWithPrefix}\` - # download and install Node.js - nvm install ${release.major} + # verifies the right NPM version is in the environment + npm -v # should print \`${release.npm}\``; + + snippets.BREW = dedent` + # download and install Node.js + brew install node@${release.major} + + # verifies the right Node.js version is in the environment + node -v # should print \`${release.versionWithPrefix}\` + + # verifies the right NPM version is in the environment + npm -v # should print \`${release.npm}\``; + } - # verifies the right Node.js version is in the environment - node -v # should print \`${release.versionWithPrefix}\` + if (os === 'WIN') { + snippets.FNM = dedent` + # installs fnm (Fast Node Manager) + winget install Schniz.fnm - # verifies the right NPM version is in the environment - npm -v # should print \`${release.npm}\``; + # download and install Node.js + fnm use --install-if-missing ${release.major} - snippets.BREW = dedent` - # download and install Node.js - brew install node@${release.major} + # verifies the right Node.js version is in the environment + node -v # should print \`${release.versionWithPrefix}\` - # verifies the right Node.js version is in the environment - node -v # should print \`${release.versionWithPrefix}\` + # verifies the right NPM version is in the environment + npm -v # should print \`${release.npm}\``; - # verifies the right NPM version is in the environment - npm -v # should print \`${release.npm}\``; - // eslint-disable-next-line no-fallthrough - case os === 'WIN': - snippets.CHOCO = dedent` + snippets.CHOCO = dedent` # download and install Node.js choco install nodejs${release.isLts ? '-lts' : ''} --version="${release.version}" @@ -58,9 +86,6 @@ export const getNodeDownloadSnippet = (release: NodeRelease, os: UserOS) => { # verifies the right NPM version is in the environment npm -v # should print \`${release.npm}\``; - // eslint-disable-next-line no-fallthrough - default: - break; } return snippets;