microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
improve-package-name-resolver-test

Branches

Tags

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

Clone

HTTPS

Download ZIP

gulp_scripts/smoke-build.js

92lines · modeblame

617154f8Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)8 months ago1const 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
bdbc6a68Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)6 months ago9// VSIX output path (saved at repo root temporarily; removed after copy)
10const repoRoot = path.resolve(__dirname, '..');
11const vsixSource = path.resolve(repoRoot, vsixName);
617154f8Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)8 months ago12
1f8dc9e5Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)6 months ago13// Target directory for smoke tests (repo-relative, matches test expectations)
617154f8Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)8 months ago14const targetDir = path.resolve(
1f8dc9e5Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)6 months ago15repoRoot,
617154f8Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)8 months ago16'test',
17'smoke',
18'resources',
19'extension'
20);
21
bdbc6a68Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)6 months ago22function removeVsixFilesInDir(dir) {
23if (!fs.existsSync(dir)) return;
24const entries = fs.readdirSync(dir);
25for (const entry of entries) {
26if (entry.toLowerCase().endsWith('.vsix')) {
27try {
28fs.unlinkSync(path.join(dir, entry));
29console.log(`Removed VSIX: ${path.join(dir, entry)}`);
30} catch (e) {
31console.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
40removeVsixFilesInDir(rootDir);
41// 2) test/smoke root
42removeVsixFilesInDir(path.join(rootDir, 'test'));
43removeVsixFilesInDir(path.join(rootDir, 'test', 'smoke'));
44removeVsixFilesInDir(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
617154f8Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)8 months ago49function buildVsix() {
bdbc6a68Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)6 months ago50console.log('Packaging VSIX...');
617154f8Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)8 months ago51execSync(`npx vsce package -o "${vsixSource}"`, { stdio: 'inherit' });
52if (!fs.existsSync(vsixSource)) {
bdbc6a68Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)6 months ago53throw new Error('VSIX not found. Ensure `vsce package` succeeded and entry file is not ignored.');
617154f8Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)8 months ago54}
bdbc6a68Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)6 months ago55console.log(`VSIX packaged: ${vsixSource}`);
617154f8Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)8 months ago56}
57
58function copyVsix() {
bdbc6a68Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)6 months ago59console.log('Copying VSIX to smoke resources...');
617154f8Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)8 months ago60if (!fs.existsSync(targetDir)) fs.mkdirSync(targetDir, { recursive: true });
bdbc6a68Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)6 months ago61// Ensure only one VSIX exists in target by cleaning any existing ones
62removeVsixFilesInDir(targetDir);
617154f8Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)8 months ago63const targetPath = path.join(targetDir, path.basename(vsixSource));
64fs.copyFileSync(vsixSource, targetPath);
bdbc6a68Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)6 months ago65console.log(`Copied to: ${targetPath}`);
66// Remove the source VSIX from repo root to avoid duplicates elsewhere
67try {
68fs.unlinkSync(vsixSource);
69console.log(`Removed source VSIX from repo root: ${vsixSource}`);
70} catch (e) {
71console.warn(`Failed to remove source VSIX at repo root: ${String(e)}`);
72}
617154f8Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)8 months ago73}
74
75function runSmokeTests() {
bdbc6a68Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)6 months ago76console.log('Running smoke tests...');
617154f8Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)8 months ago77execSync('npm run smoke-tests', { stdio: 'inherit' });
bdbc6a68Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)6 months ago78console.log('Smoke tests completed');
617154f8Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)8 months ago79}
80
81try {
bdbc6a68Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)6 months ago82// Clean any stray VSIX files in common locations before building
83removeOtherVsixFilesExceptTarget(repoRoot, targetDir);
617154f8Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)8 months ago84buildVsix();
85copyVsix();
86if (process.argv.includes('--test')) {
87runSmokeTests();
88}
89} catch (err) {
90console.error(err.message || err);
91process.exit(1);
92}