@lvce-editor/extension-host-helper-process 0.11.7 → 0.11.8

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.11.7",
3
+ "version": "0.11.8",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -16,7 +16,11 @@
16
16
  "node": ">=16"
17
17
  },
18
18
  "dependencies": {
19
+ "@babel/code-frame": "^7.18.6",
20
+ "clean-stack": "^5.0.1",
19
21
  "execa": "^6.1.0",
22
+ "got": "^12.5.3",
23
+ "lines-and-columns": "^2.0.3",
20
24
  "ws": "^8.11.0"
21
25
  }
22
26
  }
@@ -0,0 +1,7 @@
1
+ import * as Ajax from './Ajax.js'
2
+
3
+ export const name = 'Ajax'
4
+
5
+ export const Commands = {
6
+ getJson: Ajax.getJson,
7
+ }
@@ -0,0 +1,6 @@
1
+ import got from 'got'
2
+
3
+ export const getJson = async (url) => {
4
+ const json = await got(url).json()
5
+ return json
6
+ }
@@ -1,5 +1,6 @@
1
1
  import * as Command from '../Command/Command.js'
2
2
  import * as JsonRpc from '../JsonRpc/JsonRpc.js'
3
+ import * as PrettyError from '../PrettyError/PrettyError.js'
3
4
 
4
5
  export const getResponse = async (message) => {
5
6
  try {
@@ -26,10 +27,18 @@ export const getResponse = async (message) => {
26
27
  },
27
28
  }
28
29
  }
30
+ const prettyError = PrettyError.prepare(error)
29
31
  return {
30
32
  jsonrpc: JsonRpc.Version,
31
33
  id: message.id,
32
- error,
34
+ error: {
35
+ code: -32001,
36
+ message: prettyError.message,
37
+ data: {
38
+ stack: prettyError.stack,
39
+ codeFrame: prettyError.codeFrame,
40
+ },
41
+ },
33
42
  }
34
43
  }
35
44
  }
@@ -4,6 +4,8 @@ export const load = (moduleId) => {
4
4
  switch (moduleId) {
5
5
  case ModuleId.Exec:
6
6
  return import('../Exec/Exec.ipc.js')
7
+ case ModuleId.Ajax:
8
+ return import('../Ajax/Ajax.ipc.js')
7
9
  default:
8
10
  throw new Error(`module ${moduleId} not found`)
9
11
  }
@@ -1 +1,2 @@
1
1
  export const Exec = 1
2
+ export const Ajax = 2
@@ -1,9 +1,19 @@
1
1
  import * as ModuleId from '../ModuleId/ModuleId.js'
2
2
 
3
+ const getPrefix = (commandId) => {
4
+ if (!commandId || typeof commandId !== 'string') {
5
+ return commandId
6
+ }
7
+ return commandId.slice(0, commandId.indexOf('.'))
8
+ }
9
+
3
10
  export const getModuleId = (commandId) => {
4
- switch (commandId) {
5
- case 'Exec.exec':
11
+ const prefix = getPrefix(commandId)
12
+ switch (prefix) {
13
+ case 'Exec':
6
14
  return ModuleId.Exec
15
+ case 'Ajax':
16
+ return ModuleId.Ajax
7
17
  default:
8
18
  throw new Error(`command ${commandId} not found`)
9
19
  }
@@ -0,0 +1,53 @@
1
+ import { codeFrameColumns } from '@babel/code-frame'
2
+ import cleanStack from 'clean-stack'
3
+ import { readFileSync } from 'node:fs'
4
+ import { fileURLToPath } from 'node:url'
5
+ import * as SplitLines from '../SplitLines/SplitLines.js'
6
+
7
+ const getActualPath = (fileUri) => {
8
+ if (fileUri.startsWith('file://')) {
9
+ return fileURLToPath(fileUri)
10
+ }
11
+ return fileUri
12
+ }
13
+
14
+ export const prepare = (error) => {
15
+ const message = error.message
16
+ if (error && error.cause) {
17
+ const cause = error.cause()
18
+ if (cause) {
19
+ error = cause
20
+ }
21
+ }
22
+ const cleanedStack = cleanStack(error.stack)
23
+ const lines = SplitLines.splitLines(cleanedStack)
24
+ const file = lines[1]
25
+ let codeFrame = ''
26
+ if (error.codeFrame) {
27
+ codeFrame = error.codeFrame
28
+ } else if (file) {
29
+ let match = file.match(/\((.*):(\d+):(\d+)\)$/)
30
+ if (!match) {
31
+ match = file.match(/at (.*):(\d+):(\d+)$/)
32
+ }
33
+ if (match) {
34
+ const [_, path, line, column] = match
35
+ const actualPath = getActualPath(path)
36
+ const rawLines = readFileSync(actualPath, 'utf-8')
37
+ const location = {
38
+ start: {
39
+ line: Number.parseInt(line),
40
+ column: Number.parseInt(column),
41
+ },
42
+ }
43
+
44
+ codeFrame = codeFrameColumns(rawLines, location)
45
+ }
46
+ }
47
+ const relevantStack = lines.slice(1).join('\n')
48
+ return {
49
+ message,
50
+ stack: relevantStack,
51
+ codeFrame,
52
+ }
53
+ }
@@ -0,0 +1,3 @@
1
+ export const splitLines = (lines) => {
2
+ return lines.split('\n')
3
+ }