@lvce-editor/pty-host 1.1.0 → 1.2.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/pty-host",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "",
5
5
  "main": "src/ptyHostMain.js",
6
6
  "bin": "bin/ptyHost.js",
@@ -19,7 +19,7 @@
19
19
  "node": ">=18"
20
20
  },
21
21
  "dependencies": {
22
- "@lvce-editor/ipc": "^8.2.1",
22
+ "@lvce-editor/ipc": "^9.1.0",
23
23
  "@lvce-editor/json-rpc": "^1.3.0",
24
24
  "@lvce-editor/pretty-error": "^1.5.0",
25
25
  "@lvce-editor/verror": "^1.2.0",
@@ -5,8 +5,10 @@ import * as PtyController from '../PtyController/PtyController.js'
5
5
  import * as TerminalProcessCommandType from '../TerminalProcessCommandType/TerminalProcessCommandType.js'
6
6
 
7
7
  export const commandMap = {
8
- [TerminalProcessCommandType.HandleElectronMessagePort]: HandleElectronMessagePort.handleElectronMessagePort,
9
- [TerminalProcessCommandType.HandleNodeMessagePort]: HandleNodeMessagePort.handleNodeMessagePort,
8
+ [TerminalProcessCommandType.HandleElectronMessagePort]:
9
+ HandleElectronMessagePort.handleElectronMessagePort,
10
+ [TerminalProcessCommandType.HandleNodeMessagePort]:
11
+ HandleNodeMessagePort.handleNodeMessagePort,
10
12
  [TerminalProcessCommandType.HandleWebSocket]: HandleWebSocket.handleWebSocket,
11
13
  [TerminalProcessCommandType.TerminalCreate]: PtyController.create,
12
14
  [TerminalProcessCommandType.TerminalResize]: PtyController.resize,
@@ -3,7 +3,8 @@ export const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND'
3
3
  export const E_ICON_THEME_NOT_FOUND = 'E_ICON_THEME_NOT_FOUND'
4
4
  export const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE'
5
5
  export const E_MANIFEST_NOT_FOUND = 'E_MANIFEST_NOT_FOUND'
6
- export const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON'
6
+ export const E_MODULES_NOT_SUPPORTED_IN_ELECTRON =
7
+ 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON'
7
8
  export const EACCES = 'EACCES'
8
9
  export const ECONNRESET = 'ECONNRESET'
9
10
  export const EEXIST = 'EEXIST'
@@ -20,7 +20,9 @@ const preparePrettyError = (error) => {
20
20
  }
21
21
 
22
22
  const printPrettyError = (prettyError) => {
23
- console.error(`${prettyError.message}\n${prettyError.codeFrame}\n${prettyError.stack}`)
23
+ console.error(
24
+ `${prettyError.message}\n${prettyError.codeFrame}\n${prettyError.stack}`,
25
+ )
24
26
  }
25
27
 
26
28
  export const handleError = (error) => {
@@ -62,7 +64,12 @@ export const handleUncaughtExceptionMonitor = (error, origin) => {
62
64
  return
63
65
  }
64
66
  const prettyError = PrettyError.prepare(error)
65
- // @ts-ignore
66
- Logger.error(prettyError.codeFrame + Character.NewLine + prettyError.stack + Character.NewLine)
67
+ Logger.error(
68
+ // @ts-ignore
69
+ prettyError.codeFrame +
70
+ Character.NewLine +
71
+ prettyError.stack +
72
+ Character.NewLine,
73
+ )
67
74
  Process.setExitCode(ExitCode.Error)
68
75
  }
@@ -3,9 +3,9 @@ import * as HandleIpc from '../HandleIpc/HandleIpc.js'
3
3
  import * as IpcChild from '../IpcChild/IpcChild.js'
4
4
  import * as IpcChildType from '../IpcChildType/IpcChildType.js'
5
5
 
6
- export const handleWebSocket = async (request, handle) => {
7
- Assert.object(request)
6
+ export const handleWebSocket = async (handle, request) => {
8
7
  Assert.object(handle)
8
+ Assert.object(request)
9
9
  const ipc = await IpcChild.listen({
10
10
  method: IpcChildType.WebSocket,
11
11
  request,
@@ -6,7 +6,11 @@ export const isIgnoredError = (error) => {
6
6
  // parent process is disposed, ignore
7
7
  return true
8
8
  }
9
- if (error && error.code === ErrorCodes.ERR_IPC_CHANNEL_CLOSED && !Process.isConnected()) {
9
+ if (
10
+ error &&
11
+ error.code === ErrorCodes.ERR_IPC_CHANNEL_CLOSED &&
12
+ !Process.isConnected()
13
+ ) {
10
14
  // parent process is disposed, ignore
11
15
  return true
12
16
  }
@@ -4,7 +4,10 @@ import * as Listen from '../Listen/Listen.js'
4
4
  import * as ProcessListeners from '../ProcessListeners/ProcessListeners.js'
5
5
 
6
6
  export const main = async () => {
7
- process.on('uncaughtExceptionMonitor', ProcessListeners.handleUncaughtExceptionMonitor)
7
+ process.on(
8
+ 'uncaughtExceptionMonitor',
9
+ ProcessListeners.handleUncaughtExceptionMonitor,
10
+ )
8
11
  process.on('disconnect', ProcessListeners.handleDisconnect)
9
12
  CommandState.registerCommands(CommandMap.commandMap)
10
13
  await Listen.listen()
@@ -1,18 +1,18 @@
1
- import { spawn } from "node-pty";
2
- import { VError } from "../VError/VError.js";
3
- import * as Assert from "../Assert/Assert.js";
1
+ import { spawn } from 'node-pty'
2
+ import { VError } from '../VError/VError.js'
3
+ import * as Assert from '../Assert/Assert.js'
4
4
 
5
5
  class DataEvent extends Event {
6
6
  constructor(data) {
7
- super("data");
8
- this.data = data;
7
+ super('data')
8
+ this.data = data
9
9
  }
10
10
  }
11
11
 
12
12
  class ExitEvent extends Event {
13
13
  constructor(data) {
14
- super("exit");
15
- this.data = data;
14
+ super('exit')
15
+ this.data = data
16
16
  }
17
17
  }
18
18
 
@@ -22,47 +22,47 @@ class Pty extends EventTarget {
22
22
  * @param {import('node-pty').IPty} pty
23
23
  */
24
24
  constructor(pty) {
25
- super();
26
- this.pty = pty;
25
+ super()
26
+ this.pty = pty
27
27
 
28
28
  const handleData = (data) => {
29
- this.dispatchEvent(new DataEvent(data));
30
- };
29
+ this.dispatchEvent(new DataEvent(data))
30
+ }
31
31
  const handleExit = (data) => {
32
- this.dispatchEvent(new ExitEvent(data));
33
- };
34
- this.pty.onData(handleData);
35
- this.pty.onExit(handleExit);
32
+ this.dispatchEvent(new ExitEvent(data))
33
+ }
34
+ this.pty.onData(handleData)
35
+ this.pty.onExit(handleExit)
36
36
  }
37
37
 
38
38
  resize(columns, rows) {
39
- this.pty.resize(columns, rows);
39
+ this.pty.resize(columns, rows)
40
40
  }
41
41
 
42
42
  dispose() {
43
- this.pty.kill();
43
+ this.pty.kill()
44
44
  }
45
45
 
46
46
  write(data) {
47
- this.pty.write(data);
47
+ this.pty.write(data)
48
48
  }
49
49
  }
50
50
 
51
51
  // @ts-ignore
52
52
  export const create = ({ env = {}, cwd, command, args } = {}) => {
53
53
  try {
54
- Assert.string(cwd);
55
- Assert.string(command);
56
- Assert.array(args);
54
+ Assert.string(cwd)
55
+ Assert.string(command)
56
+ Assert.array(args)
57
57
  const pty = spawn(command, args, {
58
58
  encoding: null,
59
59
  cwd,
60
60
  // cols: 10,
61
61
  // rows: 10,
62
- });
63
- const wrapped = new Pty(pty);
64
- return wrapped;
62
+ })
63
+ const wrapped = new Pty(pty)
64
+ return wrapped
65
65
  } catch (error) {
66
- throw new VError(error, `Failed to create terminal`);
66
+ throw new VError(error, `Failed to create terminal`)
67
67
  }
68
- };
68
+ }
@@ -1,5 +1,7 @@
1
1
  import * as Logger from '../Logger/Logger.js'
2
2
 
3
3
  export const printPrettyError = (prettyError, prefix = '') => {
4
- Logger.error(`${prefix}${prettyError.type}: ${prettyError.message}\n\n${prettyError.codeFrame}\n\n${prettyError.stack}\n`)
4
+ Logger.error(
5
+ `${prefix}${prettyError.type}: ${prettyError.message}\n\n${prettyError.codeFrame}\n\n${prettyError.stack}\n`,
6
+ )
5
7
  }
@@ -1,56 +1,56 @@
1
- import * as Assert from "../Assert/Assert.js";
2
- import * as Debug from "../Debug/Debug.js";
3
- import * as Pty from "../Pty/Pty.js";
4
- import * as PtyState from "../PtyState/PtyState.js";
1
+ import * as Assert from '../Assert/Assert.js'
2
+ import * as Debug from '../Debug/Debug.js'
3
+ import * as Pty from '../Pty/Pty.js'
4
+ import * as PtyState from '../PtyState/PtyState.js'
5
5
 
6
6
  // TODO maybe merge pty and pty controller
7
7
  export const create = (ipc, id, cwd, command, args) => {
8
- Assert.number(id);
9
- Assert.string(cwd);
10
- Assert.string(command);
11
- Assert.array(args);
12
- Assert.object(ipc);
13
- Debug.debug(`create ${id} ${cwd}`);
14
- const pty = Pty.create({ cwd, command, args });
8
+ Assert.number(id)
9
+ Assert.string(cwd)
10
+ Assert.string(command)
11
+ Assert.array(args)
12
+ Assert.object(ipc)
13
+ Debug.debug(`create ${id} ${cwd}`)
14
+ const pty = Pty.create({ cwd, command, args })
15
15
  const handleData = (event) => {
16
16
  ipc.send({
17
- jsonrpc: "2.0",
18
- method: "Viewlet.send",
19
- params: [id, "handleData", event.data],
20
- });
21
- };
17
+ jsonrpc: '2.0',
18
+ method: 'Viewlet.send',
19
+ params: [id, 'handleData', event.data],
20
+ })
21
+ }
22
22
 
23
- pty.addEventListener("data", handleData);
24
- PtyState.set(id, pty);
25
- };
23
+ pty.addEventListener('data', handleData)
24
+ PtyState.set(id, pty)
25
+ }
26
26
 
