Skip to content

Commit

Permalink
Add temporary patch for broken flow version output (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink authored Apr 2, 2024
1 parent add1492 commit b9761f3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
18 changes: 11 additions & 7 deletions extension/src/flow-cli/cli-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const CHECK_FLOW_CLI_CMD_NO_JSON = (flowCommand: string): string => `${flowComma
const KNOWN_BINS = ['flow', 'flow-c1']

const CADENCE_V1_CLI_REGEX = /-cadence-v1.0.0/g
const LEGACY_VERSION_REGEXP = /Version:\s*(v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)(\s|$)/m

export interface CliBinary {
name: string
Expand Down Expand Up @@ -118,14 +119,17 @@ export class CliProvider {
async #fetchBinaryInformationOld (bin: string): Promise<CliBinary | null> {
try {
// Get user's version informaton
const buffer: string = (await execDefault(CHECK_FLOW_CLI_CMD_NO_JSON(
const output = (await execDefault(CHECK_FLOW_CLI_CMD_NO_JSON(
bin
))).stdout
)))

// Format version string from output
let versionStr: string | null = parseFlowCliVersion(buffer)
let versionStr: string | null = parseFlowCliVersion(output.stdout)
if (versionStr === null) {
// Try to fallback to stderr as patch for bugged version
versionStr = parseFlowCliVersion(output.stderr)
}

versionStr = semver.clean(versionStr)
versionStr = versionStr != null ? semver.clean(versionStr) : null
if (versionStr === null) return null

// Ensure user has a compatible version number installed
Expand Down Expand Up @@ -181,6 +185,6 @@ export function isCadenceV1Cli (version: semver.SemVer): boolean {
return CADENCE_V1_CLI_REGEX.test(version.raw)
}

export function parseFlowCliVersion (buffer: Buffer | string): string {
return (buffer.toString().split('\n')[0]).split(' ')[1]
export function parseFlowCliVersion (buffer: Buffer | string): string | null {
return buffer.toString().match(LEGACY_VERSION_REGEXP)?.[1] ?? null
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Cadence",
"publisher": "onflow",
"description": "This extension integrates Cadence, the resource-oriented smart contract programming language of Flow, into Visual Studio Code.",
"version": "2.3.0",
"version": "2.3.1",
"repository": {
"type": "git",
"url": "https://github.com/onflow/vscode-cadence.git"
Expand Down

0 comments on commit b9761f3

Please sign in to comment.