Skip to content

Commit 6a7e917

Browse files
RyanLee-Devclaude
andcommitted
refactor: JSON-only config, remove yaml dependency
- config/paths.ts: config.yaml → config.json - config/loader.ts: JSON.parse/stringify, no yaml import - output/formatter.ts: drop yaml case, OutputFormat = 'text' | 'json' - config/schema.ts: remove 'yaml' from output types - config/set.ts, command.ts, registry.ts: update output format docs - auth/resolver.ts, auth/login.ts, auth/logout.ts: config.yaml → config.json - package.json, bun.lock: remove yaml dependency - tests: remove yaml test case, update config.yaml refs Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 87fbbda commit 6a7e917

14 files changed

Lines changed: 19 additions & 33 deletions

File tree

bun.lock

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
"prepublishOnly": "bun run build:npm"
2323
},
2424
"dependencies": {
25-
"@clack/prompts": "^0.7.0",
26-
"yaml": "^2.7.1"
25+
"@clack/prompts": "^0.7.0"
2726
},
2827
"devDependencies": {
2928
"typescript": "^5.8.3",

src/auth/resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function resolveCredential(config: Config): Promise<ResolvedCredent
2020

2121
// 3. API key from config file
2222
if (config.fileApiKey) {
23-
return { token: config.fileApiKey, method: 'api-key', source: 'config.yaml' };
23+
return { token: config.fileApiKey, method: 'api-key', source: 'config.json' };
2424
}
2525

2626
// 4. Environment variable

src/command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const GLOBAL_OPTIONS: OptionDef[] = [
4242
{ flag: '--api-key <key>', description: 'API key' },
4343
{ flag: '--region <region>', description: 'API region: global, cn' },
4444
{ flag: '--base-url <url>', description: 'API base URL' },
45-
{ flag: '--output <format>', description: 'Output format: text, json, yaml' },
45+
{ flag: '--output <format>', description: 'Output format: text, json' },
4646
{ flag: '--timeout <seconds>', description: 'Request timeout', type: 'number' },
4747
{ flag: '--quiet', description: 'Suppress non-essential output' },
4848
{ flag: '--verbose', description: 'Print HTTP request/response details' },

src/commands/auth/login.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default defineCommand({
7777
);
7878
}
7979

80-
// Store key in config.yaml
80+
// Store key in config.json
8181
const existing = readConfigFile() as Record<string, unknown>;
8282
existing.api_key = key;
8383
await writeConfigFile(existing);

src/commands/auth/logout.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default defineCommand({
2323

2424
if (config.dryRun) {
2525
if (creds) console.log('Would remove ~/.minimax/credentials.json');
26-
if (hasConfigKey) console.log('Would clear api_key from ~/.minimax/config.yaml');
26+
if (hasConfigKey) console.log('Would clear api_key from ~/.minimax/config.json');
2727
if (!creds && !hasConfigKey) console.log('No credentials to clear.');
2828
console.log('No changes made.');
2929
return;
@@ -39,7 +39,7 @@ export default defineCommand({
3939
const updated = fileConfig as Record<string, unknown>;
4040
delete updated.api_key;
4141
await writeConfigFile(updated);
42-
process.stderr.write('Cleared api_key from ~/.minimax/config.yaml\n');
42+
process.stderr.write('Cleared api_key from ~/.minimax/config.json\n');
4343
} catch { /* ignore */ }
4444
}
4545

src/commands/config/set.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ export default defineCommand({
4848
);
4949
}
5050

51-
if (key === 'output' && !['text', 'json', 'yaml'].includes(value)) {
51+
if (key === 'output' && !['text', 'json'].includes(value)) {
5252
throw new CLIError(
53-
`Invalid output format "${value}". Valid values: text, json, yaml`,
53+
`Invalid output format "${value}". Valid values: text, json`,
5454
ExitCode.USAGE,
5555
);
5656
}

src/config/loader.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { readFileSync, writeFileSync, existsSync } from 'fs';
2-
import { parse as parseYaml, stringify as yamlStringify } from 'yaml';
32
import { parseConfigFile, REGIONS, type Config, type ConfigFile, type Region } from './schema';
43
import { ensureConfigDir, getConfigPath } from './paths';
54
import { detectOutputFormat, type OutputFormat } from '../output/formatter';
@@ -9,15 +8,15 @@ export function readConfigFile(): ConfigFile {
98
const path = getConfigPath();
109
if (!existsSync(path)) return {};
1110
try {
12-
return parseConfigFile(parseYaml(readFileSync(path, 'utf-8')));
11+
return parseConfigFile(JSON.parse(readFileSync(path, 'utf-8')));
1312
} catch {
1413
return {};
1514
}
1615
}
1716

1817
export async function writeConfigFile(data: Record<string, unknown>): Promise<void> {
1918
await ensureConfigDir();
20-
writeFileSync(getConfigPath(), yamlStringify(data), { mode: 0o600 });
19+
writeFileSync(getConfigPath(), JSON.stringify(data, null, 2) + '\n', { mode: 0o600 });
2120
}
2221

2322
export function loadConfig(flags: GlobalFlags): Config {
@@ -31,7 +30,6 @@ export function loadConfig(flags: GlobalFlags): Config {
3130
const cachedRegion = file.region;
3231
const region = (explicitRegion || cachedRegion || 'global') as Region;
3332

34-
// Re-detect if: no explicit region AND (no cached region OR key fingerprint changed)
3533
const activeKey = apiKey || fileApiKey || envApiKey;
3634
const keyFingerprint = activeKey ? activeKey.slice(0, 8) : undefined;
3735
const needsRegionDetection = !explicitRegion

src/config/paths.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function getConfigDir(): string {
88
}
99

1010
export function getConfigPath(): string {
11-
return join(getConfigDir(), 'config.yaml');
11+
return join(getConfigDir(), 'config.json');
1212
}
1313

1414
export function getCredentialsPath(): string {

src/config/schema.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ export interface ConfigFile {
1010
region?: Region;
1111
region_key_fingerprint?: string;
1212
base_url?: string;
13-
output?: 'text' | 'json' | 'yaml';
13+
output?: 'text' | 'json';
1414
timeout?: number;
1515
}
1616

1717
const VALID_REGIONS = new Set<string>(['global', 'cn']);
18-
const VALID_OUTPUTS = new Set<string>(['text', 'json', 'yaml']);
18+
const VALID_OUTPUTS = new Set<string>(['text', 'json']);
1919

2020
export function parseConfigFile(raw: unknown): ConfigFile {
2121
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return {};
@@ -38,7 +38,7 @@ export interface Config {
3838
fileApiKey?: string;
3939
region: Region;
4040
baseUrl: string;
41-
output: 'text' | 'json' | 'yaml';
41+
output: 'text' | 'json';
4242
timeout: number;
4343
verbose: boolean;
4444
quiet: boolean;

0 commit comments

Comments
 (0)