@lvce-editor/pty-host 0.17.4 → 0.17.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/pty-host",
3
- "version": "0.17.4",
3
+ "version": "0.17.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -16,10 +16,8 @@
16
16
  "node": ">=16"
17
17
  },
18
18
  "dependencies": {
19
- "@babel/code-frame": "^7.22.10",
20
- "@lvce-editor/pretty-error": "^1.0.0",
19
+ "@lvce-editor/pretty-error": "^1.1.0",
21
20
  "debug": "^4.3.4",
22
- "lines-and-columns": "^2.0.3",
23
21
  "verror": "^1.10.1",
24
22
  "ws": "^8.13.0"
25
23
  },
@@ -1,17 +0,0 @@
1
- // parsing error handling based on https://github.com/sindresorhus/parse-json/blob/main/index.js
2
-
3
- import { JsonParsingError } from '../JsonParsingError/JsonParsingError.js'
4
-
5
- export const parse = async (string, filePath) => {
6
- try {
7
- return JSON.parse(string)
8
- } catch (error) {
9
- const JsonError = await import('../JsonError/JsonError.js')
10
- const errorProps = JsonError.getErrorPropsFromError(error, string, filePath)
11
- throw new JsonParsingError(errorProps.message, errorProps.codeFrame, errorProps.stack)
12
- }
13
- }
14
-
15
- export const stringify = (value) => {
16
- return JSON.stringify(value, null, 2) + '\n'
17
- }
@@ -1,64 +0,0 @@
1
- import { codeFrameColumns } from '@babel/code-frame'
2
- import { LinesAndColumns } from 'lines-and-columns'
3
-
4
- // parsing error handling based on https://github.com/sindresorhus/parse-json/blob/main/index.js
5
-
6
- const emptyError = {
7
- message: '',
8
- stack: '',
9
- codeFrame: '',
10
- }
11
-
12
- export const getErrorPropsFromError = (error, string, filePath) => {
13
- const indexMatch = error.message.match(/in JSON at position (\d+)/)
14
- if (indexMatch && indexMatch.length > 0) {
15
- const lines = new LinesAndColumns(string)
16
- const index = Number(indexMatch[1])
17
- const location = lines.locationForIndex(index)
18
- if (location) {
19
- const line = location.line + 1
20
- const column = location.column + 1
21
- const codeFrame = codeFrameColumns(string, { start: { line, column } }, { highlightCode: false })
22
- return {
23
- codeFrame,
24
- message: 'Json Parsing Error',
25
- stack: ` at ${filePath}:${line}:${column}`,
26
- }
27
- }
28
- }
29
- if (string.length === 0) {
30
- return {
31
- codeFrame: ``,
32
- message: 'Json Parsing Error: Cannot parse empty string',
33
- stack: ` at ${filePath}`,
34
- }
35
- }
36
-
37
- if (error.message === 'Unexpected end of JSON input') {
38
- const lines = new LinesAndColumns(string)
39
- const index = string.length - 1
40
- const location = lines.locationForIndex(index)
41
- if (location) {
42
- const codeFrame = codeFrameColumns(string, { start: { line: location.line + 1, column: location.column + 1 } }, { highlightCode: false })
43
- return {
44
- codeFrame,
45
- message: 'Json Parsing Error',
46
- stack: ` at ${filePath}`,
47
- }
48
- }
49
- }
50
- return {
51
- codeFrame: ``,
52
- message: 'Json Parsing Error',
53
- stack: ` at ${filePath}`,
54
- }
55
- }
56
-
57
- export const getErrorProps = (string, filePath) => {
58
- try {
59
- JSON.parse(string)
60
- return emptyError
61
- } catch (error) {
62
- return getErrorPropsFromError(error, string, filePath)
63
- }
64
- }
@@ -1,17 +0,0 @@
1
- import * as JoinLines from '../JoinLines/JoinLines.js'
2
- import * as SplitLines from '../SplitLines/SplitLines.js'
3
-
4
- export class JsonParsingError extends Error {
5
- constructor(message, codeFrame, stack) {
6
- super(message)
7
- this.name = 'JsonParsingError'
8
- if (codeFrame) {
9
- this.codeFrame = codeFrame
10
- }
11
-
12
- if (stack) {
13
- const parentStack = JoinLines.joinLines(SplitLines.splitLines(this.stack).slice(1))
14
- this.stack = this.name + ': ' + this.message + '\n' + stack + '\n' + parentStack
15
- }
16
- }
17
- }