@lvce-editor/typescript-compile-process 1.5.0 → 2.0.0

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.
Files changed (2) hide show
  1. package/dist/index.js +24 -40
  2. package/package.json +4 -5
package/dist/index.js CHANGED
@@ -1,27 +1,8 @@
1
1
  import * as Command from '@lvce-editor/command';
2
- import { execute } from '@lvce-editor/command';
3
2
  import { object, string } from '@lvce-editor/assert';
4
- import { handleJsonRpcMessage, resolve } from '@lvce-editor/json-rpc';
5
- import { IpcChildWithWebSocket, IpcChildWithElectronMessagePort, IpcChildWithElectronUtilityProcess, IpcChildWithNodeWorker, IpcChildWithNodeForkedProcess } from '@lvce-editor/ipc';
3
+ import { WebSocketRpcParent, ElectronMessagePortRpcClient, ElectronUtilityProcessRpcClient, NodeForkedProcessRpcClient } from '@lvce-editor/rpc';
6
4
  import { VError } from '@lvce-editor/verror';
7
5
 
8
- const prepare = error => {
9
- return error;
10
- };
11
- const requiresSocket = method => {
12
- return false;
13
- };
14
- const logError = error => {
15
- console.error(error);
16
- };
17
- const handleMessage = event => {
18
- return handleJsonRpcMessage(event.target, event.data, execute, resolve, prepare, logError, requiresSocket);
19
- };
20
-
21
- const handleIpc = ipc => {
22
- ipc.addEventListener('message', handleMessage);
23
- };
24
-
25
6
  const NodeWorker = 1;
26
7
  const NodeForkedProcess = 2;
27
8
  const ElectronUtilityProcess = 3;
@@ -46,15 +27,13 @@ const Auto = () => {
46
27
  const getModule = method => {
47
28
  switch (method) {
48
29
  case NodeForkedProcess:
49
- return IpcChildWithNodeForkedProcess;
50
- case NodeWorker:
51
- return IpcChildWithNodeWorker;
30
+ return NodeForkedProcessRpcClient;
52
31
  case ElectronUtilityProcess:
53
- return IpcChildWithElectronUtilityProcess;
32
+ return ElectronUtilityProcessRpcClient;
54
33
  case ElectronMessagePort:
55
- return IpcChildWithElectronMessagePort;
34
+ return ElectronMessagePortRpcClient;
56
35
  case WebSocket:
57
- return IpcChildWithWebSocket;
36
+ return WebSocketRpcParent;
58
37
  default:
59
38
  throw new Error('unexpected ipc type');
60
39
  }
@@ -64,34 +43,37 @@ const listen$1 = async ({
64
43
  method,
65
44
  ...params
66
45
  }) => {
67
- const module = await getModule(method);
68
- // @ts-ignore
69
- const rawIpc = await module.listen(params);
46
+ const module = getModule(method);
70
47
  // @ts-ignore
71
- if (module.signal) {
72
- // @ts-ignore
73
- module.signal(rawIpc);
74
- }
75
- // @ts-ignore
76
- const ipc = module.wrap(rawIpc);
77
- return ipc;
48
+ const rpc = await module.create(params);
49
+ return rpc;
78
50
  };
79
51
 
80
52
  const handleElectronMessagePort = async (messagePort, ipcId) => {
81
53
  object(messagePort);
82
54
  // Assert.number(ipcId)
83
55
  // TODO use handleIncomingIpc function
84
- const ipc = await listen$1({
56
+ await listen$1({
85
57
  method: ElectronMessagePort,
86
58
  messagePort
87
59
  });
88
- handleIpc(ipc);
89
60
  };
90
61
 
91
62
  const importScript = async url => {
92
63
  return await import(url);
93
64
  };
94
65
 
66
+ const isModuleNotFoundError = error => {
67
+ return error && error.code === 'ERR_MODULE_NOT_FOUND';
68
+ };
69
+
70
+ class TypeScriptNotFoundError extends Error {
71
+ constructor() {
72
+ super('Failed to load typescript: Typescript not found');
73
+ this.code = 'E_TYPESCRIPT_NOT_FOUND';
74
+ }
75
+ }
76
+
95
77
  const loadTypeScript = async typescriptPath => {
96
78
  try {
97
79
  const typescript = await importScript(typescriptPath);
@@ -101,6 +83,9 @@ const loadTypeScript = async typescriptPath => {
101
83
  }
102
84
  return actual;
103
85
  } catch (error) {
86
+ if (isModuleNotFoundError(error)) {
87
+ throw new TypeScriptNotFoundError();
88
+ }
104
89
  throw new VError(error, `Failed to load typescript`);
105
90
  }
106
91
  };
@@ -138,10 +123,9 @@ const commandMap = {
138
123
  };
139
124
 
140
125
  const listen = async () => {
141
- const ipc = await listen$1({
126
+ await listen$1({
142
127
  method: Auto()
143
128
  });
144
- handleIpc(ipc);
145
129
  };
146
130
 
147
131
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/typescript-compile-process",
3
- "version": "1.5.0",
3
+ "version": "2.0.0",
4
4
  "description": "TypeScript Compile Process",
5
5
  "main": "dist/index.js",
6
6
  "bin": "bin/typescriptCompileProcess.js",
@@ -19,10 +19,9 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@lvce-editor/assert": "^1.3.0",
22
- "@lvce-editor/command": "^1.1.0",
23
- "@lvce-editor/ipc": "^11.0.1",
24
- "@lvce-editor/json-rpc": "^4.2.0",
25
- "@lvce-editor/verror": "^1.4.0"
22
+ "@lvce-editor/command": "^1.2.0",
23
+ "@lvce-editor/rpc": "^1.11.0",
24
+ "@lvce-editor/verror": "^1.6.0"
26
25
  },
27
26
  "xo": {
28
27
  "rules": {