fork-ts-checker-webpack-plugin 7.2.4 → 7.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/plugin.js CHANGED
@@ -70,7 +70,7 @@ exports.ForkTsCheckerWebpackPlugin = ForkTsCheckerWebpackPlugin;
70
70
  /**
71
71
  * Current version of the plugin
72
72
  */
73
- ForkTsCheckerWebpackPlugin.version = '7.2.4'; // will be replaced by the @semantic-release/exec
73
+ ForkTsCheckerWebpackPlugin.version = '7.2.5'; // will be replaced by the @semantic-release/exec
74
74
  /**
75
75
  * Default pools for the plugin concurrency limit
76
76
  */
@@ -1,23 +1,4 @@
1
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
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -29,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
29
10
  };
30
11
  Object.defineProperty(exports, "__esModule", { value: true });
31
12
  exports.wrapRpc = void 0;
32
- const process = __importStar(require("process"));
13
+ const controlled_promise_1 = require("../utils/async/controlled-promise");
33
14
  const rpc_error_1 = require("./rpc-error");
34
15
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
16
  function wrapRpc(childProcess) {
@@ -41,50 +22,52 @@ function wrapRpc(childProcess) {
41
22
  throw new Error(`Process ${childProcess.pid} doesn't have open IPC channels`);
42
23
  }
43
24
  const id = uuid();
44
- const resultPromise = new Promise((resolve, reject) => {
45
- const handleMessage = (message) => {
46
- if (message.id === id) {
47
- if (message.type === 'resolve') {
48
- resolve(message.value);
49
- unsubscribe();
50
- }
51
- else if (message.type === 'reject') {
52
- reject(message.error);
53
- unsubscribe();
54
- }
55
- }
56
- };
57
- const handleClose = (code, signal) => {
58
- reject(new rpc_error_1.RpcExitError(code
59
- ? `Process ${process.pid} exited with code "${code}" [${signal}]`
60
- : `Process ${process.pid} exited [${signal}].`, code, signal));
61
- unsubscribe();
62
- };
63
- const subscribe = () => {
64
- childProcess.on('message', handleMessage);
65
- childProcess.on('close', handleClose);
66
- };
67
- const unsubscribe = () => {
68
- childProcess.off('message', handleMessage);
69
- childProcess.off('exit', handleClose);
70
- };
71
- subscribe();
72
- });
73
- yield new Promise((resolve, reject) => {
74
- childProcess.send({
75
- type: 'call',
76
- id,
77
- args,
78
- }, (error) => {
79
- if (error) {
80
- reject(error);
25
+ // create promises
26
+ const { promise: resultPromise, resolve: resolveResult, reject: rejectResult, } = (0, controlled_promise_1.createControlledPromise)();
27
+ const { promise: sendPromise, resolve: resolveSend, reject: rejectSend, } = (0, controlled_promise_1.createControlledPromise)();
28
+ const handleMessage = (message) => {
29
+ if ((message === null || message === void 0 ? void 0 : message.id) === id) {
30
+ if (message.type === 'resolve') {
31
+ // assume the contract is respected
32
+ resolveResult(message.value);
33
+ removeHandlers();
81
34
  }
82
- else {
83
- resolve(undefined);
35
+ else if (message.type === 'reject') {
36
+ rejectResult(message.error);
37
+ removeHandlers();
84
38
  }
85
- });
39
+ }
40
+ };
41
+ const handleClose = (code, signal) => {
42
+ rejectResult(new rpc_error_1.RpcExitError(code
43
+ ? `Process ${childProcess.pid} exited with code ${code}` +
44
+ (signal ? ` [${signal}]` : '')
45
+ : `Process ${childProcess.pid} exited` + (signal ? ` [${signal}]` : ''), code, signal));
46
+ removeHandlers();
47
+ };
48
+ // to prevent event handler leaks
49
+ const removeHandlers = () => {
50
+ childProcess.off('message', handleMessage);
51
+ childProcess.off('close', handleClose);
52
+ };
53
+ // add event listeners
54
+ childProcess.on('message', handleMessage);
55
+ childProcess.on('close', handleClose);
56
+ // send call message
57
+ childProcess.send({
58
+ type: 'call',
59
+ id,
60
+ args,
61
+ }, (error) => {
62
+ if (error) {
63
+ rejectSend(error);
64
+ removeHandlers();
65
+ }
66
+ else {
67
+ resolveSend(undefined);
68
+ }
86
69
  });
87
- return resultPromise;
70
+ return sendPromise.then(() => resultPromise);
88
71
  }));
89
72
  }
90
73
  exports.wrapRpc = wrapRpc;
@@ -0,0 +1,6 @@
1
+ declare function createControlledPromise<T = unknown>(): {
2
+ promise: Promise<T>;
3
+ resolve: (value: T) => void;
4
+ reject: (error: unknown) => void;
5
+ };
6
+ export { createControlledPromise };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createControlledPromise = void 0;
4
+ function createControlledPromise() {
5
+ let resolve = () => undefined;
6
+ let reject = () => undefined;
7
+ const promise = new Promise((aResolve, aReject) => {
8
+ resolve = aResolve;
9
+ reject = aReject;
10
+ });
11
+ return {
12
+ promise,
13
+ resolve,
14
+ reject,
15
+ };
16
+ }
17
+ exports.createControlledPromise = createControlledPromise;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fork-ts-checker-webpack-plugin",
3
- "version": "7.2.4",
3
+ "version": "7.2.5",
4
4
  "description": "Runs typescript type checker and linter on separate process.",
5
5
  "keywords": [
6
6
  "webpack",