27
27
  export const write = (id, data) => {
28
- const pty = PtyState.get(id);
28
+ const pty = PtyState.get(id)
29
29
  if (!pty) {
30
- throw new Error(`pty ${id} not found`);
30
+ throw new Error(`pty ${id} not found`)
31
31
  }
32
- pty.write(data);
33
- };
32
+ pty.write(data)
33
+ }
34
34
 
35
35
  export const resize = (id, columns, rows) => {
36
- const pty = PtyState.get(id);
36
+ const pty = PtyState.get(id)
37
37
  if (!pty) {
38
- throw new Error(`pty ${id} not found`);
38
+ throw new Error(`pty ${id} not found`)
39
39
  }
40
- pty.resize(columns, rows);
41
- };
40
+ pty.resize(columns, rows)
41
+ }
42
42
 
43
43
  export const dispose = (id) => {
44
- const pty = PtyState.get(id);
44
+ const pty = PtyState.get(id)
45
45
  if (!pty) {
46
- throw new Error(`pty ${id} not found`);
46
+ throw new Error(`pty ${id} not found`)
47
47
  }
48
- pty.dispose();
49
- PtyState.remove(id);
50
- };
48
+ pty.dispose()
49
+ PtyState.remove(id)
50
+ }
51
51
 
52
52
  export const disposeAll = () => {
53
53
  for (const id in PtyState.getAll()) {
54
- dispose(id);
54
+ dispose(id)
55
55
  }
56
- };
56
+ }
@@ -1,5 +1,7 @@
1
- export const HandleElectronMessagePort = 'HandleElectronMessagePort.handleElectronMessagePort'
2
- export const HandleNodeMessagePort = 'HandleNodeMessagePort.handleNodeMessagePort'
1
+ export const HandleElectronMessagePort =
2
+ 'HandleElectronMessagePort.handleElectronMessagePort'
3
+ export const HandleNodeMessagePort =
4
+ 'HandleNodeMessagePort.handleNodeMessagePort'
3
5
  export const HandleWebSocket = 'HandleWebSocket.handleWebSocket'
4
6
  export const TerminalCreate = 'Terminal.create'
5
7
  export const TerminalResize = 'Terminal.resize'