tap-after-compile-to-get-issues.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. exports.tapAfterCompileToGetIssues = void 0;
  13. const infrastructure_logger_1 = require("../infrastructure-logger");
  14. const issue_webpack_error_1 = require("../issue/issue-webpack-error");
  15. const plugin_hooks_1 = require("../plugin-hooks");
  16. function tapAfterCompileToGetIssues(compiler, config, state) {
  17. const hooks = (0, plugin_hooks_1.getPluginHooks)(compiler);
  18. const { debug } = (0, infrastructure_logger_1.getInfrastructureLogger)(compiler);
  19. compiler.hooks.afterCompile.tapPromise('ForkTsCheckerWebpackPlugin', (compilation) => __awaiter(this, void 0, void 0, function* () {
  20. if (compilation.compiler !== compiler) {
  21. // run only for the compiler that the plugin was registered for
  22. return;
  23. }
  24. let issues = [];
  25. try {
  26. issues = yield state.issuesPromise;
  27. }
  28. catch (error) {
  29. hooks.error.call(error, compilation);
  30. return;
  31. }
  32. debug('Got issues from getIssuesWorker.', issues === null || issues === void 0 ? void 0 : issues.length);
  33. if (!issues) {
  34. // some error has been thrown or it was canceled
  35. return;
  36. }
  37. // filter list of issues by provided issue predicate
  38. issues = issues.filter(config.issue.predicate);
  39. // modify list of issues in the plugin hooks
  40. issues = hooks.issues.call(issues, compilation);
  41. issues.forEach((issue) => {
  42. const error = new issue_webpack_error_1.IssueWebpackError(config.formatter.format(issue), config.formatter.pathType, issue);
  43. if (issue.severity === 'warning') {
  44. compilation.warnings.push(error);
  45. }
  46. else {
  47. compilation.errors.push(error);
  48. }
  49. });
  50. }));
  51. }
  52. exports.tapAfterCompileToGetIssues = tapAfterCompileToGetIssues;