ts-jest 27.0.6 → 27.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/.ts-jest-digest +1 -1
  2. package/CHANGELOG.md +53 -0
  3. package/CONTRIBUTING.md +95 -42
  4. package/README.md +1 -1
  5. package/dist/cli/config/init.js +16 -16
  6. package/dist/cli/config/migrate.js +23 -19
  7. package/dist/cli/helpers/presets.js +2 -2
  8. package/dist/cli/index.js +14 -7
  9. package/dist/compiler/compiler-utils.js +3 -3
  10. package/dist/compiler/index.d.ts +3 -0
  11. package/dist/compiler/index.js +15 -0
  12. package/dist/compiler/ts-compiler.d.ts +1 -1
  13. package/dist/compiler/ts-compiler.js +38 -35
  14. package/dist/compiler/ts-jest-compiler.d.ts +1 -1
  15. package/dist/config/config-set.d.ts +3 -3
  16. package/dist/config/config-set.js +65 -37
  17. package/dist/config/index.d.ts +2 -0
  18. package/dist/config/index.js +14 -0
  19. package/dist/config/paths-to-module-name-mapper.js +10 -10
  20. package/dist/index.d.ts +8 -0
  21. package/dist/index.js +18 -0
  22. package/dist/presets/create-jest-preset.js +2 -2
  23. package/dist/transformers/hoist-jest.d.ts +4 -1
  24. package/dist/transformers/hoist-jest.js +72 -94
  25. package/dist/transformers/path-mapping.d.ts +2 -2
  26. package/dist/transformers/path-mapping.js +33 -26
  27. package/dist/ts-jest-transformer.d.ts +3 -1
  28. package/dist/ts-jest-transformer.js +96 -41
  29. package/dist/types.d.ts +12 -2
  30. package/dist/utils/backports.js +2 -2
  31. package/dist/utils/get-package-version.js +1 -1
  32. package/dist/utils/importer.js +24 -18
  33. package/dist/utils/index.d.ts +4 -0
  34. package/dist/utils/index.js +15 -0
  35. package/dist/utils/json.js +1 -1
  36. package/dist/utils/jsonable-value.js +1 -1
  37. package/dist/utils/logger.js +3 -3
  38. package/dist/utils/sha1.js +1 -1
  39. package/dist/utils/ts-error.js +1 -1
  40. package/dist/utils/version-checkers.js +3 -3
  41. package/package.json +32 -32
  42. package/presets/index.d.ts +1 -1
  43. package/utils/index.js +13 -0
@@ -26,10 +26,14 @@ var __read = (this && this.__read) || function (o, n) {
26
26
  }
27
27
  return ar;
28
28
  };
29
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
30
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
31
- to[j] = from[i];
32
- return to;
29
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
30
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
31
+ if (ar || !(i in from)) {
32
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
33
+ ar[i] = from[i];
34
+ }
35
+ }
36
+ return to.concat(ar || Array.prototype.slice.call(from));
33
37
  };
