"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NpmConfigService = void 0;
const yok_1 = require("../common/yok");
const child_process_1 = require("child_process");
const decorators_1 = require("../common/decorators");
class NpmConfigService {
    constructor() {
        this.config = {};
    }
    getConfig() {
        this.readConfig();
        return this.config;
    }
    readConfig() {
        try {
            const res = (0, child_process_1.execSync)("npm config list --json --global");
            // const data: any = npmconfig.read();
            const data = JSON.parse(res.toString());
            // todo: remove if not needed with npm config list --json?
            Object.entries(data).forEach(([key, value]) => {
                // replace env ${VARS} in strings with the process.env value
                this.config[key] =
                    typeof value !== "string"
                        ? value
                        : value.replace(/\${([^}]+)}/, (_, envVar) => process.env[envVar]);
            });
        }
        catch (e) { }
    }
}
__decorate([
    (0, decorators_1.cache)()
], NpmConfigService.prototype, "readConfig", null);
exports.NpmConfigService = NpmConfigService;
yok_1.injector.register("npmConfigService", NpmConfigService);
//# sourceMappingURL=npm-config-service.js.map