diff --git a/extension/src/utils/flow-version.ts b/extension/src/utils/flow-version.ts index d1603741..f97eb9a6 100644 --- a/extension/src/utils/flow-version.ts +++ b/extension/src/utils/flow-version.ts @@ -31,13 +31,13 @@ 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-]+)*))?)/g - let versionMatch = output.match(versionRegex) + let versionMatch = versionRegex.exec(output) 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-]+)*)))?)/g - versionMatch ??= output.match(fallbackRegex) + versionMatch ??= fallbackRegex.exec(output) 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.`) return versionMatch[1] diff --git a/extension/test/unit/parser.test.ts b/extension/test/unit/parser.test.ts index cf5fc3c0..d4b12ce8 100644 --- a/extension/test/unit/parser.test.ts +++ b/extension/test/unit/parser.test.ts @@ -3,7 +3,7 @@ import { ASSERT_EQUAL } from '../globals' suite('Parsing Unit Tests', () => { test('Flow CLI Version Extraction', async () => { - let versionTest: Buffer = Buffer.from('Version: v0.1.0\nCommit: 0a1b2c3d') + let versionTest: Buffer = Buffer.from('Foobar123\nVersion: v0.1.0\nCommit: 0a1b2c3d') let formatted = extractFlowCLIVersion(versionTest) ASSERT_EQUAL(formatted, 'v0.1.0')