@@ -4,27 +4,19 @@ const success = watch ? 'Watch build succeeded' : 'Build succeeded';
44const fs = require ( 'fs' ) ;
55const path = require ( 'path' ) ;
66
7- // Replace telemetry token before building
8- function replaceTelemetryToken ( ) {
7+ // Replace telemetry token in generated bundle files after building
8+ function replaceTelemetryTokenInBundle ( ) {
99 const telemetryToken = process . env . TELEMETRY_TRACKING_TOKEN ;
1010 if ( ! telemetryToken ) {
1111 console . error ( 'Error: TELEMETRY_TRACKING_TOKEN environment variable is not set' ) ;
1212 process . exit ( 1 ) ;
1313 }
14-
15- const constantsPath = path . join ( __dirname , '../src/constants.ts' ) ;
16- let constantsContent = fs . readFileSync ( constantsPath , 'utf8' ) ;
17-
18- // Replace the placeholder with the actual token
19- constantsContent = constantsContent . replace ( '<TELEMETRY_TRACKING_TOKEN>' , telemetryToken ) ;
20-
21- fs . writeFileSync ( constantsPath , constantsContent ) ;
22- console . log ( 'Telemetry token replaced successfully' ) ;
14+ const file = 'bundle/extension.js' ;
15+ let content = fs . readFileSync ( file , 'utf-8' ) ;
16+ content = content . replace ( '<TELEMETRY_TRACKING_TOKEN>' , telemetryToken ) ;
17+ fs . writeFileSync ( file , content , 'utf-8' ) ;
2318}
2419
25- // Replace the token before building
26- replaceTelemetryToken ( ) ;
27-
2820require ( 'esbuild' )
2921 . build ( {
3022 entryPoints : [ 'src/extension.ts' , 'src/language-server/main.ts' ] ,
@@ -35,6 +27,10 @@ require('esbuild')
3527 sourcemap : ! minify ,
3628 minify,
3729 } )
30+ . then ( ( ) => {
31+ // Replace the token after building outputs
32+ replaceTelemetryTokenInBundle ( ) ;
33+ } )
3834 . then ( ( ) => {
3935 fs . cpSync ( './src/res' , 'bundle/res' , { force : true , recursive : true } ) ;
4036 fs . cpSync ( './src/vscode/res' , 'bundle/res' , { force : true , recursive : true } ) ;
0 commit comments