@lvce-editor/shared-process 0.4.4 → 0.6.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.
Files changed (51) hide show
  1. package/config/builtinCommands.json +15 -2
  2. package/config/defaultKeyBindings.json +33 -0
  3. package/config/defaultSettings.json +7 -3
  4. package/extensions/builtin.language-basics-docker/extension.json +1 -1
  5. package/extensions/builtin.language-basics-docker/src/tokenizeDockerfile.js +29 -11
  6. package/extensions/builtin.language-basics-editorconfig/src/tokenizeEditorConfig.js +62 -11
  7. package/extensions/builtin.language-basics-gitattributes/src/tokenizeGitAttributes.js +32 -5
  8. package/extensions/builtin.language-basics-html/src/tokenizeHtml.js +7 -2
  9. package/extensions/builtin.language-basics-javascript/extension.json +1 -1
  10. package/extensions/builtin.language-basics-javascript/src/tokenizeJavaScript.js +11 -7
  11. package/extensions/builtin.language-basics-json/extension.json +3 -2
  12. package/extensions/builtin.language-basics-json/src/tokenizeJson.js +11 -24
  13. package/extensions/builtin.language-basics-nvmrc/README.md +14 -0
  14. package/extensions/builtin.language-basics-nvmrc/extension.json +12 -0
  15. package/extensions/builtin.language-basics-nvmrc/src/tokenizeNvmrc.js +30 -0
  16. package/extensions/builtin.language-basics-plaintext/src/tokenizePlaintext.js +4 -7
  17. package/extensions/builtin.language-basics-rust/README.md +14 -0
  18. package/extensions/builtin.language-basics-rust/extension.json +12 -0
  19. package/extensions/builtin.language-basics-rust/src/tokenizeRust.js +158 -0
  20. package/extensions/builtin.language-basics-shellscript/src/tokenizeShellScript.js +37 -7
  21. package/extensions/builtin.language-basics-toml/extension.json +1 -1
  22. package/extensions/builtin.language-basics-toml/src/tokenizeToml.js +93 -8
  23. package/extensions/builtin.language-basics-yaml/src/tokenizeYaml.js +138 -10
  24. package/extensions/builtin.vscode-icons/icon-theme.json +14 -0
  25. package/extensions/builtin.vscode-icons/icons/file_type_master-co.svg +1 -0
  26. package/extensions/builtin.vscode-icons/icons/file_type_wgsl.svg +86 -0
  27. package/package.json +8 -7
  28. package/src/parts/Cli/Cli.js +24 -0
  29. package/src/parts/CliInstall/CliInstall.js +10 -0
  30. package/src/parts/CliLink/CliLink.js +6 -0
  31. package/src/parts/CliList/CliList.js +15 -0
  32. package/src/parts/Download/Download.js +5 -13
  33. package/src/parts/DownloadAndExtract/DownloadAndExtract.js +14 -0
  34. package/src/parts/Error/FileSystemError.js +10 -0
  35. package/src/parts/ExtensionInstall/ExtensionInstall.ipc.js +6 -0
  36. package/src/parts/ExtensionInstall/ExtensionInstall.js +25 -0
  37. package/src/parts/ExtensionInstallFromGitHub/ExtensionInstallFromGitHub.js +34 -0
  38. package/src/parts/ExtensionInstallFromUrl/ExtensionInstallFromUrl.js +32 -0
  39. package/src/parts/ExtensionInstallParseInput/ExtensionInstallParseInput.js +84 -0
  40. package/src/parts/ExtensionLink/ExtensionLink.js +32 -0
  41. package/src/parts/ExtensionList/ExtensionList.js +66 -0
  42. package/src/parts/ExtensionManagement/ExtensionManagement.js +4 -3
  43. package/src/parts/ExtensionUninstall/ExtensionUninstall.js +0 -0
  44. package/src/parts/Extract/Extract.js +34 -0
  45. package/src/parts/FileSystem/FileSystem.js +21 -2
  46. package/src/parts/FileSystemErrorCodes/FileSystemErrorCodes.js +4 -0
  47. package/src/parts/Path/Path.js +4 -0
  48. package/src/parts/Preferences/Preferences.js +17 -1
  49. package/src/parts/SymLink/SymLink.js +15 -0
  50. package/src/parts/TmpFile/TmpFile.js +15 -0
  51. package/src/sharedProcessMain.js +16 -5
@@ -51,11 +51,17 @@ export const readFile = async (path) => {
51
51
  }
52
52
  }
53
53
 
