Skip to content

Commit bdbc6a6

Browse files
committed
smoke-build: ensure single latest VSIX only in test/smoke/resources/extension; remove duplicates from repo root and other paths
1 parent 966335f commit bdbc6a6

1 file changed

Lines changed: 48 additions & 9 deletions

File tree

gulp_scripts/smoke-build.js

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ const { execSync } = require('child_process');
66
const pkg = require('../package.json');
77
const vsixName = `${pkg.name}-${pkg.version}.vsix`;
88

9-
// VSIX output path (saved at repo root)
10-
const vsixSource = path.resolve(__dirname, '..', vsixName);
9+
// VSIX output path (saved at repo root temporarily; removed after copy)
10+
const repoRoot = path.resolve(__dirname, '..');
11+
const vsixSource = path.resolve(repoRoot, vsixName);
1112

1213
// Target directory for smoke tests (Windows/macOS friendly)
1314
const targetDir = path.resolve(
@@ -20,30 +21,68 @@ const targetDir = path.resolve(
2021
'extension'
2122
);
2223

24+
function removeVsixFilesInDir(dir) {
25+
if (!fs.existsSync(dir)) return;
26+
const entries = fs.readdirSync(dir);
27+
for (const entry of entries) {
28+
if (entry.toLowerCase().endsWith('.vsix')) {
29+
try {
30+
fs.unlinkSync(path.join(dir, entry));
31+
console.log(`Removed VSIX: ${path.join(dir, entry)}`);
32+
} catch (e) {
33+
console.warn(`Failed to remove VSIX ${entry} in ${dir}: ${String(e)}`);
34+
}
35+
}
36+
}
37+
}
38+
39+
function removeOtherVsixFilesExceptTarget(rootDir, targetDirAbs) {
40+
// Remove VSIX files in repo root and known locations except target directory
41+
// 1) repo root
42+
removeVsixFilesInDir(rootDir);
43+
// 2) test/smoke root
44+
removeVsixFilesInDir(path.join(rootDir, 'test'));
45+
removeVsixFilesInDir(path.join(rootDir, 'test', 'smoke'));
46+
removeVsixFilesInDir(path.join(rootDir, 'test', 'smoke', 'resources'));
47+
// 3) explicit extension target handled separately
48+
// Any accidental VSIX in node_modules or dist should be ignored/not expected.
49+
}
50+
2351
function buildVsix() {
24-
console.log('📦 Packaging VSIX...');
52+
console.log('Packaging VSIX...');
2553
execSync(`npx vsce package -o "${vsixSource}"`, { stdio: 'inherit' });
2654
if (!fs.existsSync(vsixSource)) {
27-
throw new Error('VSIX not found. Ensure `vsce package` succeeded and entry file is not ignored.');
55+
throw new Error('VSIX not found. Ensure `vsce package` succeeded and entry file is not ignored.');
2856
}
29-
console.log(`VSIX packaged: ${vsixSource}`);
57+
console.log(`VSIX packaged: ${vsixSource}`);
3058
}
3159

3260
function copyVsix() {
33-
console.log('📂 Copying VSIX to smoke resources...');
61+
console.log('Copying VSIX to smoke resources...');
3462
if (!fs.existsSync(targetDir)) fs.mkdirSync(targetDir, { recursive: true });
63+
// Ensure only one VSIX exists in target by cleaning any existing ones
64+
removeVsixFilesInDir(targetDir);
3565
const targetPath = path.join(targetDir, path.basename(vsixSource));
3666
fs.copyFileSync(vsixSource, targetPath);
37-
console.log(`✅ Copied to: ${targetPath}`);
67+
console.log(`Copied to: ${targetPath}`);
68+
// Remove the source VSIX from repo root to avoid duplicates elsewhere
69+
try {
70+
fs.unlinkSync(vsixSource);
71+
console.log(`Removed source VSIX from repo root: ${vsixSource}`);
72+
} catch (e) {
73+
console.warn(`Failed to remove source VSIX at repo root: ${String(e)}`);
74+
}
3875
}
3976

4077
function runSmokeTests() {
41-
console.log('🚀 Running smoke tests...');
78+
console.log('Running smoke tests...');
4279
execSync('npm run smoke-tests', { stdio: 'inherit' });
43-
console.log('Smoke tests completed');
80+
console.log('Smoke tests completed');
4481
}
4582

4683
try {
84+
// Clean any stray VSIX files in common locations before building
85+
removeOtherVsixFilesExceptTarget(repoRoot, targetDir);
4786
buildVsix();
4887
copyVsix();
4988
if (process.argv.includes('--test')) {

0 commit comments

Comments
 (0)