ts-jest 26.1.0 → 26.1.1

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
- eeca777d22e47cf3d4ed72c46ec92618ae5691f9
1
+ 5e9f319e512fe352ff9b9947c24dd3a512e4be3f
package/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ <a name="26.1.1"></a>
2
+ ## [26.1.1](https://github.com/kulshekhar/ts-jest/compare/v26.1.0...v26.1.1) (2020-06-21)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * **compiler:** generate source map correctly when tsconfig `mapRoot` is set ([#1741](https://github.com/kulshekhar/ts-jest/issues/1741)) ([01ac417](https://github.com/kulshekhar/ts-jest/commit/01ac417)), closes [#1718](https://github.com/kulshekhar/ts-jest/issues/1718)
8
+ * **config:** show version warning when using ts-jest without babel ([#1729](https://github.com/kulshekhar/ts-jest/issues/1729)) ([e512bc0](https://github.com/kulshekhar/ts-jest/commit/e512bc0)), fixes [#1678-issuecomment-641930332](https://github.com//github.com/kulshekhar/ts-jest/pull/1678/issues/issuecomment-641930332), [#1678-issuecomment-639528993](https://github.com//github.com/kulshekhar/ts-jest/pull/1678/issues/issuecomment-639528993)
9
+
10
+
11
+
1
12
  <a name="26.1.0"></a>
2
13
  # [26.1.0](https://github.com/kulshekhar/ts-jest/compare/v26.0.0...v26.1.0) (2020-05-30)
3
14
 
@@ -30,16 +30,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
30
30
  exports.createCompilerInstance = void 0;
31
31
  var fs_1 = require("fs");
32
32
  var mkdirp = require("mkdirp");
33
- var path_1 = require("path");
34
33
  var compiler_utils_1 = require("./compiler-utils");
35
34
  var language_service_1 = require("./language-service");
36
35
  var transpiler_1 = require("./transpiler");
37
- function updateOutput(outputText, normalizedFileName, sourceMap, getExtension) {
38
- var base = path_1.basename(normalizedFileName);
36
+ var SOURCE_MAPPING_PREFIX = 'sourceMappingURL=';
37
+ function updateOutput(outputText, normalizedFileName, sourceMap) {
39
38
  var base64Map = Buffer.from(updateSourceMap(sourceMap, normalizedFileName), 'utf8').toString('base64');
40
39
  var sourceMapContent = "data:application/json;charset=utf-8;base64," + base64Map;
41
- var sourceMapLength = (base + ".map").length + (getExtension(normalizedFileName).length - path_1.extname(normalizedFileName).length);
42
- return outputText.slice(0, -sourceMapLength) + sourceMapContent;
40
+ return (outputText.slice(0, outputText.lastIndexOf(SOURCE_MAPPING_PREFIX) + SOURCE_MAPPING_PREFIX.length) + sourceMapContent);
43
41
  }
44
42
  var updateSourceMap = function (sourceMapText, normalizedFileName) {
45
43
  var sourceMap = JSON.parse(sourceMapText);
@@ -48,10 +46,10 @@ var updateSourceMap = function (sourceMapText, normalizedFileName) {
48
46
  delete sourceMap.sourceRoot;
49
47
  return JSON.stringify(sourceMap);
50
48
  };
51
- var compileAndCacheResult = function (memoryCache, compileFn, getExtension, logger) { return function (code, fileName, lineOffset) {
49
+ var compileAndCacheResult = function (memoryCache, compileFn, logger) { return function (code, fileName, lineOffset) {
52
50
  logger.debug({ fileName: fileName }, 'compileAndCacheResult(): get compile output');
53
51
  var _a = __read(compileFn(code, fileName, lineOffset), 2), value = _a[0], sourceMap = _a[1];
54
- var output = updateOutput(value, fileName, sourceMap, getExtension);
52
+ var output = updateOutput(value, fileName, sourceMap);
55
53
  memoryCache.files.set(fileName, __assign(__assign({}, memoryCache.files.get(fileName)), { output: output }));
56
54
  return output;
57
55
  }; };
@@ -59,7 +57,6 @@ exports.createCompilerInstance = function (configs) {
59
57
  var logger = configs.logger.child({ namespace: 'ts-compiler' });
60
58
  var compilerOptions = configs.parsedTsConfig.options, tsJest = configs.tsJest;
61
59
  var cacheDir = configs.tsCacheDir;
62
- var ts = configs.compilerModule;
63
60
  var extensions = ['.ts', '.tsx'];
64
61
  var memoryCache = {
65
62
  files: new Map(),
@@ -82,9 +79,6 @@ exports.createCompilerInstance = function (configs) {
82
79
  version: 0,
83
80
  });
84
81
  });
85
- var getExtension = compilerOptions.jsx === ts.JsxEmit.Preserve
86
- ? function (path) { return (/\.[tj]sx$/.test(path) ? '.jsx' : '.js'); }
87
- : function (_) { return '.js'; };
88
82
  var compilerInstance;
89
83
  if (!tsJest.isolatedModules) {
90
84
  compilerInstance = language_service_1.initializeLanguageServiceInstance(configs, memoryCache, logger);
@@ -92,6 +86,6 @@ exports.createCompilerInstance = function (configs) {
92
86
  else {
93
87
  compilerInstance = transpiler_1.initializeTranspilerInstance(configs, memoryCache, logger);
94
88
  }
95
- var compile = compileAndCacheResult(memoryCache, compilerInstance.compileFn, getExtension, logger);
89
+ var compile = compileAndCacheResult(memoryCache, compilerInstance.compileFn, logger);
96
90
  return { cwd: configs.cwd, compile: compile, program: compilerInstance.program };
97
91
  };
@@ -47,6 +47,7 @@ var __spread = (this && this.__spread) || function () {
47
47
  for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
48
48
  return ar;
49
49
  };
50
+ var _a;
50
51
  Object.defineProperty(exports, "__esModule", { value: true });
51
52
  exports.ConfigSet = exports.TS_JEST_OUT_DIR = exports.IGNORE_DIAGNOSTIC_CODES = exports.MATCH_NOTHING = void 0;
52
53
  var bs_logger_1 = require("bs-logger");
@@ -77,6 +78,12 @@ exports.IGNORE_DIAGNOSTIC_CODES = [
77
78
  18003,
78
79
  ];
79
80
  exports.TS_JEST_OUT_DIR = '$$ts-jest$$';
81
+ var TARGET_TO_VERSION_MAPPING = (_a = {},
82
+ _a[typescript_1.ScriptTarget.ES2018] = 'es2018',
83
+ _a[typescript_1.ScriptTarget.ES2019] = 'es2019',
84
+ _a[typescript_1.ScriptTarget.ES2020] = 'es2020',
85
+ _a[typescript_1.ScriptTarget.ESNext] = 'ESNext',
86
+ _a);
80
87
  var normalizeRegex = function (pattern) {
81
88
  return pattern ? (typeof pattern === 'string' ? pattern : pattern.source) : undefined;
82
89
  };
@@ -316,8 +323,8 @@ var ConfigSet = (function () {
316
323
  Object.defineProperty(ConfigSet.prototype, "_parsedTsConfig", {
317
324
  get: function () {
318
325
  var tsConfig = this.tsJest.tsConfig;
319
- var configFilePath = tsConfig && tsConfig.kind === 'file' ? tsConfig.value : undefined;
320
- var result = this.readTsConfig(tsConfig && tsConfig.kind === 'inline' ? tsConfig.value : undefined, configFilePath, tsConfig == null);
326
+ var configFilePath = (tsConfig === null || tsConfig === void 0 ? void 0 : tsConfig.kind) === 'file' ? tsConfig.value : undefined;
327
+ var result = this.readTsConfig((tsConfig === null || tsConfig === void 0 ? void 0 : tsConfig.kind) === 'inline' ? tsConfig.value : undefined, configFilePath, tsConfig == null);
321
328
  this.raiseDiagnostics(result.errors, configFilePath);
322
329
  this.logger.debug({ tsconfig: result }, 'normalized typescript config');
323
330
  return result;
@@ -604,6 +611,7 @@ var ConfigSet = (function () {
604
611
  };
605
612
  ConfigSet.prototype.readTsConfig = function (compilerOptions, resolvedConfigFile, noProject) {
606
613
  var e_2, _a;
614
+ var _b;
607
615
  var config = { compilerOptions: Object.create(null) };
608
616
  var basePath = normalize_slashes_1.normalizeSlashes(this.rootDir);
609
617
  var configFileName;
@@ -648,8 +656,8 @@ var ConfigSet = (function () {
648
656
  finalOptions.outDir = exports.TS_JEST_OUT_DIR;
649
657
  }
650
658
  try {
651
- for (var _b = __values(Object.keys(forcedOptions)), _c = _b.next(); !_c.done; _c = _b.next()) {
652
- var key = _c.value;
659
+ for (var _c = __values(Object.keys(forcedOptions)), _d = _c.next(); !_d.done; _d = _c.next()) {
660
+ var key = _d.value;
653
661
  var val = forcedOptions[key];
654
662
  if (val === undefined) {
655
663
  delete finalOptions[key];
@@ -662,17 +670,18 @@ var ConfigSet = (function () {
662
670
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
663
671
  finally {
664
672
  try {
665
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
673
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
666
674
  }
667
675
  finally { if (e_2) throw e_2.error; }
668
676
  }
669
677
  var nodeJsVer = process.version;
670
678
  var compilationTarget = result.options.target;
671
- if ((nodeJsVer.startsWith('v10') && compilationTarget > typescript_1.ScriptTarget.ES2018) ||
672
- (nodeJsVer.startsWith('v12') && compilationTarget > typescript_1.ScriptTarget.ES2019)) {
679
+ if (!this.tsJest.babelConfig &&
680
+ ((nodeJsVer.startsWith('v10') && compilationTarget > typescript_1.ScriptTarget.ES2018) ||
681
+ (nodeJsVer.startsWith('v12') && compilationTarget > typescript_1.ScriptTarget.ES2019))) {
673
682
  var message = messages_1.interpolate("There is a mismatch between your NodeJs version {{nodeJsVer}} and your TypeScript target {{compilationTarget}}. This might lead to some unexpected errors when running tests with `ts-jest`. To fix this, you can check https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping", {
674
683
  nodeJsVer: process.version,
675
- compilationTarget: config.compilerOptions.target,
684
+ compilationTarget: (_b = config.compilerOptions.target) !== null && _b !== void 0 ? _b : TARGET_TO_VERSION_MAPPING[compilationTarget],
676
685
  });
677
686
  logger.warn(message);
678
687
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-jest",
3
- "version": "26.1.0",
3
+ "version": "26.1.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "bin": "cli.js",