Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Commit 1b630d2

Browse files
authored
Fix getFlowVersion (#235)
1 parent 6e74d86 commit 1b630d2

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

.changeset/nasty-otters-chew.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@onflow/flow-js-testing": patch
3+
---
4+
5+
Add fallback for version checking CLI when JSON not supported

src/utils.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,18 @@ export async function getFlowVersion(flowCommand = "flow") {
5252
"Could not determine Flow CLI version, please make sure it is installed and available in your PATH"
5353
)
5454
} else {
55-
const versionStr = JSON.parse(stdout).version
56-
const version = semver.parse(versionStr)
55+
let versionStr
56+
try {
57+
versionStr = JSON.parse(stdout).version
58+
} catch (error) {
59+
// fallback to regex for older versions of the CLI without JSON output
60+
const rxResult = /^Version: ([^\s]+)/m.exec(stdout)
61+
if (rxResult) {
62+
versionStr = rxResult[1]
63+
}
64+
}
65+
66+
const version = versionStr ? semver.parse(versionStr) : undefined
5767
if (!version) {
5868
reject(`Invalid Flow CLI version string: ${versionStr}`)
5969
}

0 commit comments

Comments
 (0)