@lvce-editor/pty-host 0.22.7 → 0.23.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/package.json +2 -1
- package/src/parts/IpcChild/IpcChild.js +3 -0
- package/src/parts/IpcChildWithElectronUtilityProcess/IpcChildWithElectronUtilityProcess.js +1 -48
- package/src/parts/IpcChildWithWebSocket/IpcChildWithWebSocket.js +1 -56
- package/src/parts/CleanStack/CleanStack.js +0 -93
- package/src/parts/CommandNotFoundError/CommandNotFoundError.js +0 -9
- package/src/parts/EncodingType/EncodingType.js +0 -1
- package/src/parts/FirstWebSocketEventType/FirstWebSocketEventType.js +0 -2
- package/src/parts/GetFirstEvent/GetFirstEvent.js +0 -24
- package/src/parts/GetFirstWebSocketEvent/GetFirstWebSocketEvent.js +0 -25
- package/src/parts/Id/Id.js +0 -7
- package/src/parts/IsWebSocket/IsWebSocket.js +0 -5
- package/src/parts/IsWebSocketOpen/IsWebSocketOpen.js +0 -5
- package/src/parts/JoinLines/JoinLines.js +0 -3
- package/src/parts/Platform/Platform.js +0 -1
- package/src/parts/Promises/Promises.js +0 -19
- package/src/parts/SplitLines/SplitLines.js +0 -3
- package/src/parts/WebSocketSerialization/WebSocketSerialization.js +0 -7
- package/src/parts/WebSocketServer/WebSocketServer.ipc.js +0 -7
- package/src/parts/WebSocketServer/WebSocketServer.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/pty-host",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"node": ">=18"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
+
"@lvce-editor/ipc": "^2.1.0",
|
|
19
20
|
"@lvce-editor/json-rpc": "^1.0.0",
|
|
20
21
|
"@lvce-editor/pretty-error": "^1.4.1",
|
|
21
22
|
"@lvce-editor/verror": "^1.1.2",
|
|
@@ -4,6 +4,9 @@ export const listen = async ({ method, ...params }) => {
|
|
|
4
4
|
const module = await IpcChildModule.getModule(method)
|
|
5
5
|
// @ts-ignore
|
|
6
6
|
const rawIpc = await module.listen(params)
|
|
7
|
+
if (module.signal) {
|
|
8
|
+
module.signal(rawIpc)
|
|
9
|
+
}
|
|
7
10
|
const ipc = module.wrap(rawIpc)
|
|
8
11
|
return ipc
|
|
9
12
|
}
|
|
@@ -1,48 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export const listen = () => {
|
|
4
|
-
// @ts-ignore
|
|
5
|
-
const parentPort = process.parentPort
|
|
6
|
-
if (!parentPort) {
|
|
7
|
-
throw new IpcError('parent port must be defined')
|
|
8
|
-
}
|
|
9
|
-
parentPort.postMessage('ready')
|
|
10
|
-
return parentPort
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const getActualData = (event) => {
|
|
14
|
-
const { data, ports } = event
|
|
15
|
-
if (ports.length === 0) {
|
|
16
|
-
return data
|
|
17
|
-
}
|
|
18
|
-
return {
|
|
19
|
-
...data,
|
|
20
|
-
params: [...data.params, ...ports],
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const wrap = (parentPort) => {
|
|
25
|
-
return {
|
|
26
|
-
parentPort,
|
|
27
|
-
on(event, listener) {
|
|
28
|
-
if (event === 'message') {
|
|
29
|
-
const wrappedListener = (event) => {
|
|
30
|
-
const actualData = getActualData(event)
|
|
31
|
-
listener(actualData)
|
|
32
|
-
}
|
|
33
|
-
this.parentPort.on(event, wrappedListener)
|
|
34
|
-
} else {
|
|
35
|
-
throw new Error('unsupported event type')
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
off(event, listener) {
|
|
39
|
-
this.parentPort.off(event, listener)
|
|
40
|
-
},
|
|
41
|
-
send(message) {
|
|
42
|
-
this.parentPort.postMessage(message)
|
|
43
|
-
},
|
|
44
|
-
dispose() {
|
|
45
|
-
this.parentPort.close()
|
|
46
|
-
},
|
|
47
|
-
}
|
|
48
|
-
}
|
|
1
|
+
export * from '@lvce-editor/ipc/dist/parts/IpcChildWithElectronUtilityProcess/IpcChildWithElectronUtilityProcess.js'
|
|
@@ -1,56 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { IpcError } from '../IpcError/IpcError.js'
|
|
3
|
-
import * as IsWebSocketOpen from '../IsWebSocketOpen/IsWebSocketOpen.js'
|
|
4
|
-
import * as WebSocketSerialization from '../WebSocketSerialization/WebSocketSerialization.js'
|
|
5
|
-
import * as WebSocketServer from '../WebSocketServer/WebSocketServer.js'
|
|
6
|
-
|
|
7
|
-
export const listen = async ({ request, handle }) => {
|
|
8
|
-
if (!request) {
|
|
9
|
-
throw new IpcError('request must be defined')
|
|
10
|
-
}
|
|
11
|
-
if (!handle) {
|
|
12
|
-
throw new IpcError('handle must be defined')
|
|
13
|
-
}
|
|
14
|
-
const webSocket = await WebSocketServer.handleUpgrade(request, handle)
|
|
15
|
-
webSocket.pause()
|
|
16
|
-
if (!IsWebSocketOpen.isWebSocketOpen(webSocket)) {
|
|
17
|
-
const { type, event } = await GetFirstWebSocketEvent.getFirstWebSocketEvent(webSocket)
|
|
18
|
-
}
|
|
19
|
-
return webSocket
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const wrap = (webSocket) => {
|
|
23
|
-
return {
|
|
24
|
-
webSocket,
|
|
25
|
-
/**
|
|
26
|
-
* @type {any}
|
|
27
|
-
*/
|
|
28
|
-
wrappedListener: undefined,
|
|
29
|
-
on(event, listener) {
|
|
30
|
-
switch (event) {
|
|
31
|
-
case 'message':
|
|
32
|
-
const wrappedListener = (message) => {
|
|
33
|
-
const data = WebSocketSerialization.deserialize(message)
|
|
34
|
-
listener(data)
|
|
35
|
-
}
|
|
36
|
-
webSocket.on('message', wrappedListener)
|
|
37
|
-
break
|
|
38
|
-
default:
|
|
39
|
-
throw new Error('unknown event listener type')
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
off(event, listener) {
|
|
43
|
-
this.webSocket.off(event, listener)
|
|
44
|
-
},
|
|
45
|
-
send(message) {
|
|
46
|
-
const stringifiedMessage = WebSocketSerialization.serialize(message)
|
|
47
|
-
this.webSocket.send(stringifiedMessage)
|
|
48
|
-
},
|
|
49
|
-
dispose() {
|
|
50
|
-
this.webSocket.close()
|
|
51
|
-
},
|
|
52
|
-
start() {
|
|
53
|
-
this.webSocket.resume()
|
|
54
|
-
},
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
export * from '@lvce-editor/ipc/dist/parts/IpcChildWithWebSocket/IpcChildWithWebSocket.js'
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import * as SplitLines from '../SplitLines/SplitLines.js'
|
|
2
|
-
|
|
3
|
-
const RE_AT = /^\s+at/
|
|
4
|
-
const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/
|
|
5
|
-
const RE_OBJECT_AS = /^\s*at (async )?Object\.\w+ \[as ([\w\.]+)\]/
|
|
6
|
-
const RE_GET_RESPONSE = /^\s*at async getResponse/
|
|
7
|
-
const RE_WEBSOCKET_HANDLE_MESSAGE = /^\s*at async WebSocket.handleMessage/
|
|
8
|
-
const RE_EXECUTE_COMMAND_ASYNC = /^\s*at executeCommandAsync/
|
|
9
|
-
const RE_HANDLE_OTHER_MESSAGES_FROM_MESSAGE_PORT = /^\s*at async MessagePort\.handleOtherMessagesFromMessagePort/
|
|
10
|
-
|
|
11
|
-
const isInternalLine = (line) => {
|
|
12
|
-
return line.includes('node:') || RE_AT_PROMISE_INDEX.test(line) || line.includes('node_modules/ws')
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const isRelevantLine = (line) => {
|
|
16
|
-
return !isInternalLine(line)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const isApplicationUsefulLine = (line, index) => {
|
|
20
|
-
if (index === 0) {
|
|
21
|
-
return true
|
|
22
|
-
}
|
|
23
|
-
if (RE_GET_RESPONSE.test(line)) {
|
|
24
|
-
return false
|
|
25
|
-
}
|
|
26
|
-
if (RE_WEBSOCKET_HANDLE_MESSAGE.test(line)) {
|
|
27
|
-
return false
|
|
28
|
-
}
|
|
29
|
-
if (RE_EXECUTE_COMMAND_ASYNC.test(line)) {
|
|
30
|
-
return false
|
|
31
|
-
}
|
|
32
|
-
if (RE_HANDLE_OTHER_MESSAGES_FROM_MESSAGE_PORT.test(line)) {
|
|
33
|
-
return false
|
|
34
|
-
}
|
|
35
|
-
return true
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const isNormalStackLine = (line) => {
|
|
39
|
-
return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const cleanLine = (line) => {
|
|
43
|
-
if (line.startsWith(' at exports.')) {
|
|
44
|
-
return ' at ' + line.slice(' at exports.'.length)
|
|
45
|
-
}
|
|
46
|
-
if (line.startsWith(' at async exports.')) {
|
|
47
|
-
return ' at async ' + line.slice(' at async exports.'.length)
|
|
48
|
-
}
|
|
49
|
-
if (line.startsWith(' at async Module.')) {
|
|
50
|
-
return ' at async ' + line.slice(' at async Module.'.length)
|
|
51
|
-
}
|
|
52
|
-
if (line.startsWith(' at Module.')) {
|
|
53
|
-
return ' at ' + line.slice(' at Module.'.length)
|
|
54
|
-
}
|
|
55
|
-
const objectMatch = line.match(RE_OBJECT_AS)
|
|
56
|
-
if (objectMatch) {
|
|
57
|
-
const rest = line.slice(objectMatch[0].length)
|
|
58
|
-
if (objectMatch[1]) {
|
|
59
|
-
return ' at ' + objectMatch[1] + objectMatch[2] + rest
|
|
60
|
-
}
|
|
61
|
-
return ' at ' + objectMatch[2] + rest
|
|
62
|
-
}
|
|
63
|
-
return line
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const getDetails = (lines) => {
|
|
67
|
-
const index = lines.findIndex(isNormalStackLine)
|
|
68
|
-
return {
|
|
69
|
-
custom: lines.slice(0, index),
|
|
70
|
-
actualStack: lines.slice(index).map(cleanLine),
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const RE_PATH_1 = /^\/(.*)(\d+)$/
|
|
75
|
-
|
|
76
|
-
const mergeCustom = (custom, relevantStack) => {
|
|
77
|
-
if (custom.length === 0) {
|
|
78
|
-
return relevantStack
|
|
79
|
-
}
|
|
80
|
-
const firstLine = custom[0]
|
|
81
|
-
if (RE_PATH_1.test(firstLine)) {
|
|
82
|
-
return [` at ${firstLine}`, ...relevantStack]
|
|
83
|
-
}
|
|
84
|
-
return relevantStack
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export const cleanStack = (stack) => {
|
|
88
|
-
const lines = SplitLines.splitLines(stack)
|
|
89
|
-
const { custom, actualStack } = getDetails(lines)
|
|
90
|
-
const relevantStack = actualStack.filter(isRelevantLine).filter(isApplicationUsefulLine)
|
|
91
|
-
const merged = mergeCustom(custom, relevantStack)
|
|
92
|
-
return merged
|
|
93
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const Utf8 = 'utf8'
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import * as Promises from '../Promises/Promises.js'
|
|
2
|
-
|
|
3
|
-
export const getFirstEvent = async (eventEmitter, eventMap) => {
|
|
4
|
-
const { resolve, promise } = Promises.withResolvers()
|
|
5
|
-
const listenerMap = Object.create(null)
|
|
6
|
-
const cleanup = (value) => {
|
|
7
|
-
for (const event of Object.keys(eventMap)) {
|
|
8
|
-
eventEmitter.off(event, listenerMap[event])
|
|
9
|
-
}
|
|
10
|
-
resolve(value)
|
|
11
|
-
}
|
|
12
|
-
for (const [event, type] of Object.entries(eventMap)) {
|
|
13
|
-
const listener = (event) => {
|
|
14
|
-
cleanup({
|
|
15
|
-
type,
|
|
16
|
-
event,
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
eventEmitter.on(event, listener)
|
|
20
|
-
listenerMap[event] = listener
|
|
21
|
-
}
|
|
22
|
-
const { type, event } = await promise
|
|
23
|
-
return { type, event }
|
|
24
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { WebSocket } from 'ws'
|
|
2
|
-
import * as FirstWebSocketEventType from '../FirstWebSocketEventType/FirstWebSocketEventType.js'
|
|
3
|
-
import * as GetFirstEvent from '../GetFirstEvent/GetFirstEvent.js'
|
|
4
|
-
|
|
5
|
-
export const getFirstWebSocketEvent = async (webSocket) => {
|
|
6
|
-
switch (webSocket.readyState) {
|
|
7
|
-
case WebSocket.OPEN:
|
|
8
|
-
return {
|
|
9
|
-
type: FirstWebSocketEventType.Open,
|
|
10
|
-
event: undefined,
|
|
11
|
-
}
|
|
12
|
-
case WebSocket.CLOSED:
|
|
13
|
-
return {
|
|
14
|
-
type: FirstWebSocketEventType.Close,
|
|
15
|
-
event: undefined,
|
|
16
|
-
}
|
|
17
|
-
default:
|
|
18
|
-
break
|
|
19
|
-
}
|
|
20
|
-
const { type, event } = await GetFirstEvent.getFirstEvent(webSocket, {
|
|
21
|
-
open: FirstWebSocketEventType.Open,
|
|
22
|
-
close: FirstWebSocketEventType.Close,
|
|
23
|
-
})
|
|
24
|
-
return { type, event }
|
|
25
|
-
}
|
package/src/parts/Id/Id.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const isWindows = process.platform === 'win32'
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export const withResolvers = () => {
|
|
2
|
-
/**
|
|
3
|
-
* @type {any}
|
|
4
|
-
*/
|
|
5
|
-
let _resolve
|
|
6
|
-
/**
|
|
7
|
-
* @type {any}
|
|
8
|
-
*/
|
|
9
|
-
let _reject
|
|
10
|
-
const promise = new Promise((resolve, reject) => {
|
|
11
|
-
_resolve = resolve
|
|
12
|
-
_reject = reject
|
|
13
|
-
})
|
|
14
|
-
return {
|
|
15
|
-
resolve: _resolve,
|
|
16
|
-
reject: _reject,
|
|
17
|
-
promise,
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@lvce-editor/web-socket-server'
|