Skip to content

Commit 1d45319

Browse files
authored
Avoid referencing not-yet published @types/vscode versions (#534)
1 parent 547da2f commit 1d45319

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

generators/app/env.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,38 @@ import * as fs from 'fs';
77
import * as path from 'path';
88
import { fileURLToPath } from 'url';
99

10-
const fallbackVersion = '^1.54.0';
10+
const fallbackVersion = '^1.103.0';
1111
let versionPromise = undefined;
1212

1313
export function getLatestVSCodeVersion() {
1414
if (!versionPromise) {
15-
versionPromise = request.xhr({ url: 'https://update.code.visualstudio.com/api/releases/stable', headers: { "X-API-Version": "2" } }).then(res => {
16-
if (res.status === 200) {
17-
try {
18-
var tagsAndCommits = JSON.parse(res.responseText);
19-
if (Array.isArray(tagsAndCommits) && tagsAndCommits.length > 0) {
20-
var segments = tagsAndCommits[0].version.split('.');
21-
if (segments.length === 3) {
22-
return '^' + segments[0] + '.' + segments[1] + '.0';
15+
// Fetch the latest published @types/vscode version from the npm registry
16+
// and return a caret-pinned range (e.g. ^1.93.0).
17+
versionPromise = request
18+
.xhr({ url: 'https://registry.npmjs.org/@types/vscode/latest', headers: { 'Accept': 'application/json' } })
19+
.then(
20+
res => {
21+
if (res.status === 200) {
22+
try {
23+
const meta = JSON.parse(res.responseText);
24+
if (meta && typeof meta.version === 'string' && meta.version) {
25+
return '^' + meta.version;
26+
}
27+
} catch (e) {
28+
console.log('Problem parsing @types/vscode metadata: ' + res.responseText, e);
2329
}
30+
} else {
31+
console.warn('Unable to evaluate the latest @types/vscode version: Status code: ' + res.status + ', ' + res.responseText);
2432
}
25-
} catch (e) {
26-
console.log('Problem parsing version: ' + res.responseText, e);
33+
console.warn('Falling back to: ' + fallbackVersion);
34+
return fallbackVersion;
35+
},
36+
err => {
37+
console.warn('Unable to evaluate the latest @types/vscode version: Error: ', err);
38+
console.warn('Falling back to: ' + fallbackVersion);
39+
return fallbackVersion;
2740
}
28-
} else {
29-
console.warn('Unable to evaluate the latest vscode version: Status code: ' + res.status + ', ' + res.responseText);
30-
}
31-
console.warn('Falling back to: ' + fallbackVersion);
32-
return fallbackVersion;
33-
}, err => {
34-
console.warn('Unable to evaluate the latest vscode version: Error: ', err);
35-
console.warn('Falling back to: ' + fallbackVersion);
36-
return fallbackVersion;
37-
});
41+
);
3842
}
3943
return versionPromise;
4044
};

0 commit comments

Comments
 (0)