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);
11 if (configFilePath !== undefined) {
12 if (compilerCompatible) {
13 log.logInfo(`${compilerDetailsLogMessage} and ${configFilePath}`);
16 log.logInfo(`ts-loader: Using config file at ${configFilePath}`);
18 configFile = compiler.readConfigFile(configFilePath, compiler.sys.readFile);
19 if (configFile.error !== undefined) {
20 configFileError = (0, utils_1.formatErrors)([configFile.error], loaderOptions, colors, compiler, { file: configFilePath }, loader.context)[0];
24 if (compilerCompatible) {
25 log.logInfo(compilerDetailsLogMessage);
34 if (configFileError === undefined) {
35 configFile.config.compilerOptions = Object.assign({}, configFile.config.compilerOptions);
43 exports.getConfigFile = getConfigFile;
45 * Find a tsconfig file by name or by path.
46 * By name, the tsconfig.json is found using the same method as `tsc`, starting in the current
47 * directory and continuing up the parent directory chain.
48 * By path, the file will be found by resolving the given path relative to the requesting entry file.
50 * @param compiler The TypeScript compiler instance
51 * @param requestDirPath The directory in which the entry point requesting the tsconfig.json lies
52 * @param configFile The tsconfig file name to look for or a path to that file
53 * @return The absolute path to the tsconfig file, undefined if none was found.
55 function findConfigFile(compiler, requestDirPath, configFile) {
56 // If `configFile` is an absolute path, return it right away
57 if (path.isAbsolute(configFile)) {
58 return compiler.sys.fileExists(configFile) ? configFile : undefined;
60 // If `configFile` is a relative path, resolve it.
61 // We define a relative path as: starts with
62 // one or two dots + a common directory delimiter
63 if (configFile.match(/^\.\.?(\/|\\)/) !== null) {
64 const resolvedPath = path.resolve(requestDirPath, configFile);
65 return compiler.sys.fileExists(resolvedPath) ? resolvedPath : undefined;
66 // If `configFile` is a file name, find it in the directory tree
70 const fileName = path.join(requestDirPath, configFile);
71 if (compiler.sys.fileExists(fileName)) {
74 const parentPath = path.dirname(requestDirPath);
75 if (parentPath === requestDirPath) {
78 requestDirPath = parentPath;
83 function getConfigParseResult(compiler, configFile, basePath, configFilePath, loaderOptions) {
84 const configParseResult = compiler.parseJsonConfigFileContent(configFile.config, {
86 useCaseSensitiveFileNames: (0, utils_1.useCaseSensitiveFileNames)(compiler, loaderOptions),
87 }, basePath, getCompilerOptionsToExtend(compiler, loaderOptions, basePath, configFilePath || 'tsconfig.json'));
88 if (!loaderOptions.projectReferences) {
89 configParseResult.projectReferences = undefined;
91 // set internal options.configFilePath flag on options to denote that we read this from a file
92 configParseResult.options = Object.assign({}, configParseResult.options, {
95 return configParseResult;
97 exports.getConfigParseResult = getConfigParseResult;
98 const extendedConfigCache = new Map();
99 function getParsedCommandLine(compiler, loaderOptions, configFilePath) {
100 const result = compiler.getParsedCommandLineOfConfigFile(configFilePath, getCompilerOptionsToExtend(compiler, loaderOptions, path.dirname(configFilePath), configFilePath), {
102 useCaseSensitiveFileNames: (0, utils_1.useCaseSensitiveFileNames)(compiler, loaderOptions),
103 // eslint-disable-next-line @typescript-eslint/no-empty-function
104 onUnRecoverableConfigFileDiagnostic: () => { },
105 }, extendedConfigCache);
107 result.options = (0, compilerSetup_1.getCompilerOptions)(result, compiler);
111 exports.getParsedCommandLine = getParsedCommandLine;
112 function getCompilerOptionsToExtend(compiler, loaderOptions, basePath, configFileName) {
113 return compiler.convertCompilerOptionsFromJson(loaderOptions.compilerOptions, basePath, configFileName).options;
115 //# sourceMappingURL=config.js.map