-
Notifications
You must be signed in to change notification settings - Fork 631
fix: --use-on-cd reverts to default version when leaving versioned directories #1504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "fnm": patch | ||
| --- | ||
|
|
||
| Fixed `--use-on-cd` with `local` strategy to revert to the default Node version when entering a directory without a version file. Previously, the Node version would remain "stuck" on the last project version after leaving a versioned directory. This now matches nvm's auto-switching behavior. | ||
|
|
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,84 @@ | ||||||
| import { writeFile, mkdir } from "node:fs/promises" | ||||||
| import { join } from "node:path" | ||||||
| import { script } from "./shellcode/script.js" | ||||||
| import { Bash, Fish, PowerShell, Zsh } from "./shellcode/shells.js" | ||||||
| import testCwd from "./shellcode/test-cwd.js" | ||||||
| import testNodeVersion from "./shellcode/test-node-version.js" | ||||||
| import describe from "./describe.js" | ||||||
|
|
||||||
| const defaultVersion = "v8.11.3" | ||||||
| const projectVersion = "v12.22.12" | ||||||
|
|
||||||
| for (const shell of [Bash, Zsh, Fish, PowerShell]) { | ||||||
| describe(shell, () => { | ||||||
| test(`reverts to default when leaving versioned directory (local strategy)`, async () => { | ||||||
| await mkdir(join(testCwd(), "subdir"), { recursive: true }) | ||||||
| await writeFile(join(testCwd(), "subdir", ".node-version"), projectVersion) | ||||||
|
|
||||||
| await script(shell) | ||||||
| .then(shell.env({ useOnCd: true })) | ||||||
| .then(shell.call("fnm", ["install", defaultVersion])) | ||||||
| .then(shell.call("fnm", ["install", projectVersion])) | ||||||
| .then(shell.call("fnm", ["default", defaultVersion])) | ||||||
| .then(shell.call("cd", ["subdir"])) | ||||||
| .then(testNodeVersion(shell, projectVersion)) | ||||||
| .then(shell.call("cd", [".."])) | ||||||
| .then(testNodeVersion(shell, defaultVersion)) | ||||||
| .execute(shell) | ||||||
| }) | ||||||
|
|
||||||
| test(`stays on project version while inside project (local strategy)`, async () => { | ||||||
|
||||||
| test(`stays on project version while inside project (local strategy)`, async () => { | |
| test(`reverts to default in subdirectories without version files (local strategy)`, async () => { |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,11 @@ pub struct Env { | |||||
| #[clap(long, hide = true)] | ||||||
| multi: bool, | ||||||
| /// Print the script to change Node versions every directory change | ||||||
| /// | ||||||
| /// When entering a directory with a version file, fnm switches to that version. | ||||||
| /// When entering a directory without a version file, fnm switches to the default version. | ||||||
|
||||||
| /// When entering a directory without a version file, fnm switches to the default version. | |
| /// When leaving a directory with a version file and entering one without, fnm reverts to the default Node.js version (if one is configured). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test file excludes WinCmd from the shell tests (line 12 only tests Bash, Zsh, Fish, PowerShell), but the existing use-on-cd.test.ts includes WinCmd (line 9). Since the Windows Cmd shell hook uses a different implementation (cd.cmd file) that was not updated in this PR, this omission hides the fact that the new revert-to-default behavior is not available for Windows Cmd users. Consider either: