@lvce-editor/extension-host-helper-process 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/CommandMap/CommandMap.js +0 -4
- package/src/parts/IpcChild/IpcChild.js +5 -0
- package/src/parts/IpcChildWithElectronUtilityProcess/IpcChildWithElectronUtilityProcess.js +1 -43
- package/src/parts/IpcChildWithWebSocket/IpcChildWithWebSocket.js +1 -56
- package/src/parts/Ajax/Ajax.ipc.js +0 -7
- package/src/parts/Ajax/Ajax.js +0 -13
- package/src/parts/Exec/Exec.ipc.js +0 -7
- package/src/parts/Exec/Exec.js +0 -16
- package/src/parts/FirstWebSocketEventType/FirstWebSocketEventType.js +0 -2
- package/src/parts/GetData/GetData.js +0 -3
- package/src/parts/GetFirstWebSocketEvent/GetFirstWebSocketEvent.js +0 -41
- package/src/parts/GetWebSocket/GetWebSocket.js +0 -25
- package/src/parts/HandleJsonRpcMessage/HandleJsonRpcMessage.js +0 -10
- package/src/parts/Id/Id.js +0 -7
- package/src/parts/IsMessagePort/IsMessagePort.js +0 -3
- package/src/parts/IsSocket/IsSocket.js +0 -5
- package/src/parts/IsWebSocket/IsWebSocket.js +0 -5
- package/src/parts/IsWebSocketOpen/IsWebSocketOpen.js +0 -5
- package/src/parts/Json/Json.js +0 -7
- package/src/parts/Module/Module.js +0 -12
- package/src/parts/ModuleId/ModuleId.js +0 -2
- package/src/parts/ModuleMap/ModuleMap.js +0 -20
- package/src/parts/Process/Process.ipc.js +0 -9
- 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/extension-host-helper-process",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@lvce-editor/assert": "^1.2.0",
|
|
20
|
+
"@lvce-editor/ipc": "^2.1.0",
|
|
20
21
|
"@lvce-editor/json-rpc": "^1.0.0",
|
|
21
22
|
"@lvce-editor/pretty-error": "^1.4.1",
|
|
22
23
|
"@lvce-editor/verror": "^1.1.2",
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import * as Ajax from '../Ajax/Ajax.js'
|
|
2
|
-
import * as Exec from '../Exec/Exec.js'
|
|
3
1
|
import * as HandleElectronMessagePort from '../HandleElectronMessagePort/HandleElectronMessagePort.js'
|
|
4
2
|
import * as HandleWebSocket from '../HandleWebSocket/HandleWebSocket.js'
|
|
5
3
|
import * as LoadFile from '../LoadFile/LoadFile.js'
|
|
6
4
|
|
|
7
5
|
export const commandMap = {
|
|
8
|
-
'Exec.exec': Exec.exec,
|
|
9
|
-
'Ajax.getJson': Ajax.getJson,
|
|
10
6
|
'HandleWebSocket.handleWebSocket': HandleWebSocket.handleWebSocket,
|
|
11
7
|
'LoadFile.loadFile': LoadFile.loadFile,
|
|
12
8
|
'HandleElectronMessagePort.handleElectronMessagePort': HandleElectronMessagePort.handleElectronMessagePort,
|
|
@@ -3,6 +3,11 @@ import * as IpcChildModule from '../IpcChildModule/IpcChildModule.js'
|
|
|
3
3
|
export const listen = async ({ method, ...params }) => {
|
|
4
4
|
const module = await IpcChildModule.getModule(method)
|
|
5
5
|
const rawIpc = await module.listen(params)
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
if (module.signal) {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
module.signal(rawIpc)
|
|
10
|
+
}
|
|
6
11
|
const ipc = module.wrap(rawIpc)
|
|
7
12
|
return ipc
|
|
8
13
|
}
|
|
@@ -1,43 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { IpcError } from '../IpcError/IpcError.js'
|
|
3
|
-
|
|
4
|
-
export const listen = () => {
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
const parentPort = process.parentPort
|
|
7
|
-
if (!parentPort) {
|
|
8
|
-
throw new IpcError('parent port must be defined')
|
|
9
|
-
}
|
|
10
|
-
parentPort.postMessage('ready')
|
|
11
|
-
return parentPort
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const wrap = (parentPort) => {
|
|
15
|
-
return {
|
|
16
|
-
parentPort,
|
|
17
|
-
on(event, listener) {
|
|
18
|
-
if (event === 'message') {
|
|
19
|
-
const wrappedListener = (event) => {
|
|
20
|
-
const actualData = GetUtilityProcessPortData.getUtilityProcessPortData(event)
|
|
21
|
-
listener(actualData)
|
|
22
|
-
}
|
|
23
|
-
this.parentPort.on(event, wrappedListener)
|
|
24
|
-
} else if (event === 'close') {
|
|
25
|
-
this.parentPort.on('close', listener)
|
|
26
|
-
} else {
|
|
27
|
-
throw new Error('unsupported event type')
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
off(event, listener) {
|
|
31
|
-
this.parentPort.off(event, listener)
|
|
32
|
-
},
|
|
33
|
-
send(message) {
|
|
34
|
-
this.parentPort.postMessage(message)
|
|
35
|
-
},
|
|
36
|
-
sendAndTransfer(message, transfer) {
|
|
37
|
-
this.parentPort.postMessage(message, transfer)
|
|
38
|
-
},
|
|
39
|
-
dispose() {
|
|
40
|
-
this.parentPort.close()
|
|
41
|
-
},
|
|
42
|
-
}
|
|
43
|
-
}
|
|
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'
|
package/src/parts/Ajax/Ajax.js
DELETED
package/src/parts/Exec/Exec.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { execa } from 'execa'
|
|
2
|
-
import * as Assert from '../Assert/Assert.js'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated use node api directly
|
|
6
|
-
*/
|
|
7
|
-
export const exec = async (file, args, options) => {
|
|
8
|
-
Assert.string(file)
|
|
9
|
-
Assert.array(args)
|
|
10
|
-
const { stdout, stderr, exitCode } = await execa(file, args, options)
|
|
11
|
-
return {
|
|
12
|
-
stdout,
|
|
13
|
-
stderr,
|
|
14
|
-
exitCode,
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import * as FirstWebSocketEventType from '../FirstWebSocketEventType/FirstWebSocketEventType.js'
|
|
2
|
-
import { WebSocket } from 'ws'
|
|
3
|
-
|
|
4
|
-
export const getFirstWebSocketEvent = async (webSocket) => {
|
|
5
|
-
switch (webSocket.readyState) {
|
|
6
|
-
case WebSocket.OPEN:
|
|
7
|
-
return {
|
|
8
|
-
type: FirstWebSocketEventType.Open,
|
|
9
|
-
event: undefined,
|
|
10
|
-
}
|
|
11
|
-
case WebSocket.CLOSED:
|
|
12
|
-
return {
|
|
13
|
-
type: FirstWebSocketEventType.Close,
|
|
14
|
-
event: undefined,
|
|
15
|
-
}
|
|
16
|
-
default:
|
|
17
|
-
break
|
|
18
|
-
}
|
|
19
|
-
const { type, event } = await new Promise((resolve) => {
|
|
20
|
-
const cleanup = (value) => {
|
|
21
|
-
webSocket.off('open', handleOpen)
|
|
22
|
-
webSocket.off('close', handleClose)
|
|
23
|
-
resolve(value)
|
|
24
|
-
}
|
|
25
|
-
const handleOpen = (event) => {
|
|
26
|
-
cleanup({
|
|
27
|
-
type: FirstWebSocketEventType.Open,
|
|
28
|
-
event,
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
const handleClose = (event) => {
|
|
32
|
-
cleanup({
|
|
33
|
-
type: FirstWebSocketEventType.Close,
|
|
34
|
-
event,
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
webSocket.on('open', handleOpen)
|
|
38
|
-
webSocket.on('close', handleClose)
|
|
39
|
-
})
|
|
40
|
-
return { type, event }
|
|
41
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import * as _ws from 'ws'
|
|
2
|
-
|
|
3
|
-
export const getWebSocket = async (message, handle) => {
|
|
4
|
-
// workaround for jest or node bug
|
|
5
|
-
const WebSocketServer = _ws.WebSocketServer
|
|
6
|
-
? _ws.WebSocketServer
|
|
7
|
-
: // @ts-ignore
|
|
8
|
-
_ws.default.WebSocketServer
|
|
9
|
-
|
|
10
|
-
const webSocketServer = new WebSocketServer({
|
|
11
|
-
noServer: true,
|
|
12
|
-
})
|
|
13
|
-
const webSocket = await new Promise((resolve, reject) => {
|
|
14
|
-
const upgradeCallback = (webSocket) => {
|
|
15
|
-
resolve(webSocket)
|
|
16
|
-
}
|
|
17
|
-
webSocketServer.handleUpgrade(
|
|
18
|
-
message,
|
|
19
|
-
handle,
|
|
20
|
-
Buffer.alloc(0),
|
|
21
|
-
upgradeCallback
|
|
22
|
-
)
|
|
23
|
-
})
|
|
24
|
-
return webSocket
|
|
25
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as GetResponse from '../GetResponse/GetResponse.js'
|
|
2
|
-
|
|
3
|
-
export const handleJsonRpcMessage = async (ipc, message, execute, resolve) => {
|
|
4
|
-
if ('result' in message || 'error' in message) {
|
|
5
|
-
resolve(message.id, message)
|
|
6
|
-
return
|
|
7
|
-
}
|
|
8
|
-
const response = await GetResponse.getResponse(message, execute)
|
|
9
|
-
ipc.send(response)
|
|
10
|
-
}
|
package/src/parts/Id/Id.js
DELETED
package/src/parts/Json/Json.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as ModuleId from '../ModuleId/ModuleId.js'
|
|
2
|
-
|
|
3
|
-
export const load = (moduleId) => {
|
|
4
|
-
switch (moduleId) {
|
|
5
|
-
case ModuleId.Exec:
|
|
6
|
-
return import('../Exec/Exec.ipc.js')
|
|
7
|
-
case ModuleId.Ajax:
|
|
8
|
-
return import('../Ajax/Ajax.ipc.js')
|
|
9
|
-
default:
|
|
10
|
-
throw new Error(`module ${moduleId} not found`)
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import * as ModuleId from '../ModuleId/ModuleId.js'
|
|
2
|
-
|
|
3
|
-
const getPrefix = (commandId) => {
|
|
4
|
-
if (!commandId || typeof commandId !== 'string') {
|
|
5
|
-
return commandId
|
|
6
|
-
}
|
|
7
|
-
return commandId.slice(0, commandId.indexOf('.'))
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const getModuleId = (commandId) => {
|
|
11
|
-
const prefix = getPrefix(commandId)
|
|
12
|
-
switch (prefix) {
|
|
13
|
-
case 'Exec':
|
|
14
|
-
return ModuleId.Exec
|
|
15
|
-
case 'Ajax':
|
|
16
|
-
return ModuleId.Ajax
|
|
17
|
-
default:
|
|
18
|
-
throw new Error(`command ${commandId} not found`)
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@lvce-editor/web-socket-server'
|