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 +1 -1
- package/CHANGELOG.md +98 -15
- package/README.md +10 -1
- package/dist/cli/config/init.js +5 -5
- package/dist/cli/config/migrate.js +6 -6
- package/dist/compiler/compiler-utils.js +117 -6
- package/dist/compiler/instance.js +36 -82
- package/dist/compiler/language-service.js +104 -53
- package/dist/compiler/{program.d.ts → transpiler.d.ts} +0 -0
- package/dist/compiler/transpiler.js +46 -0
- package/dist/config/config-set.js +31 -28
- package/dist/{compiler/transpile-module.d.ts → constants.d.ts} +0 -0
- package/dist/constants.js +8 -0
- package/dist/index.d.ts +7 -0
- package/dist/ts-jest-transformer.d.ts +3 -6
- package/dist/ts-jest-transformer.js +16 -26
- package/dist/types.d.ts +13 -7
- package/dist/util/backports.js +1 -1
- package/dist/util/importer.js +1 -3
- package/dist/util/version-checkers.js +1 -1
- package/package.json +16 -18
- package/preprocessor.js +1 -0
- package/presets/index.js +14 -7
- package/dist/compiler/program.js +0 -148
- package/dist/compiler/transpile-module.js +0 -22
package/.ts-jest-digest
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
a17070bc22b8d4dcc13d502438e8b25aba2ac38d
|
package/CHANGELOG.md
CHANGED
|
@@ -1,39 +1,122 @@
|
|
|
1
|
-
<a name="25.
|
|
2
|
-
|
|
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
|
-
*
|
|
8
|
-
* **
|
|
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
|
-
|
|
13
|
-
|
|
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
|
-
###
|
|
18
|
+
### Performance Improvements
|
|
17
19
|
|
|
18
|
-
*
|
|
19
|
-
*
|
|
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
|
-
###
|
|
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
|
-
|
|
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
|
-
* **
|
|
31
|
-
|
|
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:**
|
|
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
|
|
1
|
+
# ts-jest
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/ts-jest)
|
|
4
|
+
[](https://npmjs.org/package/ts-jest)
|
|
5
|
+
[](https://snyk.io/test/github/kulshekhar/ts-jest)
|
|
6
|
+
[](https://coveralls.io/github/kulshekhar/ts-jest?branch=master)
|
|
7
|
+
[](https://dependabot.com)
|
|
8
|
+
[](https://travis-ci.com/kulshekhar/ts-jest)
|
|
9
|
+
[](https://github.com/kulshekhar/ts-jest/actions)
|
|
10
|
+
[](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
|
|
package/dist/cli/config/init.js
CHANGED
|
@@ -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(
|
|
125
|
+
content.push(' ...tsjPreset,');
|
|
126
126
|
}
|
|
127
127
|
if (!jsdom)
|
|
128
128
|
content.push(" testEnvironment: 'node',");
|
|
129
129
|
if (tsconfig || shouldPostProcessWithBabel) {
|
|
130
|
-
content.push(
|
|
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(
|
|
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
|
|
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
|
-
|
|
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 =
|
|
164
|
-
after =
|
|
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 =
|
|
170
|
-
prefix =
|
|
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
|
-
|
|
7
|
-
|
|
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 },
|
|
15
|
-
memoryCache.resolvedModules[fileName] =
|
|
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
|
|
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
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
|
102
|
-
var
|
|
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
|
-
|
|
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
|
-
|
|
116
|
-
|
|
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
|
-
|
|
74
|
+
var fsMemoryCache = fs_1.readFileSync(compiler_utils_1.getResolvedModulesCache(cacheDir), 'utf-8');
|
|
75
|
+
memoryCache.resolvedModules = JSON.parse(fsMemoryCache);
|
|
125
76
|
}
|
|
126
|
-
|
|
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 =
|
|
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 =
|
|
92
|
+
compilerInstance = transpiler_1.initializeTranspilerInstance(configs, memoryCache, logger);
|
|
139
93
|
}
|
|
140
|
-
var compile =
|
|
94
|
+
var compile = compileAndCacheResult(memoryCache, compilerInstance.compileFn, getExtension, logger);
|
|
141
95
|
return { cwd: configs.cwd, compile: compile, program: compilerInstance.program };
|
|
142
96
|
};
|