@lvce-editor/shared-process 0.15.28 → 0.15.30
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/package.json +4 -4
- package/src/parts/GetResponse/GetResponse.js +3 -4
- package/src/parts/HandleJsonRpcMessage/HandleJsonRpcMessage.js +2 -2
- package/src/parts/JsonRpc/JsonRpc.js +8 -24
- package/src/parts/JsonRpcEvent/JsonRpcEvent.js +9 -0
- package/src/parts/JsonRpcRequest/JsonRpcRequest.js +16 -0
- package/src/parts/OutputChannel/OutputChannel.ipc.js +5 -11
- package/src/parts/Terminal/Terminal.js +10 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/shared-process",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.30",
|
|
4
4
|
"description": "Utility package for @lvce-editor/server",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@babel/code-frame": "^7.22.5",
|
|
20
|
-
"@lvce-editor/extension-host": "0.15.
|
|
21
|
-
"@lvce-editor/extension-host-helper-process": "0.15.
|
|
22
|
-
"@lvce-editor/pty-host": "0.15.
|
|
20
|
+
"@lvce-editor/extension-host": "0.15.30",
|
|
21
|
+
"@lvce-editor/extension-host-helper-process": "0.15.30",
|
|
22
|
+
"@lvce-editor/pty-host": "0.15.30",
|
|
23
23
|
"debug": "^4.3.4",
|
|
24
24
|
"execa": "^7.1.1",
|
|
25
25
|
"exit-hook": "^3.2.0",
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import * as Command from '../Command/Command.js'
|
|
2
1
|
import * as GetErrorResponse from '../GetErrorResponse/GetErrorResponse.js'
|
|
3
2
|
import * as GetSuccessResponse from '../GetSuccessResponse/GetSuccessResponse.js'
|
|
4
3
|
import * as RequiresSocket from '../RequiresSocket/RequiresSocket.js'
|
|
5
4
|
|
|
6
|
-
export const getResponse = async (message, ipc) => {
|
|
5
|
+
export const getResponse = async (message, ipc, execute) => {
|
|
7
6
|
try {
|
|
8
7
|
const result = RequiresSocket.requiresSocket(message.method)
|
|
9
|
-
? await
|
|
10
|
-
: await
|
|
8
|
+
? await execute(message.method, ipc, ...message.params)
|
|
9
|
+
: await execute(message.method, ...message.params)
|
|
11
10
|
return GetSuccessResponse.getSuccessResponse(message, result)
|
|
12
11
|
} catch (error) {
|
|
13
12
|
return GetErrorResponse.getErrorResponse(message, error, ipc)
|
|
@@ -5,7 +5,7 @@ import { JsonRpcError } from '../JsonRpcError/JsonRpcError.js'
|
|
|
5
5
|
export const handleJsonRpcMessage = async (ipc, message, execute, resolve) => {
|
|
6
6
|
if ('id' in message) {
|
|
7
7
|
if ('method' in message) {
|
|
8
|
-
const response = await GetResponse.getResponse(message, execute)
|
|
8
|
+
const response = await GetResponse.getResponse(message, ipc, execute)
|
|
9
9
|
try {
|
|
10
10
|
ipc.send(response)
|
|
11
11
|
} catch (error) {
|
|
@@ -18,7 +18,7 @@ export const handleJsonRpcMessage = async (ipc, message, execute, resolve) => {
|
|
|
18
18
|
return
|
|
19
19
|
}
|
|
20
20
|
if ('method' in message) {
|
|
21
|
-
await GetResponse.getResponse(message, execute)
|
|
21
|
+
await GetResponse.getResponse(message, ipc, execute)
|
|
22
22
|
return
|
|
23
23
|
}
|
|
24
24
|
throw new JsonRpcError('unexpected message')
|
|
@@ -1,39 +1,23 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
1
|
+
import * as JsonRpcEvent from '../JsonRpcEvent/JsonRpcEvent.js'
|
|
2
|
+
import * as JsonRpcRequest from '../JsonRpcRequest/JsonRpcRequest.js'
|
|
3
3
|
import * as UnwrapJsonRpcResult from '../UnwrapJsonRpcResult/UnwrapJsonRpcResult.js'
|
|
4
4
|
|
|
5
5
|
export const send = (transport, method, ...params) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
method,
|
|
9
|
-
params,
|
|
10
|
-
})
|
|
6
|
+
const message = JsonRpcEvent.create(method, params)
|
|
7
|
+
transport.send(message)
|
|
11
8
|
}
|
|
12
9
|
|
|
13
10
|
export const invoke = async (ipc, method, ...params) => {
|
|
14
|
-
const {
|
|
15
|
-
ipc.send(
|
|
16
|
-
jsonrpc: JsonRpcVersion.Two,
|
|
17
|
-
method,
|
|
18
|
-
params,
|
|
19
|
-
id,
|
|
20
|
-
})
|
|
11
|
+
const { message, promise } = JsonRpcRequest.create(method, params)
|
|
12
|
+
ipc.send(message)
|
|
21
13
|
const responseMessage = await promise
|
|
22
14
|
const result = UnwrapJsonRpcResult.unwrapJsonRpcResult(responseMessage)
|
|
23
15
|
return result
|
|
24
16
|
}
|
|
25
17
|
|
|
26
18
|
export const invokeAndTransfer = async (ipc, handle, method, ...params) => {
|
|
27
|
-
const {
|
|
28
|
-
ipc.sendAndTransfer(
|
|
29
|
-
{
|
|
30
|
-
jsonrpc: JsonRpcVersion.Two,
|
|
31
|
-
method,
|
|
32
|
-
params,
|
|
33
|
-
id,
|
|
34
|
-
},
|
|
35
|
-
handle
|
|
36
|
-
)
|
|
19
|
+
const { message, promise } = JsonRpcRequest.create(method, params)
|
|
20
|
+
ipc.sendAndTransfer(message, handle)
|
|
37
21
|
const responseMessage = await promise
|
|
38
22
|
const result = UnwrapJsonRpcResult.unwrapJsonRpcResult(responseMessage)
|
|
39
23
|
return result
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as Callback from '../Callback/Callback.js'
|
|
2
|
+
import * as JsonRpcVersion from '../JsonRpcVersion/JsonRpcVersion.js'
|
|
3
|
+
|
|
4
|
+
export const create = (method, params) => {
|
|
5
|
+
const { id, promise } = Callback.registerPromise()
|
|
6
|
+
const message = {
|
|
7
|
+
jsonrpc: JsonRpcVersion.Two,
|
|
8
|
+
method,
|
|
9
|
+
params,
|
|
10
|
+
id,
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
message,
|
|
14
|
+
promise,
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Assert from '../Assert/Assert.js'
|
|
2
|
-
import * as
|
|
2
|
+
import * as JsonRpcEvent from '../JsonRpcEvent/JsonRpcEvent.js'
|
|
3
3
|
import * as OutputChannelState from '../OutputChannelState/OutputChannelState.js'
|
|
4
4
|
import * as OutputChannel from './OutputChannel.js'
|
|
5
5
|
|
|
@@ -17,19 +17,13 @@ const open = (socket, id, path) => {
|
|
|
17
17
|
}
|
|
18
18
|
const onData = (data) => {
|
|
19
19
|
console.log('send data', data)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
method: 'Output.handleData',
|
|
23
|
-
params: [data],
|
|
24
|
-
})
|
|
20
|
+
const message = JsonRpcEvent.create('Output.handleData', [data])
|
|
21
|
+
socket.send(message)
|
|
25
22
|
}
|
|
26
23
|
const onError = (error) => {
|
|
27
24
|
console.info(`[shared process] output channel error: ${error}`)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
method: 'Output.handleError',
|
|
31
|
-
params: [error],
|
|
32
|
-
})
|
|
25
|
+
const message = JsonRpcEvent.create('Output.handleError', [error])
|
|
26
|
+
socket.send(message)
|
|
33
27
|
}
|
|
34
28
|
const outputChannel = OutputChannel.open(path, onData, onError)
|
|
35
29
|
OutputChannelState.set(id, outputChannel)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Assert from '../Assert/Assert.js'
|
|
2
|
-
import * as
|
|
2
|
+
import * as JsonRpcEvent from '../JsonRpcEvent/JsonRpcEvent.js'
|
|
3
3
|
import * as PtyHost from '../PtyHost/PtyHost.js'
|
|
4
4
|
import * as TerminalState from '../TerminalState/TerminalState.js'
|
|
5
5
|
import { VError } from '../VError/VError.js'
|
|
@@ -28,21 +28,18 @@ const createTerminal = (ptyHost, socket) => {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
export const create = async (
|
|
31
|
+
export const create = async (ipc, id, cwd, command, args) => {
|
|
32
32
|
try {
|
|
33
|
-
Assert.object(
|
|
33
|
+
Assert.object(ipc)
|
|
34
34
|
Assert.number(id)
|
|
35
35
|
Assert.string(cwd)
|
|
36
36
|
// TODO race condition because of await
|
|
37
37
|
const ptyHost = await PtyHost.getOrCreate()
|
|
38
|
-
const terminal = createTerminal(ptyHost,
|
|
38
|
+
const terminal = createTerminal(ptyHost, ipc)
|
|
39
39
|
TerminalState.add(id, terminal)
|
|
40
40
|
// TODO use invoke
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
method: 'Terminal.create',
|
|
44
|
-
params: [id, cwd, command, args],
|
|
45
|
-
})
|
|
41
|
+
const message = JsonRpcEvent.create('Terminal.create', [id, cwd, command, args])
|
|
42
|
+
ptyHost.send(message)
|
|
46
43
|
} catch (error) {
|
|
47
44
|
throw new VError(error, `Failed to create terminal`)
|
|
48
45
|
}
|
|
@@ -57,11 +54,8 @@ export const write = (id, data) => {
|
|
|
57
54
|
return
|
|
58
55
|
}
|
|
59
56
|
// TODO should use invoke
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
method: 'Terminal.write',
|
|
63
|
-
params: [id, data],
|
|
64
|
-
})
|
|
57
|
+
const message = JsonRpcEvent.create('Terminal.write', [id, data])
|
|
58
|
+
ptyHost.send(message)
|
|
65
59
|
}
|
|
66
60
|
|
|
67
61
|
export const resize = (state, columns, rows) => {
|
|
@@ -73,12 +67,9 @@ export const dispose = async (id) => {
|
|
|
73
67
|
terminal.dispose()
|
|
74
68
|
TerminalState.remove(id)
|
|
75
69
|
const ptyHost = await PtyHost.getOrCreate()
|
|
70
|
+
const message = JsonRpcEvent.create('Terminal.dispose', [id])
|
|
76
71
|
// TODO use invoke
|
|
77
|
-
ptyHost.send(
|
|
78
|
-
jsonrpc: JsonRpcVersion.Two,
|
|
79
|
-
method: 'Terminal.dispose',
|
|
80
|
-
params: [id],
|
|
81
|
-
})
|
|
72
|
+
ptyHost.send(message)
|
|
82
73
|
}
|
|
83
74
|
|
|
84
75
|
export const disposeAll = () => {
|