format.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.formatWarnMsg = exports.formatInfoMsg = exports.removeNVueInfoFormatter = exports.formatErrMsg = void 0;
  4. const uni_shared_1 = require("@dcloudio/uni-shared");
  5. const shared_1 = require("@vue/shared");
  6. const env_1 = require("../hbx/env");
  7. const alias_1 = require("../hbx/alias");
  8. const log_1 = require("../hbx/log");
  9. const errFormatters = [];
  10. const infoFormatters = [];
  11. const warnFormatters = [];
  12. const initErrFormattersOnce = (0, uni_shared_1.once)(() => {
  13. if ((0, env_1.isInHBuilderX)()) {
  14. errFormatters.push(alias_1.moduleAliasFormatter);
  15. }
  16. errFormatters.push(log_1.errorFormatter);
  17. });
  18. const initInfoFormattersOnce = (0, uni_shared_1.once)(() => {
  19. if ((0, env_1.runByHBuilderX)()) {
  20. if (
  21. // 开发模式下
  22. process.env.UNI_PLATFORM === 'h5' &&
  23. process.env.NODE_ENV !== 'production') {
  24. infoFormatters.push(log_1.h5ServeFormatter);
  25. }
  26. }
  27. infoFormatters.push(log_1.removeInfoFormatter);
  28. });
  29. const initWarnFormattersOnce = (0, uni_shared_1.once)(() => {
  30. warnFormatters.push(log_1.removeWarnFormatter);
  31. });
  32. function formatErrMsg(msg, options) {
  33. if (options && (0, env_1.isInHBuilderX)()) {
  34. options.timestamp = false;
  35. }
  36. initErrFormattersOnce();
  37. const formatter = errFormatters.find(({ test }) => test(msg, options));
  38. if (formatter) {
  39. return formatter.format(msg, options);
  40. }
  41. return msg;
  42. }
  43. exports.formatErrMsg = formatErrMsg;
  44. const REMOVED_NVUE_MSGS = [
  45. (msg) => {
  46. // vite v2.7.10 building for development... (x2)
  47. return msg.includes('vite v') && msg.includes('building ');
  48. },
  49. ];
  50. exports.removeNVueInfoFormatter = {
  51. test(msg) {
  52. return !!REMOVED_NVUE_MSGS.find((m) => (0, shared_1.isString)(m) ? msg.includes(m) : m(msg));
  53. },
  54. format() {
  55. return '';
  56. },
  57. };
  58. const nvueInfoFormatters = [];
  59. const initNVueInfoFormattersOnce = (0, uni_shared_1.once)(() => {
  60. nvueInfoFormatters.push(exports.removeNVueInfoFormatter);
  61. });
  62. function formatInfoMsg(msg, options) {
  63. if (options && (0, env_1.isInHBuilderX)()) {
  64. options.timestamp = false;
  65. }
  66. initInfoFormattersOnce();
  67. const formatter = infoFormatters.find(({ test }) => test(msg, options));
  68. if (formatter) {
  69. return formatter.format(msg, options);
  70. }
  71. if (options?.nvue) {
  72. initNVueInfoFormattersOnce();
  73. const formatter = nvueInfoFormatters.find(({ test }) => test(msg, options));
  74. if (formatter) {
  75. return formatter.format(msg, options);
  76. }
  77. }
  78. return msg;
  79. }
  80. exports.formatInfoMsg = formatInfoMsg;
  81. function formatWarnMsg(msg, options) {
  82. if (options && (0, env_1.isInHBuilderX)()) {
  83. options.timestamp = false;
  84. }
  85. initWarnFormattersOnce();
  86. const formatter = warnFormatters.find(({ test }) => test(msg, options));
  87. if (formatter) {
  88. return formatter.format(msg, options);
  89. }
  90. return msg;
  91. }
  92. exports.formatWarnMsg = formatWarnMsg;