UNPKG

5.36 kBJavaScriptView Raw
1"use strict";
2var __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};
13var _a;
14Object.defineProperty(exports, "__esModule", { value: true });
15exports.backportTsJestDebugEnvVar = exports.backportJestConfig = void 0;
16var bs_logger_1 = require("bs-logger");
17var messages_1 = require("./messages");
18var context = (_a = {}, _a[bs_logger_1.LogContexts.namespace] = 'backports', _a);
19/**
20 * @internal
21 */
22var backportJestConfig = function (logger, config) {
23 logger.debug(__assign(__assign({}, context), { config: config }), 'backporting config');
24 // eslint-disable-next-line @typescript-eslint/no-explicit-any
25 var _a = (config || {}).globals, globals = _a === void 0 ? {} : _a;
26 var _b = globals["ts-jest"], tsJest = _b === void 0 ? {} : _b;
27 // eslint-disable-next-line @typescript-eslint/no-explicit-any
28 var mergeTsJest = {};
29 var hadWarnings = false;
30 var warnConfig = function (oldPath, newPath, note) {
31 hadWarnings = true;
32 logger.warn(context, (0, messages_1.interpolate)(note ? "\"[jest-config].{{oldPath}}\" is deprecated, use \"[jest-config].{{newPath}}\" instead.\n \u21B3 {{note}}" /* Deprecations.ConfigOptionWithNote */ : "\"[jest-config].{{oldPath}}\" is deprecated, use \"[jest-config].{{newPath}}\" instead." /* Deprecations.ConfigOption */, {
33 oldPath: oldPath,
34 newPath: newPath,
35 note: note,
36 }));
37 };
38 if ('__TS_CONFIG__' in globals) {
39 warnConfig('globals.__TS_CONFIG__', 'globals.ts-jest.tsconfig');
40 if (typeof globals.__TS_CONFIG__ === 'object') {
41 mergeTsJest.tsconfig = globals.__TS_CONFIG__;
42 }
43 delete globals.__TS_CONFIG__;
44 }
45 if ('__TRANSFORM_HTML__' in globals) {
46 warnConfig('globals.__TRANSFORM_HTML__', 'globals.ts-jest.stringifyContentPathRegex');
47 if (globals.__TRANSFORM_HTML__) {
48 mergeTsJest.stringifyContentPathRegex = '\\.html?$';
49 }
50 delete globals.__TRANSFORM_HTML__;
51 }
52 if ('typeCheck' in tsJest) {
53 warnConfig('globals.ts-jest.typeCheck', 'globals.ts-jest.isolatedModules');
54 mergeTsJest.isolatedModules = !tsJest.typeCheck;
55 delete tsJest.typeCheck;
56 }
57 if ('tsConfigFile' in tsJest) {
58 warnConfig('globals.ts-jest.tsConfigFile', 'globals.ts-jest.tsconfig');
59 if (tsJest.tsConfigFile) {
60 mergeTsJest.tsconfig = tsJest.tsConfigFile;
61 }
62 delete tsJest.tsConfigFile;
63 }
64 if ('tsConfig' in tsJest) {
65 warnConfig('globals.ts-jest.tsConfig', 'globals.ts-jest.tsconfig');
66 if (tsJest.tsConfig) {
67 mergeTsJest.tsconfig = tsJest.tsConfig;
68 }
69 delete tsJest.tsConfig;
70 }
71 if ('enableTsDiagnostics' in tsJest) {
72 warnConfig('globals.ts-jest.enableTsDiagnostics', 'globals.ts-jest.diagnostics');
73 if (tsJest.enableTsDiagnostics) {
74 mergeTsJest.diagnostics = { warnOnly: true };
75 if (typeof tsJest.enableTsDiagnostics === 'string')
76 mergeTsJest.diagnostics.exclude = [tsJest.enableTsDiagnostics];
77 }
78 else {
79 mergeTsJest.diagnostics = false;
80 }
81 delete tsJest.enableTsDiagnostics;
82 }
83 if ('useBabelrc' in tsJest) {
84 warnConfig('globals.ts-jest.useBabelrc', 'globals.ts-jest.babelConfig', "See `babel-jest` related issue: https://github.com/facebook/jest/issues/3845" /* Deprecations.ConfigOptionUseBabelRcNote */);
85 if (tsJest.useBabelrc != null) {
86 mergeTsJest.babelConfig = tsJest.useBabelrc ? true : {};
87 }
88 delete tsJest.useBabelrc;
89 }
90 if ('skipBabel' in tsJest) {
91 warnConfig('globals.ts-jest.skipBabel', 'globals.ts-jest.babelConfig');
92 if (tsJest.skipBabel === false && !mergeTsJest.babelConfig) {
93 mergeTsJest.babelConfig = true;
94 }
95 delete tsJest.skipBabel;
96 }
97 // if we had some warnings we can inform the user about the CLI tool
98 if (hadWarnings) {
99 logger.warn(context, "Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate <config-file>." /* Helps.MigrateConfigUsingCLI */);
100 }
101 return __assign(__assign({}, config), { globals: __assign(__assign({}, globals), { 'ts-jest': __assign(__assign({}, mergeTsJest), tsJest) }) });
102};
103exports.backportJestConfig = backportJestConfig;
104/**
105 * @internal
106 */
107var backportTsJestDebugEnvVar = function (logger) {
108 if ('TS_JEST_DEBUG' in process.env) {
109 var shouldLog = !/^\s*(?:0|f(?:alse)?|no?|disabled?|off|)\s*$/i.test(process.env.TS_JEST_DEBUG || '');
110 delete process.env.TS_JEST_DEBUG;
111 if (shouldLog) {
112 process.env.TS_JEST_LOG = 'ts-jest.log,stderr:warn';
113 }
114 logger.warn(context, (0, messages_1.interpolate)("Using env. var \"{{old}}\" is deprecated, use \"{{new}}\" instead." /* Deprecations.EnvVar */, {
115 old: 'TS_JEST_DEBUG',
116 new: 'TS_JEST_LOG',
117 }));
118 }
119};
120exports.backportTsJestDebugEnvVar = backportTsJestDebugEnvVar;