Add node modules and compiled JavaScript from main (#54)
Co-authored-by: Oliver King <oking3@uncc.edu>
This commit is contained in:
committed by
GitHub
parent
4a983766a0
commit
52d71d28bd
2
node_modules/ts-jest/dist/legacy/compiler/compiler-utils.d.ts
generated
vendored
Normal file
2
node_modules/ts-jest/dist/legacy/compiler/compiler-utils.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export declare const SOURCE_MAPPING_PREFIX = "sourceMappingURL=";
|
||||
export declare function updateOutput(outputText: string, normalizedFileName: string, sourceMap?: string): string;
|
22
node_modules/ts-jest/dist/legacy/compiler/compiler-utils.js
generated
vendored
Normal file
22
node_modules/ts-jest/dist/legacy/compiler/compiler-utils.js
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.updateOutput = exports.SOURCE_MAPPING_PREFIX = void 0;
|
||||
var utils_1 = require("../../utils");
|
||||
exports.SOURCE_MAPPING_PREFIX = 'sourceMappingURL=';
|
||||
function updateOutput(outputText, normalizedFileName, sourceMap) {
|
||||
if (sourceMap) {
|
||||
var base64Map = Buffer.from(updateSourceMap(sourceMap, normalizedFileName), 'utf8').toString('base64');
|
||||
var sourceMapContent = "data:application/json;charset=utf-8;base64,".concat(base64Map);
|
||||
return (outputText.slice(0, outputText.lastIndexOf(exports.SOURCE_MAPPING_PREFIX) + exports.SOURCE_MAPPING_PREFIX.length) +
|
||||
sourceMapContent);
|
||||
}
|
||||
return outputText;
|
||||
}
|
||||
exports.updateOutput = updateOutput;
|
||||
var updateSourceMap = function (sourceMapText, normalizedFileName) {
|
||||
var sourceMap = JSON.parse(sourceMapText);
|
||||
sourceMap.file = normalizedFileName;
|
||||
sourceMap.sources = [normalizedFileName];
|
||||
delete sourceMap.sourceRoot;
|
||||
return (0, utils_1.stringify)(sourceMap);
|
||||
};
|
2
node_modules/ts-jest/dist/legacy/compiler/index.d.ts
generated
vendored
Normal file
2
node_modules/ts-jest/dist/legacy/compiler/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './ts-compiler';
|
||||
export * from './ts-jest-compiler';
|
18
node_modules/ts-jest/dist/legacy/compiler/index.js
generated
vendored
Normal file
18
node_modules/ts-jest/dist/legacy/compiler/index.js
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__exportStar(require("./ts-compiler"), exports);
|
||||
__exportStar(require("./ts-jest-compiler"), exports);
|
21
node_modules/ts-jest/dist/legacy/compiler/ts-compiler.d.ts
generated
vendored
Normal file
21
node_modules/ts-jest/dist/legacy/compiler/ts-compiler.d.ts
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
import { Logger } from 'bs-logger';
|
||||
import type { CompilerOptions, CustomTransformers, Program, TranspileOutput } from 'typescript';
|
||||
import type { StringMap, TsCompilerInstance, TsJestAstTransformer, TsJestCompileOptions, TTypeScript } from '../../types';
|
||||
import { CompiledOutput } from '../../types';
|
||||
import type { ConfigSet } from '../config/config-set';
|
||||
export declare class TsCompiler implements TsCompilerInstance {
|
||||
readonly configSet: ConfigSet;
|
||||
readonly runtimeCacheFS: StringMap;
|
||||
protected readonly _logger: Logger;
|
||||
protected readonly _ts: TTypeScript;
|
||||
protected readonly _initialCompilerOptions: CompilerOptions;
|
||||
protected _compilerOptions: CompilerOptions;
|
||||
private _runtimeCacheFS;
|
||||
private _fileContentCache;
|
||||
program: Program | undefined;
|
||||
constructor(configSet: ConfigSet, runtimeCacheFS: StringMap);
|
||||
getResolvedModules(fileContent: string, fileName: string, runtimeCacheFS: StringMap): string[];
|
||||
getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): CompiledOutput;
|
||||
protected _transpileOutput(fileContent: string, fileName: string): TranspileOutput;
|
||||
protected _makeTransformers(customTransformers: TsJestAstTransformer): CustomTransformers;
|
||||
}
|
334
node_modules/ts-jest/dist/legacy/compiler/ts-compiler.js
generated
vendored
Normal file
334
node_modules/ts-jest/dist/legacy/compiler/ts-compiler.js
generated
vendored
Normal file
@ -0,0 +1,334 @@
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
var __read = (this && this.__read) || function (o, n) {
|
||||
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
||||
if (!m) return o;
|
||||
var i = m.call(o), r, ar = [], e;
|
||||
try {
|
||||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
||||
}
|
||||
catch (error) { e = { error: error }; }
|
||||
finally {
|
||||
try {
|
||||
if (r && !r.done && (m = i["return"])) m.call(i);
|
||||
}
|
||||
finally { if (e) throw e.error; }
|
||||
}
|
||||
return ar;
|
||||
};
|
||||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
||||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
||||
if (ar || !(i in from)) {
|
||||
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
||||
ar[i] = from[i];
|
||||
}
|
||||
}
|
||||
return to.concat(ar || Array.prototype.slice.call(from));
|
||||
};
|
||||
var __values = (this && this.__values) || function(o) {
|
||||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
||||
if (m) return m.call(o);
|
||||
if (o && typeof o.length === "number") return {
|
||||
next: function () {
|
||||
if (o && i >= o.length) o = void 0;
|
||||
return { value: o && o[i++], done: !o };
|
||||
}
|
||||
};
|
||||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TsCompiler = void 0;
|
||||
var path_1 = require("path");
|
||||
var bs_logger_1 = require("bs-logger");
|
||||
var lodash_memoize_1 = __importDefault(require("lodash.memoize"));
|
||||
var constants_1 = require("../../constants");
|
||||
var utils_1 = require("../../utils");
|
||||
var messages_1 = require("../../utils/messages");
|
||||
var compiler_utils_1 = require("./compiler-utils");
|
||||
var TsCompiler = (function () {
|
||||
function TsCompiler(configSet, runtimeCacheFS) {
|
||||
var _a;
|
||||
var _this = this;
|
||||
this.configSet = configSet;
|
||||
this.runtimeCacheFS = runtimeCacheFS;
|
||||
this._projectVersion = 1;
|
||||
this._ts = configSet.compilerModule;
|
||||
this._logger = utils_1.rootLogger.child({ namespace: 'ts-compiler' });
|
||||
this._parsedTsConfig = this.configSet.parsedTsConfig;
|
||||
this._initialCompilerOptions = __assign({}, this._parsedTsConfig.options);
|
||||
this._compilerOptions = __assign({}, this._initialCompilerOptions);
|
||||
this._runtimeCacheFS = runtimeCacheFS;
|
||||
if (!this.configSet.isolatedModules) {
|
||||
this._fileContentCache = new Map();
|
||||
this._fileVersionCache = new Map();
|
||||
this._cachedReadFile = this._logger.wrap((_a = {
|
||||
namespace: 'ts:serviceHost',
|
||||
call: null
|
||||
},
|
||||
_a[bs_logger_1.LogContexts.logLevel] = bs_logger_1.LogLevels.trace,
|
||||
_a), 'readFile', (0, lodash_memoize_1.default)(this._ts.sys.readFile));
|
||||
this._moduleResolutionHost = {
|
||||
fileExists: (0, lodash_memoize_1.default)(this._ts.sys.fileExists),
|
||||
readFile: this._cachedReadFile,
|
||||
directoryExists: (0, lodash_memoize_1.default)(this._ts.sys.directoryExists),
|
||||
getCurrentDirectory: function () { return _this.configSet.cwd; },
|
||||
realpath: this._ts.sys.realpath && (0, lodash_memoize_1.default)(this._ts.sys.realpath),
|
||||
getDirectories: (0, lodash_memoize_1.default)(this._ts.sys.getDirectories),
|
||||
};
|
||||
this._moduleResolutionCache = this._ts.createModuleResolutionCache(this.configSet.cwd, function (x) { return x; }, this._compilerOptions);
|
||||
this._createLanguageService();
|
||||
}
|
||||
}
|
||||
TsCompiler.prototype.getResolvedModules = function (fileContent, fileName, runtimeCacheFS) {
|
||||
var _this = this;
|
||||
if (!this.runtimeCacheFS.size) {
|
||||
this._runtimeCacheFS = runtimeCacheFS;
|
||||
}
|
||||
this._logger.debug({ fileName: fileName }, 'getResolvedModules(): resolve direct imported module paths');
|
||||
var importedModulePaths = Array.from(new Set(this._getImportedModulePaths(fileContent, fileName)));
|
||||
this._logger.debug({ fileName: fileName }, 'getResolvedModules(): resolve nested imported module paths from directed imported module paths');
|
||||
importedModulePaths.forEach(function (importedModulePath) {
|
||||
var resolvedFileContent = _this._getFileContentFromCache(importedModulePath);
|
||||
importedModulePaths.push.apply(importedModulePaths, __spreadArray([], __read(_this._getImportedModulePaths(resolvedFileContent, importedModulePath).filter(function (modulePath) { return !importedModulePaths.includes(modulePath); })), false));
|
||||
});
|
||||
return importedModulePaths;
|
||||
};
|
||||
TsCompiler.prototype.getCompiledOutput = function (fileContent, fileName, options) {
|
||||
var e_1, _a;
|
||||
var moduleKind = this._initialCompilerOptions.module;
|
||||
var esModuleInterop = this._initialCompilerOptions.esModuleInterop;
|
||||
var allowSyntheticDefaultImports = this._initialCompilerOptions.allowSyntheticDefaultImports;
|
||||
var currentModuleKind = this._compilerOptions.module;
|
||||
var isEsmMode = this.configSet.useESM && options.supportsStaticESM;
|
||||
if ((this.configSet.babelJestTransformer || (!this.configSet.babelJestTransformer && options.supportsStaticESM)) &&
|
||||
this.configSet.useESM) {
|
||||
moduleKind =
|
||||
!moduleKind ||
|
||||
(moduleKind &&
|
||||
![this._ts.ModuleKind.ES2015, this._ts.ModuleKind.ES2020, this._ts.ModuleKind.ESNext].includes(moduleKind))
|
||||
? this._ts.ModuleKind.ESNext
|
||||
: moduleKind;
|
||||
esModuleInterop = true;
|
||||
allowSyntheticDefaultImports = true;
|
||||
}
|
||||
else {
|
||||
moduleKind = this._ts.ModuleKind.CommonJS;
|
||||
}
|
||||
this._compilerOptions = __assign(__assign({}, this._compilerOptions), { allowSyntheticDefaultImports: allowSyntheticDefaultImports, esModuleInterop: esModuleInterop, module: moduleKind });
|
||||
if (this._languageService) {
|
||||
this._logger.debug({ fileName: fileName }, 'getCompiledOutput(): compiling using language service');
|
||||
this._updateMemoryCache(fileContent, fileName, currentModuleKind === moduleKind);
|
||||
var output = this._languageService.getEmitOutput(fileName);
|
||||
var diagnostics = this.getDiagnostics(fileName);
|
||||
if (!isEsmMode && diagnostics.length) {
|
||||
this.configSet.raiseDiagnostics(diagnostics, fileName, this._logger);
|
||||
if (options.watchMode) {
|
||||
this._logger.debug({ fileName: fileName }, '_doTypeChecking(): starting watch mode computing diagnostics');
|
||||
try {
|
||||
for (var _b = __values(options.depGraphs.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
||||
var entry = _c.value;
|
||||
var normalizedModuleNames = entry[1].resolvedModuleNames.map(function (moduleName) { return (0, path_1.normalize)(moduleName); });
|
||||
var fileToReTypeCheck = entry[0];
|
||||
if (normalizedModuleNames.includes(fileName) && this.configSet.shouldReportDiagnostics(fileToReTypeCheck)) {
|
||||
this._logger.debug({ fileToReTypeCheck: fileToReTypeCheck }, '_doTypeChecking(): computing diagnostics using language service');
|
||||
this._updateMemoryCache(this._getFileContentFromCache(fileToReTypeCheck), fileToReTypeCheck);
|
||||
var importedModulesDiagnostics = __spreadArray(__spreadArray([], __read(this._languageService.getSemanticDiagnostics(fileToReTypeCheck)), false), __read(this._languageService.getSyntacticDiagnostics(fileToReTypeCheck)), false);
|
||||
this.configSet.raiseDiagnostics(importedModulesDiagnostics, fileName, this._logger);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
||||
finally {
|
||||
try {
|
||||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
||||
}
|
||||
finally { if (e_1) throw e_1.error; }
|
||||
}
|
||||
}
|
||||
}
|
||||
if (output.emitSkipped) {
|
||||
if (constants_1.TS_TSX_REGEX.test(fileName)) {
|
||||
throw new Error((0, messages_1.interpolate)("Unable to process '{{file}}', please make sure that `outDir` in your tsconfig is neither `''` or `'.'`. You can also configure Jest config option `transformIgnorePatterns` to inform `ts-jest` to transform {{file}}", { file: fileName }));
|
||||
}
|
||||
else {
|
||||
this._logger.warn((0, messages_1.interpolate)("Unable to process '{{file}}', falling back to original file content. You can also configure Jest config option `transformIgnorePatterns` to ignore {{file}} from transformation or make sure that `outDir` in your tsconfig is neither `''` or `'.'`", { file: fileName }));
|
||||
return {
|
||||
code: fileContent,
|
||||
};
|
||||
}
|
||||
}
|
||||
if (!output.outputFiles.length) {
|
||||
throw new TypeError((0, messages_1.interpolate)("Unable to require `.d.ts` file for file: {{file}}.\nThis is usually the result of a faulty configuration or import. Make sure there is a `.js`, `.json` or another executable extension available alongside `{{file}}`.", {
|
||||
file: (0, path_1.basename)(fileName),
|
||||
}));
|
||||
}
|
||||
var outputFiles = output.outputFiles;
|
||||
return this._compilerOptions.sourceMap
|
||||
? {
|
||||
code: (0, compiler_utils_1.updateOutput)(outputFiles[1].text, fileName, outputFiles[0].text),
|
||||
diagnostics: diagnostics,
|
||||
}
|
||||
: {
|
||||
code: (0, compiler_utils_1.updateOutput)(outputFiles[0].text, fileName),
|
||||
diagnostics: diagnostics,
|
||||
};
|
||||
}
|
||||
else {
|
||||
this._logger.debug({ fileName: fileName }, 'getCompiledOutput(): compiling as isolated module');
|
||||
var result = this._transpileOutput(fileContent, fileName);
|
||||
if (result.diagnostics && this.configSet.shouldReportDiagnostics(fileName)) {
|
||||
this.configSet.raiseDiagnostics(result.diagnostics, fileName, this._logger);
|
||||
}
|
||||
return {
|
||||
code: (0, compiler_utils_1.updateOutput)(result.outputText, fileName, result.sourceMapText),
|
||||
};
|
||||
}
|
||||
};
|
||||
TsCompiler.prototype._transpileOutput = function (fileContent, fileName) {
|
||||
return this._ts.transpileModule(fileContent, {
|
||||
fileName: fileName,
|
||||
transformers: this._makeTransformers(this.configSet.resolvedTransformers),
|
||||
compilerOptions: this._compilerOptions,
|
||||
reportDiagnostics: this.configSet.shouldReportDiagnostics(fileName),
|
||||
});
|
||||
};
|
||||
TsCompiler.prototype._makeTransformers = function (customTransformers) {
|
||||
var _this = this;
|
||||
return {
|
||||
before: customTransformers.before.map(function (beforeTransformer) {
|
||||
return beforeTransformer.factory(_this, beforeTransformer.options);
|
||||
}),
|
||||
after: customTransformers.after.map(function (afterTransformer) {
|
||||
return afterTransformer.factory(_this, afterTransformer.options);
|
||||
}),
|
||||
afterDeclarations: customTransformers.afterDeclarations.map(function (afterDeclarations) {
|
||||
return afterDeclarations.factory(_this, afterDeclarations.options);
|
||||
}),
|
||||
};
|
||||
};
|
||||
TsCompiler.prototype._createLanguageService = function () {
|
||||
var _this = this;
|
||||
var _a;
|
||||
this._parsedTsConfig.fileNames
|
||||
.filter(function (fileName) { return constants_1.TS_TSX_REGEX.test(fileName) && !_this.configSet.isTestFile(fileName); })
|
||||
.forEach(function (fileName) { return _this._fileVersionCache.set(fileName, 0); });
|
||||
var serviceHost = {
|
||||
getProjectVersion: function () { return String(_this._projectVersion); },
|
||||
getScriptFileNames: function () { return __spreadArray([], __read(_this._fileVersionCache.keys()), false); },
|
||||
getScriptVersion: function (fileName) {
|
||||
var normalizedFileName = (0, path_1.normalize)(fileName);
|
||||
var version = _this._fileVersionCache.get(normalizedFileName);
|
||||
return version === undefined ? undefined : String(version);
|
||||
},
|
||||
getScriptSnapshot: function (fileName) {
|
||||
var _a, _b, _c, _d;
|
||||
var normalizedFileName = (0, path_1.normalize)(fileName);
|
||||
var hit = _this._isFileInCache(normalizedFileName);
|
||||
_this._logger.trace({ normalizedFileName: normalizedFileName, cacheHit: hit }, 'getScriptSnapshot():', 'cache', hit ? 'hit' : 'miss');
|
||||
if (!hit) {
|
||||
var fileContent = (_d = (_b = (_a = _this._fileContentCache.get(normalizedFileName)) !== null && _a !== void 0 ? _a : _this._runtimeCacheFS.get(normalizedFileName)) !== null && _b !== void 0 ? _b : (_c = _this._cachedReadFile) === null || _c === void 0 ? void 0 : _c.call(_this, normalizedFileName)) !== null && _d !== void 0 ? _d : undefined;
|
||||
if (fileContent !== undefined) {
|
||||
_this._fileContentCache.set(normalizedFileName, fileContent);
|
||||
_this._fileVersionCache.set(normalizedFileName, 1);
|
||||
}
|
||||
}
|
||||
var contents = _this._fileContentCache.get(normalizedFileName);
|
||||
if (contents === undefined)
|
||||
return;
|
||||
return _this._ts.ScriptSnapshot.fromString(contents);
|
||||
},
|
||||
fileExists: (0, lodash_memoize_1.default)(this._ts.sys.fileExists),
|
||||
readFile: (_a = this._cachedReadFile) !== null && _a !== void 0 ? _a : this._ts.sys.readFile,
|
||||
readDirectory: (0, lodash_memoize_1.default)(this._ts.sys.readDirectory),
|
||||
getDirectories: (0, lodash_memoize_1.default)(this._ts.sys.getDirectories),
|
||||
directoryExists: (0, lodash_memoize_1.default)(this._ts.sys.directoryExists),
|
||||
realpath: this._ts.sys.realpath && (0, lodash_memoize_1.default)(this._ts.sys.realpath),
|
||||
getNewLine: function () { return constants_1.LINE_FEED; },
|
||||
getCurrentDirectory: function () { return _this.configSet.cwd; },
|
||||
getCompilationSettings: function () { return _this._compilerOptions; },
|
||||
getDefaultLibFileName: function () { return _this._ts.getDefaultLibFilePath(_this._compilerOptions); },
|
||||
getCustomTransformers: function () { return _this._makeTransformers(_this.configSet.resolvedTransformers); },
|
||||
resolveModuleNames: function (moduleNames, containingFile) {
|
||||
return moduleNames.map(function (moduleName) { return _this._resolveModuleName(moduleName, containingFile).resolvedModule; });
|
||||
},
|
||||
};
|
||||
this._logger.debug('created language service');
|
||||
this._languageService = this._ts.createLanguageService(serviceHost, this._ts.createDocumentRegistry());
|
||||
this.program = this._languageService.getProgram();
|
||||
};
|
||||
TsCompiler.prototype._getFileContentFromCache = function (filePath) {
|
||||
var normalizedFilePath = (0, path_1.normalize)(filePath);
|
||||
var resolvedFileContent = this._runtimeCacheFS.get(normalizedFilePath);
|
||||
if (!resolvedFileContent) {
|
||||
resolvedFileContent = this._moduleResolutionHost.readFile(normalizedFilePath);
|
||||
this._runtimeCacheFS.set(normalizedFilePath, resolvedFileContent);
|
||||
}
|
||||
return resolvedFileContent;
|
||||
};
|
||||
TsCompiler.prototype._getImportedModulePaths = function (resolvedFileContent, containingFile) {
|
||||
var _this = this;
|
||||
return this._ts
|
||||
.preProcessFile(resolvedFileContent, true, true)
|
||||
.importedFiles.map(function (importedFile) {
|
||||
var resolvedModule = _this._resolveModuleName(importedFile.fileName, containingFile).resolvedModule;
|
||||
var resolvedFileName = resolvedModule === null || resolvedModule === void 0 ? void 0 : resolvedModule.resolvedFileName;
|
||||
return resolvedFileName && !(resolvedModule === null || resolvedModule === void 0 ? void 0 : resolvedModule.isExternalLibraryImport) ? resolvedFileName : '';
|
||||
})
|
||||
.filter(function (resolveFileName) { return !!resolveFileName; });
|
||||
};
|
||||
TsCompiler.prototype._resolveModuleName = function (moduleNameToResolve, containingFile) {
|
||||
return this._ts.resolveModuleName(moduleNameToResolve, containingFile, this._compilerOptions, this._moduleResolutionHost, this._moduleResolutionCache);
|
||||
};
|
||||
TsCompiler.prototype._isFileInCache = function (fileName) {
|
||||
return (this._fileContentCache.has(fileName) &&
|
||||
this._fileVersionCache.has(fileName) &&
|
||||
this._fileVersionCache.get(fileName) !== 0);
|
||||
};
|
||||
TsCompiler.prototype._updateMemoryCache = function (contents, fileName, isModuleKindTheSame) {
|
||||
if (isModuleKindTheSame === void 0) { isModuleKindTheSame = true; }
|
||||
this._logger.debug({ fileName: fileName }, 'updateMemoryCache: update memory cache for language service');
|
||||
var shouldIncrementProjectVersion = false;
|
||||
var hit = this._isFileInCache(fileName);
|
||||
if (!hit) {
|
||||
this._fileVersionCache.set(fileName, 1);
|
||||
shouldIncrementProjectVersion = true;
|
||||
}
|
||||
else {
|
||||
var prevVersion = this._fileVersionCache.get(fileName);
|
||||
var previousContents = this._fileContentCache.get(fileName);
|
||||
if (previousContents !== contents) {
|
||||
this._fileVersionCache.set(fileName, prevVersion + 1);
|
||||
this._fileContentCache.set(fileName, contents);
|
||||
shouldIncrementProjectVersion = true;
|
||||
}
|
||||
if (!this._parsedTsConfig.fileNames.includes(fileName) || !isModuleKindTheSame) {
|
||||
shouldIncrementProjectVersion = true;
|
||||
}
|
||||
}
|
||||
if (shouldIncrementProjectVersion)
|
||||
this._projectVersion++;
|
||||
};
|
||||
TsCompiler.prototype.getDiagnostics = function (fileName) {
|
||||
var diagnostics = [];
|
||||
if (this.configSet.shouldReportDiagnostics(fileName)) {
|
||||
this._logger.debug({ fileName: fileName }, '_doTypeChecking(): computing diagnostics using language service');
|
||||
diagnostics.push.apply(diagnostics, __spreadArray(__spreadArray([], __read(this._languageService.getSemanticDiagnostics(fileName)), false), __read(this._languageService.getSyntacticDiagnostics(fileName)), false));
|
||||
}
|
||||
return diagnostics;
|
||||
};
|
||||
return TsCompiler;
|
||||
}());
|
||||
exports.TsCompiler = TsCompiler;
|
8
node_modules/ts-jest/dist/legacy/compiler/ts-jest-compiler.d.ts
generated
vendored
Normal file
8
node_modules/ts-jest/dist/legacy/compiler/ts-jest-compiler.d.ts
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
import type { CompilerInstance, CompiledOutput, StringMap, TsJestCompileOptions } from '../../types';
|
||||
import type { ConfigSet } from '../config/config-set';
|
||||
export declare class TsJestCompiler implements CompilerInstance {
|
||||
private readonly _compilerInstance;
|
||||
constructor(configSet: ConfigSet, runtimeCacheFS: StringMap);
|
||||
getResolvedModules(fileContent: string, fileName: string, runtimeCacheFS: StringMap): string[];
|
||||
getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): CompiledOutput;
|
||||
}
|
17
node_modules/ts-jest/dist/legacy/compiler/ts-jest-compiler.js
generated
vendored
Normal file
17
node_modules/ts-jest/dist/legacy/compiler/ts-jest-compiler.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TsJestCompiler = void 0;
|
||||
var ts_compiler_1 = require("./ts-compiler");
|
||||
var TsJestCompiler = (function () {
|
||||
function TsJestCompiler(configSet, runtimeCacheFS) {
|
||||
this._compilerInstance = new ts_compiler_1.TsCompiler(configSet, runtimeCacheFS);
|
||||
}
|
||||
TsJestCompiler.prototype.getResolvedModules = function (fileContent, fileName, runtimeCacheFS) {
|
||||
return this._compilerInstance.getResolvedModules(fileContent, fileName, runtimeCacheFS);
|
||||
};
|
||||
TsJestCompiler.prototype.getCompiledOutput = function (fileContent, fileName, options) {
|
||||
return this._compilerInstance.getCompiledOutput(fileContent, fileName, options);
|
||||
};
|
||||
return TsJestCompiler;
|
||||
}());
|
||||
exports.TsJestCompiler = TsJestCompiler;
|
28
node_modules/ts-jest/dist/legacy/config/config-set.d.ts
generated
vendored
Normal file
28
node_modules/ts-jest/dist/legacy/config/config-set.d.ts
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
import { Logger } from 'bs-logger';
|
||||
import type * as ts from 'typescript';
|
||||
import type { RawCompilerOptions } from '../../raw-compiler-options';
|
||||
import type { ProjectConfigTsJest, TsJestAstTransformer, TTypeScript } from '../../types';
|
||||
export declare class ConfigSet {
|
||||
readonly parentLogger?: Logger | undefined;
|
||||
readonly tsJestDigest: string;
|
||||
readonly logger: Logger;
|
||||
readonly compilerModule: TTypeScript;
|
||||
readonly isolatedModules: boolean;
|
||||
readonly cwd: string;
|
||||
readonly rootDir: string;
|
||||
cacheSuffix: string;
|
||||
tsCacheDir: string | undefined;
|
||||
parsedTsConfig: ts.ParsedCommandLine | Record<string, any>;
|
||||
resolvedTransformers: TsJestAstTransformer;
|
||||
useESM: boolean;
|
||||
constructor(jestConfig: ProjectConfigTsJest | undefined, parentLogger?: Logger | undefined);
|
||||
protected _resolveTsConfig(compilerOptions?: RawCompilerOptions, resolvedConfigFile?: string): Record<string, any>;
|
||||
isTestFile(fileName: string): boolean;
|
||||
shouldStringifyContent(filePath: string): boolean;
|
||||
raiseDiagnostics(diagnostics: ts.Diagnostic[], filePath?: string, logger?: Logger): void;
|
||||
shouldReportDiagnostics(filePath: string): boolean;
|
||||
resolvePath(inputPath: string, { throwIfMissing, nodeResolve }?: {
|
||||
throwIfMissing?: boolean;
|
||||
nodeResolve?: boolean;
|
||||
}): string;
|
||||
}
|
521
node_modules/ts-jest/dist/legacy/config/config-set.js
generated
vendored
Normal file
521
node_modules/ts-jest/dist/legacy/config/config-set.js
generated
vendored
Normal file
@ -0,0 +1,521 @@
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __values = (this && this.__values) || function(o) {
|
||||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
||||
if (m) return m.call(o);
|
||||
if (o && typeof o.length === "number") return {
|
||||
next: function () {
|
||||
if (o && i >= o.length) o = void 0;
|
||||
return { value: o && o[i++], done: !o };
|
||||
}
|
||||
};
|
||||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
||||
};
|
||||
var __read = (this && this.__read) || function (o, n) {
|
||||
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
||||
if (!m) return o;
|
||||
var i = m.call(o), r, ar = [], e;
|
||||
try {
|
||||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
||||
}
|
||||
catch (error) { e = { error: error }; }
|
||||
finally {
|
||||
try {
|
||||
if (r && !r.done && (m = i["return"])) m.call(i);
|
||||
}
|
||||
finally { if (e) throw e.error; }
|
||||
}
|
||||
return ar;
|
||||
};
|
||||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
||||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
||||
if (ar || !(i in from)) {
|
||||
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
||||
ar[i] = from[i];
|
||||
}
|
||||
}
|
||||
return to.concat(ar || Array.prototype.slice.call(from));
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ConfigSet = exports.TS_JEST_OUT_DIR = exports.IGNORE_DIAGNOSTIC_CODES = exports.MY_DIGEST = void 0;
|
||||
var fs_1 = require("fs");
|
||||
var module_1 = __importDefault(require("module"));
|
||||
var path_1 = require("path");
|
||||
var bs_logger_1 = require("bs-logger");
|
||||
var jest_util_1 = require("jest-util");
|
||||
var json5_1 = __importDefault(require("json5"));
|
||||
var constants_1 = require("../../constants");
|
||||
var hoistJestTransformer = __importStar(require("../../transformers/hoist-jest"));
|
||||
var utils_1 = require("../../utils");
|
||||
var backports_1 = require("../../utils/backports");
|
||||
var importer_1 = require("../../utils/importer");
|
||||
var messages_1 = require("../../utils/messages");
|
||||
var normalize_slashes_1 = require("../../utils/normalize-slashes");
|
||||
var sha1_1 = require("../../utils/sha1");
|
||||
var ts_error_1 = require("../../utils/ts-error");
|
||||
exports.MY_DIGEST = (0, fs_1.readFileSync)((0, path_1.resolve)(__dirname, '../../../.ts-jest-digest'), 'utf8');
|
||||
exports.IGNORE_DIAGNOSTIC_CODES = [
|
||||
6059,
|
||||
18002,
|
||||
18003,
|
||||
];
|
||||
exports.TS_JEST_OUT_DIR = '$$ts-jest$$';
|
||||
var normalizeRegex = function (pattern) {
|
||||
return pattern ? (typeof pattern === 'string' ? pattern : pattern.source) : undefined;
|
||||
};
|
||||
var toDiagnosticCode = function (code) { var _a; return code ? (_a = parseInt("".concat(code).trim().replace(/^TS/, ''), 10)) !== null && _a !== void 0 ? _a : undefined : undefined; };
|
||||
var toDiagnosticCodeList = function (items, into) {
|
||||
var e_1, _a;
|
||||
if (into === void 0) { into = []; }
|
||||
try {
|
||||
for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
|
||||
var item = items_1_1.value;
|
||||
if (typeof item === 'string') {
|
||||
var children = item.trim().split(/\s*,\s*/g);
|
||||
if (children.length > 1) {
|
||||
toDiagnosticCodeList(children, into);
|
||||
continue;
|
||||
}
|
||||
item = children[0];
|
||||
}
|
||||
if (!item)
|
||||
continue;
|
||||
var code = toDiagnosticCode(item);
|
||||
if (code && !into.includes(code))
|
||||
into.push(code);
|
||||
}
|
||||
}
|
||||
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
||||
finally {
|
||||
try {
|
||||
if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
|
||||
}
|
||||
finally { if (e_1) throw e_1.error; }
|
||||
}
|
||||
return into;
|
||||
};
|
||||
var requireFromString = function (code, fileName) {
|
||||
var paths = module_1.default._nodeModulePaths((0, path_1.dirname)(fileName));
|
||||
var parent = module.parent;
|
||||
var m = new module_1.default(fileName, parent);
|
||||
m.filename = fileName;
|
||||
m.paths = [].concat(paths);
|
||||
m._compile(code, fileName);
|
||||
var exports = m.exports;
|
||||
parent && parent.children && parent.children.splice(parent.children.indexOf(m), 1);
|
||||
return exports;
|
||||
};
|
||||
var ConfigSet = (function () {
|
||||
function ConfigSet(jestConfig, parentLogger) {
|
||||
var _a, _b;
|
||||
var _c, _d, _e, _f;
|
||||
this.parentLogger = parentLogger;
|
||||
this.tsJestDigest = exports.MY_DIGEST;
|
||||
this.resolvedTransformers = {
|
||||
before: [],
|
||||
after: [],
|
||||
afterDeclarations: [],
|
||||
};
|
||||
this.useESM = false;
|
||||
this._overriddenCompilerOptions = {
|
||||
inlineSourceMap: false,
|
||||
declaration: false,
|
||||
noEmit: false,
|
||||
removeComments: false,
|
||||
out: undefined,
|
||||
outFile: undefined,
|
||||
composite: undefined,
|
||||
declarationDir: undefined,
|
||||
declarationMap: undefined,
|
||||
emitDeclarationOnly: undefined,
|
||||
sourceRoot: undefined,
|
||||
tsBuildInfoFile: undefined,
|
||||
};
|
||||
this.logger = this.parentLogger
|
||||
? this.parentLogger.child((_a = {}, _a[bs_logger_1.LogContexts.namespace] = 'config', _a))
|
||||
: utils_1.rootLogger.child({ namespace: 'config' });
|
||||
this._backportJestCfg(jestConfig !== null && jestConfig !== void 0 ? jestConfig : Object.create(null));
|
||||
this.cwd = (0, path_1.normalize)((_c = this._jestCfg.cwd) !== null && _c !== void 0 ? _c : process.cwd());
|
||||
this.rootDir = (0, path_1.normalize)((_d = this._jestCfg.rootDir) !== null && _d !== void 0 ? _d : this.cwd);
|
||||
var tsJestCfg = this._jestCfg.globals && this._jestCfg.globals['ts-jest'];
|
||||
var options = tsJestCfg !== null && tsJestCfg !== void 0 ? tsJestCfg : Object.create(null);
|
||||
this.compilerModule = importer_1.importer.typescript("Using \"ts-jest\" requires this package to be installed.", (_e = options.compiler) !== null && _e !== void 0 ? _e : 'typescript');
|
||||
this.isolatedModules = (_f = options.isolatedModules) !== null && _f !== void 0 ? _f : false;
|
||||
this.logger.debug({ compilerModule: this.compilerModule }, 'normalized compiler module config via ts-jest option');
|
||||
this._setupConfigSet(options);
|
||||
this._resolveTsCacheDir();
|
||||
this._matchablePatterns = __spreadArray(__spreadArray([], __read(this._jestCfg.testMatch), false), __read(this._jestCfg.testRegex), false).filter(function (pattern) {
|
||||
return pattern instanceof RegExp || typeof pattern === 'string';
|
||||
});
|
||||
if (!this._matchablePatterns.length) {
|
||||
(_b = this._matchablePatterns).push.apply(_b, __spreadArray([], __read(constants_1.DEFAULT_JEST_TEST_MATCH), false));
|
||||
}
|
||||
this._matchTestFilePath = (0, jest_util_1.globsToMatcher)(this._matchablePatterns.filter(function (pattern) { return typeof pattern === 'string'; }));
|
||||
}
|
||||
ConfigSet.prototype._backportJestCfg = function (jestCfg) {
|
||||
var _a, _b;
|
||||
var config = (0, backports_1.backportJestConfig)(this.logger, jestCfg);
|
||||
this.logger.debug({ jestConfig: config }, 'normalized jest config');
|
||||
this._jestCfg = __assign(__assign({}, config), { testMatch: (_a = config.testMatch) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_JEST_TEST_MATCH, testRegex: (_b = config.testRegex) !== null && _b !== void 0 ? _b : [] });
|
||||
};
|
||||
ConfigSet.prototype._setupConfigSet = function (options) {
|
||||
var _this = this;
|
||||
var _a, _b, _c, _d, _e;
|
||||
this.useESM = (_a = options.useESM) !== null && _a !== void 0 ? _a : false;
|
||||
if (!options.babelConfig) {
|
||||
this.logger.debug('babel is disabled');
|
||||
}
|
||||
else {
|
||||
var baseBabelCfg = { cwd: this.cwd };
|
||||
if (typeof options.babelConfig === 'string') {
|
||||
var babelCfgPath = this.resolvePath(options.babelConfig);
|
||||
var babelFileExtName = (0, path_1.extname)(options.babelConfig);
|
||||
if (babelFileExtName === '.js' || babelFileExtName === '.cjs') {
|
||||
this.babelConfig = __assign(__assign({}, baseBabelCfg), require(babelCfgPath));
|
||||
}
|
||||
else {
|
||||
this.babelConfig = __assign(__assign({}, baseBabelCfg), json5_1.default.parse((0, fs_1.readFileSync)(babelCfgPath, 'utf-8')));
|
||||
}
|
||||
}
|
||||
else if (typeof options.babelConfig === 'object') {
|
||||
this.babelConfig = __assign(__assign({}, baseBabelCfg), options.babelConfig);
|
||||
}
|
||||
else {
|
||||
this.babelConfig = baseBabelCfg;
|
||||
}
|
||||
this.logger.debug({ babelConfig: this.babelConfig }, 'normalized babel config via ts-jest option');
|
||||
this.babelJestTransformer = importer_1.importer
|
||||
.babelJest("Using \"babel-jest\" requires this package to be installed.")
|
||||
.createTransformer(this.babelConfig);
|
||||
this.logger.debug('created babel-jest transformer');
|
||||
}
|
||||
var diagnosticsOpt = (_b = options.diagnostics) !== null && _b !== void 0 ? _b : true;
|
||||
var ignoreList = __spreadArray([], __read(exports.IGNORE_DIAGNOSTIC_CODES), false);
|
||||
if (typeof diagnosticsOpt === 'object') {
|
||||
var ignoreCodes = diagnosticsOpt.ignoreCodes;
|
||||
if (ignoreCodes) {
|
||||
Array.isArray(ignoreCodes) ? ignoreList.push.apply(ignoreList, __spreadArray([], __read(ignoreCodes), false)) : ignoreList.push(ignoreCodes);
|
||||
}
|
||||
this._diagnostics = {
|
||||
pretty: (_c = diagnosticsOpt.pretty) !== null && _c !== void 0 ? _c : true,
|
||||
exclude: (_d = diagnosticsOpt.exclude) !== null && _d !== void 0 ? _d : [],
|
||||
ignoreCodes: toDiagnosticCodeList(ignoreList),
|
||||
throws: !diagnosticsOpt.warnOnly,
|
||||
};
|
||||
}
|
||||
else {
|
||||
this._diagnostics = {
|
||||
ignoreCodes: diagnosticsOpt ? toDiagnosticCodeList(ignoreList) : [],
|
||||
exclude: [],
|
||||
pretty: true,
|
||||
throws: diagnosticsOpt,
|
||||
};
|
||||
}
|
||||
this._shouldIgnoreDiagnosticsForFile = this._diagnostics.exclude.length
|
||||
? (0, jest_util_1.globsToMatcher)(this._diagnostics.exclude)
|
||||
: function () { return false; };
|
||||
this.logger.debug({ diagnostics: this._diagnostics }, 'normalized diagnostics config via ts-jest option');
|
||||
var tsconfigOpt = options.tsconfig;
|
||||
var configFilePath = typeof tsconfigOpt === 'string' ? this.resolvePath(tsconfigOpt) : undefined;
|
||||
this.parsedTsConfig = this._getAndResolveTsConfig(typeof tsconfigOpt === 'object' ? tsconfigOpt : undefined, configFilePath);
|
||||
this.raiseDiagnostics(this.parsedTsConfig.errors, configFilePath);
|
||||
this.logger.debug({ tsconfig: this.parsedTsConfig }, 'normalized typescript config via ts-jest option');
|
||||
this.resolvedTransformers.before = [
|
||||
{
|
||||
factory: hoistJestTransformer.factory,
|
||||
name: hoistJestTransformer.name,
|
||||
version: hoistJestTransformer.version,
|
||||
},
|
||||
];
|
||||
var astTransformers = options.astTransformers;
|
||||
if (astTransformers) {
|
||||
var resolveTransformerFunc_1 = function (transformerPath) {
|
||||
var transformerFunc;
|
||||
if ((0, path_1.extname)(transformerPath) === '.ts') {
|
||||
var compiledTransformer = importer_1.importer
|
||||
.esBuild("Using \"esbuild\" requires this package to be installed.")
|
||||
.transformSync((0, fs_1.readFileSync)(transformerPath, 'utf-8'), {
|
||||
loader: 'ts',
|
||||
format: 'cjs',
|
||||
target: 'es2015',
|
||||
}).code;
|
||||
transformerFunc = requireFromString(compiledTransformer, transformerPath.replace('.ts', '.js'));
|
||||
}
|
||||
else {
|
||||
transformerFunc = require(transformerPath);
|
||||
}
|
||||
if (!transformerFunc.version) {
|
||||
_this.logger.warn("The AST transformer {{file}} must have an `export const version = <your_transformer_version>`", { file: transformerPath });
|
||||
}
|
||||
if (!transformerFunc.name) {
|
||||
_this.logger.warn("The AST transformer {{file}} must have an `export const name = <your_transformer_name>`", { file: transformerPath });
|
||||
}
|
||||
return transformerFunc;
|
||||
};
|
||||
var resolveTransformers = function (transformers) {
|
||||
return transformers.map(function (transformer) {
|
||||
if (typeof transformer === 'string') {
|
||||
return resolveTransformerFunc_1(_this.resolvePath(transformer, { nodeResolve: true }));
|
||||
}
|
||||
else {
|
||||
return __assign(__assign({}, resolveTransformerFunc_1(_this.resolvePath(transformer.path, { nodeResolve: true }))), { options: transformer.options });
|
||||
}
|
||||
});
|
||||
};
|
||||
if (astTransformers.before) {
|
||||
(_e = this.resolvedTransformers.before) === null || _e === void 0 ? void 0 : _e.push.apply(_e, __spreadArray([], __read(resolveTransformers(astTransformers.before)), false));
|
||||
}
|
||||
if (astTransformers.after) {
|
||||
this.resolvedTransformers = __assign(__assign({}, this.resolvedTransformers), { after: resolveTransformers(astTransformers.after) });
|
||||
}
|
||||
if (astTransformers.afterDeclarations) {
|
||||
this.resolvedTransformers = __assign(__assign({}, this.resolvedTransformers), { afterDeclarations: resolveTransformers(astTransformers.afterDeclarations) });
|
||||
}
|
||||
}
|
||||
this.logger.debug({ customTransformers: this.resolvedTransformers }, 'normalized custom AST transformers via ts-jest option');
|
||||
if (options.stringifyContentPathRegex) {
|
||||
this._stringifyContentRegExp =
|
||||
typeof options.stringifyContentPathRegex === 'string'
|
||||
? new RegExp(normalizeRegex(options.stringifyContentPathRegex))
|
||||
: options.stringifyContentPathRegex;
|
||||
this.logger.debug({ stringifyContentPathRegex: this._stringifyContentRegExp }, 'normalized stringifyContentPathRegex config via ts-jest option');
|
||||
}
|
||||
};
|
||||
ConfigSet.prototype._resolveTsCacheDir = function () {
|
||||
this.cacheSuffix = (0, sha1_1.sha1)((0, utils_1.stringify)({
|
||||
version: this.compilerModule.version,
|
||||
digest: this.tsJestDigest,
|
||||
babelConfig: this.babelConfig,
|
||||
tsconfig: {
|
||||
options: this.parsedTsConfig.options,
|
||||
raw: this.parsedTsConfig.raw,
|
||||
},
|
||||
isolatedModules: this.isolatedModules,
|
||||
diagnostics: this._diagnostics,
|
||||
transformers: Object.values(this.resolvedTransformers)
|
||||
.reduce(function (prevVal, currentVal) { return __spreadArray(__spreadArray([], __read(prevVal), false), [currentVal], false); })
|
||||
.map(function (transformer) { return "".concat(transformer.name, "-").concat(transformer.version); }),
|
||||
}));
|
||||
if (!this._jestCfg.cache) {
|
||||
this.logger.debug('file caching disabled');
|
||||
}
|
||||
else {
|
||||
var res = (0, path_1.join)(this._jestCfg.cacheDirectory, 'ts-jest', this.cacheSuffix.substr(0, 2), this.cacheSuffix.substr(2));
|
||||
this.logger.debug({ cacheDirectory: res }, 'will use file caching');
|
||||
this.tsCacheDir = res;
|
||||
}
|
||||
};
|
||||
ConfigSet.prototype._getAndResolveTsConfig = function (compilerOptions, resolvedConfigFile) {
|
||||
var e_2, _a, _b;
|
||||
var _c, _d, _e;
|
||||
var result = this._resolveTsConfig(compilerOptions, resolvedConfigFile);
|
||||
var forcedOptions = this._overriddenCompilerOptions;
|
||||
var finalOptions = result.options;
|
||||
if (finalOptions.target === undefined) {
|
||||
finalOptions.target = this.compilerModule.ScriptTarget.ES2015;
|
||||
}
|
||||
var target = finalOptions.target;
|
||||
var defaultModule = [this.compilerModule.ScriptTarget.ES3, this.compilerModule.ScriptTarget.ES5].includes(target)
|
||||
? this.compilerModule.ModuleKind.CommonJS
|
||||
: this.compilerModule.ModuleKind.ESNext;
|
||||
var moduleValue = (_c = finalOptions.module) !== null && _c !== void 0 ? _c : defaultModule;
|
||||
if (!this.babelConfig &&
|
||||
moduleValue !== this.compilerModule.ModuleKind.CommonJS &&
|
||||
!(finalOptions.esModuleInterop || finalOptions.allowSyntheticDefaultImports)) {
|
||||
result.errors.push({
|
||||
code: 151001,
|
||||
messageText: "If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information.",
|
||||
category: this.compilerModule.DiagnosticCategory.Message,
|
||||
file: undefined,
|
||||
start: undefined,
|
||||
length: undefined,
|
||||
});
|
||||
if (!('allowSyntheticDefaultImports' in finalOptions)) {
|
||||
finalOptions.allowSyntheticDefaultImports = true;
|
||||
}
|
||||
}
|
||||
if (finalOptions.allowJs && !finalOptions.outDir) {
|
||||
finalOptions.outDir = exports.TS_JEST_OUT_DIR;
|
||||
}
|
||||
try {
|
||||
for (var _f = __values(Object.keys(forcedOptions)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
||||
var key = _g.value;
|
||||
var val = forcedOptions[key];
|
||||
if (val === undefined) {
|
||||
delete finalOptions[key];
|
||||
}
|
||||
else {
|
||||
finalOptions[key] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
||||
finally {
|
||||
try {
|
||||
if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
|
||||
}
|
||||
finally { if (e_2) throw e_2.error; }
|
||||
}
|
||||
var nodeJsVer = process.version;
|
||||
var compilationTarget = result.options.target;
|
||||
var TARGET_TO_VERSION_MAPPING = (_b = {},
|
||||
_b[this.compilerModule.ScriptTarget.ES2018] = 'es2018',
|
||||
_b[this.compilerModule.ScriptTarget.ES2019] = 'es2019',
|
||||
_b[this.compilerModule.ScriptTarget.ES2020] = 'es2020',
|
||||
_b[this.compilerModule.ScriptTarget.ESNext] = 'ESNext',
|
||||
_b);
|
||||
if (compilationTarget &&
|
||||
!this.babelConfig &&
|
||||
nodeJsVer.startsWith('v12') &&
|
||||
compilationTarget > this.compilerModule.ScriptTarget.ES2019) {
|
||||
var message = (0, messages_1.interpolate)("There is a mismatch between your NodeJs version {{nodeJsVer}} and your TypeScript target {{compilationTarget}}. This might lead to some unexpected errors when running tests with `ts-jest`. To fix this, you can check https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping", {
|
||||
nodeJsVer: process.version,
|
||||
compilationTarget: TARGET_TO_VERSION_MAPPING[compilationTarget],
|
||||
});
|
||||
this.logger.warn(message);
|
||||
}
|
||||
var resultOptions = result.options;
|
||||
var sourceMap = (_d = resultOptions.sourceMap) !== null && _d !== void 0 ? _d : true;
|
||||
return __assign(__assign({}, result), { options: __assign(__assign({}, resultOptions), { sourceMap: sourceMap, inlineSources: sourceMap, module: (_e = resultOptions.module) !== null && _e !== void 0 ? _e : this.compilerModule.ModuleKind.CommonJS }) });
|
||||
};
|
||||
ConfigSet.prototype._resolveTsConfig = function (compilerOptions, resolvedConfigFile) {
|
||||
var config = { compilerOptions: Object.create(null) };
|
||||
var basePath = (0, normalize_slashes_1.normalizeSlashes)(this.rootDir);
|
||||
var ts = this.compilerModule;
|
||||
var configFileName = resolvedConfigFile
|
||||
? (0, normalize_slashes_1.normalizeSlashes)(resolvedConfigFile)
|
||||
: ts.findConfigFile((0, normalize_slashes_1.normalizeSlashes)(this.rootDir), ts.sys.fileExists);
|
||||
if (configFileName) {
|
||||
this.logger.debug({ tsConfigFileName: configFileName }, 'readTsConfig(): reading', configFileName);
|
||||
var result = ts.readConfigFile(configFileName, ts.sys.readFile);
|
||||
if (result.error) {
|
||||
return { errors: [result.error], fileNames: [], options: {} };
|
||||
}
|
||||
config = result.config;
|
||||
basePath = (0, normalize_slashes_1.normalizeSlashes)((0, path_1.dirname)(configFileName));
|
||||
}
|
||||
config.compilerOptions = __assign(__assign({}, config.compilerOptions), compilerOptions);
|
||||
return ts.parseJsonConfigFileContent(config, ts.sys, basePath, undefined, configFileName);
|
||||
};
|
||||
ConfigSet.prototype.isTestFile = function (fileName) {
|
||||
var _this = this;
|
||||
return this._matchablePatterns.some(function (pattern) {
|
||||
return typeof pattern === 'string' ? _this._matchTestFilePath(fileName) : pattern.test(fileName);
|
||||
});
|
||||
};
|
||||
ConfigSet.prototype.shouldStringifyContent = function (filePath) {
|
||||
return this._stringifyContentRegExp ? this._stringifyContentRegExp.test(filePath) : false;
|
||||
};
|
||||
ConfigSet.prototype.raiseDiagnostics = function (diagnostics, filePath, logger) {
|
||||
var _this = this;
|
||||
var ignoreCodes = this._diagnostics.ignoreCodes;
|
||||
var DiagnosticCategory = this.compilerModule.DiagnosticCategory;
|
||||
var filteredDiagnostics = filePath && !this.shouldReportDiagnostics(filePath)
|
||||
? []
|
||||
: diagnostics.filter(function (diagnostic) {
|
||||
var _a;
|
||||
if (((_a = diagnostic.file) === null || _a === void 0 ? void 0 : _a.fileName) && !_this.shouldReportDiagnostics(diagnostic.file.fileName)) {
|
||||
return false;
|
||||
}
|
||||
return !ignoreCodes.includes(diagnostic.code);
|
||||
});
|
||||
if (!filteredDiagnostics.length)
|
||||
return;
|
||||
var error = this.createTsError(filteredDiagnostics);
|
||||
var importantCategories = [DiagnosticCategory.Warning, DiagnosticCategory.Error];
|
||||
if (this._diagnostics.throws && filteredDiagnostics.some(function (d) { return importantCategories.includes(d.category); })) {
|
||||
throw error;
|
||||
}
|
||||
logger ? logger.warn({ error: error }, error.message) : this.logger.warn({ error: error }, error.message);
|
||||
};
|
||||
ConfigSet.prototype.shouldReportDiagnostics = function (filePath) {
|
||||
var fileExtension = (0, path_1.extname)(filePath);
|
||||
return constants_1.JS_JSX_EXTENSIONS.includes(fileExtension)
|
||||
? this.parsedTsConfig.options.checkJs && !this._shouldIgnoreDiagnosticsForFile(filePath)
|
||||
: !this._shouldIgnoreDiagnosticsForFile(filePath);
|
||||
};
|
||||
ConfigSet.prototype.createTsError = function (diagnostics) {
|
||||
var _this = this;
|
||||
var formatDiagnostics = this._diagnostics.pretty
|
||||
? this.compilerModule.formatDiagnosticsWithColorAndContext
|
||||
: this.compilerModule.formatDiagnostics;
|
||||
var diagnosticHost = {
|
||||
getNewLine: function () { return '\n'; },
|
||||
getCurrentDirectory: function () { return _this.cwd; },
|
||||
getCanonicalFileName: function (path) { return path; },
|
||||
};
|
||||
var diagnosticText = formatDiagnostics(diagnostics, diagnosticHost);
|
||||
var diagnosticCodes = diagnostics.map(function (x) { return x.code; });
|
||||
return new ts_error_1.TSError(diagnosticText, diagnosticCodes);
|
||||
};
|
||||
ConfigSet.prototype.resolvePath = function (inputPath, _a) {
|
||||
var _b = _a === void 0 ? {} : _a, _c = _b.throwIfMissing, throwIfMissing = _c === void 0 ? true : _c, _d = _b.nodeResolve, nodeResolve = _d === void 0 ? false : _d;
|
||||
var path = inputPath;
|
||||
var nodeResolved = false;
|
||||
if (path.startsWith('<rootDir>')) {
|
||||
path = (0, path_1.resolve)((0, path_1.join)(this.rootDir, path.substr(9)));
|
||||
}
|
||||
else if (!(0, path_1.isAbsolute)(path)) {
|
||||
if (!path.startsWith('.') && nodeResolve) {
|
||||
try {
|
||||
path = require.resolve(path);
|
||||
nodeResolved = true;
|
||||
}
|
||||
catch (_) { }
|
||||
}
|
||||
if (!nodeResolved) {
|
||||
path = (0, path_1.resolve)(this.cwd, path);
|
||||
}
|
||||
}
|
||||
if (!nodeResolved && nodeResolve) {
|
||||
try {
|
||||
path = require.resolve(path);
|
||||
nodeResolved = true;
|
||||
}
|
||||
catch (_) { }
|
||||
}
|
||||
if (throwIfMissing && !(0, fs_1.existsSync)(path)) {
|
||||
throw new Error((0, messages_1.interpolate)("File not found: {{inputPath}} (resolved as: {{resolvedPath}})", { inputPath: inputPath, resolvedPath: path }));
|
||||
}
|
||||
this.logger.debug({ fromPath: inputPath, toPath: path }, 'resolved path from', inputPath, 'to', path);
|
||||
return path;
|
||||
};
|
||||
return ConfigSet;
|
||||
}());
|
||||
exports.ConfigSet = ConfigSet;
|
5
node_modules/ts-jest/dist/legacy/index.d.ts
generated
vendored
Normal file
5
node_modules/ts-jest/dist/legacy/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
import { TsJestTransformer } from './ts-jest-transformer';
|
||||
declare const _default: {
|
||||
createTransformer: () => TsJestTransformer;
|
||||
};
|
||||
export default _default;
|
6
node_modules/ts-jest/dist/legacy/index.js
generated
vendored
Normal file
6
node_modules/ts-jest/dist/legacy/index.js
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var ts_jest_transformer_1 = require("./ts-jest-transformer");
|
||||
exports.default = {
|
||||
createTransformer: function () { return new ts_jest_transformer_1.TsJestTransformer(); },
|
||||
};
|
22
node_modules/ts-jest/dist/legacy/ts-jest-transformer.d.ts
generated
vendored
Normal file
22
node_modules/ts-jest/dist/legacy/ts-jest-transformer.d.ts
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
import type { SyncTransformer, TransformedSource } from '@jest/transform';
|
||||
import type { CompilerInstance, ProjectConfigTsJest, TransformOptionsTsJest } from '../types';
|
||||
import { ConfigSet } from './config/config-set';
|
||||
export declare class TsJestTransformer implements SyncTransformer {
|
||||
private readonly _logger;
|
||||
protected _compiler: CompilerInstance;
|
||||
private _tsResolvedModulesCachePath;
|
||||
private _transformCfgStr;
|
||||
private _depGraphs;
|
||||
private _watchMode;
|
||||
constructor();
|
||||
private _configsFor;
|
||||
protected _createConfigSet(config: ProjectConfigTsJest | undefined): ConfigSet;
|
||||
protected _createCompiler(configSet: ConfigSet, cacheFS: Map<string, string>): void;
|
||||
process(sourceText: string, sourcePath: string, transformOptions: TransformOptionsTsJest): TransformedSource;
|
||||
processAsync(sourceText: string, sourcePath: string, transformOptions: TransformOptionsTsJest): Promise<TransformedSource>;
|
||||
private processWithTs;
|
||||
private runTsJestHook;
|
||||
getCacheKey(fileContent: string, filePath: string, transformOptions: TransformOptionsTsJest): string;
|
||||
getCacheKeyAsync(sourceText: string, sourcePath: string, transformOptions: TransformOptionsTsJest): Promise<string>;
|
||||
private _getFsCachedResolvedModules;
|
||||
}
|
324
node_modules/ts-jest/dist/legacy/ts-jest-transformer.js
generated
vendored
Normal file
324
node_modules/ts-jest/dist/legacy/ts-jest-transformer.js
generated
vendored
Normal file
@ -0,0 +1,324 @@
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var __read = (this && this.__read) || function (o, n) {
|
||||
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
||||
if (!m) return o;
|
||||
var i = m.call(o), r, ar = [], e;
|
||||
try {
|
||||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
||||
}
|
||||
catch (error) { e = { error: error }; }
|
||||
finally {
|
||||
try {
|
||||
if (r && !r.done && (m = i["return"])) m.call(i);
|
||||
}
|
||||
finally { if (e) throw e.error; }
|
||||
}
|
||||
return ar;
|
||||
};
|
||||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
||||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
||||
if (ar || !(i in from)) {
|
||||
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
||||
ar[i] = from[i];
|
||||
}
|
||||
}
|
||||
return to.concat(ar || Array.prototype.slice.call(from));
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TsJestTransformer = exports.CACHE_KEY_EL_SEPARATOR = void 0;
|
||||
var fs_1 = require("fs");
|
||||
var path_1 = __importDefault(require("path"));
|
||||
var constants_1 = require("../constants");
|
||||
var utils_1 = require("../utils");
|
||||
var importer_1 = require("../utils/importer");
|
||||
var messages_1 = require("../utils/messages");
|
||||
var sha1_1 = require("../utils/sha1");
|
||||
var version_checkers_1 = require("../utils/version-checkers");
|
||||
var compiler_1 = require("./compiler");
|
||||
var config_set_1 = require("./config/config-set");
|
||||
exports.CACHE_KEY_EL_SEPARATOR = '\x00';
|
||||
var TsJestTransformer = (function () {
|
||||
function TsJestTransformer() {
|
||||
this._depGraphs = new Map();
|
||||
this._watchMode = false;
|
||||
this._logger = utils_1.rootLogger.child({ namespace: 'ts-jest-transformer' });
|
||||
version_checkers_1.VersionCheckers.jest.warn();
|
||||
this.getCacheKey = this.getCacheKey.bind(this);
|
||||
this.getCacheKeyAsync = this.getCacheKeyAsync.bind(this);
|
||||
this.process = this.process.bind(this);
|
||||
this.processAsync = this.processAsync.bind(this);
|
||||
this._logger.debug('created new transformer');
|
||||
process.env.TS_JEST = '1';
|
||||
}
|
||||
TsJestTransformer.prototype._configsFor = function (transformOptions) {
|
||||
var config = transformOptions.config, cacheFS = transformOptions.cacheFS;
|
||||
var ccs = TsJestTransformer._cachedConfigSets.find(function (cs) { return cs.jestConfig.value === config; });
|
||||
var configSet;
|
||||
if (ccs) {
|
||||
this._transformCfgStr = ccs.transformerCfgStr;
|
||||
this._compiler = ccs.compiler;
|
||||
this._depGraphs = ccs.depGraphs;
|
||||
this._tsResolvedModulesCachePath = ccs.tsResolvedModulesCachePath;
|
||||
this._watchMode = ccs.watchMode;
|
||||
configSet = ccs.configSet;
|
||||
}
|
||||
else {
|
||||
var serializedJestCfg_1 = (0, utils_1.stringify)(config);
|
||||
var serializedCcs = TsJestTransformer._cachedConfigSets.find(function (cs) { return cs.jestConfig.serialized === serializedJestCfg_1; });
|
||||
if (serializedCcs) {
|
||||
serializedCcs.jestConfig.value = config;
|
||||
this._transformCfgStr = serializedCcs.transformerCfgStr;
|
||||
this._compiler = serializedCcs.compiler;
|
||||
this._depGraphs = serializedCcs.depGraphs;
|
||||
this._tsResolvedModulesCachePath = serializedCcs.tsResolvedModulesCachePath;
|
||||
this._watchMode = serializedCcs.watchMode;
|
||||
configSet = serializedCcs.configSet;
|
||||
}
|
||||
else {
|
||||
this._logger.info('no matching config-set found, creating a new one');
|
||||
configSet = this._createConfigSet(config);
|
||||
var jest_1 = __assign({}, config);
|
||||
jest_1.cacheDirectory = undefined;
|
||||
this._transformCfgStr = "".concat(new utils_1.JsonableValue(jest_1).serialized).concat(configSet.cacheSuffix);
|
||||
this._createCompiler(configSet, cacheFS);
|
||||
this._getFsCachedResolvedModules(configSet);
|
||||
this._watchMode = process.argv.includes('--watch');
|
||||
TsJestTransformer._cachedConfigSets.push({
|
||||
jestConfig: new utils_1.JsonableValue(config),
|
||||
configSet: configSet,
|
||||
transformerCfgStr: this._transformCfgStr,
|
||||
compiler: this._compiler,
|
||||
depGraphs: this._depGraphs,
|
||||
tsResolvedModulesCachePath: this._tsResolvedModulesCachePath,
|
||||
watchMode: this._watchMode,
|
||||
});
|
||||
}
|
||||
}
|
||||
return configSet;
|
||||
};
|
||||
TsJestTransformer.prototype._createConfigSet = function (config) {
|
||||
return new config_set_1.ConfigSet(config);
|
||||
};
|
||||
TsJestTransformer.prototype._createCompiler = function (configSet, cacheFS) {
|
||||
this._compiler = new compiler_1.TsJestCompiler(configSet, cacheFS);
|
||||
};
|
||||
TsJestTransformer.prototype.process = function (sourceText, sourcePath, transformOptions) {
|
||||
this._logger.debug({ fileName: sourcePath, transformOptions: transformOptions }, 'processing', sourcePath);
|
||||
var configs = this._configsFor(transformOptions);
|
||||
var shouldStringifyContent = configs.shouldStringifyContent(sourcePath);
|
||||
var babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
|
||||
var result = {
|
||||
code: this.processWithTs(sourceText, sourcePath, transformOptions).code,
|
||||
};
|
||||
if (babelJest) {
|
||||
this._logger.debug({ fileName: sourcePath }, 'calling babel-jest processor');
|
||||
result = babelJest.process(result.code, sourcePath, __assign(__assign({}, transformOptions), { instrument: false }));
|
||||
}
|
||||
result = this.runTsJestHook(sourcePath, sourceText, transformOptions, result);
|
||||
return result;
|
||||
};
|
||||
TsJestTransformer.prototype.processAsync = function (sourceText, sourcePath, transformOptions) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var _this = this;
|
||||
return __generator(this, function (_a) {
|
||||
this._logger.debug({ fileName: sourcePath, transformOptions: transformOptions }, 'processing', sourcePath);
|
||||
return [2, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
||||
var configs, shouldStringifyContent, babelJest, result, processWithTsResult;
|
||||
var _a;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
configs = this._configsFor(transformOptions);
|
||||
shouldStringifyContent = configs.shouldStringifyContent(sourcePath);
|
||||
babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
|
||||
processWithTsResult = this.processWithTs(sourceText, sourcePath, transformOptions);
|
||||
result = {
|
||||
code: processWithTsResult.code,
|
||||
};
|
||||
if ((_a = processWithTsResult.diagnostics) === null || _a === void 0 ? void 0 : _a.length) {
|
||||
reject(configs.createTsError(processWithTsResult.diagnostics));
|
||||
}
|
||||
if (!babelJest) return [3, 2];
|
||||
this._logger.debug({ fileName: sourcePath }, 'calling babel-jest processor');
|
||||
return [4, babelJest.processAsync(result.code, sourcePath, __assign(__assign({}, transformOptions), { instrument: false }))];
|
||||
case 1:
|
||||
result = _b.sent();
|
||||
_b.label = 2;
|
||||
case 2:
|
||||
result = this.runTsJestHook(sourcePath, sourceText, transformOptions, result);
|
||||
resolve(result);
|
||||
return [2];
|
||||
}
|
||||
});
|
||||
}); })];
|
||||
});
|
||||
});
|
||||
};
|
||||
TsJestTransformer.prototype.processWithTs = function (sourceText, sourcePath, transformOptions) {
|
||||
var result;
|
||||
var configs = this._configsFor(transformOptions);
|
||||
var shouldStringifyContent = configs.shouldStringifyContent(sourcePath);
|
||||
var babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
|
||||
var isDefinitionFile = sourcePath.endsWith(constants_1.DECLARATION_TYPE_EXT);
|
||||
var isJsFile = constants_1.JS_JSX_REGEX.test(sourcePath);
|
||||
var isTsFile = !isDefinitionFile && constants_1.TS_TSX_REGEX.test(sourcePath);
|
||||
if (shouldStringifyContent) {
|
||||
result = {
|
||||
code: "module.exports=".concat((0, utils_1.stringify)(sourceText)),
|
||||
};
|
||||
}
|
||||
else if (isDefinitionFile) {
|
||||
result = {
|
||||
code: '',
|
||||
};
|
||||
}
|
||||
else if (!configs.parsedTsConfig.options.allowJs && isJsFile) {
|
||||
this._logger.warn({ fileName: sourcePath }, (0, messages_1.interpolate)("Got a `.js` file to compile while `allowJs` option is not set to `true` (file: {{path}}). To fix this:\n - if you want TypeScript to process JS files, set `allowJs` to `true` in your TypeScript config (usually tsconfig.json)\n - if you do not want TypeScript to process your `.js` files, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match `.js` files anymore", { path: sourcePath }));
|
||||
result = {
|
||||
code: sourceText,
|
||||
};
|
||||
}
|
||||
else if (isJsFile || isTsFile) {
|
||||
result = this._compiler.getCompiledOutput(sourceText, sourcePath, {
|
||||
depGraphs: this._depGraphs,
|
||||
supportsStaticESM: transformOptions.supportsStaticESM,
|
||||
watchMode: this._watchMode,
|
||||
});
|
||||
}
|
||||
else {
|
||||
var message = babelJest ? "Got a unknown file type to compile (file: {{path}}). To fix this, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match this kind of files anymore. If you still want Babel to process it, add another entry to the `transform` option with value `babel-jest` which key matches this type of files." : "Got a unknown file type to compile (file: {{path}}). To fix this, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match this kind of files anymore.";
|
||||
this._logger.warn({ fileName: sourcePath }, (0, messages_1.interpolate)(message, { path: sourcePath }));
|
||||
result = {
|
||||
code: sourceText,
|
||||
};
|
||||
}
|
||||
return result;
|
||||
};
|
||||
TsJestTransformer.prototype.runTsJestHook = function (sourcePath, sourceText, transformOptions, compiledOutput) {
|
||||
var hooksFile = process.env.TS_JEST_HOOKS;
|
||||
var hooks;
|
||||
if (hooksFile) {
|
||||
hooksFile = path_1.default.resolve(this._configsFor(transformOptions).cwd, hooksFile);
|
||||
hooks = importer_1.importer.tryTheseOr(hooksFile, {});
|
||||
}
|
||||
if (hooks === null || hooks === void 0 ? void 0 : hooks.afterProcess) {
|
||||
this._logger.debug({ fileName: sourcePath, hookName: 'afterProcess' }, 'calling afterProcess hook');
|
||||
var newResult = hooks.afterProcess([sourceText, sourcePath, transformOptions.config, transformOptions], compiledOutput);
|
||||
if (newResult) {
|
||||
return newResult;
|
||||
}
|
||||
}
|
||||
return compiledOutput;
|
||||
};
|
||||
TsJestTransformer.prototype.getCacheKey = function (fileContent, filePath, transformOptions) {
|
||||
var _a;
|
||||
var configs = this._configsFor(transformOptions);
|
||||
this._logger.debug({ fileName: filePath, transformOptions: transformOptions }, 'computing cache key for', filePath);
|
||||
var _b = transformOptions.instrument, instrument = _b === void 0 ? false : _b;
|
||||
var constructingCacheKeyElements = [
|
||||
this._transformCfgStr,
|
||||
exports.CACHE_KEY_EL_SEPARATOR,
|
||||
configs.rootDir,
|
||||
exports.CACHE_KEY_EL_SEPARATOR,
|
||||
"instrument:".concat(instrument ? 'on' : 'off'),
|
||||
exports.CACHE_KEY_EL_SEPARATOR,
|
||||
fileContent,
|
||||
exports.CACHE_KEY_EL_SEPARATOR,
|
||||
filePath,
|
||||
];
|
||||
if (!configs.isolatedModules && this._tsResolvedModulesCachePath) {
|
||||
var resolvedModuleNames = void 0;
|
||||
if (((_a = this._depGraphs.get(filePath)) === null || _a === void 0 ? void 0 : _a.fileContent) === fileContent) {
|
||||
this._logger.debug({ fileName: filePath, transformOptions: transformOptions }, 'getting resolved modules from disk caching or memory caching for', filePath);
|
||||
resolvedModuleNames = this._depGraphs
|
||||
.get(filePath)
|
||||
.resolvedModuleNames.filter(function (moduleName) { return (0, fs_1.existsSync)(moduleName); });
|
||||
}
|
||||
else {
|
||||
this._logger.debug({ fileName: filePath, transformOptions: transformOptions }, 'getting resolved modules from TypeScript API for', filePath);
|
||||
resolvedModuleNames = this._compiler.getResolvedModules(fileContent, filePath, transformOptions.cacheFS);
|
||||
this._depGraphs.set(filePath, {
|
||||
fileContent: fileContent,
|
||||
resolvedModuleNames: resolvedModuleNames,
|
||||
});
|
||||
(0, fs_1.writeFileSync)(this._tsResolvedModulesCachePath, (0, utils_1.stringify)(__spreadArray([], __read(this._depGraphs), false)));
|
||||
}
|
||||
resolvedModuleNames.forEach(function (moduleName) {
|
||||
constructingCacheKeyElements.push(exports.CACHE_KEY_EL_SEPARATOR, moduleName, exports.CACHE_KEY_EL_SEPARATOR, (0, fs_1.statSync)(moduleName).mtimeMs.toString());
|
||||
});
|
||||
}
|
||||
return sha1_1.sha1.apply(void 0, __spreadArray([], __read(constructingCacheKeyElements), false));
|
||||
};
|
||||
TsJestTransformer.prototype.getCacheKeyAsync = function (sourceText, sourcePath, transformOptions) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
return [2, Promise.resolve(this.getCacheKey(sourceText, sourcePath, transformOptions))];
|
||||
});
|
||||
});
|
||||
};
|
||||
TsJestTransformer.prototype._getFsCachedResolvedModules = function (configSet) {
|
||||
var cacheDir = configSet.tsCacheDir;
|
||||
if (!configSet.isolatedModules && cacheDir) {
|
||||
(0, fs_1.mkdirSync)(cacheDir, { recursive: true });
|
||||
this._tsResolvedModulesCachePath = path_1.default.join(cacheDir, (0, sha1_1.sha1)('ts-jest-resolved-modules', exports.CACHE_KEY_EL_SEPARATOR));
|
||||
try {
|
||||
var cachedTSResolvedModules = (0, fs_1.readFileSync)(this._tsResolvedModulesCachePath, 'utf-8');
|
||||
this._depGraphs = new Map((0, utils_1.parse)(cachedTSResolvedModules));
|
||||
}
|
||||
catch (e) { }
|
||||
}
|
||||
};
|
||||
TsJestTransformer._cachedConfigSets = [];
|
||||
return TsJestTransformer;
|
||||
}());
|
||||
exports.TsJestTransformer = TsJestTransformer;
|
Reference in New Issue
Block a user