node-pty 1.1.0 → 1.2.0-beta.10

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.
Files changed (264) hide show
  1. package/README.md +3 -5
  2. package/binding.gyp +76 -37
  3. package/lib/unixTerminal.js +6 -3
  4. package/lib/utils.js +1 -1
  5. package/lib/windowsPtyAgent.js +32 -95
  6. package/lib/windowsTerminal.js +2 -2
  7. package/package.json +6 -5
  8. package/prebuilds/darwin-arm64/pty.node +0 -0
  9. package/prebuilds/darwin-arm64/spawn-helper +0 -0
  10. package/prebuilds/darwin-x64/pty.node +0 -0
  11. package/prebuilds/darwin-x64/spawn-helper +0 -0
  12. package/prebuilds/linux-arm64/pty.node +0 -0
  13. package/prebuilds/linux-x64/pty.node +0 -0
  14. package/prebuilds/win32-arm64/conpty.node +0 -0
  15. package/prebuilds/win32-arm64/conpty.pdb +0 -0
  16. package/prebuilds/win32-arm64/conpty_console_list.node +0 -0
  17. package/prebuilds/win32-arm64/conpty_console_list.pdb +0 -0
  18. package/prebuilds/win32-x64/conpty.node +0 -0
  19. package/prebuilds/win32-x64/conpty.pdb +0 -0
  20. package/prebuilds/win32-x64/conpty_console_list.node +0 -0
  21. package/prebuilds/win32-x64/conpty_console_list.pdb +0 -0
  22. package/scripts/post-install.js +1 -5
  23. package/src/unix/pty.cc +111 -35
  24. package/src/win/conpty.cc +1 -2
  25. package/typings/node-pty.d.ts +13 -9
  26. package/deps/.editorconfig +0 -2
  27. package/deps/winpty/.drone.yml +0 -17
  28. package/deps/winpty/.gitattributes +0 -19
  29. package/deps/winpty/LICENSE +0 -21
  30. package/deps/winpty/Makefile +0 -166
  31. package/deps/winpty/README.md +0 -151
  32. package/deps/winpty/RELEASES.md +0 -280
  33. package/deps/winpty/VERSION.txt +0 -1
  34. package/deps/winpty/configure +0 -167
  35. package/deps/winpty/misc/BufferResizeTests.cc +0 -90
  36. package/deps/winpty/misc/ChangeScreenBuffer.cc +0 -53
  37. package/deps/winpty/misc/ClearConsole.cc +0 -72
  38. package/deps/winpty/misc/ConinMode.cc +0 -117
  39. package/deps/winpty/misc/ConinMode.ps1 +0 -116
  40. package/deps/winpty/misc/ConoutMode.cc +0 -113
  41. package/deps/winpty/misc/DebugClient.py +0 -42
  42. package/deps/winpty/misc/DebugServer.py +0 -63
  43. package/deps/winpty/misc/DumpLines.py +0 -5
  44. package/deps/winpty/misc/EnableExtendedFlags.txt +0 -46
  45. package/deps/winpty/misc/Font-Report-June2016/CP437-Consolas.txt +0 -528
  46. package/deps/winpty/misc/Font-Report-June2016/CP437-Lucida.txt +0 -633
  47. package/deps/winpty/misc/Font-Report-June2016/CP932.txt +0 -630
  48. package/deps/winpty/misc/Font-Report-June2016/CP936.txt +0 -630
  49. package/deps/winpty/misc/Font-Report-June2016/CP949.txt +0 -630
  50. package/deps/winpty/misc/Font-Report-June2016/CP950.txt +0 -630
  51. package/deps/winpty/misc/Font-Report-June2016/MinimumWindowWidths.txt +0 -16
  52. package/deps/winpty/misc/Font-Report-June2016/Results.txt +0 -4
  53. package/deps/winpty/misc/Font-Report-June2016/Windows10SetFontBugginess.txt +0 -144
  54. package/deps/winpty/misc/FontSurvey.cc +0 -100
  55. package/deps/winpty/misc/FormatChar.h +0 -21
  56. package/deps/winpty/misc/FreezePerfTest.cc +0 -62
  57. package/deps/winpty/misc/GetCh.cc +0 -20
  58. package/deps/winpty/misc/GetConsolePos.cc +0 -41
  59. package/deps/winpty/misc/GetFont.cc +0 -261
  60. package/deps/winpty/misc/IdentifyConsoleWindow.ps1 +0 -51
  61. package/deps/winpty/misc/IsNewConsole.cc +0 -87
  62. package/deps/winpty/misc/MouseInputNotes.txt +0 -90
  63. package/deps/winpty/misc/MoveConsoleWindow.cc +0 -34
  64. package/deps/winpty/misc/Notes.txt +0 -219
  65. package/deps/winpty/misc/OSVersion.cc +0 -27
  66. package/deps/winpty/misc/ScreenBufferFreezeInactive.cc +0 -101
  67. package/deps/winpty/misc/ScreenBufferTest.cc +0 -671
  68. package/deps/winpty/misc/ScreenBufferTest2.cc +0 -151
  69. package/deps/winpty/misc/SelectAllTest.cc +0 -45
  70. package/deps/winpty/misc/SetBufferSize.cc +0 -32
  71. package/deps/winpty/misc/SetCursorPos.cc +0 -10
  72. package/deps/winpty/misc/SetFont.cc +0 -145
  73. package/deps/winpty/misc/SetWindowRect.cc +0 -36
  74. package/deps/winpty/misc/ShowArgv.cc +0 -12
  75. package/deps/winpty/misc/ShowConsoleInput.cc +0 -40
  76. package/deps/winpty/misc/Spew.py +0 -5
  77. package/deps/winpty/misc/TestUtil.cc +0 -172
  78. package/deps/winpty/misc/UnicodeDoubleWidthTest.cc +0 -102
  79. package/deps/winpty/misc/UnicodeWideTest1.cc +0 -246
  80. package/deps/winpty/misc/UnicodeWideTest2.cc +0 -130
  81. package/deps/winpty/misc/UnixEcho.cc +0 -89
  82. package/deps/winpty/misc/Utf16Echo.cc +0 -46
  83. package/deps/winpty/misc/VeryLargeRead.cc +0 -122
  84. package/deps/winpty/misc/VkEscapeTest.cc +0 -56
  85. package/deps/winpty/misc/Win10ResizeWhileFrozen.cc +0 -52
  86. package/deps/winpty/misc/Win10WrapTest1.cc +0 -57
  87. package/deps/winpty/misc/Win10WrapTest2.cc +0 -30
  88. package/deps/winpty/misc/Win32Echo1.cc +0 -26
  89. package/deps/winpty/misc/Win32Echo2.cc +0 -19
  90. package/deps/winpty/misc/Win32Test1.cc +0 -46
  91. package/deps/winpty/misc/Win32Test2.cc +0 -70
  92. package/deps/winpty/misc/Win32Test3.cc +0 -78
  93. package/deps/winpty/misc/Win32Write1.cc +0 -44
  94. package/deps/winpty/misc/WindowsBugCrashReader.cc +0 -27
  95. package/deps/winpty/misc/WriteConsole.cc +0 -106
  96. package/deps/winpty/misc/build32.sh +0 -9
  97. package/deps/winpty/misc/build64.sh +0 -9
  98. package/deps/winpty/misc/color-test.sh +0 -212
  99. package/deps/winpty/misc/font-notes.txt +0 -300
  100. package/deps/winpty/misc/winbug-15048.cc +0 -201
  101. package/deps/winpty/ship/build-pty4j-libpty.bat +0 -36
  102. package/deps/winpty/ship/common_ship.py +0 -53
  103. package/deps/winpty/ship/make_msvc_package.py +0 -165
  104. package/deps/winpty/ship/ship.py +0 -108
  105. package/deps/winpty/src/agent/Agent.cc +0 -613
  106. package/deps/winpty/src/agent/Agent.h +0 -103
  107. package/deps/winpty/src/agent/AgentCreateDesktop.cc +0 -84
  108. package/deps/winpty/src/agent/AgentCreateDesktop.h +0 -28
  109. package/deps/winpty/src/agent/ConsoleFont.cc +0 -632
  110. package/deps/winpty/src/agent/ConsoleFont.h +0 -28
  111. package/deps/winpty/src/agent/ConsoleInput.cc +0 -852
  112. package/deps/winpty/src/agent/ConsoleInput.h +0 -109
  113. package/deps/winpty/src/agent/ConsoleInputReencoding.cc +0 -121
  114. package/deps/winpty/src/agent/ConsoleInputReencoding.h +0 -36
  115. package/deps/winpty/src/agent/ConsoleLine.cc +0 -152
  116. package/deps/winpty/src/agent/ConsoleLine.h +0 -41
  117. package/deps/winpty/src/agent/Coord.h +0 -87
  118. package/deps/winpty/src/agent/DebugShowInput.cc +0 -239
  119. package/deps/winpty/src/agent/DebugShowInput.h +0 -32
  120. package/deps/winpty/src/agent/DefaultInputMap.cc +0 -422
  121. package/deps/winpty/src/agent/DefaultInputMap.h +0 -28
  122. package/deps/winpty/src/agent/DsrSender.h +0 -30
  123. package/deps/winpty/src/agent/EventLoop.cc +0 -99
  124. package/deps/winpty/src/agent/EventLoop.h +0 -47
  125. package/deps/winpty/src/agent/InputMap.cc +0 -246
  126. package/deps/winpty/src/agent/InputMap.h +0 -114
  127. package/deps/winpty/src/agent/LargeConsoleRead.cc +0 -71
  128. package/deps/winpty/src/agent/LargeConsoleRead.h +0 -68
  129. package/deps/winpty/src/agent/NamedPipe.cc +0 -378
  130. package/deps/winpty/src/agent/NamedPipe.h +0 -125
  131. package/deps/winpty/src/agent/Scraper.cc +0 -699
  132. package/deps/winpty/src/agent/Scraper.h +0 -103
  133. package/deps/winpty/src/agent/SimplePool.h +0 -75
  134. package/deps/winpty/src/agent/SmallRect.h +0 -143
  135. package/deps/winpty/src/agent/Terminal.cc +0 -535
  136. package/deps/winpty/src/agent/Terminal.h +0 -69
  137. package/deps/winpty/src/agent/UnicodeEncoding.h +0 -157
  138. package/deps/winpty/src/agent/UnicodeEncodingTest.cc +0 -189
  139. package/deps/winpty/src/agent/Win32Console.cc +0 -107
  140. package/deps/winpty/src/agent/Win32Console.h +0 -67
  141. package/deps/winpty/src/agent/Win32ConsoleBuffer.cc +0 -193
  142. package/deps/winpty/src/agent/Win32ConsoleBuffer.h +0 -99
  143. package/deps/winpty/src/agent/main.cc +0 -114
  144. package/deps/winpty/src/agent/subdir.mk +0 -61
  145. package/deps/winpty/src/configurations.gypi +0 -60
  146. package/deps/winpty/src/debugserver/DebugServer.cc +0 -117
  147. package/deps/winpty/src/debugserver/subdir.mk +0 -41
  148. package/deps/winpty/src/include/winpty.h +0 -242
  149. package/deps/winpty/src/include/winpty_constants.h +0 -131
  150. package/deps/winpty/src/libwinpty/AgentLocation.cc +0 -75
  151. package/deps/winpty/src/libwinpty/AgentLocation.h +0 -28
  152. package/deps/winpty/src/libwinpty/LibWinptyException.h +0 -54
  153. package/deps/winpty/src/libwinpty/WinptyInternal.h +0 -72
  154. package/deps/winpty/src/libwinpty/subdir.mk +0 -46
  155. package/deps/winpty/src/libwinpty/winpty.cc +0 -970
  156. package/deps/winpty/src/shared/AgentMsg.h +0 -38
  157. package/deps/winpty/src/shared/BackgroundDesktop.cc +0 -122
  158. package/deps/winpty/src/shared/BackgroundDesktop.h +0 -73
  159. package/deps/winpty/src/shared/Buffer.cc +0 -103
  160. package/deps/winpty/src/shared/Buffer.h +0 -102
  161. package/deps/winpty/src/shared/DebugClient.cc +0 -187
  162. package/deps/winpty/src/shared/DebugClient.h +0 -38
  163. package/deps/winpty/src/shared/GenRandom.cc +0 -138
  164. package/deps/winpty/src/shared/GenRandom.h +0 -55
  165. package/deps/winpty/src/shared/GetCommitHash.bat +0 -13
  166. package/deps/winpty/src/shared/Mutex.h +0 -54
  167. package/deps/winpty/src/shared/OsModule.h +0 -63
  168. package/deps/winpty/src/shared/OwnedHandle.cc +0 -36
  169. package/deps/winpty/src/shared/OwnedHandle.h +0 -45
  170. package/deps/winpty/src/shared/PrecompiledHeader.h +0 -43
  171. package/deps/winpty/src/shared/StringBuilder.h +0 -227
  172. package/deps/winpty/src/shared/StringBuilderTest.cc +0 -114
  173. package/deps/winpty/src/shared/StringUtil.cc +0 -55
  174. package/deps/winpty/src/shared/StringUtil.h +0 -80
  175. package/deps/winpty/src/shared/TimeMeasurement.h +0 -63
  176. package/deps/winpty/src/shared/UnixCtrlChars.h +0 -45
  177. package/deps/winpty/src/shared/UpdateGenVersion.bat +0 -20
  178. package/deps/winpty/src/shared/WindowsSecurity.cc +0 -460
  179. package/deps/winpty/src/shared/WindowsSecurity.h +0 -104
  180. package/deps/winpty/src/shared/WindowsVersion.cc +0 -252
  181. package/deps/winpty/src/shared/WindowsVersion.h +0 -29
  182. package/deps/winpty/src/shared/WinptyAssert.cc +0 -55
  183. package/deps/winpty/src/shared/WinptyAssert.h +0 -64
  184. package/deps/winpty/src/shared/WinptyException.cc +0 -57
  185. package/deps/winpty/src/shared/WinptyException.h +0 -43
  186. package/deps/winpty/src/shared/WinptyVersion.cc +0 -42
  187. package/deps/winpty/src/shared/WinptyVersion.h +0 -27
  188. package/deps/winpty/src/shared/winpty_snprintf.h +0 -99
  189. package/deps/winpty/src/subdir.mk +0 -5
  190. package/deps/winpty/src/tests/subdir.mk +0 -28
  191. package/deps/winpty/src/tests/trivial_test.cc +0 -158
  192. package/deps/winpty/src/unix-adapter/InputHandler.cc +0 -114
  193. package/deps/winpty/src/unix-adapter/InputHandler.h +0 -56
  194. package/deps/winpty/src/unix-adapter/OutputHandler.cc +0 -80
  195. package/deps/winpty/src/unix-adapter/OutputHandler.h +0 -53
  196. package/deps/winpty/src/unix-adapter/Util.cc +0 -86
  197. package/deps/winpty/src/unix-adapter/Util.h +0 -31
  198. package/deps/winpty/src/unix-adapter/WakeupFd.cc +0 -70
  199. package/deps/winpty/src/unix-adapter/WakeupFd.h +0 -42
  200. package/deps/winpty/src/unix-adapter/main.cc +0 -729
  201. package/deps/winpty/src/unix-adapter/subdir.mk +0 -41
  202. package/deps/winpty/src/winpty.gyp +0 -234
  203. package/deps/winpty/vcbuild.bat +0 -83
  204. package/lib/conpty_console_list_agent.js.map +0 -1
  205. package/lib/eventEmitter2.js.map +0 -1
  206. package/lib/eventEmitter2.test.js +0 -30
  207. package/lib/eventEmitter2.test.js.map +0 -1
  208. package/lib/index.js.map +0 -1
  209. package/lib/interfaces.js.map +0 -1
  210. package/lib/shared/conout.js.map +0 -1
  211. package/lib/terminal.js.map +0 -1
  212. package/lib/terminal.test.js +0 -139
  213. package/lib/terminal.test.js.map +0 -1
  214. package/lib/testUtils.test.js +0 -28
  215. package/lib/testUtils.test.js.map +0 -1
  216. package/lib/types.js.map +0 -1
  217. package/lib/unixTerminal.js.map +0 -1
  218. package/lib/unixTerminal.test.js +0 -351
  219. package/lib/unixTerminal.test.js.map +0 -1
  220. package/lib/utils.js.map +0 -1
  221. package/lib/windowsConoutConnection.js.map +0 -1
  222. package/lib/windowsPtyAgent.js.map +0 -1
  223. package/lib/windowsPtyAgent.test.js +0 -90
  224. package/lib/windowsPtyAgent.test.js.map +0 -1
  225. package/lib/windowsTerminal.js.map +0 -1
  226. package/lib/windowsTerminal.test.js +0 -219
  227. package/lib/windowsTerminal.test.js.map +0 -1
  228. package/lib/worker/conoutSocketWorker.js.map +0 -1
  229. package/prebuilds/win32-arm64/pty.node +0 -0
  230. package/prebuilds/win32-arm64/pty.pdb +0 -0
  231. package/prebuilds/win32-arm64/winpty-agent.exe +0 -0
  232. package/prebuilds/win32-arm64/winpty-agent.pdb +0 -0
  233. package/prebuilds/win32-arm64/winpty.dll +0 -0
  234. package/prebuilds/win32-arm64/winpty.pdb +0 -0
  235. package/prebuilds/win32-x64/pty.node +0 -0
  236. package/prebuilds/win32-x64/pty.pdb +0 -0
  237. package/prebuilds/win32-x64/winpty-agent.exe +0 -0
  238. package/prebuilds/win32-x64/winpty-agent.pdb +0 -0
  239. package/prebuilds/win32-x64/winpty.dll +0 -0
  240. package/prebuilds/win32-x64/winpty.pdb +0 -0
  241. package/scripts/gen-compile-commands.js +0 -8
  242. package/scripts/increment-version.js +0 -54
  243. package/src/conpty_console_list_agent.ts +0 -15
  244. package/src/eventEmitter2.test.ts +0 -30
  245. package/src/eventEmitter2.ts +0 -48
  246. package/src/index.ts +0 -52
  247. package/src/interfaces.ts +0 -130
  248. package/src/native.d.ts +0 -54
  249. package/src/shared/conout.ts +0 -15
  250. package/src/terminal.test.ts +0 -119
  251. package/src/terminal.ts +0 -211
  252. package/src/testUtils.test.ts +0 -23
  253. package/src/tsconfig.json +0 -22
  254. package/src/types.ts +0 -15
  255. package/src/unixTerminal.test.ts +0 -367
  256. package/src/unixTerminal.ts +0 -388
  257. package/src/utils.ts +0 -29
  258. package/src/win/winpty.cc +0 -333
  259. package/src/windowsConoutConnection.ts +0 -82
  260. package/src/windowsPtyAgent.test.ts +0 -94
  261. package/src/windowsPtyAgent.ts +0 -321
  262. package/src/windowsTerminal.test.ts +0 -229
  263. package/src/windowsTerminal.ts +0 -203
  264. package/src/worker/conoutSocketWorker.ts +0 -22
