* Special migration function to convert custom_modes.json to YAML format
(settingsDir: string, outputChannel: vscode.OutputChannel)
| 70 | * Special migration function to convert custom_modes.json to YAML format |
| 71 | */ |
| 72 | async function migrateCustomModesToYaml(settingsDir: string, outputChannel: vscode.OutputChannel): Promise<void> { |
| 73 | const oldJsonPath = path.join(settingsDir, deprecatedCustomModesJSONFilename) |
| 74 | const newYamlPath = path.join(settingsDir, GlobalFileNames.customModes) |
| 75 | |
| 76 | // Only proceed if JSON exists and YAML doesn't |
| 77 | const jsonExists = await fileExistsAtPath(oldJsonPath) |
| 78 | const yamlExists = await fileExistsAtPath(newYamlPath) |
| 79 | |
| 80 | if (!jsonExists) { |
| 81 | outputChannel.appendLine("No custom_modes.json found, skipping YAML migration") |
| 82 | return |
| 83 | } |
| 84 | |
| 85 | if (yamlExists) { |
| 86 | outputChannel.appendLine("custom_modes.yaml already exists, skipping migration") |
| 87 | return |
| 88 | } |
| 89 | |
| 90 | try { |
| 91 | // Read JSON content |
| 92 | const jsonContent = await fs.readFile(oldJsonPath, "utf-8") |
| 93 | |
| 94 | try { |
| 95 | // Parse JSON to object (using the yaml library just to be safe/consistent) |
| 96 | const customModesData = yaml.parse(jsonContent) |
| 97 | |
| 98 | // Convert to YAML with no line width limit to prevent line breaks |
| 99 | const yamlContent = yaml.stringify(customModesData, { lineWidth: 0 }) |
| 100 | |
| 101 | // Write YAML file |
| 102 | await fs.writeFile(newYamlPath, yamlContent, "utf-8") |
| 103 | |
| 104 | // Keeping the old JSON file for backward compatibility |
| 105 | // This allows users to roll back if needed |
| 106 | outputChannel.appendLine( |
| 107 | "Successfully migrated custom_modes.json to YAML format (original JSON file preserved for rollback purposes)", |
| 108 | ) |
| 109 | } catch (parseError) { |
| 110 | // Handle corrupt JSON file |
| 111 | outputChannel.appendLine( |
| 112 | `Error parsing custom_modes.json: ${parseError}. File might be corrupted. Skipping migration.`, |
| 113 | ) |
| 114 | } |
| 115 | } catch (fileError) { |
| 116 | outputChannel.appendLine(`Error reading custom_modes.json: ${fileError}. Skipping migration.`) |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Removes commands from old defaults that could execute arbitrary code |
no test coverage detected