UNPKG

dts-jest

Version:

A preprocessor for Jest to snapshot test TypeScript declaration (.d.ts) files

31 lines (30 loc) 1.68 kB
"use strict"; exports.__esModule = true; var path = require("path"); var create_message_1 = require("./create-message"); var get_diagnostic_message_1 = require("./get-diagnostic-message"); exports.load_compiler_options = function (raw_options, ts) { return typeof raw_options === 'string' ? load_from_tsconfig(raw_options, ts) : load_from_raw_options(raw_options, ts); }; function load_from_raw_options(raw_options, ts) { var _a = ts.convertCompilerOptionsFromJson(raw_options, process.cwd()), errors = _a.errors, options = _a.options; if (errors.length !== 0) { throw new Error(create_message_1.create_message('Unexpected error(s) while loading compiler options:', errors.map(get_diagnostic_message_1.get_diagnostic_message))); } return { options: options, file_names: [] }; } function load_from_tsconfig(filename, ts) { var _a = ts.readConfigFile(filename, ts.sys.readFile), tsconfig = _a.config, error = _a.error; // istanbul ignore next if (error !== undefined) { throw new Error(create_message_1.create_message("Unexpected error(s) while reading tsconfig (" + filename + "):", [get_diagnostic_message_1.get_diagnostic_message(error)])); } var dirname = path.dirname(filename); var _b = ts.parseJsonConfigFileContent(tsconfig, ts.sys, dirname), errors = _b.errors, options = _b.options, file_names = _b.fileNames; if (errors.length !== 0) { throw new Error(create_message_1.create_message("Unexpected error(s) while parsing tsconfig (" + filename + "):", errors.map(get_diagnostic_message_1.get_diagnostic_message))); } return { options: options, file_names: file_names }; }