@lvce-editor/shared-process 0.21.5 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/shared-process",
3
- "version": "0.21.5",
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.5",
23
- "@lvce-editor/extension-host-helper-process": "0.21.5",
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.5",
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",
@@ -41,7 +41,7 @@
41
41
  "optionalDependencies": {
42
42
  "@lvce-editor/ripgrep": "^1.0.1",
43
43
  "extract-zip": "^2.0.1",
44
- "open": "^10.0.0",
44
+ "open": "^10.0.1",
45
45
  "symlink-dir": "^5.2.0",
46
46
  "tail": "^2.2.6",
47
47
  "tmp-promise": "^3.0.3",
@@ -185,7 +185,6 @@ const applyOverrides = async ({ root, commitHash, pathPrefix }) => {
185
185
  )
186
186
  }
187
187
  await replace(Path.join(root, 'dist', 'index.html'), `/${commitHash}`, `${pathPrefix}/${commitHash}`)
188
- await replace(Path.join(root, 'dist', 'index.html'), `/${commitHash}/manifest.json`, `${pathPrefix}/${commitHash}/manifest.json`)
189
188
 
190
189
  if (pathPrefix) {
191
190
  await replace(
@@ -1,23 +1,43 @@
1
- import { readFile } from '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
- import * as Platform from '../Platform/Platform.js'
5
+ import * as HttpStatusCode from '../HttpStatusCode/HttpStatusCode.js'
6
+ import * as IsEnoentError from '../IsEnoentError/IsEnoentError.js'
7
+ import * as Logger from '../Logger/Logger.js'
6
8
 
7
9
  export const getElectronFileResponse = async (url) => {
8
- const pathName = GetElectronFileResponseRelativePath.getElectronFileResponseRelativePath(url)
9
- const absolutePath = GetElectronFileResponseAbsolutePath.getElectronFileResponseAbsolutePath(pathName)
10
- let content = await readFile(absolutePath)
11
- if (!Platform.isProduction && url === `${Platform.scheme}://-/`) {
12
- // @ts-ignore
13
- content = content.toString().replace(' <link rel="manifest" href="/manifest.json" crossorigin="use-credentials" />\n', '')
14
- }
15
- const headers = GetHeaders.getHeaders(absolutePath)
16
- return {
17
- body: content,
18
- init: {
19
- status: 200,
20
- headers,
21
- },
10
+ try {
11
+ const pathName = GetElectronFileResponseRelativePath.getElectronFileResponseRelativePath(url)
12
+ const absolutePath = GetElectronFileResponseAbsolutePath.getElectronFileResponseAbsolutePath(pathName)
13
+ const content = await GetElectronFileResponseContent.getElectronFileResponseContent(absolutePath, url)
14
+ const headers = GetHeaders.getHeaders(absolutePath)
15
+ return {
16
+ body: content,
17
+ init: {
18
+ status: HttpStatusCode.Ok,
19
+ headers,
20
+ },
21
+ }
22
+ } catch (error) {
23
+ if (IsEnoentError.isEnoentError(error)) {
24
+ return {
25
+ body: 'not-found',
26
+ init: {
27
+ status: HttpStatusCode.NotFound,
28
+ statusText: 'not-found',
29
+ headers: {},
30
+ },
31
+ }
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
+ }
22
42
  }
23
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
+ }
@@ -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 { scheme } = Platform
6
- const pathName = decoded.slice(`${scheme}://-`.length)
12
+ const pathName = decoded.slice(prefixLength)
7
13
  return pathName
8
14
  }
@@ -9,6 +9,7 @@ export const getMimeType = (fileExtension) => {
9
9
  case '.ttf':
10
10
  return MimeType.FontTtf
11
11
  case '.js':
12
+ case '.ts':
12
13
  return MimeType.TextJavaScript
13
14
  case '.svg':
14
15
  return MimeType.ImageSvgXml
@@ -16,6 +17,8 @@ export const getMimeType = (fileExtension) => {
16
17
  return MimeType.ImagePng
17
18
  case '.json':
18
19
  return MimeType.ApplicationJson
20
+ case '.mp3':
21
+ return MimeType.AudioMpeg
19
22
  default:
20
23
  console.warn(`unsupported file extension: ${fileExtension}`)
21
24
  return ''
@@ -0,0 +1,6 @@
1
+ import { join } from 'path'
2
+ import * as Root from '../Root/Root.js'
3
+
4
+ export const getTypeScriptPath = () => {
5
+ return join(Root.root, 'extensions', 'builtin.language-features-typescript', 'node', 'node_modules', 'typescript', 'lib', 'typescript.js')
6
+ }
@@ -0,0 +1,7 @@
1
+ import * as HandleRemoteRequest from './HandleRemoteRequest.js'
2
+
3
+ export const name = 'HandleRemoteRequest'
4
+
5
+ export const Commands = {
6
+ handleRemoteRequest: HandleRemoteRequest.handleRemoteRequest,
7
+ }
@@ -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,3 @@
1
+ export const NotFound = 404
2
+ export const Ok = 200
3
+ export const ServerError = 500
@@ -0,0 +1,3 @@
1
+ export const isTypeScriptPath = (uri) => {
2
+ return uri.endsWith('.ts')
3
+ }
@@ -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
  }
@@ -67,3 +67,4 @@ export const HandleWindowAllClosed = 60
67
67
  export const HandleMessagePortForTerminalProcess = 61
68
68
  export const TemporaryMessagePort = 62
69
69
  export const GetElectronFileResponse = 63
70
+ export const HandleRemoteRequest = 64
@@ -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.5'
64
+ export const version = '0.21.7'
65
65
 
66
- export const commit = 'ce18293'
66
+ export const commit = '6005be2'
67
67
 
68
- export const date = '2023-12-22T15:56:21.000Z'
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
+ }