1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.getTsNodeRegistrationProperties = exports.createSyntheticEmitHost = exports.isModulePathsMatch = exports.getOutputDirForSourceFile = void 0;
|
7 | const path_1 = __importDefault(require("path"));
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | function getOutputDirForSourceFile(context, sourceFile) {
|
15 | const { tsInstance, emitHost, outputFileNamesCache, compilerOptions, tsInstance: { getOwnEmitOutputFilePath, getOutputExtension }, } = context;
|
16 | if (outputFileNamesCache.has(sourceFile))
|
17 | return outputFileNamesCache.get(sourceFile);
|
18 |
|
19 |
|
20 | const outputPath = sourceFile.path && sourceFile.resolvedPath && sourceFile.path !== sourceFile.resolvedPath
|
21 | ? sourceFile.resolvedPath
|
22 | : getOwnEmitOutputFilePath(sourceFile.fileName, emitHost, getOutputExtension(sourceFile.fileName, compilerOptions));
|
23 | if (!outputPath)
|
24 | throw new Error(`Could not resolve output path for ${sourceFile.fileName}. Please report a GH issue at: ` +
|
25 | `https://github.com/LeDDGroup/typescript-transform-paths/issues`);
|
26 | const res = path_1.default.dirname(outputPath);
|
27 | outputFileNamesCache.set(sourceFile, res);
|
28 | return tsInstance.normalizePath(res);
|
29 | }
|
30 | exports.getOutputDirForSourceFile = getOutputDirForSourceFile;
|
31 |
|
32 |
|
33 |
|
34 | function isModulePathsMatch(context, moduleName) {
|
35 | const { pathsPatterns, tsInstance: { matchPatternOrExact }, } = context;
|
36 | return !!(pathsPatterns && matchPatternOrExact(pathsPatterns, moduleName));
|
37 | }
|
38 | exports.isModulePathsMatch = isModulePathsMatch;
|
39 |
|
40 |
|
41 |
|
42 | function createSyntheticEmitHost(compilerOptions, tsInstance, getCanonicalFileName, fileNames) {
|
43 | return {
|
44 | getCompilerOptions: () => compilerOptions,
|
45 | getCurrentDirectory: tsInstance.sys.getCurrentDirectory,
|
46 | getCommonSourceDirectory: () => tsInstance.getCommonSourceDirectoryOfConfig({ options: compilerOptions, fileNames: fileNames }, !tsInstance.sys.useCaseSensitiveFileNames),
|
47 | getCanonicalFileName,
|
48 | };
|
49 | }
|
50 | exports.createSyntheticEmitHost = createSyntheticEmitHost;
|
51 |
|
52 |
|
53 |
|
54 | function getTsNodeRegistrationProperties(tsInstance) {
|
55 | var _a;
|
56 | let tsNodeSymbol;
|
57 | try {
|
58 | tsNodeSymbol = (_a = require("ts-node")) === null || _a === void 0 ? void 0 : _a["REGISTER_INSTANCE"];
|
59 | }
|
60 | catch (_b) {
|
61 | return undefined;
|
62 | }
|
63 | if (!global.process[tsNodeSymbol])
|
64 | return undefined;
|
65 | const { config, options } = global.process[tsNodeSymbol];
|
66 | const { configFilePath } = config.options;
|
67 | const pcl = configFilePath
|
68 | ? tsInstance.getParsedCommandLineOfConfigFile(configFilePath, {}, tsInstance.sys)
|
69 | : void 0;
|
70 | const fileNames = (pcl === null || pcl === void 0 ? void 0 : pcl.fileNames) || config.fileNames;
|
71 | const compilerOptions = Object.assign(config.options, options.compilerOptions, { outDir: pcl === null || pcl === void 0 ? void 0 : pcl.options.outDir });
|
72 | return { compilerOptions, fileNames, tsNodeOptions: options };
|
73 | }
|
74 | exports.getTsNodeRegistrationProperties = getTsNodeRegistrationProperties;
|
75 |
|
76 |
|
\ | No newline at end of file |