microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1fe78525cb3778a3fadfcad91e71c2720d5cb626

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

gulp_scripts/smoke-build.js

92lines · modecode

1const fs = require('fs');
2const path = require('path');
3const { execSync } = require('child_process');
4
5// Read package.json to compute VSIX file name as <name>-<version>.vsix
6const pkg = require('../package.json');
7const vsixName = `${pkg.name}-${pkg.version}.vsix`;
8
9// VSIX output path (saved at repo root temporarily; removed after copy)
10const repoRoot = path.resolve(__dirname, '..');
11const vsixSource = path.resolve(repoRoot, vsixName);
12
13// Target directory for smoke tests (repo-relative, matches test expectations)
14const targetDir = path.resolve(
15 repoRoot,
16 'test',
17 'smoke',
18 'resources',
19 'extension'
20);
21
22function removeVsixFilesInDir(dir) {
23 if (!fs.existsSync(dir)) return;
24 const entries = fs.readdirSync(dir);
25 for (const entry of entries) {
26 if (entry.toLowerCase().endsWith('.vsix')) {
27 try {
28 fs.unlinkSync(path.join(dir, entry));
29 console.log(`Removed VSIX: ${path.join(dir, entry)}`);
30 } catch (e) {
31 console.warn(`Failed to remove VSIX ${entry} in ${dir}: ${String(e)}`);
32 }
33 }
34 }
35}
36
37function removeOtherVsixFilesExceptTarget(rootDir, targetDirAbs) {
38 // Remove VSIX files in repo root and known locations except target directory
39 // 1) repo root
40 removeVsixFilesInDir(rootDir);
41 // 2) test/smoke root
42 removeVsixFilesInDir(path.join(rootDir, 'test'));
43 removeVsixFilesInDir(path.join(rootDir, 'test', 'smoke'));
44 removeVsixFilesInDir(path.join(rootDir, 'test', 'smoke', 'resources'));
45 // 3) explicit extension target handled separately
46 // Any accidental VSIX in node_modules or dist should be ignored/not expected.
47}
48
49function buildVsix() {
50 console.log('Packaging VSIX...');
51 execSync(`npx vsce package -o "${vsixSource}"`, { stdio: 'inherit' });
52 if (!fs.existsSync(vsixSource)) {
53 throw new Error('VSIX not found. Ensure `vsce package` succeeded and entry file is not ignored.');
54 }
55 console.log(`VSIX packaged: ${vsixSource}`);
56}
57
58function copyVsix() {
59 console.log('Copying VSIX to smoke resources...');
60 if (!fs.existsSync(targetDir)) fs.mkdirSync(targetDir, { recursive: true });
61 // Ensure only one VSIX exists in target by cleaning any existing ones
62 removeVsixFilesInDir(targetDir);
63 const targetPath = path.join(targetDir, path.basename(vsixSource));
64 fs.copyFileSync(vsixSource, targetPath);
65 console.log(`Copied to: ${targetPath}`);
66 // Remove the source VSIX from repo root to avoid duplicates elsewhere
67 try {
68 fs.unlinkSync(vsixSource);
69 console.log(`Removed source VSIX from repo root: ${vsixSource}`);
70 } catch (e) {
71 console.warn(`Failed to remove source VSIX at repo root: ${String(e)}`);
72 }
73}
74
75function runSmokeTests() {
76 console.log('Running smoke tests...');
77 execSync('npm run smoke-tests', { stdio: 'inherit' });
78 console.log('Smoke tests completed');
79}
80
81try {
82 // Clean any stray VSIX files in common locations before building
83 removeOtherVsixFilesExceptTarget(repoRoot, targetDir);
84 buildVsix();
85 copyVsix();
86 if (process.argv.includes('--test')) {
87 runSmokeTests();
88 }
89} catch (err) {
90 console.error(err.message || err);
91 process.exit(1);
92}