34
38
  var __values = (this && this.__values) || function(o) {
35
39
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
@@ -49,9 +53,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
49
53
  exports.TsCompiler = void 0;
50
54
  var path_1 = require("path");
51
55
  var bs_logger_1 = require("bs-logger");
52
- var memoize_1 = __importDefault(require("lodash/memoize"));
56
+ var lodash_memoize_1 = __importDefault(require("lodash.memoize"));
53
57
  var constants_1 = require("../constants");
54
- var logger_1 = require("../utils/logger");
58
+ var utils_1 = require("../utils");
55
59
  var messages_1 = require("../utils/messages");
56
60
  var compiler_utils_1 = require("./compiler-utils");
57
61
  var TsCompiler = (function () {
@@ -62,7 +66,7 @@ var TsCompiler = (function () {
62
66
  this.runtimeCacheFS = runtimeCacheFS;
63
67
  this._projectVersion = 1;
64
68
  this._ts = configSet.compilerModule;
65
- this._logger = logger_1.rootLogger.child({ namespace: 'ts-compiler' });
69
+ this._logger = utils_1.rootLogger.child({ namespace: 'ts-compiler' });
66
70
  this._parsedTsConfig = this.configSet.parsedTsConfig;
67
71
  this._initialCompilerOptions = __assign({}, this._parsedTsConfig.options);
68
72
  this._compilerOptions = __assign({}, this._initialCompilerOptions);
@@ -75,14 +79,14 @@ var TsCompiler = (function () {
75
79
  call: null
76
80
  },
77
81
  _a[bs_logger_1.LogContexts.logLevel] = bs_logger_1.LogLevels.trace,
78
- _a), 'readFile', memoize_1.default(this._ts.sys.readFile));
82
+ _a), 'readFile', (0, lodash_memoize_1.default)(this._ts.sys.readFile));
79
83
  this._moduleResolutionHost = {
80
- fileExists: memoize_1.default(this._ts.sys.fileExists),
84
+ fileExists: (0, lodash_memoize_1.default)(this._ts.sys.fileExists),
81
85
  readFile: this._cachedReadFile,
82
- directoryExists: memoize_1.default(this._ts.sys.directoryExists),
86
+ directoryExists: (0, lodash_memoize_1.default)(this._ts.sys.directoryExists),
83
87
  getCurrentDirectory: function () { return _this.configSet.cwd; },
84
- realpath: this._ts.sys.realpath && memoize_1.default(this._ts.sys.realpath),
85
- getDirectories: memoize_1.default(this._ts.sys.getDirectories),
88
+ realpath: this._ts.sys.realpath && (0, lodash_memoize_1.default)(this._ts.sys.realpath),
89
+ getDirectories: (0, lodash_memoize_1.default)(this._ts.sys.getDirectories),
86
90
  };
87
91
  this._moduleResolutionCache = this._ts.createModuleResolutionCache(this.configSet.cwd, function (x) { return x; }, this._compilerOptions);
88
92
  this._createLanguageService();
@@ -98,7 +102,7 @@ var TsCompiler = (function () {
98
102
  this._logger.debug({ fileName: fileName }, 'getResolvedModules(): resolve nested imported module paths from directed imported module paths');
99
103
  importedModulePaths.forEach(function (importedModulePath) {
100
104
  var resolvedFileContent = _this._getFileContentFromCache(importedModulePath);
101
- importedModulePaths.push.apply(importedModulePaths, __spreadArray([], __read(_this._getImportedModulePaths(resolvedFileContent, importedModulePath).filter(function (modulePath) { return !importedModulePaths.includes(modulePath); }))));
105
+ importedModulePaths.push.apply(importedModulePaths, __spreadArray([], __read(_this._getImportedModulePaths(resolvedFileContent, importedModulePath).filter(function (modulePath) { return !importedModulePaths.includes(modulePath); })), false));
102
106
  });
103
107
  return importedModulePaths;
104
108
  };
@@ -121,8 +125,7 @@ var TsCompiler = (function () {
121
125
  else {
122
126
  moduleKind = this._ts.ModuleKind.CommonJS;
123
127
  }
124
- this._compilerOptions = __assign(__assign({}, this._compilerOptions), { allowSyntheticDefaultImports: allowSyntheticDefaultImports,
125
- esModuleInterop: esModuleInterop, module: moduleKind });
128
+ this._compilerOptions = __assign(__assign({}, this._compilerOptions), { allowSyntheticDefaultImports: allowSyntheticDefaultImports, esModuleInterop: esModuleInterop, module: moduleKind });
126
129
  if (this._languageService) {
127
130
  this._logger.debug({ fileName: fileName }, 'getCompiledOutput(): compiling using language service');
128
131
  this._updateMemoryCache(fileContent, fileName, currentModuleKind === moduleKind);
@@ -130,21 +133,21 @@ var TsCompiler = (function () {
130
133
  this._doTypeChecking(fileName, options.depGraphs, options.watchMode);
131
134
  if (output.emitSkipped) {
132
135
  if (constants_1.TS_TSX_REGEX.test(fileName)) {
133
- throw new Error(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 }));
136
+ 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 }));
134
137
  }
135
138
  else {
136
- this._logger.warn(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 }));
137
- return compiler_utils_1.updateOutput(fileContent, fileName, undefined);
139
+ 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 }));
140
+ return (0, compiler_utils_1.updateOutput)(fileContent, fileName, undefined);
138
141
  }
139
142
  }
140
143
  if (!output.outputFiles.length) {
141
- throw new TypeError(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}}`.", {
142
- file: path_1.basename(fileName),
144
+ 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}}`.", {
145
+ file: (0, path_1.basename)(fileName),
143
146
  }));
144
147
  }
145
148
  return this._compilerOptions.sourceMap
146
- ? compiler_utils_1.updateOutput(output.outputFiles[1].text, fileName, output.outputFiles[0].text)
147
- : compiler_utils_1.updateOutput(output.outputFiles[0].text, fileName, undefined);
149
+ ? (0, compiler_utils_1.updateOutput)(output.outputFiles[1].text, fileName, output.outputFiles[0].text)
150
+ : (0, compiler_utils_1.updateOutput)(output.outputFiles[0].text, fileName, undefined);
148
151
  }
