Skip to content

Commit

Permalink
fixup regex
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed Jan 12, 2024
1 parent c5029f0 commit a519012
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions extension/src/utils/flow-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ async function fetchFlowVersion (): Promise<semver.SemVer | null> {
export function extractFlowCLIVersion (buffer: Buffer | string): string | null {
const output = buffer.toString()

const versionRegex = /Version: 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-]+)*))?/
const versionRegex = /Version: 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-]+)*))?)/g
let versionMatch = output.match(versionRegex)

if (versionMatch != null) return versionMatch[1]

// Fallback regex to semver if versionRegex fails (protect against future changes to flow version output)
const fallbackRegex = /^((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-]+)*)))?$/
const fallbackRegex = /(((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-]+)*)))?)/g
versionMatch ??= output.match(fallbackRegex)
if (versionMatch != null) {
void vscode.window.showWarningMessage(`Unfamiliar Flow CLI version format. Assuming that version is ${versionMatch[1]}. Please report this issue to the Flow team.`)
Expand Down

0 comments on commit a519012

Please sign in to comment.