ts-jest 29.3.2 → 29.3.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.
@@ -1,53 +1,36 @@
1
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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
4
  };
41
5
  Object.defineProperty(exports, "__esModule", { value: true });
42
6
  exports.tsTranspileModule = exports.isModernNodeModuleKind = 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';
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const typescript_1 = __importDefault(require("typescript"));
9
+ const messages_1 = require("../../utils/messages");
10
+ const barebonesLibContent = `/// <reference no-default-lib="true"/>
11
+ interface Boolean {}
12
+ interface Function {}
13
+ interface CallableFunction {}
14
+ interface NewableFunction {}
15
+ interface IArguments {}
16
+ interface Number {}
17
+ interface Object {}
18
+ interface RegExp {}
19
+ interface String {}
20
+ interface Array<T> { length: number; [n: number]: T; }
21
+ interface SymbolConstructor {
22
+ (desc?: string | number): symbol;
23
+ for(name: string): symbol;
24
+ readonly toStringTag: symbol;
25
+ }
26
+ declare var Symbol: SymbolConstructor;
27
+ interface Symbol {
28
+ readonly [Symbol.toStringTag]: string;
29
+ }`;
30
+ const barebonesLibName = 'lib.d.ts';
31
+ let barebonesLibSourceFile;
32
+ const carriageReturnLineFeed = '\r\n';
33
+ const lineFeed = '\n';
51
34
  function getNewLineCharacter(options) {
52
35
  switch (options.newLine) {
53
36
  case typescript_1.default.NewLineKind.CarriageReturnLineFeed:
@@ -57,11 +40,11 @@ function getNewLineCharacter(options) {
57
40
  return lineFeed;
58
41
  }
59
42
  }
60
- var isModernNodeModuleKind = function (module) {
43
+ const isModernNodeModuleKind = (module) => {
61
44
  return module ? [typescript_1.default.ModuleKind.Node16, /* ModuleKind.Node18 */ 101, typescript_1.default.ModuleKind.NodeNext].includes(module) : false;
62
45
  };
63
46
  exports.isModernNodeModuleKind = isModernNodeModuleKind;
64
- var shouldCheckProjectPkgJsonContent = function (fileName, moduleKind) {
47
+ const shouldCheckProjectPkgJsonContent = (fileName, moduleKind) => {
65
48
  return fileName.endsWith('package.json') && (0, exports.isModernNodeModuleKind)(moduleKind);
66
49
  };
67
50
  /**
@@ -70,41 +53,29 @@ var shouldCheckProjectPkgJsonContent = function (fileName, moduleKind) {
70
53
  * - Remove generation of declaration files
71
54
  * - Allow using custom AST transformers with the internal created {@link Program}
72
55
  */
73
- var transpileWorker = function (input, transpileOptions) {
74
- var e_1, _a;
75
- var _b, _c, _d, _e, _f;
76
- barebonesLibSourceFile !== null && barebonesLibSourceFile !== void 0 ? barebonesLibSourceFile : (barebonesLibSourceFile = typescript_1.default.createSourceFile(barebonesLibName, barebonesLibContent, {
56
+ const transpileWorker = (input, transpileOptions) => {
57
+ barebonesLibSourceFile ??= typescript_1.default.createSourceFile(barebonesLibName, barebonesLibContent, {
77
58
  languageVersion: typescript_1.default.ScriptTarget.Latest,
78
- }));
79
- var diagnostics = [];
80
- var options = transpileOptions.compilerOptions
59
+ });
60
+ const diagnostics = [];
61
+ const options = transpileOptions.compilerOptions
81
62
  ? // @ts-expect-error internal TypeScript API
82
63
  typescript_1.default.fixupCompilerOptions(transpileOptions.compilerOptions, diagnostics)
83
64
  : {};
84
65
  // mix in default options
85
- var defaultOptions = typescript_1.default.getDefaultCompilerOptions();
86
- for (var key in defaultOptions) {
66
+ const defaultOptions = typescript_1.default.getDefaultCompilerOptions();
67
+ for (const key in defaultOptions) {
87
68
  if (Object.hasOwn(defaultOptions, key) && options[key] === undefined) {
88
69
  options[key] = defaultOptions[key];
89
70
  }
90
71
  }
91
- try {
92
- // @ts-expect-error internal TypeScript API
93
- for (var _g = __values(typescript_1.default.transpileOptionValueCompilerOptions), _h = _g.next(); !_h.done; _h = _g.next()) {
94
- var option = _h.value;
95
- // Do not set redundant config options if `verbatimModuleSyntax` was supplied.
96
- if (options.verbatimModuleSyntax && new Set(['isolatedModules']).has(option.name)) {
97
- continue;
98
- }
99
- options[option.name] = option.transpileOptionValue;
100
- }
101
- }
102
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
103
- finally {
104
- try {
105
- if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
72
+ // @ts-expect-error internal TypeScript API
73
+ for (const option of typescript_1.default.transpileOptionValueCompilerOptions) {
74
+ // Do not set redundant config options if `verbatimModuleSyntax` was supplied.
75
+ if (options.verbatimModuleSyntax && new Set(['isolatedModules']).has(option.name)) {
76
+ continue;
106
77
  }
107
- finally { if (e_1) throw e_1.error; }
78
+ options[option.name] = option.transpileOptionValue;
108
79
  }
109
80
  // transpileModule does not write anything to disk so there is no need to verify that there are no conflicts between input and output paths.
110
81
  options.suppressOutputPathCheck = true;
@@ -112,12 +83,12 @@ var transpileWorker = function (input, transpileOptions) {
112
83
  options.allowNonTsExtensions = true;
113
84
  options.declaration = false;
114
85
  options.declarationMap = false;
115
- var newLine = getNewLineCharacter(options);
86
+ const newLine = getNewLineCharacter(options);
116
87
  // if jsx is specified then treat file as .tsx
117
- 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');
88
+ const inputFileName = transpileOptions.fileName ?? (transpileOptions.compilerOptions?.jsx ? 'module.tsx' : 'module.ts');
118
89
  // Create a compilerHost object to allow the compiler to read and write files
119
- var compilerHost = {
120
- getSourceFile: function (fileName) {
90
+ const compilerHost = {
91
+ getSourceFile: (fileName) => {
121
92
  // @ts-expect-error internal TypeScript API
122
93
  if (fileName === typescript_1.default.normalizePath(inputFileName)) {
123
94
  return sourceFile;
@@ -125,7 +96,7 @@ var transpileWorker = function (input, transpileOptions) {
125
96
  // @ts-expect-error internal TypeScript API
126
97
  return fileName === typescript_1.default.normalizePath(barebonesLibName) ? barebonesLibSourceFile : undefined;
127
98
  },
128
- writeFile: function (name, text) {
99
+ writeFile: (name, text) => {
129
100
  if (node_path_1.default.extname(name) === '.map') {
130
101
  sourceMapText = text;
131
102
  }
@@ -133,33 +104,33 @@ var transpileWorker = function (input, transpileOptions) {
133
104
  outputText = text;
134
105
  }
135
106
  },
136
- getDefaultLibFileName: function () { return barebonesLibName; },
137
- useCaseSensitiveFileNames: function () { return false; },
138
- getCanonicalFileName: function (fileName) { return fileName; },
139
- getCurrentDirectory: function () { return ''; },
140
- getNewLine: function () { return newLine; },
141
- fileExists: function (fileName) {
107
+ getDefaultLibFileName: () => barebonesLibName,
108
+ useCaseSensitiveFileNames: () => false,
109
+ getCanonicalFileName: (fileName) => fileName,
110
+ getCurrentDirectory: () => '',
111
+ getNewLine: () => newLine,
112
+ fileExists: (fileName) => {
142
113
  if (shouldCheckProjectPkgJsonContent(fileName, options.module)) {
143
114
  return typescript_1.default.sys.fileExists(fileName);
144
115
  }
145
116
  return fileName === inputFileName;
146
117
  },
147
- readFile: function (fileName) {
118
+ readFile: (fileName) => {
148
119
  if (shouldCheckProjectPkgJsonContent(fileName, options.module)) {
149
120
  return typescript_1.default.sys.readFile(fileName);
150
121
  }
151
122
  return '';
152
123
  },
153
- directoryExists: function () { return true; },
154
- getDirectories: function () { return []; },
124
+ directoryExists: () => true,
125
+ getDirectories: () => [],
155
126
  };
156
- var sourceFile = typescript_1.default.createSourceFile(inputFileName, input, {
157
- languageVersion: (_d = options.target) !== null && _d !== void 0 ? _d : typescript_1.default.ScriptTarget.ESNext,
127
+ const sourceFile = typescript_1.default.createSourceFile(inputFileName, input, {
128
+ languageVersion: options.target ?? typescript_1.default.ScriptTarget.ESNext,
158
129
  impliedNodeFormat: typescript_1.default.getImpliedNodeFormatForFile(inputFileName,
159
130
  /*packageJsonInfoCache*/ undefined, compilerHost, options),
160
131
  // @ts-expect-error internal TypeScript API
161
132
  setExternalModuleIndicator: typescript_1.default.getSetExternalModuleIndicator(options),
162
- jsDocParsingMode: (_e = transpileOptions.jsDocParsingMode) !== null && _e !== void 0 ? _e : typescript_1.default.JSDocParsingMode.ParseAll,
133
+ jsDocParsingMode: transpileOptions.jsDocParsingMode ?? typescript_1.default.JSDocParsingMode.ParseAll,
163
134
  });
164
135
  if (transpileOptions.moduleName) {
165
136
  sourceFile.moduleName = transpileOptions.moduleName;
@@ -169,21 +140,21 @@ var transpileWorker = function (input, transpileOptions) {
169
140
  sourceFile.renamedDependencies = new Map(Object.entries(transpileOptions.renamedDependencies));
170
141
  }
171
142
  // Output
172
- var outputText;
173
- var sourceMapText;
174
- var inputs = [inputFileName];
175
- var program = typescript_1.default.createProgram(inputs, options, compilerHost);
143
+ let outputText;
144
+ let sourceMapText;
145
+ const inputs = [inputFileName];
146
+ const program = typescript_1.default.createProgram(inputs, options, compilerHost);
176
147
  if (transpileOptions.reportDiagnostics) {
177
- diagnostics.push.apply(diagnostics, __spreadArray([], __read(program.getSyntacticDiagnostics(sourceFile)), false));
148
+ diagnostics.push(...program.getSyntacticDiagnostics(sourceFile));
178
149
  }
179
- diagnostics.push.apply(diagnostics, __spreadArray([], __read(program.getOptionsDiagnostics()), false));
150
+ diagnostics.push(...program.getOptionsDiagnostics());
180
151
  // Emit
181
- var result = program.emit(
152
+ const result = program.emit(
182
153
  /*targetSourceFile*/ undefined,
183
154
  /*writeFile*/ undefined,
184
155
  /*cancellationToken*/ undefined,
185
- /*emitOnlyDtsFiles*/ undefined, (_f = transpileOptions.transformers) === null || _f === void 0 ? void 0 : _f.call(transpileOptions, program));
186
- diagnostics.push.apply(diagnostics, __spreadArray([], __read(result.diagnostics), false));
156
+ /*emitOnlyDtsFiles*/ undefined, transpileOptions.transformers?.(program));
157
+ diagnostics.push(...result.diagnostics);
187
158
  if (outputText === undefined) {
188
159
  diagnostics.push({
189
160
  category: typescript_1.default.DiagnosticCategory.Error,
@@ -194,6 +165,6 @@ var transpileWorker = function (input, transpileOptions) {
194
165
  length: 0,
195
166
  });
196
167
  }
197
- return { outputText: outputText !== null && outputText !== void 0 ? outputText : '', diagnostics: diagnostics, sourceMapText: sourceMapText };
168
+ return { outputText: outputText ?? '', diagnostics, sourceMapText };
198
169
  };
199
170
  exports.tsTranspileModule = transpileWorker;
package/dist/types.js CHANGED
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var constants_1 = require("./constants");
3
+ const constants_1 = require("./constants");
@@ -1,38 +1,26 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
15
3
  exports.backportTsJestDebugEnvVar = exports.backportJestConfig = void 0;
16
- var bs_logger_1 = require("bs-logger");
17
- var messages_1 = require("./messages");
18
- var context = (_a = {}, _a[bs_logger_1.LogContexts.namespace] = 'backports', _a);
4
+ const bs_logger_1 = require("bs-logger");
5
+ const messages_1 = require("./messages");
6
+ const context = { [bs_logger_1.LogContexts.namespace]: 'backports' };
19
7
  /**
20
8
  * @internal
21
9
  */
22
- var backportJestConfig = function (logger, config) {
23
- logger.debug(__assign(__assign({}, context), { config: config }), 'backporting config');
10
+ const backportJestConfig = (logger, config) => {
11
+ logger.debug({ ...context, config }, 'backporting config');
24
12
  // 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;
13
+ const { globals = {} } = (config || {});
14
+ const { 'ts-jest': tsJest = {} } = globals;
27
15
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
- var mergeTsJest = {};
29
- var hadWarnings = false;
30
- var warnConfig = function (oldPath, newPath, note) {
16
+ const mergeTsJest = {};
17
+ let hadWarnings = false;
18
+ const warnConfig = (oldPath, newPath, note) => {
31
19
  hadWarnings = true;
32
20
  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,
21
+ oldPath,
22
+ newPath,
23
+ note,
36
24
  }));
37
25
  };
38
26
  if ('__TS_CONFIG__' in globals) {
@@ -98,15 +86,25 @@ var backportJestConfig = function (logger, config) {
98
86
  if (hadWarnings) {
99
87
  logger.warn(context, "Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate <config-file>." /* Helps.MigrateConfigUsingCLI */);
100
88
  }
101
- return __assign(__assign({}, config), { globals: __assign(__assign({}, globals), { 'ts-jest': __assign(__assign({}, mergeTsJest), tsJest) }) });
89
+ return {
90
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
91
+ ...config,
92
+ globals: {
93
+ ...globals,
94
+ 'ts-jest': {
95
+ ...mergeTsJest,
96
+ ...tsJest,
97
+ },
98
+ },
99
+ };
102
100
  };
103
101
  exports.backportJestConfig = backportJestConfig;
104
102
  /**
105
103
  * @internal
106
104
  */
107
- var backportTsJestDebugEnvVar = function (logger) {
105
+ const backportTsJestDebugEnvVar = (logger) => {
108
106
  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 || '');
107
+ const shouldLog = !/^\s*(?:0|f(?:alse)?|no?|disabled?|off|)\s*$/i.test(process.env.TS_JEST_DEBUG || '');
110
108
  delete process.env.TS_JEST_DEBUG;
111
109
  if (shouldLog) {
112
110
  process.env.TS_JEST_LOG = 'ts-jest.log,stderr:warn';
@@ -6,9 +6,9 @@ exports.getPackageVersion = getPackageVersion;
6
6
  */
7
7
  function getPackageVersion(moduleName) {
8
8
  try {
9
- return require("".concat(moduleName, "/package.json")).version;
9
+ return require(`${moduleName}/package.json`).version;
10
10
  }
11
- catch (_a) {
11
+ catch {
12
12
  return undefined;
13
13
  }
14
14
  }
@@ -1,98 +1,52 @@
1
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
2
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
14
3
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
15
4
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
16
5
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
17
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
18
7
  };
19
- var __read = (this && this.__read) || function (o, n) {
20
- var m = typeof Symbol === "function" && o[Symbol.iterator];
21
- if (!m) return o;
22
- var i = m.call(o), r, ar = [], e;
23
- try {
24
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
25
- }
26
- catch (error) { e = { error: error }; }
27
- finally {
28
- try {
29
- if (r && !r.done && (m = i["return"])) m.call(i);
30
- }
31
- finally { if (e) throw e.error; }
32
- }
33
- return ar;
34
- };
35
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
36
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
37
- if (ar || !(i in from)) {
38
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
39
- ar[i] = from[i];
40
- }
41
- }
42
- return to.concat(ar || Array.prototype.slice.call(from));
43
- };
44
8
  Object.defineProperty(exports, "__esModule", { value: true });
45
9
  exports.importer = exports.Importer = void 0;
46
10
  exports.__requireModule = __requireModule;
47
- var logger_1 = require("./logger");
48
- var memoize_1 = require("./memoize");
49
- var messages_1 = require("./messages");
50
- var logger = logger_1.rootLogger.child({ namespace: 'Importer' });
11
+ const logger_1 = require("./logger");
12
+ const memoize_1 = require("./memoize");
13
+ const messages_1 = require("./messages");
14
+ const logger = logger_1.rootLogger.child({ namespace: 'Importer' });
51
15
  /**
52
16
  * @internal
53
17
  */
54
- var Importer = /** @class */ (function () {
55
- function Importer() {
18
+ class Importer {
19
+ static get instance() {
20
+ logger.debug('creating Importer singleton');
21
+ return new Importer();
56
22
  }
57
- Object.defineProperty(Importer, "instance", {
58
- get: function () {
59
- logger.debug('creating Importer singleton');
60
- return new Importer();
61
- },
62
- enumerable: false,
63
- configurable: true
64
- });
65
- Importer.prototype.babelJest = function (why) {
23
+ babelJest(why) {
66
24
  return this._import(why, 'babel-jest');
67
- };
68
- Importer.prototype.babelCore = function (why) {
25
+ }
26
+ babelCore(why) {
69
27
  return this._import(why, '@babel/core');
70
- };
71
- Importer.prototype.typescript = function (why, which) {
28
+ }
29
+ typescript(why, which) {
72
30
  return this._import(why, which);
73
- };
74
- Importer.prototype.esBuild = function (why) {
31
+ }
32
+ esBuild(why) {
75
33
  return this._import(why, 'esbuild');
76
- };
77
- Importer.prototype.tryThese = function (moduleName) {
78
- var fallbacks = [];
79
- for (var _i = 1; _i < arguments.length; _i++) {
80
- fallbacks[_i - 1] = arguments[_i];
81
- }
82
- var name;
83
- var loaded;
84
- var tries = __spreadArray([moduleName], __read(fallbacks), false);
34
+ }
35
+ tryThese(moduleName, ...fallbacks) {
36
+ let name;
37
+ let loaded;
38
+ const tries = [moduleName, ...fallbacks];
85
39
  while ((name = tries.shift()) !== undefined) {
86
- var req = requireWrapper(name);
40
+ const req = requireWrapper(name);
87
41
  // remove exports from what we're going to log
88
42
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
- var contextReq = __assign({}, req);
43
+ const contextReq = { ...req };
90
44
  delete contextReq.exports;
91
45
  if (req.exists) {
92
46
  // module exists
93
47
  loaded = req;
94
48
  if (req.error) {
95
- logger.error({ requireResult: contextReq }, "failed loading module '".concat(name, "'"), req.error.message);
49
+ logger.error({ requireResult: contextReq }, `failed loading module '${name}'`, req.error.message);
96
50
  }
97
51
  else {
98
52
  logger.debug({ requireResult: contextReq }, 'loaded module', name);
@@ -101,17 +55,16 @@ var Importer = /** @class */ (function () {
101
55
  }
102
56
  else {
103
57
  // module does not exists in the path
104
- logger.debug({ requireResult: contextReq }, "module '".concat(name, "' not found"));
58
+ logger.debug({ requireResult: contextReq }, `module '${name}' not found`);
105
59
  }
106
60
  }
107
61
  // return the loaded one, could be one that has been loaded, or one which has failed during load
108
62
  // but not one which does not exists
109
63
  return loaded;
110
- };
111
- Importer.prototype.tryTheseOr = function (moduleNames, missingResult, allowLoadError) {
112
- if (allowLoadError === void 0) { allowLoadError = false; }
113
- var args = Array.isArray(moduleNames) ? moduleNames : [moduleNames];
114
- var result = this.tryThese.apply(this, __spreadArray([], __read(args), false));
64
+ }
65
+ tryTheseOr(moduleNames, missingResult, allowLoadError = false) {
66
+ const args = Array.isArray(moduleNames) ? moduleNames : [moduleNames];
67
+ const result = this.tryThese(...args);
115
68
  if (!result)
116
69
  return missingResult;
117
70
  if (!result.error)
@@ -119,67 +72,59 @@ var Importer = /** @class */ (function () {
119
72
  if (allowLoadError)
120
73
  return missingResult;
121
74
  throw result.error;
122
- };
123
- Importer.prototype._import = function (why, moduleName, _a) {
124
- var _b = _a === void 0 ? {} : _a, _c = _b.alternatives, alternatives = _c === void 0 ? [] : _c, _d = _b.installTip, installTip = _d === void 0 ? moduleName : _d;
75
+ }
76
+ _import(why, moduleName, { alternatives = [], installTip = moduleName } = {}) {
125
77
  // try to load any of the alternative after trying main one
126
- var res = this.tryThese.apply(this, __spreadArray([moduleName], __read(alternatives), false));
78
+ const res = this.tryThese(moduleName, ...alternatives);
127
79
  // if we could load one, return it
128
- if (res === null || res === void 0 ? void 0 : res.exists) {
80
+ if (res?.exists) {
129
81
  if (!res.error)
130
82
  return res.exports;
131
83
  // it could not load because of a failure while importing, but it exists
132
84
  throw new Error((0, messages_1.interpolate)("Loading module {{module}} failed with error: {{error}}" /* Errors.LoadingModuleFailed */, { module: res.given, error: res.error.message }));
133
85
  }
134
86
  // if it couldn't load, build a nice error message so the user can fix it by himself
135
- var msg = alternatives.length ? "Unable to load any of these modules: {{module}}. {{reason}}. To fix it:\n{{fix}}" /* Errors.UnableToLoadAnyModule */ : "Unable to load the module {{module}}. {{reason}} To fix it:\n{{fix}}" /* Errors.UnableToLoadOneModule */;
136
- var loadModule = __spreadArray([moduleName], __read(alternatives), false).map(function (m) { return "\"".concat(m, "\""); }).join(', ');
87
+ const msg = alternatives.length ? "Unable to load any of these modules: {{module}}. {{reason}}. To fix it:\n{{fix}}" /* Errors.UnableToLoadAnyModule */ : "Unable to load the module {{module}}. {{reason}} To fix it:\n{{fix}}" /* Errors.UnableToLoadOneModule */;
88
+ const loadModule = [moduleName, ...alternatives].map((m) => `"${m}"`).join(', ');
137
89
  if (typeof installTip === 'string') {
138
- installTip = [{ module: installTip, label: "install \"".concat(installTip, "\"") }];
90
+ installTip = [{ module: installTip, label: `install "${installTip}"` }];
139
91
  }
140
- var fix = installTip
141
- .map(function (tip) { return " ".concat(installTip.length === 1 ? '↳' : '•', " ").concat((0, messages_1.interpolate)("{{label}}: `npm i -D {{module}}` (or `yarn add --dev {{module}}`)" /* Helps.FixMissingModule */, tip)); })
92
+ const fix = installTip
93
+ .map((tip) => ` ${installTip.length === 1 ? '↳' : '•'} ${(0, messages_1.interpolate)("{{label}}: `npm i -D {{module}}` (or `yarn add --dev {{module}}`)" /* Helps.FixMissingModule */, tip)}`)
142
94
  .join('\n');
143
95
  throw new Error((0, messages_1.interpolate)(msg, {
144
96
  module: loadModule,
145
97
  reason: why,
146
- fix: fix,
98
+ fix,
147
99
  }));
148
- };
149
- __decorate([
150
- (0, memoize_1.Memoize)(function () {
151
- var args = [];
152
- for (var _i = 0; _i < arguments.length; _i++) {
153
- args[_i] = arguments[_i];
154
- }
155
- return args.join(':');
156
- })
157
- ], Importer.prototype, "tryThese", null);
158
- __decorate([
159
- (0, memoize_1.Memoize)()
160
- ], Importer, "instance", null);
161
- return Importer;
162
- }());
100
+ }
101
+ }
163
102
  exports.Importer = Importer;
103
+ __decorate([
104
+ (0, memoize_1.Memoize)((...args) => args.join(':'))
105
+ ], Importer.prototype, "tryThese", null);
106
+ __decorate([
107
+ (0, memoize_1.Memoize)()
108
+ ], Importer, "instance", null);
164
109
  /**
165
110
  * @internal
166
111
  */
167
112
  exports.importer = Importer.instance;
168
113
  function requireWrapper(moduleName) {
169
- var path;
170
- var exists = false;
114
+ let path;
115
+ let exists = false;
171
116
  try {
172
117
  path = resolveModule(moduleName);
173
118
  exists = true;
174
119
  }
175
120
  catch (error) {
176
- return { error: error, exists: exists, given: moduleName };
121
+ return { error: error, exists, given: moduleName };
177
122
  }
178
- var result = { exists: exists, path: path, given: moduleName };
123
+ const result = { exists, path, given: moduleName };
179
124
  try {
180
125
  result.exports = requireModule(path);
181
126
  }
182
- catch (_a) {
127
+ catch {
183
128
  try {
184
129
  result.exports = requireModule(moduleName);
185
130
  }
@@ -189,8 +134,8 @@ function requireWrapper(moduleName) {
189
134
  }
190
135
  return result;
191
136
  }
192
- var requireModule = function (mod) { return require(mod); };
193
- var resolveModule = function (mod) { return require.resolve(mod, { paths: [process.cwd(), __dirname] }); };
137
+ let requireModule = (mod) => require(mod);
138
+ let resolveModule = (mod) => require.resolve(mod, { paths: [process.cwd(), __dirname] });
194
139
  /**
195
140
  * @internal
196
141
  */
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.stringify = stringify;
7
7
  exports.parse = parse;
8
- var fast_json_stable_stringify_1 = __importDefault(require("fast-json-stable-stringify"));
9
- var UNDEFINED = 'undefined';
8
+ const fast_json_stable_stringify_1 = __importDefault(require("fast-json-stable-stringify"));
9
+ const UNDEFINED = 'undefined';
10
10
  function stringify(input) {
11
11
  return input === undefined ? UNDEFINED : (0, fast_json_stable_stringify_1.default)(input);
12
12
  }