@lvce-editor/shared-process 0.21.6 → 0.21.8

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.6",
3
+ "version": "0.21.8",
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.6",
23
- "@lvce-editor/extension-host-helper-process": "0.21.6",
22
+ "@lvce-editor/extension-host": "0.21.8",
23
+ "@lvce-editor/extension-host-helper-process": "0.21.8",
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.6",
27
+ "@lvce-editor/pty-host": "0.21.8",
28
28
  "@lvce-editor/verror": "^1.1.2",
29
29
  "debug": "^4.3.4",
30
30
  "execa": "^8.0.1",
@@ -35,14 +35,14 @@
35
35
  "p-queue": "^8.0.1",
36
36
  "parse-json": "^8.1.0",
37
37
  "tar-fs": "^3.0.4",
38
- "ws": "^8.15.1",
38
+ "ws": "^8.16.0",
39
39
  "xdg-basedir": "^5.1.0"
40
40
  },
41
41
  "optionalDependencies": {
42
42
  "@lvce-editor/ripgrep": "^1.0.1",
43
43
  "extract-zip": "^2.0.1",
44
44
  "open": "^10.0.1",
45
- "symlink-dir": "^5.2.0",
45
+ "symlink-dir": "^5.2.1",
46
46
  "tail": "^2.2.6",
47
47
  "tmp-promise": "^3.0.3",
48
48
  "trash": "^8.1.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 Platform from '../Platform/Platform.js'
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
- let content = await readFile(absolutePath)
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'] || process.env['TRANSPILE_TYPESCRIPT']) {
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,8 @@ export const getMimeType = (fileExtension) => {
9
9
  case '.ttf':
10
10
  return MimeType.FontTtf
11
11
  case '.js':
12
+ case '.mjs':
13
+ case '.ts':
12
14
  return MimeType.TextJavaScript
13
15
  case '.svg':
14
16
  return MimeType.ImageSvgXml
@@ -0,0 +1,14 @@
1
+ import { join } from 'node:path'
2
+ import * as PlatformPaths from '../PlatformPaths/PlatformPaths.js'
3
+
4
+ export const getTypeScriptPath = () => {
5
+ return join(
6
+ PlatformPaths.getBuiltinExtensionsPath(),
7
+ 'builtin.language-features-typescript',
8
+ 'node',
9
+ 'node_modules',
10
+ 'typescript',
11
+ 'lib',
12
+ 'typescript.js',
13
+ )
14
+ }
@@ -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
+ }
@@ -1,2 +1,3 @@
1
1
  export const NotFound = 404
2
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
+ }
@@ -1,5 +1,5 @@
1
1
  export const ApplicationFontWoff = 'application/font-woff'
2
- export const ApplicationJson = 'aplication/json'
2
+ export const ApplicationJson = 'application/json'
3
3
  export const AudioMidi = 'audio/midi'
4
4
  export const AudioMpeg = 'audio/mpeg'
5
5
  export const AudioOgg = 'audio/ogg'
@@ -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.6'
64
+ export const version = '0.21.8'
65
65
 
66
- export const commit = 'f4cb33e'
66
+ export const commit = 'b6072b1'
67
67
 
68
- export const date = '2023-12-23T22:04:56.000Z'
68
+ export const date = '2023-12-27T09:35:13.000Z'
69
69
 
70
70
  export const getVersion = () => {
71
71
  return version
@@ -0,0 +1,20 @@
1
+ import { VError } from '@lvce-editor/verror'
2
+ import * as Assert from '../Assert/Assert.js'
3
+ import * as GetTypeScriptPath from '../GetTypeScriptPath/GetTypeScriptPath.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
+ const typescript = await LoadTypeScript.loadTypeScript(typescriptPath)
11
+ const newContent = await typescript.transpileModule(code, {
12
+ compilerOptions: {
13
+ target: 'esnext',
14
+ },
15
+ })
16
+ return newContent
17
+ } catch (error) {
18
+ throw new VError(error, `Failed to transpile typescript`)
19
+ }
20
+ }