1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getParsedCommandLine = exports.getConfigParseResult = exports.getConfigFile = void 0;
|
4 | const path = require("path");
|
5 | const compilerSetup_1 = require("./compilerSetup");
|
6 | const utils_1 = require("./utils");
|
7 | function getConfigFile(compiler, colors, loader, loaderOptions, compilerCompatible, log, compilerDetailsLogMessage) {
|
8 | const configFilePath = findConfigFile(compiler, path.dirname(loader.resourcePath), loaderOptions.configFile);
|
9 | let configFileError;
|
10 | let configFile;
|
11 | if (configFilePath !== undefined) {
|
12 | if (compilerCompatible) {
|
13 | log.logInfo(`${compilerDetailsLogMessage} and ${configFilePath}`);
|
14 | }
|
15 | else {
|
16 | log.logInfo(`ts-loader: Using config file at ${configFilePath}`);
|
17 | }
|
18 | configFile = compiler.readConfigFile(configFilePath, compiler.sys.readFile);
|
19 | if (configFile.error !== undefined) {
|
20 | configFileError = utils_1.formatErrors([configFile.error], loaderOptions, colors, compiler, { file: configFilePath }, loader.context)[0];
|
21 | }
|
22 | }
|
23 | else {
|
24 | if (compilerCompatible) {
|
25 | log.logInfo(compilerDetailsLogMessage);
|
26 | }
|
27 | configFile = {
|
28 | config: {
|
29 | compilerOptions: {},
|
30 | files: [],
|
31 | },
|
32 | };
|
33 | }
|
34 | if (configFileError === undefined) {
|
35 | configFile.config.compilerOptions = Object.assign({}, configFile.config.compilerOptions);
|
36 | }
|
37 | return {
|
38 | configFilePath,
|
39 | configFile,
|
40 | configFileError,
|
41 | };
|
42 | }
|
43 | exports.getConfigFile = getConfigFile;
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | function findConfigFile(compiler, requestDirPath, configFile) {
|
56 |
|
57 | if (path.isAbsolute(configFile)) {
|
58 | return compiler.sys.fileExists(configFile) ? configFile : undefined;
|
59 | }
|
60 |
|
61 |
|
62 |
|
63 | if (configFile.match(/^\.\.?(\/|\\)/) !== null) {
|
64 | const resolvedPath = path.resolve(requestDirPath, configFile);
|
65 | return compiler.sys.fileExists(resolvedPath) ? resolvedPath : undefined;
|
66 |
|
67 | }
|
68 | else {
|
69 | while (true) {
|
70 | const fileName = path.join(requestDirPath, configFile);
|
71 | if (compiler.sys.fileExists(fileName)) {
|
72 | return fileName;
|
73 | }
|
74 | const parentPath = path.dirname(requestDirPath);
|
75 | if (parentPath === requestDirPath) {
|
76 | break;
|
77 | }
|
78 | requestDirPath = parentPath;
|
79 | }
|
80 | return undefined;
|
81 | }
|
82 | }
|
83 | function getConfigParseResult(compiler, configFile, basePath, configFilePath, loaderOptions) {
|
84 | const configParseResult = compiler.parseJsonConfigFileContent(configFile.config, Object.assign(Object.assign({}, compiler.sys), { useCaseSensitiveFileNames: utils_1.useCaseSensitiveFileNames(compiler, loaderOptions) }), basePath, getCompilerOptionsToExtend(compiler, loaderOptions, basePath, configFilePath || 'tsconfig.json'));
|
85 | if (!loaderOptions.projectReferences) {
|
86 | configParseResult.projectReferences = undefined;
|
87 | }
|
88 |
|
89 | configParseResult.options = Object.assign({}, configParseResult.options, {
|
90 | configFilePath,
|
91 | });
|
92 | return configParseResult;
|
93 | }
|
94 | exports.getConfigParseResult = getConfigParseResult;
|
95 | const extendedConfigCache = new Map();
|
96 | function getParsedCommandLine(compiler, loaderOptions, configFilePath) {
|
97 | const result = compiler.getParsedCommandLineOfConfigFile(configFilePath, getCompilerOptionsToExtend(compiler, loaderOptions, path.dirname(configFilePath), configFilePath), Object.assign(Object.assign({}, compiler.sys), { useCaseSensitiveFileNames: utils_1.useCaseSensitiveFileNames(compiler, loaderOptions),
|
98 |
|
99 | onUnRecoverableConfigFileDiagnostic: () => { } }), extendedConfigCache);
|
100 | if (result) {
|
101 | result.options = compilerSetup_1.getCompilerOptions(result);
|
102 | }
|
103 | return result;
|
104 | }
|
105 | exports.getParsedCommandLine = getParsedCommandLine;
|
106 | function getCompilerOptionsToExtend(compiler, loaderOptions, basePath, configFileName) {
|
107 | return compiler.convertCompilerOptionsFromJson(loaderOptions.compilerOptions, basePath, configFileName).options;
|
108 | }
|
109 |
|
\ | No newline at end of file |