@lvce-editor/pty-host 0.15.17 → 0.15.18
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 +1 -1
- package/src/parts/CommandMap/CommandMap.js +7 -4
- package/src/parts/HandleNodeMessagePort/HandleNodeMessagePort.js +12 -0
- package/src/parts/IpcChildModule/IpcChildModule.js +2 -0
- package/src/parts/IpcChildType/IpcChildType.js +1 -0
- package/src/parts/IpcChildWithElectronMessagePort/IpcChildWithElectronMessagePort.js +6 -0
- package/src/parts/IpcChildWithElectronUtilityProcess/IpcChildWithElectronUtilityProcess.js +3 -1
- package/src/parts/IpcChildWithNodeForkedProcess/IpcChildWithNodeForkedProcess.js +3 -1
- package/src/parts/IpcChildWithNodeMessagePort/IpcChildWithNodeMessagePort.js +27 -0
- package/src/parts/IpcError/IpcError.js +6 -0
- package/src/parts/IsMessagePort/IsMessagePort.js +3 -0
- package/src/parts/IsMessagePortMain/IsMessagePortMain.js +3 -0
- package/src/parts/NodePty/NodePty.js +60 -0
- package/src/parts/Pty/Pty.js +1 -60
- package/src/parts/PtyController/PtyController.js +2 -1
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import * as PtyController from '../PtyController/PtyController.js'
|
|
2
|
-
import * as HandleWebSocket from '../HandleWebSocket/HandleWebSocket.js'
|
|
3
1
|
import * as HandleElectronMessagePort from '../HandleElectronMessagePort/HandleElectronMessagePort.js'
|
|
2
|
+
import * as HandleNodeMessagePort from '../HandleNodeMessagePort/HandleNodeMessagePort.js'
|
|
3
|
+
import * as HandleWebSocket from '../HandleWebSocket/HandleWebSocket.js'
|
|
4
|
+
import * as PtyController from '../PtyController/PtyController.js'
|
|
4
5
|
|
|
5
6
|
export const commandMap = {
|
|
7
|
+
'HandleElectronMessagePort.handleElectronMessagePort': HandleElectronMessagePort.handleElectronMessagePort,
|
|
8
|
+
'HandleNodeMessagePort.handleNodeMessagePort': HandleNodeMessagePort.handleNodeMessagePort,
|
|
9
|
+
'HandleWebSocket.handleWebSocket': HandleWebSocket.handleWebSocket,
|
|
6
10
|
'Terminal.create': PtyController.create,
|
|
7
11
|
'Terminal.write': PtyController.write,
|
|
8
|
-
'
|
|
9
|
-
'HandleElectronMessagePort.handleElectronMessagePort': HandleElectronMessagePort.handleElectronMessagePort,
|
|
12
|
+
'Terminal.dispose': PtyController.dispose,
|
|
10
13
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as HandleIpc from '../HandleIpc/HandleIpc.js'
|
|
2
|
+
import * as IpcChild from '../IpcChild/IpcChild.js'
|
|
3
|
+
import * as IpcChildType from '../IpcChildType/IpcChildType.js'
|
|
4
|
+
|
|
5
|
+
export const handleNodeMessagePort = async (messagePort) => {
|
|
6
|
+
const ipc = await IpcChild.listen({
|
|
7
|
+
method: IpcChildType.NodeMessagePort,
|
|
8
|
+
messagePort,
|
|
9
|
+
})
|
|
10
|
+
HandleIpc.handleIpc(ipc)
|
|
11
|
+
messagePort.start()
|
|
12
|
+
}
|
|
@@ -12,6 +12,8 @@ export const getModule = (method) => {
|
|
|
12
12
|
return import('../IpcChildWithElectronUtilityProcess/IpcChildWithElectronUtilityProcess.js')
|
|
13
13
|
case IpcChildType.ElectronMessagePort:
|
|
14
14
|
return import('../IpcChildWithElectronMessagePort/IpcChildWithElectronMessagePort.js')
|
|
15
|
+
case IpcChildType.NodeMessagePort:
|
|
16
|
+
return import('../IpcChildWithNodeMessagePort/IpcChildWithNodeMessagePort.js')
|
|
15
17
|
default:
|
|
16
18
|
throw new Error('unexpected ipc type')
|
|
17
19
|
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
import { IpcError } from '../IpcError/IpcError.js'
|
|
2
|
+
import * as IsMessagePortMain from '../IsMessagePortMain/IsMessagePortMain.js'
|
|
3
|
+
|
|
1
4
|
export const listen = ({ messagePort }) => {
|
|
5
|
+
if (!IsMessagePortMain.isMessagePortMain(messagePort)) {
|
|
6
|
+
throw new IpcError('port must be of type MessagePortMain')
|
|
7
|
+
}
|
|
2
8
|
return messagePort
|
|
3
9
|
}
|
|
4
10
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { IpcError } from '../IpcError/IpcError.js'
|
|
2
|
+
|
|
1
3
|
export const listen = () => {
|
|
2
4
|
// @ts-ignore
|
|
3
5
|
const parentPort = process.parentPort
|
|
4
6
|
if (!parentPort) {
|
|
5
|
-
throw new
|
|
7
|
+
throw new IpcError('parent port must be defined')
|
|
6
8
|
}
|
|
7
9
|
parentPort.postMessage('ready')
|
|
8
10
|
return parentPort
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { IpcError } from '../IpcError/IpcError.js'
|
|
2
|
+
import * as IsMessagePort from '../IsMessagePort/IsMessagePort.js'
|
|
3
|
+
|
|
4
|
+
export const listen = async ({ messagePort }) => {
|
|
5
|
+
if (!IsMessagePort.isMessagePort(messagePort)) {
|
|
6
|
+
throw new IpcError(`port must be of type MessagePort`)
|
|
7
|
+
}
|
|
8
|
+
return messagePort
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const wrap = (port) => {
|
|
12
|
+
return {
|
|
13
|
+
port,
|
|
14
|
+
on(event, listener) {
|
|
15
|
+
this.port.on(event, listener)
|
|
16
|
+
},
|
|
17
|
+
off(event, listener) {
|
|
18
|
+
this.port.off(event, listener)
|
|
19
|
+
},
|
|
20
|
+
send(message) {
|
|
21
|
+
this.port.postMessage(message)
|
|
22
|
+
},
|
|
23
|
+
dispose() {
|
|
24
|
+
this.port.close()
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { spawn } from 'node-pty'
|
|
2
|
+
import * as Platform from '../Platform/Platform.js'
|
|
3
|
+
import * as Assert from '../Assert/Assert.js'
|
|
4
|
+
import VError from 'verror'
|
|
5
|
+
|
|
6
|
+
const getSpawnOptions = () => {
|
|
7
|
+
if (Platform.isWindows) {
|
|
8
|
+
return {
|
|
9
|
+
command: 'powershell.exe',
|
|
10
|
+
args: [],
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
command: 'bash',
|
|
15
|
+
args: ['-i'],
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const create = ({ env = {}, cwd } = {}) => {
|
|
20
|
+
try {
|
|
21
|
+
Assert.string(cwd)
|
|
22
|
+
const spawnOptions = getSpawnOptions()
|
|
23
|
+
const pty = spawn(spawnOptions.command, spawnOptions.args, {
|
|
24
|
+
encoding: null,
|
|
25
|
+
cwd,
|
|
26
|
+
// cols: 10,
|
|
27
|
+
// rows: 10,
|
|
28
|
+
})
|
|
29
|
+
return pty
|
|
30
|
+
} catch (error) {
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
throw new VError(error, `Failed to create terminal`)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const onData = (pty, fn) => {
|
|
37
|
+
Assert.object(pty)
|
|
38
|
+
pty.onData(fn)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const write = (pty, data) => {
|
|
42
|
+
try {
|
|
43
|
+
Assert.object(pty)
|
|
44
|
+
pty.write(data)
|
|
45
|
+
} catch (error) {
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
throw new VError(error, `Failed to write data to terminal`)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const resize = (pty, columns, rows) => {
|
|
52
|
+
Assert.object(pty)
|
|
53
|
+
Assert.number(columns)
|
|
54
|
+
Assert.number(rows)
|
|
55
|
+
pty.resize(columns, rows)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const dispose = (pty) => {
|
|
59
|
+
pty.kill()
|
|
60
|
+
}
|
package/src/parts/Pty/Pty.js
CHANGED
|
@@ -1,60 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import * as Platform from '../Platform/Platform.js'
|
|
3
|
-
import * as Assert from '../Assert/Assert.js'
|
|
4
|
-
import VError from 'verror'
|
|
5
|
-
|
|
6
|
-
const getSpawnOptions = () => {
|
|
7
|
-
if (Platform.isWindows) {
|
|
8
|
-
return {
|
|
9
|
-
command: 'powershell.exe',
|
|
10
|
-
args: [],
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return {
|
|
14
|
-
command: 'bash',
|
|
15
|
-
args: ['-i'],
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const create = ({ env = {}, cwd } = {}) => {
|
|
20
|
-
try {
|
|
21
|
-
Assert.string(cwd)
|
|
22
|
-
const spawnOptions = getSpawnOptions()
|
|
23
|
-
const pty = spawn(spawnOptions.command, spawnOptions.args, {
|
|
24
|
-
encoding: null,
|
|
25
|
-
cwd,
|
|
26
|
-
// cols: 10,
|
|
27
|
-
// rows: 10,
|
|
28
|
-
})
|
|
29
|
-
return pty
|
|
30
|
-
} catch (error) {
|
|
31
|
-
// @ts-ignore
|
|
32
|
-
throw new VError(error, `Failed to create terminal`)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const onData = (pty, fn) => {
|
|
37
|
-
Assert.object(pty)
|
|
38
|
-
pty.onData(fn)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export const write = (pty, data) => {
|
|
42
|
-
try {
|
|
43
|
-
Assert.object(pty)
|
|
44
|
-
pty.write(data)
|
|
45
|
-
} catch (error) {
|
|
46
|
-
// @ts-ignore
|
|
47
|
-
throw new VError(error, `Failed to write data to terminal`)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export const resize = (pty, columns, rows) => {
|
|
52
|
-
Assert.object(pty)
|
|
53
|
-
Assert.number(columns)
|
|
54
|
-
Assert.number(rows)
|
|
55
|
-
pty.resize(columns, rows)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export const dispose = (pty) => {
|
|
59
|
-
pty.kill()
|
|
60
|
-
}
|
|
1
|
+
export * from '../NodePty/NodePty.js'
|