fix: preserve config imports defaults

This commit is contained in:
Peter Steinberger 2025-12-30 01:25:04 +01:00
parent 6b9fa78bdb
commit d55b813c4f
3 changed files with 32 additions and 3 deletions

View File

@ -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

View File

@ -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;
}

View 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();
});
});