Skip to content

Commit 0b346ce

Browse files
committed
Add retries to download-vscode.js script
1 parent 080790c commit 0b346ce

File tree

1 file changed

+24
-27
lines changed

1 file changed

+24
-27
lines changed

extensions/vscode/scripts/download-vscode.js

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,35 @@
88
*
99
* Usage: node scripts/download-vscode.js [version]
1010
*
11-
* The version defaults to the minimum VS Code version from engines.vscode in
12-
* package.json (e.g. "^1.110.0" -> "1.110.0"). Pass "stable" or an explicit
13-
* version to override.
11+
* The version defaults to 'stable' to match the .vscode-test.mjs configuration.
12+
* Pass an explicit version (e.g. "1.110.0") to override.
1413
*/
1514

16-
import { readFileSync } from 'node:fs';
1715
import { downloadAndUnzipVSCode } from '@vscode/test-electron';
1816

19-
function getEnginesVscodeVersion() {
20-
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
21-
const range = pkg.engines?.vscode;
22-
if (range) {
23-
const match = range.match(/(\d+\.\d+\.\d+)/);
24-
if (match) return match[1];
25-
}
26-
return 'stable';
27-
}
28-
29-
const version = process.argv[2] || getEnginesVscodeVersion();
17+
const MAX_RETRIES = 3;
18+
const version = process.argv[2] || 'stable';
3019

3120
console.log(`Downloading VS Code (${version}) for integration tests...`);
3221

33-
try {
34-
const vscodeExecutablePath = await downloadAndUnzipVSCode({
35-
version,
36-
timeout: 120_000,
37-
});
38-
console.log(`✅ VS Code downloaded to: ${vscodeExecutablePath}`);
39-
} catch (error) {
40-
console.error(
41-
'❌ Failed to download VS Code:',
42-
error instanceof Error ? error.message : String(error),
43-
);
44-
process.exit(1);
22+
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
23+
try {
24+
const vscodeExecutablePath = await downloadAndUnzipVSCode({
25+
version,
26+
timeout: 120_000,
27+
});
28+
console.log(`✅ VS Code downloaded to: ${vscodeExecutablePath}`);
29+
process.exit(0);
30+
} catch (error) {
31+
const message = error instanceof Error ? error.message : String(error);
32+
console.error(`❌ Attempt ${attempt}/${MAX_RETRIES} failed: ${message}`);
33+
if (attempt < MAX_RETRIES) {
34+
const delayMs = attempt * 5_000;
35+
console.log(` Retrying in ${delayMs / 1_000}s...`);
36+
await new Promise((resolve) => setTimeout(resolve, delayMs));
37+
} else {
38+
console.error('❌ All download attempts failed.');
39+
process.exit(1);
40+
}
41+
}
4542
}

0 commit comments

Comments
 (0)