"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const pnpm_logger_1 = require("pnpm-logger");
const pnpmPkgJson_1 = require("../pnpmPkgJson");
const modulesController_1 = require("../fs/modulesController");
const normalizeRegistryUrl = require("normalize-registry-url");
const defaults = (opts) => {
    const prefix = process.cwd();
    return {
        fetchRetries: 2,
        fetchRetryFactor: 10,
        fetchRetryMintimeout: 1e4,
        fetchRetryMaxtimeout: 6e4,
        store: '~/.pnpm-store',
        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,
        independentLeaves: false,
    };
};
exports.default = (opts) => {
    opts = opts || {};
    if (opts) {
        for (const key in opts) {
            if (opts[key] === undefined) {
                delete opts[key];
            }
        }
    }
    if (opts.storePath && !opts.store) {
        pnpm_logger_1.default.warn('the `store-path` config is deprecated. Use `store` instead.');
        opts.store = opts.storePath;
    }
    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.userAgent.startsWith('npm/')) {
        extendedOpts.userAgent = `${pnpmPkgJson_1.default.name}/${pnpmPkgJson_1.default.version} ${extendedOpts.userAgent}`;
    }
    extendedOpts.registry = normalizeRegistryUrl(extendedOpts.registry);
    if (extendedOpts.global) {
        const subfolder = modulesController_1.LAYOUT_VERSION.toString() + (extendedOpts.independentLeaves ? '_independent_leaves' : '');
        extendedOpts.prefix = path.join(extendedOpts.prefix, subfolder);
    }
    return extendedOpts;
};
//# sourceMappingURL=extendOptions.js.map