@lvce-editor/shared-process 0.6.1 → 0.7.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/shared-process",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -20,8 +20,8 @@
20
20
  "node": ">=16"
21
21
  },
22
22
  "dependencies": {
23
- "@lvce-editor/extension-host": "0.6.1",
24
- "@lvce-editor/pty-host": "0.6.1",
23
+ "@lvce-editor/extension-host": "0.7.0",
24
+ "@lvce-editor/pty-host": "0.7.0",
25
25
  "chokidar": "^3.5.3",
26
26
  "debug": "^4.3.4",
27
27
  "execa": "^6.1.0",
@@ -1,13 +1,16 @@
1
1
  import * as ExtensionInstallParseInput from '../ExtensionInstallParseInput/ExtensionInstallParseInput.js'
2
+ import * as ExtensionInstallType from '../ExtensionInstallType/ExtensionInstallType.js'
2
3
 
3
4
  const getModule = (type) => {
4
5
  switch (type) {
5
- case ExtensionInstallParseInput.InstallType.GithubRepository:
6
+ case ExtensionInstallType.GithubRepository:
6
7
  return import(
7
8
  '../ExtensionInstallFromGitHub/ExtensionInstallFromGitHub.js'
8
9
  )
9
- case ExtensionInstallParseInput.InstallType.Url:
10
+ case ExtensionInstallType.Url:
10
11
  return import('../ExtensionInstallFromUrl/ExtensionInstallFromUrl.js')
12
+ case ExtensionInstallType.File:
13
+ return import('../ExtensionInstallFromFile/ExtensionInstallFromFile.js')
11
14
  default:
12
15
  throw new Error('module not found')
13
16
  }
@@ -15,10 +18,9 @@ const getModule = (type) => {
15
18
 
16
19
  export const install = async (input) => {
17
20
  const parsed = ExtensionInstallParseInput.parse(input)
18
- if (parsed.type === ExtensionInstallParseInput.InstallType.ParsingError) {
19
- throw new Error(`Failed to parse input: ${parsed.options.message}`)
21
+ if (parsed.type === ExtensionInstallType.ParsingError) {
22
+ throw new Error(`Cannot install ${input}: ${parsed.options.message}`)
20
23
  }
21
- console.log({ parsed })
22
24
  const module = await getModule(parsed.type)
23
25
  // @ts-ignore
24
26
  await module.install(parsed.options)
@@ -0,0 +1,39 @@
1
+ import VError from 'verror'
2
+ import * as Assert from '../Assert/Assert.js'
3
+ import * as Extract from '../Extract/Extract.js'
4
+ import * as FileSystem from '../FileSystem/FileSystem.js'
5
+ import * as Path from '../Path/Path.js'
6
+ import * as Platform from '../Platform/Platform.js'
7
+
8
+ const getCachedExtensionFolderName = (path) => {
9
+ const baseName = Path.basename(path)
10
+ if (baseName.endsWith('.tar.br')) {
11
+ return 'file-' + baseName.slice(0, -'.tar.br'.length)
12
+ }
13
+ return `file-${baseName}`
14
+ }
15
+
16
+ export const install = async ({ path }) => {
17
+ try {
18
+ const cachedExtensionsPath = Platform.getCachedExtensionsPath()
19
+ const cachedExtensionFolderName = getCachedExtensionFolderName(path)
20
+ const cachedExtensionPath = Path.join(
21
+ cachedExtensionsPath,
22
+ cachedExtensionFolderName
23
+ )
24
+ await Extract.extractTarBr(path, cachedExtensionPath)
25
+ const extensionsPath = Platform.getExtensionsPath()
26
+ const manifestPath = Path.join(cachedExtensionPath, 'extension.json')
27
+ const manifestContent = await FileSystem.readFile(manifestPath)
28
+ const manifestJson = JSON.parse(manifestContent)
29
+ const id = manifestJson.id
30
+ if (!id) {
31
+ throw new Error('missing id in extension manifest')
32
+ }
33
+ const outDir = Path.join(extensionsPath, id)
34
+ await FileSystem.remove(outDir)
35
+ await FileSystem.rename(cachedExtensionPath, outDir)
36
+ } catch (error) {
37
+ throw new VError(error, `Failed to install ${path}`)
38
+ }
39
+ }
@@ -1,8 +1,5 @@
1
- export const InstallType = {
2
- Url: 1,
3
- GithubRepository: 2,
4
- ParsingError: 3,
5
- }
1
+ import * as ExtensionInstallType from '../ExtensionInstallType/ExtensionInstallType.js'
2
+ import * as Path from '../Path/Path.js'
6
3
 
7
4
  const parseUrlGithub = (input) => {
8
5
  const parts = input.split('/')
@@ -11,7 +8,7 @@ const parseUrlGithub = (input) => {
11
8
  const user = parts[3]
12
9
  const repo = parts[4]
13
10
  return {
14
- type: InstallType.GithubRepository,
11
+ type: ExtensionInstallType.GithubRepository,
15
12
  options: {
16
13
  user,
17
14
  repo,
@@ -26,7 +23,7 @@ const parseUrlGithub = (input) => {
26
23
  const commit = parts[6]
27
24
  if (type === 'tree') {
28
25
  return {
29
- type: InstallType.GithubRepository,
26
+ type: ExtensionInstallType.GithubRepository,
30
27
  options: {
31
28
  user,
32
29
  repo,
@@ -36,7 +33,7 @@ const parseUrlGithub = (input) => {
36
33
  }
37
34
  if (type === 'pull') {
38
35
  return {
39
- type: InstallType.ParsingError,
36
+ type: ExtensionInstallType.ParsingError,
40
37
  options: {
41
38
  message: 'Cannot download from Pull Request',
42
39
  },
@@ -44,7 +41,7 @@ const parseUrlGithub = (input) => {
44
41
  }
45
42
  }
46
43
  return {
47
- type: InstallType.ParsingError,
44
+ type: ExtensionInstallType.ParsingError,
48
45
  options: {
49
46
  message: 'Failed to parse github url',
50
47
  },
@@ -57,26 +54,41 @@ const parseUrl = (input) => {
57
54
  }
58
55
  if (input.endsWith('.tar.br')) {
59
56
  return {
60
- type: InstallType.Url,
57
+ type: ExtensionInstallType.Url,
61
58
  options: {
62
59
  url: input,
63
60
  },
64
61
  }
65
62
  }
66
63
  return {
67
- type: InstallType.ParsingError,
64
+ type: ExtensionInstallType.ParsingError,
68
65
  options: {
69
66
  message: 'Failed to parse url',
70
67
  },
71
68
  }
72
69
  }
73
70
 
71
+ const parseFile = (input) => {
72
+ return {
73
+ type: ExtensionInstallType.File,
74
+ options: {
75
+ path: input,
76
+ },
77
+ }
78
+ }
79
+
74
80
  export const parse = (input) => {
75
81
  if (input.startsWith('https://')) {
76
82
  return parseUrl(input)
77
83
  }
84
+ if (input.startsWith('.')) {
85
+ return parseFile(input)
86
+ }
87
+ if (Path.isAbsolute(input)) {
88
+ return parseFile(input)
89
+ }
78
90
  return {
79
- type: InstallType.ParsingError,
91
+ type: ExtensionInstallType.ParsingError,
80
92
  options: {
81
93
  message: 'Failed to parse input',
82
94
  },
@@ -0,0 +1,7 @@
1
+ export const Url = 1
2
+
3
+ export const GithubRepository = 2
4
+
5
+ export const ParsingError = 3
6
+
7
+ export const File = 4
@@ -19,3 +19,11 @@ export const dirname = (path) => {
19
19
  export const basename = (path) => {
20
20
  return NodePath.basename(path)
21
21
  }
22
+
23
+ export const resolve = (path) => {
24
+ return NodePath.resolve(path)
25
+ }
26
+
27
+ export const isAbsolute = (path) => {
28
+ return NodePath.isAbsolute(path)
29
+ }