diff --git a/extension/src/flow-cli/cli-provider.ts b/extension/src/flow-cli/cli-provider.ts index 3cfe03cc..38286657 100644 --- a/extension/src/flow-cli/cli-provider.ts +++ b/extension/src/flow-cli/cli-provider.ts @@ -6,7 +6,9 @@ import * as vscode from 'vscode' import { Settings } from '../settings/settings' import { isEqual } from 'lodash' -const CHECK_FLOW_CLI_CMD = (flowCommand: string): string => `${flowCommand} version` +const CHECK_FLOW_CLI_CMD = (flowCommand: string): string => `${flowCommand} version --output=json` +const CHECK_FLOW_CLI_CMD_NO_JSON = (flowCommand: string): string => `${flowCommand} version` + const KNOWN_BINS = ['flow', 'flow-c1'] const CADENCE_V1_CLI_REGEX = /-cadence-v1.0.0/g @@ -16,6 +18,10 @@ export interface CliBinary { version: semver.SemVer } +interface FlowVersionOutput { + version: string +} + interface AvailableBinariesCache { [key: string]: StateCache } @@ -85,6 +91,7 @@ export class CliProvider { }) } + // Fetches the binary information for the given binary async #fetchBinaryInformation (bin: string): Promise { try { // Get user's version informaton @@ -92,6 +99,29 @@ export class CliProvider { bin ))).stdout + // Format version string from output + const versionInfo: FlowVersionOutput = JSON.parse(buffer) + + // Ensure user has a compatible version number installed + const version: semver.SemVer | null = semver.parse(versionInfo.version) + if (version === null) return null + + return { name: bin, version } + } catch { + // Fallback to old method if JSON is not supported/fails + return await this.#fetchBinaryInformationOld(bin) + } + } + + // Old version of fetchBinaryInformation (before JSON was supported) + // Used as fallback for old CLI versions + async #fetchBinaryInformationOld (bin: string): Promise { + try { + // Get user's version informaton + const buffer: string = (await execDefault(CHECK_FLOW_CLI_CMD_NO_JSON( + bin + ))).stdout + // Format version string from output let versionStr: string | null = parseFlowCliVersion(buffer)