Skip to content

Commit 498365c

Browse files
committed
Expose SHA in settings
1 parent 0855948 commit 498365c

File tree

8 files changed

+107
-59
lines changed

8 files changed

+107
-59
lines changed

apps/vscode-nightly/esbuild.mjs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as fs from "fs"
33
import * as path from "path"
44
import { fileURLToPath } from "url"
55

6-
import { copyPaths, copyLocales, copyWasms, generatePackageJson } from "@roo-code/build"
6+
import { getGitSha, copyPaths, copyLocales, copyWasms, generatePackageJson } from "@roo-code/build"
77

88
const __filename = fileURLToPath(import.meta.url)
99
const __dirname = path.dirname(__filename)
@@ -13,6 +13,13 @@ async function main() {
1313
const minify = production
1414
const sourcemap = !production
1515

16+
const overrideJson = JSON.parse(fs.readFileSync(path.join(__dirname, "package.nightly.json"), "utf8"))
17+
console.log(`[main] name: ${overrideJson.name}`)
18+
console.log(`[main] version: ${overrideJson.version}`)
19+
20+
const gitSha = getGitSha()
21+
console.log(`[main] gitSha: ${gitSha}`)
22+
1623
/**
1724
* @type {import('esbuild').BuildOptions}
1825
*/
@@ -26,7 +33,9 @@ async function main() {
2633
platform: "node",
2734
define: {
2835
"process.env.PKG_NAME": '"roo-code-nightly"',
36+
"process.env.PKG_VERSION": `"${overrideJson.version}"`,
2937
"process.env.PKG_OUTPUT_CHANNEL": '"Roo-Code-Nightly"',
38+
...(gitSha ? { "process.env.PKG_SHA": `"${gitSha}"` } : {}),
3039
},
3140
}
3241

@@ -72,10 +81,6 @@ async function main() {
7281
build.onEnd(() => {
7382
const packageJson = JSON.parse(fs.readFileSync(path.join(srcDir, "package.json"), "utf8"))
7483

75-
const overrideJson = JSON.parse(
76-
fs.readFileSync(path.join(__dirname, "package.nightly.json"), "utf8"),
77-
)
78-
7984
const generatedPackageJson = generatePackageJson({
8085
packageJson,
8186
overrideJson,

packages/build/src/index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
import * as fs from "fs"
22
import * as path from "path"
3+
import { execSync } from "child_process"
34

4-
import { ViewsContainer, Views, MenuItem, Menus, Configuration, contributesSchema } from "./types.js"
5+
import { ViewsContainer, Views, Menus, Configuration, contributesSchema } from "./types.js"
6+
7+
export function getGitSha() {
8+
let gitSha = undefined
9+
10+
try {
11+
gitSha = execSync("git rev-parse HEAD").toString().trim()
12+
} catch (e) {}
13+
14+
return gitSha
15+
}
516

617
export function copyPaths(copyPaths: [string, string][], srcDir: string, dstDir: string) {
718
copyPaths.forEach(([srcRelPath, dstRelPath]) => {
819
const stats = fs.lstatSync(path.join(srcDir, srcRelPath))
920

10-
console.log(`[copyPaths] ${srcRelPath} -> ${dstRelPath}`)
11-
1221
if (stats.isDirectory()) {
1322
if (fs.existsSync(path.join(dstDir, dstRelPath))) {
1423
fs.rmSync(path.join(dstDir, dstRelPath), { recursive: true })

src/exports/roo-code.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,6 +1545,7 @@ declare const Package: {
15451545
readonly name: string
15461546
readonly version: string
15471547
readonly outputChannel: string
1548+
readonly sha: string | undefined
15481549
}
15491550
/**
15501551
* ProviderName

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export async function activate(context: vscode.ExtensionContext) {
5151
extensionContext = context
5252
outputChannel = vscode.window.createOutputChannel(Package.outputChannel)
5353
context.subscriptions.push(outputChannel)
54-
outputChannel.appendLine(`${Package.name} extension activated`)
54+
outputChannel.appendLine(`${Package.name} extension activated - ${JSON.stringify(Package)}`)
5555

5656
// Migrate old settings to new
5757
await migrateSettings(context, outputChannel)

src/schemas/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ import { publisher, name, version } from "../package.json"
1919
// by VSCode, but that build artifact is not used during the transpile step of
2020
// the build, so we still need this override mechanism.
2121
export const Package = {
22-
publisher: process.env.PKG_PUBLISHER || publisher,
22+
publisher,
2323
name: process.env.PKG_NAME || name,
2424
version: process.env.PKG_VERSION || version,
2525
outputChannel: process.env.PKG_OUTPUT_CHANNEL || "Roo-Code",
26+
sha: process.env.PKG_SHA,
2627
} as const
2728

2829
/**

webview-ui/src/components/settings/About.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Info, Download, Upload, TriangleAlert } from "lucide-react"
55

66
import { VSCodeCheckbox, VSCodeLink } from "@vscode/webview-ui-toolkit/react"
77

8+
import { Package } from "@roo/schemas"
89
import { TelemetrySetting } from "@roo/shared/TelemetrySetting"
910

1011
import { vscode } from "@/utils/vscode"
@@ -15,17 +16,21 @@ import { SectionHeader } from "./SectionHeader"
1516
import { Section } from "./Section"
1617

1718
type AboutProps = HTMLAttributes<HTMLDivElement> & {
18-
version: string
1919
telemetrySetting: TelemetrySetting
2020
setTelemetrySetting: (setting: TelemetrySetting) => void
2121
}
2222

23-
export const About = ({ version, telemetrySetting, setTelemetrySetting, className, ...props }: AboutProps) => {
23+
export const About = ({ telemetrySetting, setTelemetrySetting, className, ...props }: AboutProps) => {
2424
const { t } = useAppTranslation()
2525

2626
return (
2727
<div className={cn("flex flex-col gap-2", className)} {...props}>
28-
<SectionHeader description={`Version: ${version}`}>
28+
<SectionHeader
29+
description={
30+
Package.sha
31+
? `Version: ${Package.version} (${Package.sha.slice(0, 8)})`
32+
: `Version: ${Package.version}`
33+
}>
2934
<div className="flex items-center gap-2">
3035
<Info className="w-4" />
3136
<div>{t("settings:sections.about")}</div>

webview-ui/src/components/settings/SettingsView.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
9999
const { t } = useAppTranslation()
100100

101101
const extensionState = useExtensionState()
102-
const { currentApiConfigName, listApiConfigMeta, uriScheme, version, settingsImportedAt } = extensionState
102+
const { currentApiConfigName, listApiConfigMeta, uriScheme, settingsImportedAt } = extensionState
103103

104104
const [isDiscardDialogShow, setDiscardDialogShow] = useState(false)
105105
const [isChangeDetected, setChangeDetected] = useState(false)
@@ -638,11 +638,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
638638

639639
{/* About Section */}
640640
{activeTab === "about" && (
641-
<About
642-
version={version}
643-
telemetrySetting={telemetrySetting}
644-
setTelemetrySetting={setTelemetrySetting}
645-
/>
641+
<About telemetrySetting={telemetrySetting} setTelemetrySetting={setTelemetrySetting} />
646642
)}
647643
</TabContent>
648644
</div>

webview-ui/vite.config.ts

Lines changed: 71 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { resolve } from "path"
22
import fs from "fs"
3+
import { execSync } from "child_process"
34

45
import { defineConfig, type Plugin } from "vite"
56
import 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
2525
const 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

Comments
 (0)