Skip to content

Commit

Permalink
fix --use-on-cd failing with newly released default of --resolve-engi…
Browse files Browse the repository at this point in the history
…nes when `engines` key didn't exist (#1326)

* fix: swallow missing dotfile if silent_if_unchanged provided

* add test

* add changeset

* fix implementation lmao
  • Loading branch information
Schniz authored Nov 17, 2024
1 parent 144b3e9 commit 172fb0a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tasty-flowers-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fnm": patch
---

fix --use-on-cd failing with newly released default of --resolve-engines when `engines` key didn't exist
14 changes: 14 additions & 0 deletions e2e/use-on-cd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,19 @@ for (const shell of [Bash, Zsh, Fish, PowerShell, WinCmd]) {
.then(testNodeVersion(shell, "v12.22.12"))
.execute(shell)
})

test(`doesn't throw on missing env data`, async () => {
await mkdir(join(testCwd(), "subdir"), { recursive: true })
await writeFile(
join(testCwd(), "subdir", "package.json"),
JSON.stringify({
name: "hello",
}),
)
await script(shell)
.then(shell.env({ useOnCd: true, resolveEngines: true }))
.then(shell.call("cd", ["subdir"]))
.execute(shell)
})
})
}
8 changes: 7 additions & 1 deletion src/commands/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ impl Command for Use {
VersionFileStrategy::Local => InferVersionError::Local,
VersionFileStrategy::Recursive => InferVersionError::Recursive,
})
.map_err(|source| Error::CantInferVersion { source })?;
.map_err(|source| Error::CantInferVersion { source });

// Swallow the missing version error if `silent_if_unchanged` was provided
let requested_version = match (self.silent_if_unchanged, requested_version) {
(true, Err(_)) => return Ok(()),
(_, v) => v?,
};

let (message, version_path) = if let UserVersion::Full(Version::Bypassed) =
requested_version
Expand Down

0 comments on commit 172fb0a

Please sign in to comment.