backports.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. "use strict";
  2. var __assign = (this && this.__assign) || function () {
  3. __assign = Object.assign || function(t) {
  4. for (var s, i = 1, n = arguments.length; i < n; i++) {
  5. s = arguments[i];
  6. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  7. t[p] = s[p];
  8. }
  9. return t;
  10. };
  11. return __assign.apply(this, arguments);
  12. };
  13. var _a;
  14. Object.defineProperty(exports, "__esModule", { value: true });
  15. var bs_logger_1 = require("bs-logger");
  16. var messages_1 = require("./messages");
  17. var context = (_a = {}, _a[bs_logger_1.LogContexts.namespace] = 'backports', _a);
  18. exports.backportJestConfig = function (logger, config) {
  19. logger.debug(__assign(__assign({}, context), { config: config }), 'backporting config');
  20. var _a = (config || {}).globals, globals = _a === void 0 ? {} : _a;
  21. var _b = globals["ts-jest"], tsJest = _b === void 0 ? {} : _b;
  22. var mergeTsJest = {};
  23. var hadWarnings = false;
  24. var warnConfig = function (oldPath, newPath, note) {
  25. hadWarnings = true;
  26. logger.warn(context, messages_1.interpolate(note ? messages_1.Deprecateds.ConfigOptionWithNote : messages_1.Deprecateds.ConfigOption, {
  27. oldPath: oldPath,
  28. newPath: newPath,
  29. note: note,
  30. }));
  31. };
  32. if ('__TS_CONFIG__' in globals) {
  33. warnConfig('globals.__TS_CONFIG__', 'globals.ts-jest.tsConfig');
  34. if (typeof globals.__TS_CONFIG__ === 'object') {
  35. mergeTsJest.tsConfig = globals.__TS_CONFIG__;
  36. }
  37. delete globals.__TS_CONFIG__;
  38. }
  39. if ('__TRANSFORM_HTML__' in globals) {
  40. warnConfig('globals.__TRANSFORM_HTML__', 'globals.ts-jest.stringifyContentPathRegex');
  41. if (globals.__TRANSFORM_HTML__) {
  42. mergeTsJest.stringifyContentPathRegex = '\\.html?$';
  43. }
  44. delete globals.__TRANSFORM_HTML__;
  45. }
  46. if ('typeCheck' in tsJest) {
  47. warnConfig('globals.ts-jest.typeCheck', 'globals.ts-jest.isolatedModules');
  48. mergeTsJest.isolatedModules = !tsJest.typeCheck;
  49. delete tsJest.typeCheck;
  50. }
  51. if ('tsConfigFile' in tsJest) {
  52. warnConfig('globals.ts-jest.tsConfigFile', 'globals.ts-jest.tsConfig');
  53. if (tsJest.tsConfigFile) {
  54. mergeTsJest.tsConfig = tsJest.tsConfigFile;
  55. }
  56. delete tsJest.tsConfigFile;
  57. }
  58. if ('enableTsDiagnostics' in tsJest) {
  59. warnConfig('globals.ts-jest.enableTsDiagnostics', 'globals.ts-jest.diagnostics');
  60. if (tsJest.enableTsDiagnostics) {
  61. mergeTsJest.diagnostics = { warnOnly: true };
  62. if (typeof tsJest.enableTsDiagnostics === 'string')
  63. mergeTsJest.diagnostics.pathRegex = tsJest.enableTsDiagnostics;
  64. }
  65. else {
  66. mergeTsJest.diagnostics = false;
  67. }
  68. delete tsJest.enableTsDiagnostics;
  69. }
  70. if ('useBabelrc' in tsJest) {
  71. warnConfig('globals.ts-jest.useBabelrc', 'globals.ts-jest.babelConfig', messages_1.Deprecateds.ConfigOptionUseBabelRcNote);
  72. if (tsJest.useBabelrc != null) {
  73. mergeTsJest.babelConfig = tsJest.useBabelrc ? true : {};
  74. }
  75. delete tsJest.useBabelrc;
  76. }
  77. if ('skipBabel' in tsJest) {
  78. warnConfig('globals.ts-jest.skipBabel', 'globals.ts-jest.babelConfig');
  79. if (tsJest.skipBabel === false && !mergeTsJest.babelConfig) {
  80. mergeTsJest.babelConfig = true;
  81. }
  82. delete tsJest.skipBabel;
  83. }
  84. if (hadWarnings) {
  85. logger.warn(context, messages_1.Helps.MigrateConfigUsingCLI);
  86. }
  87. return __assign(__assign({}, config), { globals: __assign(__assign({}, globals), { 'ts-jest': __assign(__assign({}, mergeTsJest), tsJest) }) });
  88. };
  89. exports.backportTsJestDebugEnvVar = function (logger) {
  90. if ('TS_JEST_DEBUG' in process.env) {
  91. var shouldLog = !/^\s*(?:0|f(?:alse)?|no?|disabled?|off|)\s*$/i.test(process.env.TS_JEST_DEBUG || '');
  92. delete process.env.TS_JEST_DEBUG;
  93. if (shouldLog) {
  94. process.env.TS_JEST_LOG = "ts-jest.log,stderr:warn";
  95. }
  96. logger.warn(context, messages_1.interpolate(messages_1.Deprecateds.EnvVar, {
  97. old: 'TS_JEST_DEBUG',
  98. new: 'TS_JEST_LOG',
  99. }));
  100. }
  101. };