You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.7 KiB

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