Skip to content

Commit d804507

Browse files
committed
feat: use mise dr --json to check if mise can self update
1 parent fb4932c commit d804507

2 files changed

Lines changed: 17 additions & 18 deletions

File tree

src/miseService.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { existsSync } from "node:fs";
2-
import { readlink, rm, symlink } from "node:fs/promises";
2+
import { readlink, realpath, rm, symlink } from "node:fs/promises";
33
import * as os from "node:os";
44
import path from "node:path";
55
import { createCache } from "async-cache-dedupe";
@@ -210,14 +210,11 @@ export class MiseService {
210210
const hasValidMiseVersion = await this.hasValidMiseVersion();
211211
if (!hasValidMiseVersion) {
212212
const canSelfUpdate = await this.canSelfUpdate();
213-
const isSelfUpdateDisabled = await this.isSelfUpdateDisabled();
214213

215214
const selection = await vscode.window.showErrorMessage(
216215
`Mise version ${version} is not supported. Please update to a supported version.`,
217216
{ modal: true },
218-
canSelfUpdate && !isSelfUpdateDisabled
219-
? "Run mise self-update"
220-
: "open mise website",
217+
canSelfUpdate ? "Run mise self-update" : "open mise website",
221218
);
222219
this.hasVerifiedMiseVersion = true;
223220
if (selection === "Run mise self-update") {
@@ -800,26 +797,32 @@ export class MiseService {
800797
return [year, minor, patch] as [number, number, number];
801798
}
802799

803-
// Checks whether the mise binary has the self-update command
800+
// Checks whether the mise binary can self-update.
804801
async canSelfUpdate() {
805802
if (!this.getMiseBinaryPath()) {
806803
return false;
807804
}
808805

809-
try {
810-
await this.execMiseCommand("self-update --help");
811-
return true;
812-
} catch (e) {
813-
return false;
806+
const miseConfig = await this.getMiseConfiguration();
807+
if (miseConfig.self_update_available != null) {
808+
logger.debug(
809+
"self_update_available value from mise dr:",
810+
miseConfig.self_update_available,
811+
);
812+
return !miseConfig.self_update_available;
814813
}
814+
815+
const isSelfUpdateDisabled = await this.isSelfUpdateDisabled();
816+
return !isSelfUpdateDisabled;
815817
}
816818

817819
// Checks for the presence of the `.disable-self-update` sentinel file in the Mise lib
818820
// dir, to determine if self-update is disabled (ie installed using a package manager).
819821
// It's a re-implementation of the `is_available()` function from `SelfUpdate`.
820822
// https://github.com/jdx/mise/blob/863505d4089126780c2352fb1218c6550c3cf9d8/src/cli/self_update.rs#L100
821-
isSelfUpdateDisabled(): boolean {
823+
async isSelfUpdateDisabled(): Promise<boolean> {
822824
logger.info("Checking if self-update is disabled...");
825+
823826
try {
824827
const miseBinPath = this.getMiseBinaryPath();
825828
logger.info(`miseBinPath: ${miseBinPath}`);
@@ -828,7 +831,7 @@ export class MiseService {
828831
}
829832

830833
// Get canonical path of the mise binary
831-
const canonicalPath = require("node:fs").realpathSync(miseBinPath);
834+
const canonicalPath = await realpath(miseBinPath);
832835

833836
// Get parent directory, then parent of that (two levels up)
834837
const parentDir = path.dirname(canonicalPath);
@@ -888,11 +891,6 @@ export class MiseService {
888891
}
889892

890893
const canSelfUpdate = await this.canSelfUpdate();
891-
const isSelfUpdateDisabled = await this.isSelfUpdateDisabled();
892-
893-
if (isSelfUpdateDisabled) {
894-
return;
895-
}
896894

897895
const suggestion = await vscode.window.showInformationMessage(
898896
`New Mise version available ${miseVersion.latest}. (Current: ${miseVersion.current})`,

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ type MiseDirs = {
8787

8888
type MiseConfig = {
8989
dirs: MiseDirs;
90+
self_update_available?: boolean;
9091
};
9192

9293
/*

0 commit comments

Comments
 (0)