@lvce-editor/shared-process 0.12.1 → 0.14.0

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 (102) hide show
  1. package/config/defaultKeyBindings.json +30 -0
  2. package/config/defaultSettings.json +6 -0
  3. package/extensions/builtin.language-basics-css/extension.json +2 -1
  4. package/extensions/builtin.language-basics-css/languageConfiguration.json +21 -0
  5. package/extensions/builtin.language-basics-css/src/tokenizeCss.js +7 -1
  6. package/extensions/builtin.language-basics-html/src/tokenizeHtml.js +77 -27
  7. package/extensions/builtin.language-basics-javascript/src/tokenizeJavaScript.js +29 -1
  8. package/extensions/builtin.language-basics-json/extension.json +4 -2
  9. package/extensions/builtin.language-basics-json/src/tokenizeJson.js +3 -0
  10. package/extensions/builtin.language-basics-jsx/src/tokenizeJsx.js +18 -5
  11. package/extensions/builtin.language-basics-vue/src/tokenizeVue.js +1 -1
  12. package/extensions/builtin.language-basics-xml/extension.json +3 -1
  13. package/package.json +9 -10
  14. package/src/parts/Assert/Assert.js +1 -6
  15. package/src/parts/AssertionError/AssertionError.js +6 -0
  16. package/src/parts/BulkReplacement/BulkReplacement.ipc.js +7 -0
  17. package/src/parts/BulkReplacement/BulkReplacement.js +20 -0
  18. package/src/parts/BulkReplacementContent/BulkReplacementContent.js +30 -0
  19. package/src/parts/ChildProcessError/ChildProcessError.js +45 -0
  20. package/src/parts/ChromeExtension/ChromeExtension.js +2 -5
  21. package/src/parts/CleanStack/CleanStack.js +90 -2
  22. package/src/parts/CliList/CliList.js +3 -0
  23. package/src/parts/ClipBoard/ClipBoard.js +2 -2
  24. package/src/parts/ClipBoard/ClipBoardGnome.js +1 -2
  25. package/src/parts/ClipBoard/ClipBoardNoop.js +2 -2
  26. package/src/parts/ClipBoard/ClipBoardWindows.js +1 -3
  27. package/src/parts/Command/Command.js +5 -10
  28. package/src/parts/Credentials/Credentials.ipc.js +5 -5
  29. package/src/parts/Credentials/Credentials.js +2 -10
  30. package/src/parts/Desktop/Desktop.js +22 -0
  31. package/src/parts/Download/Download.js +2 -2
  32. package/src/parts/Error/Error.js +1 -1
  33. package/src/parts/ErrorCodes/ErrorCodes.js +2 -1
  34. package/src/parts/ErrorHandling/ErrorHandling.js +8 -14
  35. package/src/parts/ExtensionHost/ExtensionHost.js +1 -2
  36. package/src/parts/ExtensionHost/ExtensionHostKeyBindings.js +0 -12
  37. package/src/parts/ExtensionHostRpc/ExtensionHostRpc.js +1 -1
  38. package/src/parts/ExtensionInstallFromFile/ExtensionInstallFromFile.js +1 -1
  39. package/src/parts/ExtensionInstallFromGitHub/ExtensionInstallFromGitHub.js +1 -1
  40. package/src/parts/ExtensionInstallFromUrl/ExtensionInstallFromUrl.js +1 -1
  41. package/src/parts/ExtensionLink/ExtensionLink.js +0 -19
  42. package/src/parts/ExtensionList/ExtensionList.js +11 -2
  43. package/src/parts/ExtensionManagement/ExtensionManagement.js +6 -58
  44. package/src/parts/ExtensionManagement/ExtensionManagementColorTheme.js +3 -1
  45. package/src/parts/ExtensionManagement/ExtensionManagementIconTheme.js +1 -1
  46. package/src/parts/ExtensionManagement/ExtensionManagementLanguages.js +7 -3
  47. package/src/parts/ExtensionManifestInputType/ExtensionManifestInputType.js +2 -0
  48. package/src/parts/ExtensionManifests/ExtensionManifests.js +3 -0
  49. package/src/parts/ExtensionManifests/ExtensionManifestsFromFolder.js +5 -15
  50. package/src/parts/ExtensionManifests/ExtensionManifestsFromLinkedExtensionsFolder.js +56 -0
  51. package/src/parts/ExtensionUninstall/ExtensionUninstall.js +18 -0
  52. package/src/parts/ExtensionUnlink/ExtensionUnlink.js +1 -1
  53. package/src/parts/Extract/Extract.js +2 -6
  54. package/src/parts/ExtractZip/ExtractZip.js +1 -1
  55. package/src/parts/{Error → FileNotFoundError}/FileNotFoundError.js +9 -2
  56. package/src/parts/FileSystem/FileSystem.js +6 -32
  57. package/src/parts/FirstNodeWorkerEventType/FirstNodeWorkerEventType.js +5 -0
  58. package/src/parts/GetDirentType/GetDirentType.js +27 -0
  59. package/src/parts/GetFirstNodeChildProcessEvent/GetFirstNodeChildProcessEvent.js +39 -0
  60. package/src/parts/GetFirstNodeWorkerEvent/GetFirstNodeWorkerEvent.js +21 -0
  61. package/src/parts/GetNewLineIndex/GetNewLineIndex.js +9 -0
  62. package/src/parts/GetResponse/GetResponse.js +16 -6
  63. package/src/parts/GetTextSearchRipGrepArgs/GetTextSearchRipGrepArgs.js +14 -0
  64. package/src/parts/InstallExtension/InstallExtension.ipc.js +6 -0
  65. package/src/parts/InstallExtension/InstallExtension.js +33 -0
  66. package/src/parts/IpcParent/IpcParent.js +9 -0
  67. package/src/parts/IpcParentModule/IpcParentModule.js +12 -0
  68. package/src/parts/IpcParentType/IpcParentType.js +2 -0
  69. package/src/parts/IpcParentWithNodeForkedProcess/IpcParentWithNodeForkedProcess.js +49 -0
  70. package/src/parts/IpcParentWithNodeWorker/IpcParentWithNodeWorker.js +36 -0
  71. package/src/parts/IsEnoentErrorWindows/IsEnoentErrorWindows.js +3 -0
  72. package/src/parts/IsIgnoredError/IsIgnoredError.js +14 -0
  73. package/src/parts/Json/Json.js +3 -5
  74. package/src/parts/JsonError/JsonError.js +8 -14
  75. package/src/parts/JsonParsingError/JsonParsingError.js +17 -0
  76. package/src/parts/Jsonc/Jsonc.js +304 -0
  77. package/src/parts/JsoncCharCode/JsoncCharCode.js +23 -0
  78. package/src/parts/JsoncFile/JsoncFile.js +8 -0
  79. package/src/parts/JsoncTokenType/JsoncTokenType.js +11 -0
  80. package/src/parts/LimitString/LimitString.js +3 -1
  81. package/src/parts/MergeStacks/MergeStacks.js +3 -2
  82. package/src/parts/Module/Module.js +4 -0
  83. package/src/parts/ModuleId/ModuleId.js +2 -0
  84. package/src/parts/ModuleMap/ModuleMap.js +4 -0
  85. package/src/parts/Native/Native.js +1 -1
  86. package/src/parts/ParentIpc/ParentIpc.js +2 -1
  87. package/src/parts/Platform/Platform.js +0 -21
  88. package/src/parts/Preferences/Preferences.js +6 -8
  89. package/src/parts/PrettyError/PrettyError.js +16 -7
  90. package/src/parts/PrintPrettyError/PrintPrettyError.js +3 -1
  91. package/src/parts/RecentlyOpened/RecentlyOpened.js +3 -7
  92. package/src/parts/RequiresSocket/RequiresSocket.js +1 -0
  93. package/src/parts/RipGrep/RipGrep.js +1 -1
  94. package/src/parts/SearchFile/SearchFile.js +4 -9
  95. package/src/parts/Socket/Socket.js +2 -7
  96. package/src/parts/Terminal/Terminal.ipc.js +4 -41
  97. package/src/parts/Terminal/Terminal.js +29 -25
  98. package/src/parts/TextSearch/TextSearch.js +102 -108
  99. package/src/parts/ToAbsolutePaths/ToAbsolutePaths.js +9 -0
  100. package/src/parts/ToTextSearchResult/ToTextSearchResult.js +42 -0
  101. package/src/parts/Trash/Trash.js +1 -2
  102. /package/src/parts/{RgPath/RgPath.js → RipGrepPath/RipGrepPath.js} +0 -0
