Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/witty-drives-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"fnm": patch
---

fix `cd /d <drive>` failing in Windows Command Prompt when use-on-cd is enabled: the generated `cd.cmd` always prepended `/d`, so a user-supplied `/d` was passed twice and `cd` failed with "The syntax of the command is incorrect". Fixes #1556

```sh-session
> cd /d D:\
The syntax of the command is incorrect.
```
22 changes: 22 additions & 0 deletions e2e/repros/issue-1556.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { writeFile, mkdir } from "node:fs/promises"
import { join } from "node:path"
import { script } from "../shellcode/script.js"
import { WinCmd } from "../shellcode/shells.js"
import testCwd from "../shellcode/test-cwd.js"
import testNodeVersion from "../shellcode/test-node-version.js"
import describe from "../describe.js"

describe(WinCmd, () => {
test(`issue #1556: cd /d works with use-on-cd`, async () => {
const subdir = join(testCwd(), "subdir")
await mkdir(subdir, { recursive: true })
await writeFile(join(subdir, ".node-version"), "v12.22.12")
await script(WinCmd)
.then(WinCmd.env({ useOnCd: true }))
.then(WinCmd.call("fnm", ["install", "v8.11.3"]))
.then(WinCmd.call("fnm", ["install", "v12.22.12"]))
.then(WinCmd.call("cd", ["/d", subdir]))
.then(testNodeVersion(WinCmd, "v12.22.12"))
.execute(WinCmd)
})
})
6 changes: 5 additions & 1 deletion src/shell/windows_cmd/cd.cmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
@echo off
cd /d %*
rem Add /d only when the user didn't pass it themselves, so `cd /d D:\` works (#1556).
rem No if/else parentheses or setlocal here: %* may contain ")" (e.g. "C:\Program Files (x86)"),
rem and endlocal would revert the directory change.
if /i "%~1" == "/d" cd %*
if /i not "%~1" == "/d" cd /d %*
if "%FNM_VERSION_FILE_STRATEGY%" == "recursive" (
fnm use --silent-if-unchanged
) else (
Expand Down