1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getCompilerOptions = void 0;
|
4 | var ts = require("typescript");
|
5 | var path = require("path");
|
6 | var get_absolute_path_1 = require("./helpers/get-absolute-path");
|
7 | var fix_path_1 = require("./helpers/fix-path");
|
8 | var check_diagnostics_errors_1 = require("./helpers/check-diagnostics-errors");
|
9 | var logger_1 = require("./logger");
|
10 | var parseConfigHost = {
|
11 | useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
|
12 | readDirectory: ts.sys.readDirectory,
|
13 | fileExists: ts.sys.fileExists,
|
14 | readFile: ts.sys.readFile,
|
15 | };
|
16 | function getCompilerOptions(inputFileNames, preferredConfigPath) {
|
17 | var configFileName = preferredConfigPath !== undefined ? preferredConfigPath : findConfig(inputFileNames);
|
18 | logger_1.verboseLog("Using config: " + configFileName);
|
19 | var configParseResult = ts.readConfigFile(configFileName, ts.sys.readFile);
|
20 | check_diagnostics_errors_1.checkDiagnosticsErrors(configParseResult.error !== undefined ? [configParseResult.error] : [], 'Error while processing tsconfig file');
|
21 | var compilerOptionsParseResult = ts.parseJsonConfigFileContent(configParseResult.config, parseConfigHost, path.resolve(path.dirname(configFileName)), undefined, get_absolute_path_1.getAbsolutePath(configFileName));
|
22 |
|
23 |
|
24 | var diagnostics = compilerOptionsParseResult.errors
|
25 | .filter(function (d) { return d.code !== 18003 ; });
|
26 | check_diagnostics_errors_1.checkDiagnosticsErrors(diagnostics, 'Error while processing tsconfig compiler options');
|
27 | return compilerOptionsParseResult.options;
|
28 | }
|
29 | exports.getCompilerOptions = getCompilerOptions;
|
30 | function findConfig(inputFiles) {
|
31 | if (inputFiles.length !== 1) {
|
32 | throw new Error('Cannot find tsconfig for multiple files. Please specify preferred tsconfig file');
|
33 | }
|
34 | var searchPath = fix_path_1.fixPath(inputFiles[0]);
|
35 | var configFileName = ts.findConfigFile(searchPath, ts.sys.fileExists);
|
36 | if (!configFileName) {
|
37 | throw new Error("Cannot find config file for file " + searchPath);
|
38 | }
|
39 | return configFileName;
|
40 | }
|