Skip to content

Commit

Permalink
fix: Do not specify version with mise upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
hverlin committed Nov 28, 2024
1 parent 65ef041 commit 95f0e4f
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 96 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@rsbuild/core": "^1.1.0",
"@rsbuild/core": "^1.1.6",
"@rsbuild/plugin-react": "^1.0.7",
"@types/node": "^22.9.0",
"@types/react": "^18.3.12",
Expand Down
116 changes: 53 additions & 63 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/miseFileWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { MiseService } from "./miseService";
import { logger } from "./utils/logger";
import {
allowedFileTaskDirs,
legacyFiles,
idiomaticFiles,
misePatterns,
} from "./utils/miseUtilts";

Expand Down Expand Up @@ -51,7 +51,7 @@ export class MiseFileWatcher {

this.fileWatchers.push(
vscode.workspace.createFileSystemWatcher(
new vscode.RelativePattern(rootFolder, `{${legacyFiles}}`),
new vscode.RelativePattern(rootFolder, `{${idiomaticFiles}}`),
),
);

Expand Down
26 changes: 22 additions & 4 deletions src/miseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { uniqBy } from "./utils/fn";
import { logger } from "./utils/logger";
import { resolveMisePath } from "./utils/miseBinLocator";
import { type MiseConfig, parseMiseConfig } from "./utils/miseDoctorParser";
import { idiomaticFileToTool, idiomaticFiles } from "./utils/miseUtilts";
import { showSettingsNotification } from "./utils/notify";
import { execAsync, execAsyncMergeOutput } from "./utils/shell";
import { type MiseTaskInfo, parseTaskInfo } from "./utils/taskInfoParser";
Expand Down Expand Up @@ -690,8 +691,25 @@ export class MiseService {
const content = await vscode.workspace.fs.readFile(
vscode.Uri.file(trackedConfigPath),
);
const config = parse(content.toString());
return { path: trackedConfigPath, tools: config.tools ?? {} };
if (trackedConfigPath.endsWith(".toml")) {
const config = parse(content.toString());
return { path: trackedConfigPath, tools: config.tools ?? {} };
}
const idiomaticFile = [...idiomaticFiles].find((ext) =>
trackedConfigPath.endsWith(ext),
);
if (idiomaticFile) {
return {
path: trackedConfigPath,
tools: {
// @ts-ignore
[idiomaticFileToTool[idiomaticFile]]: content
.toString()
.trim(),
},
};
}
return { path: trackedConfigPath, tools: {} };
}
} catch {
return {};
Expand Down Expand Up @@ -736,12 +754,12 @@ export class MiseService {
: this.runMiseToolActionInConsole("prune --dry-run");
}

async upgradeToolInConsole(toolName: string, version: string) {
async upgradeToolInConsole(toolName: string) {
if (!this.getMiseBinaryPath()) {
return;
}

await this.runMiseToolActionInConsole(`up ${toolName}@${version}`);
await this.runMiseToolActionInConsole(`up ${toolName}`);
}

async installToolInConsole(toolName: string, version: string) {
Expand Down
4 changes: 3 additions & 1 deletion src/providers/envProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as vscode from "vscode";
import { isMiseExtensionEnabled } from "../configuration";
import type { MiseService } from "../miseService";
import { logger } from "../utils/logger";
import { findEnvVarPosition } from "../utils/miseFileParser";

export class MiseEnvsProvider implements vscode.TreeDataProvider<EnvItem> {
Expand Down Expand Up @@ -130,7 +131,7 @@ export function registerEnvsCommands(
vscode.commands.registerCommand(
"mise.setEnvVariable",
async (filePath: string | undefined) => {
let selectedPath = filePath;
let selectedPath = filePath?.trim?.();
if (!selectedPath) {
selectedPath = await vscode.window.showQuickPick(
await miseService.getMiseTomlConfigFilePathsEvenIfMissing(),
Expand All @@ -142,6 +143,7 @@ export function registerEnvsCommands(
return;
}

logger.info(`Selected path: ${selectedPath}`);
const environmentVariableName = await vscode.window.showInputBox({
placeHolder: "Environment variable name",
});
Expand Down
4 changes: 2 additions & 2 deletions src/providers/tasksProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { MiseService } from "../miseService";
import { expandPath, setupMiseToml, setupTaskFile } from "../utils/fileUtils";
import { logger } from "../utils/logger";
import { findTaskPosition } from "../utils/miseFileParser";
import { allowedFileTaskDirs, legacyFiles } from "../utils/miseUtilts";
import { allowedFileTaskDirs, idiomaticFiles } from "../utils/miseUtilts";
import { execAsync } from "../utils/shell";
import type { MiseTaskInfo } from "../utils/taskInfoParser";

Expand Down Expand Up @@ -52,7 +52,7 @@ export class MiseTasksProvider implements vscode.TreeDataProvider<TreeNode> {
const configFiles = await this.miseService.getMiseConfigFiles();
const groupedTasks = this.groupTasksBySource(tasks);
for (const configFile of configFiles) {
if (legacyFiles.has(path.basename(configFile.path))) {
if (idiomaticFiles.has(path.basename(configFile.path))) {
continue;
}

Expand Down
37 changes: 20 additions & 17 deletions src/utils/miseUtilts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,23 @@ export const misePatterns = [
".mise.*.local.toml",
].join(",");

export const legacyFiles = new Set([
".crystal-version",
".exenv-version",
".go-version",
"go.mod",
".java-version",
".sdkmanrc",
".nvmrc",
".node-version",
".python-version",
".ruby-version",
"Gemfile",
".terraform-version",
".packer-version",
"main.tf",
".yarnrc",
]);
export const idiomaticFileToTool = {
".crystal-version": "crystal",
".exenv-version": "elixir",
".go-version": "go",
"go.mod": "go",
".java-version": "java",
".sdkmanrc": "java",
".nvmrc": "node",
".node-version": "node",
".python-version": "python",
".python-versions": "python",
".ruby-version": "ruby",
Gemfile: "ruby",
".terraform-version": "terraform",
".packer-version": "packer",
"main.tf": "terraform",
".yarnrc": "yarn",
} as const;

export const idiomaticFiles = new Set(Object.keys(idiomaticFileToTool));
5 changes: 1 addition & 4 deletions src/webviewPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ export default class WebViewPanel {
}
case "upgradeTool": {
return executeAction(message, async () =>
miseService.upgradeToolInConsole(
message.mutationKey[1],
message.mutationKey[2],
),
miseService.upgradeToolInConsole(message.mutationKey[1]),
);
}
case "installTool": {
Expand Down
Loading

0 comments on commit 95f0e4f

Please sign in to comment.