54
- export const writeFile = async (path, content) => {
54
+ /**
55
+ *
56
+ * @param {string} path
57
+ * @param {string} content
58
+ * @param {BufferEncoding} encoding
59
+ */
60
+ export const writeFile = async (path, content, encoding = 'utf8') => {
55
61
  try {
56
62
  // queue would be more correct for concurrent writes but also slower
57
63
  // Queue.add(`writeFile/${path}`, () =>
58
- await fs.writeFile(path, content)
64
+ await fs.writeFile(path, content, encoding)
59
65
  } catch (error) {
60
66
  if (error && error.code === FileSystemErrorCodes.ENOENT) {
61
67
  throw new FileNotFoundError(path)
@@ -179,10 +185,22 @@ export const mkdir = async (path) => {
179
185
  }
180
186
  }
181
187
 
188
+ const fallbackRename = async (oldPath, newPath) => {
189
+ try {
190
+ await fs.cp(oldPath, newPath, { recursive: true })
191
+ await fs.rm(oldPath, { recursive: true })
192
+ } catch (error) {
193
+ throw new VError(error, `Failed to rename "${oldPath}" to "${newPath}"`)
194
+ }
195
+ }
196
+
182
197
  export const rename = async (oldPath, newPath) => {
183
198
  try {
184
199
  await fs.rename(oldPath, newPath)
185
200
  } catch (error) {
201
+ if (error && error.code === FileSystemErrorCodes.EXDEV) {
202
+ return fallbackRename(oldPath, newPath)
203
+ }
186
204
  throw new VError(error, `Failed to rename "${oldPath}" to "${newPath}"`)
187
205
  }
188
206
  }
@@ -214,6 +232,7 @@ export const getRealPath = async (path) => {
214
232
  if (
215
233
  error &&
216
234
  error instanceof globalThis.Error &&
235
+ // @ts-ignore
217
236
  error.code === FileSystemErrorCodes.ENOENT
218
237
  ) {
219
238
  let content
@@ -1 +1,5 @@
1
1
  export const ENOENT = 'ENOENT'
2
+
3
+ export const EXDEV = 'EXDEV'
4
+
5
+ export const EEXIST = 'EEXIST'
@@ -15,3 +15,7 @@ export const join = (...parts) => {
15
15
  export const dirname = (path) => {
16
16
  return NodePath.dirname(path)
17
17
  }
18
+
19
+ export const basename = (path) => {
20
+ return NodePath.basename(path)
21
+ }
@@ -37,6 +37,17 @@ export const getDefaultPreferences = async () => {
37
37
  // TODO efficiently load preferences -> first load cached preferences
38
38
  // -> on idle check preferences
39
39
 
40
+ const getOverrides = () => {
41
+ const argvSliced = process.argv.slice(2)
42
+ const overrides = {}
43
+ for (const argv of argvSliced) {
44
+ console.log({ argv })
45
+ if (argv.startsWith('--theme=')) {
46
+ overrides['workbench.colorTheme'] = argv.slice('--theme='.length)
47
+ }
48
+ }
49
+ return overrides
50
+ }
40
51
  // TODO compare with timestamp/hash that preferences are fresh
41
52
  export const getAll = async () => {
42
53
  try {
@@ -50,8 +61,13 @@ export const getAll = async () => {
50
61
  // }
51
62
  const defaultPreferences = await getDefaultPreferences()
52
63
  const userPreferences = await getUserPreferences()
64
+ const overrides = getOverrides()
53
65
  // TODO separate backend and frontend preferences, ui only needs frontend preferences
54
- const preferences = { ...defaultPreferences, ...userPreferences }
66
+ const preferences = {
67
+ ...defaultPreferences,
68
+ ...userPreferences,
69
+ ...overrides,
70
+ }
55
71
  // try {
56
72
  // await mkdir(dirname(CACHED_SETTINGS_PATH), { recursive: true })
57
73
  // await writeFile(
@@ -0,0 +1,15 @@
1
+ import { symlink } from 'node:fs/promises'
2
+ import { FileSystemError } from '../Error/FileSystemError.js'
3
+
4
+ // TODO maybe move this to FileSystem module
5
+
6
+ export const createSymLink = async (target, path) => {
7
+ try {
8
+ await symlink(target, path)
9
+ } catch (error) {
10
+ throw new FileSystemError(
11
+ error,
12
+ `Failed to create symbolic link from ${target} to ${path}`
13
+ )
14
+ }
15
+ }
@@ -0,0 +1,15 @@
1
+ import { file, dir } from 'tmp-promise'
2
+
3
+ export const getTmpFile = async () => {
4
+ const { path } = await file({
5
+ prefix: 'lvce-extension-',
6
+ })
7
+ return path
8
+ }
9
+
10
+ export const getTmpDir = async () => {
11
+ const { path } = await dir({
12
+ prefix: 'lvce-extension-',
13
+ })
14
+ return path
15
+ }
@@ -37,22 +37,33 @@ const handleDisconnect = () => {
37
37
  console.info('[shared process] disconnected')
38
38
  }
39
39
 
40
- const handleBeforeExit = () => {
41
- console.info('[shared process] will exit now')
42
- }
40
+ // const handleBeforeExit = () => {
41
+ // console.info('[shared process] will exit now')
42
+ // }
43
43
 
44
44
  const handleSigTerm = () => {
45
45
  console.info('[shared-process] sigterm')
46
46
  }
47
47
 
48
- const main = () => {
48
+ const knownCliArgs = ['install', 'list', 'link']
49
+
50
+ const main = async () => {
51
+ const argv = process.argv.slice(2)
52
+ const argv0 = argv[0]
53
+ if (knownCliArgs.includes(argv0)) {
54
+ const module = await import('./parts/Cli/Cli.js')
55
+ await module.handleCliArgs(argv, console, process)
56
+ return
57
+ }
58
+
49
59
  console.log('[shared process] started')
50
- process.on('beforeExit', handleBeforeExit)
60
+ // process.on('beforeExit', handleBeforeExit)
51
61
  process.on('disconnect', handleDisconnect)
52
62
  process.on('SIGTERM', handleSigTerm)
53
63
 
54
64
  process.on('uncaughtExceptionMonitor', handleUncaughtExceptionMonitor)
55
65
  ParentIpc.listen()
66
+
56
67
  // ExtensionHost.start() // TODO start on demand, e.g. not when extensions should be disabled
57
68
  }
58
69