@lvce-editor/shared-process 0.38.1 → 0.38.3

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.38.1",
3
+ "version": "0.38.3",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -18,12 +18,12 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@lvce-editor/assert": "^1.3.0",
21
- "@lvce-editor/extension-host-helper-process": "0.38.1",
21
+ "@lvce-editor/extension-host-helper-process": "0.38.3",
22
22
  "@lvce-editor/ipc": "^11.1.0",
23
- "@lvce-editor/json-rpc": "^5.0.0",
23
+ "@lvce-editor/json-rpc": "^5.2.0",
24
24
  "@lvce-editor/jsonc-parser": "^1.5.0",
25
25
  "@lvce-editor/pretty-error": "^1.6.0",
26
- "@lvce-editor/verror": "^1.5.0",
26
+ "@lvce-editor/verror": "^1.6.0",
27
27
  "debug": "^4.3.7",
28
28
  "is-object": "^1.0.2",
29
29
  "xdg-basedir": "^5.1.0"
@@ -15,6 +15,6 @@ export const addCustomPathsToIndexHtml = async (content) => {
15
15
  }
16
16
  const stringifiedConfig = JSON.stringify(config, null, 2);
17
17
  newContent = newContent.toString().replace('</title>', `</title>
18
- <script type="application.json" id="Config">${stringifiedConfig}</script>`);
18
+ <script type="application/json" id="Config">${stringifiedConfig}</script>`);
19
19
  return newContent;
20
20
  };
@@ -1,34 +1,7 @@
1
1
  import { readdir } from 'node:fs/promises';
2
- const generateTestOverviewHtml = (dirents) => {
3
- const pre = `<!DOCTYPE html>
4
- <html lang="en">
5
- <head>
6
- <meta charset="UTF-8" />
7
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
8
- <title>Tests</title>
9
- </head>
10
- <body>
11
- <h1>Tests</h1>
12
- <p>Available Tests</p>
13
- <ul>
14
- `;
15
- let middle = ``;
16
- // TODO properly escape name
17
- for (const dirent of dirents) {
18
- if (dirent.endsWith('.js') && !dirent.startsWith('_')) {
19
- const name = dirent.slice(0, -'.js'.length);
20
- middle += ` <li><a href="./${name}.html">${name}</a></li>
21
- `;
22
- }
23
- }
24
- const post = ` </ul>
25
- </body>
26
- </html>
27
- `;
28
- return pre + middle + post;
29
- };
2
+ import * as CreateTestOverviewHtml from '../CreateTestOverviewHtml/CreateTestOverviewHtml.js';
30
3
  export const createTestOverview = async (testPathSrc) => {
31
4
  const dirents = await readdir(testPathSrc);
32
- const testOverviewHtml = generateTestOverviewHtml(dirents);
5
+ const testOverviewHtml = CreateTestOverviewHtml.createTestOverviewHtml(dirents);
33
6
  return testOverviewHtml;
34
7
  };
@@ -0,0 +1,28 @@
1
+ export const createTestOverviewHtml = (dirents) => {
2
+ const pre = `<!DOCTYPE html>
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="UTF-8" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Tests</title>
8
+ </head>
9
+ <body>
10
+ <h1>Tests</h1>
11
+ <p>Available Tests</p>
12
+ <ul>
13
+ `;
14
+ let middle = ``;
15
+ // TODO properly escape name
16
+ for (const dirent of dirents) {
17
+ if (dirent.endsWith('.js') && !dirent.startsWith('_')) {
18
+ const name = dirent.slice(0, -'.js'.length);
19
+ middle += ` <li><a href="./${name}.html">${name}</a></li>
20
+ `;
21
+ }
22
+ }
23
+ const post = ` </ul>
24
+ </body>
25
+ </html>
26
+ `;
27
+ return pre + middle + post;
28
+ };
@@ -0,0 +1,10 @@
1
+ import * as HttpStatusCode from '../HttpStatusCode/HttpStatusCode.js';
2
+ export const getContentResponse = async (content, headers = {}) => {
3
+ return {
4
+ body: content,
5
+ init: {
6
+ status: HttpStatusCode.Ok,
7
+ headers,
8
+ },
9
+ };
10
+ };
@@ -5,10 +5,10 @@ import * as GetElectronFileResponseRelativePath from '../GetElectronFileResponse
5
5
  import * as GetEtag from '../GetEtag/GetEtag.js';
6
6
  import * as GetHeaders from '../GetHeaders/GetHeaders.js';
7
7
  import * as GetNotFoundResponse from '../GetNotFoundResponse/GetNotFoundResponse.js';
8
+ import * as GetContentResponse from '../GetContentResponse/GetContentResponse.js';
8
9
  import * as GetNotModifiedResponse from '../GetNotModifiedResponse/GetNotModifiedResponse.js';
9
10
  import * as GetServerErrorResponse from '../GetServerErrorResponse/GetServerErrorResponse.js';
10
11
  import * as HttpHeader from '../HttpHeader/HttpHeader.js';
11
- import * as HttpStatusCode from '../HttpStatusCode/HttpStatusCode.js';
12
12
  import * as IsEnoentError from '../IsEnoentError/IsEnoentError.js';
13
13
  import * as Logger from '../Logger/Logger.js';
14
14
  // TODO maybe handle app responses and webview responses separately
@@ -37,13 +37,7 @@ export const getElectronFileResponse = async (url, request) => {
37
37
  if (etag) {
38
38
  headers[HttpHeader.Etag] = etag;
39
39
  }
40
- return {
41
- body: content,
42
- init: {
43
- status: HttpStatusCode.Ok,
44
- headers,
45
- },
46
- };
40
+ return GetContentResponse.getContentResponse(content, headers);
47
41
  }
48
42
  catch (error) {
49
43
  if (IsEnoentError.isEnoentError(error)) {
@@ -1,15 +1,16 @@
1
1
  import { tmpdir } from 'node:os';
2
2
  import { join } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
- import * as IndexHtmlPath from '../IndexHtmlPath/IndexHtmlPath.js';
5
4
  import * as Path from '../Path/Path.js';
6
5
  import * as Platform from '../Platform/Platform.js';
7
6
  import * as Root from '../Root/Root.js';
7
+ import * as StaticPath from '../StaticPath/StaticPath.js';
8
8
  // TODO clean up this code
9
9
  export const getElectronFileResponseAbsolutePath = (pathName) => {
10
10
  // TODO remove if/else in prod (use replacement)
11
11
  if (pathName === `/` || pathName.startsWith(`/?`)) {
12
- return IndexHtmlPath.indexHtmlPath;
12
+ const staticPath = StaticPath.getStaticPath();
13
+ return Path.join(staticPath, 'index.html');
13
14
  }
14
15
  if (pathName.startsWith(`/packages`)) {
15
16
  return Path.join(Root.root, pathName);
@@ -36,5 +37,6 @@ export const getElectronFileResponseAbsolutePath = (pathName) => {
36
37
  if (pathName.startsWith('/home')) {
37
38
  return pathName;
38
39
  }
39
- return Path.join(Root.root, 'static', pathName);
40
+ const staticPath = StaticPath.getStaticPath();
41
+ return Path.join(staticPath, pathName);
40
42
  };
@@ -0,0 +1,10 @@
1
+ import * as HttpStatusCode from '../HttpStatusCode/HttpStatusCode.js';
2
+ export const getMultipleChoiceResponse = async (content, headers = {}) => {
3
+ return {
4
+ body: content,
5
+ init: {
6
+ status: HttpStatusCode.MultipleChoices,
7
+ headers,
8
+ },
9
+ };
10
+ };
@@ -1,53 +1,51 @@
1
1
  import { readFile } from 'node:fs/promises';
2
2
  import { join } from 'node:path';
3
3
  import * as AddCustomPathsToIndexHtml from '../AddCustomPathsToIndexHtml/AddCustomPathsToIndexHtml.js';
4
+ import * as ContentSecurityPolicyDocument from '../ContentSecurityPolicyDocument/ContentSecurityPolicyDocument.js';
4
5
  import * as CreateTestOverview from '../CreateTestOverview/CreateTestOverview.js';
5
6
  import * as CrossOriginEmbedderPolicy from '../CrossOriginEmbedderPolicy/CrossOriginEmbedderPolicy.js';
6
7
  import * as CrossOriginOpenerPolicy from '../CrossOriginOpenerPolicy/CrossOriginOpenerPolicy.js';
7
8
  import * as CrossOriginResourcePolicy from '../CrossOriginResourcePolicy/CrossOriginResourcePolicy.js';
8
- import * as ContentSecurityPolicyDocument from '../ContentSecurityPolicyDocument/ContentSecurityPolicyDocument.js';
9
+ import * as GetContentResponse from '../GetContentResponse/GetContentResponse.js';
10
+ import * as GetMultipleChoiceResponse from '../GetMultipleChoiceResponse/GetMultipleChoiceResponse.js';
9
11
  import * as GetPathName from '../GetPathName/GetPathName.js';
10
12
  import * as GetTestPath from '../GetTestPath/GetTestPath.js';
11
13
  import * as HttpHeader from '../HttpHeader/HttpHeader.js';
12
14
  import * as HttpStatusCode from '../HttpStatusCode/HttpStatusCode.js';
15
+ import * as Logger from '../Logger/Logger.js';
13
16
  export const getTestRequestResponse = async (request, indexHtmlPath) => {
14
- const pathName = GetPathName.getPathName(request);
15
- if (pathName.endsWith('.html')) {
16
- const body = await readFile(indexHtmlPath, 'utf8');
17
- const content = await AddCustomPathsToIndexHtml.addCustomPathsToIndexHtml(body);
18
- return {
19
- body: content,
20
- init: {
21
- status: HttpStatusCode.Ok,
22
- headers: {
23
- [HttpHeader.CrossOriginEmbedderPolicy]: CrossOriginEmbedderPolicy.value,
24
- [HttpHeader.CrossOriginResourcePolicy]: CrossOriginResourcePolicy.value,
25
- [HttpHeader.ContentSecurityPolicy]: ContentSecurityPolicyDocument.value,
26
- },
27
- },
28
- };
17
+ try {
18
+ const pathName = GetPathName.getPathName(request);
19
+ if (pathName.endsWith('.html')) {
20
+ const body = await readFile(indexHtmlPath, 'utf8');
21
+ const content = await AddCustomPathsToIndexHtml.addCustomPathsToIndexHtml(body);
22
+ const headers = {
23
+ [HttpHeader.CrossOriginEmbedderPolicy]: CrossOriginEmbedderPolicy.value,
24
+ [HttpHeader.CrossOriginResourcePolicy]: CrossOriginResourcePolicy.value,
25
+ [HttpHeader.ContentSecurityPolicy]: ContentSecurityPolicyDocument.value,
26
+ };
27
+ return GetContentResponse.getContentResponse(content, headers);
28
+ }
29
+ if (pathName === '/tests/') {
30
+ const testPath = GetTestPath.getTestPath();
31
+ const testPathSrc = join(testPath, 'src');
32
+ const body = await CreateTestOverview.createTestOverview(testPathSrc);
33
+ const headers = {
34
+ [HttpHeader.CacheControl]: 'public, max-age=0, must-revalidate',
35
+ [HttpHeader.CrossOriginEmbedderPolicy]: CrossOriginEmbedderPolicy.value,
36
+ [HttpHeader.CrossOriginOpenerPolicy]: CrossOriginOpenerPolicy.value,
37
+ [HttpHeader.ContentSecurityPolicy]: "default-src 'none'",
38
+ };
39
+ return GetMultipleChoiceResponse.getMultipleChoiceResponse(body, headers);
40
+ }
29
41
  }
30
- if (pathName === '/tests/') {
31
- const testPath = GetTestPath.getTestPath();
32
- const testPathSrc = join(testPath, 'src');
33
- const body = await CreateTestOverview.createTestOverview(testPathSrc);
42
+ catch (error) {
43
+ Logger.error(error);
34
44
  return {
35
- body,
45
+ body: 'Internal server error',
36
46
  init: {
37
- status: HttpStatusCode.MultipleChoices,
38
- headers: {
39
- [HttpHeader.CacheControl]: 'public, max-age=0, must-revalidate',
40
- [HttpHeader.CrossOriginEmbedderPolicy]: CrossOriginEmbedderPolicy.value,
41
- [HttpHeader.CrossOriginOpenerPolicy]: CrossOriginOpenerPolicy.value,
42
- [HttpHeader.ContentSecurityPolicy]: "default-src 'none'",
43
- },
47
+ status: HttpStatusCode.ServerError,
44
48
  },
45
49
  };
46
50
  }
47
- return {
48
- body: 'not-found',
49
- init: {
50
- status: HttpStatusCode.NotFound,
51
- },
52
- };
53
51
  };
@@ -41,9 +41,9 @@ export const getAppImageName = () => {
41
41
  export const getSetupName = () => {
42
42
  return 'Lvce-Setup';
43
43
  };
44
- export const version = '0.38.1';
45
- export const commit = 'f0d21f8';
46
- export const date = '2024-11-14T20:27:22.000Z';
44
+ export const version = '0.38.3';
45
+ export const commit = 'a98e66d';
46
+ export const date = '2024-11-16T21:06:30.000Z';
47
47
  export const getVersion = () => {
48
48
  return version;
49
49
  };
@@ -0,0 +1,15 @@
1
+ import { dirname, join } from 'node:path';
2
+ import * as IsBuiltServer from '../IsBuiltServer/IsBuiltServer.js';
3
+ import * as Root from '../Root/Root.js';
4
+ import { fileURLToPath } from 'node:url';
5
+ export const getStaticPath = () => {
6
+ if (IsBuiltServer.isBuiltServer) {
7
+ // TODO maybe move static files to separate package
8
+ const serverIndexUri = import.meta.resolve('@lvce-editor/server');
9
+ const serverIndexPath = fileURLToPath(serverIndexUri);
10
+ const serverPath = dirname(serverIndexPath);
11
+ const staticPath = join(serverPath, 'static');
12
+ return staticPath;
13
+ }
14
+ return join(Root.root, 'static');
15
+ };