@lvce-editor/shared-process 0.17.1 → 0.17.3

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/shared-process",
3
- "version": "0.17.1",
3
+ "version": "0.17.3",
4
4
  "description": "Utility package for @lvce-editor/server",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -16,10 +16,11 @@
16
16
  "node": ">=16"
17
17
  },
18
18
  "dependencies": {
19
- "@babel/code-frame": "^7.22.5",
20
- "@lvce-editor/extension-host": "0.17.1",
21
- "@lvce-editor/extension-host-helper-process": "0.17.1",
22
- "@lvce-editor/pty-host": "0.17.1",
19
+ "@babel/code-frame": "^7.22.10",
20
+ "@lvce-editor/extension-host": "0.17.3",
21
+ "@lvce-editor/extension-host-helper-process": "0.17.3",
22
+ "@lvce-editor/pretty-error": "^0.1.1",
23
+ "@lvce-editor/pty-host": "0.17.3",
23
24
  "debug": "^4.3.4",
24
25
  "execa": "^7.2.0",
25
26
  "exit-hook": "^3.2.0",
@@ -34,11 +35,11 @@
34
35
  },
35
36
  "optionalDependencies": {
36
37
  "extract-zip": "^2.0.1",
37
- "vscode-ripgrep-with-github-api-error-fix": "^2.8.0",
38
38
  "open": "^9.1.0",
39
39
  "symlink-dir": "^5.1.1",
40
+ "tail": "^2.2.6",
40
41
  "tmp-promise": "^3.0.3",
41
42
  "trash": "^8.1.1",
42
- "tail": "^2.2.6"
43
+ "vscode-ripgrep-with-github-api-error-fix": "^2.9.0"
43
44
  }
44
45
  }
@@ -8,8 +8,11 @@ import * as GetNsisDownloadPath from '../GetNsisUpdateDownloadPath/GetNsisUpdate
8
8
  import * as GetWindowsNsisDownloadUrl from '../GetWindowsNsisDownloadUrl/GetWindowsNsisDownloadUrl.js'
9
9
  import * as Logger from '../Logger/Logger.js'
10
10
  import * as Platform from '../Platform/Platform.js'
11
+ import * as UpdateState from '../UpdateState/UpdateState.js'
12
+ import * as UpdateStateType from '../UpdateStateType/UpdateStateType.js'
11
13
  import { VError } from '../VError/VError.js'
12
14
 
