@lvce-editor/shared-process 0.22.7 → 0.23.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.
- package/package.json +4 -3
- package/src/parts/IpcChildWithElectronUtilityProcess/IpcChildWithElectronUtilityProcess.js +1 -45
- package/src/parts/IpcChildWithWebSocket/IpcChildWithWebSocket.js +1 -59
- package/src/parts/IpcParentWithNodeForkedProcess/IpcParentWithNodeForkedProcess.js +1 -53
- package/src/parts/Platform/Platform.js +3 -3
- package/src/parts/AppWindowStates/AppWindowStates.js +0 -62
- package/src/parts/ChildProcess/ChildProcessWithFork.js +0 -19
- package/src/parts/ChildProcessError/ChildProcessError.js +0 -21
- package/src/parts/Configuration/Configuration.ipc.js +0 -6
- package/src/parts/Configuration/Configuration.js +0 -36
- package/src/parts/CreateCpuProfile/CreateCpuProfile.js +0 -59
- package/src/parts/Credentials/Credentials.ipc.js +0 -9
- package/src/parts/Credentials/Credentials.js +0 -61
- package/src/parts/DevtoolsProtocolRpc/DevtoolsProtocolRpc.js +0 -32
- package/src/parts/ErrorType/ErrorType.js +0 -4
- package/src/parts/ExtensionHostIpcWithWorker/ExtensionHostIpcWithWorker.js +0 -34
- package/src/parts/FirstWebSocketEventType/FirstWebSocketEventType.js +0 -2
- package/src/parts/GetActualPath/GetActualPath.js +0 -8
- package/src/parts/GetErrorConstructor/GetErrorConstructor.js +0 -28
- package/src/parts/GetFirstNodeChildProcessEvent/GetFirstNodeChildProcessEvent.js +0 -41
- package/src/parts/GetFirstWebSocketEvent/GetFirstWebSocketEvent.js +0 -25
- package/src/parts/GetHelpfulChildProcessError/GetHelpfulChildProcessError.js +0 -119
- package/src/parts/GetUtilityProcessPortData/GetUtilityProcessPortData.js +0 -10
- package/src/parts/Header/Header.js +0 -1
- package/src/parts/IsSocket/IsSocket.js +0 -5
- package/src/parts/IsWebSocketOpen/IsWebSocketOpen.js +0 -5
- package/src/parts/JsonParsingError/JsonParsingError.js +0 -19
- package/src/parts/MergeStacks/MergeStacks.js +0 -20
- package/src/parts/NormalizeErrorLine/NormalizeErrorLine.js +0 -9
- package/src/parts/PassThroughElectronMessageForTerminalProcess/PassThroughElectronMessageForTerminalProcess.js +0 -29
- package/src/parts/PassThroughElectronMessagePort/PassThroughElectronMessagePort.ipc.js +0 -7
- package/src/parts/PassThroughElectronMessagePort/PassThroughElectronMessagePort.js +0 -4
- package/src/parts/PassThroughElectronMessagePortModule/PassThroughElectronMessagePortModule.js +0 -8
- package/src/parts/WebSocketReadyState/WebSocketReadyState.js +0 -5
- package/src/parts/WebSocketSerialization/WebSocketSerialization.js +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/shared-process",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -18,11 +18,12 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@lvce-editor/assert": "^1.2.0",
|
|
21
|
-
"@lvce-editor/extension-host-helper-process": "0.
|
|
21
|
+
"@lvce-editor/extension-host-helper-process": "0.23.0",
|
|
22
|
+
"@lvce-editor/ipc": "^2.1.0",
|
|
22
23
|
"@lvce-editor/json-rpc": "^1.0.0",
|
|
23
24
|
"@lvce-editor/jsonc-parser": "^1.1.0",
|
|
24
25
|
"@lvce-editor/pretty-error": "^1.4.1",
|
|
25
|
-
"@lvce-editor/pty-host": "0.
|
|
26
|
+
"@lvce-editor/pty-host": "0.23.0",
|
|
26
27
|
"@lvce-editor/verror": "^1.1.2",
|
|
27
28
|
"@lvce-editor/web-socket-server": "^1.1.0",
|
|
28
29
|
"debug": "^4.3.4",
|
|
@@ -1,45 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export const listen = () => {
|
|
4
|
-
// @ts-ignore
|
|
5
|
-
const { parentPort } = process
|
|
6
|
-
if (!parentPort) {
|
|
7
|
-
throw new Error('parent port must be defined')
|
|
8
|
-
}
|
|
9
|
-
return parentPort
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const signal = (parentPort) => {
|
|
13
|
-
parentPort.postMessage('ready')
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const wrap = (parentPort) => {
|
|
17
|
-
return {
|
|
18
|
-
parentPort,
|
|
19
|
-
on(event, listener) {
|
|
20
|
-
if (event === 'message') {
|
|
21
|
-
const wrappedListener = (event) => {
|
|
22
|
-
const actualData = GetUtilityProcessPortData.getUtilityProcessPortData(event)
|
|
23
|
-
listener(actualData)
|
|
24
|
-
}
|
|
25
|
-
this.parentPort.on(event, wrappedListener)
|
|
26
|
-
} else if (event === 'close') {
|
|
27
|
-
this.parentPort.on('close', listener)
|
|
28
|
-
} else {
|
|
29
|
-
throw new Error('unsupported event type')
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
off(event, listener) {
|
|
33
|
-
this.parentPort.off(event, listener)
|
|
34
|
-
},
|
|
35
|
-
send(message) {
|
|
36
|
-
this.parentPort.postMessage(message)
|
|
37
|
-
},
|
|
38
|
-
sendAndTransfer(message, transfer) {
|
|
39
|
-
this.parentPort.postMessage(message, transfer)
|
|
40
|
-
},
|
|
41
|
-
dispose() {
|
|
42
|
-
this.parentPort.close()
|
|
43
|
-
},
|
|
44
|
-
}
|
|
45
|
-
}
|
|
1
|
+
export * from '@lvce-editor/ipc/dist/parts/IpcChildWithElectronUtilityProcess/IpcChildWithElectronUtilityProcess.js'
|
|
@@ -1,59 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { IpcError } from '../IpcError/IpcError.js'
|
|
3
|
-
import * as IsWebSocketOpen from '../IsWebSocketOpen/IsWebSocketOpen.js'
|
|
4
|
-
import * as WebSocketSerialization from '../WebSocketSerialization/WebSocketSerialization.js'
|
|
5
|
-
import * as WebSocketServer from '../WebSocketServer/WebSocketServer.js'
|
|
6
|
-
|
|
7
|
-
export const listen = async ({ request, handle }) => {
|
|
8
|
-
if (!request) {
|
|
9
|
-
throw new IpcError('request must be defined')
|
|
10
|
-
}
|
|
11
|
-
if (!handle) {
|
|
12
|
-
throw new IpcError('handle must be defined')
|
|
13
|
-
}
|
|
14
|
-
const webSocket = await WebSocketServer.handleUpgrade(request, handle)
|
|
15
|
-
webSocket.pause()
|
|
16
|
-
if (!IsWebSocketOpen.isWebSocketOpen(webSocket)) {
|
|
17
|
-
const { type, event } = await GetFirstWebSocketEvent.getFirstWebSocketEvent(webSocket)
|
|
18
|
-
}
|
|
19
|
-
return webSocket
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const wrap = (webSocket) => {
|
|
23
|
-
return {
|
|
24
|
-
webSocket,
|
|
25
|
-
/**
|
|
26
|
-
* @type {any}
|
|
27
|
-
*/
|
|
28
|
-
wrappedListener: undefined,
|
|
29
|
-
on(event, listener) {
|
|
30
|
-
switch (event) {
|
|
31
|
-
case 'message':
|
|
32
|
-
const wrappedListener = (message) => {
|
|
33
|
-
const data = WebSocketSerialization.deserialize(message)
|
|
34
|
-
listener(data)
|
|
35
|
-
}
|
|
36
|
-
webSocket.on('message', wrappedListener)
|
|
37
|
-
break
|
|
38
|
-
case 'close':
|
|
39
|
-
webSocket.on('close', listener)
|
|
40
|
-
break
|
|
41
|
-
default:
|
|
42
|
-
throw new Error('unknown event listener type')
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
off(event, listener) {
|
|
46
|
-
this.webSocket.off(event, listener)
|
|
47
|
-
},
|
|
48
|
-
send(message) {
|
|
49
|
-
const stringifiedMessage = WebSocketSerialization.serialize(message)
|
|
50
|
-
this.webSocket.send(stringifiedMessage)
|
|
51
|
-
},
|
|
52
|
-
dispose() {
|
|
53
|
-
this.webSocket.close()
|
|
54
|
-
},
|
|
55
|
-
start() {
|
|
56
|
-
this.webSocket.resume()
|
|
57
|
-
},
|
|
58
|
-
}
|
|
59
|
-
}
|
|
1
|
+
export * from '@lvce-editor/ipc/dist/parts/IpcChildWithWebSocket/IpcChildWithWebSocket.js'
|
|
@@ -1,53 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import * as Assert from '../Assert/Assert.js'
|
|
3
|
-
import { ChildProcessError } from '../ChildProcessError/ChildProcessError.js'
|
|
4
|
-
import * as FirstNodeWorkerEventType from '../FirstNodeWorkerEventType/FirstNodeWorkerEventType.js'
|
|
5
|
-
import * as GetFirstNodeChildProcessEvent from '../GetFirstNodeChildProcessEvent/GetFirstNodeChildProcessEvent.js'
|
|
6
|
-
import { VError } from '../VError/VError.js'
|
|
7
|
-
|
|
8
|
-
export const create = async ({ path, argv = [], env, execArgv = [], stdio = 'inherit', name = 'child process' }) => {
|
|
9
|
-
try {
|
|
10
|
-
Assert.string(path)
|
|
11
|
-
const actualArgv = ['--ipc-type=node-forked-process', ...argv]
|
|
12
|
-
const childProcess = fork(path, actualArgv, {
|
|
13
|
-
env,
|
|
14
|
-
execArgv,
|
|
15
|
-
stdio: 'pipe',
|
|
16
|
-
})
|
|
17
|
-
const { type, event, stdout, stderr } = await GetFirstNodeChildProcessEvent.getFirstNodeChildProcessEvent(childProcess)
|
|
18
|
-
if (type === FirstNodeWorkerEventType.Exit) {
|
|
19
|
-
throw new ChildProcessError(stderr)
|
|
20
|
-
}
|
|
21
|
-
if (type === FirstNodeWorkerEventType.Error) {
|
|
22
|
-
throw new Error(`child process had an error ${event}`)
|
|
23
|
-
}
|
|
24
|
-
if (stdio === 'inherit' && childProcess.stdout && childProcess.stderr) {
|
|
25
|
-
childProcess.stdout.pipe(process.stdout)
|
|
26
|
-
childProcess.stderr.pipe(process.stderr)
|
|
27
|
-
}
|
|
28
|
-
return childProcess
|
|
29
|
-
} catch (error) {
|
|
30
|
-
throw new VError(error, `Failed to launch ${name}`)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const wrap = (childProcess) => {
|
|
35
|
-
return {
|
|
36
|
-
childProcess,
|
|
37
|
-
on(event, listener) {
|
|
38
|
-
this.childProcess.on(event, listener)
|
|
39
|
-
},
|
|
40
|
-
off(event, listener) {
|
|
41
|
-
this.childProcess.off(event, listener)
|
|
42
|
-
},
|
|
43
|
-
send(message) {
|
|
44
|
-
this.childProcess.send(message)
|
|
45
|
-
},
|
|
46
|
-
sendAndTransfer(message, handle) {
|
|
47
|
-
this.childProcess.send(message, handle)
|
|
48
|
-
},
|
|
49
|
-
dispose() {
|
|
50
|
-
this.childProcess.kill()
|
|
51
|
-
},
|
|
52
|
-
}
|
|
53
|
-
}
|
|
1
|
+
export * from '@lvce-editor/ipc/dist/parts/IpcParentWithNodeForkedProcess/IpcParentWithNodeForkedProcess.js'
|
|
@@ -61,11 +61,11 @@ export const getSetupName = () => {
|
|
|
61
61
|
return 'Lvce-Setup'
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
export const version = '0.
|
|
64
|
+
export const version = '0.23.0'
|
|
65
65
|
|
|
66
|
-
export const commit = '
|
|
66
|
+
export const commit = 'c25a55a'
|
|
67
67
|
|
|
68
|
-
export const date = '2024-
|
|
68
|
+
export const date = '2024-02-01T19:16:57.000Z'
|
|
69
69
|
|
|
70
70
|
export const getVersion = () => {
|
|
71
71
|
return version
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
export const state = {
|
|
2
|
-
/**
|
|
3
|
-
* @type {any[]}
|
|
4
|
-
*/
|
|
5
|
-
windowStates: [],
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const findByWindowId = (windowId) => {
|
|
9
|
-
const { windowStates } = state
|
|
10
|
-
for (const windowState of windowStates) {
|
|
11
|
-
if (windowState.windowId === windowId) {
|
|
12
|
-
return windowState
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return undefined
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const findByWebContentsId = (webContentsId) => {
|
|
19
|
-
const { windowStates } = state
|
|
20
|
-
for (const windowState of windowStates) {
|
|
21
|
-
if (windowState.webContentsId === webContentsId) {
|
|
22
|
-
return windowState
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return undefined
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const findIndexById = (id) => {
|
|
29
|
-
const { windowStates } = state
|
|
30
|
-
for (let i = 0; i < windowStates.length; i++) {
|
|
31
|
-
const windowState = windowStates[i]
|
|
32
|
-
if (windowState.windowId === id) {
|
|
33
|
-
return i
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return -1
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const remove = (windowId) => {
|
|
40
|
-
const index = findIndexById(windowId)
|
|
41
|
-
if (index === -1) {
|
|
42
|
-
throw new Error(`expected window ${windowId} to be in windows array`)
|
|
43
|
-
}
|
|
44
|
-
state.windowStates.splice(index, 1)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const getAll = () => {
|
|
48
|
-
return state.windowStates
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export const add = (config) => {
|
|
52
|
-
state.windowStates.push(config)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export const findByPort = (port) => {
|
|
56
|
-
for (const config of state.windowStates) {
|
|
57
|
-
if (config.port === port) {
|
|
58
|
-
return config
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return undefined
|
|
62
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { fork } from 'node:child_process'
|
|
2
|
-
|
|
3
|
-
export const create = (path) => {
|
|
4
|
-
const childProcess = fork(path)
|
|
5
|
-
let _listener
|
|
6
|
-
return {
|
|
7
|
-
get onmessage() {
|
|
8
|
-
return _listener
|
|
9
|
-
},
|
|
10
|
-
set onmessage(listener) {
|
|
11
|
-
if (listener) {
|
|
12
|
-
childProcess.on('message', listener)
|
|
13
|
-
} else {
|
|
14
|
-
childProcess.off('message', listener)
|
|
15
|
-
}
|
|
16
|
-
_listener = listener
|
|
17
|
-
},
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import * as GetHelpfulChildProcessError from '../GetHelpfulChildProcessError/GetHelpfulChildProcessError.js'
|
|
2
|
-
import * as JoinLines from '../JoinLines/JoinLines.js'
|
|
3
|
-
import * as SplitLines from '../SplitLines/SplitLines.js'
|
|
4
|
-
|
|
5
|
-
export class ChildProcessError extends Error {
|
|
6
|
-
constructor(stderr) {
|
|
7
|
-
const { message, code, stack } = GetHelpfulChildProcessError.getHelpfulChildProcessError('', stderr)
|
|
8
|
-
super(message || 'child process error')
|
|
9
|
-
this.name = 'ChildProcessError'
|
|
10
|
-
if (code) {
|
|
11
|
-
this.code = code
|
|
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
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import * as Character from '../Character/Character.js'
|
|
2
|
-
import { writeFile } from '../FileSystem/FileSystem.js'
|
|
3
|
-
import * as JsonFile from '../JsonFile/JsonFile.js'
|
|
4
|
-
|
|
5
|
-
let settings
|
|
6
|
-
let settingsPromise
|
|
7
|
-
|
|
8
|
-
const readSettings = async () => {
|
|
9
|
-
// TODO allow jsonc
|
|
10
|
-
if (!settings) {
|
|
11
|
-
if (!settingsPromise) {
|
|
12
|
-
settingsPromise = JsonFile.readJson('/tmp/settings.json')
|
|
13
|
-
}
|
|
14
|
-
await settingsPromise
|
|
15
|
-
}
|
|
16
|
-
return settings
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const writeSettings = async () => {
|
|
20
|
-
// TODO jsonc
|
|
21
|
-
await writeFile('/tmp/settings.json', JSON.stringify(settings, null, 2) + Character.NewLine)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const get = async (key) => {
|
|
25
|
-
await readSettings()
|
|
26
|
-
// TODO allow nested object get
|
|
27
|
-
return settings[key]
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const set = async (key, value) => {
|
|
31
|
-
await readSettings()
|
|
32
|
-
// TODO allow nested object set?
|
|
33
|
-
// how does vscode do it?
|
|
34
|
-
settings[key] = value
|
|
35
|
-
await writeSettings()
|
|
36
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { writeFile } from 'node:fs/promises'
|
|
2
|
-
import { tmpdir } from 'node:os'
|
|
3
|
-
import { join } from 'node:path'
|
|
4
|
-
import got from 'got'
|
|
5
|
-
import { WebSocket } from 'ws'
|
|
6
|
-
import * as DevtoolsProtocolRpc from '../DevtoolsProtocolRpc/DevtoolsProtocolRpc.js'
|
|
7
|
-
|
|
8
|
-
const createConnection = (webSocketDebuggerUrl) => {
|
|
9
|
-
const webSocket = new WebSocket(webSocketDebuggerUrl)
|
|
10
|
-
// console.log({ webSocket })
|
|
11
|
-
return {
|
|
12
|
-
on(event, listener) {
|
|
13
|
-
if (event === 'message') {
|
|
14
|
-
const wrappedListener = (string) => {
|
|
15
|
-
listener(JSON.parse(string))
|
|
16
|
-
}
|
|
17
|
-
webSocket.on(event, wrappedListener)
|
|
18
|
-
} else {
|
|
19
|
-
webSocket.on(event, listener)
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
send(message) {
|
|
23
|
-
webSocket.send(JSON.stringify(message))
|
|
24
|
-
},
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const createCpuProfile = async (pid) => {
|
|
29
|
-
// AttachDebugger.attachDebugger(pid)
|
|
30
|
-
const response = await got('http://localhost:9229/json/list').json()
|
|
31
|
-
const first = response[0]
|
|
32
|
-
const { webSocketDebuggerUrl } = first
|
|
33
|
-
const ipc = createConnection(webSocketDebuggerUrl)
|
|
34
|
-
|
|
35
|
-
await new Promise((r) => {
|
|
36
|
-
ipc.on('open', r)
|
|
37
|
-
})
|
|
38
|
-
const rpc = DevtoolsProtocolRpc.create(ipc)
|
|
39
|
-
const result = await rpc.invoke('Debugger.enable')
|
|
40
|
-
const { debuggerId } = result.result
|
|
41
|
-
console.log({ debuggerId })
|
|
42
|
-
const p = await rpc.invoke('Profiler.enable')
|
|
43
|
-
await rpc.invoke('Profiler.start')
|
|
44
|
-
await new Promise((r) => {
|
|
45
|
-
setTimeout(r, 10000)
|
|
46
|
-
})
|
|
47
|
-
const profileResult = await rpc.invoke('Profiler.stop')
|
|
48
|
-
console.log({ profileResult })
|
|
49
|
-
const { profile } = profileResult.result
|
|
50
|
-
const profilePath = join(tmpdir(), 'node-profile.cpuprofile')
|
|
51
|
-
const profileString = JSON.stringify(profile)
|
|
52
|
-
await writeFile(profilePath, profileString)
|
|
53
|
-
console.log('finished')
|
|
54
|
-
// const value = await rpc.invoke('Runtime.evaluate', {
|
|
55
|
-
// expression: '1+1',
|
|
56
|
-
// })
|
|
57
|
-
// await rpc.invoke('Debugger.pause')
|
|
58
|
-
// console.log({ value })
|
|
59
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import * as Credentials from './Credentials.js'
|
|
2
|
-
|
|
3
|
-
export const Commands = {
|
|
4
|
-
deletePassword: Credentials.deletePassword,
|
|
5
|
-
findCredentials: Credentials.findCredentials,
|
|
6
|
-
findPassword: Credentials.findPassword,
|
|
7
|
-
getPassword: Credentials.getPassword,
|
|
8
|
-
setPassword: Credentials.setPassword,
|
|
9
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import keytar from 'keytar'
|
|
2
|
-
import { VError } from '../VError/VError.js'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @param {string} service
|
|
6
|
-
* @param {string} account
|
|
7
|
-
*/
|
|
8
|
-
export const deletePassword = async (service, account) => {
|
|
9
|
-
try {
|
|
10
|
-
return await keytar.deletePassword(service, account)
|
|
11
|
-
} catch (error) {
|
|
12
|
-
throw new VError(error, `Failed to delete password from service ${service}`)
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @param {string} service
|
|
18
|
-
*/
|
|
19
|
-
export const findCredentials = async (service) => {
|
|
20
|
-
try {
|
|
21
|
-
return keytar.findCredentials(service)
|
|
22
|
-
} catch (error) {
|
|
23
|
-
throw new VError(error, `Failed to find credentials from service ${service}`)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @param {string} service
|
|
29
|
-
*/
|
|
30
|
-
export const findPassword = async (service) => {
|
|
31
|
-
try {
|
|
32
|
-
return await keytar.findPassword(service)
|
|
33
|
-
} catch (error) {
|
|
34
|
-
throw new VError(error, `Failed to find password from service ${service}`)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @param {string} service
|
|
40
|
-
* @param {string} account
|
|
41
|
-
*/
|
|
42
|
-
export const getPassword = async (service, account) => {
|
|
43
|
-
try {
|
|
44
|
-
return await keytar.getPassword(service, account)
|
|
45
|
-
} catch (error) {
|
|
46
|
-
throw new VError(error, `Failed to get password from service ${service}`)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @param {string} service
|
|
52
|
-
* @param {string} account
|
|
53
|
-
* @param {string} password
|
|
54
|
-
*/
|
|
55
|
-
export const setPassword = async (service, account, password) => {
|
|
56
|
-
try {
|
|
57
|
-
return await keytar.setPassword(service, account, password)
|
|
58
|
-
} catch (error) {
|
|
59
|
-
throw new VError(error, `Failed to set password for service ${service}`)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const Id = {
|
|
2
|
-
id: 1,
|
|
3
|
-
create() {
|
|
4
|
-
return this.id++
|
|
5
|
-
},
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const create = (ipc) => {
|
|
9
|
-
const callbacks = Object.create(null)
|
|
10
|
-
const handleMessage = (message) => {
|
|
11
|
-
if ('result' in message) {
|
|
12
|
-
const callback = callbacks[message.id]
|
|
13
|
-
callback(message)
|
|
14
|
-
delete callbacks[message.id]
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
ipc.on('message', handleMessage)
|
|
18
|
-
return {
|
|
19
|
-
invoke(method, params = {}) {
|
|
20
|
-
const id = Id.create()
|
|
21
|
-
const promise = new Promise((resolve, reject) => {
|
|
22
|
-
callbacks[id] = resolve
|
|
23
|
-
})
|
|
24
|
-
ipc.send({
|
|
25
|
-
method,
|
|
26
|
-
id,
|
|
27
|
-
params,
|
|
28
|
-
})
|
|
29
|
-
return promise
|
|
30
|
-
},
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Worker } from 'node:worker_threads'
|
|
2
|
-
import * as Platform from '../Platform/Platform.js'
|
|
3
|
-
|
|
4
|
-
export const create = async () => {
|
|
5
|
-
const extensionHostPath = await Platform.getExtensionHostPath()
|
|
6
|
-
const child = new Worker(extensionHostPath, {
|
|
7
|
-
execArgv: ['--experimental-json-modules', '--max-old-space-size=60', '--enable-source-maps'],
|
|
8
|
-
env: {
|
|
9
|
-
...process.env,
|
|
10
|
-
LOGS_DIR: Platform.getLogsDir(),
|
|
11
|
-
CONFIG_DIR: Platform.getConfigDir(),
|
|
12
|
-
},
|
|
13
|
-
})
|
|
14
|
-
return {
|
|
15
|
-
on(event, listener) {
|
|
16
|
-
switch (event) {
|
|
17
|
-
case 'message':
|
|
18
|
-
child.on('message', listener)
|
|
19
|
-
break
|
|
20
|
-
case 'error':
|
|
21
|
-
child.on('error', listener)
|
|
22
|
-
break
|
|
23
|
-
default:
|
|
24
|
-
break
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
send(message) {
|
|
28
|
-
child.postMessage(message)
|
|
29
|
-
},
|
|
30
|
-
dispose() {
|
|
31
|
-
child.terminate()
|
|
32
|
-
},
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import * as ErrorType from '../ErrorType/ErrorType.js'
|
|
2
|
-
|
|
3
|
-
export const getErrorConstructor = (message, type) => {
|
|
4
|
-
if (type) {
|
|
5
|
-
switch (type) {
|
|
6
|
-
case ErrorType.DomException:
|
|
7
|
-
return DOMException
|
|
8
|
-
case ErrorType.TypeError:
|
|
9
|
-
return TypeError
|
|
10
|
-
case ErrorType.SyntaxError:
|
|
11
|
-
return SyntaxError
|
|
12
|
-
case ErrorType.ReferenceError:
|
|
13
|
-
return ReferenceError
|
|
14
|
-
default:
|
|
15
|
-
return Error
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
if (message.startsWith('TypeError: ')) {
|
|
19
|
-
return TypeError
|
|
20
|
-
}
|
|
21
|
-
if (message.startsWith('SyntaxError: ')) {
|
|
22
|
-
return SyntaxError
|
|
23
|
-
}
|
|
24
|
-
if (message.startsWith('ReferenceError: ')) {
|
|
25
|
-
return ReferenceError
|
|
26
|
-
}
|
|
27
|
-
return Error
|
|
28
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import * as FirstNodeWorkerEventType from '../FirstNodeWorkerEventType/FirstNodeWorkerEventType.js'
|
|
2
|
-
|
|
3
|
-
export const getFirstNodeChildProcessEvent = async (childProcess) => {
|
|
4
|
-
const { type, event, stdout, stderr } = await new Promise((resolve, reject) => {
|
|
5
|
-
let stderr = ''
|
|
6
|
-
let stdout = ''
|
|
7
|
-
const cleanup = (value) => {
|
|
8
|
-
if (childProcess.stdout && childProcess.stderr) {
|
|
9
|
-
childProcess.stderr.off('data', handleStdErrData)
|
|
10
|
-
childProcess.stdout.off('data', handleStdoutData)
|
|
11
|
-
}
|
|
12
|
-
childProcess.off('message', handleMessage)
|
|
13
|
-
childProcess.off('exit', handleExit)
|
|
14
|
-
childProcess.off('error', handleError)
|
|
15
|
-
resolve(value)
|
|
16
|
-
}
|
|
17
|
-
const handleStdErrData = (data) => {
|
|
18
|
-
stderr += data
|
|
19
|
-
}
|
|
20
|
-
const handleStdoutData = (data) => {
|
|
21
|
-
stdout += data
|
|
22
|
-
}
|
|
23
|
-
const handleMessage = (event) => {
|
|
24
|
-
cleanup({ type: FirstNodeWorkerEventType.Message, event, stdout, stderr })
|
|
25
|
-
}
|
|
26
|
-
const handleExit = (event) => {
|
|
27
|
-
cleanup({ type: FirstNodeWorkerEventType.Exit, event, stdout, stderr })
|
|
28
|
-
}
|
|
29
|
-
const handleError = (event) => {
|
|
30
|
-
cleanup({ type: FirstNodeWorkerEventType.Error, event, stdout, stderr })
|
|
31
|
-
}
|
|
32
|
-
if (childProcess.stdout && childProcess.stderr) {
|
|
33
|
-
childProcess.stderr.on('data', handleStdErrData)
|
|
34
|
-
childProcess.stdout.on('data', handleStdoutData)
|
|
35
|
-
}
|
|
36
|
-
childProcess.on('message', handleMessage)
|
|
37
|
-
childProcess.on('exit', handleExit)
|
|
38
|
-
childProcess.on('error', handleError)
|
|
39
|
-
})
|
|
40
|
-
return { type, event, stdout, stderr }
|
|
41
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import * as FirstWebSocketEventType from '../FirstWebSocketEventType/FirstWebSocketEventType.js'
|
|
2
|
-
import * as GetFirstEvent from '../GetFirstEvent/GetFirstEvent.js'
|
|
3
|
-
import * as WebSocketReadyState from '../WebSocketReadyState/WebSocketReadyState.js'
|
|
4
|
-
|
|
5
|
-
export const getFirstWebSocketEvent = async (webSocket) => {
|
|
6
|
-
switch (webSocket.readyState) {
|
|
7
|
-
case WebSocketReadyState.Open:
|
|
8
|
-
return {
|
|
9
|
-
type: FirstWebSocketEventType.Open,
|
|
10
|
-
event: undefined,
|
|
11
|
-
}
|
|
12
|
-
case WebSocketReadyState.Closed:
|
|
13
|
-
return {
|
|
14
|
-
type: FirstWebSocketEventType.Close,
|
|
15
|
-
event: undefined,
|
|
16
|
-
}
|
|
17
|
-
default:
|
|
18
|
-
break
|
|
19
|
-
}
|
|
20
|
-
const { type, event } = await GetFirstEvent.getFirstEvent(webSocket, {
|
|
21
|
-
open: FirstWebSocketEventType.Open,
|
|
22
|
-
close: FirstWebSocketEventType.Close,
|
|
23
|
-
})
|
|
24
|
-
return { type, event }
|
|
25
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
|
|
2
|
-
import * as SplitLines from '../SplitLines/SplitLines.js'
|
|
3
|
-
import * as JoinLines from '../JoinLines/JoinLines.js'
|
|
4
|
-
|
|
5
|
-
const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/
|
|
6
|
-
const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/
|
|
7
|
-
|
|
8
|
-
const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/
|
|
9
|
-
const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/
|
|
10
|
-
|
|
11
|
-
const RE_AT = /^\s+at/
|
|
12
|
-
const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/
|
|
13
|
-
|
|
14
|
-
const isUnhelpfulNativeModuleError = (stderr) => {
|
|
15
|
-
return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const isMessageCodeBlockStartIndex = (line) => {
|
|
19
|
-
return RE_MESSAGE_CODE_BLOCK_START.test(line)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const isMessageCodeBlockEndIndex = (line) => {
|
|
23
|
-
return RE_MESSAGE_CODE_BLOCK_END.test(line)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const getMessageCodeBlock = (stderr) => {
|
|
27
|
-
const lines = SplitLines.splitLines(stderr)
|
|
28
|
-
const startIndex = lines.findIndex(isMessageCodeBlockStartIndex)
|
|
29
|
-
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex)
|
|
30
|
-
const relevantLines = lines.slice(startIndex, endIndex)
|
|
31
|
-
const relevantMessage = relevantLines.join(' ').slice('Error: '.length)
|
|
32
|
-
return relevantMessage
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const getNativeModuleErrorMessage = (stderr) => {
|
|
36
|
-
const message = getMessageCodeBlock(stderr)
|
|
37
|
-
return {
|
|
38
|
-
message: `Incompatible native node module: ${message}`,
|
|
39
|
-
code: ErrorCodes.E_INCOMPATIBLE_NATIVE_MODULE,
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const isModulesSyntaxError = (stderr) => {
|
|
44
|
-
if (!stderr) {
|
|
45
|
-
return false
|
|
46
|
-
}
|
|
47
|
-
return stderr.includes('SyntaxError: Cannot use import statement outside a module')
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const getModuleSyntaxError = (stderr) => {
|
|
51
|
-
return {
|
|
52
|
-
message: `ES Modules are not supported in electron`,
|
|
53
|
-
code: ErrorCodes.E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const isModuleNotFoundError = (stderr) => {
|
|
58
|
-
if (!stderr) {
|
|
59
|
-
return false
|
|
60
|
-
}
|
|
61
|
-
return stderr.includes('ERR_MODULE_NOT_FOUND')
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const isModuleNotFoundMessage = (line) => {
|
|
65
|
-
return line.includes('ERR_MODULE_NOT_FOUND')
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const getModuleNotFoundError = (stderr) => {
|
|
69
|
-
const lines = SplitLines.splitLines(stderr)
|
|
70
|
-
const messageIndex = lines.findIndex(isModuleNotFoundMessage)
|
|
71
|
-
const message = lines[messageIndex]
|
|
72
|
-
return {
|
|
73
|
-
message,
|
|
74
|
-
code: ErrorCodes.ERR_MODULE_NOT_FOUND,
|
|
75
|
-
}
|
|
76
|
-
}
|
|
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
|
-
|
|
102
|
-
export const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
103
|
-
if (isUnhelpfulNativeModuleError(stderr)) {
|
|
104
|
-
return getNativeModuleErrorMessage(stderr)
|
|
105
|
-
}
|
|
106
|
-
if (isModulesSyntaxError(stderr)) {
|
|
107
|
-
return getModuleSyntaxError(stderr)
|
|
108
|
-
}
|
|
109
|
-
if (isModuleNotFoundError(stderr)) {
|
|
110
|
-
return getModuleNotFoundError(stderr)
|
|
111
|
-
}
|
|
112
|
-
const lines = SplitLines.splitLines(stderr)
|
|
113
|
-
const { actualMessage, rest } = getDetails(lines)
|
|
114
|
-
return {
|
|
115
|
-
message: `${actualMessage}`,
|
|
116
|
-
code: '',
|
|
117
|
-
stack: rest,
|
|
118
|
-
}
|
|
119
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const ContentType = 'Content-Type'
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import * as JoinLines from '../JoinLines/JoinLines.js'
|
|
2
|
-
import * as SplitLines from '../SplitLines/SplitLines.js'
|
|
3
|
-
import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
|
|
4
|
-
|
|
5
|
-
export class JsonParsingError extends Error {
|
|
6
|
-
constructor(message, codeFrame, stack) {
|
|
7
|
-
super(message)
|
|
8
|
-
this.name = 'JsonParsingError'
|
|
9
|
-
this.code = ErrorCodes.E_JSON_PARSE
|
|
10
|
-
if (codeFrame) {
|
|
11
|
-
this.codeFrame = codeFrame
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (stack) {
|
|
15
|
-
const parentStack = JoinLines.joinLines(SplitLines.splitLines(this.stack).slice(1))
|
|
16
|
-
this.stack = this.name + ': ' + this.message + '\n' + stack + '\n' + parentStack
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import * as PassThroughElectronMessagePort from './PassThroughElectronMessagePort.js'
|
|
2
|
-
|
|
3
|
-
export const name = 'PassThroughElectronMessagePort'
|
|
4
|
-
|
|
5
|
-
export const Commands = {
|
|
6
|
-
passThroughElectronMessagePort: PassThroughElectronMessagePort.passThroughElectronMessagePort,
|
|
7
|
-
}
|