@lvce-editor/pty-host 4.0.0 → 4.2.0
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/dist/ptyHostMain.js +147 -55
- package/package.json +5 -5
package/dist/ptyHostMain.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { register, execute } from '@lvce-editor/command';
|
|
2
|
+
import { IpcChildWithWebSocket, IpcChildWithElectronMessagePort, IpcChildWithElectronUtilityProcess, IpcChildWithNodeForkedProcess } from '@lvce-editor/ipc';
|
|
3
|
+
import * as JsonRpc from '@lvce-editor/json-rpc';
|
|
2
4
|
import { handleJsonRpcMessage, resolve } from '@lvce-editor/json-rpc';
|
|
3
|
-
import { IpcChildWithElectronMessagePort, IpcChildWithElectronUtilityProcess, IpcChildWithWebSocket, IpcChildWithNodeWorker, IpcChildWithNodeForkedProcess } from '@lvce-editor/ipc';
|
|
4
5
|
import debugModule from 'debug';
|
|
5
6
|
import { spawn } from 'node-pty';
|
|
6
7
|
import { VError } from '@lvce-editor/verror';
|
|
@@ -9,6 +10,131 @@ import { createWriteStream } from 'node:fs';
|
|
|
9
10
|
import { tmpdir } from 'node:os';
|
|
10
11
|
import { prepare } from '@lvce-editor/pretty-error';
|
|
11
12
|
|
|
13
|
+
const createRpc = ipc => {
|
|
14
|
+
const rpc = {
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
ipc,
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated
|
|
19
|
+
*/
|
|
20
|
+
send(method, ...params) {
|
|
21
|
+
JsonRpc.send(ipc, method, ...params);
|
|
22
|
+
},
|
|
23
|
+
invoke(method, ...params) {
|
|
24
|
+
return JsonRpc.invoke(ipc, method, ...params);
|
|
25
|
+
},
|
|
26
|
+
invokeAndTransfer(method, ...params) {
|
|
27
|
+
return JsonRpc.invokeAndTransfer(ipc, method, ...params);
|
|
28
|
+
},
|
|
29
|
+
async dispose() {
|
|
30
|
+
await ipc?.dispose();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
return rpc;
|
|
34
|
+
};
|
|
35
|
+
const requiresSocket$1 = () => {
|
|
36
|
+
return false;
|
|
37
|
+
};
|
|
38
|
+
const preparePrettyError = error => {
|
|
39
|
+
return error;
|
|
40
|
+
};
|
|
41
|
+
const logError = () => {
|
|
42
|
+
// handled by renderer worker
|
|
43
|
+
};
|
|
44
|
+
const handleMessage = event => {
|
|
45
|
+
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket$1;
|
|
46
|
+
const actualExecute = event?.target?.execute || execute;
|
|
47
|
+
return handleJsonRpcMessage(event.target, event.data, actualExecute, resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
48
|
+
};
|
|
49
|
+
const handleIpc = ipc => {
|
|
50
|
+
if ('addEventListener' in ipc) {
|
|
51
|
+
ipc.addEventListener('message', handleMessage);
|
|
52
|
+
} else if ('on' in ipc) {
|
|
53
|
+
// deprecated
|
|
54
|
+
ipc.on('message', handleMessage);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const listen$2 = async (module, options) => {
|
|
58
|
+
const rawIpc = await module.listen(options);
|
|
59
|
+
if (module.signal) {
|
|
60
|
+
module.signal(rawIpc);
|
|
61
|
+
}
|
|
62
|
+
const ipc = module.wrap(rawIpc);
|
|
63
|
+
return ipc;
|
|
64
|
+
};
|
|
65
|
+
const create$e = async ({
|
|
66
|
+
commandMap,
|
|
67
|
+
messagePort,
|
|
68
|
+
requiresSocket
|
|
69
|
+
}) => {
|
|
70
|
+
// TODO create a commandMap per rpc instance
|
|
71
|
+
register(commandMap);
|
|
72
|
+
const ipc = await listen$2(IpcChildWithElectronMessagePort, {
|
|
73
|
+
messagePort
|
|
74
|
+
});
|
|
75
|
+
if (requiresSocket) {
|
|
76
|
+
ipc.requiresSocket = requiresSocket;
|
|
77
|
+
}
|
|
78
|
+
handleIpc(ipc);
|
|
79
|
+
const rpc = createRpc(ipc);
|
|
80
|
+
return rpc;
|
|
81
|
+
};
|
|
82
|
+
const ElectronMessagePortRpcClient = {
|
|
83
|
+
__proto__: null,
|
|
84
|
+
create: create$e
|
|
85
|
+
};
|
|
86
|
+
const create$d = async ({
|
|
87
|
+
commandMap
|
|
88
|
+
}) => {
|
|
89
|
+
// TODO create a commandMap per rpc instance
|
|
90
|
+
register(commandMap);
|
|
91
|
+
const ipc = await listen$2(IpcChildWithElectronUtilityProcess);
|
|
92
|
+
handleIpc(ipc);
|
|
93
|
+
const rpc = createRpc(ipc);
|
|
94
|
+
return rpc;
|
|
95
|
+
};
|
|
96
|
+
const ElectronUtilityProcessRpcClient = {
|
|
97
|
+
__proto__: null,
|
|
98
|
+
create: create$d
|
|
99
|
+
};
|
|
100
|
+
const create$7 = async ({
|
|
101
|
+
commandMap
|
|
102
|
+
}) => {
|
|
103
|
+
// TODO create a commandMap per rpc instance
|
|
104
|
+
register(commandMap);
|
|
105
|
+
const ipc = await listen$2(IpcChildWithNodeForkedProcess);
|
|
106
|
+
handleIpc(ipc);
|
|
107
|
+
const rpc = createRpc(ipc);
|
|
108
|
+
return rpc;
|
|
109
|
+
};
|
|
110
|
+
const NodeForkedProcessRpcClient = {
|
|
111
|
+
__proto__: null,
|
|
112
|
+
create: create$7
|
|
113
|
+
};
|
|
114
|
+
const create$5 = async ({
|
|
115
|
+
commandMap,
|
|
116
|
+
request,
|
|
117
|
+
handle,
|
|
118
|
+
requiresSocket
|
|
119
|
+
}) => {
|
|
120
|
+
// TODO create a commandMap per rpc instance
|
|
121
|
+
register(commandMap);
|
|
122
|
+
const ipc = await listen$2(IpcChildWithWebSocket, {
|
|
123
|
+
request,
|
|
124
|
+
handle
|
|
125
|
+
});
|
|
126
|
+
if (requiresSocket) {
|
|
127
|
+
ipc.requiresSocket = requiresSocket;
|
|
128
|
+
}
|
|
129
|
+
handleIpc(ipc);
|
|
130
|
+
const rpc = createRpc(ipc);
|
|
131
|
+
return rpc;
|
|
132
|
+
};
|
|
133
|
+
const NodeWebSocketRpcClient = {
|
|
134
|
+
__proto__: null,
|
|
135
|
+
create: create$5
|
|
136
|
+
};
|
|
137
|
+
|
|
12
138
|
class AssertionError extends Error {
|
|
13
139
|
constructor(message) {
|
|
14
140
|
super(message);
|
|
@@ -67,27 +193,13 @@ const requiresSocket = method => {
|
|
|
67
193
|
return METHODS_THAT_REQUIRE_SOCKET.has(method);
|
|
68
194
|
};
|
|
69
195
|
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return handleJsonRpcMessage(event.target, event.data, execute, resolve, preparePrettyError, logError, requiresSocket);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const handleIpc = ipc => {
|
|
81
|
-
object(ipc);
|
|
82
|
-
if ('addEventListener' in ipc) {
|
|
83
|
-
ipc.addEventListener('message', handleMessage);
|
|
84
|
-
} else if ('onmessage' in ipc) {
|
|
85
|
-
// deprecated
|
|
86
|
-
ipc.onmessage = handleMessage;
|
|
87
|
-
} else if ('on' in ipc) {
|
|
88
|
-
// deprecated
|
|
89
|
-
ipc.on('message', handleMessage);
|
|
90
|
-
}
|
|
196
|
+
const handleElectronMessagePort = async messagePort => {
|
|
197
|
+
object(messagePort);
|
|
198
|
+
await ElectronMessagePortRpcClient.create({
|
|
199
|
+
commandMap: {},
|
|
200
|
+
messagePort,
|
|
201
|
+
requiresSocket: requiresSocket
|
|
202
|
+
});
|
|
91
203
|
};
|
|
92
204
|
|
|
93
205
|
const NodeWorker = 1;
|
|
@@ -115,15 +227,13 @@ const Auto = () => {
|
|
|
115
227
|
const getModule = method => {
|
|
116
228
|
switch (method) {
|
|
117
229
|
case NodeForkedProcess:
|
|
118
|
-
return
|
|
119
|
-
case NodeWorker:
|
|
120
|
-
return IpcChildWithNodeWorker;
|
|
230
|
+
return NodeForkedProcessRpcClient;
|
|
121
231
|
case WebSocket:
|
|
122
|
-
return
|
|
232
|
+
return NodeWebSocketRpcClient;
|
|
123
233
|
case ElectronUtilityProcess:
|
|
124
|
-
return
|
|
234
|
+
return ElectronUtilityProcessRpcClient;
|
|
125
235
|
case ElectronMessagePort:
|
|
126
|
-
return
|
|
236
|
+
return ElectronMessagePortRpcClient;
|
|
127
237
|
default:
|
|
128
238
|
throw new Error('unexpected ipc type');
|
|
129
239
|
}
|
|
@@ -135,43 +245,26 @@ const listen$1 = async ({
|
|
|
135
245
|
}) => {
|
|
136
246
|
const module = getModule(method);
|
|
137
247
|
// @ts-ignore
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
if (module.signal) {
|
|
141
|
-
// @ts-ignore
|
|
142
|
-
module.signal(rawIpc);
|
|
143
|
-
}
|
|
144
|
-
// @ts-ignore
|
|
145
|
-
const ipc = module.wrap(rawIpc);
|
|
146
|
-
return ipc;
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
const handleElectronMessagePort = async messagePort => {
|
|
150
|
-
object(messagePort);
|
|
151
|
-
const ipc = await listen$1({
|
|
152
|
-
method: ElectronMessagePort,
|
|
153
|
-
messagePort
|
|
154
|
-
});
|
|
155
|
-
handleIpc(ipc);
|
|
248
|
+
const rpc = await module.create(params);
|
|
249
|
+
return rpc;
|
|
156
250
|
};
|
|
157
251
|
|
|
158
252
|
const handleNodeMessagePort = async messagePort => {
|
|
159
|
-
|
|
253
|
+
await listen$1({
|
|
160
254
|
method: NodeMessagePort,
|
|
161
255
|
messagePort
|
|
162
256
|
});
|
|
163
|
-
handleIpc(ipc);
|
|
164
257
|
};
|
|
165
258
|
|
|
166
259
|
const handleWebSocket = async (handle, request) => {
|
|
167
260
|
object(handle);
|
|
168
261
|
object(request);
|
|
169
|
-
|
|
170
|
-
|
|
262
|
+
await NodeWebSocketRpcClient.create({
|
|
263
|
+
commandMap: {},
|
|
264
|
+
handle,
|
|
171
265
|
request,
|
|
172
|
-
|
|
266
|
+
requiresSocket: requiresSocket
|
|
173
267
|
});
|
|
174
|
-
handleIpc(ipc);
|
|
175
268
|
};
|
|
176
269
|
|
|
177
270
|
const debug = debugModule('pty-host');
|
|
@@ -324,10 +417,9 @@ const commandMap = {
|
|
|
324
417
|
};
|
|
325
418
|
|
|
326
419
|
const listen = async () => {
|
|
327
|
-
|
|
420
|
+
await listen$1({
|
|
328
421
|
method: Auto()
|
|
329
422
|
});
|
|
330
|
-
handleIpc(ipc);
|
|
331
423
|
};
|
|
332
424
|
|
|
333
425
|
const NewLine = '\n';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/pty-host",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lvce-editor",
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@lvce-editor/assert": "^1.3.0",
|
|
20
20
|
"@lvce-editor/command": "^1.2.0",
|
|
21
|
-
"@lvce-editor/ipc": "^
|
|
22
|
-
"@lvce-editor/json-rpc": "^
|
|
21
|
+
"@lvce-editor/ipc": "^14.2.0",
|
|
22
|
+
"@lvce-editor/json-rpc": "^6.2.0",
|
|
23
23
|
"@lvce-editor/pretty-error": "^2.0.0",
|
|
24
|
-
"@lvce-editor/rpc": "^1.
|
|
24
|
+
"@lvce-editor/rpc": "^4.1.0",
|
|
25
25
|
"@lvce-editor/verror": "^1.6.0",
|
|
26
|
-
"debug": "^4.4.
|
|
26
|
+
"debug": "^4.4.1"
|
|
27
27
|
},
|
|
28
28
|
"optionalDependencies": {
|
|
29
29
|
"node-pty": "^1.1.0-beta34"
|