"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const typescript_1 = require("typescript");
const diagnosticToString_1 = require("./diagnosticToString");
function findTsConfig(cwd = process.cwd()) {
    const configPath = typescript_1.findConfigFile(cwd, (fileName) => fs.existsSync(fileName));
    if (!configPath) {
        throw new Error('Unable to find TypeScript configuration');
    }
    const configContents = fs.readFileSync(configPath).toString();
    const { config } = typescript_1.parseConfigFileTextToJson(configPath, configContents);
    const { compilerOptions: unparsedCompilerOptions } = config;
    const { options, errors } = typescript_1.convertCompilerOptionsFromJson(unparsedCompilerOptions, cwd, 'tsconfig.json');
    if (errors && errors.length > 0) {
        throw new Error(errors.map(x => diagnosticToString_1.diagnosticToString(x, cwd)).join('\n'));
    }
    return Object.assign({}, config, { compilerOptions: options, configPath });
}
exports.findTsConfig = findTsConfig;
//# sourceMappingURL=findTsConfig.js.map