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.
Files changed (56) hide show
  1. package/README.md +6 -4
  2. package/binding.gyp +10 -20
  3. package/deps/winpty/src/agent/Agent.cc +11 -3
  4. package/deps/winpty/src/winpty.gyp +29 -1
  5. package/lib/conpty_console_list_agent.js +3 -7
  6. package/lib/conpty_console_list_agent.js.map +1 -1
  7. package/lib/index.js +2 -1
  8. package/lib/index.js.map +1 -1
  9. package/lib/terminal.js.map +1 -1
  10. package/lib/terminal.test.js.map +1 -1
  11. package/lib/unixTerminal.js +7 -44
  12. package/lib/unixTerminal.js.map +1 -1
  13. package/lib/unixTerminal.test.js +3 -5
  14. package/lib/unixTerminal.test.js.map +1 -1
  15. package/lib/utils.js +23 -1
  16. package/lib/utils.js.map +1 -1
  17. package/lib/windowsConoutConnection.js +6 -3
  18. package/lib/windowsConoutConnection.js.map +1 -1
  19. package/lib/windowsPtyAgent.js +45 -48
  20. package/lib/windowsPtyAgent.js.map +1 -1
  21. package/lib/windowsTerminal.js +1 -1
  22. package/lib/windowsTerminal.js.map +1 -1
  23. package/lib/windowsTerminal.test.js +40 -26
  24. package/lib/windowsTerminal.test.js.map +1 -1
  25. package/lib/worker/conoutSocketWorker.js.map +1 -1
  26. package/package.json +7 -2
  27. package/scripts/gen-compile-commands.js +8 -0
  28. package/scripts/{publish.js → increment-version.js} +7 -15
  29. package/scripts/post-install.js +48 -10
  30. package/scripts/prebuild.js +35 -0
  31. package/src/conpty_console_list_agent.ts +2 -6
  32. package/src/index.ts +2 -1
  33. package/src/interfaces.ts +2 -1
  34. package/src/native.d.ts +5 -5
  35. package/src/terminal.test.ts +1 -1
  36. package/src/terminal.ts +2 -2
  37. package/src/unix/pty.cc +244 -284
  38. package/src/unixTerminal.test.ts +3 -6
  39. package/src/unixTerminal.ts +9 -36
  40. package/src/utils.ts +20 -0
  41. package/src/win/conpty.cc +268 -187
  42. package/src/win/conpty.h +41 -0
  43. package/src/win/conpty_console_list.cc +16 -15
  44. package/src/win/path_util.cc +39 -36
  45. package/src/win/path_util.h +5 -2
  46. package/src/win/winpty.cc +108 -151
  47. package/src/windowsConoutConnection.ts +6 -3
  48. package/src/windowsPtyAgent.ts +42 -43
  49. package/src/windowsTerminal.test.ts +46 -33
  50. package/src/windowsTerminal.ts +3 -3
  51. package/src/worker/conoutSocketWorker.ts +2 -2
  52. package/third_party/conpty/1.23.251008001/win10-arm64/OpenConsole.exe +0 -0
  53. package/third_party/conpty/1.23.251008001/win10-arm64/conpty.dll +0 -0
  54. package/third_party/conpty/1.23.251008001/win10-x64/OpenConsole.exe +0 -0
  55. package/third_party/conpty/1.23.251008001/win10-x64/conpty.dll +0 -0
  56. package/typings/node-pty.d.ts +9 -1
@@ -1,8 +1,11 @@
1
- var fs = require('fs');
2
- var path = require('path');
1
+ //@ts-check
3
2
 