@@ -1,321 +0,0 @@
1
- /**
2
- * Copyright (c) 2012-2015, Christopher Jeffrey, Peter Sunde (MIT License)
3
- * Copyright (c) 2016, Daniel Imms (MIT License).
4
- * Copyright (c) 2018, Microsoft Corporation (MIT License).
5
- */
6
-
7
- import * as fs from 'fs';
8
- import * as os from 'os';
9
- import * as path from 'path';
10
- import { fork } from 'child_process';
11
- import { Socket } from 'net';
12
- import { ArgvOrCommandLine } from './types';
13
- import { ConoutConnection } from './windowsConoutConnection';
14
- import { loadNativeModule } from './utils';
15
-
16
- let conptyNative: IConptyNative;
17
- let winptyNative: IWinptyNative;
18
-
19
- /**
20
- * The amount of time to wait for additional data after the conpty shell process has exited before
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
- const FLUSH_DATA_INTERVAL = 1000;
25
-
26
- /**
27
- * This agent sits between the WindowsTerminal class and provides a common interface for both conpty
28
- * and winpty.
29
- */
30
- export class WindowsPtyAgent {
31
- private _inSocket: Socket;
32
- private _outSocket: Socket;
33
- private _pid: number = 0;
34
- private _innerPid: number = 0;
35
- private _closeTimeout: NodeJS.Timer | undefined;
36
- private _exitCode: number | undefined;
37
- private _conoutSocketWorker: ConoutConnection;
38
-
39
- private _fd: any;
40
- private _pty: number;
41
- private _ptyNative: IConptyNative | IWinptyNative;
42
-
43
- public get inSocket(): Socket { return this._inSocket; }
44
- public get outSocket(): Socket { return this._outSocket; }
45
- public get fd(): any { return this._fd; }
46
- public get innerPid(): number { return this._innerPid; }
47
- public get pty(): number { return this._pty; }
48
-
49
- constructor(
50
- file: string,
51
- args: ArgvOrCommandLine,
52
- env: string[],
53
- cwd: string,
54
- cols: number,
55
- rows: number,
56
- debug: boolean,
57
- private _useConpty: boolean | undefined,
58
- private _useConptyDll: boolean = false,
59
- conptyInheritCursor: boolean = false
60
- ) {
61
- if (this._useConpty === undefined || this._useConpty === true) {
62
- this._useConpty = this._getWindowsBuildNumber() >= 18309;
63
- }
64
- if (this._useConpty) {
65
- if (!conptyNative) {
66
- conptyNative = loadNativeModule('conpty').module;
67
- }
68
- } else {
69
- if (!winptyNative) {
70
- winptyNative = loadNativeModule('pty').module;
71
- }
72
- }
73
- this._ptyNative = this._useConpty ? conptyNative : winptyNative;
74
-
75
- // Sanitize input variable.
76
- cwd = path.resolve(cwd);
77
-
78
- // Compose command line
79
- const commandLine = argsToCommandLine(file, args);
80
-
81
- // Open pty session.
82
- let term: IConptyProcess | IWinptyProcess;
83
- if (this._useConpty) {
84
- term = (this._ptyNative as IConptyNative).startProcess(file, cols, rows, debug, this._generatePipeName(), conptyInheritCursor, this._useConptyDll);
85
- } else {
86
- term = (this._ptyNative as IWinptyNative).startProcess(file, commandLine, env, cwd, cols, rows, debug);
87
- this._pid = (term as IWinptyProcess).pid;
88
- this._innerPid = (term as IWinptyProcess).innerPid;
89
- }
90
-
91
- // Not available on windows.
92
- this._fd = term.fd;
93
-
94
- // Generated incremental number that has no real purpose besides using it
95
- // as a terminal id.
96
- this._pty = term.pty;
97
-
98
- // Create terminal pipe IPC channel and forward to a local unix socket.
99
- this._outSocket = new Socket();
100
- this._outSocket.setEncoding('utf8');
101
- // The conout socket must be ready out on another thread to avoid deadlocks
102
- this._conoutSocketWorker = new ConoutConnection(term.conout, this._useConptyDll);
103
- this._conoutSocketWorker.onReady(() => {
104
- this._conoutSocketWorker.connectSocket(this._outSocket);
105
- });
106
- this._outSocket.on('connect', () => {
107
- this._outSocket.emit('ready_datapipe');
108
- });
109
-
110
- const inSocketFD = fs.openSync(term.conin, 'w');
111
- this._inSocket = new Socket({
112
- fd: inSocketFD,
113
- readable: false,
114
- writable: true
115
- });
116
- this._inSocket.setEncoding('utf8');
117
-
118
- if (this._useConpty) {
119
- const connect = (this._ptyNative as IConptyNative).connect(this._pty, commandLine, cwd, env, this._useConptyDll, c => this._$onProcessExit(c));
120
- this._innerPid = connect.pid;
121
- }
122
- }
123
-
124
- public resize(cols: number, rows: number): void {
125
- if (this._useConpty) {
126
- if (this._exitCode !== undefined) {
127
- throw new Error('Cannot resize a pty that has already exited');
128
- }
129
- (this._ptyNative as IConptyNative).resize(this._pty, cols, rows, this._useConptyDll);
130
- return;
131
- }
132
- (this._ptyNative as IWinptyNative).resize(this._pid, cols, rows);
133
- }
134
-
135
- public clear(): void {
136
- if (this._useConpty) {
137
- (this._ptyNative as IConptyNative).clear(this._pty, this._useConptyDll);
138
- }
139
- }
140
-
141
- public kill(): void {
142
- // Tell the agent to kill the pty, this releases handles to the process
143
- if (this._useConpty) {
144
- if (!this._useConptyDll) {
145
- this._inSocket.readable = false;
146
- this._outSocket.readable = false;
147
- this._getConsoleProcessList().then(consoleProcessList => {
148
- consoleProcessList.forEach((pid: number) => {
149
- try {
150
- process.kill(pid);
151
- } catch (e) {
152
- // Ignore if process cannot be found (kill ESRCH error)
153
- }
154
- });
155
- });
156
- (this._ptyNative as IConptyNative).kill(this._pty, this._useConptyDll);
157
- this._conoutSocketWorker.dispose();
158
- } else {
159
- // Close the input write handle to signal the end of session.
160
- this._inSocket.destroy();
161
- (this._ptyNative as IConptyNative).kill(this._pty, this._useConptyDll);
162
- this._outSocket.on('data', () => {
163
- this._conoutSocketWorker.dispose();
164
- });
165
- }
166
- } else {
167
- // Because pty.kill closes the handle, it will kill most processes by itself.
168
- // Process IDs can be reused as soon as all handles to them are
169
- // dropped, so we want to immediately kill the entire console process list.
170
- // If we do not force kill all processes here, node servers in particular
171
- // seem to become detached and remain running (see
172
- // Microsoft/vscode#26807).
173
- const processList: number[] = (this._ptyNative as IWinptyNative).getProcessList(this._pid);
174
- (this._ptyNative as IWinptyNative).kill(this._pid, this._innerPid);
175
- processList.forEach(pid => {
176
- try {
177
- process.kill(pid);
178
- } catch (e) {
179
- // Ignore if process cannot be found (kill ESRCH error)
180
- }
181
- });
182
- }
183
- }
184
-
185
- private _getConsoleProcessList(): Promise<number[]> {
186
- return new Promise<number[]>(resolve => {
187
- const agent = fork(path.join(__dirname, 'conpty_console_list_agent'), [ this._innerPid.toString() ]);
188
- agent.on('message', message => {
189
- clearTimeout(timeout);
190
- resolve(message.consoleProcessList);
191
- });
192
- const timeout = setTimeout(() => {
193
- // Something went wrong, just send back the shell PID
194
- agent.kill();
195
- resolve([ this._innerPid ]);
196
- }, 5000);
197
- });
198
- }
199
-
200
- public get exitCode(): number | undefined {
201
- if (this._useConpty) {
202
- return this._exitCode;
203
- }
204
- const winptyExitCode = (this._ptyNative as IWinptyNative).getExitCode(this._innerPid);
205
- return winptyExitCode === -1 ? undefined : winptyExitCode;
206
- }
207
-
208
- private _getWindowsBuildNumber(): number {
209
- const osVersion = (/(\d+)\.(\d+)\.(\d+)/g).exec(os.release());
210
- let buildNumber: number = 0;
211
- if (osVersion && osVersion.length === 4) {
212
- buildNumber = parseInt(osVersion[3]);
213
- }
214
- return buildNumber;
215
- }
216
-
217
- private _generatePipeName(): string {
218
- return `conpty-${Math.random() * 10000000}`;
219
- }
220
-
221
- /**
222
- * Triggered from the native side when a contpy process exits.
223
- */
224
- private _$onProcessExit(exitCode: number): void {
225
- this._exitCode = exitCode;
226
- if (!this._useConptyDll) {
227
- this._flushDataAndCleanUp();
228
- this._outSocket.on('data', () => this._flushDataAndCleanUp());
229
- }
230
- }
231
-
232
- private _flushDataAndCleanUp(): void {
233
- if (this._useConptyDll) {
234
- return;
235
- }
236
- if (this._closeTimeout) {
237
- clearTimeout(this._closeTimeout);
238
- }
239
- this._closeTimeout = setTimeout(() => this._cleanUpProcess(), FLUSH_DATA_INTERVAL);
240
- }
241
-
242
- private _cleanUpProcess(): void {
243
- if (this._useConptyDll) {
244
- return;
245
- }
246
- this._inSocket.readable = false;
247
- this._outSocket.readable = false;
248
- this._outSocket.destroy();
249
- }
250
- }
251
-
252
- // Convert argc/argv into a Win32 command-line following the escaping convention
253
- // documented on MSDN (e.g. see CommandLineToArgvW documentation). Copied from
254
- // winpty project.
255
- export function argsToCommandLine(file: string, args: ArgvOrCommandLine): string {
256
- if (isCommandLine(args)) {
257
- if (args.length === 0) {
258
- return file;
259
- }
260
- return `${argsToCommandLine(file, [])} ${args}`;
261
- }
262
- const argv = [file];
263
- Array.prototype.push.apply(argv, args);
264
- let result = '';
265
- for (let argIndex = 0; argIndex < argv.length; argIndex++) {
266
- if (argIndex > 0) {
267
- result += ' ';
268
- }
269
- const arg = argv[argIndex];
270
- // if it is empty or it contains whitespace and is not already quoted
271
- const hasLopsidedEnclosingQuote = xOr((arg[0] !== '"'), (arg[arg.length - 1] !== '"'));
272
- const hasNoEnclosingQuotes = ((arg[0] !== '"') && (arg[arg.length - 1] !== '"'));
273
- const quote =
274
- arg === '' ||
275
- (arg.indexOf(' ') !== -1 ||
276
- arg.indexOf('\t') !== -1) &&
277
- ((arg.length > 1) &&
278
- (hasLopsidedEnclosingQuote || hasNoEnclosingQuotes));
279
- if (quote) {
280
- result += '\"';
281
- }
282
- let bsCount = 0;
283
- for (let i = 0; i < arg.length; i++) {
284
- const p = arg[i];
285
- if (p === '\\') {
286
- bsCount++;
287
- } else if (p === '"') {
288
- result += repeatText('\\', bsCount * 2 + 1);
289
- result += '"';
290
- bsCount = 0;
291
- } else {
292
- result += repeatText('\\', bsCount);
293
- bsCount = 0;
294
- result += p;
295
- }
296
- }
297
- if (quote) {
298
- result += repeatText('\\', bsCount * 2);
299
- result += '\"';
300
- } else {
301
- result += repeatText('\\', bsCount);
302
- }
303
- }
304
- return result;
305
- }
306
-
307
- function isCommandLine(args: ArgvOrCommandLine): args is string {
308
- return typeof args === 'string';
309
- }
310
-
311
- function repeatText(text: string, count: number): string {
312
- let result = '';
313
- for (let i = 0; i < count; i++) {
314
- result += text;
315
- }
316
- return result;
317
- }
318
-
319
- function xOr(arg1: boolean, arg2: boolean): boolean {
320
- return ((arg1 && !arg2) || (!arg1 && arg2));
321
- }
@@ -1,229 +0,0 @@
1
- /**
2
- * Copyright (c) 2017, Daniel Imms (MIT License).
3
- * Copyright (c) 2018, Microsoft Corporation (MIT License).
4
- */
5
-
6
- import * as fs from 'fs';
7
- import * as assert from 'assert';
8
- import { WindowsTerminal } from './windowsTerminal';
9
- import * as path from 'path';
10
- import * as psList from 'ps-list';
11
-
12
- interface IProcessState {
13
- // Whether the PID must exist or must not exist
14
- [pid: number]: boolean;
15
- }
16
-
17
- interface IWindowsProcessTreeResult {
18
- name: string;
19
- pid: number;
20
- }
21
-
22
- function pollForProcessState(desiredState: IProcessState, intervalMs: number = 100, timeoutMs: number = 2000): Promise<void> {
23
- return new Promise<void>(resolve => {
24
- let tries = 0;
25
- const interval = setInterval(() => {
26
- psList({ all: true }).then(ps => {
27
- let success = true;
28
- const pids = Object.keys(desiredState).map(k => parseInt(k, 10));
29
- console.log('expected pids', JSON.stringify(pids));
30
- pids.forEach(pid => {
31
- if (desiredState[pid]) {
32
- if (!ps.some(p => p.pid === pid)) {
33
- console.log(`pid ${pid} does not exist`);
34
- success = false;
35
- }
36
- } else {
37
- if (ps.some(p => p.pid === pid)) {
38
- console.log(`pid ${pid} still exists`);
39
- success = false;
40
- }
41
- }
42
- });
43
- if (success) {
44
- clearInterval(interval);
45
- resolve();
46
- return;
47
- }
48
- tries++;
49
- if (tries * intervalMs >= timeoutMs) {
50
- clearInterval(interval);
51
- const processListing = pids.map(k => `${k}: ${desiredState[k]}`).join('\n');
52
- assert.fail(`Bad process state, expected:\n${processListing}`);
53
- resolve();
54
- }
55
- });
56
- }, intervalMs);
57
- });
58
- }
59
-
60
- function pollForProcessTreeSize(pid: number, size: number, intervalMs: number = 100, timeoutMs: number = 2000): Promise<IWindowsProcessTreeResult[]> {
61
- return new Promise<IWindowsProcessTreeResult[]>(resolve => {
62
- let tries = 0;
63
- const interval = setInterval(() => {
64
- psList({ all: true }).then(ps => {
65
- const openList: IWindowsProcessTreeResult[] = [];
66
- openList.push(ps.filter(p => p.pid === pid).map(p => {
67
- return { name: p.name, pid: p.pid };
68
- })[0]);
69
- const list: IWindowsProcessTreeResult[] = [];
70
- while (openList.length) {
71
- const current = openList.shift()!;
72
- ps.filter(p => p.ppid === current.pid).map(p => {
73
- return { name: p.name, pid: p.pid };
74
- }).forEach(p => openList.push(p));
75
- list.push(current);
76
- }
77
- console.log('list', JSON.stringify(list));
78
- const success = list.length === size;
79
- if (success) {
80
- clearInterval(interval);
81
- resolve(list);
82
- return;
83
- }
84
- tries++;
85
- if (tries * intervalMs >= timeoutMs) {
86
- clearInterval(interval);
87
- assert.fail(`Bad process state, expected: ${size}, actual: ${list.length}`);
88
- }
89
- });
90
- }, intervalMs);
91
- });
92
- }
93
-
94
- if (process.platform === 'win32') {
95
- [[false, false], [true, false], [true, true]].forEach(([useConpty, useConptyDll]) => {
96
- describe(`WindowsTerminal (useConpty = ${useConpty}, useConptyDll = ${useConptyDll})`, () => {
97
- describe('kill', () => {
98
- it('should not crash parent process', function (done) {
99
- this.timeout(20000);
100
- const term = new WindowsTerminal('cmd.exe', [], { useConpty, useConptyDll });
101
- term.on('exit', () => done());
102
- term.kill();
103
- });
104
- it('should kill the process tree', function (done: Mocha.Done): void {
105
- this.timeout(20000);
106
- const term = new WindowsTerminal('cmd.exe', [], { useConpty, useConptyDll });
107
- // Start sub-processes
108
- term.write('powershell.exe\r');
109
- term.write('node.exe\r');
110
- console.log('start poll for tree size');
111
- pollForProcessTreeSize(term.pid, 3, 500, 5000).then(list => {
112
- assert.strictEqual(list[0].name.toLowerCase(), 'cmd.exe');
113
- assert.strictEqual(list[1].name.toLowerCase(), 'powershell.exe');
114
- assert.strictEqual(list[2].name.toLowerCase(), 'node.exe');
115
- term.kill();
116
- const desiredState: IProcessState = {};
117
- desiredState[list[0].pid] = false;
118
- desiredState[list[1].pid] = false;
119
- desiredState[list[2].pid] = false;
120
- term.on('exit', () => {
121
- pollForProcessState(desiredState, 1000, 5000).then(() => {
122
- done();
123
- });
124
- });
125
- });
126
- });
127
- });
128
-
129
- describe('resize', () => {
130
- it('should throw a non-native exception when resizing an invalid value', function(done) {
131
- this.timeout(20000);
132
- const term = new WindowsTerminal('cmd.exe', [], { useConpty, useConptyDll });
133
- assert.throws(() => term.resize(-1, -1));
134
- assert.throws(() => term.resize(0, 0));
135
- assert.doesNotThrow(() => term.resize(1, 1));
136
- term.on('exit', () => {
137
- done();
138
- });
139
- term.kill();
140
- });
141
- it('should throw a non-native exception when resizing a killed terminal', function(done) {
142
- this.timeout(20000);
143
- const term = new WindowsTerminal('cmd.exe', [], { useConpty, useConptyDll });
144
- (<any>term)._defer(() => {
145
- term.once('exit', () => {
146
- assert.throws(() => term.resize(1, 1));
147
- done();
148
- });
149
- term.destroy();
150
- });
151
- });
152
- });
153
-
154
- describe('Args as CommandLine', () => {
155
- it('should not fail running a file containing a space in the path', function (done) {
156
- this.timeout(10000);
157
- const spaceFolder = path.resolve(__dirname, '..', 'fixtures', 'space folder');
158
- if (!fs.existsSync(spaceFolder)) {
159
- fs.mkdirSync(spaceFolder);
160
- }
161
-
162
- const cmdCopiedPath = path.resolve(spaceFolder, 'cmd.exe');
163
- const data = fs.readFileSync(`${process.env.windir}\\System32\\cmd.exe`);
164
- fs.writeFileSync(cmdCopiedPath, data);
165
-
166
- if (!fs.existsSync(cmdCopiedPath)) {
167
- // Skip test if git bash isn't installed
168
- return;
169
- }
170
- const term = new WindowsTerminal(cmdCopiedPath, '/c echo "hello world"', { useConpty, useConptyDll });
171
- let result = '';
172
- term.on('data', (data) => {
173
- result += data;
174
- });
175
- term.on('exit', () => {
176
- assert.ok(result.indexOf('hello world') >= 1);
177
- done();
178
- });
179
- });
180
- });
181
-
182
- describe('env', () => {
183
- it('should set environment variables of the shell', function (done) {
184
- this.timeout(10000);
185
- const term = new WindowsTerminal('cmd.exe', '/C echo %FOO%', { useConpty, useConptyDll, env: { FOO: 'BAR' }});
186
- let result = '';
187
- term.on('data', (data) => {
188
- result += data;
189
- });
190
- term.on('exit', () => {
191
- assert.ok(result.indexOf('BAR') >= 0);
192
- done();
193
- });
194
- });
195
- });
196
-
197
- describe('On close', () => {
198
- it('should return process zero exit codes', function (done) {
199
- this.timeout(10000);
200
- const term = new WindowsTerminal('cmd.exe', '/C exit', { useConpty, useConptyDll });
201
- term.on('exit', (code) => {
202
- assert.strictEqual(code, 0);
203
- done();
204
- });
205
- });
206
-
207
- it('should return process non-zero exit codes', function (done) {
208
- this.timeout(10000);
209
- const term = new WindowsTerminal('cmd.exe', '/C exit 2', { useConpty, useConptyDll });
210
- term.on('exit', (code) => {
211
- assert.strictEqual(code, 2);
212
- done();
213
- });
214
- });
215
- });
216
-
217
- describe('Write', () => {
218
- it('should accept input', function (done) {
219
- this.timeout(10000);
220
- const term = new WindowsTerminal('cmd.exe', '', { useConpty, useConptyDll });
221
- term.write('exit\r');
222
- term.on('exit', () => {
223
- done();
224
- });
225
- });
226
- });
227
- });
228
- });
229
- }