@lvce-editor/server 0.53.7 → 0.53.8

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.
@@ -2,7 +2,7 @@ This project incorporates components from the projects listed below, that may ha
2
2
  differing from this project:
3
3
 
4
4
 
5
- 1) License Notice for static/92d11f3/icons (from https://github.com/microsoft/vscode-icons)
5
+ 1) License Notice for static/ac6286f/icons (from https://github.com/microsoft/vscode-icons)
6
6
  ---------------------------------------
7
7
 
8
8
  Attribution 4.0 International
@@ -402,7 +402,7 @@ public licenses.
402
402
  Creative Commons may be contacted at creativecommons.org.
403
403
 
404
404
 
405
- 2) License Notice for static/92d11f3/fonts/FiraCode-VariableFont.ttf (from https://github.com/tonsky/FiraCode)
405
+ 2) License Notice for static/ac6286f/fonts/FiraCode-VariableFont.ttf (from https://github.com/tonsky/FiraCode)
406
406
  ---------------------------------------
407
407
 
408
408
  Copyright (c) 2014, The Fira Code Project Authors (https://github.com/tonsky/FiraCode)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/server",
3
- "version": "0.53.7",
3
+ "version": "0.53.8",
4
4
  "description": "Run LVCE Editor as a server.",
5
5
  "main": "index.js",
6
6
  "bin": "bin/server.js",
@@ -20,7 +20,7 @@
20
20
  "node": ">=18"
21
21
  },
22
22
  "dependencies": {
23
- "@lvce-editor/shared-process": "0.53.7",
24
- "@lvce-editor/static-server": "0.53.7"
23
+ "@lvce-editor/shared-process": "0.53.8",
24
+ "@lvce-editor/static-server": "0.53.8"
25
25
  }
26
26
  }
package/src/server.js CHANGED
@@ -46,7 +46,7 @@ const isStatic = (url) => {
46
46
  if(url === '/'){
47
47
  return true
48
48
  }
49
- if (url.startsWith('/92d11f3')) {
49
+ if (url.startsWith('/ac6286f')) {
50
50
  return true
51
51
  }
52
52
  if (url.startsWith('/favicon.ico')) {
@@ -186,6 +186,8 @@ const getOrCreateSharedProcess = () => {
186
186
  const launchStaticServerProcess = async () => {
187
187
  const staticServerPath = fileURLToPath(import.meta.resolve('@lvce-editor/static-server'))
188
188
  const ipc = await launchProcess(staticServerPath, ['--ipc-type=node-worker'])
189
+ ipc.on('message', handleMessage)
190
+
189
191
  return ipc
190
192
  }
191
193
 
@@ -264,19 +266,36 @@ const setHeaders = (response, headers) => {
264
266
  }
265
267
  }
266
268
 
269
+ const callbacks = Object.create(null)
270
+
271
+ const registerCallback = () => {
272
+ const id = createId()
273
+ const { resolve, promise } = Promise.withResolvers()
274
+ callbacks[id] = resolve
275
+ return {
276
+ id,
277
+ promise,
278
+ }
279
+ }
280
+
281
+ const handleMessage = (message) => {
282
+ const { id } = message
283
+ if (callbacks[id]) {
284
+ callbacks[id](message)
285
+ delete callbacks[id]
286
+ }
287
+ }
288
+
289
+ const hasErrorListener = new WeakSet()
290
+
267
291
  const sendHandleStaticServerProcess = async (request, res, method, ...params) => {
268
292
  request.on('error', handleRequestError)
269
- res.socket.on('error', handleSocketError)
270
- const staticServerProcess = await getOrCreateStaticServerPathProcess()
271
- const { resolve, promise } = Promise.withResolvers()
272
- const id = createId()
273
- const handleMessage = (message) => {
274
- if (message.id && message.id === id) {
275
- resolve(message)
276
- staticServerProcess.off('message', handleMessage)
277
- }
293
+ if (!hasErrorListener.has(res.socket)) {
294
+ res.socket.on('error', handleSocketError)
295
+ hasErrorListener.add(res.socket)
278
296
  }
279
- staticServerProcess.on('message', handleMessage)
297
+ const staticServerProcess = await getOrCreateStaticServerPathProcess()
298
+ const { id, promise } = registerCallback()
280
299
  staticServerProcess.send({
281
300
  jsonrpc: '2.0',
282
301
  id,