ts-jest 29.0.0 → 29.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/.ts-jest-digest +1 -1
  2. package/CHANGELOG.md +33 -0
  3. package/dist/cli/config/init.d.ts +5 -0
  4. package/dist/cli/config/init.js +62 -20
  5. package/dist/cli/config/migrate.js +50 -10
  6. package/dist/cli/help.js +7 -1
  7. package/dist/cli/helpers/presets.js +12 -5
  8. package/dist/cli/index.js +9 -5
  9. package/dist/config/paths-to-module-name-mapper.js +6 -2
  10. package/dist/constants.js +5 -0
  11. package/dist/legacy/compiler/compiler-utils.d.ts +6 -0
  12. package/dist/legacy/compiler/compiler-utils.js +10 -0
  13. package/dist/legacy/compiler/ts-compiler.d.ts +6 -0
  14. package/dist/legacy/compiler/ts-compiler.js +76 -7
  15. package/dist/legacy/compiler/ts-jest-compiler.js +2 -1
  16. package/dist/legacy/config/config-set.d.ts +7 -0
  17. package/dist/legacy/config/config-set.js +91 -12
  18. package/dist/legacy/ts-jest-transformer.d.ts +13 -0
  19. package/dist/legacy/ts-jest-transformer.js +62 -16
  20. package/dist/raw-compiler-options.d.ts +297 -0
  21. package/dist/transformers/hoist-jest.d.ts +4 -0
  22. package/dist/transformers/hoist-jest.js +24 -0
  23. package/dist/types.d.ts +100 -21
  24. package/dist/utils/backports.js +13 -4
  25. package/dist/utils/get-package-version.js +3 -0
  26. package/dist/utils/importer.js +31 -4
  27. package/dist/utils/json.js +9 -0
  28. package/dist/utils/jsonable-value.js +2 -1
  29. package/dist/utils/logger.js +1 -0
  30. package/dist/utils/memoize.js +20 -1
  31. package/dist/utils/messages.js +5 -0
  32. package/dist/utils/normalize-slashes.js +3 -0
  33. package/dist/utils/sha1.js +10 -0
  34. package/dist/utils/ts-error.js +12 -2
  35. package/dist/utils/version-checkers.js +9 -5
  36. package/package.json +10 -10
