ts-jest 26.4.4-alpha.0 → 26.5.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.
package/.ts-jest-digest CHANGED
@@ -1 +1 @@
1
- 336cc4e94740cf0fe1f2860194506c4f8866b4e4
1
+ f05021154752d867f897fb08a2c5739108a4251c
package/CHANGELOG.md CHANGED
@@ -1,3 +1,58 @@
1
+ ## [26.5.2](https://github.com/kulshekhar/ts-jest/compare/v26.5.1...v26.5.2) (2021-02-21)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **compiler:** exclude files in `outDir` from compiler source files ([#2376](https://github.com/kulshekhar/ts-jest/issues/2376)) ([9034677](https://github.com/kulshekhar/ts-jest/commit/9034677f9ce0968339d3d942a70e888996fac532)), closes [#2350](https://github.com/kulshekhar/ts-jest/issues/2350) [#2374](https://github.com/kulshekhar/ts-jest/issues/2374)
7
+ * **config:** define `matchTestFilePath` before `setupTsJestCfg` ([#2373](https://github.com/kulshekhar/ts-jest/issues/2373)) ([c427fea](https://github.com/kulshekhar/ts-jest/commit/c427fea48a24b5ce6e8b9260d3c322583b062a77)), closes [#2371](https://github.com/kulshekhar/ts-jest/issues/2371)
8
+ * **config:** improve emit skipped error message and ensure `outDir` always `TS_JEST_OUT_DIR` ([#2357](https://github.com/kulshekhar/ts-jest/issues/2357)) ([f2808bb](https://github.com/kulshekhar/ts-jest/commit/f2808bb0b15231c67ccb9a97ed606741213c03e6))
9
+ * **typings:** set correct typing for `tsconfig`/`tsConfig` option ([#2377](https://github.com/kulshekhar/ts-jest/issues/2377)) ([d4f6aff](https://github.com/kulshekhar/ts-jest/commit/d4f6aff3f181761bf25c64ff1a97dd19a69196f9)), closes [#2368](https://github.com/kulshekhar/ts-jest/issues/2368)
10
+
11
+
12
+
13
+ ## [26.5.1](https://github.com/kulshekhar/ts-jest/compare/v26.5.0...v26.5.1) (2021-02-09)
14
+
15
+
16
+ ### Features
17
+
18
+ * **config:** support typed config options for jest config typescript ([#2336](https://github.com/kulshekhar/ts-jest/issues/2336)) ([f4f5d32](https://github.com/kulshekhar/ts-jest/commit/f4f5d3205d1c80e545a32c02c6a66e7e91386f7f))
19
+ * **presets:** add typing for `presets` entry point ([#2341](https://github.com/kulshekhar/ts-jest/issues/2341)) ([e12b004](https://github.com/kulshekhar/ts-jest/commit/e12b004dcc5848d5ae0638e885147c54e11cc72b)), closes [#2325](https://github.com/kulshekhar/ts-jest/issues/2325)
20
+
21
+
22
+
23
+ # [26.5.0](https://github.com/kulshekhar/ts-jest/compare/v26.5.0...v26.4.4) (2021-01-29)
24
+
25
+
26
+ ### Bug Fixes
27
+
28
+ * reduce size of `node_modules` when adding `ts-jest` ([#2309](https://github.com/kulshekhar/ts-jest/issues/2309)) ([6bf2e8a](https://github.com/kulshekhar/ts-jest/commit/b8d5d2090567f23947d9efd87f5f869b16bf2e8a))
29
+
30
+
31
+ ### Features
32
+
33
+ * introduce `exclude` to exclude files from diagnostics ([#2308](https://github.com/kulshekhar/ts-jest/issues/2308)) ([cd82fd3](https://github.com/kulshekhar/ts-jest/commit/0c555c250774a7fd9e356cf20a3d8b693cd82fd3))
34
+
35
+
36
+ ### DEPRECATIONS
37
+
38
+ * **config**: deprecate `pathRegex` in favor of `exclude` ([#2308](https://github.com/kulshekhar/ts-jest/issues/2308)) ([cd82fd3](https://github.com/kulshekhar/ts-jest/commit/0c555c250774a7fd9e356cf20a3d8b693cd82fd3))
39
+
40
+
41
+
42
+ ## [26.4.4](https://github.com/kulshekhar/ts-jest/compare/v26.4.3...v26.4.4) (2020-11-08)
43
+
44
+
45
+ ### Bug Fixes
46
+
47
+ * revert usage of `@jest/create-cache-key-function` ([#2108](https://github.com/kulshekhar/ts-jest/issues/2108)) ([dee8231](https://github.com/kulshekhar/ts-jest/commit/dee823172ce1e8eb9e0b2dd3aeed1ab4033bd0d9)), closes [#2080](https://github.com/kulshekhar/ts-jest/issues/2080) [#2090](https://github.com/kulshekhar/ts-jest/issues/2090) [#2104](https://github.com/kulshekhar/ts-jest/issues/2104)
48
+
49
+
50
+ ### Features
51
+
52
+ * **testing:** expose all types for util `mocked` ([#2096](https://github.com/kulshekhar/ts-jest/issues/2096)) ([b1d072b](https://github.com/kulshekhar/ts-jest/commit/b1d072b52b9a7665b3a6914b0895f84f6ee3f8c0)), closes [#2086](https://github.com/kulshekhar/ts-jest/issues/2086)
53
+
54
+
55
+
1
56
  ## [26.4.3](https://github.com/kulshekhar/ts-jest/compare/v26.4.2...v26.4.3) (2020-10-26)
2
57
 
3
58
 
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,154 @@
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
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.help = exports.run = void 0;
51
+ var fs_1 = require("fs");
52
+ var json5_1 = require("json5");
53
+ var path_1 = require("path");
54
+ var presets_1 = require("../helpers/presets");
55
+ exports.run = function (args) { return __awaiter(void 0, void 0, void 0, function () {
56
+ var file, filePath, name, isPackage, exists, pkgFile, hasPackage, _a, jestPreset, askedTsconfig, force, jsdom, tsconfig, pkgJson, jsFilesProcessor, shouldPostProcessWithBabel, preset, body, base, tsJestConf, content;
57
+ var _b, _c;
58
+ return __generator(this, function (_d) {
59
+ file = (_c = (_b = args._[0]) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : 'jest.config.js';
60
+ filePath = path_1.join(process.cwd(), file);
61
+ name = path_1.basename(file);
62
+ isPackage = name === 'package.json';
63
+ exists = fs_1.existsSync(filePath);
64
+ pkgFile = isPackage ? filePath : path_1.join(process.cwd(), 'package.json');
65
+ hasPackage = isPackage || fs_1.existsSync(pkgFile);
66
+ _a = args.jestPreset, jestPreset = _a === void 0 ? true : _a, askedTsconfig = args.tsconfig, force = args.force, jsdom = args.jsdom;
67
+ tsconfig = askedTsconfig === 'tsconfig.json' ? undefined : askedTsconfig;
68
+ pkgJson = hasPackage ? JSON.parse(fs_1.readFileSync(pkgFile, 'utf8')) : {};
69
+ jsFilesProcessor = args.js, shouldPostProcessWithBabel = args.babel;
70
+ if (jsFilesProcessor == null) {
71
+ jsFilesProcessor = shouldPostProcessWithBabel ? 'babel' : undefined;
72
+ }
73
+ else if (shouldPostProcessWithBabel == null) {
74
+ shouldPostProcessWithBabel = jsFilesProcessor === 'babel';
75
+ }
76
+ if (jsFilesProcessor === 'babel') {
77
+ preset = presets_1.jsWIthBabel;
78
+ }
79
+ else if (jsFilesProcessor === 'ts') {
80
+ preset = presets_1.jsWithTs;
81
+ }
82
+ else {
83
+ preset = presets_1.defaults;
84
+ }
85
+ if (isPackage && !exists) {
86
+ throw new Error("File " + file + " does not exists.");
87
+ }
88
+ else if (!isPackage && exists && !force) {
89
+ throw new Error("Configuration file " + file + " already exists.");
90
+ }
91
+ if (!isPackage && !name.endsWith('.js')) {
92
+ throw new TypeError("Configuration file " + file + " must be a .js file or the package.json.");
93
+ }
94
+ if (hasPackage && pkgJson.jest) {
95
+ if (force && !isPackage) {
96
+ delete pkgJson.jest;
97
+ fs_1.writeFileSync(pkgFile, JSON.stringify(pkgJson, undefined, ' '));
98
+ }
99
+ else if (!force) {
100
+ throw new Error("A Jest configuration is already set in " + pkgFile + ".");
101
+ }
102
+ }
103
+ if (isPackage) {
104
+ base = jestPreset ? { preset: preset.name } : __assign({}, preset.value);
105
+ if (!jsdom)
106
+ base.testEnvironment = 'node';
107
+ if (tsconfig || shouldPostProcessWithBabel) {
108
+ tsJestConf = {};
109
+ base.globals = { 'ts-jest': tsJestConf };
110
+ if (tsconfig)
111
+ tsJestConf.tsconfig = tsconfig;
112
+ if (shouldPostProcessWithBabel)
113
+ tsJestConf.babelConfig = true;
114
+ }
115
+ body = JSON.stringify(__assign(__assign({}, pkgJson), { jest: base }), undefined, ' ');
116
+ }
117
+ else {
118
+ content = [];
119
+ if (!jestPreset) {
120
+ content.push(preset.jsImport('tsjPreset') + ";", '');
121
+ }
122
+ content.push('module.exports = {');
123
+ if (jestPreset) {
124
+ content.push(" preset: '" + preset.name + "',");
125
+ }
126
+ else {
127
+ content.push(' ...tsjPreset,');
128
+ }
129
+ if (!jsdom)
130
+ content.push(" testEnvironment: 'node',");
131
+ if (tsconfig || shouldPostProcessWithBabel) {
132
+ content.push(' globals: {');
133
+ content.push(" 'ts-jest': {");
134
+ if (tsconfig)
135
+ content.push(" tsconfig: " + json5_1.stringify(tsconfig) + ",");
136
+ if (shouldPostProcessWithBabel)
137
+ content.push(' babelConfig: true,');
138
+ content.push(' },');
139
+ content.push(' },');
140
+ }
141
+ content.push('};');
142
+ body = content.join('\n');
143
+ }
144
+ fs_1.writeFileSync(filePath, body);
145
+ process.stderr.write("\nJest configuration written to \"" + filePath + "\".\n");
146
+ return [2];
147
+ });
148
+ }); };
149
+ exports.help = function () { return __awaiter(void 0, void 0, void 0, function () {
150
+ return __generator(this, function (_a) {
151
+ process.stdout.write("\nUsage:\n ts-jest config:init [options] [<config-file>]\n\nArguments:\n <config-file> Can be a js or json Jest config file. If it is a\n package.json file, the configuration will be read from\n the \"jest\" property.\n Default: jest.config.js\n\nOptions:\n --force Discard any existing Jest config\n --js ts|babel Process .js files with ts-jest if 'ts' or with\n babel-jest if 'babel'\n --no-jest-preset Disable the use of Jest presets\n --tsconfig <file> Path to the tsconfig.json file\n --babel Pipe babel-jest after ts-jest\n --jsdom Use jsdom as test environment instead of node\n");
152
+ return [2];
153
+ });
154
+ }); };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __read = (this && this.__read) || function (o, n) {
39
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
40
+ if (!m) return o;
41
+ var i = m.call(o), r, ar = [], e;
42
+ try {
43
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
44
+ }
45
+ catch (error) { e = { error: error }; }
46
+ finally {
47
+ try {
48
+ if (r && !r.done && (m = i["return"])) m.call(i);
49
+ }
50
+ finally { if (e) throw e.error; }
51
+ }
52
+ return ar;
53
+ };
54
+ var __spread = (this && this.__spread) || function () {
55
+ for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
56
+ return ar;
57
+ };
58
+ Object.defineProperty(exports, "__esModule", { value: true });
59
+ exports.help = exports.run = void 0;
60
+ var bs_logger_1 = require("bs-logger");
61
+ var stableStringify = require("fast-json-stable-stringify");
62
+ var fs_1 = require("fs");
63
+ var json5_1 = require("json5");
64
+ var path_1 = require("path");
65
+ var backports_1 = require("../../utils/backports");
66
+ var presets_1 = require("../helpers/presets");
67
+ exports.run = function (args) { return __awaiter(void 0, void 0, void 0, function () {
68
+ var nullLogger, file, filePath, footNotes, name, isPackage, actualConfig, migratedConfig, presetName, preset, jsTransformers, jsWithTs, jsWithBabel, presetValue, migratedValue, presetValue, migratedValue, before, after, stringify, prefix;
69
+ var _a;
70
+ return __generator(this, function (_b) {
71
+ nullLogger = bs_logger_1.createLogger({ targets: [] });
72
+ file = (_a = args._[0]) === null || _a === void 0 ? void 0 : _a.toString();
73
+ filePath = path_1.resolve(process.cwd(), file);
74
+ footNotes = [];
75
+ if (!fs_1.existsSync(filePath)) {
76
+ throw new Error("Configuration file " + file + " does not exists.");
77
+ }
78
+ name = path_1.basename(file);
79
+ isPackage = name === 'package.json';
80
+ if (!/\.(js|json)$/.test(name)) {
81
+ throw new TypeError("Configuration file " + file + " must be a JavaScript or JSON file.");
82
+ }
83
+ actualConfig = require(filePath);
84
+ if (isPackage) {
85
+ actualConfig = actualConfig.jest;
86
+ }
87
+ if (!actualConfig)
88
+ actualConfig = {};
89
+ migratedConfig = backports_1.backportJestConfig(nullLogger, actualConfig);
90
+ if (!migratedConfig.preset && args.jestPreset) {
91
+ if (args.js) {
92
+ presetName = args.js === 'babel' ? "ts-jest/presets/js-with-babel" : "ts-jest/presets/js-with-ts";
93
+ }
94
+ else {
95
+ jsTransformers = Object.keys(migratedConfig.transform || {}).reduce(function (list, pattern) {
96
+ if (RegExp(pattern.replace(/^<rootDir>\/?/, '/dummy-project/')).test('/dummy-project/src/foo.js')) {
97
+ var transformer = migratedConfig.transform[pattern];
98
+ if (/\bbabel-jest\b/.test(transformer))
99
+ transformer = 'babel-jest';
100
+ else if (/\ts-jest\b/.test(transformer))
101
+ transformer = 'ts-jest';
102
+ return __spread(list, [transformer]);
103
+ }
104
+ return list;
105
+ }, []);
106
+ jsWithTs = jsTransformers.includes('ts-jest');
107
+ jsWithBabel = jsTransformers.includes('babel-jest');
108
+ if (jsWithBabel && !jsWithTs) {
109
+ presetName = "ts-jest/presets/js-with-babel";
110
+ }
111
+ else if (jsWithTs && !jsWithBabel) {
112
+ presetName = "ts-jest/presets/js-with-ts";
113
+ }
114
+ else {
115
+ presetName = "ts-jest/presets/default";
116
+ }
117
+ }
118
+ presetName = presetName || "ts-jest/presets/default";
119
+ preset = presets_1.allPresets[presetName];
120
+ footNotes.push("Detected preset '" + preset.label + "' as the best matching preset for your configuration.\nVisit https://kulshekhar.github.io/ts-jest/user/config/#jest-preset for more information about presets.\n");
121
+ }
122
+ else if (migratedConfig.preset && migratedConfig.preset.startsWith('ts-jest')) {
123
+ if (args.jestPreset === false) {
124
+ delete migratedConfig.preset;
125
+ }
126
+ else {
127
+ preset = presets_1.allPresets[migratedConfig.preset] || presets_1.defaults;
128
+ }
129
+ }
130
+ if (preset)
131
+ migratedConfig.preset = preset.name;
132
+ if (migratedConfig.moduleFileExtensions && migratedConfig.moduleFileExtensions.length && preset) {
133
+ presetValue = dedupSort(preset.value.moduleFileExtensions || []).join('::');
134
+ migratedValue = dedupSort(migratedConfig.moduleFileExtensions).join('::');
135
+ if (presetValue === migratedValue) {
136
+ delete migratedConfig.moduleFileExtensions;
137
+ }
138
+ }
139
+ if (migratedConfig.testRegex && preset) {
140
+ migratedConfig.testMatch = null;
141
+ }
142
+ else if (migratedConfig.testMatch && migratedConfig.testMatch.length && preset) {
143
+ presetValue = dedupSort(preset.value.testMatch || []).join('::');
144
+ migratedValue = dedupSort(migratedConfig.testMatch).join('::');
145
+ if (presetValue === migratedValue) {
146
+ delete migratedConfig.testMatch;
147
+ }
148
+ }
149
+ if (migratedConfig.transform) {
150
+ Object.keys(migratedConfig.transform).forEach(function (key) {
151
+ var val = migratedConfig.transform[key];
152
+ if (typeof val === 'string' && /\/?ts-jest(?:\/preprocessor\.js)?$/.test(val)) {
153
+ ;
154
+ migratedConfig.transform[key] = 'ts-jest';
155
+ }
156
+ });
157
+ }
158
+ if (preset &&
159
+ migratedConfig.transform &&
160
+ stableStringify(migratedConfig.transform) === stableStringify(preset.value.transform)) {
161
+ delete migratedConfig.transform;
162
+ }
163
+ cleanupConfig(actualConfig);
164
+ cleanupConfig(migratedConfig);
165
+ before = stableStringify(actualConfig);
166
+ after = stableStringify(migratedConfig);
167
+ if (after === before) {
168
+ process.stderr.write("\nNo migration needed for given Jest configuration\n ");
169
+ return [2];
170
+ }
171
+ stringify = file.endsWith('.json') ? JSON.stringify : json5_1.stringify;
172
+ prefix = file.endsWith('.json') ? '"jest": ' : 'module.exports = ';
173
+ if (preset && migratedConfig.transform) {
174
+ 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");
175
+ }
176
+ process.stderr.write("\nMigrated Jest configuration:\n");
177
+ process.stdout.write("" + prefix + stringify(migratedConfig, undefined, ' ') + "\n");
178
+ if (footNotes.length) {
179
+ process.stderr.write("\n" + footNotes.join('\n') + "\n");
180
+ }
181
+ return [2];
182
+ });
183
+ }); };
184
+ function cleanupConfig(config) {
185
+ if (config.globals) {
186
+ if (config.globals['ts-jest'] && Object.keys(config.globals['ts-jest']).length === 0) {
187
+ delete config.globals['ts-jest'];
188
+ }
189
+ if (Object.keys(config.globals).length === 0) {
190
+ delete config.globals;
191
+ }
192
+ }
193
+ if (config.transform && Object.keys(config.transform).length === 0) {
194
+ delete config.transform;
195
+ }
196
+ if (config.moduleFileExtensions) {
197
+ config.moduleFileExtensions = dedupSort(config.moduleFileExtensions);
198
+ if (config.moduleFileExtensions.length === 0)
199
+ delete config.moduleFileExtensions;
200
+ }
201
+ if (config.testMatch) {
202
+ config.testMatch = dedupSort(config.testMatch);
203
+ if (config.testMatch.length === 0)
204
+ delete config.testMatch;
205
+ }
206
+ if (config.preset === "ts-jest/presets/default")
207
+ config.preset = presets_1.defaults.name;
208
+ }
209
+ function dedupSort(arr) {
210
+ return arr
211
+ .filter(function (s, i, a) { return a.findIndex(function (e) { return s.toString() === e.toString(); }) === i; })
212
+ .sort(function (a, b) { return (a.toString() > b.toString() ? 1 : a.toString() < b.toString() ? -1 : 0); });
213
+ }
214
+ exports.help = function () { return __awaiter(void 0, void 0, void 0, function () {
215
+ return __generator(this, function (_a) {
216
+ process.stdout.write("\nUsage:\n ts-jest config:migrate [options] <config-file>\n\nArguments:\n <config-file> Can be a js or json Jest config file. If it is a\n package.json file, the configuration will be read from\n the \"jest\" property.\n\nOptions:\n --js ts|babel Process .js files with ts-jest if 'ts' or with\n babel-jest if 'babel'\n --no-jest-preset Disable the use of Jest presets\n");
217
+ return [2];
218
+ });
219
+ }); };
@@ -71,8 +71,9 @@ exports.initializeLanguageServiceInstance = void 0;
71
71
  var bs_logger_1 = require("bs-logger");
72
72
  var fs_1 = require("fs");
73
73
  var path_1 = require("path");
74
- var memoize = require("lodash.memoize");
74
+ var memoize = require("lodash/memoize");
75
75
  var mkdirp = require("mkdirp");
76
+ var config_set_1 = require("../config/config-set");
76
77
  var constants_1 = require("../constants");
77
78
  var messages_1 = require("../utils/messages");
78
79
  var json_1 = require("../utils/json");
@@ -113,7 +114,7 @@ exports.initializeLanguageServiceInstance = function (configs, logger) {
113
114
  catch (e) { }
114
115
  }
115
116
  configs.parsedTsConfig.fileNames
116
- .filter(function (fileName) { return !configs.isTestFile(fileName); })
117
+ .filter(function (fileName) { var _a; return !configs.isTestFile(fileName) && !fileName.includes((_a = configs.parsedTsConfig.options.outDir) !== null && _a !== void 0 ? _a : config_set_1.TS_JEST_OUT_DIR); })
117
118
  .forEach(function (fileName) {
118
119
  memoryCache.files.set(fileName, {
119
120
  version: 0,
@@ -266,7 +267,7 @@ exports.initializeLanguageServiceInstance = function (configs, logger) {
266
267
  }
267
268
  }
268
269
  if (output.emitSkipped) {
269
- throw new TypeError(path_1.relative(cwd, fileName) + ": Emit skipped for language service");
270
+ throw new Error(messages_1.interpolate("Unable to process '{{file}}'. Please make sure that `outDir` in your tsconfig is neither `''` or `'.'`.", { file: fileName }));
270
271
  }
271
272
  if (!output.outputFiles.length) {
272
273
  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}}`.", {
@@ -2,7 +2,10 @@ import type { Config } from '@jest/types';
2
2
  import { Logger } from 'bs-logger';
3
3
  import { CompilerOptions, CustomTransformers, Diagnostic, ParsedCommandLine } from 'typescript';
4
4
  import type { TTypeScript } from '../types';
5
+ import type { RawCompilerOptions } from '../tsconfig-raw';
5
6
  export declare class ConfigSet {
7
+ private readonly jestConfig;
8
+ private readonly parentLogger?;
6
9
  readonly logger: Logger;
7
10
  readonly compilerModule: TTypeScript;
8
11
  readonly isolatedModules: boolean;
@@ -13,9 +16,9 @@ export declare class ConfigSet {
13
16
  readonly rootDir: string;
14
17
  protected _overriddenCompilerOptions: Partial<CompilerOptions>;
15
18
  constructor(jestConfig: Config.ProjectConfig, parentLogger?: Logger | undefined);
16
- protected _resolveTsConfig(compilerOptions?: CompilerOptions, resolvedConfigFile?: string): Record<string, any>;
19
+ protected _resolveTsConfig(compilerOptions?: RawCompilerOptions, resolvedConfigFile?: string): Record<string, any>;
17
20
  get tsJestDigest(): string;
18
- get isTestFile(): (fileName: string) => boolean;
21
+ isTestFile(fileName: string): boolean;
19
22
  shouldStringifyContent(filePath: string): boolean;
20
23
  raiseDiagnostics(diagnostics: Diagnostic[], filePath?: string, logger?: Logger): void;
21
24
  shouldReportDiagnostics(filePath: string): boolean;
@@ -117,8 +117,8 @@ var toDiagnosticCodeList = function (items, into) {
117
117
  };
118
118
  var ConfigSet = (function () {
119
119
  function ConfigSet(jestConfig, parentLogger) {
120
- var _a;
121
- var _b, _c, _d, _e;
120
+ var _a, _b;
121
+ var _c, _d, _e, _f;
122
122
  this.jestConfig = jestConfig;
123
123
  this.parentLogger = parentLogger;
124
124
  this.customTransformers = Object.create(null);
@@ -141,14 +141,21 @@ var ConfigSet = (function () {
141
141
  this.logger = this.parentLogger
142
142
  ? this.parentLogger.child((_a = {}, _a[bs_logger_1.LogContexts.namespace] = 'config', _a))
143
143
  : logger_1.rootLogger.child({ namespace: 'config' });
144
- this.cwd = path_1.normalize((_b = this.jestConfig.cwd) !== null && _b !== void 0 ? _b : process.cwd());
145
- this.rootDir = path_1.normalize((_c = this.jestConfig.rootDir) !== null && _c !== void 0 ? _c : this.cwd);
144
+ this.cwd = path_1.normalize((_c = this.jestConfig.cwd) !== null && _c !== void 0 ? _c : process.cwd());
145
+ this.rootDir = path_1.normalize((_d = this.jestConfig.rootDir) !== null && _d !== void 0 ? _d : this.cwd);
146
146
  var tsJestCfg = this.jestConfig.globals && this.jestConfig.globals['ts-jest'];
147
147
  var options = tsJestCfg !== null && tsJestCfg !== void 0 ? tsJestCfg : Object.create(null);
148
- this.compilerModule = importer_1.importer.typescript("Using \"ts-jest\" requires this package to be installed.", (_d = options.compiler) !== null && _d !== void 0 ? _d : 'typescript');
149
- this.isolatedModules = (_e = options.isolatedModules) !== null && _e !== void 0 ? _e : false;
148
+ this.compilerModule = importer_1.importer.typescript("Using \"ts-jest\" requires this package to be installed.", (_e = options.compiler) !== null && _e !== void 0 ? _e : 'typescript');
149
+ this.isolatedModules = (_f = options.isolatedModules) !== null && _f !== void 0 ? _f : false;
150
150
  this.logger.debug({ compilerModule: this.compilerModule }, 'normalized compiler module config via ts-jest option');
151
151
  this._backportJestCfg();
152
+ this._matchablePatterns = __spread(this._jestCfg.testMatch, this._jestCfg.testRegex).filter(function (pattern) {
153
+ return pattern instanceof RegExp || typeof pattern === 'string';
154
+ });
155
+ if (!this._matchablePatterns.length) {
156
+ (_b = this._matchablePatterns).push.apply(_b, __spread(constants_1.DEFAULT_JEST_TEST_MATCH));
157
+ }
158
+ this._matchTestFilePath = jest_util_1.globsToMatcher(this._matchablePatterns.filter(function (pattern) { return typeof pattern === 'string'; }));
152
159
  this._setupTsJestCfg(options);
153
160
  this._resolveTsCacheDir();
154
161
  }
@@ -159,7 +166,7 @@ var ConfigSet = (function () {
159
166
  };
160
167
  ConfigSet.prototype._setupTsJestCfg = function (options) {
161
168
  var _this = this;
162
- var _a, _b, _c;
169
+ var _a, _b, _c, _d;
163
170
  if (options.packageJson) {
164
171
  this.logger.warn("The option `packageJson` is deprecated and will be removed in ts-jest 27. This option is not used by internal `ts-jest`");
165
172
  }
@@ -203,23 +210,36 @@ var ConfigSet = (function () {
203
210
  }
204
211
  this._diagnostics = {
205
212
  pretty: (_b = diagnosticsOpt.pretty) !== null && _b !== void 0 ? _b : true,
213
+ exclude: (_c = diagnosticsOpt.exclude) !== null && _c !== void 0 ? _c : [],
206
214
  ignoreCodes: toDiagnosticCodeList(ignoreList),
207
- pathRegex: normalizeRegex(diagnosticsOpt.pathRegex),
208
215
  throws: !diagnosticsOpt.warnOnly,
209
216
  };
217
+ if (diagnosticsOpt.pathRegex) {
218
+ this.logger.warn("The option `pathRegex` is deprecated and will be removed in ts-jest 27, use `exclude` instead");
219
+ this._diagnostics = __assign(__assign({}, this._diagnostics), { pathRegex: normalizeRegex(diagnosticsOpt.pathRegex) });
220
+ }
210
221
  }
211
222
  else {
212
223
  this._diagnostics = {
213
224
  ignoreCodes: diagnosticsOpt ? toDiagnosticCodeList(ignoreList) : [],
225
+ exclude: [],
214
226
  pretty: true,
215
227
  throws: diagnosticsOpt,
216
228
  };
217
229
  }
230
+ if (this._diagnostics.pathRegex && !this._diagnostics.exclude.length) {
231
+ this._shouldGetDiagnosticsForFile = new RegExp(this._diagnostics.pathRegex);
232
+ }
233
+ else {
234
+ this._shouldGetDiagnosticsForFile = this._diagnostics.exclude.length
235
+ ? jest_util_1.globsToMatcher(this._diagnostics.exclude)
236
+ : function () { return true; };
237
+ }
218
238
  this.logger.debug({ diagnostics: this._diagnostics }, 'normalized diagnostics config via ts-jest option');
219
239
  if (options.tsConfig) {
220
240
  this.logger.warn("The option `tsConfig` is deprecated and will be removed in ts-jest 27, use `tsconfig` instead");
221
241
  }
222
- var tsconfigOpt = (_c = options.tsConfig) !== null && _c !== void 0 ? _c : options.tsconfig;
242
+ var tsconfigOpt = (_d = options.tsConfig) !== null && _d !== void 0 ? _d : options.tsconfig;
223
243
  var configFilePath = typeof tsconfigOpt === 'string' ? this.resolvePath(tsconfigOpt) : undefined;
224
244
  this.parsedTsConfig = this._resolveTsConfig(typeof tsconfigOpt === 'object' ? tsconfigOpt : undefined, configFilePath);
225
245
  this.raiseDiagnostics(this.parsedTsConfig.errors, configFilePath);
@@ -411,23 +431,12 @@ var ConfigSet = (function () {
411
431
  enumerable: false,
412
432
  configurable: true
413
433
  });
414
- Object.defineProperty(ConfigSet.prototype, "isTestFile", {
415
- get: function () {
416
- var matchablePatterns = __spread(this._jestCfg.testMatch, this._jestCfg.testRegex).filter(function (pattern) {
417
- return pattern instanceof RegExp || typeof pattern === 'string';
418
- });
419
- if (!matchablePatterns.length) {
420
- matchablePatterns.push.apply(matchablePatterns, __spread(constants_1.DEFAULT_JEST_TEST_MATCH));
421
- }
422
- var stringPatterns = matchablePatterns.filter(function (pattern) { return typeof pattern === 'string'; });
423
- var isMatch = jest_util_1.globsToMatcher(stringPatterns);
424
- return function (fileName) {
425
- return matchablePatterns.some(function (pattern) { return (typeof pattern === 'string' ? isMatch(fileName) : pattern.test(fileName)); });
426
- };
427
- },
428
- enumerable: false,
429
- configurable: true
430
- });
434
+ ConfigSet.prototype.isTestFile = function (fileName) {
435
+ var _this = this;
436
+ return this._matchablePatterns.some(function (pattern) {
437
+ return typeof pattern === 'string' ? _this._matchTestFilePath(fileName) : pattern.test(fileName);
438
+ });
439
+ };
431
440
  ConfigSet.prototype.shouldStringifyContent = function (filePath) {
432
441
  return this._stringifyContentRegExp ? this._stringifyContentRegExp.test(filePath) : false;
433
442
  };
@@ -454,14 +463,9 @@ var ConfigSet = (function () {
454
463
  logger ? logger.warn({ error: error }, error.message) : this.logger.warn({ error: error }, error.message);
455
464
  };
456
465
  ConfigSet.prototype.shouldReportDiagnostics = function (filePath) {
457
- var pathRegex = this._diagnostics.pathRegex;
458
- if (pathRegex) {
459
- var regex = new RegExp(pathRegex);
460
- return regex.test(filePath);
461
- }
462
- else {
463
- return true;
464
- }
466
+ return this._shouldGetDiagnosticsForFile instanceof RegExp
467
+ ? this._shouldGetDiagnosticsForFile.test(filePath)
468
+ : this._shouldGetDiagnosticsForFile(filePath);
465
469
  };
466
470
  ConfigSet.prototype._createTsError = function (diagnostics) {
467
471
  var _this = this;
@@ -518,9 +522,6 @@ var ConfigSet = (function () {
518
522
  __decorate([
519
523
  memoize_1.Memoize()
520
524
  ], ConfigSet.prototype, "hooks", null);
521
- __decorate([
522
- memoize_1.Memoize()
523
- ], ConfigSet.prototype, "isTestFile", null);
524
525
  return ConfigSet;
525
526
  }());
526
527
  exports.ConfigSet = ConfigSet;
@@ -1,5 +1,5 @@
1
1
  import type { Config } from '@jest/types';
2
- export declare type TsJestPresets = Pick<Config.InitialOptions, 'moduleFileExtensions' | 'transform' | 'testMatch'>;
2
+ import type { TsJestPresets } from '../types';
3
3
  interface CreateJestPresetOptions {
4
4
  allowJs?: boolean;
5
5
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.internals = void 0;
23
+ var hoisting = __importStar(require("./hoist-jest"));
24
+ exports.internals = [hoisting];
@@ -0,0 +1,3 @@
1
+ import type * as _ts from 'typescript';
2
+ import type { ConfigSet } from '../config/config-set';
3
+ export declare function factory(cs: ConfigSet): (ctx: _ts.TransformationContext) => _ts.Transformer<_ts.SourceFile>;
@@ -0,0 +1,121 @@
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 __values = (this && this.__values) || function(o) {
14
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
15
+ if (m) return m.call(o);
16
+ if (o && typeof o.length === "number") return {
17
+ next: function () {
18
+ if (o && i >= o.length) o = void 0;
19
+ return { value: o && o[i++], done: !o };
20
+ }
21
+ };
22
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.factory = exports.version = exports.name = void 0;
26
+ var bs_logger_1 = require("bs-logger");
27
+ var path_1 = require("path");
28
+ exports.name = 'path-mapping';
29
+ exports.version = 1;
30
+ var isBaseDir = function (base, dir) { var _a; return !((_a = path_1.relative(base, dir)) === null || _a === void 0 ? void 0 : _a.startsWith('.')); };
31
+ function factory(cs) {
32
+ var _a;
33
+ var logger = cs.logger.child({ namespace: 'ts-path-mapping' });
34
+ var ts = cs.compilerModule;
35
+ var compilerOptions = cs.parsedTsConfig.options;
36
+ var rootDirs = (_a = compilerOptions.rootDirs) === null || _a === void 0 ? void 0 : _a.filter(path_1.isAbsolute);
37
+ var isDynamicImport = function (node) {
38
+ return ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword;
39
+ };
40
+ var isRequire = function (node) {
41
+ return ts.isCallExpression(node) &&
42
+ ts.isIdentifier(node.expression) &&
43
+ node.expression.text === 'require' &&
44
+ ts.isStringLiteral(node.arguments[0]) &&
45
+ node.arguments.length === 1;
46
+ };
47
+ var createVisitor = function (ctx, sf) {
48
+ var fileName = sf.fileName;
49
+ var fileDir = path_1.normalize(path_1.dirname(fileName));
50
+ var rewritePath = function (importPath) {
51
+ var e_1, _a;
52
+ var p = importPath;
53
+ var resolvedModule = ts.resolveModuleName(importPath, fileName, compilerOptions, ts.sys).resolvedModule;
54
+ if (resolvedModule) {
55
+ var resolvedFileName = resolvedModule.resolvedFileName;
56
+ var filePath = fileDir;
57
+ var modulePath = path_1.dirname(resolvedFileName);
58
+ if (rootDirs) {
59
+ var fileRootDir = '';
60
+ var moduleRootDir = '';
61
+ try {
62
+ for (var rootDirs_1 = __values(rootDirs), rootDirs_1_1 = rootDirs_1.next(); !rootDirs_1_1.done; rootDirs_1_1 = rootDirs_1.next()) {
63
+ var rootDir = rootDirs_1_1.value;
64
+ if (isBaseDir(rootDir, resolvedFileName) && rootDir.length > moduleRootDir.length)
65
+ moduleRootDir = rootDir;
66
+ if (isBaseDir(rootDir, fileName) && rootDir.length > fileRootDir.length)
67
+ fileRootDir = rootDir;
68
+ }
69
+ }
70
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
71
+ finally {
72
+ try {
73
+ if (rootDirs_1_1 && !rootDirs_1_1.done && (_a = rootDirs_1.return)) _a.call(rootDirs_1);
74
+ }
75
+ finally { if (e_1) throw e_1.error; }
76
+ }
77
+ if (fileRootDir && moduleRootDir) {
78
+ filePath = path_1.relative(fileRootDir, filePath);
79
+ modulePath = path_1.relative(moduleRootDir, modulePath);
80
+ }
81
+ }
82
+ p = path_1.normalize(path_1.join(path_1.relative(filePath, modulePath), path_1.basename(resolvedFileName)));
83
+ p = p.startsWith('.') ? p : "./" + p;
84
+ }
85
+ return p;
86
+ };
87
+ var visitor = function (node) {
88
+ var rewrittenPath;
89
+ var newNode = ts.getMutableClone(node);
90
+ if (isDynamicImport(node) || isRequire(node)) {
91
+ rewrittenPath = rewritePath(node.arguments[0].text);
92
+ return __assign(__assign({}, newNode), { arguments: ts.createNodeArray([ts.createStringLiteral(rewrittenPath)]) });
93
+ }
94
+ if (ts.isExternalModuleReference(node) && ts.isStringLiteral(node.expression)) {
95
+ rewrittenPath = rewritePath(node.expression.text);
96
+ return ts.updateExternalModuleReference(newNode, ts.createLiteral(rewrittenPath));
97
+ }
98
+ if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {
99
+ rewrittenPath = rewritePath(node.moduleSpecifier.text);
100
+ return __assign(__assign({}, newNode), { moduleSpecifier: ts.createLiteral(rewrittenPath) });
101
+ }
102
+ if (ts.isExportDeclaration(node) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
103
+ rewrittenPath = rewritePath(node.moduleSpecifier.text);
104
+ return __assign(__assign({}, newNode), { moduleSpecifier: ts.createLiteral(rewrittenPath) });
105
+ }
106
+ if (ts.isImportTypeNode(node) &&
107
+ ts.isLiteralTypeNode(node.argument) &&
108
+ ts.isStringLiteral(node.argument.literal)) {
109
+ rewrittenPath = rewritePath(node.argument.literal.text);
110
+ return __assign(__assign({}, newNode), { argument: ts.createLiteralTypeNode(ts.createStringLiteral(rewrittenPath)) });
111
+ }
112
+ return ts.visitEachChild(node, visitor, ctx);
113
+ };
114
+ return visitor;
115
+ };
116
+ return function (ctx) {
117
+ var _a;
118
+ return logger.wrap((_a = {}, _a[bs_logger_1.LogContexts.logLevel] = bs_logger_1.LogLevels.debug, _a.call = null, _a), 'visitSourceFileNode(): path mapping', function (sf) { return ts.visitNode(sf, createVisitor(ctx, sf)); });
119
+ };
120
+ }
121
+ exports.factory = factory;
@@ -5,9 +5,8 @@ import { ConfigSet } from './config/config-set';
5
5
  export declare class TsJestTransformer implements Transformer {
6
6
  protected readonly logger: Logger;
7
7
  protected _transformCfgStr: string;
8
- protected _configSet: ConfigSet;
9
8
  constructor();
9
+ configsFor(jestConfig: Config.ProjectConfig): ConfigSet;
10
10
  process(input: string, filePath: Config.Path, jestConfig: Config.ProjectConfig, transformOptions?: TransformOptions): TransformedSource | string;
11
11
  getCacheKey(fileContent: string, filePath: string, _jestConfigStr: string, transformOptions: CacheKeyOptions): string;
12
- protected createOrResolveTransformerCfg(jestConfig: Config.ProjectConfig): void;
13
12
  }
@@ -24,13 +24,50 @@ var TsJestTransformer = (function () {
24
24
  this.logger = logger_1.rootLogger.child({ namespace: 'ts-jest-transformer' });
25
25
  this.logger.debug('created new transformer');
26
26
  }
27
+ TsJestTransformer.prototype.configsFor = function (jestConfig) {
28
+ var ccs = TsJestTransformer._cachedConfigSets.find(function (cs) { return cs.jestConfig.value === jestConfig; });
29
+ var configSet;
30
+ if (ccs) {
31
+ this._transformCfgStr = ccs.transformerCfgStr;
32
+ configSet = ccs.configSet;
33
+ }
34
+ else {
35
+ var serializedJestCfg_1 = json_1.stringify(jestConfig);
36
+ var serializedCcs = TsJestTransformer._cachedConfigSets.find(function (cs) { return cs.jestConfig.serialized === serializedJestCfg_1; });
37
+ if (serializedCcs) {
38
+ serializedCcs.jestConfig.value = jestConfig;
39
+ this._transformCfgStr = serializedCcs.transformerCfgStr;
40
+ configSet = serializedCcs.configSet;
41
+ }
42
+ else {
43
+ this.logger.info('no matching config-set found, creating a new one');
44
+ configSet = new config_set_1.ConfigSet(jestConfig);
45
+ var jest_1 = __assign({}, jestConfig);
46
+ var globals = (jest_1.globals = __assign({}, jest_1.globals));
47
+ jest_1.name = undefined;
48
+ jest_1.cacheDirectory = undefined;
49
+ delete globals['ts-jest'];
50
+ this._transformCfgStr = new jsonable_value_1.JsonableValue(__assign(__assign({ digest: configSet.tsJestDigest, babel: configSet.babelConfig }, jest_1), { tsconfig: {
51
+ options: configSet.parsedTsConfig.options,
52
+ raw: configSet.parsedTsConfig.raw,
53
+ } })).serialized;
54
+ TsJestTransformer._cachedConfigSets.push({
55
+ jestConfig: new jsonable_value_1.JsonableValue(jestConfig),
56
+ configSet: configSet,
57
+ transformerCfgStr: this._transformCfgStr,
58
+ });
59
+ }
60
+ }
61
+ return configSet;
62
+ };
27
63
  TsJestTransformer.prototype.process = function (input, filePath, jestConfig, transformOptions) {
28
64
  this.logger.debug({ fileName: filePath, transformOptions: transformOptions }, 'processing', filePath);
29
65
  var result;
30
66
  var source = input;
31
- var hooks = this._configSet.hooks;
32
- var shouldStringifyContent = this._configSet.shouldStringifyContent(filePath);
33
- var babelJest = shouldStringifyContent ? undefined : this._configSet.babelJestTransformer;
67
+ var configs = this.configsFor(jestConfig);
68
+ var hooks = configs.hooks;
69
+ var shouldStringifyContent = configs.shouldStringifyContent(filePath);
70
+ var babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
34
71
  var isDefinitionFile = filePath.endsWith(constants_1.DECLARATION_TYPE_EXT);
35
72
  var isJsFile = constants_1.JS_JSX_REGEX.test(filePath);
36
73
  var isTsFile = !isDefinitionFile && constants_1.TS_TSX_REGEX.test(filePath);
@@ -40,12 +77,12 @@ var TsJestTransformer = (function () {
40
77
  else if (isDefinitionFile) {
41
78
  result = '';
42
79
  }
43
- else if (!this._configSet.parsedTsConfig.options.allowJs && isJsFile) {
80
+ else if (!configs.parsedTsConfig.options.allowJs && isJsFile) {
44
81
  this.logger.warn({ fileName: filePath }, messages_1.interpolate("Got a `.js` file to compile while `allowJs` option is not set to `true` (file: {{path}}). To fix this:\n - if you want TypeScript to process JS files, set `allowJs` to `true` in your TypeScript config (usually tsconfig.json)\n - if you do not want TypeScript to process your `.js` files, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match `.js` files anymore", { path: filePath }));
45
82
  result = source;
46
83
  }
47
84
  else if (isJsFile || isTsFile) {
48
- result = this._configSet.tsCompiler.compile(source, filePath);
85
+ result = configs.tsCompiler.compile(source, filePath);
49
86
  }
50
87
  else {
51
88
  var message = babelJest ? "Got a unknown file type to compile (file: {{path}}). To fix this, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match this kind of files anymore. If you still want Babel to process it, add another entry to the `transform` option with value `babel-jest` which key matches this type of files." : "Got a unknown file type to compile (file: {{path}}). To fix this, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match this kind of files anymore.";
@@ -66,45 +103,11 @@ var TsJestTransformer = (function () {
66
103
  return result;
67
104
  };
68
105
  TsJestTransformer.prototype.getCacheKey = function (fileContent, filePath, _jestConfigStr, transformOptions) {
69
- this.createOrResolveTransformerCfg(transformOptions.config);
106
+ var configs = this.configsFor(transformOptions.config);
70
107
  this.logger.debug({ fileName: filePath, transformOptions: transformOptions }, 'computing cache key for', filePath);
71
- var _a = transformOptions.instrument, instrument = _a === void 0 ? false : _a, _b = transformOptions.rootDir, rootDir = _b === void 0 ? this._configSet.rootDir : _b;
108
+ var _a = transformOptions.instrument, instrument = _a === void 0 ? false : _a, _b = transformOptions.rootDir, rootDir = _b === void 0 ? configs.rootDir : _b;
72
109
  return sha1_1.sha1(this._transformCfgStr, '\x00', rootDir, '\x00', "instrument:" + (instrument ? 'on' : 'off'), '\x00', fileContent, '\x00', filePath);
73
110
  };
74
- TsJestTransformer.prototype.createOrResolveTransformerCfg = function (jestConfig) {
75
- var ccs = TsJestTransformer._cachedConfigSets.find(function (cs) { return cs.jestConfig.value === jestConfig; });
76
- if (ccs) {
77
- this._transformCfgStr = ccs.transformerCfgStr;
78
- this._configSet = ccs.configSet;
79
- }
80
- else {
81
- var serializedJestCfg_1 = json_1.stringify(jestConfig);
82
- var serializedCcs = TsJestTransformer._cachedConfigSets.find(function (cs) { return cs.jestConfig.serialized === serializedJestCfg_1; });
83
- if (serializedCcs) {
84
- serializedCcs.jestConfig.value = jestConfig;
85
- this._transformCfgStr = serializedCcs.transformerCfgStr;
86
- this._configSet = serializedCcs.configSet;
87
- }
88
- else {
89
- this.logger.info('no matching config-set found, creating a new one');
90
- this._configSet = new config_set_1.ConfigSet(jestConfig);
91
- var jest_1 = __assign({}, jestConfig);
92
- var globals = (jest_1.globals = __assign({}, jest_1.globals));
93
- jest_1.name = undefined;
94
- jest_1.cacheDirectory = undefined;
95
- delete globals['ts-jest'];
96
- this._transformCfgStr = new jsonable_value_1.JsonableValue(__assign(__assign({ digest: this._configSet.tsJestDigest }, jest_1), { babel: this._configSet.babelConfig, tsconfig: {
97
- options: this._configSet.parsedTsConfig.options,
98
- raw: this._configSet.parsedTsConfig.raw,
99
- } })).serialized;
100
- TsJestTransformer._cachedConfigSets.push({
101
- jestConfig: new jsonable_value_1.JsonableValue(jestConfig),
102
- configSet: this._configSet,
103
- transformerCfgStr: this._transformCfgStr,
104
- });
105
- }
106
- }
107
- };
108
111
  TsJestTransformer._cachedConfigSets = [];
109
112
  return TsJestTransformer;
110
113
  }());
@@ -0,0 +1,105 @@
1
+ export interface RawCompilerOptions {
2
+ charset?: string;
3
+ composite?: boolean;
4
+ declaration?: boolean;
5
+ declarationDir?: string | null;
6
+ diagnostics?: boolean;
7
+ disableReferencedProjectLoad?: boolean;
8
+ emitBOM?: boolean;
9
+ emitDeclarationOnly?: boolean;
10
+ incremental?: boolean;
11
+ tsBuildInfoFile?: string;
12
+ inlineSourceMap?: boolean;
13
+ inlineSources?: boolean;
14
+ jsx?: 'preserve' | 'react' | 'react-jsx' | 'react-jsxdev' | 'react-native';
15
+ reactNamespace?: string;
16
+ jsxFactory?: string;
17
+ jsxFragmentFactory?: string;
18
+ jsxImportSource?: string;
19
+ listFiles?: boolean;
20
+ mapRoot?: string;
21
+ module?: 'CommonJS' | 'AMD' | 'System' | 'UMD' | 'ES6' | 'ES2015' | 'ES2020' | 'ESNext' | 'None' | string;
22
+ moduleResolution?: 'Classic' | 'Node';
23
+ newLine?: 'crlf' | 'lf';
24
+ noEmit?: boolean;
25
+ noEmitHelpers?: boolean;
26
+ noEmitOnError?: boolean;
27
+ noImplicitAny?: boolean;
28
+ noImplicitThis?: boolean;
29
+ noUnusedLocals?: boolean;
30
+ noUnusedParameters?: boolean;
31
+ noLib?: boolean;
32
+ noResolve?: boolean;
33
+ noStrictGenericChecks?: boolean;
34
+ skipDefaultLibCheck?: boolean;
35
+ skipLibCheck?: boolean;
36
+ outFile?: string;
37
+ outDir?: string;
38
+ preserveConstEnums?: boolean;
39
+ preserveSymlinks?: boolean;
40
+ preserveWatchOutput?: boolean;
41
+ pretty?: boolean;
42
+ removeComments?: boolean;
43
+ rootDir?: string;
44
+ isolatedModules?: boolean;
45
+ sourceMap?: boolean;
46
+ sourceRoot?: string;
47
+ suppressExcessPropertyErrors?: boolean;
48
+ suppressImplicitAnyIndexErrors?: boolean;
49
+ target?: 'ES3' | 'ES5' | 'ES6' | 'ES2015' | 'ES2016' | 'ES2017' | 'ES2018' | 'ES2019' | 'ES2020' | 'ESNext' | string;
50
+ watch?: boolean;
51
+ fallbackPolling?: 'fixedPollingInterval' | 'priorityPollingInterval' | 'dynamicPriorityPolling';
52
+ watchDirectory?: 'useFsEvents' | 'fixedPollingInterval' | 'dynamicPriorityPolling';
53
+ watchFile?: 'fixedPollingInterval' | 'priorityPollingInterval' | 'dynamicPriorityPolling' | 'useFsEvents' | 'useFsEventsOnParentDirectory';
54
+ experimentalDecorators?: boolean;
55
+ emitDecoratorMetadata?: boolean;
56
+ allowUnusedLabels?: boolean;
57
+ noImplicitReturns?: boolean;
58
+ noUncheckedIndexedAccess?: boolean;
59
+ noFallthroughCasesInSwitch?: boolean;
60
+ allowUnreachableCode?: boolean;
61
+ forceConsistentCasingInFileNames?: boolean;
62
+ generateCpuProfile?: string;
63
+ baseUrl?: string;
64
+ paths?: {
65
+ [k: string]: string[];
66
+ };
67
+ plugins?: {
68
+ name?: string;
69
+ [k: string]: unknown;
70
+ }[];
71
+ rootDirs?: string[];
72
+ typeRoots?: string[];
73
+ types?: string[];
74
+ traceResolution?: boolean;
75
+ allowJs?: boolean;
76
+ noErrorTruncation?: boolean;
77
+ allowSyntheticDefaultImports?: boolean;
78
+ noImplicitUseStrict?: boolean;
79
+ listEmittedFiles?: boolean;
80
+ disableSizeLimit?: boolean;
81
+ lib?: ('ES5' | 'ES6' | 'ES2015' | 'ES2015.Collection' | 'ES2015.Core' | 'ES2015.Generator' | 'ES2015.Iterable' | 'ES2015.Promise' | 'ES2015.Proxy' | 'ES2015.Reflect' | 'ES2015.Symbol.WellKnown' | 'ES2015.Symbol' | 'ES2016' | 'ES2016.Array.Include' | 'ES2017' | 'ES2017.Intl' | 'ES2017.Object' | 'ES2017.SharedMemory' | 'ES2017.String' | 'ES2017.TypedArrays' | 'ES2018' | 'ES2018.AsyncGenerator' | 'ES2018.AsyncIterable' | 'ES2018.Intl' | 'ES2018.Promise' | 'ES2018.Regexp' | 'ES2019' | 'ES2019.Array' | 'ES2019.Object' | 'ES2019.String' | 'ES2019.Symbol' | 'ES2020' | 'ES2020.BigInt' | 'ES2020.Promise' | 'ES2020.String' | 'ES2020.Symbol.WellKnown' | 'ESNext' | 'ESNext.Array' | 'ESNext.AsyncIterable' | 'ESNext.BigInt' | 'ESNext.Intl' | 'ESNext.Promise' | 'ESNext.String' | 'ESNext.Symbol' | 'DOM' | 'DOM.Iterable' | 'ScriptHost' | 'WebWorker' | 'WebWorker.ImportScripts')[];
82
+ strictNullChecks?: boolean;
83
+ maxNodeModuleJsDepth?: number;
84
+ importHelpers?: boolean;
85
+ importsNotUsedAsValues?: 'remove' | 'preserve' | 'error';
86
+ alwaysStrict?: boolean;
87
+ strict?: boolean;
88
+ strictBindCallApply?: boolean;
89
+ downlevelIteration?: boolean;
90
+ checkJs?: boolean;
91
+ strictFunctionTypes?: boolean;
92
+ strictPropertyInitialization?: boolean;
93
+ esModuleInterop?: boolean;
94
+ allowUmdGlobalAccess?: boolean;
95
+ keyofStringsOnly?: boolean;
96
+ useDefineForClassFields?: boolean;
97
+ declarationMap?: boolean;
98
+ resolveJsonModule?: boolean;
99
+ assumeChangesOnlyAffectDirectDependencies?: boolean;
100
+ extendedDiagnostics?: boolean;
101
+ listFilesOnly?: boolean;
102
+ disableSourceOfProjectReferenceRedirect?: boolean;
103
+ disableSolutionSearching?: boolean;
104
+ [k: string]: unknown;
105
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/types.d.ts CHANGED
@@ -1,5 +1,7 @@
1
+ import type { Config } from '@jest/types';
1
2
  import type * as _babel from 'babel__core';
2
3
  import type * as _ts from 'typescript';
4
+ import type { RawCompilerOptions } from './tsconfig-raw';
3
5
  export declare type TTypeScript = typeof _ts;
4
6
  export declare type BabelConfig = _babel.TransformOptions;
5
7
  export interface AstTransformer<T = Record<string, unknown>> {
@@ -12,8 +14,8 @@ export interface ConfigCustomTransformer {
12
14
  afterDeclarations?: (string | AstTransformer)[];
13
15
  }
14
16
  export interface TsJestGlobalOptions {
15
- tsConfig?: boolean | string | _ts.CompilerOptions;
16
- tsconfig?: boolean | string | _ts.CompilerOptions;
17
+ tsConfig?: boolean | string | RawCompilerOptions;
18
+ tsconfig?: boolean | string | RawCompilerOptions;
17
19
  packageJson?: boolean | string | Record<string, unknown>;
18
20
  isolatedModules?: boolean;
19
21
  compiler?: string;
@@ -22,15 +24,24 @@ export interface TsJestGlobalOptions {
22
24
  pretty?: boolean;
23
25
  ignoreCodes?: number | string | (number | string)[];
24
26
  pathRegex?: RegExp | string;
27
+ exclude?: Config.Glob[];
25
28
  warnOnly?: boolean;
26
29
  };
27
30
  babelConfig?: boolean | string | BabelConfig;
28
31
  stringifyContentPathRegex?: string | RegExp;
29
32
  }
33
+ export interface GlobalConfigTsJest extends Config.ConfigGlobals {
34
+ 'ts-jest': TsJestGlobalOptions;
35
+ }
36
+ export interface InitialOptionsTsJest extends Config.InitialOptions {
37
+ globals?: GlobalConfigTsJest;
38
+ }
39
+ export declare type TsJestPresets = Pick<Config.InitialOptions, 'moduleFileExtensions' | 'transform' | 'testMatch'>;
30
40
  export interface TsJestDiagnosticsCfg {
31
41
  pretty: boolean;
32
42
  ignoreCodes: number[];
33
43
  pathRegex?: string | undefined;
44
+ exclude: Config.Glob[];
34
45
  throws: boolean;
35
46
  warnOnly?: boolean;
36
47
  }
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "ts-jest",
3
- "version": "26.4.4-alpha.0",
3
+ "version": "26.5.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
- "bin": "cli.js",
6
+ "bin": {
7
+ "ts-jest": "cli.js"
8
+ },
7
9
  "description": "A preprocessor with source maps support to help use TypeScript with Jest",
8
10
  "scripts": {
9
- "prebuild": "node scripts/clean-dist.js",
11
+ "prebuild": "node scripts/pre-build.js",
10
12
  "build": "tsc -p tsconfig.build.json",
11
13
  "postbuild": "node scripts/post-build.js",
12
14
  "clean": "node scripts/clean.js",
@@ -30,7 +32,8 @@
30
32
  "prepublishOnly": "npm run test",
31
33
  "preversion": "npm run test",
32
34
  "update:e2e": "node scripts/update-e2e-templates.js",
33
- "version": "npm run changelog && git add CHANGELOG.md"
35
+ "version": "npm run changelog && git add CHANGELOG.md",
36
+ "raw-tsconfig-types": "node scripts/tsconfig-raw-types.js"
34
37
  },
35
38
  "repository": {
36
39
  "type": "git",
@@ -61,7 +64,7 @@
61
64
  "fast-json-stable-stringify": "2.x",
62
65
  "jest-util": "^26.1.0",
63
66
  "json5": "2.x",
64
- "lodash.memoize": "4.x",
67
+ "lodash": "4.x",
65
68
  "make-error": "1.x",
66
69
  "mkdirp": "1.x",
67
70
  "semver": "7.x",
@@ -89,9 +92,7 @@
89
92
  "@types/fs-extra": "latest",
90
93
  "@types/js-yaml": "latest",
91
94
  "@types/json5": "latest",
92
- "@types/lodash.memoize": "4.x",
93
- "@types/lodash.merge": "4.x",
94
- "@types/lodash.set": "4.x",
95
+ "@types/lodash": "4.x",
95
96
  "@types/micromatch": "4.x",
96
97
  "@types/mkdirp": "latest",
97
98
  "@types/node": "14.x",
@@ -114,9 +115,9 @@
114
115
  "husky": "4.x",
115
116
  "jest": "26.x",
116
117
  "js-yaml": "latest",
118
+ "json-schema-to-typescript": "^10.1.3",
117
119
  "lint-staged": "latest",
118
- "lodash.merge": "4.x",
119
- "lodash.set": "4.x",
120
+ "node-fetch": "^2.6.1",
120
121
  "npm-run-all": "latest",
121
122
  "prettier": "2.x",
122
123
  "source-map": "latest",
@@ -0,0 +1,8 @@
1
+ import type { TsJestPresets } from '../dist/types'
2
+
3
+ declare const _default: {
4
+ defaults: TsJestPresets;
5
+ jsWithTs: TsJestPresets;
6
+ jsWithBabel: TsJestPresets;
7
+ };
8
+ export = _default;