@lvce-editor/extension-host-helper-process 0.53.4 → 0.53.6

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/extension-host-helper-process",
3
- "version": "0.53.4",
3
+ "version": "0.53.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -17,8 +17,7 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@lvce-editor/assert": "^1.3.0",
20
- "@lvce-editor/ipc": "^14.2.0",
21
- "@lvce-editor/json-rpc": "^6.2.0",
20
+ "@lvce-editor/rpc": "^4.2.0",
22
21
  "@lvce-editor/verror": "^1.7.0",
23
22
  "execa": "^9.5.3",
24
23
  "got": "^14.4.7",
@@ -0,0 +1 @@
1
+ export const commandMapRef = {}
@@ -0,0 +1,3 @@
1
+ export const exit = () => {
2
+ process.exit(0)
3
+ }
@@ -1,22 +1,15 @@
1
1
  import * as Assert from '../Assert/Assert.js'
2
- import * as HandleIpc from '../HandleIpc/HandleIpc.js'
3
2
  import * as IpcChild from '../IpcChild/IpcChild.js'
3
+ import * as HandleIpcClosed from '../HandleIpcClosed/HandleIpcClosed.js'
4
4
  import * as IpcChildType from '../IpcChildType/IpcChildType.js'
5
- import * as IpcId from '../IpcId/IpcId.js'
6
5
 
