From 1b630d2c9bdd97e30d0b302997ff6c9f2c800d98 Mon Sep 17 00:00:00 2001 From: Luze26 Date: Thu, 23 May 2024 20:17:11 +0200 Subject: [PATCH] Fix getFlowVersion (#235) --- .changeset/nasty-otters-chew.md | 5 +++++ src/utils.js | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 .changeset/nasty-otters-chew.md diff --git a/.changeset/nasty-otters-chew.md b/.changeset/nasty-otters-chew.md new file mode 100644 index 0000000..2dcdfdf --- /dev/null +++ b/.changeset/nasty-otters-chew.md @@ -0,0 +1,5 @@ +--- +"@onflow/flow-js-testing": patch +--- + +Add fallback for version checking CLI when JSON not supported diff --git a/src/utils.js b/src/utils.js index cea4982..80d6832 100644 --- a/src/utils.js +++ b/src/utils.js @@ -52,8 +52,18 @@ export async function getFlowVersion(flowCommand = "flow") { "Could not determine Flow CLI version, please make sure it is installed and available in your PATH" ) } else { - const versionStr = JSON.parse(stdout).version - const version = semver.parse(versionStr) + let versionStr + try { + versionStr = JSON.parse(stdout).version + } catch (error) { + // fallback to regex for older versions of the CLI without JSON output + const rxResult = /^Version: ([^\s]+)/m.exec(stdout) + if (rxResult) { + versionStr = rxResult[1] + } + } + + const version = versionStr ? semver.parse(versionStr) : undefined if (!version) { reject(`Invalid Flow CLI version string: ${versionStr}`) }