@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 +5 -1
- package/src/parts/Ajax/Ajax.ipc.js +7 -0
- package/src/parts/Ajax/Ajax.js +6 -0
- package/src/parts/GetResponse/GetResponse.js +10 -1
- package/src/parts/Module/Module.js +2 -0
- package/src/parts/ModuleId/ModuleId.js +1 -0
- package/src/parts/ModuleMap/ModuleMap.js +12 -2
- package/src/parts/PrettyError/PrettyError.js +53 -0
- package/src/parts/SplitLines/SplitLines.js +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/extension-host-helper-process",
|
|
3
|
-
"version": "0.11.
|
|
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
|
}
|
|
@@ -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
|
}
|
|
@@ -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
|
-
|
|
5
|
-
|
|
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
|
+
}
|