7
- const handleClose = () => {
8
- process.exit(0)
9
- }
10
-
11
- export const handleElectronMessagePort = async (messagePort, ipcId) => {
6
+ export const handleElectronMessagePort = async (messagePort) => {
7
+ // TODO make it so when messageport closes, the process exits
12
8
  Assert.object(messagePort)
13
- const ipc = await IpcChild.listen({
9
+ const rpc = await IpcChild.listen({
14
10
  method: IpcChildType.ElectronMessagePort,
15
11
  messagePort,
16
12
  })
17
- HandleIpc.handleIpc(ipc)
18
- if (ipcId === IpcId.ExtensionHostWorker) {
19
- // @ts-ignore
20
- ipc.addEventListener('close', handleClose)
21
- }
13
+ // @ts-ignore
14
+ rpc.ipc.addEventListener('close', HandleIpcClosed.handleIpcClosed)
22
15
  }
@@ -0,0 +1,5 @@
1
+ import * as Exit from '../Exit/Exit.js'
2
+
3
+ export const handleIpcClosed = () => {
4
+ Exit.exit()
5
+ }
@@ -1,15 +1,16 @@
1
1
  import * as Assert from '../Assert/Assert.js'
2
- import * as HandleIpc from '../HandleIpc/HandleIpc.js'
3
2
  import * as IpcChild from '../IpcChild/IpcChild.js'
4
3
  import * as IpcChildType from '../IpcChildType/IpcChildType.js'
4
+ import * as HandleIpcClosed from '../HandleIpcClosed/HandleIpcClosed.js'
5
5
 
6
6
  export const handleWebSocket = async (handle, request) => {
7
+ // TODO make it so when websocket closes, the process exits
7
8
  Assert.object(handle)
8
9
  Assert.object(request)
9
- const ipc = await IpcChild.listen({
10
+ handle.on('close', HandleIpcClosed.handleIpcClosed)
11
+ await IpcChild.listen({
10
12
  method: IpcChildType.WebSocket,
11
13
  request,
12
14
  handle,
13
15
  })
14
- HandleIpc.handleIpc(ipc)
15
16
  }
@@ -1,13 +1,8 @@
1
1
  import * as IpcChildModule from '../IpcChildModule/IpcChildModule.js'
2
2
 
3
3
  export const listen = async ({ method, ...params }) => {
4
- const module = await IpcChildModule.getModule(method)
5
- const rawIpc = await module.listen(params)
4
+ const create = IpcChildModule.getModule(method)
6
5
  // @ts-ignore
7
- if (module.signal) {
8
- // @ts-ignore
9
- module.signal(rawIpc)
10
- }
11
- const ipc = module.wrap(rawIpc)
12
- return ipc
6
+ const rpc = await create(params)
7
+ return rpc
13
8
  }
@@ -1,21 +1,24 @@
1
1
  import {
2
- IpcChildWithElectronMessagePort,
3
- IpcChildWithElectronUtilityProcess,
4
- IpcChildWithNodeForkedProcess,
5
- IpcChildWithWebSocket,
6
- } from '@lvce-editor/ipc'
2
+ ElectronMessagePortRpcClient,
3
+ ElectronUtilityProcessRpcClient,
4
+ NodeForkedProcessRpcClient,
5
+ NodeWebSocketRpcClient,
6
+ NodeWorkerRpcClient,
7
+ } from '@lvce-editor/rpc'
7
8
  import * as IpcChildType from '../IpcChildType/IpcChildType.js'
8
9
 
9
10
  export const getModule = (method) => {
10
11
  switch (method) {
11
- case IpcChildType.WebSocket:
12
- return IpcChildWithWebSocket
13
12
  case IpcChildType.NodeForkedProcess:
14
- return IpcChildWithNodeForkedProcess
15
- case IpcChildType.ElectronMessagePort:
16
- return IpcChildWithElectronMessagePort
13
+ return NodeForkedProcessRpcClient.create
14
+ case IpcChildType.NodeWorker:
15
+ return NodeWorkerRpcClient.create
17
16
  case IpcChildType.ElectronUtilityProcess:
18
- return IpcChildWithElectronUtilityProcess
17
+ return ElectronUtilityProcessRpcClient.create
18
+ case IpcChildType.ElectronMessagePort:
19
+ return ElectronMessagePortRpcClient.create
20
+ case IpcChildType.WebSocket:
21
+ return NodeWebSocketRpcClient.create
19
22
  default:
20
23
  throw new Error('unexpected ipc type')
21
24
  }
@@ -1,38 +1,18 @@
1
- import * as ParseCliArgs from '../ParseCliArgs/ParseCliArgs.js'
2
-
3
- export const WebSocket = 1
4
- export const MessagePort = 2
5
- export const Parent = 3
1
+ export const NodeWorker = 1
2
+ export const NodeForkedProcess = 2
3
+ export const ElectronUtilityProcess = 3
6
4
  export const ElectronMessagePort = 4
7
- export const ElectronUtilityProcess = 5
8
- export const ElectronUtilityProcessMessagePort = 6
9
- export const NodeForkedProcess = 7
10
-
11
- const getRawIpcType = () => {
12
- const { argv } = process
13
- const parsedArgs = ParseCliArgs.parseCliArgs(argv.slice(2))
14
- const ipcType = parsedArgs['ipc-type']
15
- return ipcType
16
- }
5
+ export const WebSocket = 6
17
6
 
18
- export const Auto = () => {
19
- const ipcType = getRawIpcType()
20
- switch (ipcType) {
21
- case 'websocket':
22
- return WebSocket
23
- case 'message-port':
24
- return MessagePort
25
- case 'parent':
26
- return Parent
27
- case 'electron-message-port':
28
- return ElectronMessagePort
29
- case 'electron-utility-process':
30
- return ElectronUtilityProcess
31
- case 'electron-utility-process-message-port':
32
- return ElectronUtilityProcessMessagePort
33
- case 'node-forked-process':
34
- return NodeForkedProcess
35
- default:
36
- throw new Error(`[extension-host-helper-process] unknown ipc type ${ipcType}`)
7
+ export const Auto = (argv) => {
8
+ if (argv.includes('--ipc-type=node-worker')) {
9
+ return NodeWorker
10
+ }
11
+ if (argv.includes('--ipc-type=node-forked-process')) {
12
+ return NodeForkedProcess
13
+ }
14
+ if (argv.includes('--ipc-type=electron-utility-process')) {
15
+ return ElectronUtilityProcess
37
16
  }
17
+ throw new Error(`[file-system-process] unknown ipc type`)
38
18
  }
@@ -0,0 +1,12 @@
1
+ import * as CommandMap from '../CommandMap/CommandMap.js'
2
+ import * as IpcChild from '../IpcChild/IpcChild.js'
3
+ import * as IpcChildType from '../IpcChildType/IpcChildType.js'
4
+ import * as CommandMapRef from '../CommandMapRef/CommandMapRef.js'
5
+
6
+ export const listen = async (argv) => {
7
+ Object.assign(CommandMapRef.commandMapRef, CommandMap.commandMap)
8
+ await IpcChild.listen({
9
+ method: IpcChildType.Auto(argv),
10
+ commandMap: CommandMapRef.commandMapRef,
11
+ })
12
+ }
@@ -1,7 +1,7 @@
1
- import { VError } from '../VError/VError.js'
2
- import * as CommandState from '../CommandState/CommandState.js'
3
- import * as ImportScript from '../ImportScript/ImportScript.js'
1
+ import * as Command from '@lvce-editor/command'
4
2
  import * as Assert from '../Assert/Assert.js'
3
+ import * as ImportScript from '../ImportScript/ImportScript.js'
4
+ import { VError } from '../VError/VError.js'
5
5
 
6
6
  export const loadFile = async (path) => {
7
7
  try {
@@ -9,9 +9,9 @@ export const loadFile = async (path) => {
9
9
  const module = await ImportScript.importScript(path)
10
10
  if (module && module.commandMap) {
11
11
  const commandMap = module.commandMap
12
- CommandState.registerCommands(commandMap)
12
+ Command.register(commandMap)
13
13
  } else if (module && module.execute) {
14
- CommandState.setExecute(module.execute)
14
+ throw new Error(`execute function is not supported anymore. Use commandMap instead`)
15
15
  } else {
16
16
  throw new Error(`missing export const execute function`)
17
17
  }
@@ -1,13 +1,7 @@
1
- import * as CommandMap from '../CommandMap/CommandMap.js'
2
- import * as CommandState from '../CommandState/CommandState.js'
3
- import * as HandleIpc from '../HandleIpc/HandleIpc.js'
4
- import * as IpcChild from '../IpcChild/IpcChild.js'
5
- import * as IpcChildType from '../IpcChildType/IpcChildType.js'
6
1
  import * as ProcessListeners from '../ProcessListeners/ProcessListeners.js'
2
+ import * as Listen from '../Listen/Listen.js'
7
3
 
8
4
  export const main = async () => {
9
5
  process.on('disconnect', ProcessListeners.handleDisconnect)
10
- CommandState.registerCommands(CommandMap.commandMap)
11
- const ipc = await IpcChild.listen({ method: IpcChildType.Auto() })
12
- HandleIpc.handleIpc(ipc)
6
+ await Listen.listen(process.argv)
13
7
  }
@@ -1,10 +0,0 @@
1
- import { CommandNotFoundError } from '../CommandNotFoundError/CommandNotFoundError.js'
2
- import * as CommandState from '../CommandState/CommandState.js'
3
-
4
- export const execute = (command, ...args) => {
5
- const fn = CommandState.getCommand(command)
6
- if (!fn) {
7
- throw new CommandNotFoundError(command)
8
- }
9
- return fn(...args)
10
- }
@@ -1,9 +0,0 @@
1
- import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
2
-
3
- export class CommandNotFoundError extends Error {
4
- constructor(id) {
5
- super(`command ${id} not found`)
6
- this.name = 'CommandNotFoundError'
7
- this.code = ErrorCodes.E_COMMAND_NOT_FOUND
8
- }
9
- }
@@ -1,43 +0,0 @@
1
- import * as Assert from '../Assert/Assert.js'
2
- import { VError } from '../VError/VError.js'
3
-
4
- export const state = {
5
- commands: Object.create(null),
6
- /**
7
- * @type {any}
8
- */
9
- execute: undefined,
10
- }
11
-
12
- export const registerCommand = (key, fn) => {
13
- try {
14
- Assert.string(key)
15
- Assert.fn(fn)
16
- state.commands[key] = fn
17
- } catch (error) {
18
- throw new VError(error, `Failed to register command ${key}`)
19
- }
20
- }
21
-
22
- export const registerCommands = (commandMap) => {
23
- for (const [key, value] of Object.entries(commandMap)) {
24
- registerCommand(key, value)
25
- }
26
- }
27
-
28
- export const getCommand = (key) => {
29
- const { commands, execute } = state
30
- if (key in commands) {
31
- return commands[key]
32
- }
33
- if (execute) {
34
- return (...args) => {
35
- return execute(key, ...args)
36
- }
37
- }
38
- return undefined
39
- }
40
-
41
- export const setExecute = (fn) => {
42
- state.execute = fn
43
- }
@@ -1 +0,0 @@
1
- export const Message = 1
@@ -1,21 +0,0 @@
1
- import * as FirstUtilityProcessEventType from '../FirstUtilityProcessEventType/FirstUtilityProcessEventType.js'
2
-
3
- export const getFirstUtilityProcessEvent = async (parentPort) => {
4
- const { type, event } = await new Promise((resolve) => {
5
- const cleanup = (value) => {
6
- parentPort.off('message', handleMessage)
7
- resolve(value)
8
- }
9
- const handleMessage = (event) => {
10
- cleanup({
11
- type: FirstUtilityProcessEventType.Message,
12
- event,
13
- })
14
- }
15
- parentPort.on('message', handleMessage)
16
- })
17
- return {
18
- type,
19
- event,
20
- }
21
- }
@@ -1,10 +0,0 @@
1
- export const getUtilityProcessPortData = (event) => {
2
- const { data, ports } = event
3
- if (ports.length === 0) {
4
- return data
5
- }
6
- return {
7
- ...data,
8
- params: [...ports, ...data.params],
9
- }
10
- }
@@ -1,10 +0,0 @@
1
- import * as HandleMessage from '../HandleMessage/HandleMessage.js'
2
-
3
- export const handleIpc = (ipc) => {
4
- if ('addEventListener' in ipc) {
5
- ipc.addEventListener('message', HandleMessage.handleMessage)
6
- } else {
7
- // deprecated
8
- ipc.on('message', HandleMessage.handleMessage)
9
- }
10
- }
@@ -1,19 +0,0 @@
1
- import * as Callback from '../Callback/Callback.js'
2
- import * as Command from '../Command/Command.js'
3
- import * as JsonRpc from '../JsonRpc/JsonRpc.js'
4
-
5
- const preparePrettyError = (error) => {
6
- return error
7
- }
8
-
9
- const logError = (error, prettyError) => {
10
- // this is handled by shared process
11
- }
12
-
13
- const requiresSocket = () => {
14
- return false
15
- }
16
-
17
- export const handleMessage = (event) => {
18
- return JsonRpc.handleJsonRpcMessage(event.target, event.data, Command.execute, Callback.resolve, preparePrettyError, logError, requiresSocket)
19
- }
@@ -1,3 +0,0 @@
1
- export const isMessagePortMain = (value) => {
2
- return value && value.constructor && value.constructor.name === 'MessagePortMain'
3
- }
@@ -1 +0,0 @@
1
- export * from '@lvce-editor/json-rpc'
@@ -1,5 +0,0 @@
1
- import * as Logger from '../Logger/Logger.js'
2
-
3
- export const printPrettyError = (prettyError, prefix = '') => {
4
- Logger.error(`${prefix}${prettyError.type}: ${prettyError.message}\n\n${prettyError.codeFrame}\n\n${prettyError.stack}\n`)
5
- }