node-pty 1.1.0-beta4 → 1.1.0-beta40
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/README.md +6 -4
- package/binding.gyp +10 -20
- package/deps/winpty/src/agent/Agent.cc +11 -3
- package/deps/winpty/src/winpty.gyp +29 -1
- package/lib/conpty_console_list_agent.js +3 -7
- package/lib/conpty_console_list_agent.js.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/terminal.js.map +1 -1
- package/lib/terminal.test.js.map +1 -1
- package/lib/unixTerminal.js +7 -44
- package/lib/unixTerminal.js.map +1 -1
- package/lib/unixTerminal.test.js +3 -5
- package/lib/unixTerminal.test.js.map +1 -1
- package/lib/utils.js +23 -1
- package/lib/utils.js.map +1 -1
- package/lib/windowsConoutConnection.js +6 -3
- package/lib/windowsConoutConnection.js.map +1 -1
- package/lib/windowsPtyAgent.js +45 -48
- package/lib/windowsPtyAgent.js.map +1 -1
- package/lib/windowsTerminal.js +1 -1
- package/lib/windowsTerminal.js.map +1 -1
- package/lib/windowsTerminal.test.js +40 -26
- package/lib/windowsTerminal.test.js.map +1 -1
- package/lib/worker/conoutSocketWorker.js.map +1 -1
- package/package.json +7 -2
- package/scripts/gen-compile-commands.js +8 -0
- package/scripts/{publish.js → increment-version.js} +7 -15
- package/scripts/post-install.js +48 -10
- package/scripts/prebuild.js +35 -0
- package/src/conpty_console_list_agent.ts +2 -6
- package/src/index.ts +2 -1
- package/src/interfaces.ts +2 -1
- package/src/native.d.ts +5 -5
- package/src/terminal.test.ts +1 -1
- package/src/terminal.ts +2 -2
- package/src/unix/pty.cc +244 -284
- package/src/unixTerminal.test.ts +3 -6
- package/src/unixTerminal.ts +9 -36
- package/src/utils.ts +20 -0
- package/src/win/conpty.cc +268 -187
- package/src/win/conpty.h +41 -0
- package/src/win/conpty_console_list.cc +16 -15
- package/src/win/path_util.cc +39 -36
- package/src/win/path_util.h +5 -2
- package/src/win/winpty.cc +108 -151
- package/src/windowsConoutConnection.ts +6 -3
- package/src/windowsPtyAgent.ts +42 -43
- package/src/windowsTerminal.test.ts +46 -33
- package/src/windowsTerminal.ts +3 -3
- package/src/worker/conoutSocketWorker.ts +2 -2
- package/third_party/conpty/1.23.251008001/win10-arm64/OpenConsole.exe +0 -0
- package/third_party/conpty/1.23.251008001/win10-arm64/conpty.dll +0 -0
- package/third_party/conpty/1.23.251008001/win10-x64/OpenConsole.exe +0 -0
- package/third_party/conpty/1.23.251008001/win10-x64/conpty.dll +0 -0
- package/typings/node-pty.d.ts +9 -1
package/src/unixTerminal.test.ts
CHANGED
|
@@ -272,10 +272,9 @@ if (process.platform !== 'win32') {
|
|
|
272
272
|
ptyProcess.on('data', function (data) {
|
|
273
273
|
if (ptyProcess.process === 'Python') {
|
|
274
274
|
console.log('title', ptyProcess.process);
|
|
275
|
+
console.log('ready', ptyProcess.pid);
|
|
275
276
|
}
|
|
276
277
|
});
|
|
277
|
-
setTimeout(() => null, 500);
|
|
278
|
-
console.log('ready', ptyProcess.pid);
|
|
279
278
|
`;
|
|
280
279
|
const p = cp.spawn('node', ['-e', data]);
|
|
281
280
|
let sub = '';
|
|
@@ -283,12 +282,10 @@ if (process.platform !== 'win32') {
|
|
|
283
282
|
p.stdout.on('data', (data) => {
|
|
284
283
|
if (!data.toString().indexOf('title')) {
|
|
285
284
|
sub = data.toString().split(' ')[1].slice(0, -1);
|
|
286
|
-
setTimeout(() => {
|
|
287
|
-
process.kill(parseInt(pid), 'SIGINT');
|
|
288
|
-
p.kill('SIGINT');
|
|
289
|
-
}, 200);
|
|
290
285
|
} else if (!data.toString().indexOf('ready')) {
|
|
291
286
|
pid = data.toString().split(' ')[1].slice(0, -1);
|
|
287
|
+
process.kill(parseInt(pid), 'SIGINT');
|
|
288
|
+
p.kill('SIGINT');
|
|
292
289
|
}
|
|
293
290
|
});
|
|
294
291
|
p.on('exit', () => {
|
package/src/unixTerminal.ts
CHANGED
|
@@ -5,27 +5,15 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import * as net from 'net';
|
|
7
7
|
import * as path from 'path';
|
|
8
|
+
import * as tty from 'tty';
|
|
8
9
|
import { Terminal, DEFAULT_COLS, DEFAULT_ROWS } from './terminal';
|
|
9
10
|
import { IProcessEnv, IPtyForkOptions, IPtyOpenOptions } from './interfaces';
|
|
10
11
|
import { ArgvOrCommandLine } from './types';
|
|
11
|
-
import { assign } from './utils';
|
|
12
|
-
|
|
13
|
-
let pty: IUnixNative;
|
|
14
|
-
let helperPath: string;
|
|
15
|
-
try {
|
|
16
|
-
pty = require('../build/Release/pty.node');
|
|
17
|
-
helperPath = '../build/Release/spawn-helper';
|
|
18
|
-
} catch (outerError) {
|
|
19
|
-
try {
|
|
20
|
-
pty = require('../build/Debug/pty.node');
|
|
21
|
-
helperPath = '../build/Debug/spawn-helper';
|
|
22
|
-
} catch (innerError) {
|
|
23
|
-
console.error('innerError', innerError);
|
|
24
|
-
// Re-throw the exception from the Release require if the Debug require fails as well
|
|
25
|
-
throw outerError;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
12
|
+
import { assign, loadNativeModule } from './utils';
|
|
28
13
|
|
|
14
|
+
const native = loadNativeModule('pty');
|
|
15
|
+
const pty: IUnixNative = native.module;
|
|
16
|
+
let helperPath = native.dir + '/spawn-helper';
|
|
29
17
|
helperPath = path.resolve(__dirname, helperPath);
|
|
30
18
|
helperPath = helperPath.replace('app.asar', 'app.asar.unpacked');
|
|
31
19
|
helperPath = helperPath.replace('node_modules.asar', 'node_modules.asar.unpacked');
|
|
@@ -113,7 +101,7 @@ export class UnixTerminal extends Terminal {
|
|
|
113
101
|
// fork
|
|
114
102
|
const term = pty.fork(file, args, parsedEnv, cwd, this._cols, this._rows, uid, gid, (encoding === 'utf8'), helperPath, onexit);
|
|
115
103
|
|
|
116
|
-
this._socket = new
|
|
104
|
+
this._socket = new tty.ReadStream(term.fd);
|
|
117
105
|
if (encoding !== null) {
|
|
118
106
|
this._socket.setEncoding(encoding);
|
|
119
107
|
}
|
|
@@ -173,7 +161,7 @@ export class UnixTerminal extends Terminal {
|
|
|
173
161
|
this._forwardEvents();
|
|
174
162
|
}
|
|
175
163
|
|
|
176
|
-
protected _write(data: string): void {
|
|
164
|
+
protected _write(data: string | Buffer): void {
|
|
177
165
|
this._socket.write(data);
|
|
178
166
|
}
|
|
179
167
|
|
|
@@ -203,13 +191,13 @@ export class UnixTerminal extends Terminal {
|
|
|
203
191
|
// open
|
|
204
192
|
const term: IUnixOpenProcess = pty.open(cols, rows);
|
|
205
193
|
|
|
206
|
-
self._master = new
|
|
194
|
+
self._master = new tty.ReadStream(term.master);
|
|
207
195
|
if (encoding !== null) {
|
|
208
196
|
self._master.setEncoding(encoding);
|
|
209
197
|
}
|
|
210
198
|
self._master.resume();
|
|
211
199
|
|
|
212
|
-
self._slave = new
|
|
200
|
+
self._slave = new tty.ReadStream(term.slave);
|
|
213
201
|
if (encoding !== null) {
|
|
214
202
|
self._slave.setEncoding(encoding);
|
|
215
203
|
}
|
|
@@ -304,18 +292,3 @@ export class UnixTerminal extends Terminal {
|
|
|
304
292
|
delete env['LINES'];
|
|
305
293
|
}
|
|
306
294
|
}
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* Wraps net.Socket to force the handle type "PIPE" by temporarily overwriting
|
|
310
|
-
* tty_wrap.guessHandleType.
|
|
311
|
-
* See: https://github.com/chjj/pty.js/issues/103
|
|
312
|
-
*/
|
|
313
|
-
class PipeSocket extends net.Socket {
|
|
314
|
-
constructor(fd: number) {
|
|
315
|
-
const pipeWrap = (<any>process).binding('pipe_wrap'); // tslint:disable-line
|
|
316
|
-
// @types/node has fd as string? https://github.com/DefinitelyTyped/DefinitelyTyped/pull/18275
|
|
317
|
-
const handle = new pipeWrap.Pipe(pipeWrap.constants.SOCKET);
|
|
318
|
-
handle.open(fd);
|
|
319
|
-
super(<any>{ handle });
|
|
320
|
-
}
|
|
321
|
-
}
|
package/src/utils.ts
CHANGED
|
@@ -7,3 +7,23 @@ export function assign(target: any, ...sources: any[]): any {
|
|
|
7
7
|
sources.forEach(source => Object.keys(source).forEach(key => target[key] = source[key]));
|
|
8
8
|
return target;
|
|
9
9
|
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export function loadNativeModule(name: string): {dir: string, module: any} {
|
|
13
|
+
// Check build, debug, and then prebuilds.
|
|
14
|
+
const dirs = ['build/Release', 'build/Debug', `prebuilds/${process.platform}-${process.arch}`];
|
|
15
|
+
// Check relative to the parent dir for unbundled and then the current dir for bundled
|
|
16
|
+
const relative = ['..', '.'];
|
|
17
|
+
let lastError: unknown;
|
|
18
|
+
for (const d of dirs) {
|
|
19
|
+
for (const r of relative) {
|
|
20
|
+
const dir = `${r}/${d}/`;
|
|
21
|
+
try {
|
|
22
|
+
return { dir, module: require(`${dir}/${name}.node`) };
|
|
23
|
+
} catch (e) {
|
|
24
|
+
lastError = e;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
throw new Error(`Failed to load native module: ${name}.node, checked: ${dirs.join(', ')}: ${lastError}`);
|
|
29
|
+
}
|