Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

node-pty@1.2.0-beta.15.patch

86 lines4.4 KB

1diff --git a/lib/windowsConoutConnection.js b/lib/windowsConoutConnection.js
2--- a/lib/windowsConoutConnection.js
3+++ b/lib/windowsConoutConnection.js
4@@ -63,7 +63,11 @@
5 conoutPipeName: _conoutPipeName
6 };
7 var scriptPath = __dirname.replace('node_modules.asar', 'node_modules.asar.unpacked');
8- this._worker = new worker_threads_1.Worker((0, path_1.join)(scriptPath, 'worker/conoutSocketWorker.js'), { workerData: workerData });
9+ // Node's watch mode reports dependencies through worker messages.
10+ // Keep the host's watch environment out of this protocol worker.
11+ var workerEnv = Object.assign({}, process.env);
12+ delete workerEnv.WATCH_REPORT_DEPENDENCIES;
13+ this._worker = new worker_threads_1.Worker((0, path_1.join)(scriptPath, 'worker/conoutSocketWorker.js'), { workerData: workerData, env: workerEnv, execArgv: [] });
14 this._worker.on('message', function (message) {
15 switch (message) {
16 case 1 /* ConoutWorkerMessage.READY */:
17diff --git a/lib/windowsPtyAgent.js b/lib/windowsPtyAgent.js
18--- a/lib/windowsPtyAgent.js
19+++ b/lib/windowsPtyAgent.js
20@@ -20,7 +20,9 @@ var conptyNative;
21 * shutting down the socket. The timer will be reset if a new data event comes in after the timer
22 * has started.
23 */
24-var FLUSH_DATA_INTERVAL = 1000;
25+// ConPTY never closes the output pipe on its own after the shell exits, so wait this long for the last
26+// screen update. Trailing output follows the exit within about 20 ms; 1000 ms made every exit report 1 s late.
27+var FLUSH_DATA_INTERVAL = 100;
28 var CONNECTION_TIMEOUT = 5000;
29 var defaultWindowsPtyAgentOptions = {
30 connectionTimeout: CONNECTION_TIMEOUT,
31@@ -218,13 +220,31 @@
32 return Promise.resolve([]);
33 }
34 return new Promise(function (resolve) {
35- var agent = (0, child_process_1.fork)(path.join(__dirname, 'conpty_console_list_agent'), [_this._innerPid.toString()]);
36+ // Node's watch mode sends its own messages over the helper's IPC channel.
37+ var agentEnv = Object.assign({}, process.env);
38+ delete agentEnv.WATCH_REPORT_DEPENDENCIES;
39+ var settled = false;
40+ var finish = function (list) {
41+ if (settled) return;
42+ settled = true;
43+ clearTimeout(timeout);
44+ resolve(list);
45+ };
46+ var agent = (0, child_process_1.fork)(path.join(__dirname, 'conpty_console_list_agent'), [_this._innerPid.toString()], { env: agentEnv, execArgv: [], windowsHide: true });
47 agent.on('message', function (message) {
48- clearTimeout(timeout);
49- resolve(message.consoleProcessList);
50+ if (!message || !Array.isArray(message.consoleProcessList)) {
51+ return;
52+ }
53+ finish(message.consoleProcessList);
54+ });
55+ agent.on('error', function () {
56+ finish([_this._innerPid]);
57+ });
58+ agent.on('close', function () {
59+ finish([_this._innerPid]);
60 });
61 var timeout = setTimeout(function () {
62 // Something went wrong, just send back the shell PID
63 agent.kill();
64- resolve([_this._innerPid]);
65+ finish([_this._innerPid]);
66 }, 5000);
67@@ -259,7 +279,18 @@ var WindowsPtyAgent = /** @class */ (function () {
68 if (this._closeTimeout) {
69 clearTimeout(this._closeTimeout);
70 }
71- this._closeTimeout = setTimeout(function () { return _this._cleanUpProcess(); }, FLUSH_DATA_INTERVAL);
72+ // Timers run before the poll phase. After a main-thread stall longer than the interval, output that is already
73+ // buffered in the pipe would be dropped by the cleanup, so give the poll phase one turn to read it first; every
74+ // chunk it reads re-arms this timer.
75+ this._flushDataSeq = (this._flushDataSeq || 0) + 1;
76+ this._closeTimeout = setTimeout(function () {
77+ var seq = _this._flushDataSeq;
78+ setImmediate(function () {
79+ if (_this._flushDataSeq === seq) {
80+ _this._cleanUpProcess();
81+ }
82+ });
83+ }, FLUSH_DATA_INTERVAL);
84 };
85 WindowsPtyAgent.prototype._cleanUpProcess = function () {
86 if (this._useConptyDll) {