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.

33 lines
911 B

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