plugin.js 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  5. }) : (function(o, m, k, k2) {
  6. if (k2 === undefined) k2 = k;
  7. o[k2] = m[k];
  8. }));
  9. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  10. Object.defineProperty(o, "default", { enumerable: true, value: v });
  11. }) : function(o, v) {
  12. o["default"] = v;
  13. });
  14. var __importStar = (this && this.__importStar) || function (mod) {
  15. if (mod && mod.__esModule) return mod;
  16. var result = {};
  17. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  18. __setModuleDefault(result, mod);
  19. return result;
  20. };
  21. var __importDefault = (this && this.__importDefault) || function (mod) {
  22. return (mod && mod.__esModule) ? mod : { "default": mod };
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. exports.ForkTsCheckerWebpackPlugin = void 0;
  26. const path = __importStar(require("path"));
  27. const cosmiconfig_1 = require("cosmiconfig");
  28. const deepmerge_1 = __importDefault(require("deepmerge"));
  29. const schema_utils_1 = require("schema-utils");
  30. const tap_after_compile_to_add_dependencies_1 = require("./hooks/tap-after-compile-to-add-dependencies");
  31. const tap_after_environment_to_patch_watching_1 = require("./hooks/tap-after-environment-to-patch-watching");
  32. const tap_error_to_log_message_1 = require("./hooks/tap-error-to-log-message");
  33. const tap_start_to_run_workers_1 = require("./hooks/tap-start-to-run-workers");
  34. const tap_stop_to_terminate_workers_1 = require("./hooks/tap-stop-to-terminate-workers");
  35. const plugin_config_1 = require("./plugin-config");
  36. const plugin_hooks_1 = require("./plugin-hooks");
  37. const plugin_options_json_1 = __importDefault(require("./plugin-options.json"));
  38. const plugin_pools_1 = require("./plugin-pools");
  39. const plugin_state_1 = require("./plugin-state");
  40. const rpc_1 = require("./rpc");
  41. const type_script_support_1 = require("./typescript/type-script-support");
  42. class ForkTsCheckerWebpackPlugin {
  43. constructor(options = {}) {
  44. const explorerSync = (0, cosmiconfig_1.cosmiconfigSync)('fork-ts-checker');
  45. const { config: externalOptions } = explorerSync.search() || {};
  46. // first validate options directly passed to the constructor
  47. const config = { name: 'ForkTsCheckerWebpackPlugin' };
  48. (0, schema_utils_1.validate)(plugin_options_json_1.default, options, config);
  49. this.options = (0, deepmerge_1.default)(externalOptions || {}, options || {});
  50. // then validate merged options
  51. (0, schema_utils_1.validate)(plugin_options_json_1.default, this.options, config);
  52. }
  53. static getCompilerHooks(compiler) {
  54. return (0, plugin_hooks_1.getPluginHooks)(compiler);
  55. }
  56. apply(compiler) {
  57. const config = (0, plugin_config_1.createPluginConfig)(compiler, this.options);
  58. const state = (0, plugin_state_1.createPluginState)();
  59. (0, type_script_support_1.assertTypeScriptSupport)(config.typescript);
  60. const getIssuesWorker = (0, rpc_1.createRpcWorker)(path.resolve(__dirname, './typescript/worker/get-issues-worker.js'), config.typescript, config.typescript.memoryLimit);
  61. const getDependenciesWorker = (0, rpc_1.createRpcWorker)(path.resolve(__dirname, './typescript/worker/get-dependencies-worker.js'), config.typescript);
  62. (0, tap_after_environment_to_patch_watching_1.tapAfterEnvironmentToPatchWatching)(compiler, state);
  63. (0, tap_start_to_run_workers_1.tapStartToRunWorkers)(compiler, getIssuesWorker, getDependenciesWorker, config, state);
  64. (0, tap_after_compile_to_add_dependencies_1.tapAfterCompileToAddDependencies)(compiler, config, state);
  65. (0, tap_stop_to_terminate_workers_1.tapStopToTerminateWorkers)(compiler, getIssuesWorker, getDependenciesWorker, state);
  66. (0, tap_error_to_log_message_1.tapErrorToLogMessage)(compiler, config);
  67. }
  68. }
  69. exports.ForkTsCheckerWebpackPlugin = ForkTsCheckerWebpackPlugin;
  70. /**
  71. * Current version of the plugin
  72. */
  73. ForkTsCheckerWebpackPlugin.version = '8.0.0'; // will be replaced by the @semantic-release/exec
  74. /**
  75. * Default pools for the plugin concurrency limit
  76. */
  77. ForkTsCheckerWebpackPlugin.issuesPool = plugin_pools_1.issuesPool;
  78. ForkTsCheckerWebpackPlugin.dependenciesPool = plugin_pools_1.dependenciesPool;
  79. /**
  80. * @deprecated Use ForkTsCheckerWebpackPlugin.issuesPool instead
  81. */
  82. ForkTsCheckerWebpackPlugin.pool = plugin_pools_1.issuesPool;