agent-tower 0.4.0 → 0.4.2

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 (72) hide show
  1. package/node_modules/@shitiandmw/node-pty/LICENSE +69 -0
  2. package/node_modules/@shitiandmw/node-pty/README.md +165 -0
  3. package/node_modules/@shitiandmw/node-pty/lib/conpty_console_list_agent.js +16 -0
  4. package/node_modules/@shitiandmw/node-pty/lib/conpty_console_list_agent.js.map +1 -0
  5. package/node_modules/@shitiandmw/node-pty/lib/eventEmitter2.js +47 -0
  6. package/node_modules/@shitiandmw/node-pty/lib/eventEmitter2.js.map +1 -0
  7. package/node_modules/@shitiandmw/node-pty/lib/eventEmitter2.test.js +30 -0
  8. package/node_modules/@shitiandmw/node-pty/lib/eventEmitter2.test.js.map +1 -0
  9. package/node_modules/@shitiandmw/node-pty/lib/index.js +52 -0
  10. package/node_modules/@shitiandmw/node-pty/lib/index.js.map +1 -0
  11. package/node_modules/@shitiandmw/node-pty/lib/interfaces.js +7 -0
  12. package/node_modules/@shitiandmw/node-pty/lib/interfaces.js.map +1 -0
  13. package/node_modules/@shitiandmw/node-pty/lib/shared/conout.js +11 -0
  14. package/node_modules/@shitiandmw/node-pty/lib/shared/conout.js.map +1 -0
  15. package/node_modules/@shitiandmw/node-pty/lib/terminal.js +190 -0
  16. package/node_modules/@shitiandmw/node-pty/lib/terminal.js.map +1 -0
  17. package/node_modules/@shitiandmw/node-pty/lib/terminal.test.js +139 -0
  18. package/node_modules/@shitiandmw/node-pty/lib/terminal.test.js.map +1 -0
  19. package/node_modules/@shitiandmw/node-pty/lib/testUtils.test.js +28 -0
  20. package/node_modules/@shitiandmw/node-pty/lib/testUtils.test.js.map +1 -0
  21. package/node_modules/@shitiandmw/node-pty/lib/types.js +7 -0
  22. package/node_modules/@shitiandmw/node-pty/lib/types.js.map +1 -0
  23. package/node_modules/@shitiandmw/node-pty/lib/unixTerminal.js +346 -0
  24. package/node_modules/@shitiandmw/node-pty/lib/unixTerminal.js.map +1 -0
  25. package/node_modules/@shitiandmw/node-pty/lib/unixTerminal.test.js +351 -0
  26. package/node_modules/@shitiandmw/node-pty/lib/unixTerminal.test.js.map +1 -0
  27. package/node_modules/@shitiandmw/node-pty/lib/utils.js +39 -0
  28. package/node_modules/@shitiandmw/node-pty/lib/utils.js.map +1 -0
  29. package/node_modules/@shitiandmw/node-pty/lib/windowsConoutConnection.js +125 -0
  30. package/node_modules/@shitiandmw/node-pty/lib/windowsConoutConnection.js.map +1 -0
  31. package/node_modules/@shitiandmw/node-pty/lib/windowsPtyAgent.js +320 -0
  32. package/node_modules/@shitiandmw/node-pty/lib/windowsPtyAgent.js.map +1 -0
  33. package/node_modules/@shitiandmw/node-pty/lib/windowsPtyAgent.test.js +90 -0
  34. package/node_modules/@shitiandmw/node-pty/lib/windowsPtyAgent.test.js.map +1 -0
  35. package/node_modules/@shitiandmw/node-pty/lib/windowsTerminal.js +199 -0
  36. package/node_modules/@shitiandmw/node-pty/lib/windowsTerminal.js.map +1 -0
  37. package/node_modules/@shitiandmw/node-pty/lib/windowsTerminal.test.js +219 -0
  38. package/node_modules/@shitiandmw/node-pty/lib/windowsTerminal.test.js.map +1 -0
  39. package/node_modules/@shitiandmw/node-pty/lib/worker/conoutSocketWorker.js +22 -0
  40. package/node_modules/@shitiandmw/node-pty/lib/worker/conoutSocketWorker.js.map +1 -0
  41. package/node_modules/@shitiandmw/node-pty/package.json +66 -0
  42. package/node_modules/@shitiandmw/node-pty/prebuilds/darwin-arm64/pty.node +0 -0
  43. package/node_modules/@shitiandmw/node-pty/prebuilds/darwin-arm64/spawn-helper +0 -0
  44. package/node_modules/@shitiandmw/node-pty/prebuilds/darwin-x64/pty.node +0 -0
  45. package/node_modules/@shitiandmw/node-pty/prebuilds/darwin-x64/spawn-helper +0 -0
  46. package/node_modules/@shitiandmw/node-pty/prebuilds/linux-arm64/pty.node +0 -0
  47. package/node_modules/@shitiandmw/node-pty/prebuilds/linux-x64/pty.node +0 -0
  48. package/node_modules/@shitiandmw/node-pty/prebuilds/win32-arm64/conpty/OpenConsole.exe +0 -0
  49. package/node_modules/@shitiandmw/node-pty/prebuilds/win32-arm64/conpty/conpty.dll +0 -0
  50. package/node_modules/@shitiandmw/node-pty/prebuilds/win32-arm64/conpty.node +0 -0
  51. package/node_modules/@shitiandmw/node-pty/prebuilds/win32-arm64/conpty_console_list.node +0 -0
  52. package/node_modules/@shitiandmw/node-pty/prebuilds/win32-arm64/pty.node +0 -0
  53. package/node_modules/@shitiandmw/node-pty/prebuilds/win32-arm64/winpty-agent.exe +0 -0
  54. package/node_modules/@shitiandmw/node-pty/prebuilds/win32-arm64/winpty.dll +0 -0
  55. package/node_modules/@shitiandmw/node-pty/prebuilds/win32-x64/conpty/OpenConsole.exe +0 -0
  56. package/node_modules/@shitiandmw/node-pty/prebuilds/win32-x64/conpty/conpty.dll +0 -0
  57. package/node_modules/@shitiandmw/node-pty/prebuilds/win32-x64/conpty.node +0 -0
  58. package/node_modules/@shitiandmw/node-pty/prebuilds/win32-x64/conpty_console_list.node +0 -0
  59. package/node_modules/@shitiandmw/node-pty/prebuilds/win32-x64/pty.node +0 -0
  60. package/node_modules/@shitiandmw/node-pty/prebuilds/win32-x64/winpty-agent.exe +0 -0
  61. package/node_modules/@shitiandmw/node-pty/prebuilds/win32-x64/winpty.dll +0 -0
  62. package/node_modules/@shitiandmw/node-pty/scripts/gen-compile-commands.js +8 -0
  63. package/node_modules/@shitiandmw/node-pty/scripts/increment-version.js +54 -0
  64. package/node_modules/@shitiandmw/node-pty/scripts/post-install.js +80 -0
  65. package/node_modules/@shitiandmw/node-pty/scripts/prebuild.js +34 -0
  66. package/node_modules/@shitiandmw/node-pty/scripts/verify-darwin-fd-leak.js +68 -0
  67. package/node_modules/@shitiandmw/node-pty/third_party/conpty/1.23.251008001/win10-arm64/OpenConsole.exe +0 -0
  68. package/node_modules/@shitiandmw/node-pty/third_party/conpty/1.23.251008001/win10-arm64/conpty.dll +0 -0
  69. package/node_modules/@shitiandmw/node-pty/third_party/conpty/1.23.251008001/win10-x64/OpenConsole.exe +0 -0
  70. package/node_modules/@shitiandmw/node-pty/third_party/conpty/1.23.251008001/win10-x64/conpty.dll +0 -0
  71. package/node_modules/@shitiandmw/node-pty/typings/node-pty.d.ts +215 -0
  72. package/package.json +4 -2
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2017, Daniel Imms (MIT License).
4
+ * Copyright (c) 2018, Microsoft Corporation (MIT License).
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ var fs = require("fs");
8
+ var assert = require("assert");
9
+ var windowsTerminal_1 = require("./windowsTerminal");
10
+ var path = require("path");
11
+ var psList = require("ps-list");
12
+ function pollForProcessState(desiredState, intervalMs, timeoutMs) {
13
+ if (intervalMs === void 0) { intervalMs = 100; }
14
+ if (timeoutMs === void 0) { timeoutMs = 2000; }
15
+ return new Promise(function (resolve) {
16
+ var tries = 0;
17
+ var interval = setInterval(function () {
18
+ psList({ all: true }).then(function (ps) {
19
+ var success = true;
20
+ var pids = Object.keys(desiredState).map(function (k) { return parseInt(k, 10); });
21
+ console.log('expected pids', JSON.stringify(pids));
22
+ pids.forEach(function (pid) {
23
+ if (desiredState[pid]) {
24
+ if (!ps.some(function (p) { return p.pid === pid; })) {
25
+ console.log("pid " + pid + " does not exist");
26
+ success = false;
27
+ }
28
+ }
29
+ else {
30
+ if (ps.some(function (p) { return p.pid === pid; })) {
31
+ console.log("pid " + pid + " still exists");
32
+ success = false;
33
+ }
34
+ }
35
+ });
36
+ if (success) {
37
+ clearInterval(interval);
38
+ resolve();
39
+ return;
40
+ }
41
+ tries++;
42
+ if (tries * intervalMs >= timeoutMs) {
43
+ clearInterval(interval);
44
+ var processListing = pids.map(function (k) { return k + ": " + desiredState[k]; }).join('\n');
45
+ assert.fail("Bad process state, expected:\n" + processListing);
46
+ resolve();
47
+ }
48
+ });
49
+ }, intervalMs);
50
+ });
51
+ }
52
+ function pollForProcessTreeSize(pid, size, intervalMs, timeoutMs) {
53
+ if (intervalMs === void 0) { intervalMs = 100; }
54
+ if (timeoutMs === void 0) { timeoutMs = 2000; }
55
+ return new Promise(function (resolve) {
56
+ var tries = 0;
57
+ var interval = setInterval(function () {
58
+ psList({ all: true }).then(function (ps) {
59
+ var openList = [];
60
+ openList.push(ps.filter(function (p) { return p.pid === pid; }).map(function (p) {
61
+ return { name: p.name, pid: p.pid };
62
+ })[0]);
63
+ var list = [];
64
+ var _loop_1 = function () {
65
+ var current = openList.shift();
66
+ ps.filter(function (p) { return p.ppid === current.pid; }).map(function (p) {
67
+ return { name: p.name, pid: p.pid };
68
+ }).forEach(function (p) { return openList.push(p); });
69
+ list.push(current);
70
+ };
71
+ while (openList.length) {
72
+ _loop_1();
73
+ }
74
+ console.log('list', JSON.stringify(list));
75
+ var success = list.length === size;
76
+ if (success) {
77
+ clearInterval(interval);
78
+ resolve(list);
79
+ return;
80
+ }
81
+ tries++;
82
+ if (tries * intervalMs >= timeoutMs) {
83
+ clearInterval(interval);
84
+ assert.fail("Bad process state, expected: " + size + ", actual: " + list.length);
85
+ }
86
+ });
87
+ }, intervalMs);
88
+ });
89
+ }
90
+ if (process.platform === 'win32') {
91
+ [[false, false], [true, false], [true, true]].forEach(function (_a) {
92
+ var useConpty = _a[0], useConptyDll = _a[1];
93
+ describe("WindowsTerminal (useConpty = " + useConpty + ", useConptyDll = " + useConptyDll + ")", function () {
94
+ describe('kill', function () {
95
+ it('should not crash parent process', function (done) {
96
+ this.timeout(20000);
97
+ var term = new windowsTerminal_1.WindowsTerminal('cmd.exe', [], { useConpty: useConpty, useConptyDll: useConptyDll });
98
+ term.on('exit', function () { return done(); });
99
+ term.kill();
100
+ });
101
+ it('should kill the process tree', function (done) {
102
+ this.timeout(20000);
103
+ var term = new windowsTerminal_1.WindowsTerminal('cmd.exe', [], { useConpty: useConpty, useConptyDll: useConptyDll });
104
+ // Start sub-processes
105
+ term.write('powershell.exe\r');
106
+ term.write('node.exe\r');
107
+ console.log('start poll for tree size');
108
+ pollForProcessTreeSize(term.pid, 3, 500, 5000).then(function (list) {
109
+ assert.strictEqual(list[0].name.toLowerCase(), 'cmd.exe');
110
+ assert.strictEqual(list[1].name.toLowerCase(), 'powershell.exe');
111
+ assert.strictEqual(list[2].name.toLowerCase(), 'node.exe');
112
+ term.kill();
113
+ var desiredState = {};
114
+ desiredState[list[0].pid] = false;
115
+ desiredState[list[1].pid] = false;
116
+ desiredState[list[2].pid] = false;
117
+ term.on('exit', function () {
118
+ pollForProcessState(desiredState, 1000, 5000).then(function () {
119
+ done();
120
+ });
121
+ });
122
+ });
123
+ });
124
+ });
125
+ describe('resize', function () {
126
+ it('should throw a non-native exception when resizing an invalid value', function (done) {
127
+ this.timeout(20000);
128
+ var term = new windowsTerminal_1.WindowsTerminal('cmd.exe', [], { useConpty: useConpty, useConptyDll: useConptyDll });
129
+ assert.throws(function () { return term.resize(-1, -1); });
130
+ assert.throws(function () { return term.resize(0, 0); });
131
+ assert.doesNotThrow(function () { return term.resize(1, 1); });
132
+ term.on('exit', function () {
133
+ done();
134
+ });
135
+ term.kill();
136
+ });
137
+ it('should throw a non-native exception when resizing a killed terminal', function (done) {
138
+ this.timeout(20000);
139
+ var term = new windowsTerminal_1.WindowsTerminal('cmd.exe', [], { useConpty: useConpty, useConptyDll: useConptyDll });
140
+ term._defer(function () {
141
+ term.once('exit', function () {
142
+ assert.throws(function () { return term.resize(1, 1); });
143
+ done();
144
+ });
145
+ term.destroy();
146
+ });
147
+ });
148
+ });
149
+ describe('Args as CommandLine', function () {
150
+ it('should not fail running a file containing a space in the path', function (done) {
151
+ this.timeout(10000);
152
+ var spaceFolder = path.resolve(__dirname, '..', 'fixtures', 'space folder');
153
+ if (!fs.existsSync(spaceFolder)) {
154
+ fs.mkdirSync(spaceFolder);
155
+ }
156
+ var cmdCopiedPath = path.resolve(spaceFolder, 'cmd.exe');
157
+ var data = fs.readFileSync(process.env.windir + "\\System32\\cmd.exe");
158
+ fs.writeFileSync(cmdCopiedPath, data);
159
+ if (!fs.existsSync(cmdCopiedPath)) {
160
+ // Skip test if git bash isn't installed
161
+ return;
162
+ }
163
+ var term = new windowsTerminal_1.WindowsTerminal(cmdCopiedPath, '/c echo "hello world"', { useConpty: useConpty, useConptyDll: useConptyDll });
164
+ var result = '';
165
+ term.on('data', function (data) {
166
+ result += data;
167
+ });
168
+ term.on('exit', function () {
169
+ assert.ok(result.indexOf('hello world') >= 1);
170
+ done();
171
+ });
172
+ });
173
+ });
174
+ describe('env', function () {
175
+ it('should set environment variables of the shell', function (done) {
176
+ this.timeout(10000);
177
+ var term = new windowsTerminal_1.WindowsTerminal('cmd.exe', '/C echo %FOO%', { useConpty: useConpty, useConptyDll: useConptyDll, env: { FOO: 'BAR' } });
178
+ var result = '';
179
+ term.on('data', function (data) {
180
+ result += data;
181
+ });
182
+ term.on('exit', function () {
183
+ assert.ok(result.indexOf('BAR') >= 0);
184
+ done();
185
+ });
186
+ });
187
+ });
188
+ describe('On close', function () {
189
+ it('should return process zero exit codes', function (done) {
190
+ this.timeout(10000);
191
+ var term = new windowsTerminal_1.WindowsTerminal('cmd.exe', '/C exit', { useConpty: useConpty, useConptyDll: useConptyDll });
192
+ term.on('exit', function (code) {
193
+ assert.strictEqual(code, 0);
194
+ done();
195
+ });
196
+ });
197
+ it('should return process non-zero exit codes', function (done) {
198
+ this.timeout(10000);
199
+ var term = new windowsTerminal_1.WindowsTerminal('cmd.exe', '/C exit 2', { useConpty: useConpty, useConptyDll: useConptyDll });
200
+ term.on('exit', function (code) {
201
+ assert.strictEqual(code, 2);
202
+ done();
203
+ });
204
+ });
205
+ });
206
+ describe('Write', function () {
207
+ it('should accept input', function (done) {
208
+ this.timeout(10000);
209
+ var term = new windowsTerminal_1.WindowsTerminal('cmd.exe', '', { useConpty: useConpty, useConptyDll: useConptyDll });
210
+ term.write('exit\r');
211
+ term.on('exit', function () {
212
+ done();
213
+ });
214
+ });
215
+ });
216
+ });
217
+ });
218
+ }
219
+ //# sourceMappingURL=windowsTerminal.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"windowsTerminal.test.js","sourceRoot":"","sources":["../src/windowsTerminal.test.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAEH,uBAAyB;AACzB,+BAAiC;AACjC,qDAAoD;AACpD,2BAA6B;AAC7B,gCAAkC;AAYlC,SAAS,mBAAmB,CAAC,YAA2B,EAAE,UAAwB,EAAE,SAAwB;IAAlD,2BAAA,EAAA,gBAAwB;IAAE,0BAAA,EAAA,gBAAwB;IAC1G,OAAO,IAAI,OAAO,CAAO,UAAA,OAAO;QAC9B,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,IAAM,QAAQ,GAAG,WAAW,CAAC;YAC3B,MAAM,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,UAAA,EAAE;gBAC3B,IAAI,OAAO,GAAG,IAAI,CAAC;gBACnB,IAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,EAAf,CAAe,CAAC,CAAC;gBACjE,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;gBACnD,IAAI,CAAC,OAAO,CAAC,UAAA,GAAG;oBACd,IAAI,YAAY,CAAC,GAAG,CAAC,EAAE;wBACrB,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,GAAG,KAAK,GAAG,EAAb,CAAa,CAAC,EAAE;4BAChC,OAAO,CAAC,GAAG,CAAC,SAAO,GAAG,oBAAiB,CAAC,CAAC;4BACzC,OAAO,GAAG,KAAK,CAAC;yBACjB;qBACF;yBAAM;wBACL,IAAI,EAAE,CAAC,IAAI,CAAC,UAAA,CAAC,IAAI,OAAA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IAAI,EAAE,CAAC,CAAC,CAAC;wBAC5B,IAAI,EAAE,CAAC;oBACT,CAAC,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,QAAQ,CAAC,OAAO,EAAE;gBAChB,EAAE,CAAC,qBAAqB,EAAE,UAAU,IAAI;oBACtC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;oBACpB,IAAM,IAAI,GAAG,IAAI,iCAAe,CAAC,SAAS,EAAE,EAAE,EAAE,EAAE,SAAS,WAAA,EAAE,YAAY,cAAA,EAAE,CAAC,CAAC;oBAC7E,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;oBACrB,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE;wBACd,IAAI,EAAE,CAAC;oBACT,CAAC,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;CACJ"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2020, Microsoft Corporation (MIT License).
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var worker_threads_1 = require("worker_threads");
7
+ var net_1 = require("net");
8
+ var conout_1 = require("../shared/conout");
9
+ var conoutPipeName = worker_threads_1.workerData.conoutPipeName;
10
+ var conoutSocket = new net_1.Socket();
11
+ conoutSocket.setEncoding('utf8');
12
+ conoutSocket.connect(conoutPipeName, function () {
13
+ var server = net_1.createServer(function (workerSocket) {
14
+ conoutSocket.pipe(workerSocket);
15
+ });
16
+ server.listen(conout_1.getWorkerPipeName(conoutPipeName));
17
+ if (!worker_threads_1.parentPort) {
18
+ throw new Error('worker_threads parentPort is null');
19
+ }
20
+ worker_threads_1.parentPort.postMessage(1 /* READY */);
21
+ });
22
+ //# sourceMappingURL=conoutSocketWorker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conoutSocketWorker.js","sourceRoot":"","sources":["../../src/worker/conoutSocketWorker.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAEH,iDAAwD;AACxD,2BAA2C;AAC3C,2CAAuF;AAE/E,IAAA,cAAc,GAAM,2BAA0B,eAAhC,CAAiC;AAEvD,IAAM,YAAY,GAAG,IAAI,YAAM,EAAE,CAAC;AAClC,YAAY,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AACjC,YAAY,CAAC,OAAO,CAAC,cAAc,EAAE;IACnC,IAAM,MAAM,GAAG,kBAAY,CAAC,UAAA,YAAY;QACtC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,MAAM,CAAC,0BAAiB,CAAC,cAAc,CAAC,CAAC,CAAC;IACjD,IAAI,CAAC,2BAAU,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;KACtD;IACD,2BAAU,CAAC,WAAW,eAA2B,CAAC;AACpD,CAAC,CAAC,CAAC"}
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@shitiandmw/node-pty",
3
+ "description": "Fork pseudoterminals in Node.JS",
4
+ "author": {
5
+ "name": "Microsoft Corporation"
6
+ },
7
+ "version": "1.1.0-shitiandmw.2",
8
+ "license": "MIT",
9
+ "main": "./lib/index.js",
10
+ "types": "./typings/node-pty.d.ts",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/shitiandmw/node-pty.git"
14
+ },
15
+ "files": [
16
+ "binding.gyp",
17
+ "lib/",
18
+ "scripts/",
19
+ "src/",
20
+ "deps/",
21
+ "prebuilds/",
22
+ "third_party/",
23
+ "typings/"
24
+ ],
25
+ "homepage": "https://github.com/shitiandmw/node-pty",
26
+ "bugs": {
27
+ "url": "https://github.com/shitiandmw/node-pty/issues"
28
+ },
29
+ "keywords": [
30
+ "pty",
31
+ "tty",
32
+ "terminal",
33
+ "pseudoterminal",
34
+ "forkpty",
35
+ "openpty"
36
+ ],
37
+ "scripts": {
38
+ "build": "tsc -b ./src/tsconfig.json",
39
+ "watch": "tsc -b -w ./src/tsconfig.json",
40
+ "lint": "eslint -c .eslintrc.js --ext .ts src/",
41
+ "compileCommands": "node scripts/gen-compile-commands.js",
42
+ "verify:darwin-fd-leak": "node scripts/verify-darwin-fd-leak.js",
43
+ "test": "cross-env NODE_ENV=test mocha -R spec --exit lib/*.test.js",
44
+ "posttest": "npm run lint",
45
+ "prepare": "npm run build",
46
+ "prepublishOnly": "npm run build"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "dependencies": {
52
+ "node-addon-api": "^7.1.0"
53
+ },
54
+ "devDependencies": {
55
+ "@types/mocha": "^7.0.2",
56
+ "@types/node": "12",
57
+ "@typescript-eslint/eslint-plugin": "^2.27.0",
58
+ "@typescript-eslint/parser": "^2.27.0",
59
+ "cross-env": "^5.1.4",
60
+ "eslint": "^6.8.0",
61
+ "mocha": "10",
62
+ "node-gyp": "^11.4.2",
63
+ "ps-list": "^6.0.0",
64
+ "typescript": "^3.8.3"
65
+ }
66
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) 2025, Microsoft Corporation (MIT License).
3
+ */
4
+
5
+ const { execSync } = require('child_process');
6
+
7
+ console.log(`\x1b[32m> Generating compile_commands.json...\x1b[0m`);
8
+ execSync('npx --offline node-gyp configure -- -f compile_commands_json');
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Copyright (c) 2019, Microsoft Corporation (MIT License).
3
+ */
4
+
5
+ const cp = require('child_process');
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+ const packageJson = require('../package.json');
9
+
10
+ // Determine if this is a stable or beta release
11
+ const publishedVersions = getPublishedVersions();
12
+ const isStableRelease = !publishedVersions.includes(packageJson.version);
13
+
14
+ // Get the next version
15
+ const nextVersion = isStableRelease ? packageJson.version : getNextBetaVersion();
16
+ console.log(`Setting version to ${nextVersion}`);
17
+
18
+ // Set the version in package.json
19
+ const packageJsonFile = path.resolve(__dirname, '..', 'package.json');
20
+ packageJson.version = nextVersion;
21
+ fs.writeFileSync(packageJsonFile, JSON.stringify(packageJson, null, 2));
22
+
23
+ function getNextBetaVersion() {
24
+ if (!/^[0-9]+\.[0-9]+\.[0-9]+$/.exec(packageJson.version)) {
25
+ console.error('The package.json version must be of the form x.y.z');
26
+ process.exit(1);
27
+ }
28
+ const tag = 'beta';
29
+ const stableVersion = packageJson.version.split('.');
30
+ const nextStableVersion = `${stableVersion[0]}.${parseInt(stableVersion[1]) + 1}.0`;
31
+ const publishedVersions = getPublishedVersions(nextStableVersion, tag);
32
+ if (publishedVersions.length === 0) {
33
+ return `${nextStableVersion}-${tag}1`;
34
+ }
35
+ const latestPublishedVersion = publishedVersions.sort((a, b) => {
36
+ const aVersion = parseInt(a.substr(a.search(/[0-9]+$/)));
37
+ const bVersion = parseInt(b.substr(b.search(/[0-9]+$/)));
38
+ return aVersion > bVersion ? -1 : 1;
39
+ })[0];
40
+ const latestTagVersion = parseInt(latestPublishedVersion.substr(latestPublishedVersion.search(/[0-9]+$/)), 10);
41
+ return `${nextStableVersion}-${tag}${latestTagVersion + 1}`;
42
+ }
43
+
44
+ function getPublishedVersions(version, tag) {
45
+ const isWin32 = process.platform === 'win32';
46
+ const versionsProcess = isWin32 ?
47
+ cp.spawnSync('npm.cmd', ['view', packageJson.name, 'versions', '--json'], { shell: true }) :
48
+ cp.spawnSync('npm', ['view', packageJson.name, 'versions', '--json']);
49
+ const versionsJson = JSON.parse(versionsProcess.stdout);
50
+ if (tag) {
51
+ return versionsJson.filter(v => !v.search(new RegExp(`${version}-${tag}[0-9]+`)));
52
+ }
53
+ return versionsJson;
54
+ }
@@ -0,0 +1,80 @@
1
+ //@ts-check
2
+
3
+ const fs = require('fs');
4
+ const os = require('os');
5
+ const path = require('path');
6
+
7
+ const RELEASE_DIR = path.join(__dirname, '../build/Release');
8
+ const BUILD_FILES = [
9
+ path.join(RELEASE_DIR, 'conpty.node'),
10
+ path.join(RELEASE_DIR, 'conpty.pdb'),
11
+ path.join(RELEASE_DIR, 'conpty_console_list.node'),
12
+ path.join(RELEASE_DIR, 'conpty_console_list.pdb'),
13
+ path.join(RELEASE_DIR, 'pty.node'),
14
+ path.join(RELEASE_DIR, 'pty.pdb'),
15
+ path.join(RELEASE_DIR, 'spawn-helper'),
16
+ path.join(RELEASE_DIR, 'winpty-agent.exe'),
17
+ path.join(RELEASE_DIR, 'winpty-agent.pdb'),
18
+ path.join(RELEASE_DIR, 'winpty.dll'),
19
+ path.join(RELEASE_DIR, 'winpty.pdb')
20
+ ];
21
+ const CONPTY_DIR = path.join(__dirname, '../third_party/conpty');
22
+ const CONPTY_SUPPORTED_ARCH = ['x64', 'arm64'];
23
+
24
+ console.log('\x1b[32m> Cleaning release folder...\x1b[0m');
25
+
26
+ /** @param {string} folder */
27
+ function cleanFolderRecursive(folder) {
28
+ var files = [];
29
+ if (fs.existsSync(folder)) {
30
+ files = fs.readdirSync(folder);
31
+ files.forEach(function(file,index) {
32
+ var curPath = path.join(folder, file);
33
+ if (fs.lstatSync(curPath).isDirectory()) { // recurse
34
+ cleanFolderRecursive(curPath);
35
+ fs.rmdirSync(curPath);
36
+ } else if (BUILD_FILES.indexOf(curPath) < 0){ // delete file
37
+ fs.unlinkSync(curPath);
38
+ }
39
+ });
40
+ }
41
+ };
42
+
43
+ try {
44
+ cleanFolderRecursive(RELEASE_DIR);
45
+ } catch(e) {
46
+ console.log(e);
47
+ process.exit(1);
48
+ }
49
+
50
+ console.log(`\x1b[32m> Moving conpty.dll...\x1b[0m`);
51
+ if (os.platform() !== 'win32') {
52
+ console.log(' SKIPPED (not Windows)');
53
+ } else {
54
+ let windowsArch;
55
+ if (process.env.npm_config_arch) {
56
+ windowsArch = process.env.npm_config_arch;
57
+ console.log(` Using $npm_config_arch: ${windowsArch}`);
58
+ } else {
59
+ windowsArch = os.arch();
60
+ console.log(` Using os.arch(): ${windowsArch}`);
61
+ }
62
+
63
+ if (!CONPTY_SUPPORTED_ARCH.includes(windowsArch)) {
64
+ console.log(` SKIPPED (unsupported architecture ${windowsArch})`);
65
+ } else {
66
+ const versionFolder = fs.readdirSync(CONPTY_DIR)[0];
67
+ console.log(` Found version ${versionFolder}`);
68
+ const sourceFolder = path.join(CONPTY_DIR, versionFolder, `win10-${windowsArch}`);
69
+ const destFolder = path.join(RELEASE_DIR, 'conpty');
70
+ fs.mkdirSync(destFolder, { recursive: true });
71
+ for (const file of ['conpty.dll', 'OpenConsole.exe']) {
72
+ const sourceFile = path.join(sourceFolder, file);
73
+ const destFile = path.join(destFolder, file);
74
+ console.log(` Copying ${sourceFile} -> ${destFile}`);
75
+ fs.copyFileSync(sourceFile, destFile);
76
+ }
77
+ }
78
+ }
79
+
80
+ process.exit(0);
@@ -0,0 +1,34 @@
1
+ //@ts-check
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ /**
7
+ * This script checks for the prebuilt binaries for the current platform and
8
+ * architecture. It exits with 0 if prebuilds are found and 1 if not.
9
+ *
10
+ * If npm_config_build_from_source is set then it removes the prebuilds for the
11
+ * current platform so they are not loaded at runtime.
12
+ *
13
+ * Usage:
14
+ * node scripts/prebuild.js
15
+ */
16
+
17
+ const PREBUILDS_ROOT = path.join(__dirname, '..', 'prebuilds');
18
+ const PREBUILD_DIR = path.join(__dirname, '..', 'prebuilds', `${process.platform}-${process.arch}`);
19
+
20
+ // Do not use prebuilds when npm_config_build_from_source is set
21
+ if (process.env.npm_config_build_from_source === 'true') {
22
+ console.log('\x1b[33m> Removing prebuilds and rebuilding because npm_config_build_from_source is set\x1b[0m');
23
+ fs.rmSync(PREBUILDS_ROOT, { recursive: true, force: true });
24
+ process.exit(1);
25
+ }
26
+
27
+ // Check whether the correct prebuilt files exist
28
+ console.log('\x1b[32m> Checking prebuilds...\x1b[0m');
29
+ if (!fs.existsSync(PREBUILD_DIR)) {
30
+ console.log(`\x1b[33m> Rebuilding because directory ${PREBUILD_DIR} does not exist\x1b[0m`);
31
+ process.exit(1);
32
+ }
33
+
34
+ process.exit(0);
@@ -0,0 +1,68 @@
1
+ //@ts-check
2
+
3
+ const fs = require('fs');
4
+ const moduleTarget = process.env.PTY_REQUIRE_PATH || '../lib/index';
5
+ const pty = require(moduleTarget);
6
+
7
+ function fdCount() {
8
+ try {
9
+ return fs.readdirSync('/dev/fd').length;
10
+ } catch {
11
+ return -1;
12
+ }
13
+ }
14
+
15
+ async function main() {
16
+ const iterations = Number(process.env.PTY_ITERATIONS || 100);
17
+ const sampleEvery = Number(process.env.PTY_SAMPLE_EVERY || 20);
18
+ const shell = process.env.SHELL || '/bin/zsh';
19
+
20
+ console.log(`module ${moduleTarget}`);
21
+ console.log(`start fd ${fdCount()}`);
22
+
23
+ for (let i = 0; i < iterations; i++) {
24
+ const term = pty.spawn(shell, [], {
25
+ name: 'xterm-256color',
26
+ cols: 80,
27
+ rows: 24,
28
+ cwd: process.cwd(),
29
+ env: process.env,
30
+ });
31
+
32
+ await new Promise((resolve, reject) => {
33
+ let settled = false;
34
+ const timeout = setTimeout(() => {
35
+ if (settled) {
36
+ return;
37
+ }
38
+ settled = true;
39
+ try {
40
+ term.kill();
41
+ } catch {}
42
+ reject(new Error(`Timed out waiting for PTY exit at iteration ${i + 1}`));
43
+ }, 5000);
44
+
45
+ term.onExit(() => {
46
+ if (settled) {
47
+ return;
48
+ }
49
+ settled = true;
50
+ clearTimeout(timeout);
51
+ resolve();
52
+ });
53
+
54
+ setTimeout(() => term.write('exit\r'), 10);
55
+ });
56
+
57
+ if ((i + 1) % sampleEvery === 0 || i === 0 || i + 1 === iterations) {
58
+ console.log(`iter ${i + 1} fd ${fdCount()}`);
59
+ }
60
+ }
61
+
62
+ console.log(`end fd ${fdCount()}`);
63
+ }
64
+
65
+ main().catch((error) => {
66
+ console.error(error instanceof Error ? error.stack || error.message : String(error));
67
+ process.exit(1);
68
+ });