|
8 | 8 | * |
9 | 9 | * Usage: node scripts/download-vscode.js [version] |
10 | 10 | * |
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. |
14 | 13 | */ |
15 | 14 |
|
16 | | -import { readFileSync } from 'node:fs'; |
17 | 15 | import { downloadAndUnzipVSCode } from '@vscode/test-electron'; |
18 | 16 |
|
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'; |
30 | 19 |
|
31 | 20 | console.log(`Downloading VS Code (${version}) for integration tests...`); |
32 | 21 |
|
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 | + } |
45 | 42 | } |
0 commit comments