import { resolvePath } from './chunk-2FB623IG.js';
import { bundle } from './chunk-IRKSJ3RH.js';
import { __name } from './chunk-6AXVLTU5.js';
import { existsSync } from '@stryke/path/exists';
import { findFilePath, findFileName, findFileExtension } from '@stryke/path/file-path-fns';
import { joinPaths } from '@stryke/path/join-paths';

async function resolveType(context, entry) {
  const transpilePath = joinPaths(context.envPaths.temp, "transpiled", findFilePath(entry.file));
  const path = await resolvePath(context, entry.file);
  if (!path || !existsSync(path)) {
    throw new Error(`Module not found: ${entry.file}. Please check the path and try again.`);
  }
  const result = await bundle(context, path, transpilePath, {
    write: true
  }, {
    skipTransform: true
  });
  if (result.errors.length > 0) {
    throw new Error(`Failed to transpile ${entry.file}: ${result.errors.map((error) => error.text).join(", ")}`);
  }
  const resolved = await context.resolver.import(context.resolver.esmResolve(`${joinPaths(transpilePath, findFileName(entry.file).replace(findFileExtension(entry.file), ""))}.js`));
  let exportName = entry.name;
  if (!exportName) {
    exportName = "default";
  }
  const resolvedType = resolved[exportName] ?? resolved[`__\u03A9${exportName}`];
  if (!resolvedType) {
    throw new Error(`Unable to resolve type ${exportName} in ${entry.file}. Please check the path and try again.`);
  }
  return resolvedType;
}
__name(resolveType, "resolveType");
async function reflectType(context, entry) {
  return (void 0)(await resolveType(context, entry));
}
__name(reflectType, "reflectType");

export { reflectType, resolveType };
//# sourceMappingURL=chunk-BAV2W5AA.js.map
//# sourceMappingURL=chunk-BAV2W5AA.js.map