@lvce-editor/shared-process 0.16.18 → 0.16.20

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.
Files changed (53) hide show
  1. package/extensions/builtin.language-basics-javascript/src/tokenizeJavaScript.js +24 -1
  2. package/extensions/builtin.language-basics-less/src/tokenizeLess.js +17 -1
  3. package/extensions/builtin.language-basics-wgsl/README.md +16 -0
  4. package/extensions/builtin.language-basics-wgsl/extension.json +13 -0
  5. package/extensions/builtin.language-basics-wgsl/languageConfiguration.json +21 -0
  6. package/extensions/builtin.language-basics-wgsl/src/tokenizeWgsl.js +226 -0
  7. package/package.json +4 -4
  8. package/src/parts/ElectronContextMenu/ElectronContextMenu.ipc.js +7 -0
  9. package/src/parts/ElectronContextMenu/ElectronContextMenu.js +5 -0
  10. package/src/parts/ElectronProcess/ElectronProcess.ipc.js +8 -0
  11. package/src/parts/ElectronProcess/ElectronProcess.js +9 -0
  12. package/src/parts/ElectronSafeStorage/ElectronSafeStorage.ipc.js +9 -0
  13. package/src/parts/ElectronSafeStorage/ElectronSafeStorage.js +13 -0
  14. package/src/parts/ExtensionManifest/ExtensionManifest.js +2 -1
  15. package/src/parts/ExtensionManifests/ExtensionManifestsFromFolder.js +2 -4
  16. package/src/parts/ExtensionManifests/ExtensionManifestsFromLinkedExtensionsFolder.js +2 -4
  17. package/src/parts/ExtensionUnlink/ExtensionUnlink.js +2 -2
  18. package/src/parts/FileSystem/FileSystem.js +9 -4
  19. package/src/parts/GetAccurateMemoryUsage/GetAccurateMemoryUsage.js +30 -23
  20. package/src/parts/GetElectronRebuildPath/GetElectronRebuildPath.js +2 -2
  21. package/src/parts/GetFirstEvent/GetFirstEvent.js +22 -0
  22. package/src/parts/GetFirstNodeWorkerEvent/GetFirstNodeWorkerEvent.js +5 -16
  23. package/src/parts/GetFirstWebSocketEvent/GetFirstWebSocketEvent.js +3 -3
  24. package/src/parts/GetHttpErrorMessage/GetHttpErrorMessage.js +28 -0
  25. package/src/parts/GetLatestReleaseVersion/GetLatestReleaseVersion.js +2 -28
  26. package/src/parts/GetTerminalProcessPath/GetTerminalProcessPath.js +6 -0
  27. package/src/parts/IpcParentType/IpcParentType.js +1 -0
  28. package/src/parts/IpcParentWithElectronUtilityProcess/IpcParentWithElectronUtilityProcess.js +12 -0
  29. package/src/parts/IsEsrchError/IsEsrchError.js +5 -0
  30. package/src/parts/IsWindows/IsWindows.js +1 -0
  31. package/src/parts/ListProcessGetName/ListProcessGetName.js +3 -0
  32. package/src/parts/Module/Module.js +10 -2
  33. package/src/parts/ModuleId/ModuleId.js +5 -0
  34. package/src/parts/ModuleMap/ModuleMap.js +18 -0
  35. package/src/parts/PassThroughElectronMessageForTerminalProcess/PassThroughElectronMessageForTerminalProcess.js +29 -0
  36. package/src/parts/PassThroughElectronMessagePort/PassThroughElectronMessagePort.ipc.js +7 -0
  37. package/src/parts/PassThroughElectronMessagePort/PassThroughElectronMessagePort.js +4 -0
  38. package/src/parts/PassThroughElectronMessagePortModule/PassThroughElectronMessagePortModule.js +8 -0
  39. package/src/parts/Platform/Platform.ipc.js +1 -1
  40. package/src/parts/Platform/Platform.js +3 -3
  41. package/src/parts/Preferences/Preferences.js +2 -1
  42. package/src/parts/Process/Process.js +4 -0
  43. package/src/parts/PtyHost/PtyHost.js +17 -12
  44. package/src/parts/RebuildForElectron/RebuildForElectron.js +19 -0
  45. package/src/parts/RebuildForNode/RebuildForNode.js +17 -0
  46. package/src/parts/RebuildNodePty/RebuildNodePty.js +5 -38
  47. package/src/parts/RecentlyOpened/RecentlyOpened.js +3 -2
  48. package/src/parts/RemoveSymlink/RemoveSymlink.js +12 -0
  49. package/src/parts/Terminal/Terminal.js +5 -3
  50. package/src/parts/WaitForProcessToExit/WaitForProcessToExit.js +4 -24
  51. package/src/parts/WebSocketReadyState/WebSocketReadyState.js +5 -0
  52. package/src/parts/Window/ElectronWindow.ipc.js +12 -0
  53. package/src/parts/Window/ElectronWindow.js +32 -0
