@lvce-editor/shared-process 0.18.0 → 0.18.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.
@@ -89,7 +89,7 @@ export const TokenMap = {
89
89
 
90
90
  const RE_SELECTOR_ELEMENT = /^[a-zA-Z\d\->+~_%\\\p{L}]+/u
91
91
  const RE_SELECTOR_ID = /^#[\w\-\_\\]+/
92
- const RE_PSEUDO_SELECTOR = /^:[\p{L}\-]+/u
92
+ const RE_PSEUDO_SELECTOR = /^::?[\p{L}\-]+/u
93
93
  const RE_SELECTOR_CLASS = /^\.[\w\-_\p{L}\p{Emoji_Presentation}]+/u
94
94
  const RE_WHITESPACE = /^\s+/
95
95
  const RE_CURLY_OPEN = /^\{/
@@ -102,6 +102,7 @@ const RE_PROPERTY_VALUE_INSIDE_FUNCTION = /^[^\}\s\)]+/
102
102
  const RE_SEMICOLON = /^;/
103
103
  const RE_COMMA = /^,/
104
104
  const RE_ANYTHING = /^.+/s
105
+ const RE_AMPERSAND = /^\&/
105
106
  const RE_NUMERIC = /^\-?(([0-9]+\.?[0-9]*)|(\.[0-9]+))/
106
107
  const RE_ANYTHING_UNTIL_CLOSE_BRACE = /^[^\}]+/
107
108
  const RE_BLOCK_COMMENT_START = /^\/\*/
@@ -370,12 +371,16 @@ export const tokenizeLine = (line, lineState) => {
370
371
  } else if ((next = part.match(RE_SEMICOLON))) {
371
372
  token = TokenType.Punctuation
372
373
  state = State.InsideSelector
374
+ } else if ((next = part.match(RE_AMPERSAND))) {
375
+ token = TokenType.Punctuation
376
+ state = State.TopLevelContent
377
+ stack.push(State.InsideSelector)
373
378
  } else if ((next = part.match(RE_ANYTHING_UNTIL_CLOSE_BRACE))) {
374
379
  token = TokenType.Unknown
375
380
  state = State.InsideSelector
376
381
  } else if ((next = part.match(RE_CURLY_CLOSE))) {
377
382
  token = TokenType.CurlyClose
378
- state = State.TopLevelContent
383
+ state = stack.pop() || State.TopLevelContent
379
384
  } else {
380
385
  throw new Error('no')
381
386
  }
