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
5 changes: 5 additions & 0 deletions .changeset/tidy-installed-warning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fnm": patch
---

Log the already-installed warning at info level so successful repeated installations do not write to stderr or appear with `--log-level error`. Fixes #1461.
8 changes: 4 additions & 4 deletions e2e/__snapshots__/existing-installation.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ exports[`Bash warns about an existing installation: Bash 1`] = `
"set -e
eval "$(fnm env)"
fnm install v8.11.3
(fnm install v8.11.3 2>&1) | grep 'already installed' || (echo "Expected output to contain 'already installed'" && exit 1)"
(fnm install v8.11.3) | grep 'already installed' || (echo "Expected output to contain 'already installed'" && exit 1)"
`;

exports[`Fish warns about an existing installation: Fish 1`] = `
"fnm env | source
fnm install v8.11.3
begin; fnm install v8.11.3 2>&1; end | grep 'already installed'; or echo "Expected output to contain 'already installed'" && exit 1"
begin; fnm install v8.11.3; end | grep 'already installed'; or echo "Expected output to contain 'already installed'" && exit 1"
`;

exports[`PowerShell warns about an existing installation: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
fnm install v8.11.3
$($__out__ = $(fnm install v8.11.3 2>&1 | Select-String 'already installed'); if ($__out__ -eq $null) { exit 1 } else { $__out__ })"
$($__out__ = $(fnm install v8.11.3 | Select-String 'already installed'); if ($__out__ -eq $null) { exit 1 } else { $__out__ })"
`;

exports[`Zsh warns about an existing installation: Zsh 1`] = `
"set -e
eval "$(fnm env)"
fnm install v8.11.3
(fnm install v8.11.3 2>&1) | grep 'already installed' || (echo "Expected output to contain 'already installed'" && exit 1)"
(fnm install v8.11.3) | grep 'already installed' || (echo "Expected output to contain 'already installed'" && exit 1)"
`;
7 changes: 3 additions & 4 deletions e2e/existing-installation.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import getStderr from "./shellcode/get-stderr.js"
import { script } from "./shellcode/script.js"
import { Bash, Fish, PowerShell, Zsh } from "./shellcode/shells.js"
import describe from "./describe.js"
Expand All @@ -11,9 +10,9 @@ for (const shell of [Bash, Zsh, Fish, PowerShell]) {
.then(shell.call("fnm", ["install", "v8.11.3"]))
.then(
shell.scriptOutputContains(
getStderr(shell.call("fnm", ["install", "v8.11.3"])),
"'already installed'"
)
shell.call("fnm", ["install", "v8.11.3"]),
"'already installed'",
),
)
.takeSnapshot(shell)
.execute(shell)
Expand Down
51 changes: 51 additions & 0 deletions e2e/repros/issue-1461.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { writeFile } from "node:fs/promises"
import { join } from "node:path"
import describe from "../describe.js"
import { script } from "../shellcode/script.js"
import { Bash, Fish, PowerShell, Zsh } from "../shellcode/shells.js"
import testCwd from "../shellcode/test-cwd.js"

for (const shell of [Bash, Zsh, Fish, PowerShell]) {
describe(shell, () => {
test("issue #1461: repeated installation respects log levels", async () => {
await writeFile(
join(testCwd(), "check-install.cjs"),
`
const assert = require("assert")
const { spawnSync } = require("child_process")
for (const level of ["info", "all", "error", "quiet"]) {
const installed = spawnSync("fnm", ["--log-level", level, "install", "v8.11.3"], { encoding: "utf8" })
assert.strictEqual(installed.status, 0, installed.stderr)
assert.strictEqual(installed.stderr, "")
if (level === "info" || level === "all") {
assert.ok(/already installed/.test(installed.stdout))
} else {
assert.strictEqual(installed.stdout, "")
}

const failed = spawnSync("fnm", ["--log-level", level, "alias", "abcd", "efg"], { encoding: "utf8" })
assert.strictEqual(failed.status, 1)
assert.strictEqual(failed.stdout, "")
if (level === "quiet") {
assert.strictEqual(failed.stderr, "")
} else {
assert.ok(/find requested version/.test(failed.stderr))
}
}
console.log("logging checks passed")
`,
)
await script(shell)
.then(shell.env({}))
.then(shell.call("fnm", ["install", "v8.11.3"]))
.then(
shell.hasCommandOutput(
shell.call("node", ["check-install.cjs"]),
"logging checks passed",
"installation logging checks",
),
)
.execute(shell)
})
})
}
2 changes: 1 addition & 1 deletion src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl Command for Install {
show_progress,
) {
Err(err @ DownloaderError::VersionAlreadyInstalled { .. }) => {
outln!(config, Error, "{} {}", "warning:".bold().yellow(), err);
outln!(config, Info, "{} {}", "warning:".bold().yellow(), err);
}
Err(source) => Err(Error::DownloadError { source })?,
Ok(()) => {}
Expand Down