tapAfterCompileToGetIssues.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  3. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  4. return new (P || (P = Promise))(function (resolve, reject) {
  5. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  6. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  7. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  8. step((generator = generator.apply(thisArg, _arguments || [])).next());
  9. });
  10. };
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. const pluginHooks_1 = require("./pluginHooks");
  13. const IssueWebpackError_1 = require("../issue/IssueWebpackError");
  14. function tapAfterCompileToGetIssues(compiler, configuration, state) {
  15. const hooks = pluginHooks_1.getForkTsCheckerWebpackPluginHooks(compiler);
  16. compiler.hooks.afterCompile.tapPromise('ForkTsCheckerWebpackPlugin', (compilation) => __awaiter(this, void 0, void 0, function* () {
  17. if (compilation.compiler !== compiler) {
  18. // run only for the compiler that the plugin was registered for
  19. return;
  20. }
  21. let issues = [];
  22. try {
  23. issues = yield state.issuesPromise;
  24. }
  25. catch (error) {
  26. hooks.error.call(error, compilation);
  27. return;
  28. }
  29. if (!issues) {
  30. // some error has been thrown or it was canceled
  31. return;
  32. }
  33. // filter list of issues by provided issue predicate
  34. issues = issues.filter(configuration.issue.predicate);
  35. // modify list of issues in the plugin hooks
  36. issues = hooks.issues.call(issues, compilation);
  37. issues.forEach((issue) => {
  38. const error = new IssueWebpackError_1.IssueWebpackError(configuration.formatter(issue), issue);
  39. if (issue.severity === 'warning') {
  40. compilation.warnings.push(error);
  41. }
  42. else {
  43. compilation.errors.push(error);
  44. }
  45. });
  46. }));
  47. }
  48. exports.tapAfterCompileToGetIssues = tapAfterCompileToGetIssues;