"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }

var _chunk7IOWYE4Ocjs = require('./chunk-7IOWYE4O.cjs');


var _chunkQZAXYX3Xcjs = require('./chunk-QZAXYX3X.cjs');




var _chunk3HOVXAQZcjs = require('./chunk-3HOVXAQZ.cjs');


var _chunk2BONUUVScjs = require('./chunk-2BONUUVS.cjs');


var _chunkI4SIJOYBcjs = require('./chunk-I4SIJOYB.cjs');


var _chunkV2H3W5RMcjs = require('./chunk-V2H3W5RM.cjs');



var _chunkNMYOKDUEcjs = require('./chunk-NMYOKDUE.cjs');



var _chunkSCFUDB74cjs = require('./chunk-SCFUDB74.cjs');

// src/create-storm-config.ts
_chunkSCFUDB74cjs.init_cjs_shims.call(void 0, );
var _schema = require('@storm-software/config/schema');
var _extension_cache = /* @__PURE__ */ new WeakMap();
var _static_cache = void 0;
var createStormConfig = /* @__PURE__ */ _chunkSCFUDB74cjs.__name.call(void 0, async (extensionName, schema, workspaceRoot, skipLogs = false) => {
  let result;
  if (!_optionalChain([_static_cache, 'optionalAccess', _ => _.data]) || !_optionalChain([_static_cache, 'optionalAccess', _2 => _2.timestamp]) || _static_cache.timestamp < Date.now() - 8e3) {
    let _workspaceRoot = workspaceRoot;
    if (!_workspaceRoot) {
      _workspaceRoot = _chunkI4SIJOYBcjs.findWorkspaceRoot.call(void 0, );
    }
    const configEnv = _chunkNMYOKDUEcjs.getConfigEnv.call(void 0, );
    const defaultConfig = await _chunk2BONUUVScjs.getDefaultConfig.call(void 0, _workspaceRoot);
    const configFile = await _chunk7IOWYE4Ocjs.getConfigFile.call(void 0, _workspaceRoot);
    if (!configFile && !skipLogs) {
      _chunk3HOVXAQZcjs.writeWarning.call(void 0, "No Storm config file found in the current workspace. Please ensure this is the expected behavior - you can add a `storm.json` file to the root of your workspace if it is not.\n", {
        logLevel: "all"
      });
    }
    result = await _schema.StormConfigSchema.parseAsync(_chunkQZAXYX3Xcjs.defu.call(void 0, configEnv, configFile, defaultConfig));
    result.workspaceRoot ??= _workspaceRoot;
  } else {
    result = _static_cache.data;
  }
  if (schema && extensionName) {
    result.extensions = {
      ...result.extensions,
      [extensionName]: createConfigExtension(extensionName, schema)
    };
  }
  _static_cache = {
    timestamp: Date.now(),
    data: result
  };
  return result;
}, "createStormConfig");
var createConfigExtension = /* @__PURE__ */ _chunkSCFUDB74cjs.__name.call(void 0, (extensionName, schema) => {
  const extension_cache_key = {
    extensionName
  };
  if (_extension_cache.has(extension_cache_key)) {
    return _extension_cache.get(extension_cache_key);
  }
  let extension = _chunkNMYOKDUEcjs.getExtensionEnv.call(void 0, extensionName);
  if (schema) {
    extension = schema.parse(extension);
  }
  _extension_cache.set(extension_cache_key, extension);
  return extension;
}, "createConfigExtension");
var loadStormConfig = /* @__PURE__ */ _chunkSCFUDB74cjs.__name.call(void 0, async (workspaceRoot, skipLogs = false) => {
  const config = await createStormConfig(void 0, void 0, workspaceRoot, skipLogs);
  _chunkV2H3W5RMcjs.setConfigEnv.call(void 0, config);
  if (!skipLogs) {
    _chunk3HOVXAQZcjs.writeTrace.call(void 0, `\u2699\uFE0F  Using Storm configuration: 
${_chunk3HOVXAQZcjs.formatLogMessage.call(void 0, config)}`, config);
  }
  return config;
}, "loadStormConfig");





exports.createStormConfig = createStormConfig; exports.createConfigExtension = createConfigExtension; exports.loadStormConfig = loadStormConfig;
