1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.VersionCheckers = void 0;
|
4 | var semver_1 = require("semver");
|
5 | var get_package_version_1 = require("./get-package-version");
|
6 | var logger_1 = require("./logger");
|
7 | var messages_1 = require("./messages");
|
8 | var logger = logger_1.rootLogger.child({ namespace: 'versions' });
|
9 |
|
10 |
|
11 |
|
12 | exports.VersionCheckers = {
|
13 | jest: createVersionChecker('jest', ">=29.0.0 <30" ),
|
14 | typescript: createVersionChecker('typescript', ">=4.3 <6" ),
|
15 | babelJest: createVersionChecker('babel-jest', ">=29.0.0 <30" ),
|
16 | babelCore: createVersionChecker('@babel/core', ">=7.0.0-beta.0 <8" ),
|
17 | };
|
18 | function checkVersion(name, expectedRange, action) {
|
19 | if (action === void 0) { action = 'warn'; }
|
20 | var success = true;
|
21 | if (!('TS_JEST_DISABLE_VER_CHECKER' in process.env)) {
|
22 | var version = (0, get_package_version_1.getPackageVersion)(name);
|
23 | success = !!version && (0, semver_1.satisfies)(version, expectedRange);
|
24 | logger.debug({
|
25 | actualVersion: version,
|
26 | expectedVersion: expectedRange,
|
27 | }, 'checking version of %s: %s', name, success ? 'OK' : 'NOT OK');
|
28 | if (!action || success)
|
29 | return success;
|
30 | var message = (0, messages_1.interpolate)(version ? "Version {{actualVersion}} of {{module}} installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version ({{expectedVersion}}). Please do not report issues in ts-jest if you are using unsupported versions." : "Module {{module}} is not installed. If you're experiencing issues, consider installing a supported version ({{expectedVersion}})." , {
|
31 | module: name,
|
32 | actualVersion: version || '??',
|
33 | expectedVersion: rangeToHumanString(expectedRange),
|
34 | });
|
35 | if (action === 'warn') {
|
36 | logger.warn(message);
|
37 | }
|
38 | else if (action === 'throw') {
|
39 | logger.fatal(message);
|
40 | throw new RangeError(message);
|
41 | }
|
42 | }
|
43 | return success;
|
44 | }
|
45 | function rangeToHumanString(versionRange) {
|
46 | return new semver_1.Range(versionRange).toString();
|
47 | }
|
48 | function createVersionChecker(moduleName, expectedVersion) {
|
49 | var memo;
|
50 | var warn = function () {
|
51 | if (memo !== undefined)
|
52 | return memo;
|
53 | return (memo = checkVersion(moduleName, expectedVersion, 'warn'));
|
54 | };
|
55 | var raise = function () { return checkVersion(moduleName, expectedVersion, 'throw'); };
|
56 | return {
|
57 | raise: raise,
|
58 | warn: warn,
|
59 | forget: function () {
|
60 | memo = undefined;
|
61 | },
|
62 | };
|
63 | }
|