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