import { join } from 'node:path';
import { getDataDir, readJsonFile, writeJsonFile } from './json-store.js';
export const DEFAULT_NPM_REGISTRY = 'https://registry.npmmirror.com';
const FILE = () => join(getDataDir(), 'npm-settings.json');
export function getNpmSettings() {
    const settings = readJsonFile(FILE()) ?? {};
    return {
        registry: typeof settings.registry === 'string' && settings.registry.trim()
            ? settings.registry.trim()
            : DEFAULT_NPM_REGISTRY,
        proxy: typeof settings.proxy === 'string' ? settings.proxy.trim() : '',
    };
}
export function saveNpmSettings(input) {
    const settings = {
        registry: typeof input.registry === 'string' && input.registry.trim()
            ? input.registry.trim()
            : DEFAULT_NPM_REGISTRY,
        proxy: typeof input.proxy === 'string' ? input.proxy.trim() : '',
    };
    writeJsonFile(FILE(), settings);
    return settings;
}
//# sourceMappingURL=npm-settings-store.js.map