@@ -6,44 +6,81 @@ const { execSync } = require('child_process');
66const pkg = require ( '../package.json' ) ;
77const 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
12- // Target directory for smoke tests (Windows/macOS friendly )
13+ // Target directory for smoke tests (repo-relative, matches test expectations )
1314const targetDir = path . resolve (
14- process . env . USERPROFILE || process . env . HOME || '' ,
15- 'vscode-extensions' ,
16- 'vscode-react-native' ,
15+ repoRoot ,
1716 'test' ,
1817 'smoke' ,
1918 'resources' ,
2019 'extension'
2120) ;
2221
22+ function 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+
37+ function 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+
2349function buildVsix ( ) {
24- console . log ( '📦 Packaging VSIX...' ) ;
50+ console . log ( 'Packaging VSIX...' ) ;
2551 execSync ( `npx vsce package -o "${ vsixSource } "` , { stdio : 'inherit' } ) ;
2652 if ( ! fs . existsSync ( vsixSource ) ) {
27- throw new Error ( '❌ VSIX not found. Ensure `vsce package` succeeded and entry file is not ignored.' ) ;
53+ throw new Error ( 'VSIX not found. Ensure `vsce package` succeeded and entry file is not ignored.' ) ;
2854 }
29- console . log ( `✅ VSIX packaged: ${ vsixSource } ` ) ;
55+ console . log ( `VSIX packaged: ${ vsixSource } ` ) ;
3056}
3157
3258function copyVsix ( ) {
33- console . log ( '📂 Copying VSIX to smoke resources...' ) ;
59+ console . log ( 'Copying VSIX to smoke resources...' ) ;
3460 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 ) ;
3563 const targetPath = path . join ( targetDir , path . basename ( vsixSource ) ) ;
3664 fs . copyFileSync ( vsixSource , targetPath ) ;
37- console . log ( `✅ Copied to: ${ 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+ }
3873}
3974
4075function runSmokeTests ( ) {
41- console . log ( '🚀 Running smoke tests...' ) ;
76+ console . log ( 'Running smoke tests...' ) ;
4277 execSync ( 'npm run smoke-tests' , { stdio : 'inherit' } ) ;
43- console . log ( '✅ Smoke tests completed' ) ;
78+ console . log ( 'Smoke tests completed' ) ;
4479}
4580
4681try {
82+ // Clean any stray VSIX files in common locations before building
83+ removeOtherVsixFilesExceptTarget ( repoRoot , targetDir ) ;
4784 buildVsix ( ) ;
4885 copyVsix ( ) ;
4986 if ( process . argv . includes ( '--test' ) ) {
0 commit comments