@lvce-editor/shared-process 0.6.1 → 0.7.1
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/config/defaultKeyBindings.json +2 -1
- package/extensions/builtin.language-basics-dotenv/extension.json +2 -1
- package/extensions/builtin.language-basics-json/src/tokenizeJson.js +3 -1
- package/extensions/builtin.theme-slime/color-theme.json +4 -0
- package/package.json +4 -4
- package/src/parts/ExtensionInstall/ExtensionInstall.js +7 -5
- package/src/parts/ExtensionInstallFromFile/ExtensionInstallFromFile.js +39 -0
- package/src/parts/ExtensionInstallParseInput/ExtensionInstallParseInput.js +24 -12
- package/src/parts/ExtensionInstallType/ExtensionInstallType.js +7 -0
- package/src/parts/ExtensionLink/ExtensionLink.js +8 -0
- package/src/parts/Path/Path.js +8 -0
|
@@ -47,6 +47,7 @@ export const TokenType = {
|
|
|
47
47
|
Error: 18,
|
|
48
48
|
Unknown: 19,
|
|
49
49
|
Text: 20,
|
|
50
|
+
JsonPropertyValueString: 21,
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
export const TokenMap = {
|
|
@@ -70,6 +71,7 @@ export const TokenMap = {
|
|
|
70
71
|
[TokenType.NewLine]: 'NewLine',
|
|
71
72
|
[TokenType.Text]: 'Text',
|
|
72
73
|
[TokenType.Numeric]: 'Numeric',
|
|
74
|
+
[TokenType.JsonPropertyValueString]: 'JsonPropertyValueString',
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
const RE_SELECTOR = /^[\.a-zA-Z\d\-\:>]+/
|
|
@@ -205,7 +207,7 @@ export const tokenizeLine = (line, lineState) => {
|
|
|
205
207
|
break
|
|
206
208
|
case State.InsideString:
|
|
207
209
|
if ((next = part.match(RE_STRING_DOUBLE_QUOTE_CONTENT))) {
|
|
208
|
-
token = TokenType.
|
|
210
|
+
token = TokenType.JsonPropertyValueString
|
|
209
211
|
state = State.InsideString
|
|
210
212
|
} else if ((next = part.match(RE_DOUBLE_QUOTE))) {
|
|
211
213
|
token = TokenType.Punctuation
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/shared-process",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -20,13 +20,13 @@
|
|
|
20
20
|
"node": ">=16"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@lvce-editor/extension-host": "0.
|
|
24
|
-
"@lvce-editor/pty-host": "0.
|
|
23
|
+
"@lvce-editor/extension-host": "0.7.1",
|
|
24
|
+
"@lvce-editor/pty-host": "0.7.1",
|
|
25
25
|
"chokidar": "^3.5.3",
|
|
26
26
|
"debug": "^4.3.4",
|
|
27
27
|
"execa": "^6.1.0",
|
|
28
28
|
"exit-hook": "^3.1.0",
|
|
29
|
-
"got": "^12.5.
|
|
29
|
+
"got": "^12.5.1",
|
|
30
30
|
"is-object": "^1.0.2",
|
|
31
31
|
"json-parse-even-better-errors": "^2.3.1",
|
|
32
32
|
"jsonc-parser": "^3.2.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
|
|
6
|
+
case ExtensionInstallType.GithubRepository:
|
|
6
7
|
return import(
|
|
7
8
|
'../ExtensionInstallFromGitHub/ExtensionInstallFromGitHub.js'
|
|
8
9
|
)
|
|
9
|
-
case
|
|
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 ===
|
|
19
|
-
throw new Error(`
|
|
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
|
-
|
|
2
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
57
|
+
type: ExtensionInstallType.Url,
|
|
61
58
|
options: {
|
|
62
59
|
url: input,
|
|
63
60
|
},
|
|
64
61
|
}
|
|
65
62
|
}
|
|
66
63
|
return {
|
|
67
|
-
type:
|
|
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:
|
|
91
|
+
type: ExtensionInstallType.ParsingError,
|
|
80
92
|
options: {
|
|
81
93
|
message: 'Failed to parse input',
|
|
82
94
|
},
|
|
@@ -7,6 +7,10 @@ import * as SymLink from '../SymLink/SymLink.js'
|
|
|
7
7
|
|
|
8
8
|
const linkFallBack = async (path) => {
|
|
9
9
|
try {
|
|
10
|
+
const manifestPath = Path.join(path, 'extension.json')
|
|
11
|
+
if (!(await FileSystem.exists(manifestPath))) {
|
|
12
|
+
throw new Error('no extension manifest found')
|
|
13
|
+
}
|
|
10
14
|
const extensionsPath = Platform.getExtensionsPath()
|
|
11
15
|
const baseName = Path.basename(path)
|
|
12
16
|
const to = Path.join(extensionsPath, baseName)
|
|
@@ -19,6 +23,10 @@ const linkFallBack = async (path) => {
|
|
|
19
23
|
|
|
20
24
|
export const link = async (path) => {
|
|
21
25
|
try {
|
|
26
|
+
const manifestPath = Path.join(path, 'extension.json')
|
|
27
|
+
if (!(await FileSystem.exists(manifestPath))) {
|
|
28
|
+
throw new Error('no extension manifest found')
|
|
29
|
+
}
|
|
22
30
|
const extensionsPath = Platform.getExtensionsPath()
|
|
23
31
|
const baseName = Path.basename(path)
|
|
24
32
|
const to = Path.join(extensionsPath, baseName)
|
package/src/parts/Path/Path.js
CHANGED
|
@@ -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
|
+
}
|