'use strict';

var chunkAF3E2D32_cjs = require('./chunk-AF3E2D32.cjs');
var readFile = require('@stryke/fs/read-file');
var path = require('@stryke/path');
var defu = require('defu');
var ts = require('typescript');

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

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

function getTsconfigFilePath(context) {
  const tsconfigFilePath = context.options.tsconfig || path.joinPaths(context.options.projectRoot, "tsconfig.json");
  if (!path.existsSync(tsconfigFilePath)) {
    throw new Error(`Cannot find the \`tsconfig.json\` configuration file at ${tsconfigFilePath}`);
  }
  return tsconfigFilePath;
}
chunkAF3E2D32_cjs.__name(getTsconfigFilePath, "getTsconfigFilePath");
async function getParsedTypeScriptConfig(context) {
  const tsconfigFilePath = getTsconfigFilePath(context);
  let tsconfigJson = await readFile.readJsonFile(tsconfigFilePath);
  if (context.options.tsconfigRaw) {
    tsconfigJson = defu__default.default(tsconfigJson, context.options.tsconfigRaw);
  }
  const tsconfig = ts__default.default.parseJsonConfigFileContent(tsconfigJson, ts__default.default.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
  };
}
chunkAF3E2D32_cjs.__name(getParsedTypeScriptConfig, "getParsedTypeScriptConfig");

exports.getParsedTypeScriptConfig = getParsedTypeScriptConfig;
exports.getTsconfigFilePath = getTsconfigFilePath;
//# sourceMappingURL=chunk-Q2RX2PCI.cjs.map
//# sourceMappingURL=chunk-Q2RX2PCI.cjs.map