4
- var RELEASE_DIR = path.join(__dirname, '..', 'build', 'Release');
5
- var BUILD_FILES = [
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 = [
6
9
  path.join(RELEASE_DIR, 'conpty.node'),
7
10
  path.join(RELEASE_DIR, 'conpty.pdb'),
8
11
  path.join(RELEASE_DIR, 'conpty_console_list.node'),
@@ -15,14 +18,19 @@ var BUILD_FILES = [
15
18
  path.join(RELEASE_DIR, 'winpty.dll'),
16
19
  path.join(RELEASE_DIR, 'winpty.pdb')
17
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');
18
25
 
19
- cleanFolderRecursive = function(folder) {
26
+ /** @param {string} folder */
27
+ function cleanFolderRecursive(folder) {
20
28
  var files = [];
21
- if( fs.existsSync(folder) ) {
29
+ if (fs.existsSync(folder)) {
22
30
  files = fs.readdirSync(folder);
23
31
  files.forEach(function(file,index) {
24
32
  var curPath = path.join(folder, file);
25
- if(fs.lstatSync(curPath).isDirectory()) { // recurse
33
+ if (fs.lstatSync(curPath).isDirectory()) { // recurse
26
34
  cleanFolderRecursive(curPath);
27
35
  fs.rmdirSync(curPath);
28
36
  } else if (BUILD_FILES.indexOf(curPath) < 0){ // delete file
@@ -36,7 +44,37 @@ try {
36
44
  cleanFolderRecursive(RELEASE_DIR);
37
45
  } catch(e) {
38
46
  console.log(e);
39
- //process.exit(1);
40
- } finally {
41
- process.exit(0);
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
+ }
42
78
  }
79
+
80
+ process.exit(0);
@@ -0,0 +1,35 @@
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> Removing prebuilds and rebuilding because directory ${PREBUILD_DIR} does not exist\x1b[0m`);
31
+ fs.rmSync(PREBUILDS_ROOT, { recursive: true, force: true });
32
+ process.exit(1);
33
+ }
34
+
35
+ process.exit(0);
@@ -6,13 +6,9 @@
6
6
  * single console attached to a process.
7
7
  */
8
8
 
9
- let getConsoleProcessList: any;
10
- try {
11
- getConsoleProcessList = require('../build/Release/conpty_console_list.node').getConsoleProcessList;
12
- } catch (err) {
13
- getConsoleProcessList = require('../build/Debug/conpty_console_list.node').getConsoleProcessList;
14
- }
9
+ import { loadNativeModule } from './utils';
15
10
 
11
+ const getConsoleProcessList = loadNativeModule('conpty_console_list').module.getConsoleProcessList;
16
12
  const shellPid = parseInt(process.argv[2], 10);
17
13
  const consoleProcessList = getConsoleProcessList(shellPid);
18
14
  process.send!({ consoleProcessList });
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@
6
6
 
7
7
  import { ITerminal, IPtyOpenOptions, IPtyForkOptions, IWindowsPtyForkOptions } from './interfaces';
8
8
  import { ArgvOrCommandLine } from './types';
9
+ import { loadNativeModule } from './utils';
9
10
 
10
11
  let terminalCtor: any;
11
12
  if (process.platform === 'win32') {
@@ -48,4 +49,4 @@ export function open(options: IPtyOpenOptions): ITerminal {
48
49
  * Expose the native API when not Windows, note that this is not public API and
49
50
  * could be removed at any time.
50
51
  */
51
- export const native = (process.platform !== 'win32' ? require('../build/Release/pty.node') : null);
52
+ export const native = (process.platform !== 'win32' ? loadNativeModule('pty').module : null);
package/src/interfaces.ts CHANGED
@@ -22,7 +22,7 @@ export interface ITerminal {
22
22
  * Writes data to the socket.
23
23
  * @param data The data to write.
24
24
  */
25
- write(data: string): void;
25
+ write(data: string | Buffer): void;
26
26
 
27
27
  /**
28
28
  * Resize the pty.
@@ -119,6 +119,7 @@ export interface IPtyForkOptions extends IBasePtyForkOptions {
119
119
 
120
120
  export interface IWindowsPtyForkOptions extends IBasePtyForkOptions {
121
121
  useConpty?: boolean;
122
+ useConptyDll?: boolean;
122
123
  conptyInheritCursor?: boolean;
123
124
  }
124
125
 
package/src/native.d.ts CHANGED
@@ -3,11 +3,11 @@
3
3
  */
4
4
 
5
5
  interface IConptyNative {
6
- startProcess(file: string, cols: number, rows: number, debug: boolean, pipeName: string, conptyInheritCursor: boolean): IConptyProcess;
7
- connect(ptyId: number, commandLine: string, cwd: string, env: string[], onExitCallback: (exitCode: number) => void): { pid: number };
8
- resize(ptyId: number, cols: number, rows: number): void;
9
- clear(ptyId: number): void;
10
- kill(ptyId: number): void;
6
+ startProcess(file: string, cols: number, rows: number, debug: boolean, pipeName: string, conptyInheritCursor: boolean, useConptyDll: boolean): IConptyProcess;
7
+ connect(ptyId: number, commandLine: string, cwd: string, env: string[], useConptyDll: boolean, onExitCallback: (exitCode: number) => void): { pid: number };
8
+ resize(ptyId: number, cols: number, rows: number, useConptyDll: boolean): void;
9
+ clear(ptyId: number, useConptyDll: boolean): void;
10
+ kill(ptyId: number, useConptyDll: boolean): void;
11
11
  }
12
12
 
13
13
  interface IWinptyNative {
@@ -23,7 +23,7 @@ class TestTerminal extends Terminal {
23
23
  public checkType<T>(name: string, value: T, type: string, allowArray: boolean = false): void {
24
24
  this._checkType(name, value, type, allowArray);
25
25
  }
26
- protected _write(data: string): void {
26
+ protected _write(data: string | Buffer): void {
27
27
  throw new Error('Method not implemented.');
28
28
  }
29
29
  public resize(cols: number, rows: number): void {
package/src/terminal.ts CHANGED
@@ -74,9 +74,9 @@ export abstract class Terminal implements ITerminal {
74
74
  this._checkType('encoding', opt.encoding ? opt.encoding : undefined, 'string');
75
75
  }
76
76
 
77
- protected abstract _write(data: string): void;
77
+ protected abstract _write(data: string | Buffer): void;
78
78
 
79
- public write(data: string): void {
79
+ public write(data: string | Buffer): void {
80
80
  if (this.handleFlowControl) {
81
81
  // PAUSE/RESUME messages are not forwarded to the pty
82
82
  if (data === this._flowControlPause) {