fix: preserve config imports defaults
This commit is contained in:
parent
6b9fa78bdb
commit
d55b813c4f
@ -2,7 +2,8 @@
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
- Nothing yet.
|
||||
### CLI
|
||||
- Preserve default imports when `mcporter config add` writes a config file, instead of forcing `"imports": []`.
|
||||
|
||||
## [0.7.3] - 2025-12-29
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ export type ConfigLocationSummary = {
|
||||
export function cloneConfig(config: RawConfig): RawConfig {
|
||||
return {
|
||||
mcpServers: config.mcpServers ? { ...config.mcpServers } : {},
|
||||
imports: config.imports ? [...config.imports] : [],
|
||||
imports: config.imports ? [...config.imports] : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ export async function loadOrCreateConfig(loadOptions: LoadConfigOptions): Promis
|
||||
if (isErrno(error, 'ENOENT')) {
|
||||
const rootDir = loadOptions.rootDir ?? process.cwd();
|
||||
const resolved = resolveConfigPath(loadOptions.configPath, rootDir);
|
||||
return { config: { mcpServers: {}, imports: [] }, path: resolved.path };
|
||||
return { config: { mcpServers: {} }, path: resolved.path };
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
28
tests/config-add-imports.test.ts
Normal file
28
tests/config-add-imports.test.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { handleAddCommand } from '../src/cli/config/add.js';
|
||||
import { createTempConfig } from './fixtures/config-fixture.js';
|
||||
|
||||
describe('config add imports preservation', () => {
|
||||
it('keeps imports undefined when config omits the key', async () => {
|
||||
const ctx = await createTempConfig({ mcpServers: {} });
|
||||
|
||||
await handleAddCommand({ loadOptions: ctx.loadOptions } as never, ['local', 'https://local.example/mcp']);
|
||||
|
||||
const buffer = await fs.readFile(ctx.configPath, 'utf8');
|
||||
const parsed = JSON.parse(buffer) as { imports?: string[] };
|
||||
expect(Object.hasOwn(parsed, 'imports')).toBe(false);
|
||||
await ctx.cleanup();
|
||||
});
|
||||
|
||||
it('keeps imports undefined when creating a new config file', async () => {
|
||||
const ctx = await createTempConfig();
|
||||
|
||||
await handleAddCommand({ loadOptions: ctx.loadOptions } as never, ['fresh', 'https://fresh.example/mcp']);
|
||||
|
||||
const buffer = await fs.readFile(ctx.configPath, 'utf8');
|
||||
const parsed = JSON.parse(buffer) as { imports?: string[] };
|
||||
expect(Object.hasOwn(parsed, 'imports')).toBe(false);
|
||||
await ctx.cleanup();
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user