import { __name } from './chunk-6AXVLTU5.js';
import { readJsonFile } from '@stryke/fs/read-file';
import { joinPaths, existsSync } from '@stryke/path';
import defu from 'defu';
import ts from 'typescript';

function getTsconfigFilePath(context) {
  const tsconfigFilePath = context.options.tsconfig || joinPaths(context.options.projectRoot, "tsconfig.json");
  if (!existsSync(tsconfigFilePath)) {
    throw new Error(`Cannot find the \`tsconfig.json\` configuration file at ${tsconfigFilePath}`);
  }
  return tsconfigFilePath;
}
__name(getTsconfigFilePath, "getTsconfigFilePath");
async function getParsedTypeScriptConfig(context) {
  const tsconfigFilePath = getTsconfigFilePath(context);
  let tsconfigJson = await readJsonFile(tsconfigFilePath);
  if (context.options.tsconfigRaw) {
    tsconfigJson = defu(tsconfigJson, context.options.tsconfigRaw);
  }
  const tsconfig = ts.parseJsonConfigFileContent(tsconfigJson, ts.sys, context.options.projectRoot);
  if (tsconfig.errors.length > 0) {
    const errorMessage = `Cannot parse the compiler options provided in the \`tsconfigRaw\` option. Please investigate the following issues:
${tsconfig.errors.map((error) => `- ${(error.category !== void 0 && error.code ? `[${error.category}-${error.code}]: ` : "") + error.messageText.toString()}`).join("\n")}
      `;
    throw new Error(errorMessage);
  }
  return {
    ...tsconfig,
    tsconfigJson
  };
}
__name(getParsedTypeScriptConfig, "getParsedTypeScriptConfig");

export { getParsedTypeScriptConfig, getTsconfigFilePath };
//# sourceMappingURL=chunk-JRP7TVNX.js.map
//# sourceMappingURL=chunk-JRP7TVNX.js.map