Skip to content

Commit 3ff71c5

Browse files
authored
Add version check (#43)
1 parent 6ca4dd7 commit 3ff71c5

File tree

7 files changed

+161
-12
lines changed

7 files changed

+161
-12
lines changed

package-lock.json

Lines changed: 14 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"devDependencies": {
4949
"@types/json-to-ast": "^2.1.4",
5050
"@types/mocha": "^10.0.6",
51-
"@types/node": "20.8.2",
51+
"@types/node": "^20.11.17",
5252
"@types/vscode": "^1.85.0",
5353
"@typescript-eslint/eslint-plugin": "^6.19.0",
5454
"@typescript-eslint/parser": "^6.19.0",

src/commands.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,10 @@ export const registerCommands = (context: vscode.ExtensionContext) => {
1717
}
1818
)
1919
);
20+
21+
context.subscriptions.push(
22+
vscode.commands.registerCommand('dev-proxy-toolkit.upgrade', async () => {
23+
const url = 'https://aka.ms/devproxy/upgrade';
24+
vscode.env.openExternal(vscode.Uri.parse(url));
25+
}));
2026
};

src/detect.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { exec } from 'child_process';
2-
import { DevProxyInstall } from './types';
2+
import { DevProxyInstall, Release } from './types';
33
import os from 'os';
44

55
const getExecutablePath = async (filename: string): Promise<string> => {
@@ -61,12 +61,22 @@ export const detectDevProxyInstall = async (): Promise<DevProxyInstall> => {
6161
const isInstalled = filePath !== '';
6262
const isBeta = version.includes('beta');
6363
const platform = os.platform();
64+
const latestVersion = await getLatestVersion();
65+
const isLatest = latestVersion === version;
6466

6567
return {
6668
filePath,
6769
version,
6870
isInstalled,
6971
isBeta,
70-
platform
72+
platform,
73+
latestVersion,
74+
isLatest
7175
};
76+
};
77+
78+
export const getLatestVersion = async (): Promise<string> => {
79+
const request = await fetch('https://api.github.com/repos/microsoft/dev-proxy/releases');
80+
const release = await request.json() as Release;
81+
return release.tag_name.replace('v', '');
7282
};

src/notifications.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ export const handleStartNotification = (devProxyInstall: DevProxyInstall) => {
1616
};
1717
};
1818
};
19+
20+
if (!devProxyInstall.isLatest) {
21+
return () => {
22+
const message = `New Dev Proxy version ${devProxyInstall.latestVersion} is available.`;
23+
return {
24+
message,
25+
show: async () => {
26+
const result = await vscode.window.showInformationMessage(message, 'Upgrade');
27+
if (result === 'Upgrade') {
28+
await vscode.commands.executeCommand('dev-proxy-toolkit.upgrade');
29+
};
30+
}
31+
};
32+
};
33+
};
1934
};
2035