@@ -1,10 +1,10 @@
1
- import VError from 'verror'
2
1
  import * as Assert from '../Assert/Assert.js'
3
2
  import * as Download from '../Download/Download.js'
4
3
  import * as ExtractZip from '../ExtractZip/ExtractZip.js'
5
4
  import * as FileSystem from '../FileSystem/FileSystem.js'
6
5
  import * as Path from '../Path/Path.js'
7
6
  import * as Platform from '../Platform/Platform.js'
7
+ import { VError } from '../VError/VError.js'
8
8
 
9
9
  const getExtensionPath = async (tmpDir) => {
10
10
  const dirents = await FileSystem.readDirWithFileTypes(tmpDir)
@@ -19,10 +19,7 @@ export const install = async (name, url) => {
19
19
  Assert.string(name)
20
20
  Assert.string(url)
21
21
  const cachedChromeExtensionsPath = Platform.getCachedExtensionsPath()
22
- const tempFileCompressed = Path.join(
23
- cachedChromeExtensionsPath,
24
- `${name}.zip`
25
- )
22
+ const tempFileCompressed = Path.join(cachedChromeExtensionsPath, `${name}.zip`)
26
23
  const tmpDir = Path.join(cachedChromeExtensionsPath, name)
27
24
  const chromeExtensionsPath = Platform.getChromeExtensionsPath()
28
25
  await Download.download(url, tempFileCompressed)
@@ -1,5 +1,93 @@
1
- import npmCleanStack from 'clean-stack'
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
+
11
+ const isInternalLine = (line) => {
12
+ return line.includes('node:') || RE_AT_PROMISE_INDEX.test(line) || line.includes('node_modules/ws')
13
+ }
14
+
15
+ const isRelevantLine = (line) => {
16
+ return !isInternalLine(line)
17
+ }
18
+
19
+ const isApplicationUsefulLine = (line, index) => {
20
+ if (index === 0) {
21
+ return true
22
+ }
23
+ if (RE_GET_RESPONSE.test(line)) {
24
+ return false
25
+ }
26
+ if (RE_WEBSOCKET_HANDLE_MESSAGE.test(line)) {
27
+ return false
28
+ }
29
+ if (RE_EXECUTE_COMMAND_ASYNC.test(line)) {
30
+ return false
31
+ }
32
+ if (RE_HANDLE_OTHER_MESSAGES_FROM_MESSAGE_PORT.test(line)) {
33
+ return false
34
+ }
35
+ return true
36
+ }
37
+
38
+ const isNormalStackLine = (line) => {
39
+ return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line)
40
+ }
41
+
42
+ const cleanLine = (line) => {
43
+ if (line.startsWith(' at exports.')) {
44
+ return ' at ' + line.slice(' at exports.'.length)
45
+ }
46
+ if (line.startsWith(' at async exports.')) {
47
+ return ' at async ' + line.slice(' at async exports.'.length)
48
+ }
49
+ if (line.startsWith(' at async Module.')) {
50
+ return ' at async ' + line.slice(' at async Module.'.length)
51
+ }
52
+ if (line.startsWith(' at Module.')) {
53
+ return ' at ' + line.slice(' at Module.'.length)
54
+ }
55
+ const objectMatch = line.match(RE_OBJECT_AS)
56
+ if (objectMatch) {
57
+ const rest = line.slice(objectMatch[0].length)
58
+ if (objectMatch[1]) {
59
+ return ' at ' + objectMatch[1] + objectMatch[2] + rest
60
+ }
61
+ return ' at ' + objectMatch[2] + rest
62
+ }
63
+ return line
64
+ }
65
+
66
+ const getDetails = (lines) => {
67
+ const index = lines.findIndex(isNormalStackLine)
68
+ return {
69
+ custom: lines.slice(0, index),
70
+ actualStack: lines.slice(index).map(cleanLine),
71
+ }
72
+ }
73
+
74
+ const RE_PATH_1 = /^\/(.*)(\d+)$/
75
+
76
+ const mergeCustom = (custom, relevantStack) => {
77
+ if (custom.length === 0) {
78
+ return relevantStack
79
+ }
80
+ const firstLine = custom[0]
81
+ if (RE_PATH_1.test(firstLine)) {
82
+ return [` at ${firstLine}`, ...relevantStack]
83
+ }
84
+ return relevantStack
85
+ }
2
86
 
3
87
  export const cleanStack = (stack) => {
4
- return npmCleanStack(stack)
88
+ const lines = SplitLines.splitLines(stack)
89
+ const { custom, actualStack } = getDetails(lines)
90
+ const relevantStack = actualStack.filter(isRelevantLine).filter(isApplicationUsefulLine)
91
+ const merged = mergeCustom(custom, relevantStack)
92
+ return merged
5
93
  }
@@ -3,6 +3,9 @@ import * as JoinLines from '../JoinLines/JoinLines.js'
3
3
  import * as Logger from '../Logger/Logger.js'
4
4
 
5
5
  const getOutputLine = (extension) => {
6
+ if (extension.symlink) {
7
+ return `${extension.id} -> ${extension.symlink}`
8
+ }
6
9
  return `${extension.id}: ${extension.version}`
7
10
  }
8
11
 
@@ -1,8 +1,8 @@
1
- import * as Platform from '../Platform/Platform.js'
1
+ import * as Desktop from '../Desktop/Desktop.js'
2
2
  import * as DesktopType from '../DesktopType/DesktopType.js'
3
3
 
4
4
  const getClipboard = () => {
5
- const desktop = Platform.getDesktop()
5
+ const desktop = Desktop.getDesktop()
6
6
  switch (desktop) {
7
7
  case DesktopType.Gnome:
8
8
  return import('./ClipBoardGnome.js')
@@ -2,10 +2,10 @@
2
2
  // see also http://manpages.ubuntu.com/manpages/bionic/man1/xclip.1.html
3
3
  // on gnome, get current selection targets with `xclip -selection clipboard -t TARGETS -o`
4
4
 
5
- import VError from 'verror'
6
5
  import * as Exec from '../Exec/Exec.js'
7
6
  import * as JoinLines from '../JoinLines/JoinLines.js'
8
7
  import * as SplitLines from '../SplitLines/SplitLines.js'
8
+ import { VError } from '../VError/VError.js'
9
9
 
10
10
  const removePrefix = (file) => {
11
11
  if (file.startsWith('file://')) {
@@ -57,7 +57,6 @@ export const writeFiles = async (type, files) => {
57
57
  input: plainContent,
58
58
  })
59
59
  } catch (error) {
60
- // @ts-ignore
61
60
  throw new VError(error, 'Failed to copy files to clipboard')
62
61
  }
63
62
  }
@@ -1,4 +1,4 @@
1
- import * as Platform from '../Platform/Platform.js'
1
+ import * as Desktop from '../Desktop/Desktop.js'
2
2
 
3
3
  export const readFiles = async () => {
4
4
  return {
@@ -9,6 +9,6 @@ export const readFiles = async () => {
9
9
  }
10
10
 
11
11
  export const writeFiles = (type, files) => {
12
- const desktop = Platform.getDesktop()
12
+ const desktop = Desktop.getDesktop()
13
13
  console.info(`writing files to clipboard is not yet supported on ${desktop}`)
14
14
  }
@@ -1,6 +1,5 @@
1
1
  import clipboardEx from 'electron-clipboard-ex'
2
-
3
- import VError from 'verror'
2
+ import { VError } from '../VError/VError.js'
4
3
 
5
4
  export const readFiles = async () => {
6
5
  const filePaths = clipboardEx.readFilePaths()
@@ -16,7 +15,6 @@ export const writeFiles = async (type, files) => {
16
15
  try {
17
16
  clipboardEx.writeFilePaths(files)
18
17
  } catch (error) {
19
- // @ts-ignore
20
18
  throw new VError(error, 'Failed to copy files to clipboard')
21
19
  }
22
20
  }
@@ -1,3 +1,4 @@
1
+ import { CommandNotFoundError } from '../CommandNotFoundError/CommandNotFoundError.js'
1
2
  import * as ModuleMap from '../ModuleMap/ModuleMap.js'
2
3
  import { VError } from '../VError/VError.js'
3
4
 
@@ -19,9 +20,7 @@ const initializeModule = (module) => {
19
20
  }
20
21
  return
21
22
  }
22
- throw new Error(
23
- `module ${module.name} is missing an initialize function and commands`
24
- )
23
+ throw new Error(`module ${module.name} is missing an initialize function and commands`)
25
24
  }
26
25
 
27
26
  const loadModule = async (moduleId) => {
@@ -29,11 +28,7 @@ const loadModule = async (moduleId) => {
29
28
  const module = await state.load(moduleId)
30
29
  initializeModule(module)
31
30
  } catch (error) {
32
- if (
33
- error &&
34
- error instanceof SyntaxError &&
35
- error.stack === `SyntaxError: ${error.message}`
36
- ) {
31
+ if (error && error instanceof SyntaxError && error.stack === `SyntaxError: ${error.message}`) {
37
32
  Error.captureStackTrace(error, loadModule)
38
33
  }
39
34
  throw new VError(error, `failed to load module ${moduleId}`)
@@ -68,9 +63,9 @@ const executeCommandAsync = async (command, ...args) => {
68
63
  return
69
64
  }
70
65
  hasThrown.add(command)
71
- throw new Error(`Command did not register "${command}"`)
66
+ throw new CommandNotFoundError(command)
72
67
  }
73
- return execute(command, ...args)
68
+ return state.commands[command](...args)
74
69
  }
75
70
 
76
71
  export const execute = (command, ...args) => {
@@ -1,9 +1,9 @@
1
1
  import * as Credentials from './Credentials.js'
2
2
 
3
3
  export const Commands = {
4
- 801: Credentials.getPassword,
5
- 802: Credentials.setPassword,
6
- 803: Credentials.deletePassword,
7
- 804: Credentials.findPassword,
8
- 805: Credentials.findCredentials,
4
+ getPassword: Credentials.getPassword,
5
+ setPassword: Credentials.setPassword,
6
+ deletePassword: Credentials.deletePassword,
7
+ findPassword: Credentials.findPassword,
8
+ findCredentials: Credentials.findCredentials,
9
9
  }
@@ -1,5 +1,5 @@
1
1
  import keytar from 'keytar'
2
- import VError from 'verror'
2
+ import { VError } from '../VError/VError.js'
3
3
 
4
4
  /**
5
5
  * @param {string} service
@@ -9,7 +9,6 @@ export const deletePassword = async (service, account) => {
9
9
  try {
10
10
  return await keytar.deletePassword(service, account)
11
11
  } catch (error) {
12
- // @ts-ignore
13
12
  throw new VError(error, `Failed to delete password from service ${service}`)
14
13
  }
15
14
  }
@@ -21,11 +20,7 @@ export const findCredentials = async (service) => {
21
20
  try {
22
21
  return keytar.findCredentials(service)
23
22
  } catch (error) {
24
- throw new VError(
25
- // @ts-ignore
26
- error,
27
- `Failed to find credentials from service ${service}`
28
- )
23
+ throw new VError(error, `Failed to find credentials from service ${service}`)
29
24
  }
30
25
  }
31
26
 
@@ -36,7 +31,6 @@ export const findPassword = async (service) => {
36
31
  try {
37
32
  return await keytar.findPassword(service)
38
33
  } catch (error) {
39
- // @ts-ignore
40
34
  throw new VError(error, `Failed to find password from service ${service}`)
41
35
  }
42
36
  }
@@ -49,7 +43,6 @@ export const getPassword = async (service, account) => {
49
43
  try {
50
44
  return await keytar.getPassword(service, account)
51
45
  } catch (error) {
52
- // @ts-ignore
53
46
  throw new VError(error, `Failed to get password from service ${service}`)
54
47
  }
55
48
  }
@@ -63,7 +56,6 @@ export const setPassword = async (service, account, password) => {
63
56
  try {
64
57
  return await keytar.setPassword(service, account, password)
65
58
  } catch (error) {
66
- // @ts-ignore
67
59
  throw new VError(error, `Failed to set password for service ${service}`)
68
60
  }
69
61
  }
@@ -0,0 +1,22 @@
1
+ import * as DesktopType from '../DesktopType/DesktopType.js'
2
+ import * as Platform from '../Platform/Platform.js'
3
+
4
+ export const getDesktop = () => {
5
+ const { ORIGINAL_XDG_CURRENT_DESKTOP, XDG_CURRENT_DESKTOP } = process.env
6
+ if (ORIGINAL_XDG_CURRENT_DESKTOP && ORIGINAL_XDG_CURRENT_DESKTOP !== 'undefined') {
7
+ if (ORIGINAL_XDG_CURRENT_DESKTOP === 'ubuntu:GNOME') {
8
+ return DesktopType.Gnome
9
+ }
10
+ return ORIGINAL_XDG_CURRENT_DESKTOP
11
+ }
12
+ if (XDG_CURRENT_DESKTOP) {
13
+ if (XDG_CURRENT_DESKTOP === 'ubuntu:GNOME') {
14
+ return DesktopType.Gnome
15
+ }
16
+ return XDG_CURRENT_DESKTOP
17
+ }
18
+ if (Platform.isWindows) {
19
+ return DesktopType.Windows
20
+ }
21
+ return DesktopType.Unknown
22
+ }
@@ -1,9 +1,9 @@
1
+ import got, { RequestError } from 'got'
1
2
  import { createWriteStream } from 'node:fs'
2
3
  import { mkdir, rm } from 'node:fs/promises'
3
4
  import { pipeline } from 'node:stream/promises'
4
- import got, { RequestError } from 'got'
5
- import VError from 'verror'
6
5
  import * as Path from '../Path/Path.js'
6
+ import { VError } from '../VError/VError.js'
7
7
 
8
8
  export const download = async (url, outFile) => {
9
9
  try {
@@ -1,4 +1,4 @@
1
- import VError from 'verror'
1
+ import { VError } from '../VError/VError.js'
2
2
 
3
3
  /**
4
4
  *
@@ -1,6 +1,8 @@
1
1
  export const E_COLOR_THEME_NOT_FOUND = 'E_COLOR_THEME_NOT_FOUND'
2
+ export const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND'
2
3
  export const E_ICON_THEME_NOT_FOUND = 'E_ICON_THEME_NOT_FOUND'
3
4
  export const E_MANIFEST_NOT_FOUND = 'E_MANIFEST_NOT_FOUND'
5
+ export const EACCES = 'EACCES'
4
6
  export const ECONNRESET = 'ECONNRESET'
5
7
  export const EEXIST = 'EEXIST'
6
8
  export const EISDIR = 'EISDIR'
@@ -12,4 +14,3 @@ export const EPIPE = 'EPIPE'
12
14
  export const ERR_IPC_CHANNEL_CLOSED = 'ERR_IPC_CHANNEL_CLOSED'
13
15
  export const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND'
14
16
  export const EXDEV = 'EXDEV'
15
- export const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND'
@@ -1,9 +1,11 @@
1
- import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
2
1
  import * as ExitCode from '../ExitCode/ExitCode.js'
2
+ import * as IsIgnoredError from '../IsIgnoredError/IsIgnoredError.js'
3
3
  import * as JsonRpcVersion from '../JsonRpcVersion/JsonRpcVersion.js'
4
+ import * as Logger from '../Logger/Logger.js'
4
5
  import * as PrettyError from '../PrettyError/PrettyError.js'
5
6
  import * as Process from '../Process/Process.js'
6
7
  import * as Socket from '../Socket/Socket.js'
8
+ import * as GetNewLineIndex from '../GetNewLineIndex/GetNewLineIndex.js'
7
9
 
8
10
  export const state = {
9
11
  seenErrors: [],
@@ -48,7 +50,7 @@ export const handleError = (error) => {
48
50
 
49
51
  const firstErrorLine = (error) => {
50
52
  if (error.stack) {
51
- return error.stack.slice(0, error.stack.indexOf('\n'))
53
+ return error.stack.slice(0, GetNewLineIndex.getNewLineIndex(error.stack))
52
54
  }
53
55
  if (error.message) {
54
56
  return error.message
@@ -57,19 +59,11 @@ const firstErrorLine = (error) => {
57
59
  }
58
60
 
59
61
  export const handleUncaughtExceptionMonitor = (error, origin) => {
60
- console.info(`[shared process] uncaught exception: ${firstErrorLine(error)}`)
61
- if (error && error.code === ErrorCodes.EPIPE && !process.connected) {
62
- // parent process is disposed, ignore
62
+ Logger.info(`[shared process] uncaught exception: ${firstErrorLine(error)}`)
63
+ if (IsIgnoredError.isIgnoredError(error)) {
63
64
  return
64
65
  }
65
- if (error && error.code === ErrorCodes.ERR_IPC_CHANNEL_CLOSED && !Process.isConnected()) {
66
- // parent process is disposed, ignore
67
- return
68
- }
69
- // console.log(error)
70
66
  const prettyError = PrettyError.prepare(error)
71
- // console.error(prettyError.message)
72
- console.error(prettyError.codeFrame)
73
- console.error(prettyError.stack)
74
- Process.exit(ExitCode.Error)
67
+ Logger.error(prettyError.codeFrame + '\n' + prettyError.stack + '\n')
68
+ Process.setExitCode(ExitCode.Error)
75
69
  }
@@ -1,10 +1,10 @@
1
- import VError from 'verror'
2
1
  import * as Assert from '../Assert/Assert.js'
3
2
  import * as Callback from '../Callback/Callback.js'
4
3
  import * as ExtensionHostIpc from '../ExtensionHostIpc/ExtensionHostIpc.js'
5
4
  import * as ExtensionHostRpc from '../ExtensionHostRpc/ExtensionHostRpc.js'
6
5
  import * as JsonRpc from '../JsonRpc/JsonRpc.js'
7
6
  import * as JsonRpcVersion from '../JsonRpcVersion/JsonRpcVersion.js'
7
+ import { VError } from '../VError/VError.js'
8
8
 
9
9
  // TODO maybe rename to extension host management for clarity
10
10
 
@@ -41,7 +41,6 @@ export const start = async (socket) => {
41
41
  state.extensionHosts[id] = extensionHost
42
42
  return id
43
43
  } catch (error) {
44
- // @ts-ignore
45
44
  throw new VError(error, 'Failed to start extension host')
46
45
  }
47
46
  }
@@ -1,16 +1,4 @@
1
- import VError from 'verror'
2
- import * as Callback from '../Callback/Callback.js'
3
- import * as ChildProcess from '../ChildProcess/ChildProcess.js'
4
- import * as Debug from '../Debug/Debug.js'
5
- import * as Error from '../Error/Error.js'
6
1
  import * as ExtensionManagement from '../ExtensionManagement/ExtensionManagement.js'
7
- import * as ReadJson from '../JsonFile/JsonFile.js'
8
- import * as JsonRpc from '../JsonRpc/JsonRpc.js'
9
- import * as Path from '../Path/Path.js'
10
- import * as Root from '../Root/Root.js'
11
- import * as Socket from '../Socket/Socket.js'
12
- import * as TextDocument from '../TextDocument/TextDocument.js'
13
- import * as Platform from '../Platform/Platform.js'
14
2
 
15
3
  const getExtensionKeyBindings = (extension) => {
16
4
  return extension.keyBindings || []
@@ -1,6 +1,6 @@
1
- import VError from 'verror'
2
1
  import * as Assert from '../Assert/Assert.js'
3
2
  import * as Timeout from '../Timeout/Timeout.js'
3
+ import { VError } from '../VError/VError.js'
4
4
 
5
5
  // TODO maybe rename to extension host management for clarity
6
6
 
@@ -1,9 +1,9 @@
1
- import VError from 'verror'
2
1
  import * as Extract from '../Extract/Extract.js'
3
2
  import * as FileSystem from '../FileSystem/FileSystem.js'
4
3
  import * as JsonFile from '../JsonFile/JsonFile.js'
5
4
  import * as Path from '../Path/Path.js'
6
5
  import * as Platform from '../Platform/Platform.js'
6
+ import { VError } from '../VError/VError.js'
7
7
 
8
8
  const getCachedExtensionFolderName = (path) => {
9
9
  const baseName = Path.basename(path)
@@ -1,9 +1,9 @@
1
- import VError from 'verror'
2
1
  import * as DownloadAndExtract from '../DownloadAndExtract/DownloadAndExtract.js'
3
2
  import * as FileSystem from '../FileSystem/FileSystem.js'
4
3
  import * as JsonFile from '../JsonFile/JsonFile.js'
5
4
  import * as Path from '../Path/Path.js'
6
5
  import * as Platform from '../Platform/Platform.js'
6
+ import { VError } from '../VError/VError.js'
7
7
 
8
8
  export const install = async ({ user, repo, branch }) => {
9
9
  try {
@@ -1,11 +1,11 @@
1
1
  import { rename, rm } from 'node:fs/promises'
2
2
  import { join } from 'node:path'
3
- import VError from 'verror'
4
3
  import * as Download from '../Download/Download.js'
5
4
  import * as Extract from '../Extract/Extract.js'
6
5
  import * as JsonFile from '../JsonFile/JsonFile.js'
7
6
  import * as Platform from '../Platform/Platform.js'
8
7
  import * as TmpFile from '../TmpFile/TmpFile.js'
8
+ import { VError } from '../VError/VError.js'
9
9
 
10
10
  export const install = async ({ url }) => {
11
11
  try {
@@ -23,22 +23,6 @@ const linkFallBack = async (path) => {
23
23
  }
24
24
  }
25
25
 
26
- const linkMonoRepo = async (path, error) => {
27
- try {
28
- const monoRepoPath = Path.join(path, 'packages', 'extension')
29
- const manifest = await ExtensionManifest.get(monoRepoPath)
30
- if (manifest.status === ExtensionManifestStatus.Rejected) {
31
- throw manifest.reason
32
- }
33
- const linkedExtensionsPath = Platform.getLinkedExtensionsPath()
34
- // @ts-ignore
35
- const to = Path.join(linkedExtensionsPath, manifest.id)
36
- await SymLink.createSymLink(monoRepoPath, to)
37
- } catch {
38
- throw error
39
- }
40
- }
41
-
42
26
  export const link = async (path) => {
43
27
  try {
44
28
  const manifest = await ExtensionManifest.get(path)
@@ -53,9 +37,6 @@ export const link = async (path) => {
53
37
  if (error && error.code === ErrorCodes.EEXIST) {
54
38
  return linkFallBack(path)
55
39
  }
56
- if (error && error.code === ErrorCodes.E_MANIFEST_NOT_FOUND) {
57
- await linkMonoRepo(path, new VError(error, `Failed to link extension`))
58
- }
59
40
  throw new VError(error, `Failed to link extension`)
60
41
  }
61
42
  }
@@ -1,9 +1,9 @@
1
1
  import { basename } from 'node:path'
2
- import VError from 'verror'
3
2
  import * as ExtensionManifestInputType from '../ExtensionManifestInputType/ExtensionManifestInputType.js'
4
3
  import * as ExtensionManifests from '../ExtensionManifests/ExtensionManifests.js'
5
4
  import * as Platform from '../Platform/Platform.js'
6
5
  import * as ExtensionManifestStatus from '../ExtensionManifestStatus/ExtensionManifestStatus.js'
6
+ import { VError } from '../VError/VError.js'
7
7
 
8
8
  const getManifestVersion = (json) => {
9
9
  if (json && json.version && typeof json.version === 'string') {
@@ -19,12 +19,21 @@ const getManifestId = (json) => {
19
19
  return basename(json.path)
20
20
  }
21
21
 
22
+ const getSymlink = (json) => {
23
+ if (json && json.symlink && typeof json.symlink === 'string') {
24
+ return json.symlink
25
+ }
26
+ return ''
27
+ }
28
+
22
29
  const getManifestInfo = (json) => {
23
30
  const id = getManifestId(json)
24
31
  const version = getManifestVersion(json)
32
+ const symlink = getSymlink(json)
25
33
  return {
26
34
  id,
27
35
  version,
36
+ symlink,
28
37
  }
29
38
  }
30
39
 
@@ -41,7 +50,7 @@ export const list = async () => {
41
50
  try {
42
51
  const manifests = await ExtensionManifests.getAll([
43
52
  {
44
- type: ExtensionManifestInputType.Folder,
53
+ type: ExtensionManifestInputType.LinkedExtensionsFolder,
45
54
  path: Platform.getLinkedExtensionsPath(),
46
55
  },
47
56
  {
@@ -1,58 +1,10 @@
1
- import { mkdir, rename, rm } from 'node:fs/promises'
2
- import { VError } from '../VError/VError.js'
1
+ import { mkdir, rename } from 'node:fs/promises'
3
2
  import * as Debug from '../Debug/Debug.js'
4
3
  import * as ExtensionManifestInputType from '../ExtensionManifestInputType/ExtensionManifestInputType.js'
5
4
  import * as ExtensionManifests from '../ExtensionManifests/ExtensionManifests.js'
6
5
  import * as Path from '../Path/Path.js'
7
6
  import * as Platform from '../Platform/Platform.js'
8
- import * as Queue from '../Queue/Queue.js'
9
-
10
- export const install = async (id) => {
11
- // TODO this should be a stateless function, renderer-worker should have info on marketplace url
12
- // TODO use command.execute
13
- try {
14
- const { download } = await import('../Download/Download.js')
15
- const { extractTarBr } = await import('../Extract/Extract.js')
16
- const marketplaceUrl = Platform.getMarketplaceUrl()
17
- Debug.debug(`ExtensionManagement#install ${id}`)
18
- const cachedExtensionsPath = Platform.getCachedExtensionsPath()
19
- const extensionsPath = Platform.getExtensionsPath()
20
- // TODO maybe a queue is over engineering here
21
- await Queue.add('download', async () => {
22
- Debug.debug(`ExtensionManagement#download ${id}`)
23
- // TODO use command.execute
24
- await download(
25
- `${marketplaceUrl}/download/${id}`,
26
- Path.join(cachedExtensionsPath, `${id}.tar.br`)
27
- )
28
- Debug.debug(`ExtensionManagement#extract ${id}`)
29
- await extractTarBr(
30
- Path.join(cachedExtensionsPath, `${id}.tar.br`),
31
- Path.join(extensionsPath, id)
32
- )
33
- })
34
- // TODO should this be here? (probably not)
35
- // await ExtensionHost.enableExtension({
36
- // id,
37
- // type: 'marketplace',
38
- // })
39
- } catch (error) {
40
- throw new VError(error, `Failed to install extension "${id}"`)
41
- }
42
- }
43
-
44
- export const uninstall = async (id) => {
45
- try {
46
- Debug.debug(`ExtensionManagement#uninstall ${id}`)
47
- const extensionsPath = Platform.getExtensionsPath()
48
- await rm(Path.join(extensionsPath, id), { recursive: true })
49
- } catch (error) {
50
- // if (error.code === 'ENOENT') {
51
- // return
52
- // }
53
- throw new VError(error, `Failed to uninstall extension "${id}"`)
54
- }
55
- }
7
+ import { VError } from '../VError/VError.js'
56
8
 
57
9
  export const enable = async (id) => {
58
10
  try {
@@ -60,10 +12,7 @@ export const enable = async (id) => {
60
12
  const extensionsPath = Platform.getExtensionsPath()
61
13
  const disabledExtensionsPath = Platform.getDisabledExtensionsPath()
62
14
  await mkdir(extensionsPath, { recursive: true })
63
- await rename(
64
- Path.join(disabledExtensionsPath, id),
65
- Path.join(extensionsPath, id)
66
- )
15
+ await rename(Path.join(disabledExtensionsPath, id), Path.join(extensionsPath, id))
67
16
  } catch (error) {
68
17
  throw new VError(error, `Failed to enable extension "${id}"`)
69
18
  }
@@ -75,10 +24,7 @@ export const disable = async (id) => {
75
24
  const disabledExtensionsPath = Platform.getDisabledExtensionsPath()
76
25
  const extensionsPath = Platform.getExtensionsPath()
77
26
  await mkdir(disabledExtensionsPath, { recursive: true })
78
- await rename(
79
- Path.join(extensionsPath, id),
80
- Path.join(disabledExtensionsPath, id)
81
- )
27
+ await rename(Path.join(extensionsPath, id), Path.join(disabledExtensionsPath, id))
82
28
  } catch (error) {
83
29
  throw new VError(error, `Failed to disable extension ${id}`)
84
30
  }
@@ -131,3 +77,5 @@ export const getDisabledExtensions = () => {
131
77
  },
132
78
  ])
133
79
  }
80
+
81
+ export * from '../ExtensionUninstall/ExtensionUninstall.js'