ts-jest 29.1.1 → 29.1.3

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
- b3b0008986ac15bb8a6bdd80c9102577ea718871
1
+ 119b6863ec1b60a4ccead1725443bf8562134c2a
package/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ ## [29.1.3](https://github.com/kulshekhar/ts-jest/compare/v29.1.2...v29.1.3) (2024-05-21)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * add `@jest/transform` as an optional peer dependency ([0ba7f86](https://github.com/kulshekhar/ts-jest/commit/0ba7f861c3e1905de5627b4e5d2a2cadad011b67))
7
+ * bring back Node 14 support ([eda56a7](https://github.com/kulshekhar/ts-jest/commit/eda56a779789d70963b7572e2914b2a3a25ac43a))
8
+
9
+
10
+ ### Performance Improvements
11
+
12
+ * remove ts resolved module cache file ([4c88da5](https://github.com/kulshekhar/ts-jest/commit/4c88da58991b000aa90ea489acfa6aed39b36120))
13
+
14
+
15
+
16
+ ## [29.1.2](https://github.com/kulshekhar/ts-jest/compare/v29.1.1...v29.1.2) (2024-01-22)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * calculated cache key based on `supportsStaticESM` ([a5d6f2d](https://github.com/kulshekhar/ts-jest/commit/a5d6f2d4f4bfa1c7c217f6faf9310958797b436f))
22
+ * correct error handling in `processAsync` ([e7be4bf](https://github.com/kulshekhar/ts-jest/commit/e7be4bf6a863cd76efec28f40fdd5193b2f50bad)), closes [#4207](https://github.com/kulshekhar/ts-jest/issues/4207)
23
+ * use `Config.ProjectConfig` ([918312b](https://github.com/kulshekhar/ts-jest/commit/918312bee22a795ec6bb347f95df4c1ff0a054de)), closes [#4028](https://github.com/kulshekhar/ts-jest/issues/4028)
24
+
25
+
26
+
1
27
  ## [29.1.1](https://github.com/kulshekhar/ts-jest/compare/v29.1.0...v29.1.1) (2023-06-23)
2
28
 
3
29
 
@@ -1,7 +1,7 @@
1
1
  import { Logger } from 'bs-logger';
2
2
  import type * as ts from 'typescript';
3
3
  import type { RawCompilerOptions } from '../../raw-compiler-options';
4
- import type { ProjectConfigTsJest, TsJestAstTransformer, TTypeScript } from '../../types';
4
+ import type { TsJestAstTransformer, TsJestTransformOptions, TTypeScript } from '../../types';
5
5
  export declare class ConfigSet {
6
6
  readonly parentLogger?: Logger | undefined;
7
7
  /**
@@ -18,7 +18,7 @@ export declare class ConfigSet {
18
18
  parsedTsConfig: ts.ParsedCommandLine | Record<string, any>;
19
19
  resolvedTransformers: TsJestAstTransformer;
20
20
  useESM: boolean;
21
- constructor(jestConfig: ProjectConfigTsJest | undefined, parentLogger?: Logger | undefined);
21
+ constructor(jestConfig: TsJestTransformOptions['config'] | undefined, parentLogger?: Logger | undefined);
22
22
  /**
23
23
  * Load TypeScript configuration. Returns the parsed TypeScript config and any `tsconfig` options specified in ts-jest
24
24
  * Subclasses which extend `ConfigSet` can override the default behavior
@@ -1,23 +1,22 @@
1
1
  import type { SyncTransformer, TransformedSource } from '@jest/transform';
2
- import type { CompilerInstance, ProjectConfigTsJest, TransformOptionsTsJest, TsJestGlobalOptions } from '../types';
2
+ import type { CompilerInstance, TsJestTransformerOptions, TsJestTransformOptions } from '../types';
3
3
  import { ConfigSet } from './config/config-set';
4
- export declare class TsJestTransformer implements SyncTransformer {
4
+ export declare class TsJestTransformer implements SyncTransformer<TsJestTransformerOptions> {
5
5
  private readonly tsJestConfig?;
6
6
  private readonly _logger;
7
7
  protected _compiler: CompilerInstance;
8
- private _tsResolvedModulesCachePath;
9
8
  private _transformCfgStr;
10
9
  private _depGraphs;
11
10
  private _watchMode;
12
- constructor(tsJestConfig?: TsJestGlobalOptions | undefined);
11
+ constructor(tsJestConfig?: import("../types").TsJestGlobalOptions | undefined);
13
12
  private _configsFor;
14
- protected _createConfigSet(config: ProjectConfigTsJest | undefined): ConfigSet;
13
+ protected _createConfigSet(config: TsJestTransformOptions['config'] | undefined): ConfigSet;
15
14
  protected _createCompiler(configSet: ConfigSet, cacheFS: Map<string, string>): void;
16
15
  /**
17
16
  * @public
18
17
  */
19
- process(sourceText: string, sourcePath: string, transformOptions: TransformOptionsTsJest): TransformedSource;
20
- processAsync(sourceText: string, sourcePath: string, transformOptions: TransformOptionsTsJest): Promise<TransformedSource>;
18
+ process(sourceText: string, sourcePath: string, transformOptions: TsJestTransformOptions): TransformedSource;
19
+ processAsync(sourceText: string, sourcePath: string, transformOptions: TsJestTransformOptions): Promise<TransformedSource>;
21
20
  private processWithTs;
22
21
  private runTsJestHook;
23
22
  /**
@@ -27,10 +26,6 @@ export declare class TsJestTransformer implements SyncTransformer {
27
26
  *
28
27
  * @public
29
28
  */
30
- getCacheKey(fileContent: string, filePath: string, transformOptions: TransformOptionsTsJest): string;
31
- getCacheKeyAsync(sourceText: string, sourcePath: string, transformOptions: TransformOptionsTsJest): Promise<string>;
32
- /**
33
- * Subclasses extends `TsJestTransformer` can call this method to get resolved module disk cache
34
- */
35
- private _getFsCachedResolvedModules;
29
+ getCacheKey(fileContent: string, filePath: string, transformOptions: TsJestTransformOptions): string;
30
+ getCacheKeyAsync(sourceText: string, sourcePath: string, transformOptions: TsJestTransformOptions): Promise<string>;
36
31
  }
@@ -117,7 +117,6 @@ var TsJestTransformer = exports.TsJestTransformer = /** @class */ (function () {
117
117
  this._transformCfgStr = ccs.transformerCfgStr;
118
118
  this._compiler = ccs.compiler;
119
119
  this._depGraphs = ccs.depGraphs;
120
- this._tsResolvedModulesCachePath = ccs.tsResolvedModulesCachePath;
121
120
  this._watchMode = ccs.watchMode;
122
121
  configSet = ccs.configSet;
123
122
  }
@@ -133,7 +132,6 @@ var TsJestTransformer = exports.TsJestTransformer = /** @class */ (function () {
133
132
  this._transformCfgStr = serializedCcs.transformerCfgStr;
134
133
  this._compiler = serializedCcs.compiler;
135
134
  this._depGraphs = serializedCcs.depGraphs;
136
- this._tsResolvedModulesCachePath = serializedCcs.tsResolvedModulesCachePath;
137
135
  this._watchMode = serializedCcs.watchMode;
138
136
  configSet = serializedCcs.configSet;
139
137
  }
@@ -154,7 +152,6 @@ var TsJestTransformer = exports.TsJestTransformer = /** @class */ (function () {
154
152
  jest_1.cacheDirectory = undefined; // eslint-disable-line @typescript-eslint/no-explicit-any
155
153
  this._transformCfgStr = "".concat(new utils_1.JsonableValue(jest_1).serialized).concat(configSet.cacheSuffix);
156
154
  this._createCompiler(configSet, cacheFS);
157
- this._getFsCachedResolvedModules(configSet);
158
155
  this._watchMode = process.argv.includes('--watch');
159
156
  TsJestTransformer._cachedConfigSets.push({
160
157
  jestConfig: new utils_1.JsonableValue(config),
@@ -162,7 +159,6 @@ var TsJestTransformer = exports.TsJestTransformer = /** @class */ (function () {
162
159
  transformerCfgStr: this._transformCfgStr,
163
160
  compiler: this._compiler,
164
161
  depGraphs: this._depGraphs,
165
- tsResolvedModulesCachePath: this._tsResolvedModulesCachePath,
166
162
  watchMode: this._watchMode,
167
163
  });
168
164
  }
@@ -196,40 +192,34 @@ var TsJestTransformer = exports.TsJestTransformer = /** @class */ (function () {
196
192
  return result;
197
193
  };
198
194
  TsJestTransformer.prototype.processAsync = function (sourceText, sourcePath, transformOptions) {
195
+ var _a;
199
196
  return __awaiter(this, void 0, void 0, function () {
200
- var _this = this;
201
- return __generator(this, function (_a) {
202
- this._logger.debug({ fileName: sourcePath, transformOptions: transformOptions }, 'processing', sourcePath);
203
- return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
204
- var configs, shouldStringifyContent, babelJest, result, processWithTsResult;
205
- var _a;
206
- return __generator(this, function (_b) {
207
- switch (_b.label) {
208
- case 0:
209
- configs = this._configsFor(transformOptions);
210
- shouldStringifyContent = configs.shouldStringifyContent(sourcePath);
211
- babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
212
- processWithTsResult = this.processWithTs(sourceText, sourcePath, transformOptions);
213
- result = {
214
- code: processWithTsResult.code,
215
- };
216
- if ((_a = processWithTsResult.diagnostics) === null || _a === void 0 ? void 0 : _a.length) {
217
- reject(configs.createTsError(processWithTsResult.diagnostics));
218
- }
219
- if (!babelJest) return [3 /*break*/, 2];
220
- this._logger.debug({ fileName: sourcePath }, 'calling babel-jest processor');
221
- return [4 /*yield*/, babelJest.processAsync(result.code, sourcePath, __assign(__assign({}, transformOptions), { instrument: false }))];
222
- case 1:
223
- // do not instrument here, jest will do it anyway afterwards
224
- result = _b.sent();
225
- _b.label = 2;
226
- case 2:
227
- result = this.runTsJestHook(sourcePath, sourceText, transformOptions, result);
228
- resolve(result);
229
- return [2 /*return*/];
230
- }
231
- });
232
- }); })];
197
+ var configs, shouldStringifyContent, babelJest, result, processWithTsResult;
198
+ return __generator(this, function (_b) {
199
+ switch (_b.label) {
200
+ case 0:
201
+ this._logger.debug({ fileName: sourcePath, transformOptions: transformOptions }, 'processing', sourcePath);
202
+ configs = this._configsFor(transformOptions);
203
+ shouldStringifyContent = configs.shouldStringifyContent(sourcePath);
204
+ babelJest = shouldStringifyContent ? undefined : configs.babelJestTransformer;
205
+ processWithTsResult = this.processWithTs(sourceText, sourcePath, transformOptions);
206
+ result = {
207
+ code: processWithTsResult.code,
208
+ };
209
+ if ((_a = processWithTsResult.diagnostics) === null || _a === void 0 ? void 0 : _a.length) {
210
+ throw configs.createTsError(processWithTsResult.diagnostics);
211
+ }
212
+ if (!babelJest) return [3 /*break*/, 2];
213
+ this._logger.debug({ fileName: sourcePath }, 'calling babel-jest processor');
214
+ return [4 /*yield*/, babelJest.processAsync(result.code, sourcePath, __assign(__assign({}, transformOptions), { instrument: false }))];
215
+ case 1:
216
+ // do not instrument here, jest will do it anyway afterwards
217
+ result = _b.sent();
218
+ _b.label = 2;
219
+ case 2:
220
+ result = this.runTsJestHook(sourcePath, sourceText, transformOptions, result);
221
+ return [2 /*return*/, result];
222
+ }
233
223
  });
234
224
  });
235
225
  };
@@ -311,7 +301,7 @@ var TsJestTransformer = exports.TsJestTransformer = /** @class */ (function () {
311
301
  var configs = this._configsFor(transformOptions);
312
302
  this._logger.debug({ fileName: filePath, transformOptions: transformOptions }, 'computing cache key for', filePath);
313
303
  // we do not instrument, ensure it is false all the time
314
- var instrument = (_a = transformOptions.instrument, _a === void 0 ? false : _a);
304
+ var supportsStaticESM = transformOptions.supportsStaticESM, instrument = (_a = transformOptions.instrument, _a === void 0 ? false : _a);
315
305
  var constructingCacheKeyElements = [
316
306
  this._transformCfgStr,
317
307
  exports.CACHE_KEY_EL_SEPARATOR,
@@ -319,11 +309,13 @@ var TsJestTransformer = exports.TsJestTransformer = /** @class */ (function () {
319
309
  exports.CACHE_KEY_EL_SEPARATOR,
320
310
  "instrument:".concat(instrument ? 'on' : 'off'),
321
311
  exports.CACHE_KEY_EL_SEPARATOR,
312
+ "supportsStaticESM:".concat(supportsStaticESM ? 'on' : 'off'),
313
+ exports.CACHE_KEY_EL_SEPARATOR,
322
314
  fileContent,
323
315
  exports.CACHE_KEY_EL_SEPARATOR,
324
316
  filePath,
325
317
  ];
326
- if (!configs.isolatedModules && this._tsResolvedModulesCachePath) {
318
+ if (!configs.isolatedModules && configs.tsCacheDir) {
327
319
  var resolvedModuleNames = void 0;
328
320
  if (((_b = this._depGraphs.get(filePath)) === null || _b === void 0 ? void 0 : _b.fileContent) === fileContent) {
329
321
  this._logger.debug({ fileName: filePath, transformOptions: transformOptions }, 'getting resolved modules from disk caching or memory caching for', filePath);
@@ -339,7 +331,6 @@ var TsJestTransformer = exports.TsJestTransformer = /** @class */ (function () {
339
331
  fileContent: fileContent,
340
332
  resolvedModuleNames: resolvedModuleNames,
341
333
  });
342
- (0, fs_1.writeFileSync)(this._tsResolvedModulesCachePath, (0, utils_1.stringify)(__spreadArray([], __read(this._depGraphs), false)));
343
334
  }
344
335
  resolvedModuleNames.forEach(function (moduleName) {
345
336
  constructingCacheKeyElements.push(exports.CACHE_KEY_EL_SEPARATOR, moduleName, exports.CACHE_KEY_EL_SEPARATOR, (0, fs_1.statSync)(moduleName).mtimeMs.toString());
@@ -354,22 +345,6 @@ var TsJestTransformer = exports.TsJestTransformer = /** @class */ (function () {
354
345
  });
355
346
  });
356
347
  };
357
- /**
358
- * Subclasses extends `TsJestTransformer` can call this method to get resolved module disk cache
359
- */
360
- TsJestTransformer.prototype._getFsCachedResolvedModules = function (configSet) {
361
- var cacheDir = configSet.tsCacheDir;
362
- if (!configSet.isolatedModules && cacheDir) {
363
- // Make sure the cache directory exists before continuing.
364
- (0, fs_1.mkdirSync)(cacheDir, { recursive: true });
365
- this._tsResolvedModulesCachePath = path_1.default.join(cacheDir, (0, sha1_1.sha1)('ts-jest-resolved-modules', exports.CACHE_KEY_EL_SEPARATOR));
366
- try {
367
- var cachedTSResolvedModules = (0, fs_1.readFileSync)(this._tsResolvedModulesCachePath, 'utf-8');
368
- this._depGraphs = new Map((0, utils_1.parse)(cachedTSResolvedModules));
369
- }
370
- catch (e) { }
371
- }
372
- };
373
348
  /**
374
349
  * cache ConfigSet between test runs
375
350
  *
package/dist/types.d.ts CHANGED
@@ -125,8 +125,8 @@ export interface ProjectConfigTsJest extends Config.ProjectConfig {
125
125
  /**
126
126
  * @deprecated use `JestConfigWithTsJest` instead
127
127
  */
128
- export interface TransformOptionsTsJest extends TransformOptions {
129
- config: ProjectConfigTsJest;
128
+ export interface TransformOptionsTsJest<TransformerConfig = unknown> extends TransformOptions<TransformerConfig> {
129
+ config: Config.ProjectConfig;
130
130
  }
131
131
  /**
132
132
  * For typings in `jest.config.ts`
@@ -142,6 +142,7 @@ export interface InitialOptionsTsJest extends Config.InitialOptions {
142
142
  globals?: GlobalConfigTsJest;
143
143
  }
144
144
  export type TsJestTransformerOptions = TsJestGlobalOptions;
145
+ export type TsJestTransformOptions = TransformOptions<TsJestTransformerOptions>;
145
146
  export interface JestConfigWithTsJest extends Omit<Config.InitialOptions, 'transform'> {
146
147
  transform?: {
147
148
  [regex: string]: 'ts-jest' | 'ts-jest/legacy' | ['ts-jest', TsJestTransformerOptions] | ['ts-jest/legacy', TsJestTransformerOptions] | string | Config.TransformerConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-jest",
3
- "version": "29.1.1",
3
+ "version": "29.1.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "bin": {
@@ -62,6 +62,7 @@
62
62
  },
63
63
  "peerDependencies": {
64
64
  "@babel/core": ">=7.0.0-beta.0 <8",
65
+ "@jest/transform": "^29.0.0",
65
66
  "@jest/types": "^29.0.0",
66
67
  "babel-jest": "^29.0.0",
67
68
  "jest": "^29.0.0",
@@ -71,6 +72,9 @@
71
72
  "@babel/core": {
72
73
  "optional": true
73
74
  },
75
+ "@jest/transform": {
76
+ "optional": true
77
+ },
74
78
  "@jest/types": {
75
79
  "optional": true
76
80
  },
@@ -91,26 +95,26 @@
91
95
  "devDependencies": {
92
96
  "@commitlint/cli": "17.x",
93
97
  "@commitlint/config-angular": "^17.6.5",
94
- "@jest/transform": "^29.5.0",
95
- "@jest/types": "^29.5.0",
96
- "@types/babel__core": "7.x",
98
+ "@jest/transform": "^29.7.0",
99
+ "@jest/types": "^29.6.3",
100
+ "@types/babel__core": "7.20.5",
97
101
  "@types/cross-spawn": "latest",
98
102
  "@types/fs-extra": "latest",
99
103
  "@types/js-yaml": "latest",
100
- "@types/lodash.camelcase": "4.x",
101
- "@types/lodash.memoize": "4.x",
102
- "@types/lodash.set": "4.x",
103
- "@types/micromatch": "4.x",
104
- "@types/node": "18.16.18",
104
+ "@types/lodash.camelcase": "4.3.9",
105
+ "@types/lodash.memoize": "4.1.9",
106
+ "@types/lodash.set": "4.3.9",
107
+ "@types/micromatch": "4.0.7",
108
+ "@types/node": "18.19.33",
105
109
  "@types/react": "18.x",
106
110
  "@types/rimraf": "^3.0.2",
107
111
  "@types/semver": "latest",
108
112
  "@types/yargs": "latest",
109
- "@types/yargs-parser": "21.x",
110
- "@typescript-eslint/eslint-plugin": "^5.60.0",
111
- "@typescript-eslint/parser": "^5.60.0",
112
- "babel-jest": "^29.5.0",
113
- "conventional-changelog-cli": "2.x",
113
+ "@types/yargs-parser": "21.0.3",
114
+ "@typescript-eslint/eslint-plugin": "^5.62.0",
115
+ "@typescript-eslint/parser": "^5.62.0",
116
+ "babel-jest": "^29.7.0",
117
+ "conventional-changelog-cli": "2.2.2",
114
118
  "cross-spawn": "latest",
115
119
  "esbuild": "~0.17.19",
116
120
  "eslint": "^8.42.0",
@@ -125,14 +129,14 @@
125
129
  "glob": "^10.2.6",
126
130
  "glob-gitignore": "latest",
127
131
  "husky": "4.x",
128
- "jest": "^29.5.0",
132
+ "jest": "^29.7.0",
129
133
  "jest-snapshot-serializer-raw": "^1.2.0",
130
134
  "js-yaml": "latest",
131
- "json-schema-to-typescript": "^13.0.1",
135
+ "json-schema-to-typescript": "^13.0.2",
132
136
  "lint-staged": "latest",
133
137
  "lodash.camelcase": "^4.3.0",
134
138
  "lodash.set": "^4.3.2",
135
- "node-fetch": "^3.3.1",
139
+ "node-fetch": "^3.3.2",
136
140
  "prettier": "^2.8.8",
137
141
  "typescript": "~5.1.3"
138
142
  },
@@ -143,6 +147,6 @@
143
147
  ]
144
148
  },
145
149
  "engines": {
146
- "node": "^14.15.0 || ^16.10.0 || >=18.0.0"
150
+ "node": "^14.15.0 || ^16.10.0 || ^18.0.0 || >=20.0.0"
147
151
  }
148
152
  }