Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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:
Expand Down
15 changes: 13 additions & 2 deletions src/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<string> => {
try {
const outdated = await executeCommand(`${devProxyExe} outdated --short`);
return outdated ? outdated.trim() : '';
return extractVersionFromOutput(outdated);
} catch (error) {
return "";
}
Expand Down
78 changes: 78 additions & 0 deletions src/test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});