@lvce-editor/shared-process 0.18.10 → 0.18.12

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,15 +1,28 @@
1
1
  {
2
2
  "name": "@lvce-editor/shared-process",
3
- "version": "0.18.10",
3
+ "version": "0.18.12",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
+ "keywords": [
7
+ "Lvce Editor"
8
+ ],
9
+ "author": "Lvce Editor",
10
+ "license": "MIT",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/lvce-editor/lvce-editor.git",
14
+ "directory": "packages/shared-process"
15
+ },
16
+ "engines": {
17
+ "node": ">=16"
18
+ },
6
19
  "dependencies": {
7
20
  "@babel/code-frame": "^7.22.13",
8
- "@lvce-editor/extension-host": "0.18.10",
9
- "@lvce-editor/extension-host-helper-process": "0.18.10",
21
+ "@lvce-editor/extension-host": "0.18.12",
22
+ "@lvce-editor/extension-host-helper-process": "0.18.12",
10
23
  "@lvce-editor/jsonc-parser": "^1.1.0",
11
- "@lvce-editor/pretty-error": "^1.2.0",
12
- "@lvce-editor/pty-host": "0.18.10",
24
+ "@lvce-editor/pretty-error": "^1.2.1",
25
+ "@lvce-editor/pty-host": "0.18.12",
13
26
  "@lvce-editor/verror": "^1.1.1",
14
27
  "debug": "^4.3.4",
15
28
  "execa": "^8.0.1",
@@ -1,6 +1,7 @@
1
1
  import * as AutoUpdateType from '../AutoUpdateType/AutoUpdateType.js'
2
2
  import * as CompareVersion from '../CompareVersion/CompareVersion.js'
3
3
  import * as GetLatestReleaseVersion from '../GetLatestReleaseVersion/GetLatestReleaseVersion.js'
4
+ import * as IsAppImage from '../IsAppImage/IsAppImage.js'
4
5
  import * as Platform from '../Platform/Platform.js'
5
6
  import { VError } from '../VError/VError.js'
6
7
 
@@ -12,7 +13,7 @@ export const getAutoUpdateType = async () => {
12
13
  if (Platform.isWindows) {
13
14
  return AutoUpdateType.WindowsNsis
14
15
  }
15
- if (Platform.isAppImage()) {
16
+ if (IsAppImage.isAppImage()) {
16
17
  return AutoUpdateType.AppImage
17
18
  }
18
19
  return AutoUpdateType.None
@@ -1,12 +1,21 @@
1
1
  import * as GetHelpfulChildProcessError from '../GetHelpfulChildProcessError/GetHelpfulChildProcessError.js'
2
+ import * as JoinLines from '../JoinLines/JoinLines.js'
3
+ import * as SplitLines from '../SplitLines/SplitLines.js'
2
4
 
3
5
  export class ChildProcessError extends Error {
4
6
  constructor(stderr) {
5
- const { message, code } = GetHelpfulChildProcessError.getHelpfulChildProcessError('', stderr)
6
- super(message)
7
+ const { message, code, stack } = GetHelpfulChildProcessError.getHelpfulChildProcessError('', stderr)
8
+ super(message || 'child process error')
7
9
  this.name = 'ChildProcessError'
8
10
  if (code) {
9
11
  this.code = code
10
12
  }
13
+ if (stack) {
14
+ const lines = SplitLines.splitLines(this.stack)
15
+ const [firstLine, ...stackLines] = lines
16
+ const newStackLines = [firstLine, ...stack, ...stackLines]
17
+ const newStack = JoinLines.joinLines(newStackLines)
18
+ this.stack = newStack
19
+ }
11
20
  }
12
21
  }
@@ -3,6 +3,6 @@ import * as Crash from './Crash.js'
3
3
  export const name = 'Crash'
4
4
 
5
5
  export const Commands = {
6
- crashSharedProcess: Crash.crashSharedProcess,
7
6
  crashMainProcess: Crash.crashMainProcess,
7
+ crashSharedProcess: Crash.crashSharedProcess,
8
8
  }
@@ -3,6 +3,6 @@ import * as ElectronApplicationMenu from './ElectronApplicationMenu.js'
3
3
  export const name = 'ElectronApplicationMenu'
4
4
 
5
5
  export const Commands = {
6
- setItems: ElectronApplicationMenu.setItems,
7
6
  handleClick: ElectronApplicationMenu.handleClick,
7
+ setItems: ElectronApplicationMenu.setItems,
8
8
  }
@@ -0,0 +1,7 @@
1
+ import * as ElectronWindowProcessExplorer from './ElectronWindowProcessExplorer.js'
2
+
3
+ export const name = 'ElectronWindowProcessExplorer'
4
+
5
+ export const Commands = {
6
+ open: ElectronWindowProcessExplorer.open,
7
+ }
@@ -0,0 +1,5 @@
1
+ import * as ParentIpc from '../ParentIpc/ParentIpc.js'
2
+
3
+ export const open = () => {
4
+ return ParentIpc.invoke('ElectronWindowProcessExplorer.open')
5
+ }
@@ -17,3 +17,5 @@ export const getNodeEnv = () => {
17
17
  export const getRipGrepPath = () => {
18
18
  return process.env.RIP_GREP_PATH
19
19
  }
20
+
21
+ export const env = process.env
@@ -1,5 +1,6 @@
1
- import * as SplitLines from '../SplitLines/SplitLines.js'
2
1
  import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
2
+ import * as SplitLines from '../SplitLines/SplitLines.js'
3
+ import * as JoinLines from '../JoinLines/JoinLines.js'
3
4
 
4
5
  const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/
5
6
  const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/
@@ -7,6 +8,9 @@ const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js versi
7
8
  const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/
8
9
  const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/
9
10
 
11
+ const RE_AT = /^\s+at/
12
+ const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/
13
+
10
14
  const isUnhelpfulNativeModuleError = (stderr) => {
11
15
  return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr)
12
16
  }
@@ -62,7 +66,7 @@ const isModuleNotFoundMessage = (line) => {
62
66
  }
63
67
 
64
68
  const getModuleNotFoundError = (stderr) => {
65
- const lines = stderr.split('\n')
69
+ const lines = SplitLines.splitLines(stderr)
66
70
  const messageIndex = lines.findIndex(isModuleNotFoundMessage)
67
71
  const message = lines[messageIndex]
68
72
  return {
@@ -71,6 +75,30 @@ const getModuleNotFoundError = (stderr) => {
71
75
  }
72
76
  }
73
77
 
78
+ const isNormalStackLine = (line) => {
79
+ return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line)
80
+ }
81
+
82
+ const getDetails = (lines) => {
83
+ const index = lines.findIndex(isNormalStackLine)
84
+ if (index === -1) {
85
+ return {
86
+ actualMessage: JoinLines.joinLines(lines),
87
+ rest: [],
88
+ }
89
+ }
90
+ let lastIndex = index - 1
91
+ while (++lastIndex < lines.length) {
92
+ if (!isNormalStackLine(lines[lastIndex])) {
93
+ break
94
+ }
95
+ }
96
+ return {
97
+ actualMessage: lines[index - 1],
98
+ rest: lines.slice(index, lastIndex),
99
+ }
100
+ }
101
+
74
102
  export const getHelpfulChildProcessError = (stdout, stderr) => {
75
103
  if (isUnhelpfulNativeModuleError(stderr)) {
76
104
  return getNativeModuleErrorMessage(stderr)
@@ -81,8 +109,11 @@ export const getHelpfulChildProcessError = (stdout, stderr) => {
81
109
  if (isModuleNotFoundError(stderr)) {
82
110
  return getModuleNotFoundError(stderr)
83
111
  }
112
+ const lines = SplitLines.splitLines(stderr)
113
+ const { actualMessage, rest } = getDetails(lines)
84
114
  return {
85
- message: `child process error: ${stderr}`,
115
+ message: `${actualMessage}`,
86
116
  code: '',
117
+ stack: rest,
87
118
  }
88
119
  }
@@ -0,0 +1,5 @@
1
+ import * as Env from '../Env/Env.js'
2
+
3
+ export const isAppImage = () => {
4
+ return Boolean(Env.env.APPIMAGE)
5
+ }
@@ -0,0 +1,15 @@
1
+ import { setPriority } from 'node:os'
2
+ import * as Command from '../Command/Command.js'
3
+ import * as Module from '../Module/Module.js'
4
+ import * as ParentIpc from '../ParentIpc/ParentIpc.js'
5
+ import * as ProcessListeners from '../ProcessListeners/ProcessListeners.js'
6
+ import * as Signal from '../Signal/Signal.js'
7
+
8
+ export const main = async () => {
9
+ Command.setLoad(Module.load)
10
+ process.on('disconnect', ProcessListeners.handleDisconnect)
11
+ process.on(Signal.SIGTERM, ProcessListeners.handleSigTerm)
12
+ process.on('uncaughtExceptionMonitor', ProcessListeners.handleUncaughtExceptionMonitor)
13
+ await ParentIpc.listen()
14
+ setPriority(process.pid, 19)
15
+ }
@@ -0,0 +1,20 @@
1
+ import * as GetNewLineIndex from '../GetNewLineIndex/GetNewLineIndex.js'
2
+ import * as NormalizeErrorLine from '../NormalizeErrorLine/NormalizeErrorLine.js'
3
+
4
+ export const mergeStacks = (parent, child) => {
5
+ if (!child) {
6
+ return parent
7
+ }
8
+ const parentNewLineIndex = GetNewLineIndex.getNewLineIndex(parent)
9
+ const childNewLineIndex = GetNewLineIndex.getNewLineIndex(child)
10
+ if (childNewLineIndex === -1) {
11
+ return parent
12
+ }
13
+ const parentFirstLine = parent.slice(0, parentNewLineIndex)
14
+ const childRest = child.slice(childNewLineIndex)
15
+ const childFirstLine = NormalizeErrorLine.normalizeLine(child.slice(0, childNewLineIndex))
16
+ if (parentFirstLine.includes(childFirstLine)) {
17
+ return parentFirstLine + childRest
18
+ }
19
+ return child
20
+ }
@@ -46,6 +46,8 @@ export const load = (moduleId) => {
46
46
  return import('../ElectronWindow/ElectronWindow.ipc.js')
47
47
  case ModuleId.ElectronWindowAbout:
48
48
  return import('../ElectronWindowAbout/ElectronWindowAbout.ipc.js')
49
+ case ModuleId.ElectronWindowProcessExplorer:
50
+ return import('../ElectronWindowProcessExplorer/ElectronWindowProcessExplorer.ipc.js')
49
51
  case ModuleId.Exit:
50
52
  return import('../Exit/Exit.ipc.js')
51
53
  case ModuleId.ExtensionHost:
@@ -78,6 +80,8 @@ export const load = (moduleId) => {
78
80
  return import('../OpenExternal/OpenExternal.ipc.js')
79
81
  case ModuleId.OpenNativeFolder:
80
82
  return import('../OpenNativeFolder/OpenNativeFolder.ipc.js')
83
+ case ModuleId.Os:
84
+ return import('../Os/Os.ipc.js')
81
85
  case ModuleId.OutputChannel:
82
86
  return import('../OutputChannel/OutputChannel.ipc.js')
83
87
  case ModuleId.Performance:
@@ -106,8 +110,6 @@ export const load = (moduleId) => {
106
110
  return import('../WebSocketServer/WebSocketServer.ipc.js')
107
111
  case ModuleId.Workspace:
108
112
  return import('../Workspace/Workspace.ipc.js')
109
- case ModuleId.Os:
110
- return import('../Os/Os.ipc.js')
111
113
  default:
112
114
  throw new Error(`module ${moduleId} not found`)
113
115
  }
@@ -1,55 +1,56 @@
1
- export const Crash = 1
2
- export const ClipBoard = 2
3
- export const Developer = 3
4
- export const ElectronWindowAbout = 4
5
- export const ExtensionHost = 5
6
- export const ExtensionManagement = 6
7
- export const FileSystem = 7
8
- export const ElectronApplicationMenu = 8
9
- export const OpenNativeFolder = 9
10
- export const ElectronDialog = 10
11
- export const OutputChannel = 11
12
- export const Platform = 12
13
- export const ElectronClipBoard = 13
14
- export const Preferences = 14
15
- export const RecentlyOpened = 15
16
- export const Search = 16
17
- export const SearchFile = 17
18
- export const Terminal = 18
19
- export const ProcessId = 19
20
- export const TextDocument = 20
21
- export const WebSocketServer = 21
22
- export const Workspace = 22
23
- export const ChromeExtension = 23
24
- export const Download = 24
25
- export const GitLsFiles = 25
26
- export const BulkReplacement = 26
27
- export const InstallExtension = 27
28
- export const AutoUpdater = 28
29
- export const IsAutoUpdateSupported = 29
30
- export const AutoUpdaterAppImage = 30
31
- export const AutoUpdaterWindowsNsis = 31
32
- export const RebuildNodePty = 32
33
- export const ElectronNetLog = 33
34
- export const OpenExternal = 34
35
- export const ElectronSafeStorage = 35
36
- export const ElectronInitialize = 36
37
- export const HandleWebSocket = 37
38
- export const Process = 38
39
- export const AttachDebugger = 39
40
- export const HandleElectronMessagePort = 40
41
- export const ElectronProcess = 41
42
- export const HandleNodeMessagePort = 42
43
- export const GetTerminalSpawnOptions = 43
44
- export const HandleCliArgs = 44
45
- export const ListProcessesWithMemoryUsage = 45
46
- export const ElectronContextMenu = 46
47
- export const IncrementalTextSearch = 47
48
- export const Performance = 48
49
- export const ElectronBrowserView = 49
50
- export const Window = 50
51
- export const PassThroughElectronMessagePort = 51
52
- export const Exit = 52
53
- export const DesktopCapturer = 53
54
- export const ElectronContentTracing = 54
55
- export const Os = 55
1
+ export const ClipBoard = 1
2
+ export const Developer = 2
3
+ export const ExtensionHost = 3
4
+ export const ExtensionManagement = 4
5
+ export const FileSystem = 5
6
+ export const OpenNativeFolder = 6
7
+ export const OutputChannel = 7
8
+ export const Platform = 8
9
+ export const Preferences = 9
10
+ export const RecentlyOpened = 10
11
+ export const Search = 11
12
+ export const ElectronWindowProcessExplorer = 12
13
+ export const SearchFile = 13
14
+ export const Terminal = 14
15
+ export const TextDocument = 15
16
+ export const WebSocketServer = 16
17
+ export const Workspace = 17
18
+ export const ChromeExtension = 18
19
+ export const Download = 19
20
+ export const GitLsFiles = 20
21
+ export const BulkReplacement = 21
22
+ export const InstallExtension = 22
23
+ export const AutoUpdater = 23
24
+ export const IsAutoUpdateSupported = 24
25
+ export const AutoUpdaterAppImage = 25
26
+ export const AutoUpdaterWindowsNsis = 26
27
+ export const RebuildNodePty = 27
28
+ export const ElectronInitialize = 28
29
+ export const HandleWebSocket = 29
30
+ export const Process = 30
31
+ export const AttachDebugger = 31
32
+ export const HandleElectronMessagePort = 32
33
+ export const HandleNodeMessagePort = 33
34
+ export const GetTerminalSpawnOptions = 34
35
+ export const HandleCliArgs = 35
36
+ export const ListProcessesWithMemoryUsage = 36
37
+ export const IncrementalTextSearch = 37
38
+ export const Performance = 38
39
+ export const Crash = 39
40
+ export const ElectronWindowAbout = 40
41
+ export const ElectronApplicationMenu = 41
42
+ export const ElectronDialog = 42
43
+ export const ElectronClipBoard = 43
44
+ export const ProcessId = 44
45
+ export const ElectronNetLog = 45
46
+ export const OpenExternal = 46
47
+ export const ElectronSafeStorage = 47
48
+ export const ElectronProcess = 48
49
+ export const ElectronContextMenu = 49
50
+ export const ElectronBrowserView = 50
51
+ export const Window = 51
52
+ export const PassThroughElectronMessagePort = 52
53
+ export const Exit = 53
54
+ export const DesktopCapturer = 54
55
+ export const ElectronContentTracing = 55
56
+ export const Os = 56
@@ -36,8 +36,8 @@ export const getModuleId = (commandId) => {
36
36
  return ModuleId.Developer
37
37
  case 'Download.download':
38
38
  return ModuleId.Download
39
- case 'ElectronApplicationMenu.setItems':
40
39
  case 'ElectronApplicationMenu.handleClick':
40
+ case 'ElectronApplicationMenu.setItems':
41
41
  return ModuleId.ElectronApplicationMenu
42
42
  case 'ElectronBrowserView.createBrowserView':
43
43
  case 'ElectronBrowserView.disposeBrowserView':
@@ -66,6 +66,8 @@ export const getModuleId = (commandId) => {
66
66
  return ModuleId.ElectronSafeStorage
67
67
  case 'ElectronWindowAbout.open':
68
68
  return ModuleId.ElectronWindowAbout
69
+ case 'ElectronWindowProcessExplorer.open':
70
+ return ModuleId.ElectronWindowProcessExplorer
69
71
  case 'Exit.exit':
70
72
  return ModuleId.Exit
71
73
  case 'ExtensionHost.dispose':
@@ -169,6 +171,8 @@ export const getModuleId = (commandId) => {
169
171
  case 'Native.openFolder':
170
172
  case 'OpenNativeFolder.openFolder':
171
173
  return ModuleId.OpenNativeFolder
174
+ case 'Os.getTmpDir':
175
+ return ModuleId.Os
172
176
  case 'OutputChannel.close':
173
177
  case 'OutputChannel.open':
174
178
  return ModuleId.OutputChannel
@@ -177,6 +181,7 @@ export const getModuleId = (commandId) => {
177
181
  case 'Performance.getNodeStartupTiming':
178
182
  return ModuleId.Performance
179
183
  case 'Platform.getAppDir':
184
+ case 'Platform.getApplicationName':
180
185
  case 'Platform.getBuiltinExtensionsPath':
181
186
  case 'Platform.getCachedExtensionsPath':
182
187
  case 'Platform.getCacheDir':
@@ -197,15 +202,14 @@ export const getModuleId = (commandId) => {
197
202
  case 'Platform.getUserSettingsPath':
198
203
  case 'Platform.getVersion':
199
204
  case 'Platform.setEnvironmentVariables':
200
- case 'Platform.getApplicationName':
201
205
  return ModuleId.Platform
202
206
  case 'Preferences.getAll':
203
207
  return ModuleId.Preferences
208
+ case 'Process.getArch':
204
209
  case 'Process.getNodeVersion':
205
210
  case 'Process.getPid':
206
211
  case 'Process.getV8Version':
207
212
  case 'Process.kill':
208
- case 'Process.getArch':
209
213
  return ModuleId.Process
210
214
  case 'ProcessId.getMainProcessId':
211
215
  case 'ProcessId.getSharedProcessId':
@@ -237,8 +241,6 @@ export const getModuleId = (commandId) => {
237
241
  case 'Workspace.getHomeDir':
238
242
  case 'Workspace.resolveRoot':
239
243
  return ModuleId.Workspace
240
- case 'Os.getTmpDir':
241
- return ModuleId.Os
242
244
  default:
243
245
  throw new CommandNotFoundError(commandId)
244
246
  }
@@ -0,0 +1,9 @@
1
+ export const normalizeLine = (line) => {
2
+ if (line.startsWith('Error: ')) {
3
+ return line.slice(`Error: `.length)
4
+ }
5
+ if (line.startsWith('VError: ')) {
6
+ return line.slice(`VError: `.length)
7
+ }
8
+ return line
9
+ }
@@ -5,10 +5,10 @@ export const name = 'Platform'
5
5
 
6
6
  export const Commands = {
7
7
  getAppDir: PlatformPaths.getAppDir,
8
+ getApplicationName: Platform.getApplicationName,
8
9
  getBuiltinExtensionsPath: PlatformPaths.getBuiltinExtensionsPath,
9
10
  getCachedExtensionsPath: PlatformPaths.getCachedExtensionsPath,
10
11
  getCacheDir: PlatformPaths.getCacheDir,
11
- getApplicationName: Platform.getApplicationName,
12
12
  getCommit: Platform.getCommit,
13
13
  getConfigDir: PlatformPaths.getConfigDir,
14
14
  getDataDir: PlatformPaths.getDataDir,
@@ -13,10 +13,6 @@ export const isMacOs = platform === 'darwin'
13
13
 
14
14
  export const isDeb = false
15
15
 
16
- export const isAppImage = () => {
17
- return Boolean(env.APPIMAGE)
18
- }
19
-
20
16
  export const getPathSeparator = () => {
21
17
  return sep
22
18
  }
@@ -55,11 +51,11 @@ export const getSetupName = () => {
55
51
  return 'Lvce-Setup'
56
52
  }
57
53
 
58
- export const version = '0.18.10'
54
+ export const version = '0.18.12'
59
55
 
60
- export const commit = 'b4c3ec7'
56
+ export const commit = '1045890'
61
57
 
62
- export const date = '2023-10-07T08:15:16.000Z'
58
+ export const date = '2023-10-11T17:06:03.000Z'
63
59
 
64
60
  export const getVersion = () => {
65
61
  return version
@@ -5,9 +5,9 @@ export const name = 'Process'
5
5
  export const Commands = {
6
6
  crash: Process.crash,
7
7
  crashAsync: Process.crashAsync,
8
+ getArch: Process.getArch,
8
9
  getNodeVersion: Process.getNodeVersion,
9
10
  getPid: Process.getPid,
10
11
  getV8Version: Process.getV8Version,
11
12
  kill: Process.kill,
12
- getArch: Process.getArch,
13
13
  }
@@ -2,31 +2,14 @@ import exitHook from 'exit-hook'
2
2
  import * as Debug from '../Debug/Debug.js'
3
3
  import * as IpcParent from '../IpcParent/IpcParent.js'
4
4
  import * as IpcParentType from '../IpcParentType/IpcParentType.js'
5
- import * as PtyHostPath from '../PtyHostPath/PtyHostPath.js'
6
5
  import * as JsonRpc from '../JsonRpc/JsonRpc.js'
7
-
8
- export const state = {
9
- /**
10
- * @type {any}
11
- */
12
- ipc: undefined,
13
- /**
14
- * @type {any}
15
- */
16
- ptyHostPromise: undefined,
17
- /**
18
- * @type {any[]}
19
- */
20
- pendingMessages: [],
21
- send(message) {
22
- state.pendingMessages.push(message)
23
- },
24
- }
6
+ import * as PtyHostPath from '../PtyHostPath/PtyHostPath.js'
7
+ import * as PtyHostState from '../PtyHostState/PtyHostState.js'
25
8
 
26
9
  const cleanUpAll = () => {
27
- if (state.ipc) {
28
- state.ipc.dispose()
29
- state.ipc = undefined
10
+ if (PtyHostState.state.ipc) {
11
+ PtyHostState.state.ipc.dispose()
12
+ PtyHostState.state.ipc = undefined
30
13
  }
31
14
  }
32
15
 
@@ -47,40 +30,40 @@ const createPtyHost = async () => {
47
30
  })
48
31
  const handleClose = () => {
49
32
  ptyHost.off('close', handleClose)
50
- state.ipc = undefined
51
- state.ptyHostPromise = undefined
33
+ PtyHostState.state.ipc = undefined
34
+ PtyHostState.state.ptyHostPromise = undefined
52
35
  }
53
36
  ptyHost.on('close', handleClose)
54
- state.ipc = ptyHost
37
+ PtyHostState.state.ipc = ptyHost
55
38
  return ptyHost
56
39
  }
57
40
 
58
41
  export const getOrCreate = () => {
59
42
  Debug.debug('creating pty host')
60
- if (!state.ptyHostPromise) {
61
- state.ptyHostPromise = createPtyHost()
43
+ if (!PtyHostState.state.ptyHostPromise) {
44
+ PtyHostState.state.ptyHostPromise = createPtyHost()
62
45
  }
63
- return state.ptyHostPromise
46
+ return PtyHostState.state.ptyHostPromise
64
47
  }
65
48
 
66
49
  export const getCurrentInstance = () => {
67
- return state.ipc
50
+ return PtyHostState.state.ipc
68
51
  }
69
52
 
70
53
  export const disposeAll = () => {
71
- if (state.ipc) {
72
- state.ipc.removeAllListeners()
73
- if (state.ipc) {
74
- state.ipc.dispose()
75
- state.ipc = undefined
54
+ if (PtyHostState.state.ipc) {
55
+ PtyHostState.state.ipc.removeAllListeners()
56
+ if (PtyHostState.state.ipc) {
57
+ PtyHostState.state.ipc.dispose()
58
+ PtyHostState.state.ipc = undefined
76
59
  }
77
- state.ptyHostState = /* None */ 0
78
- state.send = (message) => {
79
- state.pendingMessages.push(message)
60
+ PtyHostState.state.ptyHostState = /* None */ 0
61
+ PtyHostState.state.send = (message) => {
62
+ PtyHostState.state.pendingMessages.push(message)
80
63
  }
81
64
  }
82
65
  }
83
66
 
84
67
  export const invoke = (method, ...params) => {
85
- return JsonRpc.invoke(state.ipc, method, ...params)
68
+ return JsonRpc.invoke(PtyHostState.state.ipc, method, ...params)
86
69
  }
@@ -0,0 +1,17 @@
1
+ export const state = {
2
+ /**
3
+ * @type {any}
4
+ */
5
+ ipc: undefined,
6
+ /**
7
+ * @type {any}
8
+ */
9
+ ptyHostPromise: undefined,
10
+ /**
11
+ * @type {any[]}
12
+ */
13
+ pendingMessages: [],
14
+ send(message) {
15
+ state.pendingMessages.push(message)
16
+ },
17
+ }
@@ -1,19 +1,18 @@
1
- import { spawn } from 'node:child_process'
2
- import * as FirstNodeWorkerEventType from '../FirstNodeWorkerEventType/FirstNodeWorkerEventType.js'
1
+ import { VError } from '@lvce-editor/verror'
2
+ import * as Exec from '../Exec/Exec.js'
3
3
  import * as GetElectronRebuildPath from '../GetElectronRebuildPath/GetElectronRebuildPath.js'
4
- import * as GetFirstNodeChildProcessEvent from '../GetFirstNodeChildProcessEvent/GetFirstNodeChildProcessEvent.js'
5
4
 
6
5
  /**
7
6
  * @param {string} cwd
8
7
  */
9
8
  export const rebuild = async (cwd) => {
10
- const electronRebuildPath = GetElectronRebuildPath.getElectronRebuildPath()
11
- const childProcess = spawn(electronRebuildPath, [], {
12
- cwd,
13
- stdio: 'inherit',
14
- })
15
- const { type, event } = await GetFirstNodeChildProcessEvent.getFirstNodeChildProcessEvent(childProcess)
16
- if (type === FirstNodeWorkerEventType.Error) {
17
- throw new Error(`Failed to rebuild native module: ${event}`)
9
+ try {
10
+ const electronRebuildPath = GetElectronRebuildPath.getElectronRebuildPath()
11
+ await Exec.exec(electronRebuildPath, [], {
12
+ cwd,
13
+ stdio: 'inherit',
14
+ })
15
+ } catch (error) {
16
+ throw new VError(error, `Failed to rebuild native module`)
18
17
  }
19
18
  }
@@ -1,17 +1,16 @@
1
- import { spawn } from 'node:child_process'
2
- import * as FirstNodeWorkerEventType from '../FirstNodeWorkerEventType/FirstNodeWorkerEventType.js'
3
- import * as GetFirstNodeChildProcessEvent from '../GetFirstNodeChildProcessEvent/GetFirstNodeChildProcessEvent.js'
1
+ import { VError } from '@lvce-editor/verror'
2
+ import * as Exec from '../Exec/Exec.js'
4
3
 
5
4
  /**
6
5
  * @param {string} cwd
7
6
  */
8
7
  export const rebuild = async (cwd) => {
9
- const childProcess = spawn('npm', ['rebuild'], {
10
- cwd,
11
- stdio: 'inherit',
12
- })
13
- const { type, event } = await GetFirstNodeChildProcessEvent.getFirstNodeChildProcessEvent(childProcess)
14
- if (type === FirstNodeWorkerEventType.Error) {
15
- throw new Error(`Failed to rebuild native module: ${event}`)
8
+ try {
9
+ await Exec.exec('npm', ['rebuild'], {
10
+ cwd,
11
+ stdio: 'inherit',
12
+ })
13
+ } catch (error) {
14
+ throw new VError(error, `Failed to rebuild native module`)
16
15
  }
17
16
  }
@@ -1,17 +1,3 @@
1
- import { setPriority } from 'node:os'
2
- import * as Command from './parts/Command/Command.js'
3
- import * as Module from './parts/Module/Module.js'
4
- import * as ParentIpc from './parts/ParentIpc/ParentIpc.js'
5
- import * as ProcessListeners from './parts/ProcessListeners/ProcessListeners.js'
6
- import * as Signal from './parts/Signal/Signal.js'
1
+ import * as Main from './parts/Main/Main.js'
7
2
 
8
- const main = async () => {
9
- Command.setLoad(Module.load)
10
- process.on('disconnect', ProcessListeners.handleDisconnect)
11
- process.on(Signal.SIGTERM, ProcessListeners.handleSigTerm)
12
- process.on('uncaughtExceptionMonitor', ProcessListeners.handleUncaughtExceptionMonitor)
13
- await ParentIpc.listen()
14
- setPriority(process.pid, 19)
15
- }
16
-
17
- main()
3
+ Main.main()