"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const pnpm_logger_1 = require("pnpm-logger");
const expandTilde_1 = require("../fs/expandTilde");
const pnpmPkgJson_1 = require("../pnpmPkgJson");
const DEFAULT_LOCAL_REGISTRY = expandTilde_1.default('~/.pnpm-registry');
const defaults = (opts) => {
    const prefix = process.cwd();
    return {
        fetchRetries: 2,
        fetchRetryFactor: 10,
        fetchRetryMintimeout: 1e4,
        fetchRetryMaxtimeout: 6e4,
        storePath: '~/.pnpm-store',
        localRegistry: DEFAULT_LOCAL_REGISTRY,
        ignoreScripts: false,
        strictSsl: true,
        tag: 'latest',
        production: process.env.NODE_ENV === 'production',
        bin: path.join(opts.prefix || prefix, 'node_modules', '.bin'),
        prefix,
        nodeVersion: process.version,
        force: false,
        depth: 0,
        engineStrict: false,
        metaCache: new Map(),
        networkConcurrency: 16,
        fetchingConcurrency: 16,
        lockStaleDuration: 60 * 1000,
        lock: true,
        childConcurrency: 5,
        offline: false,
        registry: 'https://registry.npmjs.org/',
        userAgent: `${pnpmPkgJson_1.default.name}/${pnpmPkgJson_1.default.version} npm/? node/${process.version} ${process.platform} ${process.arch}`,
        rawNpmConfig: {},
        alwaysAuth: false,
        update: false,
        repeatInstallDepth: -1,
        optional: true,
    };
};
exports.default = (opts) => {
    if (opts) {
        for (const key in opts) {
            if (opts[key] === undefined) {
                delete opts[key];
            }
        }
    }
    const extendedOpts = Object.assign({}, defaults(opts || {}), opts);
    if (extendedOpts.force) {
        pnpm_logger_1.default.warn('using --force I sure hope you know what you are doing');
    }
    if (extendedOpts.lock === false) {
        pnpm_logger_1.default.warn('using --no-lock I sure hope you know what you are doing');
    }
    if (extendedOpts.localRegistry !== DEFAULT_LOCAL_REGISTRY) {
        extendedOpts.localRegistry = expandTilde_1.default(extendedOpts.localRegistry, extendedOpts.prefix);
    }
    if (extendedOpts.save === false && extendedOpts.saveDev === false && extendedOpts.saveOptional === false) {
        throw new Error('Cannot install with save/saveDev/saveOptional all being equal false');
    }
    extendedOpts.save = extendedOpts.save || !extendedOpts.saveDev && !extendedOpts.saveOptional;
    if (extendedOpts.userAgent.startsWith('npm/')) {
        extendedOpts.userAgent = `${pnpmPkgJson_1.default.name}/${pnpmPkgJson_1.default.version} ${extendedOpts.userAgent}`;
    }
    return extendedOpts;
};
//# sourceMappingURL=extendOptions.js.map