Skip to content

Commit fb4932c

Browse files
committed
feat: get mise config use --json option" (#118)
1 parent b51b5d3 commit fb4932c

6 files changed

Lines changed: 63 additions & 261 deletions

File tree

src/miseService.ts

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { expandPath, isWindows, mkdirp } from "./utils/fileUtils";
1919
import { uniqBy } from "./utils/fn";
2020
import { logger } from "./utils/logger";
2121
import { resolveMisePath } from "./utils/miseBinLocator";
22-
import { type MiseConfig, parseMiseConfig } from "./utils/miseDoctorParser";
22+
import { expandConfig } from "./utils/miseDoctorParser";
2323
import {
2424
flattenJsonSchema,
2525
idiomaticFileToTool,
@@ -678,17 +678,39 @@ export class MiseService {
678678
).flat();
679679
}
680680

681+
async miseVersion() {
682+
const { stdout } = await this.cache.execCmd({
683+
command: "version --json",
684+
});
685+
686+
const version = JSON.parse(stdout) as MiseVersion;
687+
// "version": "2025.3.2 windows-x64 (2025-03-07)",
688+
const current = version.version.split(" ")[0] ?? "";
689+
return {
690+
raw: version,
691+
latest: version.latest,
692+
current: current,
693+
newVersionAvailable: version.latest !== current,
694+
};
695+
}
696+
681697
async getMiseConfiguration(): Promise<MiseConfig> {
682-
const miseCmd = this.createMiseCommand("doctor", {
698+
const miseCmd = this.createMiseCommand("doctor --json", {
683699
setMiseEnv: false,
684700
});
685701

686-
const { stdout, stderr } = await execAsyncMergeOutput(miseCmd ?? "");
702+
const { stdout, stderr } = await execAsyncMergeOutput(miseCmd ?? "{}");
687703
if (stderr) {
688704
logger.debug(miseCmd, stderr);
689705
}
690706

691-
return parseMiseConfig(stdout);
707+
try {
708+
const miseConfig = JSON.parse(stdout) as MiseConfig;
709+
return expandConfig(miseConfig);
710+
} catch (error) {
711+
logger.error(`Error parsing mise configuration: ${stdout}`, error);
712+
return {} as MiseConfig;
713+
}
692714
}
693715

694716
async miseDoctor() {
@@ -855,15 +877,13 @@ export class MiseService {
855877
return;
856878
}
857879

858-
const miseConfig = await this.getMiseConfiguration();
859-
const newMiseVersionAvailable =
860-
miseConfig.problems?.newMiseVersionAvailable;
861-
if (newMiseVersionAvailable) {
880+
const miseVersion = await this.miseVersion();
881+
if (miseVersion.newVersionAvailable) {
862882
const ignoreVersion = this.context.globalState.get<string>(
863883
"mise.ignoreNewVersion",
864884
);
865885

866-
if (ignoreVersion === newMiseVersionAvailable.latestVersion) {
886+
if (ignoreVersion === miseVersion.latest) {
867887
return;
868888
}
869889

@@ -875,7 +895,7 @@ export class MiseService {
875895
}
876896

877897
const suggestion = await vscode.window.showInformationMessage(
878-
`New Mise version available ${newMiseVersionAvailable?.latestVersion}. (Current: ${newMiseVersionAvailable?.currentVersion})`,
898+
`New Mise version available ${miseVersion.latest}. (Current: ${miseVersion.current})`,
879899
canSelfUpdate ? "Update Mise" : "How to update Mise",
880900
"Show changelog",
881901
"Ignore this update",
@@ -903,7 +923,7 @@ export class MiseService {
903923
if (suggestion === "Ignore this update") {
904924
this.context.globalState.update(
905925
"mise.ignoreNewVersion",
906-
newMiseVersionAvailable.latestVersion,
926+
miseVersion.latest,
907927
);
908928
}
909929
}

src/types.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,33 @@ type MiseToolInfo = {
7575
url?: string;
7676
};
7777
};
78+
79+
type MiseDirs = {
80+
data?: string;
81+
config?: string;
82+
cache?: string;
83+
state?: string;
84+
shims: string;
85+
[key: string]: string | undefined;
86+
};
87+
88+
type MiseConfig = {
89+
dirs: MiseDirs;
90+
};
91+
92+
/*
93+
{
94+
"version": "2025.3.2 windows-x64 (2025-03-07)",
95+
"latest": "2025.3.2",
96+
"os": "windows",
97+
"arch": "x64",
98+
"build_time": "2025-03-07 16:41:51 +00:00"
99+
}
100+
*/
101+
type MiseVersion = {
102+
version: string;
103+
latest: string;
104+
os: string;
105+
arch: string;
106+
build_time: string;
107+
};

src/utils/configureExtensionUtil.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type { VSCodeSettingValue } from "../configuration";
77
import type { MiseService } from "../miseService";
88
import { isWindows } from "./fileUtils";
99
import { logger } from "./logger";
10-
import type { MiseConfig } from "./miseDoctorParser";
1110
import type { ConfigurableExtension } from "./supportedExtensions";
1211

1312
export async function configureSimpleExtension(

src/utils/miseDoctorParser.test.ts

Lines changed: 0 additions & 162 deletions
This file was deleted.

src/utils/miseDoctorParser.ts

Lines changed: 2 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,6 @@
11
import { expandPath } from "./fileUtils";
22

3-
type MiseDirs = {
4-
data?: string;
5-
config?: string;
6-
cache?: string;
7-
state?: string;
8-
shims: string;
9-
[key: string]: string | undefined;
10-
};
11-
12-
type MiseConfig = {
13-
dirs: MiseDirs;
14-
problems?: {
15-
newMiseVersionAvailable?: {
16-
currentVersion: string;
17-
latestVersion: string;
18-
};
19-
};
20-
};
21-
22-
function parseMiseConfigRaw(content: string): MiseConfig {
23-
const result: MiseConfig = { dirs: { shims: "" }, problems: {} };
24-
const lines: string[] = content.split("\n");
25-
26-
let currentSection: string | null = null;
27-
let sectionIndentLevel = 0;
28-
29-
// example: new mise version 2024.11.19 available, currently on 2024.11.18
30-
const match = content.match(
31-
/new mise version (\d+\.\d+\.\d+) available, currently on (\d+\.\d+\.\d+)/,
32-
);
33-
if (match) {
34-
const [, latestVersion, currentVersion] = match;
35-
if (currentVersion !== undefined && latestVersion !== undefined) {
36-
result.problems ||= {};
37-
result.problems.newMiseVersionAvailable = {
38-
currentVersion,
39-
latestVersion,
40-
};
41-
}
42-
}
43-
44-
for (let i = 0; i < lines.length; i++) {
45-
const line = lines[i];
46-
if (!line) {
47-
continue;
48-
}
49-
50-
const trimmedLine = line.trim();
51-
52-
if (trimmedLine === "dirs:") {
53-
currentSection = "dirs";
54-
sectionIndentLevel = line.length - line.trimStart().length;
55-
continue;
56-
}
57-
58-
if (currentSection === "dirs" && trimmedLine.length > 0) {
59-
const lineIndentLevel = line.length - line.trimStart().length;
60-
61-
if (lineIndentLevel <= sectionIndentLevel) {
62-
if (trimmedLine !== "dirs:") {
63-
currentSection = null;
64-
continue;
65-
}
66-
}
67-
68-
const match = trimmedLine.match(/^(\w+):\s+(.+)$/);
69-
if (match) {
70-
const [, key, value] = match;
71-
if (key === undefined) {
72-
continue;
73-
}
74-
result.dirs[key] = value;
75-
}
76-
}
77-
78-
if (currentSection === "dirs" && trimmedLine === "") {
79-
currentSection = null;
80-
}
81-
}
82-
return result;
83-
}
84-
85-
function parseMiseConfig(content: string): MiseConfig {
86-
const cfg = parseMiseConfigRaw(content);
3+
function expandConfig(cfg: MiseConfig): MiseConfig {
874
for (const [key, value] of Object.entries(cfg.dirs)) {
885
if (!value) {
896
continue;
@@ -93,5 +10,4 @@ function parseMiseConfig(content: string): MiseConfig {
9310
return cfg;
9411
}
9512

96-
export { parseMiseConfig, parseMiseConfigRaw };
97-
export type { MiseConfig, MiseDirs };
13+
export { expandConfig };

src/utils/supportedExtensions.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
getConfiguredBinPath,
77
} from "./configureExtensionUtil";
88
import { mergeArrays } from "./fn";
9-
import type { MiseConfig } from "./miseDoctorParser";
109

1110
type GenerateConfigProps = {
1211
tool: MiseTool;

0 commit comments

Comments
 (0)