diff --git a/package-lock.json b/package-lock.json index 6ab89b8..1650189 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,27 +8,27 @@ "name": "dev-proxy-toolkit", "version": "0.26.0", "dependencies": { - "json-to-ast": "^2.1.0", - "semver": "^7.7.2" + "json-to-ast": "2.1.0", + "semver": "7.7.2" }, "devDependencies": { - "@types/json-to-ast": "^2.1.4", - "@types/mocha": "^10.0.9", - "@types/node": "^24.0.3", - "@types/sinon": "^17.0.4", - "@types/vscode": "^1.98.0", - "@typescript-eslint/eslint-plugin": "^8.29.0", - "@typescript-eslint/parser": "^8.29.0", - "@vscode/test-cli": "^0.0.11", - "@vscode/test-electron": "^2.4.1", - "copy-webpack-plugin": "^13.0.0", - "eslint": "^9.23.0", - "gts": "^6.0.2", - "sinon": "^21.0.0", - "ts-loader": "^9.5.2", - "typescript": "^5.8.2", - "webpack": "^5.98.0", - "webpack-cli": "^6.0.1" + "@types/json-to-ast": "2.1.4", + "@types/mocha": "10.0.10", + "@types/node": "24.0.3", + "@types/sinon": "17.0.4", + "@types/vscode": "1.101.0", + "@typescript-eslint/eslint-plugin": "8.35.0", + "@typescript-eslint/parser": "8.35.0", + "@vscode/test-cli": "0.0.11", + "@vscode/test-electron": "2.5.2", + "copy-webpack-plugin": "13.0.0", + "eslint": "9.29.0", + "gts": "6.0.2", + "sinon": "21.0.0", + "ts-loader": "9.5.2", + "typescript": "5.8.3", + "webpack": "5.99.9", + "webpack-cli": "6.0.1" }, "engines": { "vscode": "^1.101.0" diff --git a/src/detect.ts b/src/detect.ts index 96b70e2..354a520 100644 --- a/src/detect.ts +++ b/src/detect.ts @@ -41,11 +41,29 @@ export const extractVersionFromOutput = (output: string): string => { 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] : ''; + // Split into lines and look for version information on dedicated lines + // This avoids extracting versions from file paths like /opt/homebrew/Cellar/dev-proxy/v0.29.1/devproxy-errors.json + const lines = output.split('\n'); + + // Look for lines that contain version information (not file paths) + for (const line of lines) { + const trimmedLine = line.trim(); + + // Skip lines that contain file paths (indicated by slashes and common path patterns) + if (trimmedLine.includes('/') || trimmedLine.includes('\\') || trimmedLine.includes('loaded from')) { + continue; + } + + // Look for version pattern on non-filepath lines + // 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 = trimmedLine.match(semverRegex); + if (match) { + return match[1]; + } + } + + return ''; }; export const getOutdatedVersion = async (devProxyExe: string): Promise => { diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index 252bb4d..983adc9 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -625,4 +625,64 @@ suite('extractVersionFromOutput', () => { const result = detect.extractVersionFromOutput(output); assert.strictEqual(result, '1.0.0-beta.1'); }); + + test('should not extract version from file paths in error responses (issue #286)', () => { + const output = `info 1 error responses loaded from /opt/homebrew/Cellar/dev-proxy/v0.29.1/devproxy-errors.json`; + + const result = detect.extractVersionFromOutput(output); + assert.strictEqual(result, ''); + }); + + test('should extract version from update notification line, ignoring file paths (issue #286)', () => { + const output = `info 1 error responses loaded from /opt/homebrew/Cellar/dev-proxy/v0.29.0/devproxy-errors.json +info v0.29.1`; + + const result = detect.extractVersionFromOutput(output); + assert.strictEqual(result, '0.29.1'); + }); + + test('should not extract version from Windows file paths', () => { + const output = `info 1 error responses loaded from C:\\Program Files\\dev-proxy\\v0.29.1\\devproxy-errors.json`; + + const result = detect.extractVersionFromOutput(output); + assert.strictEqual(result, ''); + }); + + test('should extract version from actual update notification with Windows paths in earlier lines', () => { + const output = `info 1 error responses loaded from C:\\Program Files\\dev-proxy\\v0.29.0\\devproxy-errors.json +info v0.29.1`; + + const result = detect.extractVersionFromOutput(output); + assert.strictEqual(result, '0.29.1'); + }); + + test('should not extract beta version from Unix file paths (issue #286)', () => { + const output = `info 1 error responses loaded from /opt/homebrew/Cellar/dev-proxy/v0.30.0-beta.2/devproxy-errors.json`; + + const result = detect.extractVersionFromOutput(output); + assert.strictEqual(result, ''); + }); + + test('should not extract beta version from Windows file paths (issue #286)', () => { + const output = `info 1 error responses loaded from C:\\Program Files\\dev-proxy\\v0.30.0-beta.2\\devproxy-errors.json`; + + const result = detect.extractVersionFromOutput(output); + assert.strictEqual(result, ''); + }); + + test('should extract beta version from update notification, ignoring file paths (issue #286)', () => { + const output = `info 1 error responses loaded from /opt/homebrew/Cellar/dev-proxy/v0.30.0-beta.1/devproxy-errors.json +info v0.30.0-beta.2`; + + const result = detect.extractVersionFromOutput(output); + assert.strictEqual(result, '0.30.0-beta.2'); + }); + + test('should extract beta version from update notification with Windows paths in earlier lines (issue #286)', () => { + const output = `info 1 error responses loaded from C:\\Program Files\\dev-proxy\\v0.30.0-beta.1\\devproxy-errors.json +info v0.30.0-beta.2`; + + const result = detect.extractVersionFromOutput(output); + assert.strictEqual(result, '0.30.0-beta.2'); + }); });