"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.initializeDotEnv = initializeDotEnv;
const node_path_1 = __importDefault(require("node:path"));
const dotenv_1 = __importDefault(require("dotenv"));
const RushUserConfiguration_1 = require("../api/RushUserConfiguration");
const EnvironmentConfiguration_1 = require("../api/EnvironmentConfiguration");
function initializeDotEnv(terminal, rushJsonFilePath) {
    if (EnvironmentConfiguration_1.EnvironmentConfiguration.hasBeenValidated) {
        throw terminal.writeWarningLine(`The ${EnvironmentConfiguration_1.EnvironmentConfiguration.name} was initialized before .env files were loaded. Rush environment ` +
            'variables may have unexpected values.');
    }
    if (rushJsonFilePath) {
        const rushJsonFolder = node_path_1.default.dirname(rushJsonFilePath);
        dotenv_1.default.config({ path: `${rushJsonFolder}/.env` });
    }
    const rushUserFolder = RushUserConfiguration_1.RushUserConfiguration.getRushUserFolderPath();
    dotenv_1.default.config({ path: `${rushUserFolder}/.env` });
    // TODO: Consider adding support for repo-specific `.rush-user` `.env` files.
}
//# sourceMappingURL=dotenv.js.map