@@ -3,34 +3,41 @@ import { join } from 'node:path'
3
3
  import * as Assert from '../Assert/Assert.js'
4
4
  import * as Character from '../Character/Character.js'
5
5
  import * as EncodingType from '../EncodingType/EncodingType.js'
6
- import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
6
+ import * as IsEnoentError from '../IsEnoentError/IsEnoentError.js'
7
+ import * as IsEsrchError from '../IsEsrchError/IsEsrchError.js'
7
8
  import { VError } from '../VError/VError.js'
8
9
 
9
- export const getAccurateMemoryUsage = async (pid) => {
10
- Assert.number(pid)
10
+ const getContent = async (pid) => {
11
11
  try {
12
12
  const filePath = join('/proc', `${pid}`, 'statm')
13
- let content
14
- try {
15
- content = await readFile(filePath, EncodingType.Utf8)
16
- } catch (error) {
17
- if (
18
- error &&
19
- // @ts-ignore
20
- (error.code === ErrorCodes.ENOENT ||
21
- // @ts-ignore
22
- error.code === ErrorCodes.ESRCH)
23
- ) {
24
- return -1
25
- }
26
- throw error
13
+ const content = await readFile(filePath, EncodingType.Utf8)
14
+ return content
15
+ } catch (error) {
16
+ if (IsEnoentError.isEnoentError(error) || IsEsrchError.isEsrchError(error)) {
17
+ return ''
18
+ }
19
+ throw error
20
+ }
21
+ }
22
+
23
+ const parseMemory = (content) => {
24
+ const trimmedContent = content.trim()
25
+ const numberBlocks = trimmedContent.split(Character.Space)
26
+ const pageSize = 4096
27
+ const rss = Number.parseInt(numberBlocks[1]) * pageSize
28
+ const shared = Number.parseInt(numberBlocks[2]) * pageSize
29
+ const memory = rss - shared
30
+ return memory
31
+ }
32
+
33
+ export const getAccurateMemoryUsage = async (pid) => {
34
+ try {
35
+ Assert.number(pid)
36
+ const content = await getContent(pid)
37
+ if (!content) {
38
+ return -1
27
39
  }
28
- const trimmedContent = content.trim()
29
- const numberBlocks = trimmedContent.split(Character.Space)
30
- const pageSize = 4096
31
- const rss = Number.parseInt(numberBlocks[1]) * pageSize
32
- const shared = Number.parseInt(numberBlocks[2]) * pageSize
33
- const memory = rss - shared
40
+ const memory = parseMemory(content)
34
41
  return memory
35
42
  } catch (error) {
36
43
  throw new VError(error, 'Failed to get accurate memory usage')
@@ -1,9 +1,9 @@
1
- import * as IsElectron from '../IsElectron/IsElectron.js'
1
+ import * as IsWindows from '../IsWindows/IsWindows.js'
2
2
  import * as Path from '../Path/Path.js'
3
3
  import * as Root from '../Root/Root.js'
4
4
 
5
5
  export const getElectronRebuildPath = () => {
6
- if (IsElectron.isElectron()) {
6
+ if (IsWindows.isWindows) {
7
7
  return Path.join(Root.root, 'packages', 'main-process', 'node_modules', '.bin', 'electron-rebuild.cmd')
8
8
  }
9
9
  return Path.join(Root.root, 'packages', 'main-process', 'node_modules', '.bin', 'electron-rebuild')
@@ -0,0 +1,22 @@
1
+ export const getFirstEvent = async (eventEmitter, eventMap) => {
2
+ const { type, event } = await new Promise((resolve, reject) => {
3
+ const listenerMap = Object.create(null)
4
+ const cleanup = (value) => {
5
+ for (const event of Object.keys(eventMap)) {
6
+ eventEmitter.off(event, listenerMap[event])
7
+ }
8
+ resolve(value)
9
+ }
10
+ for (const [event, type] of Object.entries(eventMap)) {
11
+ const listener = (event) => {
12
+ cleanup({
13
+ type,
14
+ event,
15
+ })
16
+ }
17
+ eventEmitter.on(event, listener)
18
+ listenerMap[event] = listener
19
+ }
20
+ })
21
+ return { type, event }
22
+ }
@@ -1,20 +1,9 @@
1
1
  import * as FirstNodeWorkerEventType from '../FirstNodeWorkerEventType/FirstNodeWorkerEventType.js'
2
+ import * as GetFirstEvent from '../GetFirstEvent/GetFirstEvent.js'
2
3
 
3
- export const getFirstNodeWorkerEvent = async (worker) => {
4
- const { type, event } = await new Promise((resolve, reject) => {
5
- const cleanup = (value) => {
6
- worker.off('exit', handleExit)
7
- worker.off('error', handleError)
8
- resolve(value)
9
- }
10
- const handleExit = (event) => {
11
- cleanup({ type: FirstNodeWorkerEventType.Exit, event })
12
- }
13
- const handleError = (event) => {
14
- cleanup({ type: FirstNodeWorkerEventType.Error, event })
15
- }
16
- worker.on('exit', handleExit)
17
- worker.on('error', handleError)
4
+ export const getFirstNodeWorkerEvent = (worker) => {
5
+ return GetFirstEvent.getFirstEvent(worker, {
6
+ exit: FirstNodeWorkerEventType.Exit,
7
+ error: FirstNodeWorkerEventType.Error,
18
8
  })
19
- return { type, event }
20
9
  }
@@ -1,14 +1,14 @@
1
1
  import * as FirstWebSocketEventType from '../FirstWebSocketEventType/FirstWebSocketEventType.js'
2
- import { WebSocket } from 'ws'
2
+ import * as WebSocketReadyState from '../WebSocketReadyState/WebSocketReadyState.js'
3
3
 
4
4
  export const getFirstWebSocketEvent = async (webSocket) => {
5
5
  switch (webSocket.readyState) {
6
- case WebSocket.OPEN:
6
+ case WebSocketReadyState.Open:
7
7
  return {
8
8
  type: FirstWebSocketEventType.Open,
9
9
  event: undefined,
10
10
  }
11
- case WebSocket.CLOSED:
11
+ case WebSocketReadyState.Closed:
12
12
  return {
13
13
  type: FirstWebSocketEventType.Close,
14
14
  event: undefined,
@@ -0,0 +1,28 @@
1
+ import { HTTPError } from 'got'
2
+
3
+ /**
4
+ *
5
+ * @param {HTTPError} error
6
+ */
7
+ export const getHttpErrorMessage = (error) => {
8
+ try {
9
+ const body = error.response.body
10
+ if (error.response.url.includes('api.github.com') && typeof body === 'string') {
11
+ const json = JSON.parse(body)
12
+ if (json.message) {
13
+ const message = json.message
14
+ if (message.includes('rate limit exceeded')) {
15
+ const reset = error.response.headers['x-ratelimit-reset']
16
+ const limit = error.response.headers['x-ratelimit-limit']
17
+ if (reset && typeof reset === 'string' && typeof limit === 'string') {
18
+ const resetDate = new Date(parseInt(reset) * 1000)
19
+ const limitAmount = parseInt(limit)
20
+ return `GitHub rate limit of ${limitAmount} requests per hour execeeded, resets at ${resetDate}`
21
+ }
22
+ }
23
+ return json.message
24
+ }
25
+ }
26
+ } catch {}
27
+ return `${error.message}`
28
+ }
@@ -1,33 +1,7 @@
1
1
  import got, { HTTPError } from 'got'
2
+ import * as GetHttpErrorMessage from '../GetHttpErrorMessage/GetHttpErrorMessage.js'
2
3
  import { VError } from '../VError/VError.js'
3
4
 
4
- /**
5
- *
6
- * @param {HTTPError} error
7
- */
8
- const getHttpErrorMessage = (error) => {
9
- try {
10
- const body = error.response.body
11
- if (error.response.url.includes('api.github.com') && typeof body === 'string') {
12
- const json = JSON.parse(body)
13
- if (json.message) {
14
- const message = json.message
15
- if (message.includes('rate limit exceeded')) {
16
- const reset = error.response.headers['x-ratelimit-reset']
17
- const limit = error.response.headers['x-ratelimit-limit']
18
- if (reset && typeof reset === 'string' && typeof limit === 'string') {
19
- const resetDate = new Date(parseInt(reset) * 1000)
20
- const limitAmount = parseInt(limit)
21
- return `GitHub rate limit of ${limitAmount} requests per hour execeeded, resets at ${resetDate}`
22
- }
23
- }
24
- return json.message
25
- }
26
- }
27
- } catch {}
28
- return `${error.message}`
29
- }
30
-
31
5
  const parseVersionFromUrl = (url, repository) => {
32
6
  if (!url.includes('releases/tag')) {
33
7
  if (url.endsWith('/releases')) {
@@ -51,7 +25,7 @@ export const getLatestReleaseVersion = async (repository) => {
51
25
  return version
52
26
  } catch (error) {
53
27
  if (error instanceof HTTPError) {
54
- const httpErrorMessage = getHttpErrorMessage(error)
28
+ const httpErrorMessage = GetHttpErrorMessage.getHttpErrorMessage(error)
55
29
  throw new VError(`Failed to get latest release for ${repository}: ${httpErrorMessage}`)
56
30
  }
57
31
  // @ts-ignore
@@ -0,0 +1,6 @@
1
+ import * as Path from '../Path/Path.js'
2
+ import * as Root from '../Root/Root.js'
3
+
4
+ export const getTerminalProcessPath = () => {
5
+ return Path.join(Root.root, 'packages', 'pty-host', 'src', 'ptyHostMain.js')
6
+ }
@@ -1,2 +1,3 @@
1
1
  export const NodeWorker = 1
2
2
  export const NodeForkedProcess = 2
3
+ export const ElectronUtilityProcess = 3
@@ -0,0 +1,12 @@
1
+ import * as ParentIpc from '../ParentIpc/ParentIpc.js'
2
+
3
+ export const create = async (options) => {
4
+ // TODO how to launch process without race condition?
5
+ // when promise resolves, process might have already exited
6
+ const messagePort = await ParentIpc.invoke('IpcParent.create', { ...options })
7
+ return messagePort
8
+ }
9
+
10
+ export const wrap = (messagePort) => {
11
+ return {}
12
+ }
@@ -0,0 +1,5 @@
1
+ import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
2
+
3
+ export const isEsrchError = (error) => {
4
+ return error && error.code === ErrorCodes.ESRCH
5
+ }
@@ -0,0 +1 @@
1
+ export const isWindows = process.platform === 'win32'
@@ -50,5 +50,8 @@ export const getName = (pid, cmd, rootPid, pidMap) => {
50
50
  if (cmd.startsWith(`/opt/sublime_text/sublime_text `)) {
51
51
  return 'sublime-text'
52
52
  }
53
+ if(cmd.includes('\\conhost.exe')){
54
+ return 'conhost.exe'
55
+ }
53
56
  return `${cmd}`
54
57
  }
@@ -20,8 +20,14 @@ export const load = (moduleId) => {
20
20
  return import('../Developer/Developer.ipc.js')
21
21
  case ModuleId.Download:
22
22
  return import('../Download/Download.ipc.js')
23
+ case ModuleId.ElectronContextMenu:
24
+ return import('../ElectronContextMenu/ElectronContextMenu.ipc.js')
23
25
  case ModuleId.ElectronInitialize:
24
26
  return import('../ElectronInitialize/ElectronInitialize.ipc.js')
27
+ case ModuleId.ElectronProcess:
28
+ return import('../ElectronProcess/ElectronProcess.ipc.js')
29
+ case ModuleId.ElectronSafeStorage:
30
+ return import('../ElectronSafeStorage/ElectronSafeStorage.ipc.js')
25
31
  case ModuleId.ExtensionHost:
26
32
  return import('../ExtensionHost/ExtensionHost.ipc.js')
27
33
  case ModuleId.ExtensionManagement:
@@ -52,6 +58,8 @@ export const load = (moduleId) => {
52
58
  return import('../OpenNativeFolder/OpenNativeFolder.ipc.js')
53
59
  case ModuleId.OutputChannel:
54
60
  return import('../OutputChannel/OutputChannel.ipc.js')
61
+ case ModuleId.Performance:
62
+ return import('../Performance/Performance.ipc.js')
55
63
  case ModuleId.Platform:
56
64
  return import('../Platform/Platform.ipc.js')
57
65
  case ModuleId.Preferences:
@@ -72,10 +80,10 @@ export const load = (moduleId) => {
72
80
  return import('../TextSearch/TextSearch.ipc.js')
73
81
  case ModuleId.WebSocketServer:
74
82
  return import('../WebSocketServer/WebSocketServer.ipc.js')
83
+ case ModuleId.Window:
84
+ return import('../Window/ElectronWindow.ipc.js')
75
85
  case ModuleId.Workspace:
76
86
  return import('../Workspace/Workspace.ipc.js')
77
- case ModuleId.Performance:
78
- return import('../Performance/Performance.ipc.js')
79
87
  default:
80
88
  throw new Error(`module ${moduleId} not found`)
81
89
  }
@@ -24,14 +24,19 @@ export const IsAutoUpdateSupported = 23
24
24
  export const AutoUpdaterAppImage = 24
25
25
  export const AutoUpdaterWindowsNsis = 25
26
26
  export const RebuildNodePty = 26
27
+ export const ElectronSafeStorage = 80
27
28
  export const ElectronInitialize = 27
28
29
  export const HandleWebSocket = 28
29
30
  export const Process = 29
30
31
  export const AttachDebugger = 30
31
32
  export const HandleElectronMessagePort = 31
33
+ export const ElectronProcess = 70
32
34
  export const HandleNodeMessagePort = 32
33
35
  export const GetTerminalSpawnOptions = 33
34
36
  export const HandleCliArgs = 34
35
37
  export const ListProcessesWithMemoryUsage = 35
38
+ export const ElectronContextMenu = 40
36
39
  export const IncrementalTextSearch = 36
37
40
  export const Performance = 37
41
+ export const Window = 38
42
+ export const PassThroughElectronMessagePort = 39
@@ -3,6 +3,8 @@ import * as ModuleId from '../ModuleId/ModuleId.js'
3
3
 
4
4
  export const getModuleId = (commandId) => {
5
5
  switch (commandId) {
6
+ case 'PassthroughElectronMessagePort.passThroughElectronMessagePort':
7
+ return ModuleId.PassThroughElectronMessagePort
6
8
  case 'AttachDebugger.attachDebugger':
7
9
  return ModuleId.AttachDebugger
8
10
  case 'AutoUpdater.getAutoUpdateType':
@@ -22,6 +24,10 @@ export const getModuleId = (commandId) => {
22
24
  case 'ClipBoard.readFiles':
23
25
  case 'ClipBoard.writeFiles':
24
26
  return ModuleId.ClipBoard
27
+ case 'ElectronSafeStorage.encryptString':
28
+ case 'ElectronSafeStorage.decryptString':
29
+ case 'ElectronSafeStorage.isEncryptionAvailable':
30
+ return ModuleId.ElectronSafeStorage
25
31
  case 'Developer.allocateMemory':
26
32
  case 'Developer.crashSharedProcess':
27
33
  case 'Developer.createHeapSnapshot':
@@ -177,13 +183,25 @@ export const getModuleId = (commandId) => {
177
183
  case 'Terminal.resize':
178
184
  case 'Terminal.write':
179
185
  return ModuleId.Terminal
186
+ case 'ElectronProcess.getChromeVersion':
187
+ case 'ElectronProcess.getElectronVersion':
188
+ return ModuleId.ElectronProcess
180
189
  case 4820:
181
190
  return ModuleId.TextDocument
191
+ case 'ElectronContextMenu.openContextMenu':
192
+ return ModuleId.ElectronContextMenu
182
193
  case 'WebSocketServer.handleUpgrade':
183
194
  return ModuleId.WebSocketServer
184
195
  case 'Workspace.getHomeDir':
185
196
  case 'Workspace.resolveRoot':
186
197
  return ModuleId.Workspace
198
+ case 'ElectronWindow.minimize':
199
+ case 'ElectronWindow.maximize':
200
+ case 'ElectronWindow.toggleDevtools':
201
+ case 'ElectronWindow.unmaximize':
202
+ case 'ElectronWindow.close':
203
+ case 'ElectronWindow.reload':
204
+ return ModuleId.Window
187
205
  default:
188
206
  throw new CommandNotFoundError(commandId)
189
207
  }
@@ -0,0 +1,29 @@
1
+ import * as Assert from '../Assert/Assert.js'
2
+ import * as GetTerminalProcessPath from '../GetTerminalProcessPath/GetTerminalProcessPath.js'
3
+ import * as IpcParent from '../IpcParent/IpcParent.js'
4
+ import * as IpcParentType from '../IpcParentType/IpcParentType.js'
5
+
6
+ /**
7
+ *
8
+ * @returns
9
+ */
10
+ export const handlePort = async (browserWindowPort, type, name) => {
11
+ Assert.object(browserWindowPort)
12
+ Assert.string(type)
13
+ Assert.string(name)
14
+ const ptyHostPath = GetTerminalProcessPath.getTerminalProcessPath()
15
+ const ipc = await IpcParent.create({
16
+ method: IpcParentType.ElectronUtilityProcess,
17
+ path: ptyHostPath,
18
+ name,
19
+ })
20
+ // TODO use connectIpc for better error handling
21
+ ipc.sendAndTransfer(
22
+ {
23
+ jsonrpc: '2.0',
24
+ method: 'HandleElectronMessagePort.handleElectronMessagePort',
25
+ params: [],
26
+ },
27
+ [browserWindowPort]
28
+ )
29
+ }
@@ -0,0 +1,7 @@
1
+ import * as PassThroughElectronMessagePort from './PassThroughElectronMessagePort.js'
2
+
3
+ export const name = 'PassThroughElectronMessagePort'
4
+
5
+ export const Commands = {
6
+ passThroughElectronMessagePort: PassThroughElectronMessagePort.passThroughElectronMessagePort,
7
+ }
@@ -0,0 +1,4 @@
1
+ import * as Path from '../Path/Path.js'
2
+ import * as Root from '../Root/Root.js'
3
+
4
+ export const passThroughElectronMessagePort = () => {}
@@ -0,0 +1,8 @@
1
+ export const getModule = (type) => {
2
+ switch (type) {
3
+ case 'terminal-process':
4
+ return import('../PassThroughElectronMessageForTerminalProcess/PassThroughElectronMessageForTerminalProcess.js')
5
+ default:
6
+ return undefined
7
+ }
8
+ }
@@ -21,8 +21,8 @@ export const Commands = {
21
21
  getRecentlyOpenedPath: Platform.getRecentlyOpenedPath,
22
22
  getTestPath: Platform.getTestPath,
23
23
  getTmpDir: Platform.getTmpDir,
24
+ getUserKeyBindingsPath: Platform.getUserKeyBindingsPath,
24
25
  getUserSettingsPath: Platform.getUserSettingsPath,
25
26
  getVersion: Platform.getVersion,
26
27
  setEnvironmentVariables: Platform.setEnvironmentVariables,
27
- getUserKeyBindingsPath: Platform.getUserKeyBindingsPath,
28
28
  }
@@ -169,11 +169,11 @@ export const getSetupName = () => {
169
169
  return 'Lvce-Setup'
170
170
  }
171
171
 
172
- export const version = '0.16.18'
172
+ export const version = '0.16.20'
173
173
 
174
- export const commit = 'd5caee6'
174
+ export const commit = '2a4c633'
175
175
 
176
- export const date = '2023-07-20T14:53:13.000Z'
176
+ export const date = '2023-07-29T10:35:52.000Z'
177
177
 
178
178
  export const getVersion = () => {
179
179
  return version
@@ -2,6 +2,7 @@ import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
2
2
  import * as JsoncFile from '../JsoncFile/JsoncFile.js'
3
3
  import * as Platform from '../Platform/Platform.js'
4
4
  import * as Process from '../Process/Process.js'
5
+ import * as IsEnoentError from '../IsEnoentError/IsEnoentError.js'
5
6
  import { VError } from '../VError/VError.js'
6
7
  // TODO need jsonc parser for settings with comments
7
8
 
@@ -12,7 +13,7 @@ export const getUserPreferences = async () => {
12
13
  try {
13
14
  json = await JsoncFile.readJsonc(userSettingsPath)
14
15
  } catch (error) {
15
- if (error && error.code === ErrorCodes.ENOENT) {
16
+ if (IsEnoentError.isEnoentError(error)) {
16
17
  return {}
17
18
  }
18
19
  throw error
@@ -1,4 +1,5 @@
1
1
  import { VError } from '../VError/VError.js'
2
+ import * as IsEsrchError from '../IsEsrchError/IsEsrchError.js'
2
3
 
3
4
  export const crash = (message) => {
4
5
  throw new Error(message)
@@ -34,6 +35,9 @@ export const kill = (pid, signal) => {
34
35
  try {
35
36
  process.kill(pid, signal)
36
37
  } catch (error) {
38
+ if (IsEsrchError.isEsrchError(error)) {
39
+ return
40
+ }
37
41
  throw new VError(error, `Failed to kill process ${pid} with signal ${signal}`)
38
42
  }
39
43
  }
@@ -3,12 +3,13 @@ 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
5
  import * as PtyHostPath from '../PtyHostPath/PtyHostPath.js'
6
+ import * as JsonRpc from '../JsonRpc/JsonRpc.js'
6
7
 
7
8
  export const state = {
8
9
  /**
9
10
  * @type {any}
10
11
  */
11
- ptyHost: undefined,
12
+ ipc: undefined,
12
13
  /**
13
14
  * @type {any}
14
15
  */
@@ -23,9 +24,9 @@ export const state = {
23
24
  }
24
25
 
25
26
  const cleanUpAll = () => {
26
- if (state.ptyHost) {
27
- state.ptyHost.dispose()
28
- state.ptyHost = undefined
27
+ if (state.ipc) {
28
+ state.ipc.dispose()
29
+ state.ipc = undefined
29
30
  }
30
31
  }
31
32
 
@@ -46,11 +47,11 @@ const createPtyHost = async () => {
46
47
  })
47
48
  const handleClose = () => {
48
49
  ptyHost.off('close', handleClose)
49
- state.ptyHost = undefined
50
+ state.ipc = undefined
50
51
  state.ptyHostPromise = undefined
51
52
  }
52
53
  ptyHost.on('close', handleClose)
53
- state.ptyHost = ptyHost
54
+ state.ipc = ptyHost
54
55
  return ptyHost
55
56
  }
56
57
 
@@ -63,15 +64,15 @@ export const getOrCreate = () => {
63
64
  }
64
65
 
65
66
  export const getCurrentInstance = () => {
66
- return state.ptyHost
67
+ return state.ipc
67
68
  }
68
69
 
69
70
  export const disposeAll = () => {
70
- if (state.ptyHost) {
71
- state.ptyHost.removeAllListeners()
72
- if (state.ptyHost) {
73
- state.ptyHost.dispose()
74
- state.ptyHost = undefined
71
+ if (state.ipc) {
72
+ state.ipc.removeAllListeners()
73
+ if (state.ipc) {
74
+ state.ipc.dispose()
75
+ state.ipc = undefined
75
76
  }
76
77
  state.ptyHostState = /* None */ 0
77
78
  state.send = (message) => {
@@ -79,3 +80,7 @@ export const disposeAll = () => {
79
80
  }
80
81
  }
81
82
  }
83
+
84
+ export const invoke = (method, ...params) => {
85
+ return JsonRpc.invoke(state.ipc, method, ...params)
86
+ }
@@ -0,0 +1,19 @@
1
+ import { spawn } from 'node:child_process'
2
+ import * as FirstNodeWorkerEventType from '../FirstNodeWorkerEventType/FirstNodeWorkerEventType.js'
3
+ import * as GetElectronRebuildPath from '../GetElectronRebuildPath/GetElectronRebuildPath.js'
4
+ import * as GetFirstNodeChildProcessEvent from '../GetFirstNodeChildProcessEvent/GetFirstNodeChildProcessEvent.js'
5
+
6
+ /**
7
+ * @param {string} cwd
8
+ */
9
+ 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}`)
18
+ }
19
+ }
@@ -0,0 +1,17 @@
1
+ import { spawn } from 'node:child_process'
2
+ import * as FirstNodeWorkerEventType from '../FirstNodeWorkerEventType/FirstNodeWorkerEventType.js'
3
+ import * as GetFirstNodeChildProcessEvent from '../GetFirstNodeChildProcessEvent/GetFirstNodeChildProcessEvent.js'
4
+
5
+ /**
6
+ * @param {string} cwd
7
+ */
8
+ 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}`)
16
+ }
17
+ }
@@ -1,7 +1,3 @@
1
- import { spawn } from 'node:child_process'
2
- import * as FirstNodeWorkerEventType from '../FirstNodeWorkerEventType/FirstNodeWorkerEventType.js'
3
- import * as GetElectronRebuildPath from '../GetElectronRebuildPath/GetElectronRebuildPath.js'
4
- import * as GetFirstNodeChildProcessEvent from '../GetFirstNodeChildProcessEvent/GetFirstNodeChildProcessEvent.js'
5
1
  import * as IsElectron from '../IsElectron/IsElectron.js'
6
2
  import * as Path from '../Path/Path.js'
7
3
  import * as Root from '../Root/Root.js'
@@ -11,47 +7,18 @@ const getPtyHostPath = () => {
11
7
  return Path.join(Root.root, 'packages', 'pty-host')
12
8
  }
13
9
 
14
- /**
15
- * @param {string} cwd
16
- */
17
- const rebuildNodePtyElectron = async (cwd) => {
18
- const electronRebuildPath = GetElectronRebuildPath.getElectronRebuildPath()
19
- const childProcess = spawn(electronRebuildPath, [], {
20
- cwd,
21
- stdio: 'inherit',
22
- })
23
- const { type, event } = await GetFirstNodeChildProcessEvent.getFirstNodeChildProcessEvent(childProcess)
24
- if (type === FirstNodeWorkerEventType.Error) {
25
- throw new Error(`Failed to rebuild native module: ${event}`)
26
- }
27
- }
28
-
29
- /**
30
- * @param {string} cwd
31
- */
32
- const rebuildNodePtyNode = async (cwd) => {
33
- const childProcess = spawn('npm', ['rebuild'], {
34
- cwd,
35
- stdio: 'inherit',
36
- })
37
- const { type, event } = await GetFirstNodeChildProcessEvent.getFirstNodeChildProcessEvent(childProcess)
38
- if (type === FirstNodeWorkerEventType.Error) {
39
- throw new Error(`Failed to rebuild native module: ${event}`)
40
- }
41
- }
42
-
43
- const getFn = () => {
10
+ const getModule = () => {
44
11
  if (IsElectron.isElectron()) {
45
- return rebuildNodePtyElectron
12
+ return import('../RebuildForElectron/RebuildForElectron.js')
46
13
  }
47
- return rebuildNodePtyNode
14
+ return import('../RebuildForNode/RebuildForNode.js')
48
15
  }
49
16
 
50
17
  export const rebuildNodePty = async () => {
51
18
  try {
52
19
  const ptyHostPath = getPtyHostPath()
53
- const rebuild = getFn()
54
- await rebuild(ptyHostPath)
20
+ const module = await getModule()
21
+ await module.rebuild(ptyHostPath)
55
22
  } catch (error) {
56
23
  throw new VError(error, `Failed to rebuild node-pty`)
57
24
  }