@ohos-ports/lydell-node-pty 1.2.0-beta.15

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/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Simon Lydell
4
+
5
+ All rights reserved.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # @lydell/node-pty
2
+
3
+ Smaller distribution of [microsoft/node-pty](https://github.com/microsoft/node-pty).
4
+
5
+ - microsoft/node-pty ships with prebuilt binaries for multiple platforms. @lydell/node-pty only installs the prebuilt binaries needed for the current platform (depends on your package manager).
6
+ - microsoft/node-pty supports compiling using node-gyp on unsupported platforms, which requires more source files (about two and a half megabytes). @lydell/node-pty only works on platforms with prebuilt binaries and never calls node-gyp.
7
+ - microsoft/node-pty ships with Windows-specific and Unix-like-specific JavaScript code on all platforms. @lydell/node-pty only ships Windows-specific JavaScript files for Windows, and Unix-like-specific JavaScript files for non-Windows. This only saves a few tens of kilobytes, though.
8
+ - microsoft/node-pty is tens of megabytes. @lydell/node-pty is way less than one megabyte on macOS and Linux, and around half of microsoft/node-pty on Windows. The thing that takes the most space is microsoft/node-pty are the two Windows binaries it ships.
9
+
10
+ All in all, once microsoft/node-pty [only ships the needed prebuilt binaries for the current platform](https://github.com/microsoft/node-pty/issues/864), there probably isn’t much of a point to @lydell/node-pty anymore. It would only save a couple of megabytes (at the expense of not being able to compile on unsupported platforms).
11
+
12
+ @lydell/node-pty is built like this:
13
+
14
+ 1. Download the original node-pty npm package.
15
+ 2. Make one copy of it per supported platform.
16
+ 3. For each copy, only include relevant files.
17
+ 4. Make the @lydell/node-pty wrapper package, which depends on all the platform-specific packages using `"optionalDependencies"` in package.json, allowing package managers to only install the platform-specific package matching the current platform. The wrapper package only re-exports everything from the correct platform-specific package.
18
+
19
+ ## pty.js
20
+
21
+ microsoft/node-pty is forked from [chjj/pty.js](https://github.com/chjj/pty.js) with the primary goals being to provide better support for later Node.js versions and Windows.
22
+
23
+ ## License
24
+
25
+ Copyright (c) 2012-2015, Christopher Jeffrey (MIT License).<br>
26
+ Copyright (c) 2016, Daniel Imms (MIT License).<br>
27
+ Copyright (c) 2018, Microsoft Corporation (MIT License).
28
+
29
+ ## Version
30
+
31
+ @lydell/node-pty@1.2.0-beta.15 is based on node-pty@1.2.0-beta.15.
32
+
33
+ ## Prebuilt binaries
34
+
35
+ This package includes prebuilt binaries for the following platforms and architectures:
36
+
37
+ - macOS ARM64 (darwin-arm64)
38
+ - macOS x86_64 (darwin-x64)
39
+ - Linux ARM64 (linux-arm64)
40
+ - Linux x86_64 (linux-x64)
41
+ - Windows ARM64 (win32-arm64)
42
+ - Windows x86_64 (win32-x64)
package/index.js ADDED
@@ -0,0 +1,54 @@
1
+ const IS_HARMONYOS =
2
+ process.platform === "openharmony" || process.platform === "harmonyos";
3
+
4
+ // On HarmonyOS the prebuilt @lydell/node-pty-* platform packages cannot be used.
5
+ // The @ohos-ports/node-pty port provides the HarmonyOS native binding instead.
6
+ const PACKAGE_NAME = IS_HARMONYOS
7
+ ? "@ohos-ports/node-pty"
8
+ : `@lydell/node-pty-${process.platform}-${process.arch}`;
9
+
10
+ const help = `
11
+ This can happen if you use the "--omit=optional" (or "--no-optional") npm flag.
12
+ The "optionalDependencies" package.json feature is used to install the correct
13
+ binary executable for your current platform. Remove that flag to use @lydell/node-pty.
14
+
15
+ This can also happen if the "node_modules" folder was copied between two operating systems
16
+ that need different binaries - including "virtual" operating systems like Docker and WSL.
17
+ If so, try installing with npm rather than copying "node_modules".
18
+ `.trim();
19
+
20
+ function requirePlatformSpecificPackage() {
21
+ try {
22
+ return require(PACKAGE_NAME);
23
+ } catch (error) {
24
+ if (error && error.code === "MODULE_NOT_FOUND") {
25
+ const optionalDependencies = getOptionalDependencies();
26
+ throw new Error(
27
+ optionalDependencies === undefined
28
+ ? `The @lydell/node-pty package could not find the platform-specific package: ${PACKAGE_NAME}\n\n${help}\n\nYour platform (${process.platform}-${process.arch}) might not be supported.`
29
+ : PACKAGE_NAME in optionalDependencies
30
+ ? `The @lydell/node-pty package supports your platform (${process.platform}-${process.arch}), but it could not find the platform-specific package for it: ${PACKAGE_NAME}\n\n${help}`
31
+ : `The @lydell/node-pty package currently does not support your platform: ${process.platform}-${process.arch}`,
32
+ { cause: error }
33
+ );
34
+ } else {
35
+ throw error;
36
+ }
37
+ }
38
+ }
39
+
40
+ function getOptionalDependencies() {
41
+ try {
42
+ return require("./package.json").optionalDependencies;
43
+ } catch (_error) {
44
+ return undefined;
45
+ }
46
+ }
47
+
48
+ // These two lines are needed for `import * as pty from "@lydell/node-pty"` to work.
49
+ // `import * as pty` is used in the README of microsoft/node-pty.
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ // prettier-ignore
52
+ exports.native = exports.open = exports.createTerminal = exports.fork = exports.spawn = void 0;
53
+
54
+ module.exports = requirePlatformSpecificPackage();
package/node-pty.d.ts ADDED
@@ -0,0 +1,215 @@
1
+ /**
2
+ * Copyright (c) 2017, Daniel Imms (MIT License).
3
+ * Copyright (c) 2018, Microsoft Corporation (MIT License).
4
+ */
5
+
6
+ declare module '@lydell/node-pty' {
7
+ /**
8
+ * Forks a process as a pseudoterminal.
9
+ * @param file The file to launch.
10
+ * @param args The file's arguments as argv (string[]) or in a pre-escaped CommandLine format
11
+ * (string). Note that the CommandLine option is only available on Windows and is expected to be
12
+ * escaped properly.
13
+ * @param options The options of the terminal.
14
+ * @see CommandLineToArgvW https://msdn.microsoft.com/en-us/library/windows/desktop/bb776391(v=vs.85).aspx
15
+ * @see Parsing C++ Command-Line Arguments https://msdn.microsoft.com/en-us/library/17w5ykft.aspx
16
+ * @see GetCommandLine https://msdn.microsoft.com/en-us/library/windows/desktop/ms683156.aspx
17
+ */
18
+ export function spawn(file: string, args: string[] | string, options: IPtyForkOptions | IWindowsPtyForkOptions): IPty;
19
+
20
+ export interface IBasePtyForkOptions {
21
+
22
+ /**
23
+ * Name of the terminal to be set in environment ($TERM variable).
24
+ */
25
+ name?: string;
26
+
27
+ /**
28
+ * Number of intial cols of the pty.
29
+ */
30
+ cols?: number;
31
+
32
+ /**
33
+ * Number of initial rows of the pty.
34
+ */
35
+ rows?: number;
36
+
37
+ /**
38
+ * Working directory to be set for the child program.
39
+ */
40
+ cwd?: string;
41
+
42
+ /**
43
+ * Environment to be set for the child program.
44
+ */
45
+ env?: { [key: string]: string | undefined };
46
+
47
+ /**
48
+ * String encoding of the underlying pty.
49
+ * If set, incoming data will be decoded to strings and outgoing strings to bytes applying this encoding.
50
+ * If unset, incoming data will be delivered as raw bytes (Buffer type).
51
+ * By default 'utf8' is assumed, to unset it explicitly set it to `null`.
52
+ */
53
+ encoding?: string | null;
54
+
55
+ /**
56
+ * (EXPERIMENTAL)
57
+ * Whether to enable flow control handling (false by default). If enabled a message of `flowControlPause`
58
+ * will pause the socket and thus blocking the child program execution due to buffer back pressure.
59
+ * A message of `flowControlResume` will resume the socket into flow mode.
60
+ * For performance reasons only a single message as a whole will match (no message part matching).
61
+ * If flow control is enabled the `flowControlPause` and `flowControlResume` messages are not forwarded to
62
+ * the underlying pseudoterminal.
63
+ */
64
+ handleFlowControl?: boolean;
65
+
66
+ /**
67
+ * (EXPERIMENTAL)
68
+ * The string that should pause the pty when `handleFlowControl` is true. Default is XOFF ('\x13').
69
+ */
70
+ flowControlPause?: string;
71
+
72
+ /**
73
+ * (EXPERIMENTAL)
74
+ * The string that should resume the pty when `handleFlowControl` is true. Default is XON ('\x11').
75
+ */
76
+ flowControlResume?: string;
77
+ }
78
+
79
+ export interface IPtyForkOptions extends IBasePtyForkOptions {
80
+ /**
81
+ * Security warning: use this option with great caution,
82
+ * as opened file descriptors with higher privileges might leak to the child program.
83
+ */
84
+ uid?: number;
85
+ gid?: number;
86
+ }
87
+
88
+ export interface IWindowsPtyForkOptions extends IBasePtyForkOptions {
89
+ /**
90
+ * Whether to use the ConPTY system on Windows. When this is not set, ConPTY will be used when
91
+ * the Windows build number is >= 18309 (instead of winpty). Note that ConPTY is available from
92
+ * build 17134 but is too unstable to enable by default.
93
+ *
94
+ * @deprecated This option is ignored and will be removed in a future version.
95
+ * https://github.com/microsoft/node-pty/issues/871
96
+ */
97
+ useConpty?: boolean;
98
+
99
+ /**
100
+ * (EXPERIMENTAL)
101
+ *
102
+ * Whether to use the conpty.dll shipped with the node-pty package instead of the one built into
103
+ * Windows. Defaults to false.
104
+ */
105
+ useConptyDll?: boolean;
106
+
107
+ /**
108
+ * Whether to use PSEUDOCONSOLE_INHERIT_CURSOR in conpty.
109
+ * @see https://docs.microsoft.com/en-us/windows/console/createpseudoconsole
110
+ */
111
+ conptyInheritCursor?: boolean;
112
+ }
113
+
114
+ /**
115
+ * An interface representing a pseudoterminal.
116
+ */
117
+ export interface IPty {
118
+ /**
119
+ * The process ID of the outer process.
120
+ */
121
+ readonly pid: number;
122
+
123
+ /**
124
+ * The column size in characters.
125
+ */
126
+ readonly cols: number;
127
+
128
+ /**
129
+ * The row size in characters.
130
+ */
131
+ readonly rows: number;
132
+
133
+ /**
134
+ * The title of the active process.
135
+ */
136
+ readonly process: string;
137
+
138
+ /**
139
+ * (EXPERIMENTAL)
140
+ * Whether to handle flow control. Useful to disable/re-enable flow control during runtime.
141
+ * Use this for binary data that is likely to contain the `flowControlPause` string by accident.
142
+ */
143
+ handleFlowControl: boolean;
144
+
145
+ /**
146
+ * Adds an event listener for when a data event fires. This happens when data is returned from
147
+ * the pty.
148
+ * @returns an `IDisposable` to stop listening.
149
+ */
150
+ readonly onData: IEvent<string>;
151
+
152
+ /**
153
+ * Adds an event listener for when an exit event fires. This happens when the pty exits.
154
+ * @returns an `IDisposable` to stop listening.
155
+ */
156
+ readonly onExit: IEvent<{ exitCode: number, signal?: number }>;
157
+
158
+ /**
159
+ * Resizes the dimensions of the pty.
160
+ * @param columns The number of columns to use.
161
+ * @param rows The number of rows to use.
162
+ * @param pixelSize Optional pixel dimensions of the pty. On Unix, this sets the `ws_xpixel`
163
+ * and `ws_ypixel` fields of the `winsize` struct. Applications running in the pty can read
164
+ * these values via the `TIOCGWINSZ` ioctl. This parameter is ignored on Windows.
165
+ */
166
+ resize(columns: number, rows: number, pixelSize?: { width: number, height: number }): void;
167
+
168
+ /**
169
+ * Clears the pty's internal representation of its buffer. This is a no-op
170
+ * unless on Windows/ConPTY. This is useful if the buffer is cleared on the
171
+ * frontend in order to synchronize state with the backend to avoid ConPTY
172
+ * possibly reprinting the screen.
173
+ */
174
+ clear(): void;
175
+
176
+ /**
177
+ * Writes data to the pty.
178
+ * @param data The data to write.
179
+ */
180
+ write(data: string | Buffer): void;
181
+
182
+ /**
183
+ * Kills the pty.
184
+ * @param signal The signal to use, defaults to SIGHUP. This parameter is not supported on
185
+ * Windows.
186
+ * @throws Will throw when signal is used on Windows.
187
+ */
188
+ kill(signal?: string): void;
189
+
190
+ /**
191
+ * Pauses the pty for customizable flow control.
192
+ */
193
+ pause(): void;
194
+
195
+ /**
196
+ * Resumes the pty for customizable flow control.
197
+ */
198
+ resume(): void;
199
+ }
200
+
201
+ /**
202
+ * An object that can be disposed via a dispose function.
203
+ */
204
+ export interface IDisposable {
205
+ dispose(): void;
206
+ }
207
+
208
+ /**
209
+ * An event that can be listened to.
210
+ * @returns an `IDisposable` to stop listening.
211
+ */
212
+ export interface IEvent<T> {
213
+ (listener: (e: T) => any): IDisposable;
214
+ }
215
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@ohos-ports/lydell-node-pty",
3
+ "description": "Smaller distribution of node-pty.",
4
+ "author": "Simon Lydell",
5
+ "version": "1.2.0-beta.15",
6
+ "license": "MIT",
7
+ "type": "commonjs",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./node-pty.d.ts",
11
+ "default": "./index.js"
12
+ }
13
+ },
14
+ "types": "./node-pty.d.ts",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/ohos-ports/ohos-ports.git",
18
+ "directory": "ports/lydell-node-pty/1.2.0-beta.15"
19
+ },
20
+ "keywords": [
21
+ "pty",
22
+ "tty",
23
+ "terminal",
24
+ "pseudoterminal",
25
+ "forkpty",
26
+ "openpty",
27
+ "prebuild",
28
+ "prebuilt"
29
+ ],
30
+ "dependencies": {
31
+ "@ohos-ports/node-pty": "^1.1.0-beta.4"
32
+ },
33
+ "bugs": {
34
+ "url": "https://github.com/ohos-ports/ohos-ports/issues"
35
+ },
36
+ "files": [
37
+ "index.js",
38
+ "node-pty.d.ts",
39
+ "README.md",
40
+ "LICENSE"
41
+ ]
42
+ }