From d3668917b3f726bd7c7148b0856bf4b1191fb753 Mon Sep 17 00:00:00 2001 From: Garry Trinder Date: Wed, 25 Jun 2025 11:30:00 +0100 Subject: [PATCH] Fix new version notification. Closes #281 Closes #281 --- CHANGELOG.md | 6 ++- src/detect.ts | 15 +++++++- src/test/extension.test.ts | 78 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0315a21..3ee9337 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 > **Note**: odd version numbers, for example, `0.13.0`, are not included in this changelog. They are used to test the new features and fixes before the final release. -## [0.25.3] - Unreleased +## [0.25.4] - Unreleased ### Added: @@ -24,6 +24,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Improved diagnostics range detection to ensure that they only appear againt the relevant code and don't overlap with ending quotes and commas - Detection: Changed isDevProxyRunning check to use Dev Proxy API instead of process detection +### Fixed: + +- Detection: Improved new version detection logic to resolve issue where toast notification would output irrelevant information + ## [0.24.0] - 2025-06-04 ### Added: diff --git a/src/detect.ts b/src/detect.ts index e9bddbe..96b70e2 100644 --- a/src/detect.ts +++ b/src/detect.ts @@ -25,7 +25,6 @@ export const detectDevProxyInstall = async (versionPreference: VersionPreference const isOutdated = isInstalled && outdatedVersion !== ''; const isRunning = await isDevProxyRunning(devProxyExe); vscode.commands.executeCommand('setContext', 'isDevProxyRunning', isRunning); - return { version, isInstalled, @@ -37,10 +36,22 @@ export const detectDevProxyInstall = async (versionPreference: VersionPreference }; }; +export const extractVersionFromOutput = (output: string): string => { + if (!output) { + return ''; + } + + // Extract version number using semver pattern + // Matches: major.minor.patch[-prerelease][+build] but only captures up to prerelease + const semverRegex = /v?(\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?)(?:\+[a-zA-Z0-9.-]+)?/; + const match = output.match(semverRegex); + return match ? match[1] : ''; +}; + export const getOutdatedVersion = async (devProxyExe: string): Promise => { try { const outdated = await executeCommand(`${devProxyExe} outdated --short`); - return outdated ? outdated.trim() : ''; + return extractVersionFromOutput(outdated); } catch (error) { return ""; } diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index 3bb23f3..252bb4d 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -548,3 +548,81 @@ suite('Commands', () => { assert.ok(jwtCreateCommand, 'JWT create command should be registered'); }); }); + +suite('extractVersionFromOutput', () => { + test('should extract stable version from Dev Proxy output', () => { + const output = ` info 1 error responses loaded from /opt/homebrew/Cellar/dev-proxy/0.29.0/devproxy-errors.json + info v0.29.0`; + + const result = detect.extractVersionFromOutput(output); + assert.strictEqual(result, '0.29.0'); + }); + + test('should extract beta version from Dev Proxy output', () => { + const output = ` info 1 error responses loaded from /opt/homebrew/Cellar/dev-proxy/0.30.0-beta.1/devproxy-errors.json + info v0.30.0-beta.1`; + + const result = detect.extractVersionFromOutput(output); + assert.strictEqual(result, '0.30.0-beta.1'); + }); + + test('should extract version without v prefix', () => { + const output = ` info Some message + info 1.2.3`; + + const result = detect.extractVersionFromOutput(output); + assert.strictEqual(result, '1.2.3'); + }); + + test('should extract pre-release version with alpha identifier', () => { + const output = ` info Dev Proxy version + info v2.1.0-alpha.5`; + + const result = detect.extractVersionFromOutput(output); + assert.strictEqual(result, '2.1.0-alpha.5'); + }); + + test('should extract pre-release version with rc identifier', () => { + const output = ` info Dev Proxy version + info v1.5.0-rc.2`; + + const result = detect.extractVersionFromOutput(output); + assert.strictEqual(result, '1.5.0-rc.2'); + }); + + test('should return empty string for output without version', () => { + const output = ` info Some random output + info No version here`; + + const result = detect.extractVersionFromOutput(output); + assert.strictEqual(result, ''); + }); + + test('should return empty string for empty output', () => { + const result = detect.extractVersionFromOutput(''); + assert.strictEqual(result, ''); + }); + + test('should return empty string for null/undefined output', () => { + const result1 = detect.extractVersionFromOutput(null as any); + const result2 = detect.extractVersionFromOutput(undefined as any); + assert.strictEqual(result1, ''); + assert.strictEqual(result2, ''); + }); + + test('should extract first version when multiple versions present', () => { + const output = ` info v1.0.0 + info v2.0.0`; + + const result = detect.extractVersionFromOutput(output); + assert.strictEqual(result, '1.0.0'); + }); + + test('should handle version with build metadata', () => { + const output = ` info Build info + info v1.0.0-beta.1+build.123`; + + const result = detect.extractVersionFromOutput(output); + assert.strictEqual(result, '1.0.0-beta.1'); + }); +});