@lvce-editor/shared-process 0.15.20 → 0.15.22
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/extensions/builtin.language-basics-css/src/tokenizeCss.js +10 -1
- package/package.json +4 -4
- package/src/parts/ErrorCodes/ErrorCodes.js +2 -0
- package/src/parts/ExitCode/ExitCode.js +1 -1
- package/src/parts/ExtensionHostHelperProcessIpc/ExtensionHostHelperProcessIpc.js +9 -48
- package/src/parts/HandleIpc/HandleIpc.js +4 -24
- package/src/parts/HandleJsonRpcMessage/HandleJsonRpcMessage.js +27 -0
- package/src/parts/HandleSocketError/HandleSocketError.js +9 -0
- package/src/parts/HandleWebSocketForExtensionHostHelperProcess/HandleWebSocketForExtensionHostHelperProcess.js +6 -2
- package/src/parts/HandleWebSocketForSharedProcess/HandleWebSocketForSharedProcess.js +2 -10
- package/src/parts/JsonParsingError/JsonParsingError.js +2 -0
- package/src/parts/JsonRpcError/JsonRpcError.js +6 -0
- package/src/parts/RecentlyOpened/RecentlyOpened.js +4 -9
- package/src/parts/Signal/Signal.js +1 -0
- package/src/sharedProcessMain.js +3 -0
- package/src/sharedProcessMain.cjs +0 -1
|
@@ -55,6 +55,7 @@ export const TokenType = {
|
|
|
55
55
|
FuntionName: 890,
|
|
56
56
|
String: 891,
|
|
57
57
|
KeywordImport: 892,
|
|
58
|
+
CssSelectorClass: 893,
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
export const TokenMap = {
|
|
@@ -81,10 +82,12 @@ export const TokenMap = {
|
|
|
81
82
|
[TokenType.FuntionName]: 'Function',
|
|
82
83
|
[TokenType.String]: 'String',
|
|
83
84
|
[TokenType.KeywordImport]: 'KeywordImport',
|
|
85
|
+
[TokenType.CssSelectorClass]: 'CssSelectorClass',
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
const RE_SELECTOR = /^[\.a-zA-Z\d\-\:>\+\~\_%\\]+/
|
|
87
89
|
const RE_SELECTOR_ID = /^#[\w\-\_]+/
|
|
90
|
+
const RE_SELECTOR_CLASS = /^\.[\w\-\_]+/
|
|
88
91
|
const RE_WHITESPACE = /^\s+/
|
|
89
92
|
const RE_CURLY_OPEN = /^\{/
|
|
90
93
|
const RE_CURLY_CLOSE = /^\}/
|
|
@@ -153,7 +156,10 @@ export const tokenizeLine = (line, lineState) => {
|
|
|
153
156
|
const part = line.slice(index)
|
|
154
157
|
switch (state) {
|
|
155
158
|
case State.TopLevelContent:
|
|
156
|
-
if ((next = part.match(
|
|
159
|
+
if ((next = part.match(RE_SELECTOR_CLASS))) {
|
|
160
|
+
token = TokenType.CssSelectorClass
|
|
161
|
+
state = State.AfterSelector
|
|
162
|
+
} else if ((next = part.match(RE_SELECTOR))) {
|
|
157
163
|
token = TokenType.CssSelector
|
|
158
164
|
state = State.AfterSelector
|
|
159
165
|
} else if ((next = part.match(RE_SELECTOR_ID))) {
|
|
@@ -336,6 +342,9 @@ export const tokenizeLine = (line, lineState) => {
|
|
|
336
342
|
} else if ((next = part.match(RE_NUMERIC))) {
|
|
337
343
|
token = TokenType.Numeric
|
|
338
344
|
state = State.AfterPropertyNameAfterColon
|
|
345
|
+
} else if ((next = part.match(RE_PROPERTY_NAME))) {
|
|
346
|
+
token = TokenType.CssPropertyName
|
|
347
|
+
state = State.AfterPropertyName
|
|
339
348
|
} else if ((next = part.match(RE_ANYTHING_UNTIL_CLOSE_BRACE))) {
|
|
340
349
|
token = TokenType.Unknown
|
|
341
350
|
state = State.InsideSelector
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/shared-process",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.22",
|
|
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.
|
|
21
|
-
"@lvce-editor/extension-host-helper-process": "0.15.
|
|
22
|
-
"@lvce-editor/pty-host": "0.15.
|
|
20
|
+
"@lvce-editor/extension-host": "0.15.22",
|
|
21
|
+
"@lvce-editor/extension-host-helper-process": "0.15.22",
|
|
22
|
+
"@lvce-editor/pty-host": "0.15.22",
|
|
23
23
|
"debug": "^4.3.4",
|
|
24
24
|
"execa": "^7.1.1",
|
|
25
25
|
"exit-hook": "^3.2.0",
|
|
@@ -4,6 +4,7 @@ export const E_ICON_THEME_NOT_FOUND = 'E_ICON_THEME_NOT_FOUND'
|
|
|
4
4
|
export const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE'
|
|
5
5
|
export const E_MANIFEST_NOT_FOUND = 'E_MANIFEST_NOT_FOUND'
|
|
6
6
|
export const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON'
|
|
7
|
+
export const E_JSON_PARSE = 'E_JSON_PARSE'
|
|
7
8
|
export const EACCES = 'EACCES'
|
|
8
9
|
export const ECONNRESET = 'ECONNRESET'
|
|
9
10
|
export const EEXIST = 'EEXIST'
|
|
@@ -16,3 +17,4 @@ export const EPIPE = 'EPIPE'
|
|
|
16
17
|
export const ERR_IPC_CHANNEL_CLOSED = 'ERR_IPC_CHANNEL_CLOSED'
|
|
17
18
|
export const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND'
|
|
18
19
|
export const EXDEV = 'EXDEV'
|
|
20
|
+
export const ERR_DLOPEN_FAILED = 'ERR_DLOPEN_FAILED'
|
|
@@ -1,51 +1,12 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as IpcParent from '../IpcParent/IpcParent.js'
|
|
2
2
|
import * as Platform from '../Platform/Platform.js'
|
|
3
3
|
|
|
4
|
-
export const create = async () => {
|
|
5
|
-
const extensionHostHelperProcessPath =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
extensionHostHelperProcessPath,
|
|
9
|
-
['--
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
on(event, listener) {
|
|
14
|
-
switch (event) {
|
|
15
|
-
case 'message':
|
|
16
|
-
childProcess.on('message', listener)
|
|
17
|
-
break
|
|
18
|
-
case 'error':
|
|
19
|
-
childProcess.on('error', listener)
|
|
20
|
-
break
|
|
21
|
-
case 'exit':
|
|
22
|
-
childProcess.on('exit', listener)
|
|
23
|
-
break
|
|
24
|
-
default:
|
|
25
|
-
throw new Error(`unsupported event type ${event}`)
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
off(event, listener) {
|
|
29
|
-
switch (event) {
|
|
30
|
-
case 'message':
|
|
31
|
-
childProcess.off('message', listener)
|
|
32
|
-
break
|
|
33
|
-
case 'error':
|
|
34
|
-
childProcess.off('error', listener)
|
|
35
|
-
break
|
|
36
|
-
case 'exit':
|
|
37
|
-
childProcess.off('exit', listener)
|
|
38
|
-
break
|
|
39
|
-
default:
|
|
40
|
-
throw new Error(`unsupported event type ${event}`)
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
send(message) {
|
|
44
|
-
childProcess.send(message)
|
|
45
|
-
},
|
|
46
|
-
dispose() {
|
|
47
|
-
childProcess.kill()
|
|
48
|
-
},
|
|
49
|
-
_process: childProcess,
|
|
50
|
-
}
|
|
4
|
+
export const create = async ({ method }) => {
|
|
5
|
+
const extensionHostHelperProcessPath = await Platform.getExtensionHostHelperProcessPath()
|
|
6
|
+
const ipc = await IpcParent.create({
|
|
7
|
+
method,
|
|
8
|
+
path: extensionHostHelperProcessPath,
|
|
9
|
+
execArgv: ['--max-old-space-size=60', '--enable-source-maps'],
|
|
10
|
+
})
|
|
11
|
+
return ipc
|
|
51
12
|
}
|
|
@@ -1,30 +1,10 @@
|
|
|
1
1
|
import * as Callback from '../Callback/Callback.js'
|
|
2
2
|
import * as Command from '../Command/Command.js'
|
|
3
|
-
import * as
|
|
4
|
-
|
|
5
|
-
const handleJsonRpcResult = (message) => {
|
|
6
|
-
Callback.resolve(message.id, message.result)
|
|
7
|
-
}
|
|
3
|
+
import * as HandleJsonRpcMessage from '../HandleJsonRpcMessage/HandleJsonRpcMessage.js'
|
|
8
4
|
|
|
9
5
|
export const handleIpc = (ipc) => {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const response = await GetResponse.getResponse(message, ipc)
|
|
13
|
-
ipc.send(response)
|
|
14
|
-
} else {
|
|
15
|
-
// TODO handle error
|
|
16
|
-
Command.execute(message.method, ...message.params)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const handleMessageFromParentProcess = async (message) => {
|
|
21
|
-
if (message.result) {
|
|
22
|
-
return handleJsonRpcResult(message)
|
|
23
|
-
}
|
|
24
|
-
if (message.method) {
|
|
25
|
-
return handleJsonRpcMessage(message)
|
|
26
|
-
}
|
|
27
|
-
console.warn('unknown message', message)
|
|
6
|
+
const handleMessage = (message) => {
|
|
7
|
+
return HandleJsonRpcMessage.handleJsonRpcMessage(ipc, message, Command.execute, Callback.resolve)
|
|
28
8
|
}
|
|
29
|
-
ipc.on('message',
|
|
9
|
+
ipc.on('message', handleMessage)
|
|
30
10
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as ErrorHandling from '../ErrorHandling/ErrorHandling.js'
|
|
2
|
+
import * as GetErrorResponse from '../GetErrorResponse/GetErrorResponse.js'
|
|
3
|
+
import * as GetResponse from '../GetResponse/GetResponse.js'
|
|
4
|
+
import * as Logger from '../Logger/Logger.js'
|
|
5
|
+
import { JsonRpcError } from '../JsonRpcError/JsonRpcError.js'
|
|
6
|
+
|
|
7
|
+
export const handleJsonRpcMessage = async (ipc, message, execute, resolve) => {
|
|
8
|
+
if ('id' in message) {
|
|
9
|
+
if ('method' in message) {
|
|
10
|
+
const response = await GetResponse.getResponse(message, execute)
|
|
11
|
+
try {
|
|
12
|
+
ipc.send(response)
|
|
13
|
+
} catch (error) {
|
|
14
|
+
const errorResponse = GetErrorResponse.getErrorResponse(message, error)
|
|
15
|
+
ipc.send(errorResponse)
|
|
16
|
+
}
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
resolve(message.id, message)
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
if ('method' in message) {
|
|
23
|
+
await GetResponse.getResponse(message, execute)
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
throw new JsonRpcError('unexpected message')
|
|
27
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
|
|
2
|
+
import * as Logger from '../Logger/Logger.js'
|
|
3
|
+
|
|
4
|
+
export const handleSocketError = (error) => {
|
|
5
|
+
if (error && error.code === ErrorCodes.ECONNRESET) {
|
|
6
|
+
return
|
|
7
|
+
}
|
|
8
|
+
Logger.info('[info shared process: handle error]', error)
|
|
9
|
+
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import * as ExtensionHostHelperProcessIpc from '../ExtensionHostHelperProcessIpc/ExtensionHostHelperProcessIpc.js'
|
|
2
|
+
import * as IpcParentType from '../IpcParentType/IpcParentType.js'
|
|
3
|
+
import * as JsonRpc from '../JsonRpc/JsonRpc.js'
|
|
2
4
|
|
|
3
5
|
export const handleWebSocket = async (message, handle) => {
|
|
4
|
-
const ipc = await ExtensionHostHelperProcessIpc.create(
|
|
5
|
-
|
|
6
|
+
const ipc = await ExtensionHostHelperProcessIpc.create({
|
|
7
|
+
method: IpcParentType.NodeForkedProcess,
|
|
8
|
+
})
|
|
9
|
+
await JsonRpc.invokeAndTransfer(ipc, handle, 'HandleWebSocket.handleWebSocket', message)
|
|
6
10
|
}
|
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
|
|
2
1
|
import * as HandleIpc from '../HandleIpc/HandleIpc.js'
|
|
2
|
+
import * as HandleSocketError from '../HandleSocketError/HandleSocketError.js'
|
|
3
3
|
import * as IpcChild from '../IpcChild/IpcChild.js'
|
|
4
4
|
import * as IpcChildType from '../IpcChildType/IpcChildType.js'
|
|
5
|
-
import * as Logger from '../Logger/Logger.js'
|
|
6
5
|
import * as WebSocketServer from '../WebSocketServer/WebSocketServer.js'
|
|
7
6
|
|
|
8
|
-
const handleSocketError = (error) => {
|
|
9
|
-
if (error && error.code === ErrorCodes.ECONNRESET) {
|
|
10
|
-
return
|
|
11
|
-
}
|
|
12
|
-
Logger.info('[info shared process: handle error]', error)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
7
|
export const handleWebSocket = async (message, handle) => {
|
|
16
|
-
handle.on('error', handleSocketError)
|
|
8
|
+
handle.on('error', HandleSocketError.handleSocketError)
|
|
17
9
|
const webSocket = await WebSocketServer.handleUpgrade(message, handle)
|
|
18
10
|
const ipc = await IpcChild.listen({
|
|
19
11
|
method: IpcChildType.WebSocket,
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import * as JoinLines from '../JoinLines/JoinLines.js'
|
|
2
2
|
import * as SplitLines from '../SplitLines/SplitLines.js'
|
|
3
|
+
import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
|
|
3
4
|
|
|
4
5
|
export class JsonParsingError extends Error {
|
|
5
6
|
constructor(message, codeFrame, stack) {
|
|
6
7
|
super(message)
|
|
7
8
|
this.name = 'JsonParsingError'
|
|
9
|
+
this.code = ErrorCodes.E_JSON_PARSE
|
|
8
10
|
if (codeFrame) {
|
|
9
11
|
this.codeFrame = codeFrame
|
|
10
12
|
}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { dirname } from 'node:path'
|
|
2
2
|
import * as Assert from '../Assert/Assert.js'
|
|
3
|
-
import
|
|
3
|
+
import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
|
|
4
4
|
import * as FileSystem from '../FileSystem/FileSystem.js'
|
|
5
5
|
import * as Json from '../Json/Json.js'
|
|
6
6
|
import * as JsonFile from '../JsonFile/JsonFile.js'
|
|
7
7
|
import * as Platform from '../Platform/Platform.js'
|
|
8
8
|
import { VError } from '../VError/VError.js'
|
|
9
9
|
|
|
10
|
-
const isValid = (recentlyOpened) => {
|
|
11
|
-
return recentlyOpened && Array.isArray(recentlyOpened)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
10
|
const addToArrayUnique = (recentlyOpened, path) => {
|
|
15
11
|
const index = recentlyOpened.indexOf(path)
|
|
16
12
|
if (index === -1) {
|
|
@@ -24,10 +20,9 @@ const getRecentlyOpened = async (recentlyOpenedPath) => {
|
|
|
24
20
|
const parsed = await JsonFile.readJson(recentlyOpenedPath)
|
|
25
21
|
return parsed
|
|
26
22
|
} catch (error) {
|
|
27
|
-
|
|
28
|
-
if (error.message.includes('File not found')) {
|
|
23
|
+
if (error && error.code === ErrorCodes.ENOENT) {
|
|
29
24
|
// ignore
|
|
30
|
-
} else if (error.
|
|
25
|
+
} else if (error && error.code === ErrorCodes.E_JSON_PARSE) {
|
|
31
26
|
// ignore
|
|
32
27
|
} else {
|
|
33
28
|
throw new VError(error, `Failed to read recently opened`)
|
|
@@ -41,7 +36,7 @@ const setRecentlyOpened = async (recentlyOpenedPath, newRecentlyOpened) => {
|
|
|
41
36
|
try {
|
|
42
37
|
await FileSystem.writeFile(recentlyOpenedPath, stringified)
|
|
43
38
|
} catch (error) {
|
|
44
|
-
if (error && error
|
|
39
|
+
if (error && error.code === ErrorCodes.ENOENT) {
|
|
45
40
|
await FileSystem.mkdir(dirname(recentlyOpenedPath))
|
|
46
41
|
await FileSystem.writeFile(recentlyOpenedPath, stringified)
|
|
47
42
|
return
|
package/src/sharedProcessMain.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as Command from './parts/Command/Command.js'
|
|
2
2
|
import * as ErrorHandling from './parts/ErrorHandling/ErrorHandling.js'
|
|
3
|
+
import * as ExitCode from './parts/ExitCode/ExitCode.js'
|
|
3
4
|
import * as Module from './parts/Module/Module.js'
|
|
4
5
|
import * as ParentIpc from './parts/ParentIpc/ParentIpc.js'
|
|
5
6
|
import * as Process from './parts/Process/Process.js'
|
|
@@ -10,6 +11,7 @@ import * as Signal from './parts/Signal/Signal.js'
|
|
|
10
11
|
|
|
11
12
|
const handleDisconnect = () => {
|
|
12
13
|
console.info('[shared process] disconnected')
|
|
14
|
+
Process.exit(ExitCode.Success)
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
// const handleBeforeExit = () => {
|
|
@@ -18,6 +20,7 @@ const handleDisconnect = () => {
|
|
|
18
20
|
|
|
19
21
|
const handleSigTerm = () => {
|
|
20
22
|
console.info('[shared-process] sigterm')
|
|
23
|
+
Process.exit(ExitCode.Success)
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
const knownCliArgs = ['install', 'list', 'link', 'unlink']
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import('./sharedProcessMain.js')
|