15
+ // TODO make it possible to cancel downloading updates
13
16
  export const downloadUpdate = async (version) => {
14
17
  try {
15
18
  Assert.string(version)
@@ -19,7 +22,9 @@ export const downloadUpdate = async (version) => {
19
22
  const downLoadUrl = GetWindowsNsisDownloadUrl.getDownloadUrl(repository, version, fileName)
20
23
  const outFile = GetNsisDownloadPath.getNsisUpdateDownloadPath(version)
21
24
  Logger.info(`[shared-process] downloading nsis update: ${downLoadUrl} -> ${outFile}`)
25
+ UpdateState.set(UpdateStateType.Downloading)
22
26
  await Download.download(downLoadUrl, outFile)
27
+ UpdateState.set(UpdateStateType.Downloaded)
23
28
  Logger.info(`[shared-process] downloaded nsis update: ${outFile}`)
24
29
  return outFile
25
30
  } catch (error) {
@@ -32,6 +37,7 @@ export const installAndRestart = async (downloadPath) => {
32
37
  Assert.string(downloadPath)
33
38
  const args = GetNsisUpdateArgs.getNsisUpdateArgs()
34
39
  Logger.info(`[shared-process] spawning nsis update: ${downloadPath}`)
40
+ UpdateState.set(UpdateStateType.Updating)
35
41
  const child = spawn(downloadPath, args, {
36
42
  stdio: 'inherit',
37
43
  detached: true,
@@ -169,11 +169,11 @@ export const getSetupName = () => {
169
169
  return 'Lvce-Setup'
170
170
  }
171
171
 
172
- export const version = '0.17.1'
172
+ export const version = '0.17.3'
173
173
 
174
- export const commit = 'b3e9c7f'
174
+ export const commit = '8dd517b'
175
175
 
176
- export const date = '2023-08-05T20:50:47.000Z'
176
+ export const date = '2023-08-12T15:25:18.000Z'
177
177
 
178
178
  export const getVersion = () => {
179
179
  return version
@@ -1,107 +1,7 @@
1
1
  import { codeFrameColumns } from '@babel/code-frame'
2
2
  import { LinesAndColumns } from 'lines-and-columns'
3
- import { readFileSync } from 'node:fs'
4
- import * as CleanStack from '../CleanStack/CleanStack.js'
5
- import * as EncodingType from '../EncodingType/EncodingType.js'
6
- import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
7
- import * as GetActualPath from '../GetActualPath/GetActualPath.js'
8
- import * as JoinLines from '../JoinLines/JoinLines.js'
9
3
  import * as Json from '../Json/Json.js'
10
- import * as SplitLines from '../SplitLines/SplitLines.js'
11
- import * as Logger from '../Logger/Logger.js'
12
-
13
- const RE_MODULE_NOT_FOUND_STACK = /Cannot find package '([^']+)' imported from (.+)$/
14
-
15
- const prepareModuleNotFoundError = (error) => {
16
- const { message } = error
17
- const match = message.match(RE_MODULE_NOT_FOUND_STACK)
18
- if (!match) {
19
- return {
20
- message,
21
- stack: error.stack,
22
- codeFrame: '',
23
- }
24
- }
25
- const notFoundModule = match[1]
26
- const importedFrom = match[2]
27
- const rawLines = readFileSync(importedFrom, EncodingType.Utf8)
28
- let line = 0
29
- let column = 0
30
- const splittedLines = SplitLines.splitLines(rawLines)
31
- for (let i = 0; i < splittedLines.length; i++) {
32
- const splittedLine = splittedLines[i]
33
- const index = splittedLine.indexOf(notFoundModule)
34
- if (index !== -1) {
35
- line = i + 1
36
- column = index
37
- break
38
- }
39
- }
40
- const location = {
41
- start: {
42
- line,
43
- column,
44
- },
45
- }
46
- const codeFrame = codeFrameColumns(rawLines, location)
47
- const stackLines = SplitLines.splitLines(error.stack)
48
- const newStackLines = [stackLines[0], ` at ${importedFrom}:${line}:${column}`, ...stackLines.slice(1)]
49
- const newStack = JoinLines.joinLines(newStackLines)
50
- return {
51
- message,
52
- stack: newStack,
53
- codeFrame,
54
- }
55
- }
56
-
57
- export const prepare = (error) => {
58
- try {
59
- if (error && error.code === ErrorCodes.ERR_MODULE_NOT_FOUND) {
60
- return prepareModuleNotFoundError(error)
61
- }
62
- const { message } = error
63
- if (error && error.cause) {
64
- const cause = error.cause()
65
- if (cause) {
66
- error = cause
67
- }
68
- }
69
- const lines = CleanStack.cleanStack(error.stack)
70
- const file = lines[0]
71
- let codeFrame = ''
72
- if (error.codeFrame) {
73
- codeFrame = error.codeFrame
74
- } else if (file) {
75
- let match = file.match(/\((.*):(\d+):(\d+)\)$/)
76
- if (!match) {
77
- match = file.match(/at (.*):(\d+):(\d+)$/)
78
- }
79
- if (match) {
80
- const [_, path, line, column] = match
81
- const actualPath = GetActualPath.getActualPath(path)
82
- const rawLines = readFileSync(actualPath, EncodingType.Utf8)
83
- const location = {
84
- start: {
85
- line: Number.parseInt(line),
86
- column: Number.parseInt(column),
87
- },
88
- }
89
- codeFrame = codeFrameColumns(rawLines, location)
90
- }
91
- }
92
- const relevantStack = JoinLines.joinLines(lines)
93
- return {
94
- message,
95
- stack: relevantStack,
96
- codeFrame,
97
- type: error.constructor.name,
98
- code: error.code,
99
- }
100
- } catch (otherError) {
101
- Logger.warn(`ErrorHandling Error: ${otherError}`)
102
- return error
103
- }
104
- }
4
+ export { prepare } from '@lvce-editor/pretty-error'
105
5
 
106
6
  const fixBackslashes = (string) => {
107
7
  return string.replaceAll('\\\\', '\\')
@@ -0,0 +1,13 @@
1
+ import * as UpdateStateType from '../UpdateStateType/UpdateStateType.js'
2
+
3
+ export const state = {
4
+ updateState: UpdateStateType.Uninitialized,
5
+ }
6
+
7
+ export const get = () => {
8
+ return state.updateState
9
+ }
10
+
11
+ export const set = (value) => {
12
+ state.updateState = value
13
+ }
@@ -0,0 +1,9 @@
1
+ export const Uninitialized = 1
2
+ export const Idle = 2
3
+ export const Disabled = 3
4
+ export const CheckingForUpdates = 3
5
+ export const AvailableForDownload = 4
6
+ export const Downloading = 5
7
+ export const Downloaded = 6
8
+ export const Updating = 7
9
+ export const Ready = 8
@@ -1,97 +0,0 @@
1
- import * as SplitLines from '../SplitLines/SplitLines.js'
2
-
3
- const RE_AT = /^\s+at/
4
- const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/
5
- const RE_OBJECT_AS = /^\s*at (async )?Object\.\w+ \[as ([\w\.]+)\]/
6
- const RE_GET_RESPONSE = /^\s*at async getResponse/
7
- const RE_WEBSOCKET_HANDLE_MESSAGE = /^\s*at async WebSocket.handleMessage/
8
- const RE_EXECUTE_COMMAND_ASYNC = /^\s*at executeCommandAsync/
9
- const RE_HANDLE_OTHER_MESSAGES_FROM_MESSAGE_PORT = /^\s*at async MessagePort\.handleOtherMessagesFromMessagePort/
10
- const RE_ASSERT = /^\s*at .*\/Assert\.js/
11
-
12
- const isInternalLine = (line) => {
13
- return line.includes('node:') || RE_AT_PROMISE_INDEX.test(line) || line.includes('node_modules/ws')
14
- }
15
-
16
- const isRelevantLine = (line) => {
17
- return !isInternalLine(line)
18
- }
19
-
20
- const isApplicationUsefulLine = (line, index) => {
21
- if (index === 0) {
22
- if (RE_ASSERT.test(line)) {
23
- return false
24
- }
25
- return true
26
- }
27
- if (RE_GET_RESPONSE.test(line)) {
28
- return false
29
- }
30
- if (RE_WEBSOCKET_HANDLE_MESSAGE.test(line)) {
31
- return false
32
- }
33
- if (RE_EXECUTE_COMMAND_ASYNC.test(line)) {
34
- return false
35
- }
36
- if (RE_HANDLE_OTHER_MESSAGES_FROM_MESSAGE_PORT.test(line)) {
37
- return false
38
- }
39
- return true
40
- }
41
-
42
- const isNormalStackLine = (line) => {
43
- return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line)
44
- }
45
-
46
- const cleanLine = (line) => {
47
- if (line.startsWith(' at exports.')) {
48
- return ' at ' + line.slice(' at exports.'.length)
49
- }
50
- if (line.startsWith(' at async exports.')) {
51
- return ' at async ' + line.slice(' at async exports.'.length)
52
- }
53
- if (line.startsWith(' at async Module.')) {
54
- return ' at async ' + line.slice(' at async Module.'.length)
55
- }
56
- if (line.startsWith(' at Module.')) {
57
- return ' at ' + line.slice(' at Module.'.length)
58
- }
59
- const objectMatch = line.match(RE_OBJECT_AS)
60
- if (objectMatch) {
61
- const rest = line.slice(objectMatch[0].length)
62
- if (objectMatch[1]) {
63
- return ' at ' + objectMatch[1] + objectMatch[2] + rest
64
- }
65
- return ' at ' + objectMatch[2] + rest
66
- }
67
- return line
68
- }
69
-
70
- const getDetails = (lines) => {
71
- const index = lines.findIndex(isNormalStackLine)
72
- return {
73
- custom: lines.slice(0, index),
74
- actualStack: lines.slice(index).map(cleanLine),
75
- }
76
- }
77
-
78
- const RE_PATH_1 = /^\/(.*)(\d+)$/
79
-
80
- const mergeCustom = (custom, relevantStack) => {
81
- if (custom.length === 0) {
82
- return relevantStack
83
- }
84
- const firstLine = custom[0]
85
- if (RE_PATH_1.test(firstLine)) {
86
- return [` at ${firstLine}`, ...relevantStack]
87
- }
88
- return relevantStack
89
- }
90
-
91
- export const cleanStack = (stack) => {
92
- const lines = SplitLines.splitLines(stack)
93
- const { custom, actualStack } = getDetails(lines)
94
- const relevantStack = actualStack.filter(isRelevantLine).filter(isApplicationUsefulLine)
95
- const merged = mergeCustom(custom, relevantStack)
96
- return merged
97
- }