@lvce-editor/extension-host-helper-process 0.53.5 → 0.53.7

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.5",
3
+ "version": "0.53.7",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -17,9 +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",
22
- "@lvce-editor/rpc": "^4.1.0",
20
+ "@lvce-editor/rpc": "^4.2.0",
23
21
  "@lvce-editor/verror": "^1.7.0",
24
22
  "execa": "^9.5.3",
25
23
  "got": "^14.4.7",
@@ -0,0 +1 @@
1
+ export const commandMapRef = {}
@@ -1,10 +1,12 @@
1
1
  import * as CommandMap from '../CommandMap/CommandMap.js'
2
2
  import * as IpcChild from '../IpcChild/IpcChild.js'
3
3
  import * as IpcChildType from '../IpcChildType/IpcChildType.js'
4
+ import * as CommandMapRef from '../CommandMapRef/CommandMapRef.js'
4
5
 
5
6
  export const listen = async (argv) => {
7
+ Object.assign(CommandMapRef.commandMapRef, CommandMap.commandMap)
6
8
  await IpcChild.listen({
7
9
  method: IpcChildType.Auto(argv),
8
- commandMap: CommandMap.commandMap,
10
+ commandMap: CommandMapRef.commandMapRef,
9
11
  })
10
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,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
- }