@lvce-editor/shared-process 0.17.15 → 0.17.17

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.
@@ -81,7 +81,7 @@ const RE_SLASH = /^\//
81
81
  const RE_STRING_DOUBLE_QUOTE_CONTENT = /^[^"]+/
82
82
  const RE_STRING_SINGLE_QUOTE_CONTENT = /^[^']+/
83
83
  const RE_TAG_TEXT = /^[^\s>]+/
84
- const RE_TAGNAME = /^[!\w\-\:]+/
84
+ const RE_TAGNAME = /^[!\w\-\:\.]+/
85
85
  const RE_TEXT = /^[^<>\n]+/
86
86
  const RE_WHITESPACE = /^\s+/
87
87
  const RE_WORD = /^[^\s]+/
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@lvce-editor/shared-process",
3
- "version": "0.17.15",
3
+ "version": "0.17.17",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "dependencies": {
7
7
  "@babel/code-frame": "^7.22.13",
8
- "@lvce-editor/extension-host": "0.17.15",
9
- "@lvce-editor/extension-host-helper-process": "0.17.15",
8
+ "@lvce-editor/extension-host": "0.17.17",
9
+ "@lvce-editor/extension-host-helper-process": "0.17.17",
10
10
  "@lvce-editor/jsonc-parser": "^1.1.0",
11
11
  "@lvce-editor/pretty-error": "^1.1.1",
12
- "@lvce-editor/pty-host": "0.17.15",
12
+ "@lvce-editor/pty-host": "0.17.17",
13
13
  "@lvce-editor/verror": "^1.1.1",
14
14
  "debug": "^4.3.4",
15
15
  "execa": "^8.0.1",
@@ -1,7 +1,7 @@
1
1
  import * as ParentIpc from '../ParentIpc/ParentIpc.js'
2
2
 
3
3
  export const showOpenDialog = (title, properties) => {
4
- return ParentIpc.invoke('ELectronDialog.showOpenDialog', title, properties)
4
+ return ParentIpc.invoke('ElectronDialog.showOpenDialog', title, properties)
5
5
  }
6
6
 
7
7
  export const showMessageBox = (options) => {
@@ -0,0 +1,5 @@
1
+ import { createHash } from 'node:crypto'
2
+
3
+ export const getWorkspaceId = (absolutePath) => {
4
+ return createHash('sha256').update(absolutePath).digest('hex').slice(0, 16)
5
+ }
@@ -0,0 +1,5 @@
1
+ const RE_ABSOLUTE_URI = /^[a-z]+:\/\//
2
+
3
+ export const isAbsolutePath = (path) => {
4
+ return RE_ABSOLUTE_URI.test(path)
5
+ }
@@ -175,11 +175,11 @@ export const getSetupName = () => {
175
175
  return 'Lvce-Setup'
176
176
  }
177
177
 
178
- export const version = '0.17.15'
178
+ export const version = '0.17.17'
179
179
 
180
- export const commit = '8a09544'
180
+ export const commit = 'e9239cb'
181
181
 
182
- export const date = '2023-09-16T16:17:36.000Z'
182
+ export const date = '2023-09-17T19:26:04.000Z'
183
183
 
184
184
  export const getVersion = () => {
185
185
  return version
@@ -0,0 +1,19 @@
1
+ export const withResolvers = () => {
2
+ /**
3
+ * @type {any}
4
+ */
5
+ let _resolve
6
+ /**
7
+ * @type {any}
8
+ */
9
+ let _reject
10
+ const promise = new Promise((resolve, reject) => {
11
+ _resolve = resolve
12
+ _reject = reject
13
+ })
14
+ return {
15
+ resolve: _resolve,
16
+ reject: _reject,
17
+ promise,
18
+ }
19
+ }
@@ -1,6 +1,7 @@
1
1
  import { Buffer } from 'node:buffer'
2
2
  import * as _ws from 'ws'
3
3
  import * as IsSocket from '../IsSocket/IsSocket.js'
4
+ import * as Promises from '../Promises/Promises.js'
4
5
 
5
6
  // workaround for jest or node bug
6
7
  const WebSocketServer = _ws.WebSocketServer
@@ -19,11 +20,11 @@ export const handleUpgrade = async (request, socket) => {
19
20
  if (!IsSocket.isSocket(socket)) {
20
21
  throw new TypeError(`socket must be of type Socket`)
21
22
  }
22
- const webSocket = await new Promise((resolve, reject) => {
23
- const upgradeCallback = (ws) => {
24
- resolve(ws)
25
- }
26
- webSocketServer.handleUpgrade(request, socket, Buffer.alloc(0), upgradeCallback)
27
- })
23
+ const { resolve, promise } = Promises.withResolvers()
24
+ const upgradeCallback = (ws) => {
25
+ resolve(ws)
26
+ }
27
+ webSocketServer.handleUpgrade(request, socket, Buffer.alloc(0), upgradeCallback)
28
+ const webSocket = await promise
28
29
  return webSocket
29
30
  }
@@ -1,4 +1,5 @@
1
1
  import * as LoadWindowsProcessTree from '../LoadWindowsProcessTree/LoadWindowsProcessTree.js'
2
+ import * as Promises from '../Promises/Promises.js'
2
3
 
3
4
  /**
4
5
  *
@@ -8,9 +9,9 @@ import * as LoadWindowsProcessTree from '../LoadWindowsProcessTree/LoadWindowsPr
8
9
  */
9
10
  export const getProcessList = async (rootPid, flags) => {
10
11
  const WindowsProcessTree = await LoadWindowsProcessTree.loadWindowProcessTree()
11
- return new Promise((resolve, reject) => {
12
- WindowsProcessTree.getProcessList(rootPid, resolve, flags)
13
- })
12
+ const { resolve, promise } = Promises.withResolvers()
13
+ WindowsProcessTree.getProcessList(rootPid, resolve, flags)
14
+ return promise
14
15
  }
15
16
 
16
17
  /**
@@ -20,7 +21,7 @@ export const getProcessList = async (rootPid, flags) => {
20
21
  */
21
22
  export const addCpuUsage = async (processList) => {
22
23
  const WindowsProcessTree = await LoadWindowsProcessTree.loadWindowProcessTree()
23
- return new Promise((resolve) => {
24
- WindowsProcessTree.getProcessCpuUsage(processList, resolve)
25
- })
24
+ const { resolve, promise } = Promises.withResolvers()
25
+ WindowsProcessTree.getProcessCpuUsage(processList, resolve)
26
+ return promise
26
27
  }
@@ -1,20 +1,17 @@
1
- import { createHash } from 'node:crypto'
2
- import { readFile } from 'node:fs/promises'
3
1
  import { homedir } from 'node:os'
4
- import { join, resolve } from 'node:path'
2
+ import { isAbsolute, join, resolve } from 'node:path'
5
3
  import { fileURLToPath, pathToFileURL } from 'node:url'
6
4
  import * as Env from '../Env/Env.js'
5
+ import * as GetWorkspaceId from '../GetWorkspaceId/GetWorkspaceId.js'
6
+ import * as IsAbsolutePath from '../IsAbsolutePath/IsAbsolutePath.js'
7
+ import * as IsElectron from '../IsElectron/IsElectron.js'
8
+ import * as ParentIpc from '../ParentIpc/ParentIpc.js'
7
9
  import * as Platform from '../Platform/Platform.js'
8
10
  import * as Root from '../Root/Root.js'
9
-
10
- const RE_ABSOLUTE_URI = /^[a-z]+:\/\//
11
-
12
- const isAbsoluteUri = (path) => {
13
- return RE_ABSOLUTE_URI.test(path)
14
- }
11
+ import * as WorkspaceSource from '../WorkspaceSource/WorkspaceSource.js'
15
12
 
16
13
  const getAbsolutePath = (path) => {
17
- if (isAbsoluteUri(path)) {
14
+ if (IsAbsolutePath.isAbsolutePath(path)) {
18
15
  return path
19
16
  }
20
17
  if (path.startsWith('${cwd}')) {
@@ -26,17 +23,6 @@ const getAbsolutePath = (path) => {
26
23
  return path
27
24
  }
28
25
 
29
- const getWorkspaceStorage = async (workspaceId) => {
30
- try {
31
- const workspaceStorage = JSON.parse(
32
- await readFile(`/tmp/config/${workspaceId}`, 'utf-8')
33
- )
34
- return workspaceStorage
35
- } catch {
36
- return {}
37
- }
38
- }
39
-
40
26
  /**
41
27
  * @deprecated use platform instead
42
28
  */
@@ -48,26 +34,26 @@ export const getHomeDir = () => {
48
34
  return homeDir
49
35
  }
50
36
 
51
- const getWorkspaceId = (absolutePath) => {
52
- return createHash('sha256').update(absolutePath).digest('hex').slice(0, 16)
53
- }
54
-
55
- const configs = {
56
- messagePort1: {
57
- folder: '/tmp',
58
- },
59
- messagePort2: {
60
- folder: '~',
61
- },
62
- }
63
-
64
37
  const toUri = (path) => {
65
38
  return pathToFileURL(path).toString()
66
39
  }
67
40
 
68
41
  export const resolveRoot = async () => {
69
- // TODO ask electron, electron can do mapping
70
- // await
42
+ if (IsElectron.isElectron()) {
43
+ const argv = await ParentIpc.invoke('Process.getArgv')
44
+ const relevantArgv = argv.slice(2)
45
+ const last = relevantArgv.at(-1)
46
+ if (last && isAbsolute(last)) {
47
+ return {
48
+ path: last,
49
+ uri: toUri(last),
50
+ workspaceId: GetWorkspaceId.getWorkspaceId(last),
51
+ homeDir: Platform.getHomeDir(),
52
+ pathSeparator: Platform.getPathSeparator(),
53
+ source: 'shared-process-default',
54
+ }
55
+ }
56
+ }
71
57
 
72
58
  // TODO shared process should have no logic, this should probably be somewhere else
73
59
  const folder = Env.getFolder()
@@ -76,14 +62,14 @@ export const resolveRoot = async () => {
76
62
  return {
77
63
  path,
78
64
  uri: toUri(path),
79
- workspaceId: getWorkspaceId(path),
65
+ workspaceId: GetWorkspaceId.getWorkspaceId(path),
80
66
  homeDir: Platform.getHomeDir(),
81
67
  pathSeparator: Platform.getPathSeparator(),
82
- source: 'shared-process-env',
68
+ source: WorkspaceSource.SharedProcessEnv,
83
69
  }
84
70
  }
85
71
  const absolutePath = getAbsolutePath(folder)
86
- const workspaceId = getWorkspaceId(absolutePath)
72
+ const workspaceId = GetWorkspaceId.getWorkspaceId(absolutePath)
87
73
  // TODO this slows down startup a lot (~30-50ms)
88
74
  // const workspaceStorage = await getWorkspaceStorage(workspaceId)
89
75
  return {
@@ -92,7 +78,7 @@ export const resolveRoot = async () => {
92
78
  workspaceId,
93
79
  homeDir: Platform.getHomeDir(),
94
80
  pathSeparator: Platform.getPathSeparator(),
95
- source: 'shared-process-default',
81
+ source: WorkspaceSource.SharedProcessDefault,
96
82
  }
97
83
  }
98
84
 
@@ -0,0 +1,2 @@
1
+ export const SharedProcessEnv = 'shared-process-env'
2
+ export const SharedProcessDefault = 'shared-process-default'