"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("@pnpm/constants");
const error_1 = __importDefault(require("@pnpm/error"));
const normalize_registries_1 = __importStar(require("@pnpm/normalize-registries"));
const pnpmPkgJson_1 = __importDefault(require("../pnpmPkgJson"));
const defaults = async (opts) => {
    var _a, _b, _c;
    const packageManager = (_a = opts.packageManager) !== null && _a !== void 0 ? _a : {
        name: pnpmPkgJson_1.default.name,
        version: pnpmPkgJson_1.default.version,
    };
    return {
        childConcurrency: 5,
        depth: 0,
        engineStrict: false,
        force: false,
        forceSharedLockfile: false,
        frozenLockfile: false,
        hoistPattern: undefined,
        hooks: {},
        ignoreCurrentPrefs: false,
        ignoreScripts: false,
        include: {
            dependencies: true,
            devDependencies: true,
            optionalDependencies: true,
        },
        includeDirect: {
            dependencies: true,
            devDependencies: true,
            optionalDependencies: true,
        },
        lockfileDir: (_c = (_b = opts.lockfileDir) !== null && _b !== void 0 ? _b : opts.dir) !== null && _c !== void 0 ? _c : process.cwd(),
        lockfileOnly: false,
        nodeVersion: process.version,
        ownLifecycleHooksStdio: 'inherit',
        packageManager,
        preferFrozenLockfile: true,
        preserveWorkspaceProtocol: true,
        pruneLockfileImporters: false,
        pruneStore: false,
        rawConfig: {},
        registries: normalize_registries_1.DEFAULT_REGISTRIES,
        saveWorkspaceProtocol: true,
        shamefullyHoist: false,
        shellEmulator: false,
        sideEffectsCacheRead: false,
        sideEffectsCacheWrite: false,
        storeController: opts.storeController,
        storeDir: opts.storeDir,
        strictPeerDependencies: false,
        tag: 'latest',
        unsafePerm: process.platform === 'win32' ||
            process.platform === 'cygwin' ||
            !(process.getuid && process.setuid &&
                process.getgid && process.setgid) ||
            process.getuid() !== 0,
        update: false,
        useLockfile: true,
        userAgent: `${packageManager.name}/${packageManager.version} npm/? node/${process.version} ${process.platform} ${process.arch}`,
        verifyStoreIntegrity: true,
        workspacePackages: {},
    };
};
exports.default = async (opts) => {
    if (opts) {
        for (const key in opts) {
            if (opts[key] === undefined) {
                delete opts[key];
            }
        }
    }
    const defaultOpts = await defaults(opts);
    const extendedOpts = {
        ...defaultOpts,
        ...opts,
        storeDir: defaultOpts.storeDir,
    };
    if (!extendedOpts.useLockfile && extendedOpts.lockfileOnly) {
        throw new error_1.default('CONFIG_CONFLICT_LOCKFILE_ONLY_WITH_NO_LOCKFILE', `Cannot generate a ${constants_1.WANTED_LOCKFILE} because lockfile is set to false`);
    }
    if (extendedOpts.userAgent.startsWith('npm/')) {
        extendedOpts.userAgent = `${extendedOpts.packageManager.name}/${extendedOpts.packageManager.version} ${extendedOpts.userAgent}`;
    }
    extendedOpts.registries = normalize_registries_1.default(extendedOpts.registries);
    extendedOpts.rawConfig['registry'] = extendedOpts.registries.default; // eslint-disable-line @typescript-eslint/dot-notation
    return extendedOpts;
};
//# sourceMappingURL=extendInstallOptions.js.map