diff --git a/.changeset/tasty-flowers-attend.md b/.changeset/tasty-flowers-attend.md new file mode 100644 index 000000000..20021d094 --- /dev/null +++ b/.changeset/tasty-flowers-attend.md @@ -0,0 +1,5 @@ +--- +"fnm": patch +--- + +fix --use-on-cd failing with newly released default of --resolve-engines when `engines` key didn't exist diff --git a/e2e/use-on-cd.test.ts b/e2e/use-on-cd.test.ts index 63335489f..99bb7fa1d 100644 --- a/e2e/use-on-cd.test.ts +++ b/e2e/use-on-cd.test.ts @@ -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) + }) }) } diff --git a/src/commands/use.rs b/src/commands/use.rs index 3a7f8f2f3..531e639ee 100644 --- a/src/commands/use.rs +++ b/src/commands/use.rs @@ -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