"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleApplication = handleApplication;
const dotenv_1 = require("dotenv");
const harper_logger_ts_1 = __importDefault(require("../utility/logging/harper_logger.js"));
function handleApplication(scope) {
    const override = scope.options.getAll().override ?? false;
    scope.handleEntry((entry) => {
        if (entry.eventType !== 'add') {
            scope.requestRestart();
            return;
        }
        harper_logger_ts_1.default.debug(`Loading env file: ${entry.absolutePath}`);
        for (const [key, value] of Object.entries((0, dotenv_1.parse)(entry.contents))) {
            if (process.env[key] !== undefined) {
                harper_logger_ts_1.default.warn(`Environment variable conflict: ${key} from ${entry.absolutePath} is already set on process.env`);
                if (override) {
                    harper_logger_ts_1.default.debug(`override option enabled. overriding environment variable: ${key}`);
                }
                else {
                    continue;
                }
            }
            process.env[key] = value;
        }
    });
}
//# sourceMappingURL=loadEnv.js.map