errorHelpers.js 913 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const webpackOptionsFlag = "WEBPACK_OPTIONS";
  7. exports.cutOffByFlag = (stack, flag) => {
  8. stack = stack.split("\n");
  9. for (let i = 0; i < stack.length; i++)
  10. if (stack[i].indexOf(flag) >= 0) stack.length = i;
  11. return stack.join("\n");
  12. };
  13. exports.cutOffWebpackOptions = stack =>
  14. exports.cutOffByFlag(stack, webpackOptionsFlag);
  15. exports.cutOffMultilineMessage = (stack, message) => {
  16. stack = stack.split("\n");
  17. message = message.split("\n");
  18. return stack
  19. .reduce(
  20. (acc, line, idx) =>
  21. line === message[idx] || line === `Error: ${message[idx]}`
  22. ? acc
  23. : acc.concat(line),
  24. []
  25. )
  26. .join("\n");
  27. };
  28. exports.cleanUpWebpackOptions = (stack, message) => {
  29. stack = exports.cutOffWebpackOptions(stack);
  30. stack = exports.cutOffMultilineMessage(stack, message);
  31. return stack;
  32. };