@lvce-editor/shared-process 0.21.6 → 0.21.7
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 +4 -4
- package/src/parts/GetElectronFileResponse/GetElectronFileResponse.js +13 -7
- package/src/parts/GetElectronFileResponseContent/GetElectronFileResponseContent.js +30 -0
- package/src/parts/GetElectronFileResponseRelativePath/GetElectronFileResponseRelativePath.js +8 -2
- package/src/parts/GetMimeType/GetMimeType.js +1 -0
- package/src/parts/GetTypeScriptPath/GetTypeScriptPath.js +6 -0
- package/src/parts/HandleRemoteRequest/HandleRemoteRequest.ipc.js +7 -0
- package/src/parts/HandleRemoteRequest/HandleRemoteRequest.js +17 -0
- package/src/parts/HttpStatusCode/HttpStatusCode.js +1 -0
- package/src/parts/IsTypeScriptPath/IsTypeScriptPath.js +3 -0
- package/src/parts/LoadTypeScript/LoadTypeScript.js +14 -0
- package/src/parts/Module/Module.js +2 -0
- package/src/parts/ModuleId/ModuleId.js +1 -0
- package/src/parts/ModuleMap/ModuleMap.js +2 -0
- package/src/parts/Platform/Platform.js +3 -3
- package/src/parts/TranspileTypeScript/TranspileTypeScript.js +24 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/shared-process",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.7",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/code-frame": "^7.23.5",
|
|
21
21
|
"@lvce-editor/assert": "^1.0.1",
|
|
22
|
-
"@lvce-editor/extension-host": "0.21.
|
|
23
|
-
"@lvce-editor/extension-host-helper-process": "0.21.
|
|
22
|
+
"@lvce-editor/extension-host": "0.21.7",
|
|
23
|
+
"@lvce-editor/extension-host-helper-process": "0.21.7",
|
|
24
24
|
"@lvce-editor/json-rpc": "^0.4.0",
|
|
25
25
|
"@lvce-editor/jsonc-parser": "^1.1.0",
|
|
26
26
|
"@lvce-editor/pretty-error": "^1.3.0",
|
|
27
|
-
"@lvce-editor/pty-host": "0.21.
|
|
27
|
+
"@lvce-editor/pty-host": "0.21.7",
|
|
28
28
|
"@lvce-editor/verror": "^1.1.2",
|
|
29
29
|
"debug": "^4.3.4",
|
|
30
30
|
"execa": "^8.0.1",
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises'
|
|
2
1
|
import * as GetElectronFileResponseAbsolutePath from '../GetElectronFileResponseAbsolutePath/GetElectronFileResponseAbsolutePath.js'
|
|
2
|
+
import * as GetElectronFileResponseContent from '../GetElectronFileResponseContent/GetElectronFileResponseContent.js'
|
|
3
3
|
import * as GetElectronFileResponseRelativePath from '../GetElectronFileResponseRelativePath/GetElectronFileResponseRelativePath.js'
|
|
4
4
|
import * as GetHeaders from '../GetHeaders/GetHeaders.js'
|
|
5
5
|
import * as HttpStatusCode from '../HttpStatusCode/HttpStatusCode.js'
|
|
6
6
|
import * as IsEnoentError from '../IsEnoentError/IsEnoentError.js'
|
|
7
|
-
import * as
|
|
7
|
+
import * as Logger from '../Logger/Logger.js'
|
|
8
8
|
|
|
9
9
|
export const getElectronFileResponse = async (url) => {
|
|
10
10
|
try {
|
|
11
11
|
const pathName = GetElectronFileResponseRelativePath.getElectronFileResponseRelativePath(url)
|
|
12
12
|
const absolutePath = GetElectronFileResponseAbsolutePath.getElectronFileResponseAbsolutePath(pathName)
|
|
13
|
-
|
|
14
|
-
if (!Platform.isProduction && url === `${Platform.scheme}://-/`) {
|
|
15
|
-
// @ts-ignore
|
|
16
|
-
content = content.toString().replace(' <link rel="manifest" href="/manifest.json" crossorigin="use-credentials" />\n', '')
|
|
17
|
-
}
|
|
13
|
+
const content = await GetElectronFileResponseContent.getElectronFileResponseContent(absolutePath, url)
|
|
18
14
|
const headers = GetHeaders.getHeaders(absolutePath)
|
|
19
15
|
return {
|
|
20
16
|
body: content,
|
|
@@ -30,8 +26,18 @@ export const getElectronFileResponse = async (url) => {
|
|
|
30
26
|
init: {
|
|
31
27
|
status: HttpStatusCode.NotFound,
|
|
32
28
|
statusText: 'not-found',
|
|
29
|
+
headers: {},
|
|
33
30
|
},
|
|
34
31
|
}
|
|
35
32
|
}
|
|
33
|
+
Logger.error(error)
|
|
34
|
+
return {
|
|
35
|
+
body: 'server-error',
|
|
36
|
+
init: {
|
|
37
|
+
status: HttpStatusCode.ServerError,
|
|
38
|
+
statusText: 'server-error',
|
|
39
|
+
headers: {},
|
|
40
|
+
},
|
|
41
|
+
}
|
|
36
42
|
}
|
|
37
43
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises'
|
|
2
|
+
import * as IsTypeScriptPath from '../IsTypeScriptPath/IsTypeScriptPath.js'
|
|
3
|
+
import * as Platform from '../Platform/Platform.js'
|
|
4
|
+
import * as Preferences from '../Preferences/Preferences.js'
|
|
5
|
+
import * as TranspileTypeScript from '../TranspileTypeScript/TranspileTypeScript.js'
|
|
6
|
+
|
|
7
|
+
let cachedPreferences = undefined
|
|
8
|
+
|
|
9
|
+
const getPreferences = () => {
|
|
10
|
+
if (!cachedPreferences) {
|
|
11
|
+
cachedPreferences = Preferences.getAll()
|
|
12
|
+
}
|
|
13
|
+
return cachedPreferences
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const getElectronFileResponseContent = async (absolutePath, url) => {
|
|
17
|
+
let content = await readFile(absolutePath)
|
|
18
|
+
if (IsTypeScriptPath.isTypeScriptPath(url)) {
|
|
19
|
+
const preferences = await getPreferences()
|
|
20
|
+
if (preferences['typescript.transpile']) {
|
|
21
|
+
const newContent = await TranspileTypeScript.transpileTypeScript(content.toString())
|
|
22
|
+
content = newContent.outputText
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (!Platform.isProduction && url === `${Platform.scheme}://-/`) {
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
content = content.toString().replace(' <link rel="manifest" href="/manifest.json" crossorigin="use-credentials" />\n', '')
|
|
28
|
+
}
|
|
29
|
+
return content
|
|
30
|
+
}
|
package/src/parts/GetElectronFileResponseRelativePath/GetElectronFileResponseRelativePath.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import * as Platform from '../Platform/Platform.js'
|
|
2
2
|
|
|
3
|
+
const { scheme } = Platform
|
|
4
|
+
const prefix = `${scheme}://-`
|
|
5
|
+
const prefixLength = prefix.length
|
|
6
|
+
|
|
3
7
|
export const getElectronFileResponseRelativePath = (requestUrl) => {
|
|
8
|
+
if (requestUrl.startsWith('/')) {
|
|
9
|
+
return requestUrl
|
|
10
|
+
}
|
|
4
11
|
const decoded = decodeURI(requestUrl)
|
|
5
|
-
const
|
|
6
|
-
const pathName = decoded.slice(`${scheme}://-`.length)
|
|
12
|
+
const pathName = decoded.slice(prefixLength)
|
|
7
13
|
return pathName
|
|
8
14
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ServerResponse } from 'node:http'
|
|
2
|
+
import * as Assert from '../Assert/Assert.js'
|
|
3
|
+
import * as GetElectronFileResponse from '../GetElectronFileResponse/GetElectronFileResponse.js'
|
|
4
|
+
|
|
5
|
+
export const handleRemoteRequest = async (request, socket) => {
|
|
6
|
+
Assert.object(request)
|
|
7
|
+
Assert.object(socket)
|
|
8
|
+
const response = new ServerResponse(request)
|
|
9
|
+
response.assignSocket(socket)
|
|
10
|
+
const result = await GetElectronFileResponse.getElectronFileResponse(request.url)
|
|
11
|
+
response.statusCode = result.init.status
|
|
12
|
+
for (const [key, value] of Object.entries(result.init.headers)) {
|
|
13
|
+
response.setHeader(key, value)
|
|
14
|
+
}
|
|
15
|
+
response.setHeader('Connection', 'close')
|
|
16
|
+
response.end(result.body)
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { VError } from '@lvce-editor/verror'
|
|
2
|
+
|
|
3
|
+
export const loadTypeScript = async (typescriptPath) => {
|
|
4
|
+
try {
|
|
5
|
+
const typescript = await import(typescriptPath)
|
|
6
|
+
const actual = typescript.default
|
|
7
|
+
if (!actual) {
|
|
8
|
+
throw new Error('missing default export')
|
|
9
|
+
}
|
|
10
|
+
return actual
|
|
11
|
+
} catch (error) {
|
|
12
|
+
throw new VError(error, `Failed to load typescript`)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -136,6 +136,8 @@ export const load = (moduleId) => {
|
|
|
136
136
|
return import('../TemporaryMessagePort/TemporaryMessagePort.ipc.js')
|
|
137
137
|
case ModuleId.GetElectronFileResponse:
|
|
138
138
|
return import('../GetElectronFileResponse/GetElectronFileResponse.ipc.js')
|
|
139
|
+
case ModuleId.HandleRemoteRequest:
|
|
140
|
+
return import('../HandleRemoteRequest/HandleRemoteRequest.ipc.js')
|
|
139
141
|
default:
|
|
140
142
|
throw new Error(`module ${moduleId} not found`)
|
|
141
143
|
}
|
|
@@ -291,6 +291,8 @@ export const getModuleId = (commandId) => {
|
|
|
291
291
|
return ModuleId.TemporaryMessagePort
|
|
292
292
|
case 'GetElectronFileResponse.getElectronFileResponse':
|
|
293
293
|
return ModuleId.GetElectronFileResponse
|
|
294
|
+
case 'HandleRemoteRequest.handleRemoteRequest':
|
|
295
|
+
return ModuleId.HandleRemoteRequest
|
|
294
296
|
default:
|
|
295
297
|
throw new CommandNotFoundError(commandId)
|
|
296
298
|
}
|
|
@@ -61,11 +61,11 @@ export const getSetupName = () => {
|
|
|
61
61
|
return 'Lvce-Setup'
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
export const version = '0.21.
|
|
64
|
+
export const version = '0.21.7'
|
|
65
65
|
|
|
66
|
-
export const commit = '
|
|
66
|
+
export const commit = '6005be2'
|
|
67
67
|
|
|
68
|
-
export const date = '2023-12-
|
|
68
|
+
export const date = '2023-12-26T09:19:09.000Z'
|
|
69
69
|
|
|
70
70
|
export const getVersion = () => {
|
|
71
71
|
return version
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { VError } from '@lvce-editor/verror'
|
|
2
|
+
import * as GetTypeScriptPath from '../GetTypeScriptPath/GetTypeScriptPath.js'
|
|
3
|
+
import * as Assert from '../Assert/Assert.js'
|
|
4
|
+
import * as LoadTypeScript from '../LoadTypeScript/LoadTypeScript.js'
|
|
5
|
+
|
|
6
|
+
export const transpileTypeScript = async (code) => {
|
|
7
|
+
try {
|
|
8
|
+
Assert.string(code)
|
|
9
|
+
const typescriptPath = GetTypeScriptPath.getTypeScriptPath()
|
|
10
|
+
console.log({ typescriptPath })
|
|
11
|
+
const typescript = await LoadTypeScript.loadTypeScript(typescriptPath)
|
|
12
|
+
console.log({ k: Object.keys(typescript) })
|
|
13
|
+
const newContent = await typescript.transpileModule(code, {
|
|
14
|
+
compilerOptions: {
|
|
15
|
+
target: 'esnext',
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
console.log({ newContent })
|
|
19
|
+
return newContent
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.log({ error })
|
|
22
|
+
throw new VError(error, `Failed to transpile typescript`)
|
|
23
|
+
}
|
|
24
|
+
}
|