ts-jest 29.2.6 → 29.3.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/.lintstagedrc ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "*.{js,cjs,mjs,jsx,ts,tsx}": ["eslint --fix"],
3
+ "*.{yml,yaml,md}": ["prettier --write"]
4
+ }
package/.ts-jest-digest CHANGED
@@ -1 +1 @@
1
- bc7eea511e438e06b762bdf538d9d2c6b362e922
1
+ 3245e9def80f839e39f354a96ad062463a6384a0
package/CHANGELOG.md CHANGED
@@ -1,4 +1,32 @@
1
- ### [29.2.6](https://github.com/kulshekhar/ts-jest/compare/v29.2.5...v29.2.6) (2025-02-22)
1
+ ## [29.3.0](https://github.com/kulshekhar/ts-jest/compare/v29.2.6...v29.3.0) (2025-03-21)
2
+
3
+
4
+ ### Features
5
+
6
+ * feat: support hybrid `module` values for `isolatedModules: true` ([f372121](https://github.com/kulshekhar/ts-jest/commit/f372121))
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * fix: set `customConditions` to `undefined` in `TsCompiler` ([b091d70](https://github.com/kulshekhar/ts-jest/commit/b091d70)), closes [#4620](https://github.com/kulshekhar/ts-jest/issues/4620)
12
+
13
+
14
+ ### Code Refactoring
15
+
16
+ * refactor: remove manual version checker ([89458fc](https://github.com/kulshekhar/ts-jest/commit/89458fc))
17
+ * refactor: remove patching deps based on version checker ([bac4c43](https://github.com/kulshekhar/ts-jest/commit/bac4c43))
18
+ * refactor: deprecate `RawCompilerOptions` interface ([2b1b6cd](https://github.com/kulshekhar/ts-jest/commit/2b1b6cd))
19
+ * refactor: deprecate transform option `isolatedModules` ([7dfef71](https://github.com/kulshekhar/ts-jest/commit/7dfef71))
20
+
21
+
22
+ ## DEPRECATIONS
23
+
24
+ * `RawCompilerOptions` is deprecated in favor of `TsConfigJson.CompilerOptions` from `type-fest`
25
+ * `isolatedModules` transform option is deprecated in favor of https://www.typescriptlang.org/tsconfig/#isolatedModules
26
+
27
+
28
+
29
+ ## [29.2.6](https://github.com/kulshekhar/ts-jest/compare/v29.2.5...v29.2.6) (2025-02-22)
2
30
 
3
31
 
4
32
  ### Bug Fixes
@@ -9,7 +37,7 @@
9
37
 
10
38
 
11
39
 
12
- ### [29.2.5](https://github.com/kulshekhar/ts-jest/compare/v29.2.4...v29.2.5) (2024-08-23)
40
+ ## [29.2.5](https://github.com/kulshekhar/ts-jest/compare/v29.2.4...v29.2.5) (2024-08-23)
13
41
 
14
42
 
15
43
  ### Bug Fixes
@@ -20,7 +48,7 @@
20
48
 
21
49
 
22
50
 
23
- ### [29.2.4](https://github.com/kulshekhar/ts-jest/compare/v29.2.3...v29.2.4) (2024-08-01)
51
+ ## [29.2.4](https://github.com/kulshekhar/ts-jest/compare/v29.2.3...v29.2.4) (2024-08-01)
24
52
 
25
53
 
26
54
  ### Bug Fixes
@@ -29,7 +57,7 @@
29
57
 
30
58
 
31
59
 
32
- ### [29.2.3](https://github.com/kulshekhar/ts-jest/compare/v29.2.2...v29.2.3) (2024-07-18)
60
+ ## [29.2.3](https://github.com/kulshekhar/ts-jest/compare/v29.2.2...v29.2.3) (2024-07-18)
33
61
 
34
62
 
35
63
  ### Security Fixes
@@ -52,7 +80,7 @@
52
80
 
53
81
 
54
82
 
55
- ### [29.2.1](https://github.com/kulshekhar/ts-jest/compare/v29.2.0...v29.2.1) (2024-07-10)
83
+ ## [29.2.1](https://github.com/kulshekhar/ts-jest/compare/v29.2.0...v29.2.1) (2024-07-10)
56
84
 
57
85
 
58
86
  ### Bug Fixes
@@ -94,7 +122,7 @@
94
122
 
95
123
 
96
124
 
97
- ### [29.1.5](https://github.com/kulshekhar/ts-jest/compare/v29.1.4...v29.1.5) (2024-06-16)
125
+ ## [29.1.5](https://github.com/kulshekhar/ts-jest/compare/v29.1.4...v29.1.5) (2024-06-16)
98
126
 
99
127
 
100
128
  ### Bug Fixes
@@ -103,7 +131,7 @@
103
131
 
104
132
 
105
133
 
106
- ### [29.1.4](https://github.com/kulshekhar/ts-jest/compare/v29.1.3...v29.1.4) (2024-05-28)
134
+ ## [29.1.4](https://github.com/kulshekhar/ts-jest/compare/v29.1.3...v29.1.4) (2024-05-28)
107
135
 
108
136
 
109
137
  ### Bug Fixes
@@ -117,7 +145,7 @@
117
145
 
118
146
 
119
147
 
120
- ### [29.1.3](https://github.com/kulshekhar/ts-jest/compare/v29.1.2...v29.1.3) (2024-05-21)
148
+ ## [29.1.3](https://github.com/kulshekhar/ts-jest/compare/v29.1.2...v29.1.3) (2024-05-21)
121
149
 
122
150
 
123
151
  ### Bug Fixes
@@ -132,7 +160,7 @@
132
160
 
133
161
 
134
162
 
135
- ### [29.1.2](https://github.com/kulshekhar/ts-jest/compare/v29.1.1...v29.1.2) (2024-01-22)
163
+ ## [29.1.2](https://github.com/kulshekhar/ts-jest/compare/v29.1.1...v29.1.2) (2024-01-22)
136
164
 
137
165
 
138
166
  ### Bug Fixes
@@ -170,7 +198,7 @@
170
198
 
171
199
 
172
200
 
173
- ### [29.0.4](https://github.com/kulshekhar/ts-jest/compare/v29.0.3...v29.0.4) (2023-01-10)
201
+ ## [29.0.4](https://github.com/kulshekhar/ts-jest/compare/v29.0.3...v29.0.4) (2023-01-10)
174
202
 
175
203
 
176
204
  ### Bug Fixes
@@ -180,7 +208,7 @@
180
208
 
181
209
 
182
210
 
183
- ### [29.0.3](https://github.com/kulshekhar/ts-jest/compare/v29.0.2...v29.0.3) (2022-09-28)
211
+ ## [29.0.3](https://github.com/kulshekhar/ts-jest/compare/v29.0.2...v29.0.3) (2022-09-28)
184
212
 
185
213
 
186
214
  ### Bug Fixes
@@ -195,7 +223,7 @@
195
223
 
196
224
 
197
225
 
198
- ### [29.0.2](https://github.com/kulshekhar/ts-jest/compare/v29.0.1...v29.0.2) (2022-09-23)
226
+ ## [29.0.2](https://github.com/kulshekhar/ts-jest/compare/v29.0.1...v29.0.2) (2022-09-23)
199
227
 
200
228
 
201
229
  ### Bug Fixes
@@ -205,7 +233,7 @@
205
233
 
206
234
 
207
235
 
208
- ### [29.0.1](https://github.com/kulshekhar/ts-jest/compare/v29.0.0...v29.0.1) (2022-09-13)
236
+ ## [29.0.1](https://github.com/kulshekhar/ts-jest/compare/v29.0.0...v29.0.1) (2022-09-13)
209
237
 
210
238
 
211
239
  ### Bug Fixes
@@ -1 +1,2 @@
1
1
  export * from './paths-to-module-name-mapper';
2
+ export * from './types';
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./paths-to-module-name-mapper"), exports);
18
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,2 @@
1
+ import type { TsConfigJson } from 'type-fest';
2
+ export type TsConfigCompilerOptionsJson = TsConfigJson.CompilerOptions;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,5 @@
1
1
  import { Logger } from 'bs-logger';
2
- import type { CompilerOptions, CustomTransformers, Program, TranspileOutput } from 'typescript';
2
+ import { CompilerOptions, CustomTransformers, Program, TranspileOutput } from 'typescript';
3
3
  import type { StringMap, TsCompilerInstance, TsJestAstTransformer, TsJestCompileOptions, TTypeScript } from '../../types';
4
4
  import { CompiledOutput } from '../../types';
5
5
  import type { ConfigSet } from '../config/config-set';
@@ -54,10 +54,28 @@ exports.TsCompiler = void 0;
54
54
  var path_1 = require("path");
55
55
  var bs_logger_1 = require("bs-logger");
56
56
  var lodash_memoize_1 = __importDefault(require("lodash.memoize"));
57
+ var typescript_1 = __importDefault(require("typescript"));
57
58
  var constants_1 = require("../../constants");
59
+ // import { tsTranspileModule } from '../../transpilers/typescript/transpile-module'
60
+ var transpile_module_1 = require("../../transpilers/typescript/transpile-module");
58
61
  var utils_1 = require("../../utils");
59
62
  var messages_1 = require("../../utils/messages");
60
63
  var compiler_utils_1 = require("./compiler-utils");
64
+ var isModernNodeResolution = function (module) {
65
+ return module ? [typescript_1.default.ModuleKind.Node16, /* ModuleKind.Node18 */ 101, typescript_1.default.ModuleKind.NodeNext].includes(module) : false;
66
+ };
67
+ var shouldUseNativeTsTranspile = function (compilerOptions) {
68
+ if (!compilerOptions) {
69
+ return true;
70
+ }
71
+ var module = compilerOptions.module;
72
+ return !isModernNodeResolution(module);
73
+ };
74
+ var assertCompilerOptionsWithJestTransformMode = function (compilerOptions, isEsmMode, logger) {
75
+ if (isEsmMode && compilerOptions.module === typescript_1.default.ModuleKind.CommonJS) {
76
+ logger.error("The current compiler option \"module\" value is not suitable for Jest ESM mode. Please either use ES module kinds or Node16/NodeNext module kinds with \"type: module\" in package.json" /* Errors.InvalidModuleKindForEsm */);
77
+ }
78
+ };
61
79
  var TsCompiler = /** @class */ (function () {
62
80
  function TsCompiler(configSet, runtimeCacheFS) {
63
81
  var _a;
@@ -116,20 +134,31 @@ var TsCompiler = /** @class */ (function () {
116
134
  var _a, _b;
117
135
  var moduleResolution = (_a = this._ts.ModuleResolutionKind.Node10) !== null && _a !== void 0 ? _a : this._ts.ModuleResolutionKind.NodeJs;
118
136
  if (!isEsm) {
119
- return __assign(__assign({}, compilerOptions), { module: this._ts.ModuleKind.CommonJS, moduleResolution: moduleResolution });
137
+ return __assign(__assign({}, compilerOptions), { module: this._ts.ModuleKind.CommonJS, moduleResolution: moduleResolution,
138
+ /**
139
+ * This option is only supported in `Node16`/`NodeNext` and `Bundler` module, see https://www.typescriptlang.org/tsconfig/#customConditions
140
+ */
141
+ customConditions: undefined });
120
142
  }
121
143
  var moduleKind = (_b = compilerOptions.module) !== null && _b !== void 0 ? _b : this._ts.ModuleKind.ESNext;
122
144
  var esModuleInterop = compilerOptions.esModuleInterop;
123
- if ([this._ts.ModuleKind.Node16, this._ts.ModuleKind.NodeNext].includes(moduleKind)) {
145
+ if (isModernNodeResolution(moduleKind)) {
124
146
  esModuleInterop = true;
125
147
  moduleKind = this._ts.ModuleKind.ESNext;
126
148
  }
127
- return __assign(__assign({}, compilerOptions), { module: moduleKind, esModuleInterop: esModuleInterop, moduleResolution: moduleResolution });
149
+ return __assign(__assign({}, compilerOptions), { module: moduleKind, esModuleInterop: esModuleInterop, moduleResolution: moduleResolution,
150
+ /**
151
+ * This option is only supported in `Node16`/`NodeNext` and `Bundler` module, see https://www.typescriptlang.org/tsconfig/#customConditions
152
+ */
153
+ customConditions: undefined });
128
154
  };
129
155
  TsCompiler.prototype.getCompiledOutput = function (fileContent, fileName, options) {
130
156
  var e_1, _a;
131
157
  var isEsmMode = this.configSet.useESM && options.supportsStaticESM;
132
158
  this._compilerOptions = this.fixupCompilerOptionsForModuleKind(this._initialCompilerOptions, isEsmMode);
159
+ if (!this._initialCompilerOptions.isolatedModules && isModernNodeResolution(this._initialCompilerOptions.module)) {
160
+ this._logger.warn("Using hybrid module kind (Node16/18/Next) is only supported in \"isolatedModules: true\". Please set \"isolatedModules: true\" in your tsconfig.json." /* Helps.UsingModernNodeResolution */);
161
+ }
133
162
  var moduleKind = this._initialCompilerOptions.module;
134
163
  var currentModuleKind = this._compilerOptions.module;
135
164
  if (this._languageService) {
@@ -195,6 +224,7 @@ var TsCompiler = /** @class */ (function () {
195
224
  }
196
225
  else {
197
226
  this._logger.debug({ fileName: fileName }, 'getCompiledOutput(): compiling as isolated module');
227
+ assertCompilerOptionsWithJestTransformMode(this._initialCompilerOptions, isEsmMode, this._logger);
198
228
  var result = this._transpileOutput(fileContent, fileName);
199
229
  if (result.diagnostics && this.configSet.shouldReportDiagnostics(fileName)) {
200
230
  this.configSet.raiseDiagnostics(result.diagnostics, fileName, this._logger);
@@ -205,11 +235,19 @@ var TsCompiler = /** @class */ (function () {
205
235
  }
206
236
  };
207
237
  TsCompiler.prototype._transpileOutput = function (fileContent, fileName) {
208
- return this._ts.transpileModule(fileContent, {
238
+ if (shouldUseNativeTsTranspile(this._initialCompilerOptions)) {
239
+ return this._ts.transpileModule(fileContent, {
240
+ fileName: fileName,
241
+ transformers: this._makeTransformers(this.configSet.resolvedTransformers),
242
+ compilerOptions: this._compilerOptions,
243
+ reportDiagnostics: this.configSet.shouldReportDiagnostics(fileName),
244
+ });
245
+ }
246
+ return (0, transpile_module_1.tsTranspileModule)(fileContent, {
209
247
  fileName: fileName,
210
248
  transformers: this._makeTransformers(this.configSet.resolvedTransformers),
211
- compilerOptions: this._compilerOptions,
212
- reportDiagnostics: this.configSet.shouldReportDiagnostics(fileName),
249
+ compilerOptions: this._initialCompilerOptions,
250
+ reportDiagnostics: fileName ? this.configSet.shouldReportDiagnostics(fileName) : false,
213
251
  });
214
252
  };
215
253
  TsCompiler.prototype._makeTransformers = function (customTransformers) {
@@ -1,5 +1,6 @@
1
1
  import { Logger } from 'bs-logger';
2
2
  import type * as ts from 'typescript';
3
+ import type { TsConfigCompilerOptionsJson } from '../../config/types';
3
4
  import type { RawCompilerOptions } from '../../raw-compiler-options';
4
5
  import type { TsJestAstTransformer, TsJestTransformOptions, TTypeScript } from '../../types';
5
6
  export declare class ConfigSet {
@@ -23,7 +24,7 @@ export declare class ConfigSet {
23
24
  * Load TypeScript configuration. Returns the parsed TypeScript config and any `tsconfig` options specified in ts-jest
24
25
  * Subclasses which extend `ConfigSet` can override the default behavior
25
26
  */
26
- protected _resolveTsConfig(compilerOptions?: RawCompilerOptions, resolvedConfigFile?: string): Record<string, any>;
27
+ protected _resolveTsConfig(compilerOptions?: RawCompilerOptions | TsConfigCompilerOptionsJson, resolvedConfigFile?: string): Record<string, any>;
27
28
  isTestFile(fileName: string): boolean;
28
29
  shouldStringifyContent(filePath: string): boolean;
29
30
  raiseDiagnostics(diagnostics: ts.Diagnostic[], filePath?: string, logger?: Logger): void;
@@ -159,6 +159,7 @@ var requireFromString = function (code, fileName) {
159
159
  // @ts-expect-error `_compile` is not exposed in typing
160
160
  m._compile(code, fileName);
161
161
  var exports = m.exports;
162
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
162
163
  parent && parent.children && parent.children.splice(parent.children.indexOf(m), 1);
163
164
  return exports;
164
165
  };
@@ -207,11 +208,8 @@ var ConfigSet = /** @class */ (function () {
207
208
  var options = tsJestCfg !== null && tsJestCfg !== void 0 ? tsJestCfg : Object.create(null);
208
209
  // compiler module
209
210
  this.compilerModule = importer_1.importer.typescript("Using \"ts-jest\" requires this package to be installed." /* ImportReasons.TsJest */, (_e = options.compiler) !== null && _e !== void 0 ? _e : 'typescript');
210
- // isolatedModules
211
- this.isolatedModules = (_f = options.isolatedModules) !== null && _f !== void 0 ? _f : false;
212
211
  this.logger.debug({ compilerModule: this.compilerModule }, 'normalized compiler module config via ts-jest option');
213
212
  this._setupConfigSet(options);
214
- this._resolveTsCacheDir();
215
213
  this._matchablePatterns = __spreadArray(__spreadArray([], __read(this._jestCfg.testMatch), false), __read(this._jestCfg.testRegex), false).filter(function (pattern) {
216
214
  /**
217
215
  * jest config testRegex doesn't always deliver the correct RegExp object
@@ -223,6 +221,20 @@ var ConfigSet = /** @class */ (function () {
223
221
  (_b = this._matchablePatterns).push.apply(_b, __spreadArray([], __read(constants_1.DEFAULT_JEST_TEST_MATCH), false));
224
222
  }
225
223
  this._matchTestFilePath = (0, jest_util_1.globsToMatcher)(this._matchablePatterns.filter(function (pattern) { return typeof pattern === 'string'; }));
224
+ // isolatedModules
225
+ if (options.isolatedModules) {
226
+ this.parsedTsConfig.options.isolatedModules = true;
227
+ if (this.tsconfigFilePath) {
228
+ this.logger.warn((0, messages_1.interpolate)("\"isolatedModules\" is deprecated and will be removed in v30.0.0. Please remove \"isolatedModules\" from your \"ts-jest\" transform options and enable \"isolatedModules: true\" in {{tsconfigFilePath}} instead." /* Deprecations.IsolatedModulesWithTsconfigPath */, {
229
+ tsconfigFilePath: this.tsconfigFilePath,
230
+ }));
231
+ }
232
+ else {
233
+ this.logger.warn("\"isolatedModules\" is deprecated and will be removed in v30.0.0. Please remove \"isolatedModules\" from your \"ts-jest\" transform options and enable \"isolatedModules: true\" in a tsconfig file instead." /* Deprecations.IsolatedModulesWithoutTsconfigPath */);
234
+ }
235
+ }
236
+ this.isolatedModules = (_f = this.parsedTsConfig.options.isolatedModules) !== null && _f !== void 0 ? _f : false;
237
+ this._resolveTsCacheDir();
226
238
  }
227
239
  /**
228
240
  * @internal
@@ -275,6 +287,7 @@ var ConfigSet = /** @class */ (function () {
275
287
  if (typeof diagnosticsOpt === 'object') {
276
288
  var ignoreCodes = diagnosticsOpt.ignoreCodes;
277
289
  if (ignoreCodes) {
290
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
278
291
  Array.isArray(ignoreCodes) ? ignoreList.push.apply(ignoreList, __spreadArray([], __read(ignoreCodes), false)) : ignoreList.push(ignoreCodes);
279
292
  }
280
293
  this._diagnostics = {
@@ -428,7 +441,7 @@ var ConfigSet = /** @class */ (function () {
428
441
  !warningModulesForEsmInterop.includes(moduleValue) &&
429
442
  !(finalOptions.esModuleInterop || finalOptions.allowSyntheticDefaultImports)) {
430
443
  result.errors.push({
431
- code: 151001 /* DiagnosticCodes.ConfigModuleOption */,
444
+ code: messages_1.TsJestDiagnosticCodes.ConfigModuleOption,
432
445
  messageText: "If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information." /* Errors.ConfigNoModuleInterop */,
433
446
  category: this.compilerModule.DiagnosticCategory.Message,
434
447
  file: undefined,
@@ -446,6 +459,7 @@ var ConfigSet = /** @class */ (function () {
446
459
  var key = _g.value;
447
460
  var val = forcedOptions[key];
448
461
  if (val === undefined) {
462
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
449
463
  delete finalOptions[key];
450
464
  }
451
465
  else {
@@ -487,29 +501,28 @@ var ConfigSet = /** @class */ (function () {
487
501
  var sourceMap = (_d = resultOptions.sourceMap) !== null && _d !== void 0 ? _d : true;
488
502
  return __assign(__assign({}, result), { options: __assign(__assign({}, resultOptions), { sourceMap: sourceMap, inlineSources: sourceMap, module: (_e = resultOptions.module) !== null && _e !== void 0 ? _e : this.compilerModule.ModuleKind.CommonJS }) });
489
503
  };
490
- // eslint-disable-next-line no-dupe-class-members
491
504
  ConfigSet.prototype._resolveTsConfig = function (compilerOptions, resolvedConfigFile) {
492
505
  var config = { compilerOptions: Object.create(null) };
493
506
  var basePath = (0, normalize_slashes_1.normalizeSlashes)(this.rootDir);
494
507
  var ts = this.compilerModule;
495
508
  // Read project configuration when available.
496
- var configFileName = resolvedConfigFile
509
+ this.tsconfigFilePath = resolvedConfigFile
497
510
  ? (0, normalize_slashes_1.normalizeSlashes)(resolvedConfigFile)
498
511
  : ts.findConfigFile((0, normalize_slashes_1.normalizeSlashes)(this.rootDir), ts.sys.fileExists);
499
- if (configFileName) {
500
- this.logger.debug({ tsConfigFileName: configFileName }, 'readTsConfig(): reading', configFileName);
501
- var result = ts.readConfigFile(configFileName, ts.sys.readFile);
512
+ if (this.tsconfigFilePath) {
513
+ this.logger.debug({ tsConfigFileName: this.tsconfigFilePath }, 'readTsConfig(): reading', this.tsconfigFilePath);
514
+ var result = ts.readConfigFile(this.tsconfigFilePath, ts.sys.readFile);
502
515
  // Return diagnostics.
503
516
  if (result.error) {
504
517
  return { errors: [result.error], fileNames: [], options: {} };
505
518
  }
506
519
  config = result.config;
507
- basePath = (0, normalize_slashes_1.normalizeSlashes)((0, path_1.dirname)(configFileName));
520
+ basePath = (0, normalize_slashes_1.normalizeSlashes)((0, path_1.dirname)(this.tsconfigFilePath));
508
521
  }
509
522
  // Override default configuration options `ts-jest` requires.
510
523
  config.compilerOptions = __assign(__assign({}, config.compilerOptions), compilerOptions);
511
524
  // parse json, merge config extending others, ...
512
- return ts.parseJsonConfigFileContent(config, ts.sys, basePath, undefined, configFileName);
525
+ return ts.parseJsonConfigFileContent(config, ts.sys, basePath, undefined, this.tsconfigFilePath);
513
526
  };
514
527
  ConfigSet.prototype.isTestFile = function (fileName) {
515
528
  var _this = this;
@@ -522,6 +535,7 @@ var ConfigSet = /** @class */ (function () {
522
535
  };
523
536
  ConfigSet.prototype.raiseDiagnostics = function (diagnostics, filePath, logger) {
524
537
  var _this = this;
538
+ if (logger === void 0) { logger = this.logger; }
525
539
  var ignoreCodes = this._diagnostics.ignoreCodes;
526
540
  var DiagnosticCategory = this.compilerModule.DiagnosticCategory;
527
541
  var filteredDiagnostics = filePath && !this.shouldReportDiagnostics(filePath)
@@ -541,8 +555,7 @@ var ConfigSet = /** @class */ (function () {
541
555
  if (this._diagnostics.throws && filteredDiagnostics.some(function (d) { return importantCategories.includes(d.category); })) {
542
556
  throw error;
543
557
  }
544
- /* istanbul ignore next (already covered) */
545
- logger ? logger.warn({ error: error }, error.message) : this.logger.warn({ error: error }, error.message);
558
+ logger.warn({ error: error }, error.message);
546
559
  };
547
560
  ConfigSet.prototype.shouldReportDiagnostics = function (filePath) {
548
561
  var fileExtension = (0, path_1.extname)(filePath);
@@ -581,7 +594,9 @@ var ConfigSet = /** @class */ (function () {
581
594
  path = require.resolve(path);
582
595
  nodeResolved = true;
583
596
  }
584
- catch (_) { }
597
+ catch (_e) {
598
+ this.logger.debug({ path: path }, 'failed to resolve path', path);
599
+ }
585
600
  }
586
601
  if (!nodeResolved) {
587
602
  path = (0, path_1.resolve)(this.cwd, path);
@@ -592,7 +607,9 @@ var ConfigSet = /** @class */ (function () {
592
607
  path = require.resolve(path);
593
608
  nodeResolved = true;
594
609
  }
595
- catch (_) { }
610
+ catch (_f) {
611
+ this.logger.debug({ path: path }, 'failed to resolve path', path);
612
+ }
596
613
  }
597
614
  if (throwIfMissing && !(0, fs_1.existsSync)(path)) {
598
615
  throw new Error((0, messages_1.interpolate)("File not found: {{inputPath}} (resolved as: {{resolvedPath}})" /* Errors.FileNotFound */, { inputPath: inputPath, resolvedPath: path }));
@@ -83,7 +83,6 @@ var utils_1 = require("../utils");
83
83
  var importer_1 = require("../utils/importer");
84
84
  var messages_1 = require("../utils/messages");
85
85
  var sha1_1 = require("../utils/sha1");
86
- var version_checkers_1 = require("../utils/version-checkers");
87
86
  var compiler_1 = require("./compiler");
88
87
  var config_set_1 = require("./config/config-set");
89
88
  /**
@@ -96,7 +95,6 @@ var TsJestTransformer = /** @class */ (function () {
96
95
  this._depGraphs = new Map();
97
96
  this._watchMode = false;
98
97
  this._logger = utils_1.rootLogger.child({ namespace: 'ts-jest-transformer' });
99
- version_checkers_1.VersionCheckers.jest.warn();
100
98
  /**
101
99
  * For some unknown reasons, `this` is undefined in `getCacheKey` and `process`
102
100
  * when running Jest in ESM mode
@@ -165,7 +163,6 @@ var TsJestTransformer = /** @class */ (function () {
165
163
  }
166
164
  return configSet;
167
165
  };
168
- // eslint-disable-next-line class-methods-use-this
169
166
  TsJestTransformer.prototype._createConfigSet = function (config) {
170
167
  return new config_set_1.ConfigSet(config);
171
168
  };
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @deprecated This interface will be replaced with {@link TsConfigJson.CompilerOptions} in the next major release.
3
+ */
1
4
  export interface RawCompilerOptions {
2
5
  /**
3
6
  * Enable importing files with any extension, provided a declaration file is present.
@@ -0,0 +1,4 @@
1
+ import ts from 'typescript';
2
+ type ExtendedTsTranspileModuleFn = (input: string, transpileOptions: ts.TranspileOptions) => ts.TranspileOutput;
3
+ export declare const tsTranspileModule: ExtendedTsTranspileModuleFn;
4
+ export {};
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ var __values = (this && this.__values) || function(o) {
3
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
+ if (m) return m.call(o);
5
+ if (o && typeof o.length === "number") return {
6
+ next: function () {
7
+ if (o && i >= o.length) o = void 0;
8
+ return { value: o && o[i++], done: !o };
9
+ }
10
+ };
11
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
+ };
13
+ var __read = (this && this.__read) || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o), r, ar = [], e;
17
+ try {
18
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
+ }
20
+ catch (error) { e = { error: error }; }
21
+ finally {
22
+ try {
23
+ if (r && !r.done && (m = i["return"])) m.call(i);
24
+ }
25
+ finally { if (e) throw e.error; }
26
+ }
27
+ return ar;
28
+ };
29
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
30
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
31
+ if (ar || !(i in from)) {
32
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
33
+ ar[i] = from[i];
34
+ }
35
+ }
36
+ return to.concat(ar || Array.prototype.slice.call(from));
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.tsTranspileModule = void 0;
43
+ var node_path_1 = __importDefault(require("node:path"));
44
+ var typescript_1 = __importDefault(require("typescript"));
45
+ var messages_1 = require("../../utils/messages");
46
+ var barebonesLibContent = "/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number {}\ninterface Object {}\ninterface RegExp {}\ninterface String {}\ninterface Array<T> { length: number; [n: number]: T; }\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}";
47
+ var barebonesLibName = 'lib.d.ts';
48
+ var barebonesLibSourceFile;
49
+ var carriageReturnLineFeed = '\r\n';
50
+ var lineFeed = '\n';
51
+ function getNewLineCharacter(options) {
52
+ switch (options.newLine) {
53
+ case typescript_1.default.NewLineKind.CarriageReturnLineFeed:
54
+ return carriageReturnLineFeed;
55
+ case typescript_1.default.NewLineKind.LineFeed:
56
+ default:
57
+ return lineFeed;
58
+ }
59
+ }
60
+ /**
61
+ * Copy source code of {@link ts.transpileModule} from {@link https://github.com/microsoft/TypeScript/blob/main/src/services/transpile.ts}
62
+ * with extra modifications:
63
+ * - Remove generation of declaration files
64
+ * - Allow using custom AST transformers with the internal created {@link Program}
65
+ */
66
+ var transpileWorker = function (input, transpileOptions) {
67
+ var e_1, _a;
68
+ var _b, _c, _d, _e;
69
+ barebonesLibSourceFile !== null && barebonesLibSourceFile !== void 0 ? barebonesLibSourceFile : (barebonesLibSourceFile = typescript_1.default.createSourceFile(barebonesLibName, barebonesLibContent, {
70
+ languageVersion: typescript_1.default.ScriptTarget.Latest,
71
+ }));
72
+ var diagnostics = [];
73
+ var options = transpileOptions.compilerOptions
74
+ ? // @ts-expect-error internal TypeScript API
75
+ typescript_1.default.fixupCompilerOptions(transpileOptions.compilerOptions, diagnostics)
76
+ : {};
77
+ // mix in default options
78
+ var defaultOptions = typescript_1.default.getDefaultCompilerOptions();
79
+ for (var key in defaultOptions) {
80
+ if (Object.hasOwn(defaultOptions, key) && options[key] === undefined) {
81
+ options[key] = defaultOptions[key];
82
+ }
83
+ }
84
+ try {
85
+ // @ts-expect-error internal TypeScript API
86
+ for (var _f = __values(typescript_1.default.transpileOptionValueCompilerOptions), _g = _f.next(); !_g.done; _g = _f.next()) {
87
+ var option = _g.value;
88
+ // Do not set redundant config options if `verbatimModuleSyntax` was supplied.
89
+ if (options.verbatimModuleSyntax && new Set(['isolatedModules']).has(option.name)) {
90
+ continue;
91
+ }
92
+ options[option.name] = option.transpileOptionValue;
93
+ }
94
+ }
95
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
96
+ finally {
97
+ try {
98
+ if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
99
+ }
100
+ finally { if (e_1) throw e_1.error; }
101
+ }
102
+ // transpileModule does not write anything to disk so there is no need to verify that there are no conflicts between input and output paths.
103
+ options.suppressOutputPathCheck = true;
104
+ // Filename can be non-ts file.
105
+ options.allowNonTsExtensions = true;
106
+ options.declaration = false;
107
+ options.declarationMap = false;
108
+ var newLine = getNewLineCharacter(options);
109
+ // if jsx is specified then treat file as .tsx
110
+ var inputFileName = (_b = transpileOptions.fileName) !== null && _b !== void 0 ? _b : (((_c = transpileOptions.compilerOptions) === null || _c === void 0 ? void 0 : _c.jsx) ? 'module.tsx' : 'module.ts');
111
+ // Create a compilerHost object to allow the compiler to read and write files
112
+ var compilerHost = {
113
+ getSourceFile: function (fileName) {
114
+ // @ts-expect-error internal TypeScript API
115
+ if (fileName === typescript_1.default.normalizePath(inputFileName)) {
116
+ return sourceFile;
117
+ }
118
+ // @ts-expect-error internal TypeScript API
119
+ return fileName === typescript_1.default.normalizePath(barebonesLibName) ? barebonesLibSourceFile : undefined;
120
+ },
121
+ writeFile: function (name, text) {
122
+ if (node_path_1.default.extname(name) === '.map') {
123
+ sourceMapText = text;
124
+ }
125
+ else {
126
+ outputText = text;
127
+ }
128
+ },
129
+ getDefaultLibFileName: function () { return barebonesLibName; },
130
+ useCaseSensitiveFileNames: function () { return false; },
131
+ getCanonicalFileName: function (fileName) { return fileName; },
132
+ getCurrentDirectory: function () { return ''; },
133
+ getNewLine: function () { return newLine; },
134
+ fileExists: function (fileName) {
135
+ return fileName.endsWith('package.json') ? typescript_1.default.sys.fileExists(fileName) : fileName === inputFileName;
136
+ },
137
+ readFile: function (fileName) {
138
+ return fileName.endsWith('package.json') ? typescript_1.default.sys.readFile(fileName) : '';
139
+ },
140
+ directoryExists: function () { return true; },
141
+ getDirectories: function () { return []; },
142
+ };
143
+ var sourceFile = typescript_1.default.createSourceFile(inputFileName, input, {
144
+ languageVersion: (_d = options.target) !== null && _d !== void 0 ? _d : typescript_1.default.ScriptTarget.ESNext,
145
+ impliedNodeFormat: typescript_1.default.getImpliedNodeFormatForFile(inputFileName,
146
+ /*packageJsonInfoCache*/ undefined, compilerHost, options),
147
+ // @ts-expect-error internal TypeScript API
148
+ setExternalModuleIndicator: typescript_1.default.getSetExternalModuleIndicator(options),
149
+ jsDocParsingMode: (_e = transpileOptions.jsDocParsingMode) !== null && _e !== void 0 ? _e : typescript_1.default.JSDocParsingMode.ParseAll,
150
+ });
151
+ if (transpileOptions.moduleName) {
152
+ sourceFile.moduleName = transpileOptions.moduleName;
153
+ }
154
+ if (transpileOptions.renamedDependencies) {
155
+ // @ts-expect-error internal TypeScript API
156
+ sourceFile.renamedDependencies = new Map(Object.entries(transpileOptions.renamedDependencies));
157
+ }
158
+ // Output
159
+ var outputText;
160
+ var sourceMapText;
161
+ var inputs = [inputFileName];
162
+ var program = typescript_1.default.createProgram(inputs, options, compilerHost);
163
+ if (transpileOptions.reportDiagnostics) {
164
+ diagnostics.push.apply(diagnostics, __spreadArray([], __read(program.getSyntacticDiagnostics(sourceFile)), false));
165
+ }
166
+ diagnostics.push.apply(diagnostics, __spreadArray([], __read(program.getOptionsDiagnostics()), false));
167
+ // Emit
168
+ var result = program.emit(
169
+ /*targetSourceFile*/ undefined,
170
+ /*writeFile*/ undefined,
171
+ /*cancellationToken*/ undefined,
172
+ /*emitOnlyDtsFiles*/ undefined, transpileOptions.transformers);
173
+ diagnostics.push.apply(diagnostics, __spreadArray([], __read(result.diagnostics), false));
174
+ if (outputText === undefined) {
175
+ diagnostics.push({
176
+ category: typescript_1.default.DiagnosticCategory.Error,
177
+ code: messages_1.TsJestDiagnosticCodes.Generic,
178
+ messageText: 'No output generated',
179
+ file: sourceFile,
180
+ start: 0,
181
+ length: 0,
182
+ });
183
+ }
184
+ return { outputText: outputText !== null && outputText !== void 0 ? outputText : '', diagnostics: diagnostics, sourceMapText: sourceMapText };
185
+ };
186
+ exports.tsTranspileModule = transpileWorker;
package/dist/types.d.ts CHANGED
@@ -2,6 +2,7 @@ import type { TransformedSource, TransformOptions } from '@jest/transform';
2
2
  import type { Config } from '@jest/types';
3
3
  import type * as _babel from 'babel__core';
4
4
  import type * as _ts from 'typescript';
5
+ import type { TsConfigCompilerOptionsJson } from './config/types';
5
6
  import { ESM_JS_TRANSFORM_PATTERN, ESM_TS_JS_TRANSFORM_PATTERN, ESM_TS_TRANSFORM_PATTERN, JS_TRANSFORM_PATTERN, TS_JS_TRANSFORM_PATTERN, TS_TRANSFORM_PATTERN } from './constants';
6
7
  import type { ConfigSet } from './legacy/config/config-set';
7
8
  import type { RawCompilerOptions } from './raw-compiler-options';
@@ -20,7 +21,7 @@ export interface ConfigCustomTransformer {
20
21
  afterDeclarations?: Array<string | AstTransformer>;
21
22
  }
22
23
  /**
23
- * @deprecated use `TsJestTransformerOptions` instead
24
+ * @deprecated use {@link TsJestTransformerOptions} instead
24
25
  */
25
26
  export interface TsJestGlobalOptions {
26
27
  /**
@@ -30,19 +31,25 @@ export interface TsJestGlobalOptions {
30
31
  * - `path/to/tsconfig.json`: path to a specific tsconfig file (<rootDir> can be used)
31
32
  * - `{...}`: an object with inline compiler options
32
33
  *
33
- * @default undefined uses the default tsconfig file
34
+ * @default `undefined` (the default config file will be used if it exists)
35
+ *
36
+ * @remarks
37
+ *
38
+ * {@link RawCompilerOptions} will be replaced with {@link TsConfigCompilerOptionsJson} in the next major release
34
39
  */
35
- tsconfig?: boolean | string | RawCompilerOptions;
40
+ tsconfig?: boolean | string | RawCompilerOptions | TsConfigCompilerOptionsJson;
36
41
  /**
37
- * Compiles files as isolated modules (disables some features and type-checking)
42
+ * @deprecated use {@link TsConfigCompilerOptionsJson.isolatedModules} instead
43
+ *
44
+ * Compiles files as isolated modules (disables some features)
38
45
  *
39
- * @default undefined (disabled)
46
+ * @default `undefined` (disables transpiling files with {@link _ts.transpileModule})
40
47
  */
41
48
  isolatedModules?: boolean;
42
49
  /**
43
50
  * Compiler to use
44
51
  *
45
- * @default 'typescript'
52
+ * @default `typescript`
46
53
  */
47
54
  compiler?: 'typescript' | 'ttypescript' | string;
48
55
  /**
@@ -55,13 +62,13 @@ export interface TsJestGlobalOptions {
55
62
  * - `false`: hide diagnostics of all files (kind of useless)
56
63
  * - `{...}`: an inline object with fine grained settings
57
64
  *
58
- * @default undefined shows all diagnostics
65
+ * @default `undefined`
59
66
  */
60
67
  diagnostics?: boolean | {
61
68
  /**
62
69
  * Enables colorful and pretty output of errors
63
70
  *
64
- * @default undefined (enabled)
71
+ * @default `undefined` (enables formatting errors)
65
72
  */
66
73
  pretty?: boolean;
67
74
  /**
@@ -69,7 +76,7 @@ export interface TsJestGlobalOptions {
69
76
  * [here](https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json).
70
77
  *
71
78
  * @see https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json
72
- * @default [6059,18002,18003]
79
+ * @default `[6059,18002,18003]`
73
80
  */
74
81
  ignoreCodes?: number | string | Array<number | string>;
75
82
  /**
@@ -79,7 +86,7 @@ export interface TsJestGlobalOptions {
79
86
  /**
80
87
  * Logs TypeScript errors to stderr instead of throwing exceptions
81
88
  *
82
- * @default undefined (disabled)
89
+ * @default `undefined` (TypeScript errors will be thrown as exceptions)
83
90
  */
84
91
  warnOnly?: boolean;
85
92
  };
@@ -90,7 +97,7 @@ export interface TsJestGlobalOptions {
90
97
  * - `path/to/.babelrc`: path to a babelrc file (<rootDir> can be used)
91
98
  * - `{...}`: an object with inline babel options
92
99
  *
93
- * @default undefined does NOT use babel
100
+ * @default `undefined` (not using `Babel`)
94
101
  */
95
102
  babelConfig?: boolean | string | BabelConfig;
96
103
  /**
@@ -8,6 +8,7 @@ function getPackageVersion(moduleName) {
8
8
  try {
9
9
  return require("".concat(moduleName, "/package.json")).version;
10
10
  }
11
- catch (err) { }
12
- return;
11
+ catch (_a) {
12
+ return undefined;
13
+ }
13
14
  }
@@ -47,33 +47,17 @@ exports.__requireModule = __requireModule;
47
47
  var logger_1 = require("./logger");
48
48
  var memoize_1 = require("./memoize");
49
49
  var messages_1 = require("./messages");
50
- var version_checkers_1 = require("./version-checkers");
51
50
  var logger = logger_1.rootLogger.child({ namespace: 'Importer' });
52
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
- var passThru = function (action) { return function (input) {
54
- action();
55
- return input;
56
- }; };
57
51
  /**
58
52
  * @internal
59
53
  */
60
54
  var Importer = /** @class */ (function () {
61
- function Importer(_patches) {
62
- if (_patches === void 0) { _patches = {}; }
63
- this._patches = _patches;
55
+ function Importer() {
64
56
  }
65
57
  Object.defineProperty(Importer, "instance", {
66
58
  get: function () {
67
59
  logger.debug('creating Importer singleton');
68
- // here we can define patches to apply to modules.
69
- // it could be fixes that are not deployed, or
70
- // abstractions so that multiple versions work the same
71
- return new Importer({
72
- '@babel/core': [passThru(version_checkers_1.VersionCheckers.babelCore.warn)],
73
- 'babel-jest': [passThru(version_checkers_1.VersionCheckers.babelJest.warn)],
74
- typescript: [passThru(version_checkers_1.VersionCheckers.typescript.warn)],
75
- jest: [passThru(version_checkers_1.VersionCheckers.jest.warn)],
76
- });
60
+ return new Importer();
77
61
  },
78
62
  enumerable: false,
79
63
  configurable: true
@@ -107,14 +91,11 @@ var Importer = /** @class */ (function () {
107
91
  if (req.exists) {
108
92
  // module exists
109
93
  loaded = req;
110
- if (loaded.error) {
111
- // require-ing it failed
112
- logger.error({ requireResult: contextReq }, "failed loading module '".concat(name, "'"), loaded.error.message);
94
+ if (req.error) {
95
+ logger.error({ requireResult: contextReq }, "failed loading module '".concat(name, "'"), req.error.message);
113
96
  }
114
97
  else {
115
- // it has been loaded, let's patch it
116
98
  logger.debug({ requireResult: contextReq }, 'loaded module', name);
117
- loaded.exports = this._patch(name, loaded.exports);
118
99
  }
119
100
  break;
120
101
  }
@@ -127,7 +108,6 @@ var Importer = /** @class */ (function () {
127
108
  // but not one which does not exists
128
109
  return loaded;
129
110
  };
130
- // eslint-disable-next-line no-dupe-class-members
131
111
  Importer.prototype.tryTheseOr = function (moduleNames, missingResult, allowLoadError) {
132
112
  if (allowLoadError === void 0) { allowLoadError = false; }
133
113
  var args = Array.isArray(moduleNames) ? moduleNames : [moduleNames];
@@ -140,19 +120,12 @@ var Importer = /** @class */ (function () {
140
120
  return missingResult;
141
121
  throw result.error;
142
122
  };
143
- Importer.prototype._patch = function (name, unpatched) {
144
- if (name in this._patches) {
145
- logger.debug('patching', name);
146
- return this._patches[name].reduce(function (mod, patcher) { return patcher(mod); }, unpatched);
147
- }
148
- return unpatched;
149
- };
150
123
  Importer.prototype._import = function (why, moduleName, _a) {
151
124
  var _b = _a === void 0 ? {} : _a, _c = _b.alternatives, alternatives = _c === void 0 ? [] : _c, _d = _b.installTip, installTip = _d === void 0 ? moduleName : _d;
152
125
  // try to load any of the alternative after trying main one
153
126
  var res = this.tryThese.apply(this, __spreadArray([moduleName], __read(alternatives), false));
154
127
  // if we could load one, return it
155
- if (res && res.exists) {
128
+ if (res === null || res === void 0 ? void 0 : res.exists) {
156
129
  if (!res.error)
157
130
  return res.exports;
158
131
  // it could not load because of a failure while importing, but it exists
@@ -182,9 +155,6 @@ var Importer = /** @class */ (function () {
182
155
  return args.join(':');
183
156
  })
184
157
  ], Importer.prototype, "tryThese", null);
185
- __decorate([
186
- (0, memoize_1.Memoize)(function (name) { return name; })
187
- ], Importer.prototype, "_patch", null);
188
158
  __decorate([
189
159
  (0, memoize_1.Memoize)()
190
160
  ], Importer, "instance", null);
@@ -209,7 +179,7 @@ function requireWrapper(moduleName) {
209
179
  try {
210
180
  result.exports = requireModule(path);
211
181
  }
212
- catch (error) {
182
+ catch (_a) {
213
183
  try {
214
184
  result.exports = requireModule(moduleName);
215
185
  }
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.stringify = stringify;
7
7
  exports.parse = parse;
8
8
  exports.normalize = normalize;
9
- /* eslint-disable no-redeclare */
10
9
  var fast_json_stable_stringify_1 = __importDefault(require("fast-json-stable-stringify"));
11
10
  var UNDEFINED = 'undefined';
12
11
  function stringify(input) {
@@ -32,7 +31,7 @@ function normalize(input, _a) {
32
31
  result = undefined;
33
32
  normalize.cache.set(input, result);
34
33
  }
35
- return result === undefined ? input : result;
34
+ return result !== null && result !== void 0 ? result : input;
36
35
  }
37
36
  /**
38
37
  * @internal
@@ -6,13 +6,14 @@ var backports_1 = require("./backports");
6
6
  var original = process.env.TS_JEST_LOG;
7
7
  var buildOptions = function () {
8
8
  var _a;
9
+ var _b;
9
10
  return ({
10
11
  context: (_a = {},
11
12
  _a[bs_logger_1.LogContexts.package] = 'ts-jest',
12
13
  _a[bs_logger_1.LogContexts.logLevel] = bs_logger_1.LogLevels.trace,
13
14
  _a.version = require('../../package.json').version,
14
15
  _a),
15
- targets: process.env.TS_JEST_LOG || undefined,
16
+ targets: (_b = process.env.TS_JEST_LOG) !== null && _b !== void 0 ? _b : undefined,
16
17
  });
17
18
  };
18
19
  exports.rootLogger = (0, bs_logger_1.createLogger)(buildOptions());
@@ -1 +1,4 @@
1
- export {};
1
+ export declare const TsJestDiagnosticCodes: {
2
+ readonly Generic: 151000;
3
+ readonly ConfigModuleOption: 151001;
4
+ };
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TsJestDiagnosticCodes = void 0;
3
4
  exports.interpolate = interpolate;
4
5
  /**
5
6
  * @internal
@@ -10,3 +11,7 @@ function interpolate(msg, vars) {
10
11
  // eslint-disable-next-line no-useless-escape
11
12
  return msg.replace(/\{\{([^\}]+)\}\}/g, function (_, key) { return (key in vars ? vars[key] : _); });
12
13
  }
14
+ exports.TsJestDiagnosticCodes = {
15
+ Generic: 151000,
16
+ ConfigModuleOption: 151001,
17
+ };
package/package.json CHANGED
@@ -1,22 +1,23 @@
1
1
  {
2
2
  "name": "ts-jest",
3
- "version": "29.2.6",
3
+ "version": "29.3.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
+ "type": "commonjs",
6
7
  "bin": {
7
8
  "ts-jest": "cli.js"
8
9
  },
9
10
  "description": "A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript",
10
11
  "scripts": {
11
- "prebuild": "rimraf dist coverage *.tgz",
12
+ "prebuild": "rimraf --glob dist coverage *.tgz",
12
13
  "build": "tsc -p tsconfig.build.json",
13
14
  "postbuild": "node scripts/post-build.js",
14
- "test": "jest -c=jest-src.config.ts",
15
+ "test": "jest -c=jest.config.ts",
15
16
  "test-e2e-cjs": "jest -c=jest-e2e.config.cjs --no-cache",
16
17
  "test-e2e-esm": "node --experimental-vm-modules --no-warnings node_modules/jest/bin/jest.js -c=jest-e2e.config.mjs --no-cache",
17
18
  "test-examples": "node scripts/test-examples.js",
18
- "lint": "eslint --ext .js,.ts .",
19
- "lint-fix": "eslint --fix --ext .js,.ts .",
19
+ "lint": "eslint .",
20
+ "lint-fix": "eslint --fix .",
20
21
  "lint-prettier": "prettier \"**/*.{yml,yaml,md}\" --write",
21
22
  "lint-prettier-ci": "prettier '**/*.{yml,yaml,md}' --check",
22
23
  "doc": "cd website && npm run start",
@@ -25,9 +26,7 @@
25
26
  "prepare": "npm run build",
26
27
  "prepublishOnly": "npm run test",
27
28
  "preversion": "npm run test",
28
- "version": "npm run changelog && git add CHANGELOG.md",
29
- "raw:options": "node scripts/generate-raw-compiler-options.js",
30
- "update-e2e": "node scripts/update-e2e.js"
29
+ "version": "npm run changelog && git add CHANGELOG.md"
31
30
  },
32
31
  "repository": {
33
32
  "type": "git",
@@ -60,6 +59,7 @@
60
59
  "lodash.memoize": "^4.1.2",
61
60
  "make-error": "^1.3.6",
62
61
  "semver": "^7.7.1",
62
+ "type-fest": "^4.37.0",
63
63
  "yargs-parser": "^21.1.1"
64
64
  },
65
65
  "peerDependencies": {
@@ -87,16 +87,12 @@
87
87
  "optional": true
88
88
  }
89
89
  },
90
- "husky": {
91
- "hooks": {
92
- "pre-commit": "lint-staged",
93
- "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
94
- "post-commit": "git reset"
95
- }
96
- },
97
90
  "devDependencies": {
98
- "@commitlint/cli": "~18.6.1",
99
- "@commitlint/config-angular": "~18.6.1",
91
+ "@commitlint/cli": "^19.8.0",
92
+ "@commitlint/config-angular": "^19.8.0",
93
+ "@eslint/compat": "^1.2.7",
94
+ "@eslint/eslintrc": "^3.3.1",
95
+ "@eslint/js": "^9.23.0",
100
96
  "@jest/globals": "^29.7.0",
101
97
  "@jest/transform": "^29.7.0",
102
98
  "@jest/types": "^29.6.3",
@@ -109,39 +105,35 @@
109
105
  "@types/lodash.memoize": "^4.1.9",
110
106
  "@types/lodash.set": "^4.3.9",
111
107
  "@types/micromatch": "^4.0.9",
112
- "@types/node": "20.17.19",
108
+ "@types/node": "20.17.25",
113
109
  "@types/semver": "^7.5.8",
114
110
  "@types/yargs": "^17.0.33",
115
111
  "@types/yargs-parser": "21.0.3",
116
- "@typescript-eslint/eslint-plugin": "^7.18.0",
117
- "@typescript-eslint/parser": "^7.18.0",
112
+ "@typescript-eslint/eslint-plugin": "^8.27.0",
113
+ "@typescript-eslint/parser": "^8.27.0",
118
114
  "babel-jest": "^29.7.0",
119
115
  "conventional-changelog-cli": "^5.0.0",
120
- "esbuild": "~0.25.0",
121
- "eslint": "^8.57.1",
122
- "eslint-config-prettier": "^9.1.0",
116
+ "esbuild": "~0.25.1",
117
+ "eslint": "^9.23.0",
118
+ "eslint-config-prettier": "^10.1.1",
123
119
  "eslint-plugin-import": "^2.31.0",
124
120
  "eslint-plugin-jest": "^28.11.0",
125
- "eslint-plugin-jsdoc": "^48.11.0",
126
- "eslint-plugin-prefer-arrow": "^1.2.3",
121
+ "eslint-plugin-jsdoc": "^50.6.9",
127
122
  "eslint-plugin-prettier": "^4.2.1",
128
123
  "execa": "5.1.1",
129
124
  "fs-extra": "^11.3.0",
130
125
  "glob": "^10.2.6",
131
126
  "glob-gitignore": "^1.0.15",
132
- "husky": "~4.3.8",
127
+ "globals": "^16.0.0",
128
+ "husky": "^9.1.7",
133
129
  "jest": "^29.7.0",
134
130
  "js-yaml": "^4.1.0",
135
- "json-schema-to-typescript": "^13.1.2",
136
- "lint-staged": "^15.4.3",
131
+ "lint-staged": "^15.5.0",
132
+ "memfs": "^4.17.0",
137
133
  "prettier": "^2.8.8",
138
- "typescript": "~5.5.4"
139
- },
140
- "lint-staged": {
141
- "*.{ts,tsx,js,jsx}": [
142
- "eslint --fix",
143
- "git add"
144
- ]
134
+ "rimraf": "^5.0.10",
135
+ "typescript": "~5.5.4",
136
+ "typescript-eslint": "^8.27.0"
145
137
  },
146
138
  "engines": {
147
139
  "node": "^14.15.0 || ^16.10.0 || ^18.0.0 || >=20.0.0"
package/preprocessor.js CHANGED
@@ -1,4 +1,3 @@
1
- // eslint-disable-next-line no-console
2
1
  console.warn(
3
2
  'ts-jest[main] (WARN) Replace any occurrences of "ts-jest/dist/preprocessor.js" or ' +
4
3
  ' "<rootDir>/node_modules/ts-jest/preprocessor.js"' +
@@ -1 +0,0 @@
1
- export {};
@@ -1,63 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VersionCheckers = void 0;
4
- var semver_1 = require("semver");
5
- var get_package_version_1 = require("./get-package-version");
6
- var logger_1 = require("./logger");
7
- var messages_1 = require("./messages");
8
- var logger = logger_1.rootLogger.child({ namespace: 'versions' });
9
- /**
10
- * @internal
11
- */
12
- exports.VersionCheckers = {
13
- jest: createVersionChecker('jest', ">=29.0.0 <30" /* ExpectedVersions.Jest */),
14
- typescript: createVersionChecker('typescript', ">=4.3 <6" /* ExpectedVersions.TypeScript */),
15
- babelJest: createVersionChecker('babel-jest', ">=29.0.0 <30" /* ExpectedVersions.BabelJest */),
16
- babelCore: createVersionChecker('@babel/core', ">=7.0.0-beta.0 <8" /* ExpectedVersions.BabelCore */),
17
- };
18
- function checkVersion(name, expectedRange, action) {
19
- if (action === void 0) { action = 'warn'; }
20
- var success = true;
21
- if (!('TS_JEST_DISABLE_VER_CHECKER' in process.env)) {
22
- var version = (0, get_package_version_1.getPackageVersion)(name);
23
- success = !!version && (0, semver_1.satisfies)(version, expectedRange);
24
- logger.debug({
25
- actualVersion: version,
26
- expectedVersion: expectedRange,
27
- }, 'checking version of %s: %s', name, success ? 'OK' : 'NOT OK');
28
- if (!action || success)
29
- return success;
30
- var message = (0, messages_1.interpolate)(version ? "Version {{actualVersion}} of {{module}} installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version ({{expectedVersion}}). Please do not report issues in ts-jest if you are using unsupported versions." /* Errors.UntestedDependencyVersion */ : "Module {{module}} is not installed. If you're experiencing issues, consider installing a supported version ({{expectedVersion}})." /* Errors.MissingDependency */, {
31
- module: name,
32
- actualVersion: version || '??',
33
- expectedVersion: rangeToHumanString(expectedRange),
34
- });
35
- if (action === 'warn') {
36
- logger.warn(message);
37
- }
38
- else if (action === 'throw') {
39
- logger.fatal(message);
40
- throw new RangeError(message);
41
- }
42
- }
43
- return success;
44
- }
45
- function rangeToHumanString(versionRange) {
46
- return new semver_1.Range(versionRange).toString();
47
- }
48
- function createVersionChecker(moduleName, expectedVersion) {
49
- var memo;
50
- var warn = function () {
51
- if (memo !== undefined)
52
- return memo;
53
- return (memo = checkVersion(moduleName, expectedVersion, 'warn'));
54
- };
55
- var raise = function () { return checkVersion(moduleName, expectedVersion, 'throw'); };
56
- return {
57
- raise: raise,
58
- warn: warn,
59
- forget: function () {
60
- memo = undefined;
61
- },
62
- };
63
- }