tap-done-to-async-get-issues.js 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. var __importDefault = (this && this.__importDefault) || function (mod) {
  12. return (mod && mod.__esModule) ? mod : { "default": mod };
  13. };
  14. Object.defineProperty(exports, "__esModule", { value: true });
  15. exports.tapDoneToAsyncGetIssues = void 0;
  16. const chalk_1 = __importDefault(require("chalk"));
  17. const stats_formatter_1 = require("../formatter/stats-formatter");
  18. const webpack_formatter_1 = require("../formatter/webpack-formatter");
  19. const infrastructure_logger_1 = require("../infrastructure-logger");
  20. const issue_webpack_error_1 = require("../issue/issue-webpack-error");
  21. const plugin_hooks_1 = require("../plugin-hooks");
  22. const is_pending_1 = require("../utils/async/is-pending");
  23. const wait_1 = require("../utils/async/wait");
  24. function tapDoneToAsyncGetIssues(compiler, config, state) {
  25. const hooks = (0, plugin_hooks_1.getPluginHooks)(compiler);
  26. const { debug } = (0, infrastructure_logger_1.getInfrastructureLogger)(compiler);
  27. compiler.hooks.done.tap('ForkTsCheckerWebpackPlugin', (stats) => __awaiter(this, void 0, void 0, function* () {
  28. if (stats.compilation.compiler !== compiler) {
  29. // run only for the compiler that the plugin was registered for
  30. return;
  31. }
  32. const issuesPromise = state.issuesPromise;
  33. let issues;
  34. try {
  35. if (yield (0, is_pending_1.isPending)(issuesPromise)) {
  36. hooks.waiting.call(stats.compilation);
  37. config.logger.log(chalk_1.default.cyan('Type-checking in progress...'));
  38. }
  39. else {
  40. // wait 10ms to log issues after webpack stats
  41. yield (0, wait_1.wait)(10);
  42. }
  43. issues = yield issuesPromise;
  44. }
  45. catch (error) {
  46. hooks.error.call(error, stats.compilation);
  47. return;
  48. }
  49. if (!issues || // some error has been thrown
  50. state.issuesPromise !== issuesPromise // we have a new request - don't show results for the old one
  51. ) {
  52. return;
  53. }
  54. debug(`Got ${(issues === null || issues === void 0 ? void 0 : issues.length) || 0} issues from getIssuesWorker.`);
  55. // filter list of issues by provided issue predicate
  56. issues = issues.filter(config.issue.predicate);
  57. // modify list of issues in the plugin hooks
  58. issues = hooks.issues.call(issues, stats.compilation);
  59. const formatter = (0, webpack_formatter_1.createWebpackFormatter)(config.formatter.format, config.formatter.pathType);
  60. if (issues.length) {
  61. // follow webpack's approach - one process.write to stderr with all errors and warnings
  62. config.logger.error(issues.map((issue) => formatter(issue)).join('\n'));
  63. // print stats of the compilation
  64. config.logger.log((0, stats_formatter_1.statsFormatter)(issues, stats));
  65. }
  66. else {
  67. config.logger.log(chalk_1.default.green('No errors found.'));
  68. }
  69. // report issues to webpack-dev-server, if it's listening
  70. // skip reporting if there are no issues, to avoid an extra hot reload
  71. if (issues.length && state.webpackDevServerDoneTap) {
  72. issues.forEach((issue) => {
  73. const error = new issue_webpack_error_1.IssueWebpackError(config.formatter.format(issue), config.formatter.pathType, issue);
  74. if (issue.severity === 'warning') {
  75. stats.compilation.warnings.push(error);
  76. }
  77. else {
  78. stats.compilation.errors.push(error);
  79. }
  80. });
  81. debug('Sending issues to the webpack-dev-server.');
  82. state.webpackDevServerDoneTap.fn(stats);
  83. }
  84. }));
  85. }
  86. exports.tapDoneToAsyncGetIssues = tapDoneToAsyncGetIssues;