@lvce-editor/typescript-compile-process 1.6.0 → 2.1.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.
- package/dist/index.js +36 -40
- package/package.json +2 -3
package/dist/index.js
CHANGED
|
@@ -1,26 +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 {
|
|
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
|
-
|
|
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
|
-
};
|
|
5
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
24
6
|
|
|
25
7
|
const NodeWorker = 1;
|
|
26
8
|
const NodeForkedProcess = 2;
|
|
@@ -46,15 +28,13 @@ const Auto = () => {
|
|
|
46
28
|
const getModule = method => {
|
|
47
29
|
switch (method) {
|
|
48
30
|
case NodeForkedProcess:
|
|
49
|
-
return
|
|
50
|
-
case NodeWorker:
|
|
51
|
-
return IpcChildWithNodeWorker;
|
|
31
|
+
return NodeForkedProcessRpcClient;
|
|
52
32
|
case ElectronUtilityProcess:
|
|
53
|
-
return
|
|
33
|
+
return ElectronUtilityProcessRpcClient;
|
|
54
34
|
case ElectronMessagePort:
|
|
55
|
-
return
|
|
35
|
+
return ElectronMessagePortRpcClient;
|
|
56
36
|
case WebSocket:
|
|
57
|
-
return
|
|
37
|
+
return WebSocketRpcParent;
|
|
58
38
|
default:
|
|
59
39
|
throw new Error('unexpected ipc type');
|
|
60
40
|
}
|
|
@@ -64,34 +44,37 @@ const listen$1 = async ({
|
|
|
64
44
|
method,
|
|
65
45
|
...params
|
|
66
46
|
}) => {
|
|
67
|
-
const module =
|
|
68
|
-
// @ts-ignore
|
|
69
|
-
const rawIpc = await module.listen(params);
|
|
47
|
+
const module = getModule(method);
|
|
70
48
|
// @ts-ignore
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
module.signal(rawIpc);
|
|
74
|
-
}
|
|
75
|
-
// @ts-ignore
|
|
76
|
-
const ipc = module.wrap(rawIpc);
|
|
77
|
-
return ipc;
|
|
49
|
+
const rpc = await module.create(params);
|
|
50
|
+
return rpc;
|
|
78
51
|
};
|
|
79
52
|
|
|
80
53
|
const handleElectronMessagePort = async (messagePort, ipcId) => {
|
|
81
54
|
object(messagePort);
|
|
82
55
|
// Assert.number(ipcId)
|
|
83
56
|
// TODO use handleIncomingIpc function
|
|
84
|
-
|
|
57
|
+
await listen$1({
|
|
85
58
|
method: ElectronMessagePort,
|
|
86
59
|
messagePort
|
|
87
60
|
});
|
|
88
|
-
handleIpc(ipc);
|
|
89
61
|
};
|
|
90
62
|
|
|
91
63
|
const importScript = async url => {
|
|
92
64
|
return await import(url);
|
|
93
65
|
};
|
|
94
66
|
|
|
67
|
+
const isModuleNotFoundError = error => {
|
|
68
|
+
return error && error.code === 'ERR_MODULE_NOT_FOUND';
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
class TypeScriptNotFoundError extends Error {
|
|
72
|
+
constructor() {
|
|
73
|
+
super('Failed to load typescript: Typescript not found');
|
|
74
|
+
this.code = 'E_TYPESCRIPT_NOT_FOUND';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
95
78
|
const loadTypeScript = async typescriptPath => {
|
|
96
79
|
try {
|
|
97
80
|
const typescript = await importScript(typescriptPath);
|
|
@@ -101,6 +84,9 @@ const loadTypeScript = async typescriptPath => {
|
|
|
101
84
|
}
|
|
102
85
|
return actual;
|
|
103
86
|
} catch (error) {
|
|
87
|
+
if (isModuleNotFoundError(error)) {
|
|
88
|
+
throw new TypeScriptNotFoundError();
|
|
89
|
+
}
|
|
104
90
|
throw new VError(error, `Failed to load typescript`);
|
|
105
91
|
}
|
|
106
92
|
};
|
|
@@ -131,17 +117,27 @@ const transpileTypeScript = async code => {
|
|
|
131
117
|
}
|
|
132
118
|
};
|
|
133
119
|
|
|
120
|
+
const transpileTypeScriptAtPath = async (inPath, outPath) => {
|
|
121
|
+
try {
|
|
122
|
+
const content = await readFile(inPath, 'utf-8');
|
|
123
|
+
const newContent = await transpileTypeScript(content);
|
|
124
|
+
await writeFile(outPath, newContent);
|
|
125
|
+
} catch (error) {
|
|
126
|
+
throw new VError(error, `Failed to transpile typescript`);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
134
130
|
const commandMap = {
|
|
135
131
|
'TranspileTypeScript.transpileTypeScript': transpileTypeScript,
|
|
132
|
+
'TranspileTypeScript.transpileTypeScriptAtPath': transpileTypeScriptAtPath,
|
|
136
133
|
'TypeScript.setTypeScriptPath': set,
|
|
137
134
|
'HandleElectronMessagePort.handleElectronMessagePort': handleElectronMessagePort
|
|
138
135
|
};
|
|
139
136
|
|
|
140
137
|
const listen = async () => {
|
|
141
|
-
|
|
138
|
+
await listen$1({
|
|
142
139
|
method: Auto()
|
|
143
140
|
});
|
|
144
|
-
handleIpc(ipc);
|
|
145
141
|
};
|
|
146
142
|
|
|
147
143
|
const main = async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/typescript-compile-process",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "TypeScript Compile Process",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": "bin/typescriptCompileProcess.js",
|
|
@@ -20,8 +20,7 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@lvce-editor/assert": "^1.3.0",
|
|
22
22
|
"@lvce-editor/command": "^1.2.0",
|
|
23
|
-
"@lvce-editor/
|
|
24
|
-
"@lvce-editor/json-rpc": "^5.2.0",
|
|
23
|
+
"@lvce-editor/rpc": "^1.12.0",
|
|
25
24
|
"@lvce-editor/verror": "^1.6.0"
|
|
26
25
|
},
|
|
27
26
|
"xo": {
|