UNPKG

2.68 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.logUsagePolyfills = exports.logEntryPolyfills = exports.logPluginOrPolyfill = void 0;
7
8function _semver() {
9 const data = _interopRequireDefault(require("semver"));
10
11 _semver = function () {
12 return data;
13 };
14
15 return data;
16}
17
18var _utils = require("./utils");
19
20function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
22const wordEnds = size => {
23 return size > 1 ? "s" : "";
24};
25
26const logPluginOrPolyfill = (item, targetVersions, list) => {
27 const minVersions = list[item] || {};
28 const filteredList = Object.keys(targetVersions).reduce((result, env) => {
29 const minVersion = minVersions[env];
30 const targetVersion = targetVersions[env];
31
32 if (!minVersion) {
33 result[env] = (0, _utils.prettifyVersion)(targetVersion);
34 } else {
35 const minIsUnreleased = (0, _utils.isUnreleasedVersion)(minVersion, env);
36 const targetIsUnreleased = (0, _utils.isUnreleasedVersion)(targetVersion, env);
37
38 if (!targetIsUnreleased && (minIsUnreleased || _semver().default.lt(targetVersion.toString(), (0, _utils.semverify)(minVersion)))) {
39 result[env] = (0, _utils.prettifyVersion)(targetVersion);
40 }
41 }
42
43 return result;
44 }, {});
45 const formattedTargets = JSON.stringify(filteredList).replace(/,/g, ", ").replace(/^\{"/, '{ "').replace(/"\}$/, '" }');
46 console.log(` ${item} ${formattedTargets}`);
47};
48
49exports.logPluginOrPolyfill = logPluginOrPolyfill;
50
51const logEntryPolyfills = (polyfillName, importPolyfillIncluded, polyfills, filename, polyfillTargets, allBuiltInsList) => {
52 if (!importPolyfillIncluded) {
53 console.log(`\n[${filename}] Import of ${polyfillName} was not found.`);
54 return;
55 }
56
57 if (!polyfills.size) {
58 console.log(`\n[${filename}] Based on your targets, polyfills were not added.`);
59 return;
60 }
61
62 console.log(`\n[${filename}] Replaced ${polyfillName} entries with the following polyfill${wordEnds(polyfills.size)}:`);
63
64 for (const polyfill of polyfills) {
65 logPluginOrPolyfill(polyfill, polyfillTargets, allBuiltInsList);
66 }
67};
68
69exports.logEntryPolyfills = logEntryPolyfills;
70
71const logUsagePolyfills = (polyfills, filename, polyfillTargets, allBuiltInsList) => {
72 if (!polyfills.size) {
73 console.log(`\n[${filename}] Based on your code and targets, core-js polyfills were not added.`);
74 return;
75 }
76
77 console.log(`\n[${filename}] Added following core-js polyfill${wordEnds(polyfills.size)}:`);
78
79 for (const polyfill of polyfills) {
80 logPluginOrPolyfill(polyfill, polyfillTargets, allBuiltInsList);
81 }
82};
83
84exports.logUsagePolyfills = logUsagePolyfills;
\No newline at end of file