Skip to content

Commit 285ae56

Browse files
committed
feat: enhance update handling and success message
1 parent fc20a7e commit 285ae56

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

src/cli.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ void main();
7878

7979
async function main(): Promise<void> {
8080
const updatePromptResult = await promptForPendingUpdate(packageInfo);
81+
if (updatePromptResult.installed) {
82+
process.exit(0);
83+
}
8184

8285
const restartRef: { current: (() => void) | null } = { current: null };
8386

@@ -110,9 +113,7 @@ async function main(): Promise<void> {
110113
});
111114
}
112115

113-
if (!updatePromptResult.installed) {
114-
void checkForNpmUpdate(packageInfo);
115-
}
116+
void checkForNpmUpdate(packageInfo);
116117

117118
startApp();
118119
}

src/common/update-check.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as fs from "fs";
44
import * as os from "os";
55
import * as path from "path";
66
import { render, type Instance } from "ink";
7-
import chalk from "chalk";
87
import { UpdatePrompt, type UpdatePromptChoice } from "../ui";
98
import { killProcessTree } from "./process-tree";
109

@@ -27,6 +26,7 @@ const UPDATE_STATE_FILE = "update-check.json";
2726
const NPM_VIEW_TIMEOUT_MS = 5000;
2827
const MAX_NPM_VIEW_OUTPUT_CHARS = 64 * 1024;
2928
const TENCENT_MIRROR_REGISTRY = "https://mirrors.cloud.tencent.com/npm/";
29+
export const UPDATE_SUCCESS_MESSAGE = "🎉 Update ran successfully! Please restart Deep Code.";
3030

3131
export async function promptForPendingUpdate(packageInfo: PackageInfo): Promise<{ installed: boolean }> {
3232
const state = readUpdateState();
@@ -57,9 +57,7 @@ export async function promptForPendingUpdate(packageInfo: PackageInfo): Promise<
5757
const ok = await runNpmInstallGlobal(installSpec);
5858
if (ok) {
5959
writeUpdateState({ ...state, pending: null });
60-
process.stdout.write(
61-
`\n${chalk.red("Deep Code has been updated. Please restart the CLI to use the new version.")}\n\n`
62-
);
60+
process.stdout.write(`${UPDATE_SUCCESS_MESSAGE}\n\n`);
6361
}
6462
return { installed: ok };
6563
}

src/tests/update-check.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { test } from "node:test";
22
import assert from "node:assert/strict";
3-
import { compareVersions, parseNpmViewVersion } from "../common/update-check";
3+
import { UPDATE_SUCCESS_MESSAGE, compareVersions, parseNpmViewVersion } from "../common/update-check";
44

55
test("compareVersions orders semantic versions", () => {
66
assert.equal(compareVersions("0.1.4", "0.1.3"), 1);
@@ -14,3 +14,7 @@ test("parseNpmViewVersion parses npm view JSON and plain output", () => {
1414
assert.equal(parseNpmViewVersion("0.1.5\n"), "0.1.5");
1515
assert.equal(parseNpmViewVersion("\n"), null);
1616
});
17+
18+
test("UPDATE_SUCCESS_MESSAGE tells the user to restart Deep Code", () => {
19+
assert.equal(UPDATE_SUCCESS_MESSAGE, "🎉 Update ran successfully! Please restart Deep Code.");
20+
});

0 commit comments

Comments
 (0)