package/.ts-jest-digest CHANGED
@@ -1 +1 @@
1
- f9fb4e4bd207c5c42e82ee8e8107b923ea6a903b
1
+ 60d16d7ed3a05cdc98e1c7fc94b0fb03a86f0172
package/CHANGELOG.md CHANGED
@@ -1,3 +1,36 @@
1
+ ## [29.0.2](https://github.com/kulshekhar/ts-jest/compare/v29.0.1...v29.0.2) (2022-09-23)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * mark `ts-jest` as optional in `ConfigGlobals` ([#3816](https://github.com/kulshekhar/ts-jest/issues/3816)) ([cbb88bb](https://github.com/kulshekhar/ts-jest/commit/cbb88bba34dbb852d8f4013be6e020769feb306d)), closes [#3815](https://github.com/kulshekhar/ts-jest/issues/3815)
7
+ * use correct typings for `config:init` command ([#3825](https://github.com/kulshekhar/ts-jest/issues/3825)) ([21b94db](https://github.com/kulshekhar/ts-jest/commit/21b94dbca25b762f79e63b92dea12d830f444570))
8
+
9
+
10
+
11
+ ## [29.0.2](https://github.com/kulshekhar/ts-jest/compare/v29.0.1...v29.0.2) (2022-09-22)
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * mark `ts-jest` as optional in `ConfigGlobals` ([#3816](https://github.com/kulshekhar/ts-jest/issues/3816)) ([cbb88bb](https://github.com/kulshekhar/ts-jest/commit/cbb88bba34dbb852d8f4013be6e020769feb306d)), closes [#3815](https://github.com/kulshekhar/ts-jest/issues/3815)
17
+
18
+
19
+
20
+ ## [29.0.1](https://github.com/kulshekhar/ts-jest/compare/v29.0.0...v29.0.1) (2022-09-13)
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * **legacy:** include existing globals config in cached config ([#3803](https://github.com/kulshekhar/ts-jest/issues/3803)) ([e79be47](https://github.com/kulshekhar/ts-jest/commit/e79be47d2b81a677d0dd39d84328a38ca0f0ffc6))
26
+
27
+
28
+ ### Features
29
+
30
+ * add typings for `ts-jest` options via `transform` config ([#3805](https://github.com/kulshekhar/ts-jest/issues/3805)) ([664b0f2](https://github.com/kulshekhar/ts-jest/commit/664b0f2b446a36dd7661f4840ca3dd7722f1f6ff))
31
+
32
+
33
+
1
34
  # [29.0.0](https://github.com/kulshekhar/ts-jest/compare/v29.0.0-next.1...v29.0.0) (2022-09-08)
2
35
 
3
36
 
@@ -1 +1,6 @@
1
+ /**
2
+ * This has been written quickly. While trying to improve I realised it'd be better to have it in Jest...
3
+ * ...and I saw a merged PR with `jest --init` tool!
4
+ * TODO: see what's the best path for this
5
+ */
1
6
  export {};
@@ -1,4 +1,9 @@
1
1
  "use strict";
2
+ /**
3
+ * This has been written quickly. While trying to improve I realised it'd be better to have it in Jest...
4
+ * ...and I saw a merged PR with `jest --init` tool!
5
+ * TODO: see what's the best path for this
6
+ */
2
7
  var __assign = (this && this.__assign) || function () {
3
8
  __assign = Object.assign || function(t) {
4
9
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -46,16 +51,35 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
51
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
52
  }
48
53
  };
54
+ var __read = (this && this.__read) || function (o, n) {
55
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
56
+ if (!m) return o;
57
+ var i = m.call(o), r, ar = [], e;
58
+ try {
59
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
60
+ }
61
+ catch (error) { e = { error: error }; }
62
+ finally {
63
+ try {
64
+ if (r && !r.done && (m = i["return"])) m.call(i);
65
+ }
66
+ finally { if (e) throw e.error; }
67
+ }
68
+ return ar;
69
+ };
49
70
  Object.defineProperty(exports, "__esModule", { value: true });
50
71
  exports.help = exports.run = void 0;
51
72
  var fs_1 = require("fs");
52
73
  var path_1 = require("path");
53
74
  var json5_1 = require("json5");
54
75
  var presets_1 = require("../helpers/presets");
55
- var 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) {
76
+ /**
77
+ * @internal
78
+ */
79
+ var run = function (args /* , logger: Logger */) { return __awaiter(void 0, void 0, void 0, function () {
80
+ var file, filePath, name, isPackage, exists, pkgFile, hasPackage, _a, jestPreset, askedTsconfig, force, jsdom, tsconfig, pkgJson, jsFilesProcessor, shouldPostProcessWithBabel, preset, body, jestConfig, transformerConfig, content;
81
+ var _b, _c, _d;
82
+ return __generator(this, function (_e) {
59
83
  file = (_c = (_b = args._[0]) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : 'jest.config.js';
60
84
  filePath = (0, path_1.join)(process.cwd(), file);
61
85
  name = (0, path_1.basename)(file);
@@ -67,10 +91,13 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
67
91
  tsconfig = askedTsconfig === 'tsconfig.json' ? undefined : askedTsconfig;
68
92
  pkgJson = hasPackage ? JSON.parse((0, fs_1.readFileSync)(pkgFile, 'utf8')) : {};
69
93
  jsFilesProcessor = args.js, shouldPostProcessWithBabel = args.babel;
94
+ // set defaults for missing options
70
95
  if (jsFilesProcessor == null) {
96
+ // set default js files processor depending on whether the user wants to post-process with babel
71
97
  jsFilesProcessor = shouldPostProcessWithBabel ? 'babel' : undefined;
72
98
  }
73
99
  else if (shouldPostProcessWithBabel == null) {
100
+ // auto enables babel post-processing if the user wants babel to process js files
74
101
  shouldPostProcessWithBabel = jsFilesProcessor === 'babel';
75
102
  }
76
103
  if (jsFilesProcessor === 'babel') {
@@ -101,25 +128,36 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
101
128
  }
102
129
  }
103
130
  if (isPackage) {
104
- base = jestPreset ? { preset: preset.name } : __assign({}, preset.value);
131
+ jestConfig = jestPreset ? { preset: preset.name } : __assign({}, preset.value);
105
132
  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;
133
+ jestConfig.testEnvironment = 'node';
134
+ transformerConfig = Object.entries((_d = jestConfig.transform) !== null && _d !== void 0 ? _d : {}).reduce(function (acc, _a) {
135
+ var _b, _c;
136
+ var _d = __read(_a, 2), fileRegex = _d[0], transformerName = _d[1];
137
+ if (transformerName === 'ts-jest') {
138
+ if (tsconfig || shouldPostProcessWithBabel) {
139
+ var tsJestConf = {};
140
+ if (tsconfig)
141
+ tsJestConf.tsconfig = tsconfig;
142
+ if (shouldPostProcessWithBabel)
143
+ tsJestConf.babelConfig = true;
144
+ return __assign(__assign({}, acc), (_b = {}, _b[fileRegex] = [transformerName, tsJestConf], _b));
145
+ }
146
+ return __assign(__assign({}, acc), (_c = {}, _c[fileRegex] = transformerName, _c));
147
+ }
148
+ return acc;
149
+ }, {});
150
+ if (Object.keys(transformerConfig).length) {
151
+ jestConfig.transform = __assign(__assign({}, jestConfig.transform), transformerConfig);
114
152
  }
115
- body = JSON.stringify(__assign(__assign({}, pkgJson), { jest: base }), undefined, ' ');
153
+ body = JSON.stringify(__assign(__assign({}, pkgJson), { jest: jestConfig }), undefined, ' ');
116
154
  }
117
155
  else {
118
156
  content = [];
119
157
  if (!jestPreset) {
120
158
  content.push("".concat(preset.jsImport('tsjPreset'), ";"), '');
121
159
  }
122
- content.push("/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */");
160
+ content.push("/** @type {import('ts-jest').JestConfigWithTsJest} */");
123
161
  content.push('module.exports = {');
124
162
  if (jestPreset) {
125
163
  content.push(" preset: '".concat(preset.name, "',"));
@@ -130,28 +168,32 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
130
168
  if (!jsdom)
131
169
  content.push(" testEnvironment: 'node',");
132
170
  if (tsconfig || shouldPostProcessWithBabel) {
133
- content.push(' globals: {');
134
- content.push(" 'ts-jest': {");
171
+ content.push(' transform: {');
172
+ content.push(" '^.+\\\\.[tj]sx?$': ['ts-jest', {");
135
173
  if (tsconfig)
136
174
  content.push(" tsconfig: ".concat((0, json5_1.stringify)(tsconfig), ","));
137
175
  if (shouldPostProcessWithBabel)
138
176
  content.push(' babelConfig: true,');
139
- content.push(' },');
177
+ content.push(' }],');
140
178
  content.push(' },');
141
179
  }
142
180
  content.push('};');
181
+ // join all together
143
182
  body = content.join('\n');
144
183
  }
145
184
  (0, fs_1.writeFileSync)(filePath, body);
146
185
  process.stderr.write("\nJest configuration written to \"".concat(filePath, "\".\n"));
147
- return [2];
186
+ return [2 /*return*/];
148
187
  });
149
188
  }); };
150
189
  exports.run = run;
190
+ /**
191
+ * @internal
192
+ */
151
193
  var help = function () { return __awaiter(void 0, void 0, void 0, function () {
152
194
  return __generator(this, function (_a) {
153
195
  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");
154
- return [2];
196
+ return [2 /*return*/];
155
197
  });
156
198
  }); };
157
199
  exports.help = help;
@@ -72,7 +72,10 @@ var fast_json_stable_stringify_1 = __importDefault(require("fast-json-stable-str
72
72
  var json5_1 = require("json5");
73
73
  var backports_1 = require("../../utils/backports");
74
74
  var presets_1 = require("../helpers/presets");
75
- var run = function (args) { return __awaiter(void 0, void 0, void 0, function () {
75
+ /**
76
+ * @internal
77
+ */
78
+ var run = function (args /* , logger: Logger*/) { return __awaiter(void 0, void 0, void 0, function () {
76
79
  var nullLogger, file, filePath, footNotes, name, isPackage, actualConfig, migratedConfig, presetName, preset, jsTransformers, jsWithTs, jsWithBabel, presetValue, migratedValue, presetValue, migratedValue, globalsTsJestConfig, before, after, stringify, prefix;
77
80
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
78
81
  return __generator(this, function (_l) {
@@ -90,18 +93,22 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
90
93
  }
91
94
  actualConfig = require(filePath);
92
95
  if (isPackage) {
96
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
93
97
  actualConfig = actualConfig.jest;
94
98
  }
95
99
  if (!actualConfig)
96
100
  actualConfig = {};
97
101
  migratedConfig = (0, backports_1.backportJestConfig)(nullLogger, actualConfig);
102
+ // then we check if we can use `preset`
98
103
  if (!migratedConfig.preset && args.jestPreset) {
104
+ // find the best preset
99
105
  if (args.js) {
100
- presetName = args.js === 'babel' ? "ts-jest/presets/js-with-babel" : "ts-jest/presets/js-with-ts";
106
+ presetName = args.js === 'babel' ? "ts-jest/presets/js-with-babel" /* JestPresetNames.jsWIthBabel */ : "ts-jest/presets/js-with-ts" /* JestPresetNames.jsWithTs */;
101
107
  }
102
108
  else {
103
109
  jsTransformers = Object.keys(migratedConfig.transform || {}).reduce(function (list, pattern) {
104
110
  if (RegExp(pattern.replace(/^<rootDir>\/?/, '/dummy-project/')).test('/dummy-project/src/foo.js')) {
111
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
105
112
  var transformer = migratedConfig.transform[pattern];
106
113
  if (/\bbabel-jest\b/.test(transformer))
107
114
  transformer = 'babel-jest';
@@ -114,16 +121,18 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
114
121
  jsWithTs = jsTransformers.includes('ts-jest');
115
122
  jsWithBabel = jsTransformers.includes('babel-jest');
116
123
  if (jsWithBabel && !jsWithTs) {
117
- presetName = "ts-jest/presets/js-with-babel";
124
+ presetName = "ts-jest/presets/js-with-babel" /* JestPresetNames.jsWIthBabel */;
118
125
  }
119
126
  else if (jsWithTs && !jsWithBabel) {
120
- presetName = "ts-jest/presets/js-with-ts";
127
+ presetName = "ts-jest/presets/js-with-ts" /* JestPresetNames.jsWithTs */;
121
128
  }
122
129
  else {
123
- presetName = "ts-jest/presets/default";
130
+ // sounds like js files are NOT handled, or handled with a unknown transformer, so we do not need to handle it
131
+ presetName = "ts-jest/presets/default" /* JestPresetNames.default */;
124
132
  }
125
133
  }
126
- presetName = presetName !== null && presetName !== void 0 ? presetName : "ts-jest/presets/default";
134
+ // ensure we are using a preset
135
+ presetName = presetName !== null && presetName !== void 0 ? presetName : "ts-jest/presets/default" /* JestPresetNames.default */;
127
136
  preset = presets_1.allPresets[presetName];
128
137
  footNotes.push("Detected preset '".concat(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"));
129
138
  }
@@ -132,11 +141,14 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
132
141
  delete migratedConfig.preset;
133
142
  }
134
143
  else {
144
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
135
145
  preset = (_c = presets_1.allPresets[migratedConfig.preset]) !== null && _c !== void 0 ? _c : presets_1.defaults;
136
146
  }
137
147
  }
148
+ // enforce the correct name
138
149
  if (preset)
139
150
  migratedConfig.preset = preset.name;
151
+ // check the extensions
140
152
  if (((_d = migratedConfig.moduleFileExtensions) === null || _d === void 0 ? void 0 : _d.length) && preset) {
141
153
  presetValue = dedupSort((_e = preset.value.moduleFileExtensions) !== null && _e !== void 0 ? _e : []).join('::');
142
154
  migratedValue = dedupSort(migratedConfig.moduleFileExtensions).join('::');
@@ -144,9 +156,11 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
144
156
  delete migratedConfig.moduleFileExtensions;
145
157
  }
146
158
  }
159
+ // there is a testRegex, remove our testMatch
147
160
  if ((typeof migratedConfig.testRegex === 'string' || ((_f = migratedConfig.testRegex) === null || _f === void 0 ? void 0 : _f.length)) && preset) {
148
161
  delete migratedConfig.testMatch;
149
162
  }
163
+ // check the testMatch
150
164
  else if (((_g = migratedConfig.testMatch) === null || _g === void 0 ? void 0 : _g.length) && preset) {
151
165
  presetValue = dedupSort((_h = preset.value.testMatch) !== null && _h !== void 0 ? _h : []).join('::');
152
166
  migratedValue = dedupSort(migratedConfig.testMatch).join('::');
@@ -154,10 +168,13 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
154
168
  delete migratedConfig.testMatch;
155
169
  }
156
170
  }
171
+ // migrate the transform
157
172
  if (migratedConfig.transform) {
158
173
  Object.keys(migratedConfig.transform).forEach(function (key) {
174
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
159
175
  var val = migratedConfig.transform[key];
160
176
  if (typeof val === 'string' && /\/?ts-jest?(?:\/preprocessor\.js)?$/.test(val)) {
177
+ // eslint-disable-next-line
161
178
  ;
162
179
  migratedConfig.transform[key] = 'ts-jest';
163
180
  }
@@ -166,44 +183,63 @@ var run = function (args) { return __awaiter(void 0, void 0, void 0, function ()
166
183
  globalsTsJestConfig = (_j = migratedConfig.globals) === null || _j === void 0 ? void 0 : _j['ts-jest'];
167
184
  if (globalsTsJestConfig && migratedConfig.transform) {
168
185
  Object.keys(migratedConfig.transform).forEach(function (key) {
186
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
169
187
  var val = migratedConfig.transform[key];
170
188
  if (typeof val === 'string' && val.includes('ts-jest')) {
189
+ // eslint-disable-next-line
171
190
  ;
172
191
  migratedConfig.transform[key] = Object.keys(globalsTsJestConfig).length ? [val, globalsTsJestConfig] : val;
173
192
  }
174
193
  });
175
194
  delete ((_k = migratedConfig.globals) !== null && _k !== void 0 ? _k : Object.create(null))['ts-jest'];
176
195
  }
196
+ // check if it's the same as the preset's one
177
197
  if (preset &&
178
198
  migratedConfig.transform &&
179
199
  (0, fast_json_stable_stringify_1.default)(migratedConfig.transform) === (0, fast_json_stable_stringify_1.default)(preset.value.transform)) {
180
200
  delete migratedConfig.transform;
181
201
  }
202
+ // cleanup
182
203
  cleanupConfig(actualConfig);
183
204
  cleanupConfig(migratedConfig);
184
205
  before = (0, fast_json_stable_stringify_1.default)(actualConfig);
185
206
  after = (0, fast_json_stable_stringify_1.default)(migratedConfig);
186
207
  if (after === before) {
187
208
  process.stderr.write("\nNo migration needed for given Jest configuration\n ");
188
- return [2];
209
+ return [2 /*return*/];
189
210
  }
190
211
  stringify = file.endsWith('.json') ? JSON.stringify : json5_1.stringify;
191
212
  prefix = file.endsWith('.json') ? '"jest": ' : 'module.exports = ';
213
+ // if we are using preset, inform the user that he might be able to remove some section(s)
214
+ // we couldn't check for equality
215
+ // if (usesPreset && migratedConfig.testMatch) {
216
+ // footNotes.push(`
217
+ // I couldn't check if your "testMatch" value is the same as mine which is: ${stringify(
218
+ // presets.testMatch,
219
+ // undefined,
220
+ // ' ',
221
+ // )}
222
+ // If it is the case, you can safely remove the "testMatch" from what I've migrated.
223
+ // `)
224
+ // }
192
225
  if (preset && migratedConfig.transform) {
193
226
  footNotes.push("\nI couldn't check if your \"transform\" value is the same as mine which is: ".concat(stringify(preset.value.transform, undefined, ' '), "\nIf it is the case, you can safely remove the \"transform\" from what I've migrated.\n"));
194
227
  }
228
+ // output new config
195
229
  process.stderr.write("\nMigrated Jest configuration:\n");
196
230
  process.stdout.write("".concat(prefix).concat(stringify(migratedConfig, undefined, ' '), "\n"));
197
231
  if (footNotes.length) {
198
232
  process.stderr.write("\n".concat(footNotes.join('\n'), "\n"));
199
233
  }
200
- return [2];
234
+ return [2 /*return*/];
201
235
  });
202
236
  }); };
203
237
  exports.run = run;
204
238
  function cleanupConfig(config) {
205
239
  if (config.globals) {
240
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
206
241
  if (config.globals['ts-jest'] && Object.keys(config.globals['ts-jest']).length === 0) {
242
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
207
243
  delete config.globals['ts-jest'];
208
244
  }
209
245
  if (!Object.keys(config.globals).length) {
@@ -223,18 +259,22 @@ function cleanupConfig(config) {
223
259
  if (!config.testMatch.length)
224
260
  delete config.testMatch;
225
261
  }
226
- if (config.preset === "ts-jest/presets/default")
262
+ if (config.preset === "ts-jest/presets/default" /* JestPresetNames.default */)
227
263
  config.preset = presets_1.defaults.name;
228
264
  }
265
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
229
266
  function dedupSort(arr) {
230
267
  return arr
231
268
  .filter(function (s, i, a) { return a.findIndex(function (e) { return s.toString() === e.toString(); }) === i; })
232
269
  .sort(function (a, b) { return (a.toString() > b.toString() ? 1 : a.toString() < b.toString() ? -1 : 0); });
233
270
  }
271
+ /**
272
+ * @internal
273
+ */
234
274
  var help = function () { return __awaiter(void 0, void 0, void 0, function () {
235
275
  return __generator(this, function (_a) {
236
276
  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");
237
- return [2];
277
+ return [2 /*return*/];
238
278
  });
239
279
  }); };
240
280
  exports.help = help;
package/dist/cli/help.js CHANGED
@@ -37,11 +37,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.help = exports.run = void 0;
40
+ /**
41
+ * @internal
42
+ */
40
43
  var run = function (_) { return __awaiter(void 0, void 0, void 0, function () {
41
44
  return __generator(this, function (_a) {
42
45
  process.stdout.write("\nUsage:\n ts-jest command [options] [...args]\n\nCommands:\n config:init Creates initial Jest configuration\n config:migrate Migrates a given Jest configuration\n help [command] Show this help, or help about a command\n\nExample:\n ts-jest help config:migrate\n");
43
- return [2];
46
+ return [2 /*return*/];
44
47
  });
45
48
  }); };
46
49
  exports.run = run;
50
+ /**
51
+ * @internal
52
+ */
47
53
  exports.help = exports.run;
@@ -7,15 +7,17 @@ var definePreset = function (fullName) { return ({
7
7
  return this.isDefault ? 'ts-jest' : fullName;
8
8
  },
9
9
  get label() {
10
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
10
11
  return fullName.split('/').pop();
11
12
  },
12
13
  get jsVarName() {
13
14
  return this.isDefault
14
15
  ? 'defaults'
15
- :
16
+ : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
16
17
  fullName
17
18
  .split('/')
18
19
  .pop()
20
+ // eslint-disable-next-line no-useless-escape
19
21
  .replace(/\-([a-z])/g, function (_, l) { return l.toUpperCase(); });
20
22
  },
21
23
  get value() {
@@ -26,10 +28,15 @@ var definePreset = function (fullName) { return ({
26
28
  return "const { ".concat(this.jsVarName, ": ").concat(varName, " } = require('ts-jest/presets')");
27
29
  },
28
30
  get isDefault() {
29
- return fullName === "ts-jest/presets/default";
31
+ return fullName === "ts-jest/presets/default" /* JestPresetNames.default */;
30
32
  },
31
33
  }); };
34
+ /** @internal */
35
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
36
  exports.allPresets = {};
33
- exports.defaults = (exports.allPresets["ts-jest/presets/default"] = definePreset("ts-jest/presets/default"));
34
- exports.jsWithTs = (exports.allPresets["ts-jest/presets/js-with-ts"] = definePreset("ts-jest/presets/js-with-ts"));
35
- exports.jsWIthBabel = (exports.allPresets["ts-jest/presets/js-with-babel"] = definePreset("ts-jest/presets/js-with-babel"));
37
+ /** @internal */
38
+ exports.defaults = (exports.allPresets["ts-jest/presets/default" /* JestPresetNames.default */] = definePreset("ts-jest/presets/default" /* JestPresetNames.default */));
39
+ /** @internal */
40
+ exports.jsWithTs = (exports.allPresets["ts-jest/presets/js-with-ts" /* JestPresetNames.jsWithTs */] = definePreset("ts-jest/presets/js-with-ts" /* JestPresetNames.jsWithTs */));
41
+ /** @internal */
42
+ exports.jsWIthBabel = (exports.allPresets["ts-jest/presets/js-with-babel" /* JestPresetNames.jsWIthBabel */] = definePreset("ts-jest/presets/js-with-babel" /* JestPresetNames.jsWIthBabel */));
package/dist/cli/index.js CHANGED
@@ -65,6 +65,7 @@ function cli(args) {
65
65
  },
66
66
  },
67
67
  });
68
+ // deprecated
68
69
  if (parsedArgv.allowJs != null) {
69
70
  if (parsedArgv.js)
70
71
  throw new Error("The 'allowJs' and 'js' options cannot be set together.");
@@ -78,7 +79,7 @@ function cli(args) {
78
79
  command = 'help';
79
80
  _a = require("./".concat(command.replace(/:/g, '/'))), run = _a.run, help = _a.help;
80
81
  cmd = isHelp && command !== 'help' ? help : run;
81
- return [2, cmd(parsedArgv, logger)];
82
+ return [2 /*return*/, cmd(parsedArgv, logger)];
82
83
  });
83
84
  });
84
85
  }
@@ -87,6 +88,9 @@ var errorHasMessage = function (err) {
87
88
  return false;
88
89
  return 'message' in err;
89
90
  };
91
+ /**
92
+ * @internal
93
+ */
90
94
  function processArgv() {
91
95
  return __awaiter(this, void 0, void 0, function () {
92
96
  var err_1;
@@ -94,19 +98,19 @@ function processArgv() {
94
98
  switch (_a.label) {
95
99
  case 0:
96
100
  _a.trys.push([0, 2, , 3]);
97
- return [4, cli(process.argv.slice(2))];
101
+ return [4 /*yield*/, cli(process.argv.slice(2))];
98
102
  case 1:
99
103
  _a.sent();
100
104
  process.exit(0);
101
- return [3, 3];
105
+ return [3 /*break*/, 3];
102
106
  case 2:
103
107
  err_1 = _a.sent();
104
108
  if (errorHasMessage(err_1)) {
105
109
  logger.fatal(err_1.message);
106
110
  process.exit(1);
107
111
  }
108
- return [3, 3];
109
- case 3: return [2];
112
+ return [3 /*break*/, 3];
113
+ case 3: return [2 /*return*/];
110
114
  }
111
115
  });
112
116
  });
@@ -16,6 +16,8 @@ exports.pathsToModuleNameMapper = void 0;
16
16
  var bs_logger_1 = require("bs-logger");
17
17
  var utils_1 = require("../utils");
18
18
  var messages_1 = require("../utils/messages");
19
+ // we don't need to escape all chars, so commented out is the real one
20
+ // const escapeRegex = (str: string) => str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')
19
21
  var escapeRegex = function (str) { return str.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&'); };
20
22
  var logger = utils_1.rootLogger.child((_a = {}, _a[bs_logger_1.LogContexts.namespace] = 'path-mapper', _a));
21
23
  var pathsToModuleNameMapper = function (mapping, _a) {
@@ -27,10 +29,12 @@ var pathsToModuleNameMapper = function (mapping, _a) {
27
29
  var fromPath = _f.value;
28
30
  var pattern = void 0;
29
31
  var toPaths = mapping[fromPath];
32
+ // check that we have only one target path
30
33
  if (toPaths.length === 0) {
31
- logger.warn((0, messages_1.interpolate)("Not mapping \"{{path}}\" because it has no target.", { path: fromPath }));
34
+ logger.warn((0, messages_1.interpolate)("Not mapping \"{{path}}\" because it has no target." /* Errors.NotMappingPathWithEmptyMap */, { path: fromPath }));
32
35
  continue;
33
36
  }
37
+ // split with '*'
34
38
  var segments = fromPath.split(/\*/g);
35
39
  if (segments.length === 1) {
36
40
  var paths = toPaths.map(function (target) {
@@ -50,7 +54,7 @@ var pathsToModuleNameMapper = function (mapping, _a) {
50
54
  jestMap[pattern] = paths.length === 1 ? paths[0] : paths;
51
55
  }
52
56
  else {
53
- logger.warn((0, messages_1.interpolate)("Not mapping \"{{path}}\" because it has more than one star (`*`).", { path: fromPath }));
57
+ logger.warn((0, messages_1.interpolate)("Not mapping \"{{path}}\" because it has more than one star (`*`)." /* Errors.NotMappingMultiStarPath */, { path: fromPath }));
54
58
  }
55
59
  }
56
60
  }
package/dist/constants.js CHANGED
@@ -6,6 +6,11 @@ exports.DECLARATION_TYPE_EXT = '.d.ts';
6
6
  exports.JS_JSX_EXTENSIONS = ['.js', '.jsx'];
7
7
  exports.TS_TSX_REGEX = /\.m?tsx?$/;
8
8
  exports.JS_JSX_REGEX = /\.m?jsx?$/;
9
+ // `extensionsToTreatAsEsm` will throw error with `.mjs`
9
10
  exports.TS_EXT_TO_TREAT_AS_ESM = ['.ts', '.tsx', '.mts'];
10
11
  exports.JS_EXT_TO_TREAT_AS_ESM = ['.jsx'];
12
+ /**
13
+ * @internal
14
+ * See https://jestjs.io/docs/en/configuration#testmatch-arraystring
15
+ */
11
16
  exports.DEFAULT_JEST_TEST_MATCH = ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'];
@@ -1,2 +1,8 @@
1
+ /**
2
+ * Rely on TypeScript compiled output generation which contains this prefix to point to sourcemap location.
3
+ */
1
4
  export declare const SOURCE_MAPPING_PREFIX = "sourceMappingURL=";
5
+ /**
6
+ * Update the output remapping the source map.
7
+ */
2
8
  export declare function updateOutput(outputText: string, normalizedFileName: string, sourceMap?: string): string;
@@ -2,17 +2,27 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateOutput = exports.SOURCE_MAPPING_PREFIX = void 0;
4
4
  var utils_1 = require("../../utils");
5
+ /**
6
+ * Rely on TypeScript compiled output generation which contains this prefix to point to sourcemap location.
7
+ */
5
8
  exports.SOURCE_MAPPING_PREFIX = 'sourceMappingURL=';
9
+ /**
10
+ * Update the output remapping the source map.
11
+ */
6
12
  function updateOutput(outputText, normalizedFileName, sourceMap) {
7
13
  if (sourceMap) {
8
14
  var base64Map = Buffer.from(updateSourceMap(sourceMap, normalizedFileName), 'utf8').toString('base64');
9
15
  var sourceMapContent = "data:application/json;charset=utf-8;base64,".concat(base64Map);
16
+ // sourceMappingURL= prefix is always at the end of compiledOutput, using lastIndexOf should be the safest way to substring
10
17
  return (outputText.slice(0, outputText.lastIndexOf(exports.SOURCE_MAPPING_PREFIX) + exports.SOURCE_MAPPING_PREFIX.length) +
11
18
  sourceMapContent);
12
19
  }
13
20
  return outputText;
14
21
  }
15
22
  exports.updateOutput = updateOutput;
23
+ /**
24
+ * Update the source map contents for improved output.
25
+ */
16
26
  var updateSourceMap = function (sourceMapText, normalizedFileName) {
17
27
  var sourceMap = JSON.parse(sourceMapText);
18
28
  sourceMap.file = normalizedFileName;
@@ -10,7 +10,13 @@ export declare class TsCompiler implements TsCompilerInstance {
10
10
  protected readonly _ts: TTypeScript;
11
11
  protected readonly _initialCompilerOptions: CompilerOptions;
12
12
  protected _compilerOptions: CompilerOptions;
13
+ /**
14
+ * @private
15
+ */
13
16
  private _runtimeCacheFS;
17
+ /**
18
+ * @private
19
+ */
14
20
  private _fileContentCache;
15
21
  program: Program | undefined;
16
22
  constructor(configSet: ConfigSet, runtimeCacheFS: StringMap);