@lvce-editor/pty-host 3.2.0 → 4.1.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.
Files changed (2) hide show
  1. package/dist/ptyHostMain.js +151 -60
  2. package/package.json +4 -4
@@ -1,6 +1,7 @@
1
- import { execute, register } from '@lvce-editor/command';
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);
@@ -62,32 +188,12 @@ const string = value => {
62
188
  }
63
189
  };
64
190
 
65
- const METHODS_THAT_REQUIRE_SOCKET = new Set(['Terminal.create']);
66
- const requiresSocket = method => {
67
- return METHODS_THAT_REQUIRE_SOCKET.has(method);
68
- };
69
-
70
- const preparePrettyError = error => {
71
- return error;
72
- };
73
- const logError = () => {
74
- // PrintPrettyError.printPrettyError(prettyError, `[terminal-process] `)
75
- };
76
- const handleMessage = event => {
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
- }
191
+ const handleElectronMessagePort = async messagePort => {
192
+ object(messagePort);
193
+ await ElectronMessagePortRpcClient.create({
194
+ commandMap: {},
195
+ messagePort
196
+ });
91
197
  };
92
198
 
93
199
  const NodeWorker = 1;
@@ -115,15 +221,13 @@ const Auto = () => {
115
221
  const getModule = method => {
116
222
  switch (method) {
117
223
  case NodeForkedProcess:
118
- return IpcChildWithNodeForkedProcess;
119
- case NodeWorker:
120
- return IpcChildWithNodeWorker;
224
+ return NodeForkedProcessRpcClient;
121
225
  case WebSocket:
122
- return IpcChildWithWebSocket;
226
+ return NodeWebSocketRpcClient;
123
227
  case ElectronUtilityProcess:
124
- return IpcChildWithElectronUtilityProcess;
228
+ return ElectronUtilityProcessRpcClient;
125
229
  case ElectronMessagePort:
126
- return IpcChildWithElectronMessagePort;
230
+ return ElectronMessagePortRpcClient;
127
231
  default:
128
232
  throw new Error('unexpected ipc type');
129
233
  }
@@ -135,43 +239,31 @@ const listen$1 = async ({
135
239
  }) => {
136
240
  const module = getModule(method);
137
241
  // @ts-ignore
138
- const rawIpc = await module.listen(params);
139
- // @ts-ignore
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);
242
+ const rpc = await module.create(params);
243
+ return rpc;
156
244
  };
157
245
 
158
246
  const handleNodeMessagePort = async messagePort => {
159
- const ipc = await listen$1({
247
+ await listen$1({
160
248
  method: NodeMessagePort,
161
249
  messagePort
162
250
  });
163
- handleIpc(ipc);
251
+ };
252
+
253
+ const METHODS_THAT_REQUIRE_SOCKET = new Set(['Terminal.create']);
254
+ const requiresSocket = method => {
255
+ return METHODS_THAT_REQUIRE_SOCKET.has(method);
164
256
  };
165
257
 
166
258
  const handleWebSocket = async (handle, request) => {
167
259
  object(handle);
168
260
  object(request);
169
- const ipc = await listen$1({
170
- method: WebSocket,
261
+ await NodeWebSocketRpcClient.create({
262
+ commandMap: {},
263
+ handle,
171
264
  request,
172
- handle
265
+ requiresSocket: requiresSocket
173
266
  });
174
- handleIpc(ipc);
175
267
  };
176
268
 
177
269
  const debug = debugModule('pty-host');
@@ -324,10 +416,9 @@ const commandMap = {
324
416
  };
325
417
 
326
418
  const listen = async () => {
327
- const ipc = await listen$1({
419
+ await listen$1({
328
420
  method: Auto()
329
421
  });
330
- handleIpc(ipc);
331
422
  };
332
423
 
333
424
  const NewLine = '\n';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/pty-host",
3
- "version": "3.2.0",
3
+ "version": "4.1.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": "^13.8.0",
21
+ "@lvce-editor/ipc": "^14.1.0",
22
22
  "@lvce-editor/json-rpc": "^5.4.0",
23
23
  "@lvce-editor/pretty-error": "^2.0.0",
24
- "@lvce-editor/rpc": "^1.27.0",
24
+ "@lvce-editor/rpc": "^3.4.0",
25
25
  "@lvce-editor/verror": "^1.6.0",
26
- "debug": "^4.4.0"
26
+ "debug": "^4.4.1"
27
27
  },
28
28
  "optionalDependencies": {
29
29
  "node-pty": "^1.1.0-beta34"