ts-jest 26.0.0 → 26.1.3

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 (42) hide show
  1. package/.ts-jest-digest +1 -1
  2. package/CHANGELOG.md +53 -0
  3. package/dist/cli/config/init.js +1 -0
  4. package/dist/cli/config/migrate.js +1 -0
  5. package/dist/cli/help.js +1 -0
  6. package/dist/cli/helpers/presets.js +6 -4
  7. package/dist/cli/index.js +1 -0
  8. package/dist/compiler/instance.js +13 -55
  9. package/dist/compiler/language-service.js +157 -25
  10. package/dist/compiler/transpiler.js +2 -9
  11. package/dist/config/config-set.d.ts +2 -1
  12. package/dist/config/config-set.js +65 -39
  13. package/dist/config/create-jest-preset.d.ts +1 -5
  14. package/dist/config/create-jest-preset.js +1 -0
  15. package/dist/config/paths-to-module-name-mapper.d.ts +4 -3
  16. package/dist/config/paths-to-module-name-mapper.js +5 -9
  17. package/dist/constants.js +1 -0
  18. package/dist/index.d.ts +111 -1
  19. package/dist/index.js +1 -0
  20. package/dist/transformers/hoist-jest.js +1 -0
  21. package/dist/transformers/index.js +1 -0
  22. package/dist/ts-jest-transformer.js +6 -5
  23. package/dist/types.d.ts +4 -11
  24. package/dist/util/backports.js +1 -0
  25. package/dist/util/exported.js +3 -3
  26. package/dist/util/get-package-version.js +1 -0
  27. package/dist/util/importer.js +2 -1
  28. package/dist/util/json.js +1 -0
  29. package/dist/util/jsonable-value.js +3 -2
  30. package/dist/util/logger.js +1 -0
  31. package/dist/util/memoize.js +1 -0
  32. package/dist/util/messages.js +1 -0
  33. package/dist/util/normalize-slashes.js +1 -0
  34. package/dist/util/sha1.js +1 -0
  35. package/dist/util/testing.js +1 -0
  36. package/dist/util/ts-error.js +1 -0
  37. package/dist/util/version-checkers.js +1 -0
  38. package/jest-base.js +12 -0
  39. package/package.json +10 -14
  40. package/tsconfig.spec.json +4 -0
  41. package/dist/compiler/compiler-utils.d.ts +0 -1
  42. package/dist/compiler/compiler-utils.js +0 -33
