@lvce-editor/shared-process 0.4.3 → 0.4.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/shared-process",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -38,8 +38,8 @@
38
38
  "verror": "^1.10.1",
39
39
  "ws": "^8.8.1",
40
40
  "xdg-basedir": "^5.1.0",
41
- "@lvce-editor/pty-host": "0.4.3",
42
- "@lvce-editor/extension-host": "0.4.3"
41
+ "@lvce-editor/pty-host": "0.4.4",
42
+ "@lvce-editor/extension-host": "0.4.4"
43
43
  },
44
44
  "optionalDependencies": {
45
45
  "electron-clipboard-ex": "^1.3.3",
@@ -0,0 +1,8 @@
1
+ import VError from 'verror'
2
+
3
+ export class FileNotFoundError extends VError {
4
+ constructor(path) {
5
+ super(`File not found '${path}'`)
6
+ this.name = 'FileNotFoundError'
7
+ }
8
+ }
@@ -7,6 +7,7 @@ import * as Path from '../Path/Path.js'
7
7
  import * as Platform from '../Platform/Platform.js'
8
8
  import * as Trash from '../Trash/Trash.js'
9
9
  import * as FileSystemErrorCodes from '../FileSystemErrorCodes/FileSystemErrorCodes.js'
10
+ import { FileNotFoundError } from '../Error/FileNotFoundError.js'
10
11
 
11
12
  export const state = {
12
13
  watcherMap: Object.create(null),
@@ -44,7 +45,7 @@ export const readFile = async (path) => {
44
45
  return content
45
46
  } catch (error) {
46
47
  if (error && error.code === FileSystemErrorCodes.ENOENT) {
47
- throw new VError(`File not found '${path}'`)
48
+ throw new FileNotFoundError(path)
48
49
  }
49
50
  throw new VError(error, `Failed to read file "${path}"`)
50
51
  }
@@ -57,7 +58,7 @@ export const writeFile = async (path, content) => {
57
58
  await fs.writeFile(path, content)
58
59
  } catch (error) {
59
60
  if (error && error.code === FileSystemErrorCodes.ENOENT) {
60
- throw new VError(`File not found '${path}'`)
61
+ throw new FileNotFoundError(path)
61
62
  }
62
63
  throw new VError(error, `Failed to write to file "${path}"`)
63
64
  }
@@ -210,7 +211,11 @@ export const getRealPath = async (path) => {
210
211
  return await fs.realpath(path)
211
212
  } catch (error) {
212
213
  // @ts-ignore
213
- if (error && error instanceof globalThis.Error && error.code === 'ENOENT') {
214
+ if (
215
+ error &&
216
+ error instanceof globalThis.Error &&
217
+ error.code === FileSystemErrorCodes.ENOENT
218
+ ) {
214
219
  let content
215
220
  try {
216
221
  content = await fs.readlink(path)
@@ -1,5 +1,7 @@
1
+ import { dirname } from 'path'
1
2
  import VError from 'verror'
2
3
  import * as Assert from '../Assert/Assert.js'
4
+ import { FileNotFoundError } from '../Error/FileNotFoundError.js'
3
5
  import * as FileSystem from '../FileSystem/FileSystem.js'
4
6
  import * as Json from '../Json/Json.js'
5
7
  import * as Platform from '../Platform/Platform.js'
@@ -40,13 +42,26 @@ const getRecentlyOpened = async (recentlyOpenedPath) => {
40
42
 
41
43
  const setRecentlyOpened = async (recentlyOpenedPath, newRecentlyOpened) => {
42
44
  const stringified = Json.stringify(newRecentlyOpened)
43
- await FileSystem.writeFile(recentlyOpenedPath, stringified)
45
+ try {
46
+ await FileSystem.writeFile(recentlyOpenedPath, stringified)
47
+ } catch (error) {
48
+ if (error && error instanceof FileNotFoundError) {
49
+ await FileSystem.mkdir(dirname(recentlyOpenedPath))
50
+ await FileSystem.writeFile(recentlyOpenedPath, stringified)
51
+ return
52
+ }
53
+ throw error
54
+ }
44
55
  }
45
56
 
46
57
  export const addPath = async (path) => {
47
- Assert.string(path)
48
- const recentlyOpenedPath = Platform.getRecentlyOpenedPath()
49
- const parsed = await getRecentlyOpened(recentlyOpenedPath)
50
- const newRecentlyOpened = addToArrayUnique(parsed, path)
51
- await setRecentlyOpened(recentlyOpenedPath, newRecentlyOpened)
58
+ try {
59
+ Assert.string(path)
60
+ const recentlyOpenedPath = Platform.getRecentlyOpenedPath()
61
+ const parsed = await getRecentlyOpened(recentlyOpenedPath)
62
+ const newRecentlyOpened = addToArrayUnique(parsed, path)
63
+ await setRecentlyOpened(recentlyOpenedPath, newRecentlyOpened)
64
+ } catch (error) {
65
+ throw new VError(error, `Failed to add path to recently opened`)
66
+ }
52
67
  }