debug.js 2.6 KB

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