@@ -415,9 +420,6 @@ export const tokenizeLine = (line, lineState) => {
415
420
  } else if ((next = part.match(RE_FUNCTION))) {
416
421
  token = TokenType.FuntionName
417
422
  state = State.AfterFunctionName
418
- } else if ((next = part.match(RE_FUNCTION))) {
419
- token = TokenType.FuntionName
420
- state = State.AfterFunctionName
421
423
  } else if ((next = part.match(RE_SINGLE_QUOTE))) {
422
424
  token = TokenType.Punctuation
423
425
  state = State.InsideSingleQuoteString
@@ -437,7 +439,7 @@ export const tokenizeLine = (line, lineState) => {
437
439
  state = State.AfterPropertyNameAfterColon
438
440
  } else if ((next = part.match(RE_CURLY_CLOSE))) {
439
441
  token = TokenType.Punctuation
440
- state = State.TopLevelContent
442
+ state = stack.pop() || State.TopLevelContent
441
443
  } else if ((next = part.match(RE_BLOCK_COMMENT_START))) {
442
444
  stack.push(state)
443
445
  token = TokenType.Comment
@@ -527,7 +529,7 @@ export const tokenizeLine = (line, lineState) => {
527
529
  state = State.AfterFunctionName
528
530
  } else if ((next = part.match(RE_CURLY_CLOSE))) {
529
531
  token = TokenType.Punctuation
530
- state = State.TopLevelContent
532
+ state = stack.pop() || State.TopLevelContent
531
533
  } else if ((next = part.match(RE_BLOCK_COMMENT_START))) {
532
534
  stack.push(state)
533
535
  token = TokenType.Comment
@@ -4,6 +4,7 @@
4
4
  export const State = {
5
5
  TopLevelContent: 1,
6
6
  InsideString: 2,
7
+ InsideBlockComment: 10,
7
8
  }
8
9
 
9
10
  export const StateMap = {
@@ -22,6 +23,22 @@ export const TokenType = {
22
23
  Numeric: 6,
23
24
  Punctuation: 7,
24
25
  VariableName: 8,
26
+ Comment: 60,
27
+ Error: 141,
28
+ NewLine: 771,
29
+ LanguageConstant: 13,
30
+ Regex: 14,
31
+ KeywordImport: 215,
32
+ KeywordControl: 881,
33
+ KeywordModifier: 882,
34
+ KeywordReturn: 883,
35
+ KeywordNew: 884,
36
+ FunctionName: 885,
37
+ KeywordThis: 886,
38
+ KeywordOperator: 887,
39
+ KeywordFunction: 889,
40
+ Class: 890,
41
+ KeywordVoid: 891,
25
42
  }
26
43
 
27
44
  export const TokenMap = {
@@ -33,6 +50,25 @@ export const TokenMap = {
33
50
  [TokenType.Numeric]: 'Numeric',
34
51
  [TokenType.Punctuation]: 'Punctuation',
35
52
  [TokenType.VariableName]: 'VariableName',
53
+ [TokenType.Comment]: 'Comment',
54
+ [TokenType.Error]: 'Error',
55
+ [TokenType.PunctuationString]: 'PunctuationString',
56
+ [TokenType.NewLine]: 'NewLine',
57
+ [TokenType.Keyword]: 'Keyword',
58
+ [TokenType.VariableName]: 'VariableName',
59
+ [TokenType.LanguageConstant]: 'LanguageConstant',
60
+ [TokenType.Regex]: 'Regex',
61
+ [TokenType.KeywordImport]: 'KeywordImport',
62
+ [TokenType.KeywordControl]: 'KeywordControl',
63
+ [TokenType.KeywordModifier]: 'KeywordModifier',
64
+ [TokenType.KeywordReturn]: 'KeywordReturn',
65
+ [TokenType.KeywordNew]: 'KeywordNew',
66
+ [TokenType.FunctionName]: 'Function',
67
+ [TokenType.KeywordThis]: 'KeywordThis',
68
+ [TokenType.KeywordOperator]: 'KeywordOperator',
69
+ [TokenType.KeywordFunction]: 'KeywordFunction',
70
+ [TokenType.KeywordVoid]: 'KeywordVoid',
71
+ [TokenType.Class]: 'Class',
36
72
  }
37
73
 
38
74
  const RE_SELECTOR = /^[\.a-zA-Z\d\-\:>]+/
@@ -52,11 +88,20 @@ const RE_KEYWORD =
52
88
  /^(?:while|when|var|val|typeof|typealias|try|true|throw|this|super|return|package|object|null|is|interface|in|if|fun|for|false|else|do|continue|class|break|as|enum|String)\b/
53
89
 
54
90
  const RE_VARIABLE_NAME = /^[a-zA-Z\_\$]+/
55
- const RE_PUNCTUATION = /^[:,;\{\}\[\]\.=\(\)<>\-]/
56
91
  const RE_NUMERIC = /^\d+/
92
+ const RE_LINE_COMMENT = /^\/\/[^\n]*/
93
+ const RE_BLOCK_COMMENT_START = /^\/\*/
94
+ const RE_BLOCK_COMMENT_CONTENT = /^.+?(?=\*\/)/
95
+ const RE_BLOCK_COMMENT_END = /^\*\//
96
+ const RE_ANYTHING_UNTIL_END = /^.+/s
97
+ const RE_PUNCTUATION = /^[\(\)=\+\-><\.:;\{\}\[\]!,&\|\^\?\*%~]/
98
+ const RE_SLASH = /^\//
57
99
 
58
100
  export const initialLineState = {
59
101
  state: State.TopLevelContent,
102
+ /**
103
+ * @type {any[]}
104
+ */
60
105
  tokens: [],
61
106
  }
62
107
 
@@ -90,8 +135,71 @@ export const tokenizeLine = (line, lineState) => {
90
135
  token = TokenType.Whitespace
91
136
  state = State.TopLevelContent
92
137
  } else if ((next = part.match(RE_KEYWORD))) {
93
- token = TokenType.Keyword
94
- state = State.TopLevelContent
138
+ switch (next[0]) {
139
+ case 'true':
140
+ case 'false':
141
+ case 'null':
142
+ token = TokenType.LanguageConstant
143
+ state = State.TopLevelContent
144
+ break
145
+ case 'switch':
146
+ case 'default':
147
+ case 'case':
148
+ case 'else':
149
+ case 'if':
150
+ case 'break':
151
+ case 'throw':
152
+ case 'for':
153
+ case 'try':
154
+ case 'catch':
155
+ case 'finally':
156
+ case 'continue':
157
+ case 'when':
158
+ case 'while':
159
+ case 'do':
160
+ case 'in':
161
+ token = TokenType.KeywordControl
162
+ state = State.TopLevelContent
163
+ break
164
+ case 'return':
165
+ token = TokenType.KeywordReturn
166
+ state = State.TopLevelContent
167
+ break
168
+ case 'new':
169
+ token = TokenType.KeywordNew
170
+ state = State.TopLevelContent
171
+ break
172
+ case 'this':
173
+ token = TokenType.KeywordThis
174
+ state = State.TopLevelContent
175
+ break
176
+ case 'fun':
177
+ token = TokenType.KeywordFunction
178
+ state = State.TopLevelContent
179
+ break
180
+ case 'Infinity':
181
+ token = TokenType.Numeric
182
+ state = State.TopLevelContent
183
+ break
184
+ case 'of':
185
+ token = TokenType.Keyword
186
+ state = State.TopLevelContent
187
+ break
188
+ case 'class':
189
+ case 'extends':
190
+ token = TokenType.Keyword
191
+ state = State.TopLevelContent
192
+ break
193
+ case 'var':
194
+ case 'val':
195
+ token = TokenType.Keyword
196
+ state = State.TopLevelContent
197
+ break
198
+ default:
199
+ token = TokenType.Keyword
200
+ state = State.TopLevelContent
201
+ break
202
+ }
95
203
  } else if ((next = part.match(RE_PUNCTUATION))) {
96
204
  token = TokenType.Punctuation
97
205
  state = State.TopLevelContent
@@ -104,6 +212,24 @@ export const tokenizeLine = (line, lineState) => {
104
212
  } else if ((next = part.match(RE_QUOTE_DOUBLE))) {
105
213
  token = TokenType.PunctuationString
106
214
  state = State.InsideString
215
+ } else if ((next = part.match(RE_LINE_COMMENT))) {
216
+ token = TokenType.Comment
217
+ state = State.TopLevelContent
218
+ } else if ((next = part.match(RE_BLOCK_COMMENT_START))) {
219
+ token = TokenType.Comment
220
+ state = State.InsideBlockComment
221
+ } else if ((next = part.match(RE_SLASH))) {
222
+ if ((next = part.match(RE_BLOCK_COMMENT_START))) {
223
+ token = TokenType.Comment
224
+ state = State.InsideBlockComment
225
+ } else if ((next = part.match(RE_LINE_COMMENT))) {
226
+ token = TokenType.Comment
227
+ state = State.TopLevelContent
228
+ } else {
229
+ next = part.match(RE_SLASH)
230
+ token = TokenType.Punctuation
231
+ state = State.TopLevelContent
232
+ }
107
233
  } else {
108
234
  part //?
109
235
  throw new Error('no')
@@ -120,6 +246,20 @@ export const tokenizeLine = (line, lineState) => {
120
246
  throw new Error('no')
121
247
  }
122
248
  break
249
+ case State.InsideBlockComment:
250
+ if ((next = part.match(RE_BLOCK_COMMENT_END))) {
251
+ token = TokenType.Comment
252
+ state = State.TopLevelContent
253
+ } else if ((next = part.match(RE_BLOCK_COMMENT_CONTENT))) {
254
+ token = TokenType.Comment
255
+ state = State.InsideBlockComment
256
+ } else if ((next = part.match(RE_ANYTHING_UNTIL_END))) {
257
+ token = TokenType.Comment
258
+ state = State.InsideBlockComment
259
+ } else {
260
+ throw new Error('no')
261
+ }
262
+ break
123
263
  default:
124
264
  throw new Error('no')
125
265
  }
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@lvce-editor/shared-process",
3
- "version": "0.18.0",
3
+ "version": "0.18.2",
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.18.0",
9
- "@lvce-editor/extension-host-helper-process": "0.18.0",
8
+ "@lvce-editor/extension-host": "0.18.2",
9
+ "@lvce-editor/extension-host-helper-process": "0.18.2",
10
10
  "@lvce-editor/jsonc-parser": "^1.1.0",
11
11
  "@lvce-editor/pretty-error": "^1.2.0",
12
- "@lvce-editor/pty-host": "0.18.0",
12
+ "@lvce-editor/pty-host": "0.18.2",
13
13
  "@lvce-editor/verror": "^1.1.1",
14
14
  "debug": "^4.3.4",
15
15
  "execa": "^8.0.1",
@@ -30,6 +30,6 @@
30
30
  "tail": "^2.2.6",
31
31
  "tmp-promise": "^3.0.3",
32
32
  "trash": "^8.1.1",
33
- "vscode-ripgrep-with-github-api-error-fix": "^2.9.0"
33
+ "vscode-ripgrep-with-github-api-error-fix": "^2.10.0"
34
34
  }
35
35
  }
@@ -4,6 +4,7 @@ import * as ExtractZip from '../ExtractZip/ExtractZip.js'
4
4
  import * as FileSystem from '../FileSystem/FileSystem.js'
5
5
  import * as Path from '../Path/Path.js'
6
6
  import * as Platform from '../Platform/Platform.js'
7
+ import * as PlatformPaths from '../PlatformPaths/PlatformPaths.js'
7
8
  import { VError } from '../VError/VError.js'
8
9
 
9
10
  const getExtensionPath = async (tmpDir) => {
@@ -18,10 +19,10 @@ export const install = async (name, url) => {
18
19
  try {
19
20
  Assert.string(name)
20
21
  Assert.string(url)
21
- const cachedChromeExtensionsPath = Platform.getCachedExtensionsPath()
22
+ const cachedChromeExtensionsPath = PlatformPaths.getCachedExtensionsPath()
22
23
  const tempFileCompressed = Path.join(cachedChromeExtensionsPath, `${name}.zip`)
23
24
  const tmpDir = Path.join(cachedChromeExtensionsPath, name)
24
- const chromeExtensionsPath = Platform.getChromeExtensionsPath()
25
+ const chromeExtensionsPath = PlatformPaths.getChromeExtensionsPath()
25
26
  await Download.download(url, tempFileCompressed)
26
27
  await ExtractZip.extractZip({ inFile: tempFileCompressed, outDir: tmpDir })
27
28
  const cachedExtensionPath = await getExtensionPath(tmpDir)
@@ -97,42 +97,37 @@ const applyOverrides = async ({ root, commitHash, pathPrefix }) => {
97
97
  await replace(
98
98
  Path.join(root, 'dist', commitHash, 'packages', 'renderer-process', 'dist', 'rendererProcessMain.js'),
99
99
  'platform = getPlatform();',
100
- 'platform = "web"'
100
+ 'platform = "web"',
101
101
  )
102
102
  await replace(
103
103
  Path.join(root, 'dist', commitHash, 'packages', 'renderer-process', 'dist', 'rendererProcessMain.js'),
104
- `return "/${commitHash}";`,
105
- `return "${pathPrefix}/${commitHash}";`
106
- )
107
- await replace(
108
- Path.join(root, 'dist', commitHash, 'packages', 'renderer-worker', 'dist', 'rendererWorkerMain.js'),
109
- 'platform = getPlatform();',
110
- 'platform = "web"'
104
+ `/${commitHash}`,
105
+ `${pathPrefix}/${commitHash}`,
111
106
  )
112
107
  await replace(
113
108
  Path.join(root, 'dist', commitHash, 'packages', 'renderer-worker', 'dist', 'rendererWorkerMain.js'),
114
- `platform2 = "remote";`,
115
- 'platform2 = "web";'
109
+ 'platform = Remote;',
110
+ 'platform = Web;',
116
111
  )
117
112
  await replace(
118
113
  Path.join(root, 'dist', commitHash, 'packages', 'renderer-worker', 'dist', 'rendererWorkerMain.js'),
119
114
  `return "/${commitHash}";`,
120
- `return "${pathPrefix}/${commitHash}";`
115
+ `return "${pathPrefix}/${commitHash}";`,
121
116
  )
122
117
  await replace(
123
118
  Path.join(root, 'dist', commitHash, 'packages', 'renderer-worker', 'dist', 'rendererWorkerMain.js'),
124
119
  `return \`\${assetDir}/extensions/builtin.theme-\${colorThemeId}/color-theme.json\``,
125
- `return \`\${assetDir}/themes/\${colorThemeId}.json\``
120
+ `return \`\${assetDir}/themes/\${colorThemeId}.json\``,
126
121
  )
127
122
  await replace(
128
123
  Path.join(root, 'dist', commitHash, 'packages', 'extension-host-worker', 'dist', 'extensionHostWorkerMain.js'),
129
124
  `/${commitHash}`,
130
- `${pathPrefix}/${commitHash}`
125
+ `${pathPrefix}/${commitHash}`,
131
126
  )
132
127
  await replace(
133
128
  Path.join(root, 'dist', commitHash, 'packages', 'renderer-worker', 'dist', 'rendererWorkerMain.js'),
134
129
  `return \`\${assetDir}/extensions/builtin.\${iconThemeId}/icon-theme.json\``,
135
- `return \`\${assetDir}/icon-themes/\${iconThemeId}.json\``
130
+ `return \`\${assetDir}/icon-themes/\${iconThemeId}.json\``,
136
131
  )
137
132
 
138
133
  const extensionDirents = await FileSystem.readDir(Path.join(root, 'node_modules', '@lvce-editor', 'shared-process', 'extensions'))
@@ -167,7 +162,7 @@ const applyOverrides = async ({ root, commitHash, pathPrefix }) => {
167
162
  for (const languageBasicsDirent of languageBasicsDirents) {
168
163
  await FileSystem.copy(
169
164
  Path.join(root, 'node_modules', '@lvce-editor', 'shared-process', 'extensions', languageBasicsDirent),
170
- Path.join(root, 'dist', commitHash, 'extensions', languageBasicsDirent)
165
+ Path.join(root, 'dist', commitHash, 'extensions', languageBasicsDirent),
171
166
  )
172
167
  }
173
168
 
@@ -175,7 +170,7 @@ const applyOverrides = async ({ root, commitHash, pathPrefix }) => {
175
170
  const themeId = getThemeName(themeDirent)
176
171
  await FileSystem.copy(
177
172
  Path.join(root, 'node_modules', '@lvce-editor', 'shared-process', 'extensions', themeDirent, 'color-theme.json'),
178
- Path.join(root, 'dist', commitHash, 'themes', `${themeId}.json`)
173
+ Path.join(root, 'dist', commitHash, 'themes', `${themeId}.json`),
179
174
  )
180
175
  }
181
176
 
@@ -186,7 +181,7 @@ const applyOverrides = async ({ root, commitHash, pathPrefix }) => {
186
181
  const iconThemeId = iconThemeDirent.slice('builtin.'.length)
187
182
  await FileSystem.copy(
188
183
  Path.join(root, 'node_modules', '@lvce-editor', 'shared-process', 'extensions', iconThemeDirent, 'icon-theme.json'),
189
- Path.join(root, 'dist', commitHash, 'icon-themes', `${iconThemeId}.json`)
184
+ Path.join(root, 'dist', commitHash, 'icon-themes', `${iconThemeId}.json`),
190
185
  )
191
186
  }
192
187
  await replace(Path.join(root, 'dist', 'index.html'), `/${commitHash}`, `${pathPrefix}/${commitHash}`)
@@ -197,14 +192,14 @@ const applyOverrides = async ({ root, commitHash, pathPrefix }) => {
197
192
  Path.join(root, 'dist', 'index.html'),
198
193
  '</title>',
199
194
  `</title>
200
- <link rel="shortcut icon" type="image/x-icon" href="${pathPrefix}/favicon.ico">`
195
+ <link rel="shortcut icon" type="image/x-icon" href="${pathPrefix}/favicon.ico">`,
201
196
  )
202
197
  } else {
203
198
  await replace(
204
199
  Path.join(root, 'dist', 'index.html'),
205
200
  '</title>',
206
201
  `</title>
207
- <link rel="shortcut icon" type="image/x-icon" href="favicon.ico">`
202
+ <link rel="shortcut icon" type="image/x-icon" href="favicon.ico">`,
208
203
  )
209
204
  }
210
205
  if (pathPrefix) {
@@ -223,7 +218,7 @@ const addExtensionSeo = async ({ root, name, description }) => {
223
218
  await replace(
224
219
  Path.join(root, 'dist', 'index.html'),
225
220
  '<meta name="description" content="Online Code Editor" />',
226
- `<meta name="description" content="${description}" />`
221
+ `<meta name="description" content="${description}" />`,
227
222
  )
228
223
  }
229
224
 
@@ -243,16 +238,16 @@ const addExtensionThemes = async ({ root, extensionPath, extensionJson, commitHa
243
238
  await replace(
244
239
  Path.join(root, 'dist', commitHash, 'config', 'defaultSettings.json'),
245
240
  `"workbench.colorTheme": "slime"`,
246
- `"workbench.colorTheme": "${id}"`
241
+ `"workbench.colorTheme": "${id}"`,
247
242
  )
248
243
  await FileSystem.copyFile(Path.join(root, 'README.md'), Path.join(root, 'dist', commitHash, 'extensions', `builtin.theme-${id}`, 'README.md'))
249
244
  await FileSystem.copyFile(
250
245
  Path.join(extensionPath, 'extension.json'),
251
- Path.join(root, 'dist', commitHash, 'extensions', `builtin.theme-${id}`, 'extension.json')
246
+ Path.join(root, 'dist', commitHash, 'extensions', `builtin.theme-${id}`, 'extension.json'),
252
247
  )
253
248
  await FileSystem.copyFile(
254
249
  Path.join(extensionPath, 'color-theme.json'),
255
- Path.join(root, 'dist', commitHash, 'extensions', `builtin.theme-${id}`, 'color-theme.json')
250
+ Path.join(root, 'dist', commitHash, 'extensions', `builtin.theme-${id}`, 'color-theme.json'),
256
251
  )
257
252
  }
258
253
  const themesJson = await JsonFile.readJson(Path.join(root, 'dist', commitHash, 'config', 'themes.json'))
@@ -1,8 +1,8 @@
1
1
  import * as IpcParent from '../IpcParent/IpcParent.js'
2
- import * as Platform from '../Platform/Platform.js'
2
+ import * as PlatformPaths from '../PlatformPaths/PlatformPaths.js'
3
3
 
4
4
  export const create = async ({ method }) => {
5
- const extensionHostHelperProcessPath = await Platform.getExtensionHostHelperProcessPath()
5
+ const extensionHostHelperProcessPath = await PlatformPaths.getExtensionHostHelperProcessPath()
6
6
  const ipc = await IpcParent.create({
7
7
  method,
8
8
  path: extensionHostHelperProcessPath,
@@ -1,18 +1,18 @@
1
1
  import * as ChildProcess from '../ChildProcess/ChildProcess.js'
2
- import * as Platform from '../Platform/Platform.js'
2
+ import * as PlatformPaths from '../PlatformPaths/PlatformPaths.js'
3
3
 
4
4
  export const create = async () => {
5
- const extensionHostPath = await Platform.getExtensionHostPath()
5
+ const extensionHostPath = await PlatformPaths.getExtensionHostPath()
6
6
  const childProcess = ChildProcess.fork(
7
7
  extensionHostPath,
8
8
  ['--ipc-type=websocket', '--experimental-json-modules', '--max-old-space-size=60', '--enable-source-maps'],
9
9
  {
10
10
  env: {
11
11
  ...process.env,
12
- LOGS_DIR: Platform.getLogsDir(),
13
- CONFIG_DIR: Platform.getConfigDir(),
12
+ LOGS_DIR: PlatformPaths.getLogsDir(),
13
+ CONFIG_DIR: PlatformPaths.getConfigDir(),
14
14
  },
15
- }
15
+ },
16
16
  )
17
17
  return {
18
18
  on(event, listener) {
@@ -2,7 +2,7 @@ import * as Extract from '../Extract/Extract.js'
2
2
  import * as FileSystem from '../FileSystem/FileSystem.js'
3
3
  import * as JsonFile from '../JsonFile/JsonFile.js'
4
4
  import * as Path from '../Path/Path.js'
5
- import * as Platform from '../Platform/Platform.js'
5
+ import * as PlatformPaths from '../PlatformPaths/PlatformPaths.js'
6
6
  import { VError } from '../VError/VError.js'
7
7
 
8
8
  const getCachedExtensionFolderName = (path) => {
@@ -15,11 +15,11 @@ const getCachedExtensionFolderName = (path) => {
15
15
 
16
16
  export const install = async ({ path }) => {
17
17
  try {
18
- const cachedExtensionsPath = Platform.getCachedExtensionsPath()
18
+ const cachedExtensionsPath = PlatformPaths.getCachedExtensionsPath()
19
19
  const cachedExtensionFolderName = getCachedExtensionFolderName(path)
20
20
  const cachedExtensionPath = Path.join(cachedExtensionsPath, cachedExtensionFolderName)
21
21
  await Extract.extractTarBr(path, cachedExtensionPath)
22
- const extensionsPath = Platform.getExtensionsPath()
22
+ const extensionsPath = PlatformPaths.getExtensionsPath()
23
23
  const manifestPath = Path.join(cachedExtensionPath, 'extension.json')
24
24
  const manifestJson = await JsonFile.readJson(manifestPath)
25
25
  const { id } = manifestJson
@@ -2,12 +2,12 @@ import * as DownloadAndExtract from '../DownloadAndExtract/DownloadAndExtract.js
2
2
  import * as FileSystem from '../FileSystem/FileSystem.js'
3
3
  import * as JsonFile from '../JsonFile/JsonFile.js'
4
4
  import * as Path from '../Path/Path.js'
5
- import * as Platform from '../Platform/Platform.js'
5
+ import * as PlatformPaths from '../PlatformPaths/PlatformPaths.js'
6
6
  import { VError } from '../VError/VError.js'
7
7
 
8
8
  export const install = async ({ user, repo, branch }) => {
9
9
  try {
10
- const cachedExtensionsPath = Platform.getCachedExtensionsPath()
10
+ const cachedExtensionsPath = PlatformPaths.getCachedExtensionsPath()
11
11
  const url = `https://codeload.github.com/${user}/${repo}/tar.gz/${branch}`
12
12
  const cachedExtensionPath = Path.join(cachedExtensionsPath, `github-${user}-${repo}-${branch}`)
13
13
  await DownloadAndExtract.downloadAndExtractTarGz({
@@ -15,7 +15,7 @@ export const install = async ({ user, repo, branch }) => {
15
15
  outDir: cachedExtensionPath,
16
16
  strip: 1,
17
17
  })
18
- const extensionsPath = Platform.getExtensionsPath()
18
+ const extensionsPath = PlatformPaths.getExtensionsPath()
19
19
  const manifestPath = Path.join(cachedExtensionPath, 'extension.json')
20
20
  const manifestJson = await JsonFile.readJson(manifestPath)
21
21
  const { id } = manifestJson
@@ -3,7 +3,7 @@ import { join } from 'node:path'
3
3
  import * as Download from '../Download/Download.js'
4
4
  import * as Extract from '../Extract/Extract.js'
5
5
  import * as JsonFile from '../JsonFile/JsonFile.js'
6
- import * as Platform from '../Platform/Platform.js'
6
+ import * as PlatformPaths from '../PlatformPaths/PlatformPaths.js'
7
7
  import * as TmpFile from '../TmpFile/TmpFile.js'
8
8
  import { VError } from '../VError/VError.js'
9
9
 
@@ -12,7 +12,7 @@ export const install = async ({ url }) => {
12
12
  // TODO cache extension tar br file, probably by url <cachedExtensions>/user/repo/releases/<tag>/<fileName>
13
13
  // const cachedExtensionsPath = Platform.getCachedExtensionsPath()
14
14
  // const outFile = join(cachedExtensionsPath, 'installed-extension.tar.br')
15
- const extensionsPath = Platform.getExtensionsPath()
15
+ const extensionsPath = PlatformPaths.getExtensionsPath()
16
16
  const tmpFile = await TmpFile.getTmpFile()
17
17
  await Download.download(url, tmpFile)
18
18
  const tmpDir = await TmpFile.getTmpDir()
@@ -3,7 +3,7 @@ import * as ExtensionManifest from '../ExtensionManifest/ExtensionManifest.js'
3
3
  import * as ExtensionManifestStatus from '../ExtensionManifestStatus/ExtensionManifestStatus.js'
4
4
  import * as FileSystem from '../FileSystem/FileSystem.js'
5
5
  import * as Path from '../Path/Path.js'
6
- import * as Platform from '../Platform/Platform.js'
6
+ import * as PlatformPaths from '../PlatformPaths/PlatformPaths.js'
7
7
  import * as SymLink from '../SymLink/SymLink.js'
8
8
  import { VError } from '../VError/VError.js'
9
9
 
@@ -13,7 +13,7 @@ const linkFallBack = async (path) => {
13
13
  if (manifest.status === ExtensionManifestStatus.Rejected) {
14
14
  throw manifest.reason
15
15
  }
16
- const linkedExtensionsPath = Platform.getLinkedExtensionsPath()
16
+ const linkedExtensionsPath = PlatformPaths.getLinkedExtensionsPath()
17
17
  // @ts-ignore
18
18
  const to = Path.join(linkedExtensionsPath, manifest.id)
19
19
  await FileSystem.remove(to)
@@ -29,7 +29,7 @@ export const link = async (path) => {
29
29
  if (manifest.status === ExtensionManifestStatus.Rejected) {
30
30
  throw manifest.reason
31
31
  }
32
- const linkedExtensionsPath = Platform.getLinkedExtensionsPath()
32
+ const linkedExtensionsPath = PlatformPaths.getLinkedExtensionsPath()
33
33
  // @ts-ignore
34
34
  const to = Path.join(linkedExtensionsPath, manifest.id)
35
35
  await SymLink.createSymLink(path, to)
@@ -1,8 +1,8 @@
1
1
  import { basename } from 'node:path'
2
2
  import * as ExtensionManifestInputType from '../ExtensionManifestInputType/ExtensionManifestInputType.js'
3
- import * as ExtensionManifests from '../ExtensionManifests/ExtensionManifests.js'
4
- import * as Platform from '../Platform/Platform.js'
5
3
  import * as ExtensionManifestStatus from '../ExtensionManifestStatus/ExtensionManifestStatus.js'
4
+ import * as ExtensionManifests from '../ExtensionManifests/ExtensionManifests.js'
5
+ import * as PlatformPaths from '../PlatformPaths/PlatformPaths.js'
6
6
  import { VError } from '../VError/VError.js'
7
7
 
8
8
  const getManifestVersion = (json) => {
@@ -51,15 +51,15 @@ export const list = async () => {
51
51
  const manifests = await ExtensionManifests.getAll([
52
52
  {
53
53
  type: ExtensionManifestInputType.LinkedExtensionsFolder,
54
- path: Platform.getLinkedExtensionsPath(),
54
+ path: PlatformPaths.getLinkedExtensionsPath(),
55
55
  },
56
56
  {
57
57
  type: ExtensionManifestInputType.Folder,
58
- path: Platform.getExtensionsPath(),
58
+ path: PlatformPaths.getExtensionsPath(),
59
59
  },
60
60
  {
61
61
  type: ExtensionManifestInputType.Folder,
62
- path: Platform.getBuiltinExtensionsPath(),
62
+ path: PlatformPaths.getBuiltinExtensionsPath(),
63
63
  },
64
64
  ])
65
65
  const infos = getManifestInfos(manifests)
@@ -3,14 +3,14 @@ import * as Debug from '../Debug/Debug.js'
3
3
  import * as ExtensionManifestInputType from '../ExtensionManifestInputType/ExtensionManifestInputType.js'
4
4
  import * as ExtensionManifests from '../ExtensionManifests/ExtensionManifests.js'
5
5
  import * as Path from '../Path/Path.js'
6
- import * as Platform from '../Platform/Platform.js'
6
+ import * as PlatformPaths from '../PlatformPaths/PlatformPaths.js'
7
7
  import { VError } from '../VError/VError.js'
8
8
 
9
9
  export const enable = async (id) => {
10
10
  try {
11
11
  Debug.debug(`ExtensionManagement#enable ${id}`)
12
- const extensionsPath = Platform.getExtensionsPath()
13
- const disabledExtensionsPath = Platform.getDisabledExtensionsPath()
12
+ const extensionsPath = PlatformPaths.getExtensionsPath()
13
+ const disabledExtensionsPath = PlatformPaths.getDisabledExtensionsPath()
14
14
  await mkdir(extensionsPath, { recursive: true })
15
15
  await rename(Path.join(disabledExtensionsPath, id), Path.join(extensionsPath, id))
16
16
  } catch (error) {
@@ -21,8 +21,8 @@ export const enable = async (id) => {
21
21
  export const disable = async (id) => {
22
22
  try {
23
23
  Debug.debug(`ExtensionManagement#disable ${id}`)
24
- const disabledExtensionsPath = Platform.getDisabledExtensionsPath()
25
- const extensionsPath = Platform.getExtensionsPath()
24
+ const disabledExtensionsPath = PlatformPaths.getDisabledExtensionsPath()
25
+ const extensionsPath = PlatformPaths.getExtensionsPath()
26
26
  await mkdir(disabledExtensionsPath, { recursive: true })
27
27
  await rename(Path.join(extensionsPath, id), Path.join(disabledExtensionsPath, id))
28
28
  } catch (error) {
@@ -34,7 +34,7 @@ export const getBuiltinExtensions = () => {
34
34
  return ExtensionManifests.getAll([
35
35
  {
36
36
  type: ExtensionManifestInputType.Folder,
37
- path: Platform.getBuiltinExtensionsPath(),
37
+ path: PlatformPaths.getBuiltinExtensionsPath(),
38
38
  },
39
39
  ])
40
40
  }
@@ -43,7 +43,7 @@ export const getInstalledExtensions = () => {
43
43
  return ExtensionManifests.getAll([
44
44
  {
45
45
  type: ExtensionManifestInputType.Folder,
46
- path: Platform.getExtensionsPath(),
46
+ path: PlatformPaths.getExtensionsPath(),
47
47
  },
48
48
  ])
49
49
  }
@@ -52,19 +52,19 @@ export const getExtensions = () => {
52
52
  return ExtensionManifests.getAll([
53
53
  {
54
54
  type: ExtensionManifestInputType.OnlyExtension,
55
- path: Platform.getOnlyExtensionPath(),
55
+ path: PlatformPaths.getOnlyExtensionPath(),
56
56
  },
57
57
  {
58
58
  type: ExtensionManifestInputType.Folder,
59
- path: Platform.getLinkedExtensionsPath(),
59
+ path: PlatformPaths.getLinkedExtensionsPath(),
60
60
  },
61
61
  {
62
62
  type: ExtensionManifestInputType.Folder,
63
- path: Platform.getExtensionsPath(),
63
+ path: PlatformPaths.getExtensionsPath(),
64
64
  },
65
65
  {
66
66
  type: ExtensionManifestInputType.Folder,
67
- path: Platform.getBuiltinExtensionsPath(),
67
+ path: PlatformPaths.getBuiltinExtensionsPath(),
68
68
  },
69
69
  ])
70
70
  }
@@ -73,7 +73,7 @@ export const getDisabledExtensions = () => {
73
73
  return ExtensionManifests.getAll([
74
74
  {
75
75
  type: ExtensionManifestInputType.Folder,
76
- path: Platform.getDisabledExtensionsPath(),
76
+ path: PlatformPaths.getDisabledExtensionsPath(),
77
77
  },
78
78
  ])
79
79
  }
@@ -1,13 +1,13 @@
1
1
  import { rm } from 'node:fs/promises'
2
2
  import * as Debug from '../Debug/Debug.js'
3
3
  import * as Path from '../Path/Path.js'
4
- import * as Platform from '../Platform/Platform.js'
4
+ import * as PlatformPaths from '../PlatformPaths/PlatformPaths.js'
5
5
  import { VError } from '../VError/VError.js'
6
6
 
7
7
  export const uninstall = async (id) => {
8
8
  try {
9
9
  Debug.debug(`ExtensionManagement#uninstall ${id}`)
10
- const extensionsPath = Platform.getExtensionsPath()
10
+ const extensionsPath = PlatformPaths.getExtensionsPath()
11
11
  await rm(Path.join(extensionsPath, id), { recursive: true })
12
12
  } catch (error) {
13
13
  // if (error.code === 'ENOENT') {
@@ -1,7 +1,7 @@
1
1
  import * as ExtensionManifest from '../ExtensionManifest/ExtensionManifest.js'
2
2
  import * as ExtensionManifestStatus from '../ExtensionManifestStatus/ExtensionManifestStatus.js'
3
3
  import * as Path from '../Path/Path.js'
4
- import * as Platform from '../Platform/Platform.js'
4
+ import * as PlatformPaths from '../PlatformPaths/PlatformPaths.js'
5
5
  import * as RemoveSymlink from '../RemoveSymlink/RemoveSymlink.js'
6
6
  import { VError } from '../VError/VError.js'
7
7
 
@@ -11,7 +11,7 @@ export const unlink = async (path) => {
11
11
  if (manifest.status === ExtensionManifestStatus.Rejected) {
12
12
  throw manifest.reason
13
13
  }
14
- const linkedExtensionsPath = Platform.getLinkedExtensionsPath()
14
+ const linkedExtensionsPath = PlatformPaths.getLinkedExtensionsPath()
15
15
  // @ts-ignore
16
16
  const to = Path.join(linkedExtensionsPath, manifest.id)
17
17
  await RemoveSymlink.removeSymlink(to)
@@ -2,7 +2,7 @@ import * as Debug from '../Debug/Debug.js'
2
2
  import * as Download from '../Download/Download.js'
3
3
  import * as Extract from '../Extract/Extract.js'
4
4
  import * as Path from '../Path/Path.js'
5
- import * as Platform from '../Platform/Platform.js'
5
+ import * as PlatformPaths from '../PlatformPaths/PlatformPaths.js'
6
6
  import * as Queue from '../Queue/Queue.js'
7
7
  import { VError } from '../VError/VError.js'
8
8
 
@@ -10,10 +10,10 @@ export const installExtension = async (id) => {
10
10
  // TODO this should be a stateless function, renderer-worker should have info on marketplace url
11
11
  // TODO use command.execute
12
12
  try {
13
- const marketplaceUrl = Platform.getMarketplaceUrl()
13
+ const marketplaceUrl = PlatformPaths.getMarketplaceUrl()
14
14
  Debug.debug(`ExtensionManagement#install ${id}`)
15
- const cachedExtensionsPath = Platform.getCachedExtensionsPath()
16
- const extensionsPath = Platform.getExtensionsPath()
15
+ const cachedExtensionsPath = PlatformPaths.getCachedExtensionsPath()
16
+ const extensionsPath = PlatformPaths.getExtensionsPath()
17
17
  // TODO maybe a queue is over engineering here
18
18
  await Queue.add('download', async () => {
19
19
  Debug.debug(`ExtensionManagement#download ${id}`)
@@ -1,30 +1,31 @@
1
1
  import * as Platform from '../Platform/Platform.js'
2
+ import * as PlatformPaths from '../PlatformPaths/PlatformPaths.js'
2
3
 
3
4
  export const name = 'Platform'
4
5
 
5
6
  export const Commands = {
6
- getAppDir: Platform.getAppDir,
7
- getBuiltinExtensionsPath: Platform.getBuiltinExtensionsPath,
8
- getCachedExtensionsPath: Platform.getCachedExtensionsPath,
9
- getCacheDir: Platform.getCacheDir,
7
+ getAppDir: PlatformPaths.getAppDir,
8
+ getBuiltinExtensionsPath: PlatformPaths.getBuiltinExtensionsPath,
9
+ getCachedExtensionsPath: PlatformPaths.getCachedExtensionsPath,
10
+ getCacheDir: PlatformPaths.getCacheDir,
10
11
  getApplicationName: Platform.getApplicationName,
11
12
  getCommit: Platform.getCommit,
12
- getConfigDir: Platform.getConfigDir,
13
- getDataDir: Platform.getDataDir,
13
+ getConfigDir: PlatformPaths.getConfigDir,
14
+ getDataDir: PlatformPaths.getDataDir,
14
15
  getDate: Platform.getDate,
15
- getDisabledExtensionsPath: Platform.getDisabledExtensionsPath,
16
- getDownloadDir: Platform.getDownloadDir,
17
- getExtensionsPath: Platform.getExtensionsPath,
18
- getHomeDir: Platform.getHomeDir,
19
- getLogsDir: Platform.getLogsDir,
20
- getMarketplaceUrl: Platform.getMarketplaceUrl,
16
+ getDisabledExtensionsPath: PlatformPaths.getDisabledExtensionsPath,
17
+ getDownloadDir: PlatformPaths.getDownloadDir,
18
+ getExtensionsPath: PlatformPaths.getExtensionsPath,
19
+ getHomeDir: PlatformPaths.getHomeDir,
20
+ getLogsDir: PlatformPaths.getLogsDir,
21
+ getMarketplaceUrl: PlatformPaths.getMarketplaceUrl,
21
22
  getNodePath: Platform.getNodePath,
22
23
  getProductNameLong: Platform.getProductNameLong,
23
- getRecentlyOpenedPath: Platform.getRecentlyOpenedPath,
24
- getTestPath: Platform.getTestPath,
24
+ getRecentlyOpenedPath: PlatformPaths.getRecentlyOpenedPath,
25
+ getTestPath: PlatformPaths.getTestPath,
25
26
  getTmpDir: Platform.getTmpDir,
26
- getUserKeyBindingsPath: Platform.getUserKeyBindingsPath,
27
- getUserSettingsPath: Platform.getUserSettingsPath,
27
+ getUserKeyBindingsPath: PlatformPaths.getUserKeyBindingsPath,
28
+ getUserSettingsPath: PlatformPaths.getUserSettingsPath,
28
29
  getVersion: Platform.getVersion,
29
30
  setEnvironmentVariables: Platform.setEnvironmentVariables,
30
31
  }
@@ -1,10 +1,7 @@
1
- import { homedir, tmpdir } from 'node:os'
2
- import { isAbsolute, join, resolve, sep } from 'node:path'
3
- import { pathToFileURL } from 'node:url'
4
- import { xdgCache, xdgConfig, xdgData, xdgState } from 'xdg-basedir'
5
- import * as Path from '../Path/Path.js'
1
+ import { tmpdir } from 'node:os'
2
+ import { sep } from 'node:path'
3
+ import { xdgState } from 'xdg-basedir'
6
4
  import * as Process from '../Process/Process.js'
7
- import * as Root from '../Root/Root.js'
8
5
 
9
6
  const { env, platform } = process
10
7
 
@@ -14,54 +11,12 @@ export const isWindows = platform === 'win32'
14
11
 
15
12
  export const isMacOs = platform === 'darwin'
16
13
 
17
- export const dataDir = Path.join(xdgData || tmpdir(), applicationName)
18
-
19
- export const configDir = Path.join(xdgConfig || tmpdir(), applicationName)
20
-
21
- export const cacheDir = Path.join(xdgCache || tmpdir(), applicationName)
22
-
23
- export const homeDir = isWindows ? '' : homedir()
24
-
25
- export const appDir = Root.root
26
-
27
14
  export const isDeb = false
28
15
 
29
16
  export const isAppImage = () => {
30
17
  return Boolean(env.APPIMAGE)
31
18
  }
32
19
 
33
- export const getExtensionsPath = () => {
34
- return Path.join(dataDir, 'extensions')
35
- }
36
-
37
- export const getBuiltinExtensionsPath = () => {
38
- return Path.join(Root.root, 'extensions')
39
- }
40
-
41
- export const getDisabledExtensionsPath = () => {
42
- return Path.join(dataDir, 'disabled-extensions')
43
- }
44
-
45
- export const getCachedExtensionsPath = () => {
46
- return Path.join(cacheDir, 'cached-extensions')
47
- }
48
-
49
- export const getCachedChromeExtensionsPath = () => {
50
- return Path.join(cacheDir, 'cached-electron-browser-view-chrome-extensions')
51
- }
52
-
53
- export const getLinkedExtensionsPath = () => {
54
- return Path.join(dataDir, 'linked-extensions')
55
- }
56
-
57
- export const getChromeExtensionsPath = () => {
58
- return Path.join(dataDir, 'electron-browser-view-chrome-extensions')
59
- }
60
-
61
- export const getMarketplaceUrl = () => {
62
- return env.LVCE_MARKETPLACE_URL || 'https://marketplace.22e924c84de072d4b25b.com'
63
- }
64
-
65
20
  export const getPathSeparator = () => {
66
21
  return sep
67
22
  }
@@ -70,54 +25,12 @@ export const getStateDir = () => {
70
25
  return xdgState
71
26
  }
72
27
 
73
- export const getLogsDir = () => {
74
- return Path.join(xdgState || tmpdir(), applicationName, 'logs')
75
- }
76
-
77
- export const getUserSettingsPath = () => {
78
- return Path.join(configDir, 'settings.json')
79
- }
80
-
81
- export const getUserKeyBindingsPath = () => {
82
- return Path.join(configDir, 'keybindings.json')
83
- }
84
-
85
- export const getExtensionHostPath = async () => {
86
- const { extensionHostPath } = await import(
87
- '@lvce-editor/extension-host'
88
- )
89
- return extensionHostPath
90
- }
91
-
92
- export const getExtensionHostHelperProcessPath = async () => {
93
- const { extensionHostHelperProcessPath } = await import(
94
- '@lvce-editor/extension-host-helper-process'
95
- )
96
- return extensionHostHelperProcessPath
97
- }
98
-
99
- export const getRecentlyOpenedPath = () => {
100
- return Path.join(cacheDir, 'recently-opened.json')
101
- }
102
-
103
- export const getDefaultSettingsPath = () => {
104
- return Path.join(Root.root, 'config', 'defaultSettings.json')
105
- }
106
28
  export const setEnvironmentVariables = (variables) => {
107
29
  for (const [key, value] of Object.entries(variables)) {
108
30
  env[key] = value
109
31
  }
110
32
  }
111
33
 
112
- export const getTestPath = () => {
113
- if (env.TEST_PATH) {
114
- const absolutePath = isAbsolute(env.TEST_PATH) ? env.TEST_PATH : Path.join(process.cwd(), env.TEST_PATH)
115
- const testPath = '/remote' + pathToFileURL(absolutePath).toString().slice(7)
116
- return testPath
117
- }
118
- return '/packages/extension-host-worker-tests'
119
- }
120
-
121
34
  export const getNodePath = () => {
122
35
  return Process.argv[0]
123
36
  }
@@ -126,39 +39,6 @@ export const getTmpDir = () => {
126
39
  return tmpdir()
127
40
  }
128
41
 
129
- export const getOnlyExtensionPath = () => {
130
- const onlyExtensionPath = env.ONLY_EXTENSION
131
- if (onlyExtensionPath) {
132
- return resolve(onlyExtensionPath)
133
- }
134
- return ''
135
- }
136
-
137
- export const getAppDir = () => {
138
- return appDir
139
- }
140
-
141
- export const getCacheDir = () => {
142
- return cacheDir
143
- }
144
-
145
- export const getConfigDir = () => {
146
- return configDir
147
- }
148
-
149
- export const getDataDir = () => {
150
- return dataDir
151
- }
152
-
153
- export const getHomeDir = () => {
154
- return homeDir
155
- }
156
-
157
- export const getDownloadDir = () => {
158
- const { XDG_DOWNLOAD_DIR } = env
159
- return XDG_DOWNLOAD_DIR || join(homeDir, 'Downloads')
160
- }
161
-
162
42
  export const getRepository = () => {
163
43
  return `lvce-editor/lvce-editor`
164
44
  }
@@ -175,11 +55,11 @@ export const getSetupName = () => {
175
55
  return 'Lvce-Setup'
176
56
  }
177
57
 
178
- export const version = '0.18.0'
58
+ export const version = '0.18.2'
179
59
 
180
- export const commit = '4159d29'
60
+ export const commit = '0ef093c'
181
61
 
182
- export const date = '2023-09-24T14:32:19.000Z'
62
+ export const date = '2023-10-01T08:14:46.000Z'
183
63
 
184
64
  export const getVersion = () => {
185
65
  return version
@@ -0,0 +1,24 @@
1
+ import * as PlatformPaths from '../PlatformPaths/PlatformPaths.js'
2
+
3
+ export const name = 'PlatformPaths'
4
+
5
+ export const Commands = {
6
+ getAppDir: PlatformPaths.getAppDir,
7
+ getBuiltinExtensionsPath: PlatformPaths.getBuiltinExtensionsPath,
8
+ getCachedExtensionsPath: PlatformPaths.getCachedExtensionsPath,
9
+ getCacheDir: PlatformPaths.getCacheDir,
10
+ getConfigDir: PlatformPaths.getConfigDir,
11
+ getDataDir: PlatformPaths.getDataDir,
12
+ getDisabledExtensionsPath: PlatformPaths.getDisabledExtensionsPath,
13
+ getDownloadDir: PlatformPaths.getDownloadDir,
14
+ getExtensionsPath: PlatformPaths.getExtensionsPath,
15
+ getHomeDir: PlatformPaths.getHomeDir,
16
+ getLogsDir: PlatformPaths.getLogsDir,
17
+ getMarketplaceUrl: PlatformPaths.getMarketplaceUrl,
18
+ getNodePath: PlatformPaths.getNodePath,
19
+ getRecentlyOpenedPath: PlatformPaths.getRecentlyOpenedPath,
20
+ getTestPath: PlatformPaths.getTestPath,
21
+ getTmpDir: PlatformPaths.getTmpDir,
22
+ getUserKeyBindingsPath: PlatformPaths.getUserKeyBindingsPath,
23
+ getUserSettingsPath: PlatformPaths.getUserSettingsPath,
24
+ }
@@ -0,0 +1,148 @@
1
+ import { homedir, tmpdir } from 'node:os'
2
+ import { isAbsolute, join, resolve, sep } from 'node:path'
3
+ import { pathToFileURL } from 'node:url'
4
+ import { xdgCache, xdgConfig, xdgData, xdgState } from 'xdg-basedir'
5
+ import * as Path from '../Path/Path.js'
6
+ import * as Platform from '../Platform/Platform.js'
7
+ import * as Process from '../Process/Process.js'
8
+ import * as Root from '../Root/Root.js'
9
+
10
+ const { env } = process
11
+
12
+ export const dataDir = Path.join(xdgData || tmpdir(), Platform.applicationName)
13
+
14
+ export const configDir = Path.join(xdgConfig || tmpdir(), Platform.applicationName)
15
+
16
+ export const cacheDir = Path.join(xdgCache || tmpdir(), Platform.applicationName)
17
+
18
+ export const homeDir = Platform.isWindows ? '' : homedir()
19
+
20
+ export const appDir = Root.root
21
+
22
+ export const getExtensionsPath = () => {
23
+ return Path.join(dataDir, 'extensions')
24
+ }
25
+
26
+ export const getBuiltinExtensionsPath = () => {
27
+ return Path.join(Root.root, 'extensions')
28
+ }
29
+
30
+ export const getDisabledExtensionsPath = () => {
31
+ return Path.join(dataDir, 'disabled-extensions')
32
+ }
33
+
34
+ export const getCachedExtensionsPath = () => {
35
+ return Path.join(cacheDir, 'cached-extensions')
36
+ }
37
+
38
+ export const getCachedChromeExtensionsPath = () => {
39
+ return Path.join(cacheDir, 'cached-electron-browser-view-chrome-extensions')
40
+ }
41
+
42
+ export const getLinkedExtensionsPath = () => {
43
+ return Path.join(dataDir, 'linked-extensions')
44
+ }
45
+
46
+ export const getChromeExtensionsPath = () => {
47
+ return Path.join(dataDir, 'electron-browser-view-chrome-extensions')
48
+ }
49
+
50
+ export const getMarketplaceUrl = () => {
51
+ return env.LVCE_MARKETPLACE_URL || 'https://marketplace.22e924c84de072d4b25b.com'
52
+ }
53
+
54
+ export const getPathSeparator = () => {
55
+ return sep
56
+ }
57
+
58
+ export const getStateDir = () => {
59
+ return xdgState
60
+ }
61
+
62
+ export const getLogsDir = () => {
63
+ return Path.join(xdgState || tmpdir(), Platform.applicationName, 'logs')
64
+ }
65
+
66
+ export const getUserSettingsPath = () => {
67
+ return Path.join(configDir, 'settings.json')
68
+ }
69
+
70
+ export const getUserKeyBindingsPath = () => {
71
+ return Path.join(configDir, 'keybindings.json')
72
+ }
73
+
74
+ export const getExtensionHostPath = async () => {
75
+ const { extensionHostPath } = await import(
76
+ '@lvce-editor/extension-host'
77
+ )
78
+ return extensionHostPath
79
+ }
80
+
81
+ export const getExtensionHostHelperProcessPath = async () => {
82
+ const { extensionHostHelperProcessPath } = await import(
83
+ '@lvce-editor/extension-host-helper-process'
84
+ )
85
+ return extensionHostHelperProcessPath
86
+ }
87
+
88
+ export const getRecentlyOpenedPath = () => {
89
+ return Path.join(cacheDir, 'recently-opened.json')
90
+ }
91
+
92
+ export const getDefaultSettingsPath = () => {
93
+ return Path.join(Root.root, 'config', 'defaultSettings.json')
94
+ }
95
+
96
+ export const getTestPath = () => {
97
+ if (env.TEST_PATH) {
98
+ const absolutePath = isAbsolute(env.TEST_PATH) ? env.TEST_PATH : Path.join(process.cwd(), env.TEST_PATH)
99
+ const testPath = '/remote' + pathToFileURL(absolutePath).toString().slice(7)
100
+ return testPath
101
+ }
102
+ return '/packages/extension-host-worker-tests'
103
+ }
104
+
105
+ export const getNodePath = () => {
106
+ return Process.argv[0]
107
+ }
108
+
109
+ export const getTmpDir = () => {
110
+ return tmpdir()
111
+ }
112
+
113
+ export const getOnlyExtensionPath = () => {
114
+ const onlyExtensionPath = env.ONLY_EXTENSION
115
+ if (onlyExtensionPath) {
116
+ return resolve(onlyExtensionPath)
117
+ }
118
+ return ''
119
+ }
120
+
121
+ export const getAppDir = () => {
122
+ return appDir
123
+ }
124
+
125
+ export const getCacheDir = () => {
126
+ return cacheDir
127
+ }
128
+
129
+ export const getConfigDir = () => {
130
+ return configDir
131
+ }
132
+
133
+ export const getDataDir = () => {
134
+ return dataDir
135
+ }
136
+
137
+ export const getHomeDir = () => {
138
+ return homeDir
139
+ }
140
+
141
+ export const getDownloadDir = () => {
142
+ const { XDG_DOWNLOAD_DIR } = env
143
+ return XDG_DOWNLOAD_DIR || join(homeDir, 'Downloads')
144
+ }
145
+
146
+ export const getRepository = () => {
147
+ return `lvce-editor/lvce-editor`
148
+ }
@@ -1,14 +1,13 @@
1
- import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
1
+ import * as IsEnoentError from '../IsEnoentError/IsEnoentError.js'
2
2
  import * as JsoncFile from '../JsoncFile/JsoncFile.js'
3
- import * as Platform from '../Platform/Platform.js'
3
+ import * as PlatformPaths from '../PlatformPaths/PlatformPaths.js'
4
4
  import * as Process from '../Process/Process.js'
5
- import * as IsEnoentError from '../IsEnoentError/IsEnoentError.js'
6
5
  import { VError } from '../VError/VError.js'
7
6
  // TODO need jsonc parser for settings with comments
8
7
 
9
8
  export const getUserPreferences = async () => {
10
9
  try {
11
- const userSettingsPath = Platform.getUserSettingsPath()
10
+ const userSettingsPath = PlatformPaths.getUserSettingsPath()
12
11
  let json
13
12
  try {
14
13
  json = await JsoncFile.readJsonc(userSettingsPath)
@@ -27,7 +26,7 @@ export const getUserPreferences = async () => {
27
26
  // TODO handle error
28
27
  export const getDefaultPreferences = async () => {
29
28
  try {
30
- const defaultSettingsPath = Platform.getDefaultSettingsPath()
29
+ const defaultSettingsPath = PlatformPaths.getDefaultSettingsPath()
31
30
  return await JsoncFile.readJsonc(defaultSettingsPath)
32
31
  } catch (error) {
33
32
  throw new VError(error, 'Failed to load default preferences')
@@ -2,10 +2,10 @@ import { dirname } from 'node:path'
2
2
  import * as Assert from '../Assert/Assert.js'
3
3
  import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
4
4
  import * as FileSystem from '../FileSystem/FileSystem.js'
5
+ import * as IsEnoentError from '../IsEnoentError/IsEnoentError.js'
5
6
  import * as Json from '../Json/Json.js'
6
7
  import * as JsonFile from '../JsonFile/JsonFile.js'
7
- import * as Platform from '../Platform/Platform.js'
8
- import * as IsEnoentError from '../IsEnoentError/IsEnoentError.js'
8
+ import * as PlatformPaths from '../PlatformPaths/PlatformPaths.js'
9
9
  import { VError } from '../VError/VError.js'
10
10
 
11
11
  const addToArrayUnique = (recentlyOpened, path) => {
@@ -49,7 +49,7 @@ const setRecentlyOpened = async (recentlyOpenedPath, newRecentlyOpened) => {
49
49
  export const addPath = async (path) => {
50
50
  try {
51
51
  Assert.string(path)
52
- const recentlyOpenedPath = Platform.getRecentlyOpenedPath()
52
+ const recentlyOpenedPath = PlatformPaths.getRecentlyOpenedPath()
53
53
  const parsed = await getRecentlyOpened(recentlyOpenedPath)
54
54
  const newRecentlyOpened = addToArrayUnique(parsed, path)
55
55
  await setRecentlyOpened(recentlyOpenedPath, newRecentlyOpened)
@@ -7,6 +7,7 @@ import * as IsAbsolutePath from '../IsAbsolutePath/IsAbsolutePath.js'
7
7
  import * as IsElectron from '../IsElectron/IsElectron.js'
8
8
  import * as ParentIpc from '../ParentIpc/ParentIpc.js'
9
9
  import * as Platform from '../Platform/Platform.js'
10
+ import * as PlatformPaths from '../PlatformPaths/PlatformPaths.js'
10
11
  import * as Root from '../Root/Root.js'
11
12
  import * as WorkspaceSource from '../WorkspaceSource/WorkspaceSource.js'
12
13
 
@@ -48,7 +49,7 @@ export const resolveRoot = async () => {
48
49
  path: last,
49
50
  uri: toUri(last),
50
51
  workspaceId: GetWorkspaceId.getWorkspaceId(last),
51
- homeDir: Platform.getHomeDir(),
52
+ homeDir: PlatformPaths.getHomeDir(),
52
53
  pathSeparator: Platform.getPathSeparator(),
53
54
  source: 'shared-process-default',
54
55
  }
@@ -63,7 +64,7 @@ export const resolveRoot = async () => {
63
64
  path,
64
65
  uri: toUri(path),
65
66
  workspaceId: GetWorkspaceId.getWorkspaceId(path),
66
- homeDir: Platform.getHomeDir(),
67
+ homeDir: PlatformPaths.getHomeDir(),
67
68
  pathSeparator: Platform.getPathSeparator(),
68
69
  source: WorkspaceSource.SharedProcessEnv,
69
70
  }
@@ -76,7 +77,7 @@ export const resolveRoot = async () => {
76
77
  path: absolutePath,
77
78
  uri: toUri(absolutePath),
78
79
  workspaceId,
79
- homeDir: Platform.getHomeDir(),
80
+ homeDir: PlatformPaths.getHomeDir(),
80
81
  pathSeparator: Platform.getPathSeparator(),
81
82
  source: WorkspaceSource.SharedProcessDefault,
82
83
  }
@@ -87,7 +88,7 @@ export const resolveUri = (uri) => {
87
88
  return {
88
89
  path,
89
90
  uri,
90
- homeDir: Platform.getHomeDir(),
91
+ homeDir: PlatformPaths.getHomeDir(),
91
92
  pathSeparator: Platform.getPathSeparator(),
92
93
  }
93
94
  }