debug.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.logUsagePolyfills = exports.logEntryPolyfills = exports.logPlugin = exports.logMessage = 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 logMessage = (message, context) => {
  19. const pre = context ? `[${context}] ` : "";
  20. const logStr = ` ${pre}${message}`;
  21. console.log(logStr);
  22. };
  23. exports.logMessage = logMessage;
  24. const logPlugin = (item, targetVersions, list, context) => {
  25. const minVersions = list[item] || {};
  26. const filteredList = Object.keys(targetVersions).reduce((result, env) => {
  27. const minVersion = minVersions[env];
  28. const targetVersion = targetVersions[env];
  29. if (!minVersion) {
  30. result[env] = (0, _utils.prettifyVersion)(targetVersion);
  31. } else {
  32. const minIsUnreleased = (0, _utils.isUnreleasedVersion)(minVersion, env);
  33. const targetIsUnreleased = (0, _utils.isUnreleasedVersion)(targetVersion, env);
  34. if (!targetIsUnreleased && (minIsUnreleased || _semver().default.lt(targetVersion, (0, _utils.semverify)(minVersion)))) {
  35. result[env] = (0, _utils.prettifyVersion)(targetVersion);
  36. }
  37. }
  38. return result;
  39. }, {});
  40. const formattedTargets = JSON.stringify(filteredList).replace(/,/g, ", ").replace(/^\{"/, '{ "').replace(/"\}$/, '" }');
  41. logMessage(`${item} ${formattedTargets}`, context);
  42. };
  43. exports.logPlugin = logPlugin;
  44. const logEntryPolyfills = (importPolyfillIncluded, polyfills, filename, onDebug) => {
  45. if (!importPolyfillIncluded) {
  46. console.log(`
  47. [${filename}] \`import '@babel/polyfill'\` was not found.`);
  48. return;
  49. }
  50. if (!polyfills.size) {
  51. console.log(`
  52. [${filename}] Based on your targets, none were added.`);
  53. return;
  54. }
  55. console.log(`
  56. [${filename}] Replaced \`@babel/polyfill\` with the following polyfill${wordEnds(polyfills.size)}:`);
  57. onDebug(polyfills);
  58. };
  59. exports.logEntryPolyfills = logEntryPolyfills;
  60. const logUsagePolyfills = (polyfills, filename, onDebug) => {
  61. if (!polyfills.size) {
  62. console.log(`
  63. [${filename}] Based on your code and targets, none were added.`);
  64. return;
  65. }
  66. console.log(`
  67. [${filename}] Added following polyfill${wordEnds(polyfills.size)}:`);
  68. onDebug(polyfills);
  69. };
  70. exports.logUsagePolyfills = logUsagePolyfills;