From 2c785779b58230ee05c9accdeb70aa14325d956c Mon Sep 17 00:00:00 2001 From: Jonathan Yu Date: Tue, 1 Mar 2022 12:20:43 -0800 Subject: [PATCH] feat: add version of Code OSS to output (#4925) Show the bundled version of Code OSS in the text-based output for --version and --help, in addition to the JSON output (--version --json) Closes: #4874 --- src/node/constants.ts | 2 +- src/node/entry.ts | 14 ++++---------- test/unit/node/constants.test.ts | 6 ++++-- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/node/constants.ts b/src/node/constants.ts index b3c84048c..e27e9a4d8 100644 --- a/src/node/constants.ts +++ b/src/node/constants.ts @@ -35,7 +35,7 @@ export const httpProxyUri = * for outputting to the console. */ export function getVersionString(): string { - return [version, commit].join(" ") + return [version, commit, "with Code", codeVersion].join(" ") } /** diff --git a/src/node/entry.ts b/src/node/entry.ts index 92fd8a8e7..010f18b76 100644 --- a/src/node/entry.ts +++ b/src/node/entry.ts @@ -1,6 +1,6 @@ import { logger } from "@coder/logger" import { optionDescriptions, parse, readConfigFile, setDefaults, shouldOpenInExistingInstance } from "./cli" -import { commit, version } from "./constants" +import { getVersionString, getVersionJsonString } from "./constants" import { openInExistingInstance, runCodeServer, runVsCodeCli, shouldSpawnCliProcess } from "./main" import { isChild, wrapper } from "./wrapper" @@ -24,7 +24,7 @@ async function entry(): Promise { const args = await setDefaults(cliArgs, configArgs) if (args.help) { - console.log("code-server", version, commit) + console.log("code-server", getVersionString()) console.log("") console.log(`Usage: code-server [options] [path]`) console.log(` - Opening a directory: code-server ./path/to/your/project`) @@ -39,15 +39,9 @@ async function entry(): Promise { if (args.version) { if (args.json) { - console.log( - JSON.stringify({ - codeServer: version, - commit, - vscode: require("../../vendor/modules/code-oss-dev/package.json").version, - }), - ) + console.log(getVersionJsonString()) } else { - console.log(version, commit) + console.log(getVersionString()) } return } diff --git a/test/unit/node/constants.test.ts b/test/unit/node/constants.test.ts index 70192d70c..24501cbd2 100644 --- a/test/unit/node/constants.test.ts +++ b/test/unit/node/constants.test.ts @@ -60,7 +60,9 @@ describe("constants", () => { }) it("should return a human-readable version string", () => { - expect(constants.getVersionString()).toStrictEqual(`${mockPackageJson.version} ${mockPackageJson.commit}`) + expect(constants.getVersionString()).toStrictEqual( + `${mockPackageJson.version} ${mockPackageJson.commit} with Code ${mockCodePackageJson.version}`, + ) }) it("should return a machine-readable version string", () => { @@ -124,7 +126,7 @@ describe("constants", () => { it("should return a human-readable version string", () => { // this string is not super useful - expect(constants.getVersionString()).toStrictEqual("development development") + expect(constants.getVersionString()).toStrictEqual("development development with Code development") }) it("should return a machine-readable version string", () => {