package/.ts-jest-digest CHANGED
@@ -1 +1 @@
1
- da6ae4997a1aa7d8530ada1d1bcd5472c3da9a71
1
+ 1b4f2f24dd078873082b82fa6c70d7029f0c60ab
package/CHANGELOG.md CHANGED
@@ -1,3 +1,56 @@
1
+ ## [26.1.3](https://github.com/kulshekhar/ts-jest/compare/v26.1.2...v26.1.3) (2020-07-16)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * revert [#1793](https://github.com/kulshekhar/ts-jest/issues/1793) ([#1804](https://github.com/kulshekhar/ts-jest/issues/1804)) ([5095525](https://github.com/kulshekhar/ts-jest/commit/5095525333c8579c9c5e7f3149294b31f28d6774))
7
+
8
+
9
+
10
+ ## [26.1.2](https://github.com/kulshekhar/ts-jest/compare/v26.1.1...v26.1.2) (2020-07-13)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **compiler:** use `resolveModuleNames` TypeScript API to get resolved modules for test files ([#1784](https://github.com/kulshekhar/ts-jest/issues/1784)) ([5f26054](https://github.com/kulshekhar/ts-jest/commit/5f2605457e94b548bd7b9b28fc968554f7eefa91)), closes [#1747](https://github.com/kulshekhar/ts-jest/issues/1747)
16
+ * **config:** invalidate cache when other options in `tsconfig` change ([#1788](https://github.com/kulshekhar/ts-jest/issues/1788)) ([6948855](https://github.com/kulshekhar/ts-jest/commit/69488552eca2846f3fc6ba86ab49d7893caaf521))
17
+
18
+
19
+ ### Performance Improvements
20
+
21
+ * **compiler:** cache module resolution for `isolatedModules: false` ([#1786](https://github.com/kulshekhar/ts-jest/issues/1786)) ([7f731ed](https://github.com/kulshekhar/ts-jest/commit/7f731ed8a02755aeb41ecb27df4eaf16db2ddd95))
22
+ * **compiler:** use `globsToMatcher` from `jest-util` ([#1754](https://github.com/kulshekhar/ts-jest/issues/1754)) ([44f3913](https://github.com/kulshekhar/ts-jest/commit/44f3913c2a017734ed87346b1c5fbec639d02062))
23
+
24
+
25
+
26
+ <a name="26.1.1"></a>
27
+ ## [26.1.1](https://github.com/kulshekhar/ts-jest/compare/v26.1.0...v26.1.1) (2020-06-21)
28
+
29
+
30
+ ### Bug Fixes
31
+
32
+ * **compiler:** generate source map correctly when tsconfig `mapRoot` is set ([#1741](https://github.com/kulshekhar/ts-jest/issues/1741)) ([01ac417](https://github.com/kulshekhar/ts-jest/commit/01ac417)), closes [#1718](https://github.com/kulshekhar/ts-jest/issues/1718)
33
+ * **config:** show version warning when using ts-jest without babel ([#1729](https://github.com/kulshekhar/ts-jest/issues/1729)) ([e512bc0](https://github.com/kulshekhar/ts-jest/commit/e512bc0)), fixes [#1678-issuecomment-641930332](https://github.com//github.com/kulshekhar/ts-jest/pull/1678/issues/issuecomment-641930332), [#1678-issuecomment-639528993](https://github.com//github.com/kulshekhar/ts-jest/pull/1678/issues/issuecomment-639528993)
34
+
35
+
36
+
37
+ <a name="26.1.0"></a>
38
+ # [26.1.0](https://github.com/kulshekhar/ts-jest/compare/v26.0.0...v26.1.0) (2020-05-30)
39
+
40
+
41
+ ### Bug Fixes
42
+
43
+ * **typing:** don't mark `BabelConfig` as internal type ([#1667](https://github.com/kulshekhar/ts-jest/issues/1667)) ([558c307](https://github.com/kulshekhar/ts-jest/commit/558c307)), closes [#1666](https://github.com/kulshekhar/ts-jest/issues/1666)
44
+
45
+
46
+ ### Features
47
+
48
+ * **config:** show a warning message when TypeScript `target` version doesn't match with recommended NodeJs version ([#1678](https://github.com/kulshekhar/ts-jest/issues/1678)) ([085bdf5](https://github.com/kulshekhar/ts-jest/commit/085bdf5))
49
+ * **config:** support multiple paths for `pathsToModuleNameMapper` ([#1690](https://github.com/kulshekhar/ts-jest/issues/1690)) ([a727bd5](https://github.com/kulshekhar/ts-jest/commit/a727bd5))
50
+ * support TypeScript 3.9 ([#1653](https://github.com/kulshekhar/ts-jest/issues/1653)) ([fc3d5ad](https://github.com/kulshekhar/ts-jest/commit/fc3d5ad))
51
+
52
+
53
+
1
54
  <a name="26.0.0"></a>
2
55
  # [26.0.0](https://github.com/kulshekhar/ts-jest/compare/v25.5.1...v26.0.0) (2020-05-15)
3
56
 
@@ -47,6 +47,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
47
47
  }
48
48
  };
49
49
  Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.help = exports.run = void 0;
50
51
  var fs_1 = require("fs");
51
52
  var json5_1 = require("json5");
52
53
  var path_1 = require("path");
@@ -56,6 +56,7 @@ var __spread = (this && this.__spread) || function () {
56
56
  return ar;
57
57
  };
58
58
  Object.defineProperty(exports, "__esModule", { value: true });
59
+ exports.help = exports.run = void 0;
59
60
  var bs_logger_1 = require("bs-logger");
60
61
  var stableStringify = require("fast-json-stable-stringify");
61
62
  var fs_1 = require("fs");
package/dist/cli/help.js CHANGED
@@ -36,6 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.help = exports.run = void 0;
39
40
  exports.run = function (_) { return __awaiter(void 0, void 0, void 0, function () {
40
41
  return __generator(this, function (_a) {
41
42
  process.stdout.write("\nUsage:\n ts-jest command [options] [...args]\n\nCommands:\n config:init Creates initial Jest configuration\n config:migrate Migrates a given Jest configuration\n help [command] Show this help, or help about a command\n\nExample:\n ts-jest help config:migrate\n");
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.jsWIthBabel = exports.jsWithTs = exports.defaults = exports.allPresets = void 0;
3
4
  var definePreset = function (fullName) { return ({
4
5
  fullName: fullName,
5
6
  get name() {
@@ -11,10 +12,11 @@ var definePreset = function (fullName) { return ({
11
12
  get jsVarName() {
12
13
  return this.isDefault
13
14
  ? 'defaults'
14
- : fullName
15
- .split('/')
16
- .pop()
17
- .replace(/\-([a-z])/g, function (_, l) { return l.toUpperCase(); });
15
+ :
16
+ fullName
17
+ .split('/')
18
+ .pop()
19
+ .replace(/\-([a-z])/g, function (_, l) { return l.toUpperCase(); });
18
20
  },
19
21
  get value() {
20
22
  return require("../../../" + fullName.replace(/^ts-jest\//, '') + "/jest-preset");
package/dist/cli/index.js CHANGED
@@ -37,6 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  var _a;
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.processArgv = void 0;
40
41
  var bs_logger_1 = require("bs-logger");
41
42
  var yargsParser = require("yargs-parser");
42
43
  var logger_1 = require("../util/logger");
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __read = (this && this.__read) || function (o, n) {
14
3
  var m = typeof Symbol === "function" && o[Symbol.iterator];
15
4
  if (!m) return o;
@@ -27,70 +16,39 @@ var __read = (this && this.__read) || function (o, n) {
27
16
  return ar;
28
17
  };
29
18
  Object.defineProperty(exports, "__esModule", { value: true });
30
- var fs_1 = require("fs");
31
- var mkdirp = require("mkdirp");
32
- var path_1 = require("path");
33
- var compiler_utils_1 = require("./compiler-utils");
19
+ exports.createCompilerInstance = void 0;
34
20
  var language_service_1 = require("./language-service");
35
21
  var transpiler_1 = require("./transpiler");
36
- function updateOutput(outputText, normalizedFileName, sourceMap, getExtension) {
37
- var base = path_1.basename(normalizedFileName);
22
+ var json_1 = require("../util/json");
23
+ var SOURCE_MAPPING_PREFIX = 'sourceMappingURL=';
24
+ function updateOutput(outputText, normalizedFileName, sourceMap) {
38
25
  var base64Map = Buffer.from(updateSourceMap(sourceMap, normalizedFileName), 'utf8').toString('base64');
39
26
  var sourceMapContent = "data:application/json;charset=utf-8;base64," + base64Map;
40
- var sourceMapLength = (base + ".map").length + (getExtension(normalizedFileName).length - path_1.extname(normalizedFileName).length);
41
- return outputText.slice(0, -sourceMapLength) + sourceMapContent;
27
+ return (outputText.slice(0, outputText.lastIndexOf(SOURCE_MAPPING_PREFIX) + SOURCE_MAPPING_PREFIX.length) + sourceMapContent);
42
28
  }
43
29
  var updateSourceMap = function (sourceMapText, normalizedFileName) {
44
30
  var sourceMap = JSON.parse(sourceMapText);
45
31
  sourceMap.file = normalizedFileName;
46
32
  sourceMap.sources = [normalizedFileName];
47
33
  delete sourceMap.sourceRoot;
48
- return JSON.stringify(sourceMap);
34
+ return json_1.stringify(sourceMap);
49
35
  };
50
- var compileAndCacheResult = function (memoryCache, compileFn, getExtension, logger) { return function (code, fileName, lineOffset) {
51
- logger.debug({ fileName: fileName }, 'compileAndCacheResult(): get compile output');
36
+ var compileAndUpdateOutput = function (compileFn, logger) { return function (code, fileName, lineOffset) {
37
+ logger.debug({ fileName: fileName }, 'compileAndUpdateOutput(): get compile output');
52
38
  var _a = __read(compileFn(code, fileName, lineOffset), 2), value = _a[0], sourceMap = _a[1];
53
- var output = updateOutput(value, fileName, sourceMap, getExtension);
54
- memoryCache.files.set(fileName, __assign(__assign({}, memoryCache.files.get(fileName)), { output: output }));
55
- return output;
39
+ return updateOutput(value, fileName, sourceMap);
56
40
  }; };
57
41
  exports.createCompilerInstance = function (configs) {
58
42
  var logger = configs.logger.child({ namespace: 'ts-compiler' });
59
43
  var compilerOptions = configs.parsedTsConfig.options, tsJest = configs.tsJest;
60
- var cacheDir = configs.tsCacheDir;
61
- var ts = configs.compilerModule;
62
44
  var extensions = ['.ts', '.tsx'];
63
- var memoryCache = {
64
- files: new Map(),
65
- resolvedModules: Object.create(null),
66
- };
67
45
  if (compilerOptions.allowJs) {
68
46
  extensions.push('.js');
69
47
  extensions.push('.jsx');
70
48
  }
71
- if (cacheDir) {
72
- mkdirp.sync(cacheDir);
73
- try {
74
- var fsMemoryCache = fs_1.readFileSync(compiler_utils_1.getResolvedModulesCache(cacheDir), 'utf-8');
75
- memoryCache.resolvedModules = JSON.parse(fsMemoryCache);
76
- }
77
- catch (e) { }
78
- }
79
- configs.parsedTsConfig.fileNames.forEach(function (fileName) {
80
- memoryCache.files.set(fileName, {
81
- version: 0,
82
- });
83
- });
84
- var getExtension = compilerOptions.jsx === ts.JsxEmit.Preserve
85
- ? function (path) { return (/\.[tj]sx$/.test(path) ? '.jsx' : '.js'); }
86
- : function (_) { return '.js'; };
87
- var compilerInstance;
88
- if (!tsJest.isolatedModules) {
89
- compilerInstance = language_service_1.initializeLanguageServiceInstance(configs, memoryCache, logger);
90
- }
91
- else {
92
- compilerInstance = transpiler_1.initializeTranspilerInstance(configs, memoryCache, logger);
93
- }
94
- var compile = compileAndCacheResult(memoryCache, compilerInstance.compileFn, getExtension, logger);
49
+ var compilerInstance = !tsJest.isolatedModules
50
+ ? language_service_1.initializeLanguageServiceInstance(configs, logger)
51
+ : transpiler_1.initializeTranspilerInstance(configs, logger);
52
+ var compile = compileAndUpdateOutput(compilerInstance.compileFn, logger);
95
53
  return { cwd: configs.cwd, compile: compile, program: compilerInstance.program };
96
54
  };
@@ -1,4 +1,51 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ 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;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
2
49
  var __read = (this && this.__read) || function (o, n) {
3
50
  var m = typeof Symbol === "function" && o[Symbol.iterator];
4
51
  if (!m) return o;
@@ -19,35 +66,98 @@ var __spread = (this && this.__spread) || function () {
19
66
  for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
20
67
  return ar;
21
68
  };
69
+ var __values = (this && this.__values) || function(o) {
70
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
71
+ if (m) return m.call(o);
72
+ if (o && typeof o.length === "number") return {
73
+ next: function () {
74
+ if (o && i >= o.length) o = void 0;
75
+ return { value: o && o[i++], done: !o };
76
+ }
77
+ };
78
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
79
+ };
22
80
  Object.defineProperty(exports, "__esModule", { value: true });
81
+ exports.initializeLanguageServiceInstance = void 0;
23
82
  var bs_logger_1 = require("bs-logger");
83
+ var fs_1 = require("fs");
24
84
  var path_1 = require("path");
85
+ var memoize = require("lodash.memoize");
86
+ var mkdirp = require("mkdirp");
25
87
  var constants_1 = require("../constants");
26
88
  var messages_1 = require("../util/messages");
27
- var compiler_utils_1 = require("./compiler-utils");
28
- var memoize = require("lodash.memoize");
29
- function doTypeChecking(configs, fileName, service, logger) {
89
+ var json_1 = require("../util/json");
90
+ var sha1_1 = require("../util/sha1");
91
+ function doTypeChecking(configs, diagnosedFiles, fileName, service, logger) {
30
92
  if (configs.shouldReportDiagnostic(fileName)) {
31
93
  var diagnostics = service.getSemanticDiagnostics(fileName).concat(service.getSyntacticDiagnostics(fileName));
94
+ diagnosedFiles.push(fileName);
32
95
  configs.raiseDiagnostics(diagnostics, fileName, logger);
33
96
  }
34
97
  }
35
- exports.initializeLanguageServiceInstance = function (configs, memoryCache, logger) {
98
+ exports.initializeLanguageServiceInstance = function (configs, logger) {
36
99
  var _a;
37
100
  logger.debug('initializeLanguageServiceInstance(): create typescript compiler');
38
101
  var ts = configs.compilerModule;
39
102
  var cwd = configs.cwd;
40
103
  var cacheDir = configs.tsCacheDir;
41
104
  var _b = configs.parsedTsConfig, options = _b.options, fileNames = _b.fileNames;
105
+ var diagnosedFiles = [];
42
106
  var serviceHostTraceCtx = (_a = {
43
107
  namespace: 'ts:serviceHost',
44
108
  call: null
45
109
  },
46
110
  _a[bs_logger_1.LogContexts.logLevel] = bs_logger_1.LogLevels.trace,
47
111
  _a);
112
+ var memoryCache = {
113
+ files: new Map(),
114
+ resolvedModules: new Map(),
115
+ };
116
+ var tsResolvedModulesCachePath;
117
+ if (cacheDir) {
118
+ mkdirp.sync(cacheDir);
119
+ tsResolvedModulesCachePath = path_1.join(cacheDir, sha1_1.sha1('ts-jest-resolved-modules', '\x00'));
120
+ try {
121
+ var cachedTSResolvedModules = fs_1.readFileSync(tsResolvedModulesCachePath, 'utf-8');
122
+ memoryCache.resolvedModules = new Map(json_1.parse(cachedTSResolvedModules));
123
+ }
124
+ catch (e) { }
125
+ }
126
+ configs.parsedTsConfig.fileNames.forEach(function (fileName) {
127
+ memoryCache.files.set(fileName, {
128
+ version: 0,
129
+ });
130
+ });
48
131
  function isFileInCache(fileName) {
49
132
  return memoryCache.files.has(fileName) && memoryCache.files.get(fileName).version !== 0;
50
133
  }
134
+ var cacheReadFile = logger.wrap(serviceHostTraceCtx, 'readFile', memoize(ts.sys.readFile));
135
+ var moduleResolutionHost = {
136
+ fileExists: memoize(ts.sys.fileExists),
137
+ readFile: cacheReadFile,
138
+ directoryExists: memoize(ts.sys.directoryExists),
139
+ getCurrentDirectory: function () { return cwd; },
140
+ realpath: ts.sys.realpath && memoize(ts.sys.realpath),
141
+ getDirectories: memoize(ts.sys.getDirectories),
142
+ };
143
+ var moduleResolutionCache = ts.createModuleResolutionCache(cwd, function (x) { return x; }, options);
144
+ function resolveModuleNames(moduleNames, containingFile) {
145
+ var _a;
146
+ var normalizedContainingFile = path_1.normalize(containingFile);
147
+ var currentResolvedModules = (_a = memoryCache.resolvedModules.get(normalizedContainingFile)) !== null && _a !== void 0 ? _a : [];
148
+ return moduleNames.map(function (moduleName) {
149
+ var resolveModuleName = ts.resolveModuleName(moduleName, containingFile, options, moduleResolutionHost, moduleResolutionCache);
150
+ var resolvedModule = resolveModuleName.resolvedModule;
151
+ if (configs.isTestFile(normalizedContainingFile) && resolvedModule) {
152
+ var normalizedResolvedFileName = path_1.normalize(resolvedModule.resolvedFileName);
153
+ if (!currentResolvedModules.includes(normalizedResolvedFileName)) {
154
+ currentResolvedModules.push(normalizedResolvedFileName);
155
+ memoryCache.resolvedModules.set(normalizedContainingFile, currentResolvedModules);
156
+ }
157
+ }
158
+ return resolvedModule;
159
+ });
160
+ }
51
161
  var projectVersion = 1;
52
162
  var updateMemoryCache = function (contents, fileName) {
53
163
  logger.debug({ fileName: fileName }, 'updateMemoryCache(): update memory cache for language service');
@@ -89,11 +199,11 @@ exports.initializeLanguageServiceInstance = function (configs, memoryCache, logg
89
199
  getScriptSnapshot: function (fileName) {
90
200
  var _a;
91
201
  var normalizedFileName = path_1.normalize(fileName);
92
- var hit = memoryCache.files.has(normalizedFileName) && memoryCache.files.get(normalizedFileName).version !== 0;
202
+ var hit = isFileInCache(normalizedFileName);
93
203
  logger.trace({ normalizedFileName: normalizedFileName, cacheHit: hit }, 'getScriptSnapshot():', 'cache', hit ? 'hit' : 'miss');
94
204
  if (!hit) {
95
205
  memoryCache.files.set(normalizedFileName, {
96
- text: ts.sys.readFile(normalizedFileName),
206
+ text: cacheReadFile(normalizedFileName),
97
207
  version: 1,
98
208
  });
99
209
  }
@@ -103,42 +213,63 @@ exports.initializeLanguageServiceInstance = function (configs, memoryCache, logg
103
213
  return ts.ScriptSnapshot.fromString(contents);
104
214
  },
105
215
  fileExists: memoize(ts.sys.fileExists),
106
- readFile: logger.wrap(serviceHostTraceCtx, 'readFile', memoize(ts.sys.readFile)),
216
+ readFile: cacheReadFile,
107
217
  readDirectory: memoize(ts.sys.readDirectory),
108
218
  getDirectories: memoize(ts.sys.getDirectories),
109
219
  directoryExists: memoize(ts.sys.directoryExists),
110
- realpath: memoize(ts.sys.realpath),
220
+ realpath: ts.sys.realpath && memoize(ts.sys.realpath),
111
221
  getNewLine: function () { return constants_1.LINE_FEED; },
112
222
  getCurrentDirectory: function () { return cwd; },
113
223
  getCompilationSettings: function () { return options; },
114
224
  getDefaultLibFileName: function () { return ts.getDefaultLibFilePath(options); },
115
225
  getCustomTransformers: function () { return configs.tsCustomTransformers; },
226
+ resolveModuleNames: resolveModuleNames,
116
227
  };
117
228
  logger.debug('initializeLanguageServiceInstance(): creating language service');
118
229
  var service = ts.createLanguageService(serviceHost, ts.createDocumentRegistry());
119
230
  return {
120
231
  compileFn: function (code, fileName) {
232
+ var e_1, _a;
233
+ var _b;
121
234
  logger.debug({ fileName: fileName }, 'compileFn(): compiling using language service');
122
235
  updateMemoryCache(code, fileName);
123
236
  var output = service.getEmitOutput(fileName);
124
- logger.debug({ fileName: fileName }, 'compileFn(): computing diagnostics using language service');
125
- doTypeChecking(configs, fileName, service, logger);
126
- if (cacheDir) {
127
- if (compiler_utils_1.isTestFile(configs.testMatchPatterns, fileName)) {
128
- compiler_utils_1.cacheResolvedModules(fileName, code, memoryCache, service.getProgram(), cacheDir, logger);
129
- }
130
- else {
131
- Object.entries(memoryCache.resolvedModules)
132
- .filter(function (entry) {
133
- return entry[1].modulePaths.find(function (modulePath) { return modulePath === fileName; }) && !memoryCache.files.has(entry[0]);
134
- })
135
- .forEach(function (entry) {
136
- var testFileName = entry[0];
137
- var testFileContent = entry[1].testFileContent;
138
- logger.debug({ fileName: fileName }, 'compileFn(): computing diagnostics for test file that imports this module using language service');
139
- updateMemoryCache(testFileContent, testFileName);
140
- doTypeChecking(configs, testFileName, service, logger);
237
+ if (tsResolvedModulesCachePath) {
238
+ void (function () { return __awaiter(void 0, void 0, void 0, function () {
239
+ return __generator(this, function (_a) {
240
+ switch (_a.label) {
241
+ case 0: return [4, fs_1.writeFile(tsResolvedModulesCachePath, json_1.stringify(__spread(memoryCache.resolvedModules)), function () { })];
242
+ case 1:
243
+ _a.sent();
244
+ return [2];
245
+ }
141
246
  });
247
+ }); })();
248
+ }
249
+ if (!diagnosedFiles.includes(fileName)) {
250
+ logger.debug({ fileName: fileName }, 'compileFn(): computing diagnostics using language service');
251
+ doTypeChecking(configs, diagnosedFiles, fileName, service, logger);
252
+ }
253
+ if (!configs.isTestFile(fileName)) {
254
+ try {
255
+ for (var _c = __values(memoryCache.resolvedModules.entries()), _d = _c.next(); !_d.done; _d = _c.next()) {
256
+ var _e = __read(_d.value, 2), testFileName = _e[0], resolvedModules = _e[1];
257
+ if (resolvedModules.includes(fileName) && !diagnosedFiles.includes(testFileName)) {
258
+ var testFileContent = (_b = memoryCache.files.get(testFileName)) === null || _b === void 0 ? void 0 : _b.text;
259
+ if (!testFileContent) {
260
+ updateMemoryCache(cacheReadFile(testFileName), testFileName);
261
+ }
262
+ logger.debug({ testFileName: testFileName }, 'compileFn(): computing diagnostics using language service for test file which uses the module');
263
+ doTypeChecking(configs, diagnosedFiles, testFileName, service, logger);
264
+ }
265
+ }
266
+ }
267
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
268
+ finally {
269
+ try {
270
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
271
+ }
272
+ finally { if (e_1) throw e_1.error; }
142
273
  }
143
274
  }
144
275
  if (output.emitSkipped) {
@@ -149,6 +280,7 @@ exports.initializeLanguageServiceInstance = function (configs, memoryCache, logg
149
280
  file: path_1.basename(fileName),
150
281
  }));
151
282
  }
283
+ memoryCache.files.set(fileName, __assign(__assign({}, memoryCache.files.get(fileName)), { output: output.outputFiles[1].text }));
152
284
  return [output.outputFiles[1].text, output.outputFiles[0].text];
153
285
  },
154
286
  program: service.getProgram(),
@@ -1,20 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initializeTranspilerInstance = function (configs, memoryCache, logger) {
3
+ exports.initializeTranspilerInstance = void 0;
4
+ exports.initializeTranspilerInstance = function (configs, logger) {
4
5
  logger.debug('initializeTranspilerInstance(): create typescript compiler');
5
6
  var _a = configs.parsedTsConfig, options = _a.options, fileNames = _a.fileNames;
6
7
  var ts = configs.compilerModule;
7
8
  var program = ts.createProgram(fileNames, options);
8
- var updateFileInCache = function (contents, filePath) {
9
- var file = memoryCache.files.get(filePath);
10
- if (file && file.text !== contents) {
11
- file.version++;
12
- file.text = contents;
13
- }
14
- };
15
9
  return {
16
10
  compileFn: function (code, fileName) {
17
- updateFileInCache(code, fileName);
18
11
  logger.debug({ fileName: fileName }, 'compileFn(): compiling as isolated module');
19
12
  var result = ts.transpileModule(code, {
20
13
  fileName: fileName,
@@ -1,9 +1,10 @@
1
1
  import { Config } from '@jest/types';
2
2
  import { Logger } from 'bs-logger';
3
- import { TsCompiler, TsJestGlobalOptions } from '../types';
3
+ import { TsCompiler, TsJestGlobalOptions, TTypeScript } from '../types';
4
4
  export declare class ConfigSet {
5
5
  readonly parentOptions?: TsJestGlobalOptions | undefined;
6
6
  get versions(): Record<string, string>;
7
+ get compilerModule(): TTypeScript;
7
8
  get tsCompiler(): TsCompiler;
8
9
  get tsJestDigest(): string;
9
10
  readonly logger: Logger;