'use strict';

var chunkAF3E2D32_cjs = require('./chunk-AF3E2D32.cjs');
var c12 = require('c12');
var defu = require('defu');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var defu__default = /*#__PURE__*/_interopDefault(defu);

async function loadConfig(projectRoot, mode, cacheDir) {
  let jitiOptions;
  if (cacheDir) {
    jitiOptions = {
      fsCache: cacheDir,
      moduleCache: true
    };
  }
  const result = await Promise.all([
    c12.loadConfig({
      cwd: projectRoot,
      name: "storm",
      envName: mode,
      globalRc: true,
      packageJson: true,
      dotenv: true,
      jitiOptions
    }),
    c12.loadConfig({
      cwd: projectRoot,
      name: "storm",
      configFile: "storm",
      rcFile: false,
      globalRc: false,
      packageJson: false,
      dotenv: false,
      jitiOptions
    }),
    c12.loadConfig({
      cwd: projectRoot,
      name: "storm-stack",
      envName: mode,
      globalRc: true,
      packageJson: [
        "storm-stack",
        "stormStack"
      ],
      dotenv: true,
      jitiOptions
    }),
    c12.loadConfig({
      cwd: projectRoot,
      name: "storm-stack",
      configFile: "storm-stack",
      rcFile: false,
      globalRc: false,
      packageJson: false,
      dotenv: false,
      jitiOptions
    })
  ]);
  return defu__default.default(result[0].config, result[1].config, result[2].config, result[3].config);
}
chunkAF3E2D32_cjs.__name(loadConfig, "loadConfig");

exports.loadConfig = loadConfig;
//# sourceMappingURL=chunk-354WHETS.cjs.map
//# sourceMappingURL=chunk-354WHETS.cjs.map