import { __name } from './chunk-6AXVLTU5.js';
import { loadConfig as loadConfig$1 } from 'c12';
import defu from 'defu';

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

export { loadConfig };
//# sourceMappingURL=chunk-EH3WHYSZ.js.map
//# sourceMappingURL=chunk-EH3WHYSZ.js.map