11import { resolve } from "path"
22import fs from "fs"
3+ import { execSync } from "child_process"
34
45import { defineConfig , type Plugin } from "vite"
56import react from "@vitejs/plugin-react"
@@ -21,18 +22,15 @@ function wasmPlugin(): Plugin {
2122 }
2223}
2324
24- // Custom plugin to write the server port to a file
2525const writePortToFile = ( ) => {
2626 return {
2727 name : "write-port-to-file" ,
2828 configureServer ( server ) {
29- // Write the port to a file when the server starts
3029 server . httpServer ?. once ( "listening" , ( ) => {
3130 const address = server . httpServer . address ( )
3231 const port = typeof address === "object" && address ? address . port : null
3332
3433 if ( port ) {
35- // Write to a file in the project root
3634 const portFilePath = resolve ( __dirname , "../.vite-port" )
3735 fs . writeFileSync ( portFilePath , port . toString ( ) )
3836 console . log ( `[Vite Plugin] Server started on port ${ port } ` )
@@ -45,46 +43,79 @@ const writePortToFile = () => {
4543 }
4644}
4745
46+ function getGitSha ( ) {
47+ let gitSha : string | undefined = undefined
48+
49+ try {
50+ gitSha = execSync ( "git rev-parse HEAD" ) . toString ( ) . trim ( )
51+ } catch ( e ) { }
52+
53+ return gitSha
54+ }
55+
4856// https://vitejs.dev/config/
49- export default defineConfig ( ( { mode } ) => ( {
50- plugins : [ react ( ) , tailwindcss ( ) , writePortToFile ( ) , wasmPlugin ( ) ] ,
51- resolve : {
52- alias : {
53- "@" : resolve ( __dirname , "./src" ) ,
54- "@src" : resolve ( __dirname , "./src" ) ,
55- "@roo" : resolve ( __dirname , "../src" ) ,
57+ export default defineConfig ( ( { mode } ) => {
58+ let outDir = "../src/webview-ui/build"
59+
60+ const define : Record < string , any > = {
61+ "process.platform" : JSON . stringify ( process . platform ) ,
62+ }
63+
64+ // TODO: We can use `@roo-code/build` to generate `define` once the
65+ // monorepo is deployed.
66+ if ( mode === "nightly" ) {
67+ outDir = "../apps/vscode-nightly/build/webview-ui/build"
68+
69+ const { name, version } = JSON . parse ( fs . readFileSync ( "../apps/vscode-nightly/package.nightly.json" , "utf8" ) )
70+
71+ define [ "process.env.PKG_NAME" ] = JSON . stringify ( name )
72+ define [ "process.env.PKG_VERSION" ] = JSON . stringify ( version )
73+ define [ "process.env.PKG_OUTPUT_CHANNEL" ] = JSON . stringify ( "Roo-Code-Nightly" )
74+
75+ const gitSha = getGitSha ( )
76+
77+ if ( gitSha ) {
78+ define [ "process.env.PKG_SHA" ] = JSON . stringify ( gitSha )
79+ }
80+ }
81+
82+ return {
83+ plugins : [ react ( ) , tailwindcss ( ) , writePortToFile ( ) , wasmPlugin ( ) ] ,
84+ resolve : {
85+ alias : {
86+ "@" : resolve ( __dirname , "./src" ) ,
87+ "@src" : resolve ( __dirname , "./src" ) ,
88+ "@roo" : resolve ( __dirname , "../src" ) ,
89+ } ,
5690 } ,
57- } ,
58- build : {
59- outDir : mode === "nightly" ? "../apps/vscode-nightly/build/webview-ui/build" : "../src/webview-ui/build" ,
60- emptyOutDir : true ,
61- reportCompressedSize : false ,
62- sourcemap : true ,
63- rollupOptions : {
64- output : {
65- entryFileNames : `assets/[name].js` ,
66- chunkFileNames : `assets/[name].js ` ,
67- assetFileNames : `assets/[name].[ext]` ,
91+ build : {
92+ outDir ,
93+ emptyOutDir : true ,
94+ reportCompressedSize : false ,
95+ sourcemap : true ,
96+ rollupOptions : {
97+ output : {
98+ entryFileNames : `assets/[name].js` ,
99+ chunkFileNames : `assets/[name].js` ,
100+ assetFileNames : `assets/[name].[ext] ` ,
101+ } ,
68102 } ,
69103 } ,
70- } ,
71- server : {
72- hmr : {
73- host : "localhost" ,
74- protocol : "ws" ,
104+ server : {
105+ hmr : {
106+ host : "localhost" ,
107+ protocol : "ws" ,
108+ } ,
109+ cors : {
110+ origin : "*" ,
111+ methods : "*" ,
112+ allowedHeaders : "*" ,
113+ } ,
75114 } ,
76- cors : {
77- origin : "*" ,
78- methods : "*" ,
79- allowedHeaders : "*" ,
115+ define,
116+ optimizeDeps : {
117+ exclude : [ "@vscode/codicons" , "vscode-oniguruma" , "shiki" ] ,
80118 } ,
81- } ,
82- define : {
83- "process.platform" : JSON . stringify ( process . platform ) ,
84- "process.env.VSCODE_TEXTMATE_DEBUG" : JSON . stringify ( process . env . VSCODE_TEXTMATE_DEBUG ) ,
85- } ,
86- optimizeDeps : {
87- exclude : [ "@vscode/codicons" , "vscode-oniguruma" , "shiki" ] ,
88- } ,
89- assetsInclude : [ "**/*.wasm" , "**/*.wav" ] ,
90- } ) )
119+ assetsInclude : [ "**/*.wasm" , "**/*.wav" ] ,
120+ }
121+ } )
0 commit comments