|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information. |
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | | -// Usage: node script/build/vscodeDtsUpdate.js [branch] |
7 | | -// Downloads proposed API d.ts files from the given branch (default: main) |
8 | | -// of microsoft/vscode and writes the resolved commit SHA to package.json. |
| 6 | +// Usage: node script/build/vscodeDtsUpdate.js |
| 7 | +// Copies proposed API d.ts files from the repo's src/vscode-dts/ directory |
| 8 | +// into this extension's src/extension/ folder based on enabledApiProposals. |
9 | 9 |
|
10 | 10 | const { execSync } = require('child_process'); |
11 | 11 | const fs = require('fs'); |
12 | 12 | const path = require('path'); |
13 | | -const https = require('https'); |
14 | 13 |
|
15 | | -const branch = process.argv[2] || 'main'; |
| 14 | +const vscodeDtsDir = path.resolve('..', '..', 'src', 'vscode-dts'); |
| 15 | +const targetDir = path.resolve('src', 'extension'); |
16 | 16 |
|
17 | | -function resolveCommitSha(branch) { |
18 | | - return new Promise((resolve, reject) => { |
19 | | - const options = { |
20 | | - hostname: 'api.github.com', |
21 | | - path: `/repos/microsoft/vscode/commits/${encodeURIComponent(branch)}`, |
22 | | - headers: { 'User-Agent': 'vscode-copilot-chat', 'Accept': 'application/vnd.github.sha' } |
23 | | - }; |
24 | | - https.get(options, res => { |
25 | | - if (res.statusCode !== 200) { |
26 | | - reject(new Error(`Failed to resolve commit for branch "${branch}": HTTP ${res.statusCode}`)); |
27 | | - return; |
28 | | - } |
29 | | - let data = ''; |
30 | | - res.on('data', chunk => data += chunk); |
31 | | - res.on('end', () => resolve(data.trim())); |
32 | | - }).on('error', reject); |
33 | | - }); |
34 | | -} |
35 | | - |
36 | | -async function main() { |
37 | | - const sha = await resolveCommitSha(branch); |
38 | | - console.log(`Resolved branch "${branch}" to commit ${sha}`); |
39 | | - |
40 | | - // Download proposed d.ts files using the commit SHA |
41 | | - execSync(`node node_modules/@vscode/dts/index.js dev ${sha}`, { stdio: 'inherit' }); |
| 17 | +function main() { |
| 18 | + const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8')); |
| 19 | + const proposals = pkg.enabledApiProposals; |
| 20 | + if (!proposals || proposals.length === 0) { |
| 21 | + console.error('No enabledApiProposals found in package.json.'); |
| 22 | + process.exit(1); |
| 23 | + } |
42 | 24 |
|
43 | | - // Move downloaded files to src/extension/ |
44 | | - const files = fs.readdirSync('.').filter(f => f.startsWith('vscode.') && f.endsWith('.ts')); |
45 | | - for (const f of files) { |
46 | | - fs.renameSync(f, path.join('src', 'extension', f)); |
| 25 | + let copied = 0; |
| 26 | + for (const proposal of proposals) { |
| 27 | + const fileName = `vscode.proposed.${proposal}.d.ts`; |
| 28 | + const sourcePath = path.join(vscodeDtsDir, fileName); |
| 29 | + if (!fs.existsSync(sourcePath)) { |
| 30 | + console.warn(`Warning: ${fileName} not found in src/vscode-dts/`); |
| 31 | + continue; |
| 32 | + } |
| 33 | + fs.copyFileSync(sourcePath, path.join(targetDir, fileName)); |
| 34 | + copied++; |
47 | 35 | } |
| 36 | + console.log(`Copied ${copied} proposed API type definitions from src/vscode-dts/.`); |
48 | 37 |
|
49 | | - // Write the commit SHA to package.json |
| 38 | + // Write the current commit SHA to package.json for reference |
| 39 | + const sha = execSync('git rev-parse HEAD', { encoding: 'utf-8' }).trim(); |
50 | 40 | const pkgPath = path.resolve('package.json'); |
51 | | - const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8')); |
52 | 41 | pkg.vscodeCommit = sha; |
53 | 42 | fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, '\t') + '\n'); |
54 | 43 | console.log(`Wrote vscodeCommit: ${sha} to package.json`); |
55 | 44 | } |
56 | 45 |
|
57 | | -main().catch(err => { |
58 | | - console.error(err); |
59 | | - process.exit(1); |
60 | | -}); |
| 46 | +main(); |
0 commit comments