149
152
  else {
150
153
  this._logger.debug({ fileName: fileName }, 'getCompiledOutput(): compiling as isolated module');
@@ -152,7 +155,7 @@ var TsCompiler = (function () {
152
155
  if (result.diagnostics && this.configSet.shouldReportDiagnostics(fileName)) {
153
156
  this.configSet.raiseDiagnostics(result.diagnostics, fileName, this._logger);
154
157
  }
155
- return compiler_utils_1.updateOutput(result.outputText, fileName, result.sourceMapText);
158
+ return (0, compiler_utils_1.updateOutput)(result.outputText, fileName, result.sourceMapText);
156
159
  }
157
160
  };
158
161
  TsCompiler.prototype._transpileOutput = function (fileContent, fileName) {
@@ -184,15 +187,15 @@ var TsCompiler = (function () {
184
187
  .forEach(function (fileName) { return _this._fileVersionCache.set(fileName, 0); });
185
188
  var serviceHost = {
186
189
  getProjectVersion: function () { return String(_this._projectVersion); },
187
- getScriptFileNames: function () { return __spreadArray([], __read(_this._fileVersionCache.keys())); },
190
+ getScriptFileNames: function () { return __spreadArray([], __read(_this._fileVersionCache.keys()), false); },
188
191
  getScriptVersion: function (fileName) {
189
- var normalizedFileName = path_1.normalize(fileName);
192
+ var normalizedFileName = (0, path_1.normalize)(fileName);
190
193
  var version = _this._fileVersionCache.get(normalizedFileName);
191
194
  return version === undefined ? undefined : String(version);
192
195
  },
193
196
  getScriptSnapshot: function (fileName) {
194
197
  var _a, _b, _c, _d;
195
- var normalizedFileName = path_1.normalize(fileName);
198
+ var normalizedFileName = (0, path_1.normalize)(fileName);
196
199
  var hit = _this._isFileInCache(normalizedFileName);
197
200
  _this._logger.trace({ normalizedFileName: normalizedFileName, cacheHit: hit }, 'getScriptSnapshot():', 'cache', hit ? 'hit' : 'miss');
198
201
  if (!hit) {
@@ -207,12 +210,12 @@ var TsCompiler = (function () {
207
210
  return;
208
211
  return _this._ts.ScriptSnapshot.fromString(contents);
209
212
  },
210
- fileExists: memoize_1.default(this._ts.sys.fileExists),
213
+ fileExists: (0, lodash_memoize_1.default)(this._ts.sys.fileExists),
211
214
  readFile: this._cachedReadFile,
212
- readDirectory: memoize_1.default(this._ts.sys.readDirectory),
213
- getDirectories: memoize_1.default(this._ts.sys.getDirectories),
214
- directoryExists: memoize_1.default(this._ts.sys.directoryExists),
215
- realpath: this._ts.sys.realpath && memoize_1.default(this._ts.sys.realpath),
215
+ readDirectory: (0, lodash_memoize_1.default)(this._ts.sys.readDirectory),
216
+ getDirectories: (0, lodash_memoize_1.default)(this._ts.sys.getDirectories),
217
+ directoryExists: (0, lodash_memoize_1.default)(this._ts.sys.directoryExists),
218
+ realpath: this._ts.sys.realpath && (0, lodash_memoize_1.default)(this._ts.sys.realpath),
216
219
  getNewLine: function () { return constants_1.LINE_FEED; },
217
220
  getCurrentDirectory: function () { return _this.configSet.cwd; },
218
221
  getCompilationSettings: function () { return _this._compilerOptions; },
@@ -227,7 +230,7 @@ var TsCompiler = (function () {
227
230
  this.program = this._languageService.getProgram();
228
231
  };
229
232
  TsCompiler.prototype._getFileContentFromCache = function (filePath) {
230
- var normalizedFilePath = path_1.normalize(filePath);
233
+ var normalizedFilePath = (0, path_1.normalize)(filePath);
231
234
  var resolvedFileContent = this._runtimeCacheFS.get(normalizedFilePath);
232
235
  if (!resolvedFileContent) {
233
236
  resolvedFileContent = this._moduleResolutionHost.readFile(normalizedFilePath);
@@ -282,7 +285,7 @@ var TsCompiler = (function () {
282
285
  var e_1, _a;
283
286
  if (this.configSet.shouldReportDiagnostics(fileName)) {
284
287
  this._logger.debug({ fileName: fileName }, '_doTypeChecking(): computing diagnostics using language service');
285
- var diagnostics = __spreadArray(__spreadArray([], __read(this._languageService.getSemanticDiagnostics(fileName))), __read(this._languageService.getSyntacticDiagnostics(fileName)));
288
+ var diagnostics = __spreadArray(__spreadArray([], __read(this._languageService.getSemanticDiagnostics(fileName)), false), __read(this._languageService.getSyntacticDiagnostics(fileName)), false);
286
289
  this.configSet.raiseDiagnostics(diagnostics, fileName, this._logger);
287
290
  }
288
291
  if (watchMode) {
@@ -290,12 +293,12 @@ var TsCompiler = (function () {
290
293
  try {
291
294
  for (var _b = __values(depGraphs.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
292
295
  var entry = _c.value;
293
- var normalizedModuleNames = entry[1].resolvedModuleNames.map(function (moduleName) { return path_1.normalize(moduleName); });
296
+ var normalizedModuleNames = entry[1].resolvedModuleNames.map(function (moduleName) { return (0, path_1.normalize)(moduleName); });
294
297
  var fileToReTypeCheck = entry[0];
295
298
  if (normalizedModuleNames.includes(fileName) && this.configSet.shouldReportDiagnostics(fileToReTypeCheck)) {
296
299
  this._logger.debug({ fileToReTypeCheck: fileToReTypeCheck }, '_doTypeChecking(): computing diagnostics using language service');
297
300
  this._updateMemoryCache(this._getFileContentFromCache(fileToReTypeCheck), fileToReTypeCheck);
298
- var importedModulesDiagnostics = __spreadArray(__spreadArray([], __read(this._languageService.getSemanticDiagnostics(fileToReTypeCheck))), __read(this._languageService.getSyntacticDiagnostics(fileToReTypeCheck)));
301
+ var importedModulesDiagnostics = __spreadArray(__spreadArray([], __read(this._languageService.getSemanticDiagnostics(fileToReTypeCheck)), false), __read(this._languageService.getSyntacticDiagnostics(fileToReTypeCheck)), false);
299
302
  this.configSet.raiseDiagnostics(importedModulesDiagnostics, fileName, this._logger);
300
303
  }
301
304
  }
@@ -1,4 +1,4 @@
1
- import type { ConfigSet } from '../config/config-set';
1
+ import type { ConfigSet } from '../config';
2
2
  import type { CompilerInstance, StringMap, TsJestCompileOptions } from '../types';
3
3
  export declare class TsJestCompiler implements CompilerInstance {
4
4
  private readonly _compilerInstance;
@@ -1,5 +1,5 @@
1
1
  import { Logger } from 'bs-logger';
2
- import type { Diagnostic, ParsedCommandLine } from 'typescript';
2
+ import type * as ts from 'typescript';
3
3
  import type { RawCompilerOptions } from '../raw-compiler-options';
4
4
  import type { ProjectConfigTsJest, TsJestAstTransformer, TTypeScript } from '../types';
5
5
  export declare class ConfigSet {
@@ -12,14 +12,14 @@ export declare class ConfigSet {
12
12
  readonly rootDir: string;
13
13
  cacheSuffix: string;
14
14
  tsCacheDir: string | undefined;
15
- parsedTsConfig: ParsedCommandLine | Record<string, any>;
15
+ parsedTsConfig: ts.ParsedCommandLine | Record<string, any>;
16
16
  resolvedTransformers: TsJestAstTransformer;
17
17
  useESM: boolean;
18
18
  constructor(jestConfig: ProjectConfigTsJest | undefined, parentLogger?: Logger | undefined);
19
19
  protected _resolveTsConfig(compilerOptions?: RawCompilerOptions, resolvedConfigFile?: string): Record<string, any>;
20
20
  isTestFile(fileName: string): boolean;
21
21
  shouldStringifyContent(filePath: string): boolean;
22
- raiseDiagnostics(diagnostics: Diagnostic[], filePath?: string, logger?: Logger): void;
22
+ raiseDiagnostics(diagnostics: ts.Diagnostic[], filePath?: string, logger?: Logger): void;
23
23
  shouldReportDiagnostics(filePath: string): boolean;
24
24
  resolvePath(inputPath: string, { throwIfMissing, nodeResolve }?: {
25
25
  throwIfMissing?: boolean;
@@ -37,10 +37,14 @@ var __read = (this && this.__read) || function (o, n) {
37
37
  }
38
38
  return ar;
39
39
  };
40
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
41
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
42
- to[j] = from[i];
43
- return to;
40
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
41
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
42
+ if (ar || !(i in from)) {
43
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
44
+ ar[i] = from[i];
45
+ }
46
+ }
47
+ return to.concat(ar || Array.prototype.slice.call(from));
44
48
  };
45
49
  var __importDefault = (this && this.__importDefault) || function (mod) {
46
50
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -48,20 +52,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
48
52
  Object.defineProperty(exports, "__esModule", { value: true });
49
53
  exports.ConfigSet = exports.TS_JEST_OUT_DIR = exports.IGNORE_DIAGNOSTIC_CODES = exports.MY_DIGEST = void 0;
50
54
  var fs_1 = require("fs");
55
+ var module_1 = __importDefault(require("module"));
51
56
  var path_1 = require("path");
52
57
  var bs_logger_1 = require("bs-logger");
53
58
  var jest_util_1 = require("jest-util");
54
59
  var json5_1 = __importDefault(require("json5"));
55
60
  var constants_1 = require("../constants");
61
+ var utils_1 = require("../utils");
56
62
  var backports_1 = require("../utils/backports");
57
63
  var importer_1 = require("../utils/importer");
58
- var json_1 = require("../utils/json");
59
- var logger_1 = require("../utils/logger");
60
64
  var messages_1 = require("../utils/messages");
61
65
  var normalize_slashes_1 = require("../utils/normalize-slashes");
62
66
  var sha1_1 = require("../utils/sha1");
63
67
  var ts_error_1 = require("../utils/ts-error");
64
- exports.MY_DIGEST = fs_1.readFileSync(path_1.resolve(__dirname, '..', '..', '.ts-jest-digest'), 'utf8');
68
+ exports.MY_DIGEST = (0, fs_1.readFileSync)((0, path_1.resolve)(__dirname, '..', '..', '.ts-jest-digest'), 'utf8');
65
69
  exports.IGNORE_DIAGNOSTIC_CODES = [
66
70
  6059,
67
71
  18002,
@@ -71,7 +75,7 @@ exports.TS_JEST_OUT_DIR = '$$ts-jest$$';
71
75
  var normalizeRegex = function (pattern) {
72
76
  return pattern ? (typeof pattern === 'string' ? pattern : pattern.source) : undefined;
73
77
  };
74
- var toDiagnosticCode = function (code) { var _a; return code ? (_a = parseInt(("" + code).trim().replace(/^TS/, ''), 10)) !== null && _a !== void 0 ? _a : undefined : undefined; };
78
+ var toDiagnosticCode = function (code) { var _a; return code ? (_a = parseInt("".concat(code).trim().replace(/^TS/, ''), 10)) !== null && _a !== void 0 ? _a : undefined : undefined; };
75
79
  var toDiagnosticCodeList = function (items, into) {
76
80
  var e_1, _a;
77
81
  if (into === void 0) { into = []; }
@@ -102,6 +106,17 @@ var toDiagnosticCodeList = function (items, into) {
102
106
  }
103
107
  return into;
104
108
  };
109
+ var requireFromString = function (code, fileName) {
110
+ var paths = module_1.default._nodeModulePaths((0, path_1.dirname)(fileName));
111
+ var parent = module.parent;
112
+ var m = new module_1.default(fileName, parent);
113
+ m.filename = fileName;
114
+ m.paths = [].concat(paths);
115
+ m._compile(code, fileName);
116
+ var exports = m.exports;
117
+ parent && parent.children && parent.children.splice(parent.children.indexOf(m), 1);
118
+ return exports;
119
+ };
105
120
  var ConfigSet = (function () {
106
121
  function ConfigSet(jestConfig, parentLogger) {
107
122
  var _a, _b;
@@ -130,10 +145,10 @@ var ConfigSet = (function () {
130
145
  };
131
146
  this.logger = this.parentLogger
132
147
  ? this.parentLogger.child((_a = {}, _a[bs_logger_1.LogContexts.namespace] = 'config', _a))
133
- : logger_1.rootLogger.child({ namespace: 'config' });
148
+ : utils_1.rootLogger.child({ namespace: 'config' });
134
149
  this._backportJestCfg(jestConfig !== null && jestConfig !== void 0 ? jestConfig : Object.create(null));
135
- this.cwd = path_1.normalize((_c = this._jestCfg.cwd) !== null && _c !== void 0 ? _c : process.cwd());
136
- this.rootDir = path_1.normalize((_d = this._jestCfg.rootDir) !== null && _d !== void 0 ? _d : this.cwd);
150
+ this.cwd = (0, path_1.normalize)((_c = this._jestCfg.cwd) !== null && _c !== void 0 ? _c : process.cwd());
151
+ this.rootDir = (0, path_1.normalize)((_d = this._jestCfg.rootDir) !== null && _d !== void 0 ? _d : this.cwd);
137
152
  var tsJestCfg = this._jestCfg.globals && this._jestCfg.globals['ts-jest'];
138
153
  var options = tsJestCfg !== null && tsJestCfg !== void 0 ? tsJestCfg : Object.create(null);
139
154
  this.compilerModule = importer_1.importer.typescript("Using \"ts-jest\" requires this package to be installed.", (_e = options.compiler) !== null && _e !== void 0 ? _e : 'typescript');
@@ -141,17 +156,17 @@ var ConfigSet = (function () {
141
156
  this.logger.debug({ compilerModule: this.compilerModule }, 'normalized compiler module config via ts-jest option');
142
157
  this._setupConfigSet(options);
143
158
  this._resolveTsCacheDir();
144
- this._matchablePatterns = __spreadArray(__spreadArray([], __read(this._jestCfg.testMatch)), __read(this._jestCfg.testRegex)).filter(function (pattern) {
159
+ this._matchablePatterns = __spreadArray(__spreadArray([], __read(this._jestCfg.testMatch), false), __read(this._jestCfg.testRegex), false).filter(function (pattern) {
145
160
  return pattern instanceof RegExp || typeof pattern === 'string';
146
161
  });
147
162
  if (!this._matchablePatterns.length) {
148
- (_b = this._matchablePatterns).push.apply(_b, __spreadArray([], __read(constants_1.DEFAULT_JEST_TEST_MATCH)));
163
+ (_b = this._matchablePatterns).push.apply(_b, __spreadArray([], __read(constants_1.DEFAULT_JEST_TEST_MATCH), false));
149
164
  }
150
- this._matchTestFilePath = jest_util_1.globsToMatcher(this._matchablePatterns.filter(function (pattern) { return typeof pattern === 'string'; }));
165
+ this._matchTestFilePath = (0, jest_util_1.globsToMatcher)(this._matchablePatterns.filter(function (pattern) { return typeof pattern === 'string'; }));
151
166
  }
152
167
  ConfigSet.prototype._backportJestCfg = function (jestCfg) {
153
168
  var _a, _b;
154
- var config = backports_1.backportJestConfig(this.logger, jestCfg);
169
+ var config = (0, backports_1.backportJestConfig)(this.logger, jestCfg);
155
170
  this.logger.debug({ jestConfig: config }, 'normalized jest config');
156
171
  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 : [] });
157
172
  };
@@ -166,11 +181,11 @@ var ConfigSet = (function () {
166
181
  var baseBabelCfg = { cwd: this.cwd };
167
182
  if (typeof options.babelConfig === 'string') {
168
183
  var babelCfgPath = this.resolvePath(options.babelConfig);
169
- if (path_1.extname(options.babelConfig) === '.js') {
184
+ if ((0, path_1.extname)(options.babelConfig) === '.js') {
170
185
  this.babelConfig = __assign(__assign({}, baseBabelCfg), require(babelCfgPath));
171
186
  }
172
187
  else {
173
- this.babelConfig = __assign(__assign({}, baseBabelCfg), json5_1.default.parse(fs_1.readFileSync(babelCfgPath, 'utf-8')));
188
+ this.babelConfig = __assign(__assign({}, baseBabelCfg), json5_1.default.parse((0, fs_1.readFileSync)(babelCfgPath, 'utf-8')));
174
189
  }
175
190
  }
176
191
  else if (typeof options.babelConfig === 'object') {
@@ -186,11 +201,11 @@ var ConfigSet = (function () {
186
201
  this.logger.debug('created babel-jest transformer');
187
202
  }
188
203
  var diagnosticsOpt = (_b = options.diagnostics) !== null && _b !== void 0 ? _b : true;
189
- var ignoreList = __spreadArray([], __read(exports.IGNORE_DIAGNOSTIC_CODES));
204
+ var ignoreList = __spreadArray([], __read(exports.IGNORE_DIAGNOSTIC_CODES), false);
190
205
  if (typeof diagnosticsOpt === 'object') {
191
206
  var ignoreCodes = diagnosticsOpt.ignoreCodes;
192
207
  if (ignoreCodes) {
193
- Array.isArray(ignoreCodes) ? ignoreList.push.apply(ignoreList, __spreadArray([], __read(ignoreCodes))) : ignoreList.push(ignoreCodes);
208
+ Array.isArray(ignoreCodes) ? ignoreList.push.apply(ignoreList, __spreadArray([], __read(ignoreCodes), false)) : ignoreList.push(ignoreCodes);
194
209
  }
195
210
  this._diagnostics = {
196
211
  pretty: (_c = diagnosticsOpt.pretty) !== null && _c !== void 0 ? _c : true,
@@ -208,7 +223,7 @@ var ConfigSet = (function () {
208
223
  };
209
224
  }
210
225
  this._shouldIgnoreDiagnosticsForFile = this._diagnostics.exclude.length
211
- ? jest_util_1.globsToMatcher(this._diagnostics.exclude)
226
+ ? (0, jest_util_1.globsToMatcher)(this._diagnostics.exclude)
212
227
  : function () { return false; };
213
228
  this.logger.debug({ diagnostics: this._diagnostics }, 'normalized diagnostics config via ts-jest option');
214
229
  var tsconfigOpt = options.tsconfig;
@@ -220,7 +235,20 @@ var ConfigSet = (function () {
220
235
  var astTransformers = options.astTransformers;
221
236
  if (astTransformers) {
222
237
  var resolveTransformerFunc_1 = function (transformerPath) {
223
- var transformerFunc = require(transformerPath);
238
+ var transformerFunc;
239
+ if ((0, path_1.extname)(transformerPath) === '.ts') {
240
+ var compiledTransformer = importer_1.importer
241
+ .esBuild("Using \"esbuild\" requires this package to be installed.")
242
+ .transformSync((0, fs_1.readFileSync)(transformerPath, 'utf-8'), {
243
+ loader: 'ts',
244
+ format: 'cjs',
245
+ target: 'es2015',
246
+ }).code;
247
+ transformerFunc = requireFromString(compiledTransformer, transformerPath.replace('.ts', '.js'));
248
+ }
249
+ else {
250
+ transformerFunc = require(transformerPath);
251
+ }
224
252
  if (!transformerFunc.version) {
225
253
  _this.logger.warn("The AST transformer {{file}} must have an `export const version = <your_transformer_version>`", { file: transformerPath });
226
254
  }
@@ -240,7 +268,7 @@ var ConfigSet = (function () {
240
268
  });
241
269
  };
242
270
  if (astTransformers.before) {
243
- (_e = this.resolvedTransformers.before) === null || _e === void 0 ? void 0 : _e.push.apply(_e, __spreadArray([], __read(resolveTransformers(astTransformers.before))));
271
+ (_e = this.resolvedTransformers.before) === null || _e === void 0 ? void 0 : _e.push.apply(_e, __spreadArray([], __read(resolveTransformers(astTransformers.before)), false));
244
272
  }
245
273
  if (astTransformers.after) {
246
274
  this.resolvedTransformers = __assign(__assign({}, this.resolvedTransformers), { after: resolveTransformers(astTransformers.after) });
@@ -259,7 +287,7 @@ var ConfigSet = (function () {
259
287
  }
260
288
  };
261
289
  ConfigSet.prototype._resolveTsCacheDir = function () {
262
- this.cacheSuffix = sha1_1.sha1(json_1.stringify({
290
+ this.cacheSuffix = (0, sha1_1.sha1)((0, utils_1.stringify)({
263
291
  version: this.compilerModule.version,
264
292
  digest: this.tsJestDigest,
265
293
  babelConfig: this.babelConfig,
@@ -270,14 +298,14 @@ var ConfigSet = (function () {
270
298
  isolatedModules: this.isolatedModules,
271
299
  diagnostics: this._diagnostics,
272
300
  transformers: Object.values(this.resolvedTransformers)
273
- .reduce(function (prevVal, currentVal) { return __spreadArray(__spreadArray([], __read(prevVal)), [currentVal]); })
274
- .map(function (transformer) { return transformer.name + "-" + transformer.version; }),
301
+ .reduce(function (prevVal, currentVal) { return __spreadArray(__spreadArray([], __read(prevVal), false), [currentVal], false); })
302
+ .map(function (transformer) { return "".concat(transformer.name, "-").concat(transformer.version); }),
275
303
  }));
276
304
  if (!this._jestCfg.cache) {
277
305
  this.logger.debug('file caching disabled');
278
306
  }
279
307
  else {
280
- var res = path_1.join(this._jestCfg.cacheDirectory, 'ts-jest', this.cacheSuffix.substr(0, 2), this.cacheSuffix.substr(2));
308
+ var res = (0, path_1.join)(this._jestCfg.cacheDirectory, 'ts-jest', this.cacheSuffix.substr(0, 2), this.cacheSuffix.substr(2));
281
309
  this.logger.debug({ cacheDirectory: res }, 'will use file caching');
282
310
  this.tsCacheDir = res;
283
311
  }
@@ -345,7 +373,7 @@ var ConfigSet = (function () {
345
373
  !this.babelConfig &&
346
374
  ((nodeJsVer.startsWith('v10') && compilationTarget > this.compilerModule.ScriptTarget.ES2018) ||
347
375
  (nodeJsVer.startsWith('v12') && compilationTarget > this.compilerModule.ScriptTarget.ES2019))) {
348
- var message = 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", {
376
+ 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", {
349
377
  nodeJsVer: process.version,
350
378
  compilationTarget: TARGET_TO_VERSION_MAPPING[compilationTarget],
351
379
  });
@@ -357,11 +385,11 @@ var ConfigSet = (function () {
357
385
  };
358
386
  ConfigSet.prototype._resolveTsConfig = function (compilerOptions, resolvedConfigFile) {
359
387
  var config = { compilerOptions: Object.create(null) };
360
- var basePath = normalize_slashes_1.normalizeSlashes(this.rootDir);
388
+ var basePath = (0, normalize_slashes_1.normalizeSlashes)(this.rootDir);
361
389
  var ts = this.compilerModule;
362
390
  var configFileName = resolvedConfigFile
363
- ? normalize_slashes_1.normalizeSlashes(resolvedConfigFile)
364
- : ts.findConfigFile(normalize_slashes_1.normalizeSlashes(this.rootDir), ts.sys.fileExists);
391
+ ? (0, normalize_slashes_1.normalizeSlashes)(resolvedConfigFile)
392
+ : ts.findConfigFile((0, normalize_slashes_1.normalizeSlashes)(this.rootDir), ts.sys.fileExists);
365
393
  if (configFileName) {
366
394
  this.logger.debug({ tsConfigFileName: configFileName }, 'readTsConfig(): reading', configFileName);
367
395
  var result = ts.readConfigFile(configFileName, ts.sys.readFile);
@@ -369,7 +397,7 @@ var ConfigSet = (function () {
369
397
  return { errors: [result.error], fileNames: [], options: {} };
370
398
  }
371
399
  config = result.config;
372
- basePath = normalize_slashes_1.normalizeSlashes(path_1.dirname(configFileName));
400
+ basePath = (0, normalize_slashes_1.normalizeSlashes)((0, path_1.dirname)(configFileName));
373
401
  }
374
402
  config.compilerOptions = __assign(__assign({}, config.compilerOptions), compilerOptions);
375
403
  return ts.parseJsonConfigFileContent(config, ts.sys, basePath, undefined, configFileName);
@@ -406,7 +434,7 @@ var ConfigSet = (function () {
406
434
  logger ? logger.warn({ error: error }, error.message) : this.logger.warn({ error: error }, error.message);
407
435
  };
408
436
  ConfigSet.prototype.shouldReportDiagnostics = function (filePath) {
409
- var fileExtension = path_1.extname(filePath);
437
+ var fileExtension = (0, path_1.extname)(filePath);
410
438
  return constants_1.JS_JSX_EXTENSIONS.includes(fileExtension)
411
439
  ? this.parsedTsConfig.options.checkJs && !this._shouldIgnoreDiagnosticsForFile(filePath)
412
440
  : !this._shouldIgnoreDiagnosticsForFile(filePath);
@@ -430,9 +458,9 @@ var ConfigSet = (function () {
430
458
  var path = inputPath;
431
459
  var nodeResolved = false;
432
460
  if (path.startsWith('<rootDir>')) {
433
- path = path_1.resolve(path_1.join(this.rootDir, path.substr(9)));
461
+ path = (0, path_1.resolve)((0, path_1.join)(this.rootDir, path.substr(9)));
434
462
  }
435
- else if (!path_1.isAbsolute(path)) {
463
+ else if (!(0, path_1.isAbsolute)(path)) {
436
464
  if (!path.startsWith('.') && nodeResolve) {
437
465
  try {
438
466
  path = require.resolve(path);
@@ -441,7 +469,7 @@ var ConfigSet = (function () {
441
469
  catch (_) { }
442
470
  }
443
471
  if (!nodeResolved) {
444
- path = path_1.resolve(this.cwd, path);
472
+ path = (0, path_1.resolve)(this.cwd, path);
445
473
  }
446
474
  }
447
475
  if (!nodeResolved && nodeResolve) {
@@ -451,8 +479,8 @@ var ConfigSet = (function () {
451
479
  }
452
480
  catch (_) { }
453
481
  }
454
- if (throwIfMissing && !fs_1.existsSync(path)) {
455
- throw new Error(messages_1.interpolate("File not found: {{inputPath}} (resolved as: {{resolvedPath}})", { inputPath: inputPath, resolvedPath: path }));
482
+ if (throwIfMissing && !(0, fs_1.existsSync)(path)) {
483
+ throw new Error((0, messages_1.interpolate)("File not found: {{inputPath}} (resolved as: {{resolvedPath}})", { inputPath: inputPath, resolvedPath: path }));
456
484
  }
457
485
  this.logger.debug({ fromPath: inputPath, toPath: path }, 'resolved path from', inputPath, 'to', path);
458
486
  return path;
@@ -0,0 +1,2 @@
1
+ export * from './config-set';
2
+ export * from './paths-to-module-name-mapper';
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./config-set"), exports);
14
+ __exportStar(require("./paths-to-module-name-mapper"), exports);
@@ -14,10 +14,10 @@ var _a;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.pathsToModuleNameMapper = void 0;
16
16
  var bs_logger_1 = require("bs-logger");
17
- var logger_1 = require("../utils/logger");
17
+ var utils_1 = require("../utils");
18
18
  var messages_1 = require("../utils/messages");
19
19
  var escapeRegex = function (str) { return str.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&'); };
20
- var logger = logger_1.rootLogger.child((_a = {}, _a[bs_logger_1.LogContexts.namespace] = 'path-mapper', _a));
20
+ var logger = utils_1.rootLogger.child((_a = {}, _a[bs_logger_1.LogContexts.namespace] = 'path-mapper', _a));
21
21
  var pathsToModuleNameMapper = function (mapping, _a) {
22
22
  var e_1, _b;
23
23
  var _c = _a === void 0 ? Object.create(null) : _a, _d = _c.prefix, prefix = _d === void 0 ? '' : _d;
@@ -28,29 +28,29 @@ var pathsToModuleNameMapper = function (mapping, _a) {
28
28
  var pattern = void 0;
29
29
  var toPaths = mapping[fromPath];
30
30
  if (toPaths.length === 0) {
31
- logger.warn(messages_1.interpolate("Not mapping \"{{path}}\" because it has no target.", { path: fromPath }));
31
+ logger.warn((0, messages_1.interpolate)("Not mapping \"{{path}}\" because it has no target.", { path: fromPath }));
32
32
  continue;
33
33
  }
34
34
  var segments = fromPath.split(/\*/g);
35
35
  if (segments.length === 1) {
36
36
  var paths = toPaths.map(function (target) {
37
- var enrichedPrefix = prefix !== '' && !prefix.endsWith('/') ? prefix + "/" : prefix;
38
- return "" + enrichedPrefix + target;
37
+ var enrichedPrefix = prefix !== '' && !prefix.endsWith('/') ? "".concat(prefix, "/") : prefix;
38
+ return "".concat(enrichedPrefix).concat(target);
39
39
  });
40
- pattern = "^" + escapeRegex(fromPath) + "$";
40
+ pattern = "^".concat(escapeRegex(fromPath), "$");
41
41
  jestMap[pattern] = paths.length === 1 ? paths[0] : paths;
42
42
  }
43
43
  else if (segments.length === 2) {
44
44
  var paths = toPaths.map(function (target) {
45
45
  var enrichedTarget = target.startsWith('./') && prefix !== '' ? target.substring(target.indexOf('/') + 1) : target;
46
- var enrichedPrefix = prefix !== '' && !prefix.endsWith('/') ? prefix + "/" : prefix;
47
- return "" + enrichedPrefix + enrichedTarget.replace(/\*/g, '$1');
46
+ var enrichedPrefix = prefix !== '' && !prefix.endsWith('/') ? "".concat(prefix, "/") : prefix;
47
+ return "".concat(enrichedPrefix).concat(enrichedTarget.replace(/\*/g, '$1'));
48
48
  });
49
- pattern = "^" + escapeRegex(segments[0]) + "(.*)" + escapeRegex(segments[1]) + "$";
49
+ pattern = "^".concat(escapeRegex(segments[0]), "(.*)").concat(escapeRegex(segments[1]), "$");
50
50
  jestMap[pattern] = paths.length === 1 ? paths[0] : paths;
51
51
  }
52
52
  else {
53
- logger.warn(messages_1.interpolate("Not mapping \"{{path}}\" because it has more than one star (`*`).", { path: fromPath }));
53
+ logger.warn((0, messages_1.interpolate)("Not mapping \"{{path}}\" because it has more than one star (`*`).", { path: fromPath }));
54
54
  }
55
55
  }
56
56
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,12 @@
1
1
  import { TsJestTransformer } from './ts-jest-transformer';
2
+ export * from './constants';
3
+ export * from './compiler';
4
+ export * from './config';
5
+ export * from './presets/create-jest-preset';
6
+ export * from './utils';
7
+ export * from './raw-compiler-options';
8
+ export * from './ts-jest-transformer';
9
+ export * from './types';
2
10
  declare const _default: {
3
11
  createTransformer: () => TsJestTransformer;
4
12
  };
package/dist/index.js CHANGED
@@ -1,6 +1,24 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
2
12
  Object.defineProperty(exports, "__esModule", { value: true });
3
13
  var ts_jest_transformer_1 = require("./ts-jest-transformer");
14
+ __exportStar(require("./constants"), exports);
15
+ __exportStar(require("./compiler"), exports);
16
+ __exportStar(require("./config"), exports);
17
+ __exportStar(require("./presets/create-jest-preset"), exports);
18
+ __exportStar(require("./utils"), exports);
19
+ __exportStar(require("./raw-compiler-options"), exports);
20
+ __exportStar(require("./ts-jest-transformer"), exports);
21
+ __exportStar(require("./types"), exports);
4
22
  exports.default = {
5
23
  createTransformer: function () { return new ts_jest_transformer_1.TsJestTransformer(); },
6
24
  };
@@ -12,8 +12,8 @@ var __assign = (this && this.__assign) || function () {
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.createJestPreset = void 0;
15
- var logger_1 = require("../utils/logger");
16
- var logger = logger_1.rootLogger.child({ namespace: 'jest-preset' });
15
+ var utils_1 = require("../utils");
16
+ var logger = utils_1.rootLogger.child({ namespace: 'jest-preset' });
17
17
  function createJestPreset(allowJs, extraOptions) {
18
18
  var _a;
19
19
  if (allowJs === void 0) { allowJs = false; }
@@ -1,2 +1,5 @@
1
- export declare const version = 1;
1
+ import type _ts from 'typescript';
2
+ import type { TsCompilerInstance } from '../types';
3
+ export declare const version = 3;
2
4
  export declare const name = "hoist-jest";
5
+ export declare function factory({ configSet }: TsCompilerInstance): (ctx: _ts.TransformationContext) => _ts.Transformer<_ts.SourceFile>;