// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import path from 'node:path';
import dotenv from 'dotenv';
import { RushUserConfiguration } from '../api/RushUserConfiguration';
import { EnvironmentConfiguration } from '../api/EnvironmentConfiguration';
export function initializeDotEnv(terminal, rushJsonFilePath) {
    if (EnvironmentConfiguration.hasBeenValidated) {
        throw terminal.writeWarningLine(`The ${EnvironmentConfiguration.name} was initialized before .env files were loaded. Rush environment ` +
            'variables may have unexpected values.');
    }
    if (rushJsonFilePath) {
        const rushJsonFolder = path.dirname(rushJsonFilePath);
        dotenv.config({ path: `${rushJsonFolder}/.env` });
    }
    const rushUserFolder = RushUserConfiguration.getRushUserFolderPath();
    dotenv.config({ path: `${rushUserFolder}/.env` });
    // TODO: Consider adding support for repo-specific `.rush-user` `.env` files.
}
//# sourceMappingURL=dotenv.js.map