From e9ec127b4e913ab6e323248f34c5a384f063ddc4 Mon Sep 17 00:00:00 2001 From: Fred Date: Fri, 18 Nov 2022 01:11:04 +0800 Subject: [PATCH 01/11] feat: support to install the latest version --- src/commands/install.rs | 35 ++++++++++++++++++++++++++++++----- src/user_version.rs | 2 +- src/version.rs | 6 ++++-- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/commands/install.rs b/src/commands/install.rs index 7b37d1c22..4a8f25370 100644 --- a/src/commands/install.rs +++ b/src/commands/install.rs @@ -18,25 +18,33 @@ pub struct Install { pub version: Option, /// Install latest LTS - #[clap(long, conflicts_with = "version")] + #[clap(long, conflicts_with_all = &["version", "latest"])] pub lts: bool, + + /// Install latest version + #[clap(long, conflicts_with_all = &["version", "lts"])] + pub latest: bool, } impl Install { fn version(self) -> Result, Error> { match self { - Self { - version: Some(_), - lts: true, - } => Err(Error::TooManyVersionsProvided), Self { version: v, lts: false, + latest: false, } => Ok(v), Self { version: None, lts: true, + latest: false, } => Ok(Some(UserVersion::Full(Version::Lts(LtsType::Latest)))), + Self { + version: None, + lts: false, + latest: true, + } => Ok(Some(UserVersion::Full(Version::Latest))), + _ => Err(Error::TooManyVersionsProvided), } } } @@ -74,6 +82,20 @@ impl super::command::Command for Install { ); picked_version } + UserVersion::Full(Version::Latest) => { + let available_versions: Vec<_> = remote_node_index::list(&config.node_dist_mirror) + .map_err(|source| Error::CantListRemoteVersions { source })?; + let picked_version = available_versions.last() + .ok_or_else(|| Error::CantFindLatest)? + .version + .clone(); + debug!( + "Resolved {} into Node version {}", + Version::Latest.v_str().cyan(), + picked_version.v_str().cyan() + ); + picked_version + } current_version => { let available_versions: Vec<_> = remote_node_index::list(&config.node_dist_mirror) .map_err(|source| Error::CantListRemoteVersions { source })? @@ -153,6 +175,8 @@ pub enum Error { CantFindNodeVersion { requested_version: UserVersion }, #[error("Can't find relevant LTS named {}", lts_type)] CantFindRelevantLts { lts_type: crate::lts::LtsType }, + #[error("Can't find latest version")] + CantFindLatest, #[error("The requested version is not installable: {}", version.v_str())] UninstallableVersion { version: Version }, #[error("Too many versions provided. Please don't use --lts with a version string.")] @@ -175,6 +199,7 @@ mod tests { Install { version: UserVersion::from_str("12.0.0").ok(), lts: false, + latest: false, } .apply(&config) .expect("Can't install"); diff --git a/src/user_version.rs b/src/user_version.rs index 1e08618da..bf1897ea8 100644 --- a/src/user_version.rs +++ b/src/user_version.rs @@ -41,7 +41,7 @@ impl UserVersion { } } } - (_, Version::Bypassed | Version::Lts(_) | Version::Alias(_)) => false, + (_, Version::Bypassed | Version::Lts(_) | Version::Alias(_) | Version::Latest) => false, (Self::OnlyMajor(major), Version::Semver(other)) => *major == other.major, (Self::MajorMinor(major, minor), Version::Semver(other)) => { *major == other.major && *minor == other.minor diff --git a/src/version.rs b/src/version.rs index b6c4a132f..89d792f71 100644 --- a/src/version.rs +++ b/src/version.rs @@ -9,6 +9,7 @@ pub enum Version { Semver(semver::Version), Lts(LtsType), Alias(String), + Latest, Bypassed, } @@ -58,7 +59,7 @@ impl Version { pub fn installation_path(&self, config: &config::FnmConfig) -> std::path::PathBuf { match self { Self::Bypassed => system_version::path(), - v @ (Self::Lts(_) | Self::Alias(_)) => { + v @ (Self::Lts(_) | Self::Alias(_) | Self::Latest) => { config.aliases_dir().join(v.alias_name().unwrap()) } v @ Self::Semver(_) => config @@ -93,6 +94,7 @@ impl std::fmt::Display for Version { Self::Lts(lts) => write!(f, "lts-{}", lts), Self::Semver(semver) => write!(f, "v{}", semver), Self::Alias(alias) => write!(f, "{}", alias), + Self::Latest => write!(f, "latest"), } } } @@ -107,7 +109,7 @@ impl FromStr for Version { impl PartialEq for Version { fn eq(&self, other: &semver::Version) -> bool { match self { - Self::Bypassed | Self::Lts(_) | Self::Alias(_) => false, + Self::Bypassed | Self::Lts(_) | Self::Alias(_) | Self::Latest => false, Self::Semver(v) => v == other, } } From 091cf678d676258f9e5181309acd898b9083ec13 Mon Sep 17 00:00:00 2001 From: Fred Date: Fri, 18 Nov 2022 20:14:53 +0800 Subject: [PATCH 02/11] chore: test & fmt & clippy --- src/commands/install.rs | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/commands/install.rs b/src/commands/install.rs index 4a8f25370..ee22ebfe4 100644 --- a/src/commands/install.rs +++ b/src/commands/install.rs @@ -85,8 +85,9 @@ impl super::command::Command for Install { UserVersion::Full(Version::Latest) => { let available_versions: Vec<_> = remote_node_index::list(&config.node_dist_mirror) .map_err(|source| Error::CantListRemoteVersions { source })?; - let picked_version = available_versions.last() - .ok_or_else(|| Error::CantFindLatest)? + let picked_version = available_versions + .last() + .ok_or(Error::CantFindLatest)? .version .clone(); debug!( @@ -175,7 +176,7 @@ pub enum Error { CantFindNodeVersion { requested_version: UserVersion }, #[error("Can't find relevant LTS named {}", lts_type)] CantFindRelevantLts { lts_type: crate::lts::LtsType }, - #[error("Can't find latest version")] + #[error("Can't find any versions in the upstream version index.")] CantFindLatest, #[error("The requested version is not installable: {}", version.v_str())] UninstallableVersion { version: Version }, @@ -215,4 +216,31 @@ mod tests { .ok() ); } + + #[test] + fn test_install_latest() { + let base_dir = tempfile::tempdir().unwrap(); + let config = FnmConfig::default().with_base_dir(Some(base_dir.path().to_path_buf())); + + Install { + version: None, + lts: false, + latest: true, + } + .apply(&config) + .expect("Can't install"); + + let available_versions: Vec<_> = + remote_node_index::list(&config.node_dist_mirror).expect("Can't get node version list"); + let latest_version = available_versions.last().unwrap().version.clone(); + + assert!(config.installations_dir().exists()); + assert!(config + .installations_dir() + .join(latest_version.to_string()) + .join("installation") + .canonicalize() + .unwrap() + .exists()); + } } From e391a2c831816f6049544ddcb4c3243706533ba9 Mon Sep 17 00:00:00 2001 From: Fred Date: Fri, 18 Nov 2022 20:23:48 +0800 Subject: [PATCH 03/11] docs: update command docs --- docs/commands.md | 255 +++++++++++++++++++++-------------------------- 1 file changed, 114 insertions(+), 141 deletions(-) diff --git a/docs/commands.md b/docs/commands.md index 211ecce3e..06e84e237 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -1,7 +1,6 @@ # `fnm` - ``` -fnm 1.32.0 +fnm 1.31.1 A fast and simple Node.js manager USAGE: @@ -10,12 +9,12 @@ USAGE: OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -23,14 +22,14 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] @@ -40,12 +39,12 @@ OPTIONS: --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] @@ -78,11 +77,9 @@ SUBCOMMANDS: use Change Node.js version ``` - # `fnm alias` - ``` -fnm-alias +fnm-alias Alias a version to a common name USAGE: @@ -90,20 +87,20 @@ USAGE: ARGS: - + - + OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -111,35 +108,33 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] ``` - # `fnm completions` - ``` -fnm-completions +fnm-completions Print shell completions to stdout USAGE: @@ -148,12 +143,12 @@ USAGE: OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -161,14 +156,14 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] @@ -178,21 +173,19 @@ OPTIONS: --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] ``` - # `fnm current` - ``` -fnm-current +fnm-current Print the current Node.js version USAGE: @@ -201,12 +194,12 @@ USAGE: OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -214,35 +207,33 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] ``` - # `fnm default` - ``` -fnm-default +fnm-default Set a version as the default version This is a shorthand for `fnm alias VERSION default` @@ -252,17 +243,17 @@ USAGE: ARGS: - + OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -270,35 +261,33 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] ``` - # `fnm env` - ``` -fnm-env +fnm-env Print and set up required environment variables for fnm This command generates a series of shell commands that should be evaluated by your shell to create a @@ -314,36 +303,33 @@ USAGE: OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help Print help information - --json - Print JSON instead of shell commands - --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] --shell The shell syntax to use. Infers when missing - + [possible values: bash, zsh, fish, powershell] --use-on-cd @@ -352,21 +338,19 @@ OPTIONS: --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] ``` - # `fnm exec` - ``` -fnm-exec +fnm-exec Run a command within fnm context Example: @@ -384,12 +368,12 @@ ARGS: OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -397,14 +381,14 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] @@ -414,27 +398,23 @@ OPTIONS: --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] ``` - # `fnm help` - ``` ``` - # `fnm install` - ``` -fnm-install +fnm-install Install a new Node.js version USAGE: @@ -447,20 +427,23 @@ ARGS: OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help Print help information + --latest + Install latest version + --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] @@ -470,28 +453,26 @@ OPTIONS: --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] ``` - # `fnm list` - ``` -fnm-list +fnm-list List all locally installed Node.js versions USAGE: @@ -500,12 +481,12 @@ USAGE: OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -513,35 +494,33 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] ``` - # `fnm list-remote` - ``` -fnm-list-remote +fnm-list-remote List all remote Node.js versions USAGE: @@ -550,12 +529,12 @@ USAGE: OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -563,35 +542,33 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] ``` - # `fnm unalias` - ``` -fnm-unalias +fnm-unalias Remove an alias definition USAGE: @@ -599,17 +576,17 @@ USAGE: ARGS: - + OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -617,35 +594,33 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] ``` - # `fnm uninstall` - ``` -fnm-uninstall +fnm-uninstall Uninstall a Node.js version > Warning: when providing an alias, it will remove the Node version the alias is pointing to, along @@ -656,17 +631,17 @@ USAGE: ARGS: - + OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -674,35 +649,33 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] ``` - # `fnm use` - ``` -fnm-use +fnm-use Change Node.js version USAGE: @@ -710,17 +683,17 @@ USAGE: ARGS: - + OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -731,14 +704,14 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] @@ -749,12 +722,12 @@ OPTIONS: --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] From b384755fde7f3bcfd9fe199da064f65300a092d5 Mon Sep 17 00:00:00 2001 From: Fred Date: Fri, 18 Nov 2022 22:24:51 +0800 Subject: [PATCH 04/11] docs: update command docs --- .ci/prepare-version.js | 2 +- .ci/print-command-docs.js | 4 +- .github/workflows/rust.yml | 4 +- docs/commands.md | 252 +++++++++++++++++++++---------------- 4 files changed, 146 insertions(+), 116 deletions(-) diff --git a/.ci/prepare-version.js b/.ci/prepare-version.js index 5d6ddb2c4..f63ac3686 100755 --- a/.ci/prepare-version.js +++ b/.ci/prepare-version.js @@ -17,7 +17,7 @@ const command = cmd.command({ async handler({}) { updateCargoToml(await getPackageVersion()) exec("cargo build --release") - exec("yarn generate-command-docs --binary-path=./target/release/fnm") + exec("pnpm generate-command-docs --binary-path=./target/release/fnm") exec("./.ci/record_screen.sh") }, }) diff --git a/.ci/print-command-docs.js b/.ci/print-command-docs.js index 7b5996a4f..df61c6f34 100755 --- a/.ci/print-command-docs.js +++ b/.ci/print-command-docs.js @@ -42,7 +42,7 @@ const command = cmd.command({ if (gitStatus.state === "dirty") { process.exitCode = 1 console.error( - "The file has changed. Please re-run `yarn generate-command-docs`." + "The file has changed. Please re-run `pnpm generate-command-docs`." ) console.error(`hint: The following diff was found:`) console.error() @@ -76,7 +76,7 @@ async function main(targetFile, fnmPath) { stream.close() - await execa(`yarn`, ["prettier", "--write", targetFile]) + await execa(`pnpm`, ["prettier", "--write", targetFile]) } /** diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index ea6c600f7..4527e0a08 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -339,7 +339,7 @@ jobs: run: fnm --version - run: fnm install - name: Install Node deps - run: fnm exec -- yarn + run: fnm exec -- pnpm - name: Generate command markdown run: | - fnm exec -- yarn generate-command-docs --check --binary-path=$(which fnm) + fnm exec -- pnpm generate-command-docs --check --binary-path=$(which fnm) diff --git a/docs/commands.md b/docs/commands.md index 06e84e237..4e1644a75 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -1,6 +1,7 @@ # `fnm` + ``` -fnm 1.31.1 +fnm 1.32.0 A fast and simple Node.js manager USAGE: @@ -9,12 +10,12 @@ USAGE: OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -22,14 +23,14 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] @@ -39,12 +40,12 @@ OPTIONS: --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] @@ -77,9 +78,11 @@ SUBCOMMANDS: use Change Node.js version ``` + # `fnm alias` + ``` -fnm-alias +fnm-alias Alias a version to a common name USAGE: @@ -87,20 +90,20 @@ USAGE: ARGS: - + - + OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -108,33 +111,35 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] ``` + # `fnm completions` + ``` -fnm-completions +fnm-completions Print shell completions to stdout USAGE: @@ -143,12 +148,12 @@ USAGE: OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -156,14 +161,14 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] @@ -173,19 +178,21 @@ OPTIONS: --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] ``` + # `fnm current` + ``` -fnm-current +fnm-current Print the current Node.js version USAGE: @@ -194,12 +201,12 @@ USAGE: OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -207,33 +214,35 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] ``` + # `fnm default` + ``` -fnm-default +fnm-default Set a version as the default version This is a shorthand for `fnm alias VERSION default` @@ -243,17 +252,17 @@ USAGE: ARGS: - + OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -261,33 +270,35 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] ``` + # `fnm env` + ``` -fnm-env +fnm-env Print and set up required environment variables for fnm This command generates a series of shell commands that should be evaluated by your shell to create a @@ -303,33 +314,36 @@ USAGE: OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help Print help information + --json + Print JSON instead of shell commands + --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] --shell The shell syntax to use. Infers when missing - + [possible values: bash, zsh, fish, powershell] --use-on-cd @@ -338,19 +352,21 @@ OPTIONS: --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] ``` + # `fnm exec` + ``` -fnm-exec +fnm-exec Run a command within fnm context Example: @@ -368,12 +384,12 @@ ARGS: OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -381,14 +397,14 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] @@ -398,23 +414,27 @@ OPTIONS: --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] ``` + # `fnm help` + ``` ``` + # `fnm install` + ``` -fnm-install +fnm-install Install a new Node.js version USAGE: @@ -427,12 +447,12 @@ ARGS: OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -443,7 +463,7 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] @@ -453,26 +473,28 @@ OPTIONS: --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] ``` + # `fnm list` + ``` -fnm-list +fnm-list List all locally installed Node.js versions USAGE: @@ -481,12 +503,12 @@ USAGE: OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -494,33 +516,35 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] ``` + # `fnm list-remote` + ``` -fnm-list-remote +fnm-list-remote List all remote Node.js versions USAGE: @@ -529,12 +553,12 @@ USAGE: OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -542,33 +566,35 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] ``` + # `fnm unalias` + ``` -fnm-unalias +fnm-unalias Remove an alias definition USAGE: @@ -576,17 +602,17 @@ USAGE: ARGS: - + OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -594,33 +620,35 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] ``` + # `fnm uninstall` + ``` -fnm-uninstall +fnm-uninstall Uninstall a Node.js version > Warning: when providing an alias, it will remove the Node version the alias is pointing to, along @@ -631,17 +659,17 @@ USAGE: ARGS: - + OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -649,33 +677,35 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] ``` + # `fnm use` + ``` -fnm-use +fnm-use Change Node.js version USAGE: @@ -683,17 +713,17 @@ USAGE: ARGS: - + OPTIONS: --arch Override the architecture of the installed Node binary. Defaults to arch of fnm binary - + [env: FNM_ARCH] --fnm-dir The root directory of fnm installations - + [env: FNM_DIR] -h, --help @@ -704,14 +734,14 @@ OPTIONS: --log-level The log level of fnm commands - + [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, error] --node-dist-mirror https://nodejs.org/dist/ mirror - + [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] @@ -722,12 +752,12 @@ OPTIONS: --version-file-strategy A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a version, or when `--use-on-cd` is configured on evaluation. - + * `local`: Use the local version of Node defined within the current directory - + * `recursive`: Use the version of Node defined within the current directory and all parent directories - + [env: FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] From 47b0387e557654c1eb1b3486acd353acd41dddc3 Mon Sep 17 00:00:00 2001 From: Gal Schlezinger Date: Fri, 18 Nov 2022 18:43:30 +0200 Subject: [PATCH 05/11] Create warm-rice-appear.md --- .changeset/warm-rice-appear.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/warm-rice-appear.md diff --git a/.changeset/warm-rice-appear.md b/.changeset/warm-rice-appear.md new file mode 100644 index 000000000..8b3e02343 --- /dev/null +++ b/.changeset/warm-rice-appear.md @@ -0,0 +1,5 @@ +--- +"fnm": patch +--- + +feat: support `fnm install --latest` to install the latest Node.js version From 3dafec570037be184e9a8beb5c39ca8879834351 Mon Sep 17 00:00:00 2001 From: Gal Schlezinger Date: Fri, 18 Nov 2022 18:44:27 +0200 Subject: [PATCH 06/11] Update change set to be a minor release As this is a new feature --- .changeset/warm-rice-appear.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/warm-rice-appear.md b/.changeset/warm-rice-appear.md index 8b3e02343..6a49e19dd 100644 --- a/.changeset/warm-rice-appear.md +++ b/.changeset/warm-rice-appear.md @@ -1,5 +1,5 @@ --- -"fnm": patch +"fnm": minor --- feat: support `fnm install --latest` to install the latest Node.js version From 9a053a7eb4006ea9d861dc123bcc71d7262c6098 Mon Sep 17 00:00:00 2001 From: Fred Date: Sat, 19 Nov 2022 00:58:49 +0800 Subject: [PATCH 07/11] chore: update workflow to install pnpm --- .github/workflows/rust.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4527e0a08..03562c6e3 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -338,6 +338,9 @@ jobs: - name: Print fnm version run: fnm --version - run: fnm install + - uses: pnpm/action-setup@v2.2.4 + with: + run_install: false - name: Install Node deps run: fnm exec -- pnpm - name: Generate command markdown From 1657e45626c16fa4ac12298af7f103bbe19ee0d9 Mon Sep 17 00:00:00 2001 From: Gal Schlezinger Date: Fri, 18 Nov 2022 19:18:47 +0200 Subject: [PATCH 08/11] Remove `feat:` from changeset Because GitHub actions approval button is missing --- .changeset/warm-rice-appear.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/warm-rice-appear.md b/.changeset/warm-rice-appear.md index 6a49e19dd..575462aa1 100644 --- a/.changeset/warm-rice-appear.md +++ b/.changeset/warm-rice-appear.md @@ -2,4 +2,4 @@ "fnm": minor --- -feat: support `fnm install --latest` to install the latest Node.js version +support `fnm install --latest` to install the latest Node.js version From f5f2ca29f17a3440d576085ec34d4644d56a48e4 Mon Sep 17 00:00:00 2001 From: Gal Schlezinger Date: Fri, 18 Nov 2022 21:49:50 +0200 Subject: [PATCH 09/11] run pnpm like other tasks --- .github/workflows/rust.yml | 55 ++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 03562c6e3..04b041bbc 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -326,23 +326,38 @@ jobs: name: Ensure command docs are up-to-date needs: [build_static_linux_binary] steps: - - uses: actions/checkout@v3 - - name: Download a single artifact - uses: actions/download-artifact@v3 - with: - name: fnm-linux - - name: Make the binary runnable - run: | - sudo install fnm /bin - fnm --version - - name: Print fnm version - run: fnm --version - - run: fnm install - - uses: pnpm/action-setup@v2.2.4 - with: - run_install: false - - name: Install Node deps - run: fnm exec -- pnpm - - name: Generate command markdown - run: | - fnm exec -- pnpm generate-command-docs --check --binary-path=$(which fnm) + - name: install necessary shells + run: sudo apt-get update && sudo apt-get install -y fish zsh bash + - uses: actions/checkout@v3 + - uses: actions/download-artifact@v3 + with: + name: fnm-linux + path: target/release + - name: mark binary as executable + run: chmod +x target/release/fnm + - name: install fnm as binary + run: | + sudo install target/release/fnm /bin + fnm --version + - uses: pnpm/action-setup@v2.2.4 + with: + run_install: false + - uses: actions/setup-node@v3 + with: + node-version: 16.x + cache: 'pnpm' + - name: Get pnpm store directory + id: pnpm-cache + run: | + echo "::set-output name=pnpm_cache_dir::$(pnpm store path)" + - uses: actions/cache@v3 + name: Setup pnpm cache + with: + path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + - run: pnpm install + - name: Generate command markdown + run: | + pnpm run generate-command-docs --check --binary-path=$(which fnm) From 5906ee27a2fd419f88fd8166d2aaa0ff559c37de Mon Sep 17 00:00:00 2001 From: Gal Schlezinger Date: Fri, 18 Nov 2022 21:49:55 +0200 Subject: [PATCH 10/11] Revert "run pnpm like other tasks" This reverts commit f5f2ca29f17a3440d576085ec34d4644d56a48e4. we can revert the yarn changes and do it in a different PR --- .github/workflows/rust.yml | 55 ++++++++++++++------------------------ 1 file changed, 20 insertions(+), 35 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 04b041bbc..03562c6e3 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -326,38 +326,23 @@ jobs: name: Ensure command docs are up-to-date needs: [build_static_linux_binary] steps: - - name: install necessary shells - run: sudo apt-get update && sudo apt-get install -y fish zsh bash - - uses: actions/checkout@v3 - - uses: actions/download-artifact@v3 - with: - name: fnm-linux - path: target/release - - name: mark binary as executable - run: chmod +x target/release/fnm - - name: install fnm as binary - run: | - sudo install target/release/fnm /bin - fnm --version - - uses: pnpm/action-setup@v2.2.4 - with: - run_install: false - - uses: actions/setup-node@v3 - with: - node-version: 16.x - cache: 'pnpm' - - name: Get pnpm store directory - id: pnpm-cache - run: | - echo "::set-output name=pnpm_cache_dir::$(pnpm store path)" - - uses: actions/cache@v3 - name: Setup pnpm cache - with: - path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - run: pnpm install - - name: Generate command markdown - run: | - pnpm run generate-command-docs --check --binary-path=$(which fnm) + - uses: actions/checkout@v3 + - name: Download a single artifact + uses: actions/download-artifact@v3 + with: + name: fnm-linux + - name: Make the binary runnable + run: | + sudo install fnm /bin + fnm --version + - name: Print fnm version + run: fnm --version + - run: fnm install + - uses: pnpm/action-setup@v2.2.4 + with: + run_install: false + - name: Install Node deps + run: fnm exec -- pnpm + - name: Generate command markdown + run: | + fnm exec -- pnpm generate-command-docs --check --binary-path=$(which fnm) From 3e068392c2056b30748068202fdd5eb3018da454 Mon Sep 17 00:00:00 2001 From: Gal Schlezinger Date: Fri, 18 Nov 2022 21:50:33 +0200 Subject: [PATCH 11/11] revert the changes in .github/workflows --- .github/workflows/rust.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 03562c6e3..ea6c600f7 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -338,11 +338,8 @@ jobs: - name: Print fnm version run: fnm --version - run: fnm install - - uses: pnpm/action-setup@v2.2.4 - with: - run_install: false - name: Install Node deps - run: fnm exec -- pnpm + run: fnm exec -- yarn - name: Generate command markdown run: | - fnm exec -- pnpm generate-command-docs --check --binary-path=$(which fnm) + fnm exec -- yarn generate-command-docs --check --binary-path=$(which fnm)