@lvce-editor/shared-process 0.15.1 → 0.15.2

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.15.1",
3
+ "version": "0.15.2",
4
4
  "description": "Utility package for @lvce-editor/server",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -17,9 +17,9 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@babel/code-frame": "^7.21.4",
20
- "@lvce-editor/extension-host": "0.15.1",
21
- "@lvce-editor/extension-host-helper-process": "0.15.1",
22
- "@lvce-editor/pty-host": "0.15.1",
20
+ "@lvce-editor/extension-host": "0.15.2",
21
+ "@lvce-editor/extension-host-helper-process": "0.15.2",
22
+ "@lvce-editor/pty-host": "0.15.2",
23
23
  "debug": "^4.3.4",
24
24
  "execa": "^7.1.1",
25
25
  "exit-hook": "^3.2.0",
@@ -1,7 +1,19 @@
1
+ import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
2
+ import * as ExitCode from '../ExitCode/ExitCode.js'
1
3
  import * as ExtensionUnlink from '../ExtensionUnlink/ExtensionUnlink.js'
4
+ import * as Logger from '../Logger/Logger.js'
2
5
  import * as Process from '../Process/Process.js'
3
6
 
4
7
  export const handleCliArgs = async (argv) => {
5
- const path = argv.length > 1 ? argv[1] : Process.cwd()
6
- await ExtensionUnlink.unlink(path)
8
+ try {
9
+ const path = argv.length > 1 ? argv[1] : Process.cwd()
10
+ await ExtensionUnlink.unlink(path)
11
+ } catch (error) {
12
+ if (error && error.code === ErrorCodes.E_MANIFEST_NOT_FOUND) {
13
+ Logger.error(error.message)
14
+ Process.setExitCode(ExitCode.ExpectedError)
15
+ return
16
+ }
17
+ throw error
18
+ }
7
19
  }
@@ -24,6 +24,7 @@ export const install = async ({ user, repo, branch }) => {
24
24
  }
25
25
  const outDir = Path.join(extensionsPath, id)
26
26
  await FileSystem.remove(outDir)
27
+ await FileSystem.mkdir(extensionsPath)
27
28
  await FileSystem.rename(cachedExtensionPath, outDir)
28
29
  } catch (error) {
29
30
  throw new VError(error, `Failed to install ${user}/${repo}`)
@@ -1,12 +1,8 @@
1
1
  import * as Assert from '../Assert/Assert.js'
2
- import * as Command from '../Command/Command.js'
3
2
  import * as JsonRpcVersion from '../JsonRpcVersion/JsonRpcVersion.js'
3
+ import * as OutputChannelState from '../OutputChannelState/OutputChannelState.js'
4
4
  import * as OutputChannel from './OutputChannel.js'
5
5
 
6
- export const state = {
7
- outputChannels: Object.create(null),
8
- }
9
-
10
6
  const open = (socket, id, path) => {
11
7
  console.log({ path })
12
8
  Assert.object(socket)
@@ -16,31 +12,32 @@ const open = (socket, id, path) => {
16
12
  console.warn('socket not available')
17
13
  return
18
14
  }
19
- if (state.outputChannels[id]) {
20
- OutputChannel.dispose(state.outputChannels[id])
15
+ if (OutputChannelState.has(id)) {
16
+ OutputChannel.dispose(OutputChannelState.get(id))
21
17
  }
22
18
  const onData = (data) => {
23
19
  console.log('send data', data)
24
20
  socket.send({
25
21
  jsonrpc: JsonRpcVersion.Two,
26
- method: 2133,
27
- params: ['Output', 'handleData', data],
22
+ method: 'Output.handleData',
23
+ params: [data],
28
24
  })
29
25
  }
30
26
  const onError = (error) => {
31
27
  console.info(`[shared process] output channel error: ${error}`)
32
28
  socket.send({
33
29
  jsonrpc: JsonRpcVersion.Two,
34
- method: 2133,
35
- params: ['Output', 'handleError', error],
30
+ method: 'Output.handleError',
31
+ params: [error],
36
32
  })
37
33
  }
38
- state.outputChannels[id] = OutputChannel.open(path, onData, onError)
34
+ const outputChannel = OutputChannel.open(path, onData, onError)
35
+ OutputChannelState.set(id, outputChannel)
39
36
  }
40
37
 
41
38
  const close = (socket, id) => {
42
- OutputChannel.dispose(state.outputChannels[id])
43
- delete state.outputChannels[id]
39
+ OutputChannel.dispose(OutputChannelState.get(id))
40
+ OutputChannelState.remove(id)
44
41
  }
45
42
 
46
43
  export const name = 'OutputChannel'
@@ -0,0 +1,19 @@
1
+ export const state = {
2
+ outputChannels: Object.create(null),
3
+ }
4
+
5
+ export const set = (id, channel) => {
6
+ state.outputChannels[id] = channel
7
+ }
8
+
9
+ export const get = (id) => {
10
+ return state.outputChannels[id]
11
+ }
12
+
13
+ export const remove = (id) => {
14
+ delete state.outputChannels[id]
15
+ }
16
+
17
+ export const has = (id) => {
18
+ return id in state.outputChannels
19
+ }