Skip to content

Commit

Permalink
Merge branch 'master' into progress-bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Schniz authored May 25, 2024
2 parents 22d7645 + 8f3acbb commit 065ff49
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-paws-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fnm": patch
---

Fix `cd /D` on windows with `--use-on-cd`
5 changes: 5 additions & 0 deletions .changeset/poor-otters-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fnm": patch
---

support `x64-musl` arch by adding a `--arch x64-musl` to fnm env
5 changes: 5 additions & 0 deletions .changeset/rotten-pumpkins-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fnm": patch
---

fix: return default version if canonicalize fails
8 changes: 8 additions & 0 deletions .ci/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ set -e
RELEASE="latest"
OS="$(uname -s)"

case "${OS}" in
MINGW* | Win*) OS="Windows" ;;
esac

if [ -d "$HOME/.fnm" ]; then
INSTALL_DIR="$HOME/.fnm"
elif [ -n "$XDG_DATA_HOME" ]; then
Expand Down Expand Up @@ -70,6 +74,9 @@ set_filename() {
elif [ "$OS" = "Darwin" ]; then
USE_HOMEBREW="true"
echo "Downloading fnm using Homebrew..."
elif [ "$OS" = "Windows" ] ; then
FILENAME="fnm-windows"
echo "Downloading the latest fnm binary from GitHub..."
else
echo "OS $OS is not supported."
echo "If you think that's a bug - please file an issue to https://github.com/Schniz/fnm/issues"
Expand Down Expand Up @@ -180,6 +187,7 @@ setup_shell() {
echo ' set PATH "'"$INSTALL_DIR"'" $PATH'
echo ' fnm env | source'

echo '' >>$CONF_FILE
echo '# fnm' >>$CONF_FILE
echo 'set PATH "'"$INSTALL_DIR"'" $PATH' >>$CONF_FILE
echo 'fnm env | source' >>$CONF_FILE
Expand Down
34 changes: 19 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
<a href="https://github.com/Schniz/fnm/actions"><img src="https://img.shields.io/github/actions/workflow/status/Schniz/fnm/rust.yml?branch=master&label=workflow" alt="GitHub Actions workflow status" /></a>
</h1>

> :rocket: Fast and simple Node.js version manager, built in Rust
> 🚀 Fast and simple Node.js version manager, built in Rust
<div align="center">
<img src="./docs/fnm.svg" alt="Blazing fast!">
</div>

## Features

:earth_americas: Cross-platform support (macOS, Windows, Linux)
🌎 Cross-platform support (macOS, Windows, Linux)

:sparkles: Single file, easy installation, instant startup
Single file, easy installation, instant startup

:rocket: Built with speed in mind
🚀 Built with speed in mind

:open_file_folder: Works with `.node-version` and `.nvmrc` files
📂 Works with `.node-version` and `.nvmrc` files

## Installation

Expand All @@ -42,7 +42,7 @@ On other operating systems, upgrading `fnm` is almost the same as installing it.

`--install-dir`

Set a custom directory for fnm to be installed. The default is `$HOME/.fnm`.
Set a custom directory for fnm to be installed. The default is `$XDG_DATA_HOME/fnm` (if `$XDG_DATA_HOME` is not defined it falls back to `$HOME/.local/share/fnm` on linux and `$HOME/Library/Application Support/fnm` on MacOS).

`--skip-shell`

Expand Down Expand Up @@ -121,7 +121,7 @@ Where `<SHELL>` can be one of the supported shells:
- `bash`
- `zsh`
- `fish`
- `powershell`
- `power-shell`

Please follow your shell instructions to install them.

Expand Down Expand Up @@ -174,20 +174,24 @@ fnm env --use-on-cd | Out-String | Invoke-Expression
```

- For macOS/Linux, the profile is located at `~/.config/powershell/Microsoft.PowerShell_profile.ps1`
- On Windows, PowerShell comes pre-installed, but there are two versions of it. [Read more about it here](https://learn.microsoft.com/en-us/powershell/scripting/windows-powershell/install/installing-windows-powershell). The profile is located at different places depending on which version you're using:
- Built in PowerShell (aka "Windows PowerShell"): `~\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1`
- The newer, PowerShell >= 7, that's not built in: `~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1`

- On Windows to edit your profile you can run this in a PowerShell
```powershell
notepad $profile
```

#### Windows Command Prompt aka Batch aka WinCMD

fnm is also supported but is not entirely covered. [You can set up a startup script](https://superuser.com/a/144348) and append the following line:
fnm is also supported but is not entirely covered. [You can set up a startup script](https://superuser.com/a/144348) and append the following lines:

```batch
FOR /f "tokens=*" %i IN ('fnm env --use-on-cd') DO CALL %i
@echo off
:: for /F will launch a new instance of cmd so we create a guard to prevent an infnite loop
if not defined FNM_AUTORUN_GUARD (
set "FNM_AUTORUN_GUARD=AutorunGuard"
FOR /f "tokens=*" %%z IN ('fnm env --use-on-cd') DO CALL %%z
)
```

⚠️ If you get the error `i was unexpected at this time`, please make a .cmd file as suggested by the first step in the Usage with Cmder secton add it's path to the `AutoRun` registry key.

#### Usage with Cmder

Usage is very similar to the normal WinCMD install, apart for a few tweaks to allow being called from the cmder startup script. The example **assumes** that the `CMDER_ROOT` environment variable is **set** to the **root directory** of your Cmder installation.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"jest": "^29.3.1",
"lerna-changelog": "2.2.0",
"node-fetch": "^3.3.0",
"prettier": "3.0.1",
"prettier": "3.0.2",
"pv": "1.0.1",
"shell-escape": "^0.2.0",
"svg-term-cli": "2.1.1",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::version::Version;
pub enum Arch {
X86,
X64,
X64Musl,
Arm64,
Armv7l,
Ppc64le,
Expand Down Expand Up @@ -43,6 +44,7 @@ impl std::str::FromStr for Arch {
match s {
"x86" => Ok(Arch::X86),
"x64" => Ok(Arch::X64),
"x64-musl" => Ok(Arch::X64Musl),
"arm64" => Ok(Arch::Arm64),
"armv7l" => Ok(Arch::Armv7l),
"ppc64le" => Ok(Arch::Ppc64le),
Expand All @@ -58,6 +60,7 @@ impl std::fmt::Display for Arch {
let arch_str = match self {
Arch::X86 => String::from("x86"),
Arch::X64 => String::from("x64"),
Arch::X64Musl => String::from("x64-musl"),
Arch::Arm64 => String::from("arm64"),
Arch::Armv7l => String::from("armv7l"),
Arch::Ppc64le => String::from("ppc64le"),
Expand Down
9 changes: 6 additions & 3 deletions src/default_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use crate::version::Version;
use std::str::FromStr;

pub fn find_default_version(config: &FnmConfig) -> Option<Version> {
let version_path = config.default_version_dir().canonicalize().ok()?;
let file_name = version_path.parent()?.file_name()?;
Version::from_str(file_name.to_str()?).ok()?.into()
if let Ok(version_path) = config.default_version_dir().canonicalize() {
let file_name = version_path.parent()?.file_name()?;
Version::from_str(file_name.to_str()?).ok()?.into()
} else {
Some(Version::Alias("default".into()))
}
}
2 changes: 1 addition & 1 deletion src/shell/windows_cmd/cd.cmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@echo off
cd %1
cd %*
if "%FNM_VERSION_FILE_STRATEGY%" == "recursive" (
fnm use --silent-if-unchanged
) else (
Expand Down

0 comments on commit 065ff49

Please sign in to comment.