"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;
};
Object.defineProperty(exports, "__esModule", { value: true });
const normalize_registries_1 = __importStar(require("@pnpm/normalize-registries"));
const path = require("path");
const loadJsonFile = require("load-json-file");
const defaults = async (opts) => {
    var _a, _b, _c;
    const packageManager = (_a = opts.packageManager) !== null && _a !== void 0 ? _a : await loadJsonFile(path.join(__dirname, '../../package.json'));
    const dir = (_b = opts.dir) !== null && _b !== void 0 ? _b : process.cwd();
    const lockfileDir = (_c = opts.lockfileDir) !== null && _c !== void 0 ? _c : dir;
    return {
        childConcurrency: 5,
        development: true,
        dir,
        force: false,
        forceSharedLockfile: false,
        lockfileDir,
        optional: true,
        packageManager,
        pending: false,
        production: true,
        rawConfig: {},
        registries: normalize_registries_1.DEFAULT_REGISTRIES,
        shamefullyHoist: false,
        shellEmulator: false,
        sideEffectsCacheRead: false,
        storeDir: opts.storeDir,
        unsafePerm: process.platform === 'win32' ||
            process.platform === 'cygwin' ||
            !(process.getuid && process.setuid &&
                process.getgid && process.setgid) ||
            process.getuid() !== 0,
        useLockfile: true,
        userAgent: `${packageManager.name}/${packageManager.version} npm/? node/${process.version} ${process.platform} ${process.arch}`,
    };
};
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 };
    extendedOpts.registries = normalize_registries_1.default(extendedOpts.registries);
    return extendedOpts;
};
//# sourceMappingURL=extendRebuildOptions.js.map