ts-jest 25.3.1 → 25.5.0

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.
package/.ts-jest-digest CHANGED
@@ -1 +1 @@
1
- 840c7c291dbb4a5eddb2c5a03648044e3226c061
1
+ a17070bc22b8d4dcc13d502438e8b25aba2ac38d
package/CHANGELOG.md CHANGED
@@ -1,39 +1,122 @@
1
- <a name="25.3.1"></a>
2
- ## [25.3.1](https://github.com/kulshekhar/ts-jest/compare/v25.3.0...v25.3.1) (2020-04-03)
1
+ <a name="25.5.0"></a>
2
+ # [25.5.0](https://github.com/kulshekhar/ts-jest/compare/v25.4.0...v25.5.0) (2020-05-05)
3
3
 
4
4
 
5
5
  ### Bug Fixes
6
6
 
7
- * only do type checking while compiling file ([#1483](https://github.com/kulshekhar/ts-jest/issues/1483)) ([dbc0a08](https://github.com/kulshekhar/ts-jest/commit/dbc0a08))
8
- * **config:** set default outDir for enabled allowJs without outDir ([#1472](https://github.com/kulshekhar/ts-jest/issues/1472)) ([57c7af0](https://github.com/kulshekhar/ts-jest/commit/57c7af0))
7
+ * **compiler:** make `projectReferences` work with `isolatedModules: false` ([#1541](https://github.com/kulshekhar/ts-jest/issues/1541)) ([3e8efbe](https://github.com/kulshekhar/ts-jest/commit/3e8efbe))
8
+ * **compiler:** allow using `files` provided by `tsconfig` ([#1562](https://github.com/kulshekhar/ts-jest/issues/1562)) ([a9f02bd](https://github.com/kulshekhar/ts-jest/commit/a9f02bd))
9
+ * **config:** verify `testMatchPatterns` contain RegExp instance or string type values ([#1569](https://github.com/kulshekhar/ts-jest/issues/1569)) ([7f85bab](https://github.com/kulshekhar/ts-jest/commit/7f85bab))
9
10
 
10
11
 
12
+ ### Features
11
13
 
12
- <a name="25.3.0"></a>
13
- # [25.3.0](https://github.com/kulshekhar/ts-jest/compare/25.2.1...v25.3.0) (2020-03-30)
14
+ * **config:** add `tsconfig` alias to `tsConfig` option ([#1565](https://github.com/kulshekhar/ts-jest/issues/1565)) ([c10eb6d](https://github.com/kulshekhar/ts-jest/commit/c10eb6d))
15
+ * **config:** define 'ts-jest' on `ConfigGlobals` interface of `@jest/types` ([#1592](https://github.com/kulshekhar/ts-jest/issues/1592)) ([4526392](https://github.com/kulshekhar/ts-jest/commit/4526392))
14
16
 
15
17
 
16
- ### Bug Fixes
18
+ ### Performance Improvements
17
19
 
18
- * add jest-config to dependencies list ([6d9e0d8](https://github.com/kulshekhar/ts-jest/commit/6d9e0d8))
19
- * always do type check for all files provided to ts-jest transformer ([#1450](https://github.com/kulshekhar/ts-jest/issues/1450)) ([107e062](https://github.com/kulshekhar/ts-jest/commit/107e062))
20
- * **docs:** correct changelog, correct version in package.json ([#1406](https://github.com/kulshekhar/ts-jest/issues/1406)) ([542e181](https://github.com/kulshekhar/ts-jest/commit/542e181))
20
+ * **compiler:** don’t write compile output to file system but rely on jest cache ([#1561](https://github.com/kulshekhar/ts-jest/issues/1561)) ([d11a4ea](https://github.com/kulshekhar/ts-jest/commit/d11a4ea))
21
+ * **compiler:** improve performance for `isolatedModules: false` ([#1558](https://github.com/kulshekhar/ts-jest/issues/1558)) ([85c09e3](https://github.com/kulshekhar/ts-jest/commit/85c09e3))
21
22
 
22
23
 
23
- ### Chores
24
+ ### BREAKING CHANGES
25
+
26
+ * Any custom typing files or files which are needed to be compiled and intended to use with `jest` need to be defined in `files` option of `tsconfig`.
27
+
28
+ For example:
29
+ ```
30
+ // tsconfig.json
31
+ {
32
+ // ...other configs
33
+ "files": [
34
+ "my-custom-typings.d.ts".
35
+ "my-global-module.ts"
36
+ ]
37
+ }
38
+ ```
39
+ * **compiler:** `incremental` and `compilerHost` options are no longer available. Please remove it from your `ts-jest` config.
40
+
24
41
 
25
- * **config:** improve diagnostics message ([#1444](https://github.com/kulshekhar/ts-jest/issues/1444)) ([96cd9b3](https://github.com/kulshekhar/ts-jest/commit/96cd9b3))
42
+
43
+ <a name="25.5.0-beta.0"></a>
44
+ # [25.5.0-beta.0](https://github.com/kulshekhar/ts-jest/compare/v25.5.0-alpha.0...v25.5.0-beta.0) (2020-04-29)
45
+
46
+
47
+ ### Bug Fixes
48
+
49
+ * **compiler:** allow using `files` provided by `tsconfig` ([#1562](https://github.com/kulshekhar/ts-jest/issues/1562)) ([907a280](https://github.com/kulshekhar/ts-jest/commit/907a280))
50
+ * **config:** verify `testMatchPatterns` contain `RegExp` instance or `string` type values ([#1569](https://github.com/kulshekhar/ts-jest/issues/1569)) ([7f85bab](https://github.com/kulshekhar/ts-jest/commit/7f85bab))
26
51
 
27
52
 
28
53
  ### Features
29
54
 
30
- * **compiler:** expose internal ts `Program` via ConfigSet `TsCompiler` ([#1433](https://github.com/kulshekhar/ts-jest/issues/1433)) ([7153246](https://github.com/kulshekhar/ts-jest/commit/7153246))
31
- * **config:** add incremental option ([#1418](https://github.com/kulshekhar/ts-jest/issues/1418)) ([5a69bce](https://github.com/kulshekhar/ts-jest/commit/5a69bce))
55
+ * **config:** add `tsconfig` alias to `tsConfig` option ([#1565](https://github.com/kulshekhar/ts-jest/issues/1565)) ([c10eb6d](https://github.com/kulshekhar/ts-jest/commit/c10eb6d))
56
+
57
+
58
+ ### Performance Improvements
59
+
60
+ * **compiler:** don’t write compile output to file system but rely on `jest` cache ([#1561](https://github.com/kulshekhar/ts-jest/issues/1561)) ([07b5f62](https://github.com/kulshekhar/ts-jest/commit/07b5f62))
61
+
62
+
63
+ ### BREAKING CHANGES
32
64
 
65
+ * Any custom typing files or files which are needed to be compiled and intended to use with `jest` need to be defined in `files` option of `tsconfig`.
66
+
67
+ For example
68
+ ```
69
+ // tsconfig.json
70
+ {
71
+ // ...other configs
72
+ "files": [
73
+ "my-custom-typings.d.ts".
74
+ "my-global-module.ts"
75
+ ]
76
+ }
77
+ ```
78
+
79
+
80
+
81
+ <a name="25.5.0-alpha.0"></a>
82
+ # [25.5.0-alpha.0](https://github.com/kulshekhar/ts-jest/compare/v25.4.0...v25.5.0-alpha.0) (2020-04-22)
83
+
84
+
85
+ ### Bug Fixes
86
+
87
+ * **compiler:** make `projectReferences` work with `isolatedModules: false` ([#1541](https://github.com/kulshekhar/ts-jest/issues/1541)) ([3e8efbe](https://github.com/kulshekhar/ts-jest/commit/3e8efbe))
88
+
89
+ ### Performance
90
+
91
+ * **compiler:** improve performance for `isolatedModules: false` ([#1558](https://github.com/kulshekhar/ts-jest/issues/1558)) ([85c09e3](https://github.com/kulshekhar/ts-jest/commit/85c09e3))
33
92
 
34
93
  ### BREAKING CHANGES
35
94
 
36
- * **config:** This will affect to any snapshots or assertion against diagnostics messages
95
+ * **config:** `compilerHost` and `incremental` options are no longer available
96
+
97
+
98
+
99
+ <a name="25.4.0"></a>
100
+ # [25.4.0](https://github.com/kulshekhar/ts-jest/compare/v25.3.1...v25.4.0) (2020-04-17)
101
+
102
+
103
+ ### Bug Fixes
104
+
105
+ * **compiler:** make `projectReferences` work with `isolatedModules: true` ([#1527](https://github.com/kulshekhar/ts-jest/issues/1527)) ([aa6b74c](https://github.com/kulshekhar/ts-jest/commit/aa6b74c))
106
+ * **compiler:** make sure `LanguageService` updated with test file information before getting diagnostics for test file ([#1507](https://github.com/kulshekhar/ts-jest/issues/1507)) ([311eaeb](https://github.com/kulshekhar/ts-jest/commit/311eaeb))
107
+ * **config:** set default `outDir` when `allowJs` is true and no `outDir` in `tsconfig` ([#1502](https://github.com/kulshekhar/ts-jest/issues/1502)) ([1a287ad](https://github.com/kulshekhar/ts-jest/commit/1a287ad))
108
+ * **config:** use original jest config object instead of stringified config ([#1511](https://github.com/kulshekhar/ts-jest/issues/1511)) ([4f0bb33](https://github.com/kulshekhar/ts-jest/commit/4f0bb33))
109
+
110
+
111
+
112
+ <a name="25.3.1"></a>
113
+ ## [25.3.1](https://github.com/kulshekhar/ts-jest/compare/v25.3.0...v25.3.1) (2020-04-03)
114
+
115
+
116
+ ### Bug Fixes
117
+
118
+ * only do type checking while compiling file ([#1483](https://github.com/kulshekhar/ts-jest/issues/1483)) ([dbc0a08](https://github.com/kulshekhar/ts-jest/commit/dbc0a08))
119
+ * **config:** set default outDir for enabled allowJs without outDir ([#1472](https://github.com/kulshekhar/ts-jest/issues/1472)) ([57c7af0](https://github.com/kulshekhar/ts-jest/commit/57c7af0))
37
120
 
38
121
 
39
122
 
package/README.md CHANGED
@@ -1,4 +1,13 @@
1
- # ts-jest [![npm version](https://badge.fury.io/js/ts-jest.svg)](https://badge.fury.io/js/ts-jest) [![NPM downloads](https://img.shields.io/npm/dm/ts-jest.svg?style=flat)](https://npmjs.org/package/ts-jest) [![Known Vulnerabilities](https://snyk.io/test/github/kulshekhar/ts-jest/badge.svg)](https://snyk.io/test/github/kulshekhar/ts-jest) [![Coverage Status](https://coveralls.io/repos/github/kulshekhar/ts-jest/badge.svg?branch=master)](https://coveralls.io/github/kulshekhar/ts-jest?branch=master) [![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=kulshekhar/ts-jest)](https://dependabot.com) [![Build Status](https://travis-ci.com/kulshekhar/ts-jest.svg?branch=master)](https://travis-ci.com/kulshekhar/ts-jest)
1
+ # ts-jest
2
+
3
+ [![npm version](https://badge.fury.io/js/ts-jest.svg)](https://badge.fury.io/js/ts-jest)
4
+ [![NPM downloads](https://img.shields.io/npm/dm/ts-jest.svg?style=flat)](https://npmjs.org/package/ts-jest)
5
+ [![Known Vulnerabilities](https://snyk.io/test/github/kulshekhar/ts-jest/badge.svg)](https://snyk.io/test/github/kulshekhar/ts-jest)
6
+ [![Coverage Status](https://coveralls.io/repos/github/kulshekhar/ts-jest/badge.svg?branch=master)](https://coveralls.io/github/kulshekhar/ts-jest?branch=master)
7
+ [![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=kulshekhar/ts-jest)](https://dependabot.com)
8
+ [![Build Status](https://travis-ci.com/kulshekhar/ts-jest.svg?branch=master)](https://travis-ci.com/kulshekhar/ts-jest)
9
+ [![doc-generator](https://github.com/kulshekhar/ts-jest/workflows/doc-generator/badge.svg)](https://github.com/kulshekhar/ts-jest/actions)
10
+ [![release-and-publish](https://github.com/kulshekhar/ts-jest/workflows/release-and-publish/badge.svg)](https://github.com/kulshekhar/ts-jest/actions)
2
11
 
3
12
  <img src="./icon.png" align="right" title="ts-jest Logo" width="128" height="128">
4
13
 
@@ -122,19 +122,19 @@ exports.run = function (args) { return __awaiter(void 0, void 0, void 0, functio
122
122
  content.push(" preset: '" + preset.name + "',");
123
123
  }
124
124
  else {
125
- content.push(" ...tsjPreset,");
125
+ content.push(' ...tsjPreset,');
126
126
  }
127
127
  if (!jsdom)
128
128
  content.push(" testEnvironment: 'node',");
129
129
  if (tsconfig || shouldPostProcessWithBabel) {
130
- content.push(" globals: {");
130
+ content.push(' globals: {');
131
131
  content.push(" 'ts-jest': {");
132
132
  if (tsconfig)
133
133
  content.push(" tsconfig: " + json5_1.stringify(tsconfig) + ",");
134
134
  if (shouldPostProcessWithBabel)
135
- content.push(" babelConfig: true,");
136
- content.push(" },");
137
- content.push(" },");
135
+ content.push(' babelConfig: true,');
136
+ content.push(' },');
137
+ content.push(' },');
138
138
  }
139
139
  content.push('};');
140
140
  body = content.join('\n');
@@ -57,7 +57,7 @@ var __spread = (this && this.__spread) || function () {
57
57
  };
58
58
  Object.defineProperty(exports, "__esModule", { value: true });
59
59
  var bs_logger_1 = require("bs-logger");
60
- var stringifyJson = require("fast-json-stable-stringify");
60
+ var stableStringify = require("fast-json-stable-stringify");
61
61
  var fs_1 = require("fs");
62
62
  var json5_1 = require("json5");
63
63
  var path_1 = require("path");
@@ -155,19 +155,19 @@ exports.run = function (args) { return __awaiter(void 0, void 0, void 0, functio
155
155
  }
156
156
  if (preset &&
157
157
  migratedConfig.transform &&
158
- stringifyJson(migratedConfig.transform) === stringifyJson(preset.value.transform)) {
158
+ stableStringify(migratedConfig.transform) === stableStringify(preset.value.transform)) {
159
159
  delete migratedConfig.transform;
160
160
  }
161
161
  cleanupConfig(actualConfig);
162
162
  cleanupConfig(migratedConfig);
163
- before = stringifyJson(actualConfig);
164
- after = stringifyJson(migratedConfig);
163
+ before = stableStringify(actualConfig);
164
+ after = stableStringify(migratedConfig);
165
165
  if (after === before) {
166
166
  process.stderr.write("\nNo migration needed for given Jest configuration\n ");
167
167
  return [2];
168
168
  }
169
- stringify = /\.json$/.test(file) ? JSON.stringify : json5_1.stringify;
170
- prefix = /\.json$/.test(file) ? '"jest": ' : 'module.exports = ';
169
+ stringify = file.endsWith('.json') ? JSON.stringify : json5_1.stringify;
170
+ prefix = file.endsWith('.json') ? '"jest": ' : 'module.exports = ';
171
171
  if (preset && migratedConfig.transform) {
172
172
  footNotes.push("\nI couldn't check if your \"transform\" value is the same as mine which is: " + stringify(preset.value.transform, undefined, ' ') + "\nIf it is the case, you can safely remove the \"transform\" from what I've migrated.\n");
173
173
  }
@@ -1,25 +1,136 @@
1
1
  "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
2
18
  Object.defineProperty(exports, "__esModule", { value: true });
3
19
  var fs_1 = require("fs");
20
+ var micromatch = require("micromatch");
4
21
  var path_1 = require("path");
22
+ var _ts = require("typescript");
23
+ var constants_1 = require("../constants");
5
24
  var sha1_1 = require("../util/sha1");
6
- exports.hasOwn = Object.prototype.hasOwnProperty;
7
- function getResolvedModulesCache(cachedir) {
8
- return path_1.join(cachedir, sha1_1.sha1('ts-jest-resolved-modules', '\x00'));
25
+ function getResolvedModulesCache(cacheDir) {
26
+ return path_1.join(cacheDir, sha1_1.sha1('ts-jest-resolved-modules', '\x00'));
9
27
  }
10
28
  exports.getResolvedModulesCache = getResolvedModulesCache;
11
- function cacheResolvedModules(fileName, memoryCache, program, cacheDir, logger) {
29
+ function cacheResolvedModules(fileName, fileContent, memoryCache, program, cacheDir, logger) {
12
30
  var importReferences = program.getSourceFile(fileName).imports;
13
31
  if (importReferences.length) {
14
- logger.debug({ fileName: fileName }, "cacheResolvedModules(): get resolved modules of test file " + fileName);
15
- memoryCache.resolvedModules[fileName] = importReferences
32
+ logger.debug({ fileName: fileName }, 'cacheResolvedModules(): get resolved modules');
33
+ memoryCache.resolvedModules[fileName] = Object.create(null);
34
+ memoryCache.resolvedModules[fileName].modulePaths = importReferences
16
35
  .filter(function (importReference) { var _a; return (_a = importReference.parent.parent.resolvedModules) === null || _a === void 0 ? void 0 : _a.get(importReference.text); })
17
36
  .map(function (importReference) {
18
37
  return path_1.normalize(importReference.parent.parent.resolvedModules.get(importReference.text)
19
38
  .resolvedFileName);
20
39
  })
21
40
  .reduce(function (a, b) { return a.concat(b); }, []);
41
+ memoryCache.resolvedModules[fileName].testFileContent = fileContent;
22
42
  fs_1.writeFileSync(getResolvedModulesCache(cacheDir), JSON.stringify(memoryCache.resolvedModules));
23
43
  }
24
44
  }
25
45
  exports.cacheResolvedModules = cacheResolvedModules;
46
+ function isTestFile(testMatchPatterns, fileName) {
47
+ return testMatchPatterns.some(function (pattern) {
48
+ return typeof pattern === 'string' ? micromatch.isMatch(fileName, pattern) : pattern.test(fileName);
49
+ });
50
+ }
51
+ exports.isTestFile = isTestFile;
52
+ function isUsingProjectReferences(program, projectReferences) {
53
+ if (projectReferences && !!program.getProjectReferences) {
54
+ return Boolean(program && program.getProjectReferences());
55
+ }
56
+ return false;
57
+ }
58
+ function getResolvedProjectReferences(program) {
59
+ var _a;
60
+ var getProjectReferences = (_a = program.getResolvedProjectReferences) !== null && _a !== void 0 ? _a : program.getProjectReferences;
61
+ if (getProjectReferences) {
62
+ return getProjectReferences();
63
+ }
64
+ return;
65
+ }
66
+ function getProjectReferenceForFile(filePath, program, projectReferences) {
67
+ if (isUsingProjectReferences(program, projectReferences)) {
68
+ return (program &&
69
+ getResolvedProjectReferences(program).find(function (ref) { return (ref && ref.commandLine.fileNames.some(function (file) { return path_1.normalize(file) === filePath; })) || false; }));
70
+ }
71
+ return;
72
+ }
73
+ function getAndCacheProjectReference(filePath, program, files, projectReferences) {
74
+ var file = files.get(filePath);
75
+ if (file === null || file === void 0 ? void 0 : file.projectReference) {
76
+ return file.projectReference.project;
77
+ }
78
+ var projectReference = getProjectReferenceForFile(filePath, program, projectReferences);
79
+ if (file !== undefined) {
80
+ file.projectReference = { project: projectReference };
81
+ }
82
+ return projectReference;
83
+ }
84
+ exports.getAndCacheProjectReference = getAndCacheProjectReference;
85
+ function getOutputJavaScriptFileName(inputFileName, projectReference) {
86
+ var options = projectReference.commandLine.options;
87
+ var projectDirectory = options.rootDir || path_1.dirname(projectReference.sourceFile.fileName);
88
+ var relativePath = path_1.relative(projectDirectory, inputFileName);
89
+ var outputPath = path_1.resolve(options.outDir || projectDirectory, relativePath);
90
+ var newExtension = constants_1.JSON_REGEX.test(inputFileName)
91
+ ? '.json'
92
+ : constants_1.TS_TSX_REGEX.test(inputFileName) && options.jsx === _ts.JsxEmit.Preserve
93
+ ? '.jsx'
94
+ : '.js';
95
+ return outputPath.replace(constants_1.EXTENSION_REGEX, newExtension);
96
+ }
97
+ function getAndCacheOutputJSFileName(inputFileName, projectReference, files) {
98
+ var _a, _b;
99
+ var file = files.get(inputFileName);
100
+ if ((_a = file === null || file === void 0 ? void 0 : file.projectReference) === null || _a === void 0 ? void 0 : _a.outputFileName) {
101
+ return file.projectReference.outputFileName;
102
+ }
103
+ var outputFileName = getOutputJavaScriptFileName(inputFileName, projectReference);
104
+ if (file !== undefined) {
105
+ file.projectReference = (_b = file.projectReference) !== null && _b !== void 0 ? _b : {
106
+ project: projectReference,
107
+ };
108
+ file.projectReference.outputFileName = outputFileName;
109
+ }
110
+ return outputFileName;
111
+ }
112
+ function getCompileResultFromReferencedProject(fileName, configs, files, referencedProject) {
113
+ var _a = __read([
114
+ configs.resolvePath(referencedProject.sourceFile.fileName),
115
+ configs.resolvePath(fileName),
116
+ ], 2), relativeProjectConfigPath = _a[0], relativeFilePath = _a[1];
117
+ if (referencedProject.commandLine.options.outFile !== undefined) {
118
+ throw new Error("The referenced project at " + relativeProjectConfigPath + " is using " +
119
+ "the outFile' option, which is not supported with ts-jest.");
120
+ }
121
+ var jsFileName = getAndCacheOutputJSFileName(fileName, referencedProject, files);
122
+ var relativeJSFileName = configs.resolvePath(jsFileName);
123
+ if (!configs.compilerModule.sys.fileExists(jsFileName)) {
124
+ throw new Error('Could not find output JavaScript file for input ' +
125
+ (relativeFilePath + " (looked at " + relativeJSFileName + ").\n") +
126
+ 'The input file is part of a project reference located at ' +
127
+ (relativeProjectConfigPath + ", so ts-jest is looking for the ") +
128
+ 'project’s pre-built output on disk. Try running `tsc --build` ' +
129
+ 'to build project references.');
130
+ }
131
+ var mapFileName = jsFileName + ".map";
132
+ var outputText = configs.compilerModule.sys.readFile(jsFileName);
133
+ var sourceMapText = configs.compilerModule.sys.readFile(mapFileName);
134
+ return [outputText, sourceMapText];
135
+ }
136
+ exports.getCompileResultFromReferencedProject = getCompileResultFromReferencedProject;
@@ -1,4 +1,15 @@
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
+ };
2
13
  var __read = (this && this.__read) || function (o, n) {
3
14
  var m = typeof Symbol === "function" && o[Symbol.iterator];
4
15
  if (!m) return o;
@@ -15,26 +26,13 @@ var __read = (this && this.__read) || function (o, n) {
15
26
  }
16
27
  return ar;
17
28
  };
18
- var __values = (this && this.__values) || function(o) {
19
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
20
- if (m) return m.call(o);
21
- if (o && typeof o.length === "number") return {
22
- next: function () {
23
- if (o && i >= o.length) o = void 0;
24
- return { value: o && o[i++], done: !o };
25
- }
26
- };
27
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
28
- };
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
30
  var fs_1 = require("fs");
31
31
  var mkdirp = require("mkdirp");
32
32
  var path_1 = require("path");
33
- var sha1_1 = require("../util/sha1");
34
33
  var compiler_utils_1 = require("./compiler-utils");
35
34
  var language_service_1 = require("./language-service");
36
- var program_1 = require("./program");
37
- var transpile_module_1 = require("./transpile-module");
35
+ var transpiler_1 = require("./transpiler");
38
36
  function updateOutput(outputText, normalizedFileName, sourceMap, getExtension) {
39
37
  var base = path_1.basename(normalizedFileName);
40
38
  var base64Map = Buffer.from(updateSourceMap(sourceMap, normalizedFileName), 'utf8').toString('base64');
@@ -49,94 +47,50 @@ var updateSourceMap = function (sourceMapText, normalizedFileName) {
49
47
  delete sourceMap.sourceRoot;
50
48
  return JSON.stringify(sourceMap);
51
49
  };
52
- var getCacheName = function (sourceCode, normalizedFileName) {
53
- return sha1_1.sha1(normalizedFileName, '\x00', sourceCode);
54
- };
55
- var isValidCacheContent = function (contents) {
56
- return /(?:9|0=|Q==)$/.test(contents.slice(-3));
57
- };
58
- var readThrough = function (cachedir, memoryCache, compileFn, getExtension, logger) {
59
- if (!cachedir) {
60
- return function (code, fileName, lineOffset) {
61
- var normalizedFileName = path_1.normalize(fileName);
62
- logger.debug({ normalizedFileName: normalizedFileName }, 'readThrough(): no cache');
63
- var _a = __read(compileFn(code, normalizedFileName, lineOffset), 2), value = _a[0], sourceMap = _a[1];
64
- var output = updateOutput(value, fileName, sourceMap, getExtension);
65
- memoryCache.outputs[normalizedFileName] = output;
66
- return output;
67
- };
68
- }
69
- mkdirp.sync(cachedir);
70
- try {
71
- var resolvedModulesCache = fs_1.readFileSync(compiler_utils_1.getResolvedModulesCache(cachedir), 'utf-8');
72
- memoryCache.resolvedModules = JSON.parse(resolvedModulesCache);
73
- }
74
- catch (e) { }
75
- return function (code, fileName, lineOffset) {
76
- var normalizedFileName = path_1.normalize(fileName);
77
- var cachePath = path_1.join(cachedir, getCacheName(code, normalizedFileName));
78
- var extension = getExtension(normalizedFileName);
79
- var outputPath = "" + cachePath + extension;
80
- try {
81
- var output_1 = fs_1.readFileSync(outputPath, 'utf8');
82
- if (isValidCacheContent(output_1)) {
83
- logger.debug({ normalizedFileName: normalizedFileName }, 'readThrough(): cache hit');
84
- memoryCache.outputs[normalizedFileName] = output_1;
85
- return output_1;
86
- }
87
- }
88
- catch (err) { }
89
- logger.debug({ fileName: fileName }, 'readThrough(): cache miss');
90
- var _a = __read(compileFn(code, normalizedFileName, lineOffset), 2), value = _a[0], sourceMap = _a[1];
91
- var output = updateOutput(value, normalizedFileName, sourceMap, getExtension);
92
- logger.debug({ normalizedFileName: normalizedFileName, outputPath: outputPath }, 'readThrough(): writing caches');
93
- memoryCache.outputs[normalizedFileName] = output;
94
- fs_1.writeFileSync(outputPath, output);
95
- return output;
96
- };
97
- };
98
- exports.createCompiler = function (configs) {
99
- var e_1, _a;
50
+ var compileAndCacheResult = function (memoryCache, compileFn, getExtension, logger) { return function (code, fileName, lineOffset) {
51
+ logger.debug({ fileName: fileName }, 'compileAndCacheResult(): get compile output');
52
+ 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;
56
+ }; };
57
+ exports.createCompilerInstance = function (configs) {
100
58
  var logger = configs.logger.child({ namespace: 'ts-compiler' });
101
- var _b = configs.typescript, compilerOptions = _b.options, fileNames = _b.fileNames, tsJest = configs.tsJest;
102
- var cachedir = configs.tsCacheDir;
59
+ var compilerOptions = configs.parsedTsConfig.options, tsJest = configs.tsJest;
60
+ var cacheDir = configs.tsCacheDir;
103
61
  var ts = configs.compilerModule;
104
62
  var extensions = ['.ts', '.tsx'];
105
63
  var memoryCache = {
106
- contents: Object.create(null),
107
- versions: Object.create(null),
108
- outputs: Object.create(null),
64
+ files: new Map(),
109
65
  resolvedModules: Object.create(null),
110
66
  };
111
67
  if (compilerOptions.allowJs) {
112
68
  extensions.push('.js');
113
69
  extensions.push('.jsx');
114
70
  }
115
- try {
116
- for (var fileNames_1 = __values(fileNames), fileNames_1_1 = fileNames_1.next(); !fileNames_1_1.done; fileNames_1_1 = fileNames_1.next()) {
117
- var path = fileNames_1_1.value;
118
- memoryCache.versions[path_1.normalize(path)] = 1;
119
- }
120
- }
121
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
122
- finally {
71
+ if (cacheDir) {
72
+ mkdirp.sync(cacheDir);
123
73
  try {
124
- if (fileNames_1_1 && !fileNames_1_1.done && (_a = fileNames_1.return)) _a.call(fileNames_1);
74
+ var fsMemoryCache = fs_1.readFileSync(compiler_utils_1.getResolvedModulesCache(cacheDir), 'utf-8');
75
+ memoryCache.resolvedModules = JSON.parse(fsMemoryCache);
125
76
  }
126
- finally { if (e_1) throw e_1.error; }
77
+ catch (e) { }
127
78
  }
79
+ configs.parsedTsConfig.fileNames.forEach(function (fileName) {
80
+ memoryCache.files.set(fileName, {
81
+ version: 0,
82
+ });
83
+ });
128
84
  var getExtension = compilerOptions.jsx === ts.JsxEmit.Preserve
129
85
  ? function (path) { return (/\.[tj]sx$/.test(path) ? '.jsx' : '.js'); }
130
86
  : function (_) { return '.js'; };
131
87
  var compilerInstance;
132
88
  if (!tsJest.isolatedModules) {
133
- compilerInstance = !tsJest.compilerHost
134
- ? language_service_1.compileUsingLanguageService(configs, logger, memoryCache)
135
- : program_1.compileUsingProgram(configs, logger, memoryCache);
89
+ compilerInstance = language_service_1.initializeLanguageServiceInstance(configs, memoryCache, logger);
136
90
  }
137
91
  else {
138
- compilerInstance = transpile_module_1.compileUsingTranspileModule(configs, logger);
92
+ compilerInstance = transpiler_1.initializeTranspilerInstance(configs, memoryCache, logger);
139
93
  }
140
- var compile = readThrough(cachedir, memoryCache, compilerInstance.compileFn, getExtension, logger);
94
+ var compile = compileAndCacheResult(memoryCache, compilerInstance.compileFn, getExtension, logger);
141
95
  return { cwd: configs.cwd, compile: compile, program: compilerInstance.program };
142
96
  };