2136
export const processNotification = (notification: (() => { message: string; show: () => Promise<void>; }) | undefined) => {

src/test/extension.test.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ suite('urlsToWatch', () => {
1818
const fileName = 'config-urls-to-watch-required.json';
1919
const filePath = path.resolve(__dirname, 'examples', fileName);
2020
const document = await vscode.workspace.openTextDocument(filePath);
21-
const diagnostics = vscode.languages.getDiagnostics(document.uri);
21+
const diagnostics = vscode.languages.getDiagnostics(document.uri);
2222

2323
const expected = {
2424
message: 'Add at least one url to watch.',
@@ -241,7 +241,9 @@ suite('notifications', () => {
241241
version: '',
242242
platform: 'darwin',
243243
isInstalled: false,
244+
latestVersion: '0.14.1',
244245
isBeta: false,
246+
isLatest: false
245247
};
246248
const notification = handleStartNotification(devProxyInstall);
247249

@@ -256,7 +258,9 @@ suite('notifications', () => {
256258
version: '',
257259
platform: 'win32',
258260
isInstalled: false,
261+
latestVersion: '0.14.1',
259262
isBeta: false,
263+
isLatest: false
260264
};
261265
const notification = handleStartNotification(devProxyInstall);
262266

@@ -268,10 +272,12 @@ suite('notifications', () => {
268272
test('should not show install notification when devproxy is installed on mac', async () => {
269273
const devProxyInstall: DevProxyInstall = {
270274
filePath: 'somepath/devproxy',
271-
version: '0.1.0',
275+
version: '0.14.1',
272276
platform: 'darwin',
273277
isInstalled: true,
278+
latestVersion: '0.14.1',
274279
isBeta: false,
280+
isLatest: true
275281
};
276282
const notification = handleStartNotification(devProxyInstall);
277283

@@ -285,7 +291,9 @@ suite('notifications', () => {
285291
version: '0.1.0',
286292
platform: 'win32',
287293
isInstalled: true,
294+
latestVersion: '0.14.1',
288295
isBeta: false,
296+
isLatest: true
289297
};
290298
const notification = handleStartNotification(devProxyInstall);
291299

@@ -297,15 +305,34 @@ suite('notifications', () => {
297305
test('should not show install notification when running in unsupported operating system', async () => {
298306
const devProxyInstall: DevProxyInstall = {
299307
filePath: 'somepath/devproxy',
300-
version: '0.1.0',
308+
version: '0.14.1',
301309
platform: 'linux',
302310
isInstalled: true,
311+
latestVersion: '0.14.1',
303312
isBeta: false,
313+
isLatest: true
304314
};
305315
const notification = handleStartNotification(devProxyInstall);
306316

307317
const expected = true;
308318
const actual = notification === undefined;
309319
assert.strictEqual(actual, expected);
310320
});
321+
322+
test('should show upgrade notification when devproxy is not latest version', async () => {
323+
const devProxyInstall: DevProxyInstall = {
324+
filePath: 'somepath/devproxy',
325+
version: '0.1.0',
326+
platform: 'win32',
327+
isInstalled: true,
328+
latestVersion: '0.14.1',
329+
isBeta: false,
330+
isLatest: false
331+
};
332+
const notification = handleStartNotification(devProxyInstall);
333+
334+
const expected = 'New Dev Proxy version 0.14.1 is available.';
335+
const actual = notification !== undefined && notification().message;
336+
assert.strictEqual(actual, expected);
337+
});
311338
});

src/types.ts

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,86 @@ export type DevProxyInstall = {
2323
isInstalled: boolean;
2424
isBeta: boolean;
2525
platform: NodeJS.Platform;
26-
};
26+
latestVersion: string;
27+
isLatest: boolean;
28+
};
29+
30+
export type Release = {
31+
url: string
32+
assets_url: string
33+
upload_url: string
34+
html_url: string
35+
id: number
36+
author: Author
37+
node_id: string
38+
tag_name: string
39+
target_commitish: string
40+
name: string
41+
draft: boolean
42+
prerelease: boolean
43+
created_at: string
44+
published_at: string
45+
assets: Asset[]
46+
tarball_url: string
47+
zipball_url: string
48+
body: string
49+
mentions_count: number
50+
};
51+
52+
type Author = {
53+
login: string
54+
id: number
55+
node_id: string
56+
avatar_url: string
57+
gravatar_id: string
58+
url: string
59+
html_url: string
60+
followers_url: string
61+
following_url: string
62+
gists_url: string
63+
starred_url: string
64+
subscriptions_url: string
65+
organizations_url: string
66+
repos_url: string
67+
events_url: string
68+
received_events_url: string
69+
type: string
70+
site_admin: boolean
71+
};
72+
73+
type Asset = {
74+
url: string
75+
id: number
76+
node_id: string
77+
name: string
78+
label: string
79+
uploader: Uploader
80+
content_type: string
81+
state: string
82+
size: number
83+
download_count: number
84+
created_at: string
85+
updated_at: string
86+
browser_download_url: string
87+
};
88+
89+
type Uploader = {
90+
login: string
91+
id: number
92+
node_id: string
93+
avatar_url: string
94+
gravatar_id: string
95+
url: string
96+
html_url: string
97+
followers_url: string
98+
following_url: string
99+
gists_url: string
100+
starred_url: string
101+
subscriptions_url: string
102+
organizations_url: string
103+
repos_url: string
104+
events_url: string
105+
received_events_url: string
106+
type: string
107+
site_admin: boolean
108+
};

0 commit comments

Comments
 (0)