dts-jest
Version:
A preprocessor for Jest to snapshot test TypeScript declaration (.d.ts) files
33 lines (32 loc) • 1.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.load_compiler_options = void 0;
var path = require("path");
var create_message_1 = require("./create-message");
var get_diagnostic_message_1 = require("./get-diagnostic-message");
var 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);
};
exports.load_compiler_options = load_compiler_options;
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((0, 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((0, create_message_1.create_message)("Unexpected error(s) while reading tsconfig (".concat(filename, "):"), [(0, 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((0, create_message_1.create_message)("Unexpected error(s) while parsing tsconfig (".concat(filename, "):"), errors.map(get_diagnostic_message_1.get_diagnostic_message)));
}
return { options: options, file_names: file_names };
}