issue-webpack-error.js 1.6 KB

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.IssueWebpackError = void 0;
  7. const path_1 = __importDefault(require("path"));
  8. const chalk_1 = __importDefault(require("chalk"));
  9. const webpack_1 = __importDefault(require("webpack"));
  10. const forward_slash_1 = require("../utils/path/forward-slash");
  11. const relative_to_context_1 = require("../utils/path/relative-to-context");
  12. const issue_location_1 = require("./issue-location");
  13. class IssueWebpackError extends webpack_1.default.WebpackError {
  14. constructor(message, pathType, issue) {
  15. super(message);
  16. this.issue = issue;
  17. this.hideStack = true;
  18. // to display issue location using `loc` property, webpack requires `error.module` which
  19. // should be a NormalModule instance.
  20. // to avoid such a dependency, we do a workaround - error.file will contain formatted location instead
  21. if (issue.file) {
  22. this.file =
  23. pathType === 'absolute'
  24. ? (0, forward_slash_1.forwardSlash)(path_1.default.resolve(issue.file))
  25. : (0, relative_to_context_1.relativeToContext)(issue.file, process.cwd());
  26. if (issue.location) {
  27. this.file += `:${chalk_1.default.green.bold((0, issue_location_1.formatIssueLocation)(issue.location))}`;
  28. }
  29. }
  30. Error.captureStackTrace(this, this.constructor);
  31. }
  32. }
  33. exports.IssueWebpackError = IssueWebpackError;