@lvce-editor/file-system-process 4.1.0 → 5.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 +395 -415
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -6,72 +6,6 @@ import { join } from 'node:path';
|
|
|
6
6
|
import _trash from 'trash';
|
|
7
7
|
import { Buffer } from 'node:buffer';
|
|
8
8
|
|
|
9
|
-
class AssertionError extends Error {
|
|
10
|
-
constructor(message) {
|
|
11
|
-
super(message);
|
|
12
|
-
this.name = 'AssertionError';
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
const Object$1 = 1;
|
|
16
|
-
const Number = 2;
|
|
17
|
-
const Array$1 = 3;
|
|
18
|
-
const String = 4;
|
|
19
|
-
const Boolean$1 = 5;
|
|
20
|
-
const Function = 6;
|
|
21
|
-
const Null = 7;
|
|
22
|
-
const Unknown$1 = 8;
|
|
23
|
-
const getType = value => {
|
|
24
|
-
switch (typeof value) {
|
|
25
|
-
case 'number':
|
|
26
|
-
return Number;
|
|
27
|
-
case 'function':
|
|
28
|
-
return Function;
|
|
29
|
-
case 'string':
|
|
30
|
-
return String;
|
|
31
|
-
case 'object':
|
|
32
|
-
if (value === null) {
|
|
33
|
-
return Null;
|
|
34
|
-
}
|
|
35
|
-
if (Array.isArray(value)) {
|
|
36
|
-
return Array$1;
|
|
37
|
-
}
|
|
38
|
-
return Object$1;
|
|
39
|
-
case 'boolean':
|
|
40
|
-
return Boolean$1;
|
|
41
|
-
default:
|
|
42
|
-
return Unknown$1;
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
const object = value => {
|
|
46
|
-
const type = getType(value);
|
|
47
|
-
if (type !== Object$1) {
|
|
48
|
-
throw new AssertionError('expected value to be of type object');
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
const number = value => {
|
|
52
|
-
const type = getType(value);
|
|
53
|
-
if (type !== Number) {
|
|
54
|
-
throw new AssertionError('expected value to be of type number');
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
const string = value => {
|
|
58
|
-
const type = getType(value);
|
|
59
|
-
if (type !== String) {
|
|
60
|
-
throw new AssertionError('expected value to be of type string');
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const assertUri = uri => {
|
|
65
|
-
if (!uri.startsWith('file://')) {
|
|
66
|
-
throw new Error(`path must be a valid file uri`);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const Utf8 = 'utf8';
|
|
71
|
-
|
|
72
|
-
const ENOENT = 'ENOENT';
|
|
73
|
-
const EXDEV = 'EXDEV';
|
|
74
|
-
|
|
75
9
|
const normalizeLine = line => {
|
|
76
10
|
if (line.startsWith('Error: ')) {
|
|
77
11
|
return line.slice('Error: '.length);
|
|
@@ -128,128 +62,59 @@ class VError extends Error {
|
|
|
128
62
|
}
|
|
129
63
|
}
|
|
130
64
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return path;
|
|
136
|
-
};
|
|
137
|
-
class FileNotFoundError extends VError {
|
|
138
|
-
constructor(path) {
|
|
139
|
-
super(`File not found: '${getDisplayPath(path)}'`);
|
|
140
|
-
this.code = ENOENT;
|
|
65
|
+
class AssertionError extends Error {
|
|
66
|
+
constructor(message) {
|
|
67
|
+
super(message);
|
|
68
|
+
this.name = 'AssertionError';
|
|
141
69
|
}
|
|
142
70
|
}
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
const
|
|
147
|
-
const
|
|
148
|
-
const
|
|
149
|
-
const
|
|
150
|
-
const
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
if (dirent.isSocket()) {
|
|
164
|
-
return Socket;
|
|
165
|
-
}
|
|
166
|
-
if (dirent.isBlockDevice()) {
|
|
167
|
-
return BlockDevice;
|
|
168
|
-
}
|
|
169
|
-
if (dirent.isCharacterDevice()) {
|
|
170
|
-
return CharacterDevice;
|
|
171
|
-
}
|
|
172
|
-
if (dirent.isFIFO()) {
|
|
173
|
-
return Fifo;
|
|
174
|
-
}
|
|
175
|
-
return Unknown;
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
const getFolderSizeInternal = async path => {
|
|
179
|
-
if (path === '/') {
|
|
180
|
-
throw new Error('Invalid path for folder size');
|
|
181
|
-
}
|
|
182
|
-
let total = 0;
|
|
183
|
-
try {
|
|
184
|
-
const stats = await fs.stat(path);
|
|
185
|
-
total += stats.size;
|
|
186
|
-
if (stats.isDirectory() && !stats.isSymbolicLink()) {
|
|
187
|
-
const dirents = await fs.readdir(path);
|
|
188
|
-
for (const dirent of dirents) {
|
|
189
|
-
total += await getFolderSizeInternal(join(path, dirent));
|
|
71
|
+
const Object$1 = 1;
|
|
72
|
+
const Number = 2;
|
|
73
|
+
const Array$1 = 3;
|
|
74
|
+
const String = 4;
|
|
75
|
+
const Boolean$1 = 5;
|
|
76
|
+
const Function = 6;
|
|
77
|
+
const Null = 7;
|
|
78
|
+
const Unknown$1 = 8;
|
|
79
|
+
const getType = value => {
|
|
80
|
+
switch (typeof value) {
|
|
81
|
+
case 'number':
|
|
82
|
+
return Number;
|
|
83
|
+
case 'function':
|
|
84
|
+
return Function;
|
|
85
|
+
case 'string':
|
|
86
|
+
return String;
|
|
87
|
+
case 'object':
|
|
88
|
+
if (value === null) {
|
|
89
|
+
return Null;
|
|
190
90
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
91
|
+
if (Array.isArray(value)) {
|
|
92
|
+
return Array$1;
|
|
93
|
+
}
|
|
94
|
+
return Object$1;
|
|
95
|
+
case 'boolean':
|
|
96
|
+
return Boolean$1;
|
|
97
|
+
default:
|
|
98
|
+
return Unknown$1;
|
|
194
99
|
}
|
|
195
|
-
return total;
|
|
196
100
|
};
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
return false;
|
|
101
|
+
const object = value => {
|
|
102
|
+
const type = getType(value);
|
|
103
|
+
if (type !== Object$1) {
|
|
104
|
+
throw new AssertionError('expected value to be of type object');
|
|
202
105
|
}
|
|
203
|
-
return error.message.includes('The system cannot find the path specified.');
|
|
204
106
|
};
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
// @ts-ignore
|
|
212
|
-
const isEnoentError = error => {
|
|
213
|
-
if (!error) {
|
|
214
|
-
return false;
|
|
107
|
+
const number = value => {
|
|
108
|
+
const type = getType(value);
|
|
109
|
+
if (type !== Number) {
|
|
110
|
+
throw new AssertionError('expected value to be of type number');
|
|
215
111
|
}
|
|
216
|
-
return isEnoentErrorLinux(error) || isEnoentErrorWindows(error);
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
const FileSystemProcess = 210;
|
|
220
|
-
const MainProcess = -5;
|
|
221
|
-
const SharedProcess$1 = 1492;
|
|
222
|
-
|
|
223
|
-
const rpcs = Object.create(null);
|
|
224
|
-
const set$2 = (id, rpc) => {
|
|
225
|
-
rpcs[id] = rpc;
|
|
226
|
-
};
|
|
227
|
-
const get$1 = id => {
|
|
228
|
-
return rpcs[id];
|
|
229
112
|
};
|
|
230
|
-
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
await rpc.dispose();
|
|
236
|
-
},
|
|
237
|
-
// @ts-ignore
|
|
238
|
-
invoke(method, ...params) {
|
|
239
|
-
const rpc = get$1(rpcId);
|
|
240
|
-
// @ts-ignore
|
|
241
|
-
return rpc.invoke(method, ...params);
|
|
242
|
-
},
|
|
243
|
-
// @ts-ignore
|
|
244
|
-
invokeAndTransfer(method, ...params) {
|
|
245
|
-
const rpc = get$1(rpcId);
|
|
246
|
-
// @ts-ignore
|
|
247
|
-
return rpc.invokeAndTransfer(method, ...params);
|
|
248
|
-
},
|
|
249
|
-
set(rpc) {
|
|
250
|
-
set$2(rpcId, rpc);
|
|
251
|
-
}
|
|
252
|
-
};
|
|
113
|
+
const string = value => {
|
|
114
|
+
const type = getType(value);
|
|
115
|
+
if (type !== String) {
|
|
116
|
+
throw new AssertionError('expected value to be of type string');
|
|
117
|
+
}
|
|
253
118
|
};
|
|
254
119
|
|
|
255
120
|
const isMessagePort = value => {
|
|
@@ -882,12 +747,33 @@ const IpcChildWithWebSocket = {
|
|
|
882
747
|
wrap: wrap$9
|
|
883
748
|
};
|
|
884
749
|
|
|
750
|
+
class CommandNotFoundError extends Error {
|
|
751
|
+
constructor(command) {
|
|
752
|
+
super(`Command not found ${command}`);
|
|
753
|
+
this.name = 'CommandNotFoundError';
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
const commands = Object.create(null);
|
|
757
|
+
const register = commandMap => {
|
|
758
|
+
Object.assign(commands, commandMap);
|
|
759
|
+
};
|
|
760
|
+
const getCommand = key => {
|
|
761
|
+
return commands[key];
|
|
762
|
+
};
|
|
763
|
+
const execute = (command, ...args) => {
|
|
764
|
+
const fn = getCommand(command);
|
|
765
|
+
if (!fn) {
|
|
766
|
+
throw new CommandNotFoundError(command);
|
|
767
|
+
}
|
|
768
|
+
return fn(...args);
|
|
769
|
+
};
|
|
770
|
+
|
|
885
771
|
const Two$1 = '2.0';
|
|
886
772
|
const callbacks = Object.create(null);
|
|
887
|
-
const get = id => {
|
|
773
|
+
const get$1 = id => {
|
|
888
774
|
return callbacks[id];
|
|
889
775
|
};
|
|
890
|
-
const remove$
|
|
776
|
+
const remove$2 = id => {
|
|
891
777
|
delete callbacks[id];
|
|
892
778
|
};
|
|
893
779
|
class JsonRpcError extends Error {
|
|
@@ -906,12 +792,12 @@ const getErrorConstructor = (message, type) => {
|
|
|
906
792
|
switch (type) {
|
|
907
793
|
case DomException:
|
|
908
794
|
return DOMException;
|
|
909
|
-
case TypeError$1:
|
|
910
|
-
return TypeError;
|
|
911
|
-
case SyntaxError$1:
|
|
912
|
-
return SyntaxError;
|
|
913
795
|
case ReferenceError$1:
|
|
914
796
|
return ReferenceError;
|
|
797
|
+
case SyntaxError$1:
|
|
798
|
+
return SyntaxError;
|
|
799
|
+
case TypeError$1:
|
|
800
|
+
return TypeError;
|
|
915
801
|
default:
|
|
916
802
|
return Error;
|
|
917
803
|
}
|
|
@@ -1033,14 +919,14 @@ const warn = (...args) => {
|
|
|
1033
919
|
console.warn(...args);
|
|
1034
920
|
};
|
|
1035
921
|
const resolve = (id, response) => {
|
|
1036
|
-
const fn = get(id);
|
|
922
|
+
const fn = get$1(id);
|
|
1037
923
|
if (!fn) {
|
|
1038
924
|
console.log(response);
|
|
1039
925
|
warn(`callback ${id} may already be disposed`);
|
|
1040
926
|
return;
|
|
1041
927
|
}
|
|
1042
928
|
fn(response);
|
|
1043
|
-
remove$
|
|
929
|
+
remove$2(id);
|
|
1044
930
|
};
|
|
1045
931
|
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
1046
932
|
const getErrorType = prettyError => {
|
|
@@ -1067,56 +953,56 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
1067
953
|
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
1068
954
|
return {
|
|
1069
955
|
code: MethodNotFound,
|
|
1070
|
-
|
|
1071
|
-
|
|
956
|
+
data: error.stack,
|
|
957
|
+
message: error.message
|
|
1072
958
|
};
|
|
1073
959
|
}
|
|
1074
960
|
return {
|
|
1075
961
|
code: Custom,
|
|
1076
|
-
message: prettyError.message,
|
|
1077
962
|
data: {
|
|
1078
|
-
stack: getStack(prettyError),
|
|
1079
|
-
codeFrame: prettyError.codeFrame,
|
|
1080
|
-
type: getErrorType(prettyError),
|
|
1081
963
|
code: prettyError.code,
|
|
1082
|
-
|
|
1083
|
-
|
|
964
|
+
codeFrame: prettyError.codeFrame,
|
|
965
|
+
name: prettyError.name,
|
|
966
|
+
stack: getStack(prettyError),
|
|
967
|
+
type: getErrorType(prettyError)
|
|
968
|
+
},
|
|
969
|
+
message: prettyError.message
|
|
1084
970
|
};
|
|
1085
971
|
};
|
|
1086
|
-
const create$1 = (id, error) => {
|
|
972
|
+
const create$1$1 = (id, error) => {
|
|
1087
973
|
return {
|
|
1088
|
-
|
|
974
|
+
error,
|
|
1089
975
|
id,
|
|
1090
|
-
|
|
976
|
+
jsonrpc: Two$1
|
|
1091
977
|
};
|
|
1092
978
|
};
|
|
1093
979
|
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
1094
980
|
const prettyError = preparePrettyError(error);
|
|
1095
981
|
logError(error, prettyError);
|
|
1096
982
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
1097
|
-
return create$1(id, errorProperty);
|
|
983
|
+
return create$1$1(id, errorProperty);
|
|
1098
984
|
};
|
|
1099
|
-
const create$
|
|
985
|
+
const create$c = (message, result) => {
|
|
1100
986
|
return {
|
|
1101
|
-
jsonrpc: Two$1,
|
|
1102
987
|
id: message.id,
|
|
988
|
+
jsonrpc: Two$1,
|
|
1103
989
|
result: result ?? null
|
|
1104
990
|
};
|
|
1105
991
|
};
|
|
1106
992
|
const getSuccessResponse = (message, result) => {
|
|
1107
993
|
const resultProperty = result ?? null;
|
|
1108
|
-
return create$
|
|
994
|
+
return create$c(message, resultProperty);
|
|
1109
995
|
};
|
|
1110
996
|
const getErrorResponseSimple = (id, error) => {
|
|
1111
997
|
return {
|
|
1112
|
-
jsonrpc: Two$1,
|
|
1113
|
-
id,
|
|
1114
998
|
error: {
|
|
1115
999
|
code: Custom,
|
|
1000
|
+
data: error,
|
|
1116
1001
|
// @ts-ignore
|
|
1117
|
-
message: error.message
|
|
1118
|
-
|
|
1119
|
-
|
|
1002
|
+
message: error.message
|
|
1003
|
+
},
|
|
1004
|
+
id,
|
|
1005
|
+
jsonrpc: Two$1
|
|
1120
1006
|
};
|
|
1121
1007
|
};
|
|
1122
1008
|
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
@@ -1146,35 +1032,35 @@ const normalizeParams = args => {
|
|
|
1146
1032
|
if (args.length === 1) {
|
|
1147
1033
|
const options = args[0];
|
|
1148
1034
|
return {
|
|
1035
|
+
execute: options.execute,
|
|
1149
1036
|
ipc: options.ipc,
|
|
1037
|
+
logError: options.logError || defaultLogError,
|
|
1150
1038
|
message: options.message,
|
|
1151
|
-
execute: options.execute,
|
|
1152
|
-
resolve: options.resolve || defaultResolve,
|
|
1153
1039
|
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
1154
|
-
|
|
1155
|
-
|
|
1040
|
+
requiresSocket: options.requiresSocket || defaultRequiresSocket,
|
|
1041
|
+
resolve: options.resolve || defaultResolve
|
|
1156
1042
|
};
|
|
1157
1043
|
}
|
|
1158
1044
|
return {
|
|
1045
|
+
execute: args[2],
|
|
1159
1046
|
ipc: args[0],
|
|
1047
|
+
logError: args[5],
|
|
1160
1048
|
message: args[1],
|
|
1161
|
-
execute: args[2],
|
|
1162
|
-
resolve: args[3],
|
|
1163
1049
|
preparePrettyError: args[4],
|
|
1164
|
-
|
|
1165
|
-
|
|
1050
|
+
requiresSocket: args[6],
|
|
1051
|
+
resolve: args[3]
|
|
1166
1052
|
};
|
|
1167
1053
|
};
|
|
1168
1054
|
const handleJsonRpcMessage = async (...args) => {
|
|
1169
1055
|
const options = normalizeParams(args);
|
|
1170
1056
|
const {
|
|
1171
|
-
message,
|
|
1172
|
-
ipc,
|
|
1173
1057
|
execute,
|
|
1174
|
-
|
|
1175
|
-
preparePrettyError,
|
|
1058
|
+
ipc,
|
|
1176
1059
|
logError,
|
|
1177
|
-
|
|
1060
|
+
message,
|
|
1061
|
+
preparePrettyError,
|
|
1062
|
+
requiresSocket,
|
|
1063
|
+
resolve
|
|
1178
1064
|
} = options;
|
|
1179
1065
|
if ('id' in message) {
|
|
1180
1066
|
if ('method' in message) {
|
|
@@ -1197,36 +1083,17 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
1197
1083
|
throw new JsonRpcError('unexpected message');
|
|
1198
1084
|
};
|
|
1199
1085
|
|
|
1200
|
-
class CommandNotFoundError extends Error {
|
|
1201
|
-
constructor(command) {
|
|
1202
|
-
super(`Command not found ${command}`);
|
|
1203
|
-
this.name = 'CommandNotFoundError';
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
const commands = Object.create(null);
|
|
1207
|
-
const register = commandMap => {
|
|
1208
|
-
Object.assign(commands, commandMap);
|
|
1209
|
-
};
|
|
1210
|
-
const getCommand = key => {
|
|
1211
|
-
return commands[key];
|
|
1212
|
-
};
|
|
1213
|
-
const execute = (command, ...args) => {
|
|
1214
|
-
const fn = getCommand(command);
|
|
1215
|
-
if (!fn) {
|
|
1216
|
-
throw new CommandNotFoundError(command);
|
|
1217
|
-
}
|
|
1218
|
-
return fn(...args);
|
|
1219
|
-
};
|
|
1220
|
-
|
|
1221
1086
|
const Two = '2.0';
|
|
1222
|
-
|
|
1087
|
+
|
|
1088
|
+
const create$b = (method, params) => {
|
|
1223
1089
|
return {
|
|
1224
1090
|
jsonrpc: Two,
|
|
1225
1091
|
method,
|
|
1226
1092
|
params
|
|
1227
1093
|
};
|
|
1228
1094
|
};
|
|
1229
|
-
|
|
1095
|
+
|
|
1096
|
+
const create$a = (id, method, params) => {
|
|
1230
1097
|
const message = {
|
|
1231
1098
|
id,
|
|
1232
1099
|
jsonrpc: Two,
|
|
@@ -1235,15 +1102,14 @@ const create$r = (id, method, params) => {
|
|
|
1235
1102
|
};
|
|
1236
1103
|
return message;
|
|
1237
1104
|
};
|
|
1105
|
+
|
|
1238
1106
|
let id = 0;
|
|
1239
|
-
const create$
|
|
1107
|
+
const create$9 = () => {
|
|
1240
1108
|
return ++id;
|
|
1241
1109
|
};
|
|
1242
1110
|
|
|
1243
|
-
/* eslint-disable n/no-unsupported-features/es-syntax */
|
|
1244
|
-
|
|
1245
1111
|
const registerPromise = map => {
|
|
1246
|
-
const id = create$
|
|
1112
|
+
const id = create$9();
|
|
1247
1113
|
const {
|
|
1248
1114
|
promise,
|
|
1249
1115
|
resolve
|
|
@@ -1255,13 +1121,12 @@ const registerPromise = map => {
|
|
|
1255
1121
|
};
|
|
1256
1122
|
};
|
|
1257
1123
|
|
|
1258
|
-
// @ts-ignore
|
|
1259
1124
|
const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
|
|
1260
1125
|
const {
|
|
1261
1126
|
id,
|
|
1262
1127
|
promise
|
|
1263
1128
|
} = registerPromise(callbacks);
|
|
1264
|
-
const message = create$
|
|
1129
|
+
const message = create$a(id, method, params);
|
|
1265
1130
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
1266
1131
|
ipc.sendAndTransfer(message);
|
|
1267
1132
|
} else {
|
|
@@ -1297,12 +1162,13 @@ const createRpc = ipc => {
|
|
|
1297
1162
|
* @deprecated
|
|
1298
1163
|
*/
|
|
1299
1164
|
send(method, ...params) {
|
|
1300
|
-
const message = create$
|
|
1165
|
+
const message = create$b(method, params);
|
|
1301
1166
|
ipc.send(message);
|
|
1302
1167
|
}
|
|
1303
1168
|
};
|
|
1304
1169
|
return rpc;
|
|
1305
1170
|
};
|
|
1171
|
+
|
|
1306
1172
|
const requiresSocket$1 = () => {
|
|
1307
1173
|
return false;
|
|
1308
1174
|
};
|
|
@@ -1317,6 +1183,7 @@ const handleMessage = event => {
|
|
|
1317
1183
|
const actualExecute = event?.target?.execute || execute;
|
|
1318
1184
|
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
1319
1185
|
};
|
|
1186
|
+
|
|
1320
1187
|
const handleIpc = ipc => {
|
|
1321
1188
|
if ('addEventListener' in ipc) {
|
|
1322
1189
|
ipc.addEventListener('message', handleMessage);
|
|
@@ -1325,7 +1192,8 @@ const handleIpc = ipc => {
|
|
|
1325
1192
|
ipc.on('message', handleMessage);
|
|
1326
1193
|
}
|
|
1327
1194
|
};
|
|
1328
|
-
|
|
1195
|
+
|
|
1196
|
+
const listen$1 = async (module, options) => {
|
|
1329
1197
|
const rawIpc = await module.listen(options);
|
|
1330
1198
|
if (module.signal) {
|
|
1331
1199
|
module.signal(rawIpc);
|
|
@@ -1333,14 +1201,15 @@ const listen$2 = async (module, options) => {
|
|
|
1333
1201
|
const ipc = module.wrap(rawIpc);
|
|
1334
1202
|
return ipc;
|
|
1335
1203
|
};
|
|
1336
|
-
|
|
1204
|
+
|
|
1205
|
+
const create$8 = async ({
|
|
1337
1206
|
commandMap,
|
|
1338
1207
|
messagePort,
|
|
1339
1208
|
requiresSocket
|
|
1340
1209
|
}) => {
|
|
1341
1210
|
// TODO create a commandMap per rpc instance
|
|
1342
1211
|
register(commandMap);
|
|
1343
|
-
const ipc = await listen$
|
|
1212
|
+
const ipc = await listen$1(IpcChildWithElectronMessagePort$1, {
|
|
1344
1213
|
messagePort
|
|
1345
1214
|
});
|
|
1346
1215
|
if (requiresSocket) {
|
|
@@ -1350,26 +1219,17 @@ const create$p = async ({
|
|
|
1350
1219
|
const rpc = createRpc(ipc);
|
|
1351
1220
|
return rpc;
|
|
1352
1221
|
};
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
create: create$p
|
|
1356
|
-
};
|
|
1357
|
-
const create$o = async ({
|
|
1222
|
+
|
|
1223
|
+
const create$7 = async ({
|
|
1358
1224
|
commandMap
|
|
1359
1225
|
}) => {
|
|
1360
1226
|
// TODO create a commandMap per rpc instance
|
|
1361
1227
|
register(commandMap);
|
|
1362
|
-
const ipc = await listen$
|
|
1228
|
+
const ipc = await listen$1(IpcChildWithElectronUtilityProcess$1);
|
|
1363
1229
|
handleIpc(ipc);
|
|
1364
1230
|
const rpc = createRpc(ipc);
|
|
1365
1231
|
return rpc;
|
|
1366
1232
|
};
|
|
1367
|
-
const ElectronUtilityProcessRpcClient = {
|
|
1368
|
-
__proto__: null,
|
|
1369
|
-
create: create$o
|
|
1370
|
-
};
|
|
1371
|
-
|
|
1372
|
-
/* eslint-disable @typescript-eslint/no-misused-promises */
|
|
1373
1233
|
|
|
1374
1234
|
const createSharedLazyRpc = factory => {
|
|
1375
1235
|
let rpcPromise;
|
|
@@ -1398,7 +1258,8 @@ const createSharedLazyRpc = factory => {
|
|
|
1398
1258
|
}
|
|
1399
1259
|
};
|
|
1400
1260
|
};
|
|
1401
|
-
|
|
1261
|
+
|
|
1262
|
+
const create$6 = async ({
|
|
1402
1263
|
commandMap,
|
|
1403
1264
|
getPortTuple,
|
|
1404
1265
|
send
|
|
@@ -1408,44 +1269,39 @@ const create$k = async ({
|
|
|
1408
1269
|
port2
|
|
1409
1270
|
} = await getPortTuple();
|
|
1410
1271
|
await send(port1);
|
|
1411
|
-
const rpc = create$
|
|
1272
|
+
const rpc = create$8({
|
|
1412
1273
|
commandMap,
|
|
1413
1274
|
messagePort: port2
|
|
1414
1275
|
});
|
|
1415
1276
|
return rpc;
|
|
1416
1277
|
};
|
|
1417
|
-
|
|
1278
|
+
|
|
1279
|
+
const create$5 = async ({
|
|
1418
1280
|
commandMap,
|
|
1419
1281
|
getPortTuple,
|
|
1420
1282
|
send
|
|
1421
1283
|
}) => {
|
|
1422
1284
|
return createSharedLazyRpc(() => {
|
|
1423
|
-
return create$
|
|
1285
|
+
return create$6({
|
|
1424
1286
|
commandMap,
|
|
1425
1287
|
getPortTuple,
|
|
1426
1288
|
send
|
|
1427
1289
|
});
|
|
1428
1290
|
});
|
|
1429
1291
|
};
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
create: create$j
|
|
1433
|
-
};
|
|
1434
|
-
const create$9 = async ({
|
|
1292
|
+
|
|
1293
|
+
const create$4 = async ({
|
|
1435
1294
|
commandMap
|
|
1436
1295
|
}) => {
|
|
1437
1296
|
// TODO create a commandMap per rpc instance
|
|
1438
1297
|
register(commandMap);
|
|
1439
|
-
const ipc = await listen$
|
|
1298
|
+
const ipc = await listen$1(IpcChildWithNodeForkedProcess$1);
|
|
1440
1299
|
handleIpc(ipc);
|
|
1441
1300
|
const rpc = createRpc(ipc);
|
|
1442
1301
|
return rpc;
|
|
1443
1302
|
};
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
create: create$9
|
|
1447
|
-
};
|
|
1448
|
-
const create$7 = async ({
|
|
1303
|
+
|
|
1304
|
+
const create$3 = async ({
|
|
1449
1305
|
commandMap,
|
|
1450
1306
|
handle,
|
|
1451
1307
|
request,
|
|
@@ -1453,7 +1309,7 @@ const create$7 = async ({
|
|
|
1453
1309
|
}) => {
|
|
1454
1310
|
// TODO create a commandMap per rpc instance
|
|
1455
1311
|
register(commandMap);
|
|
1456
|
-
const ipc = await listen$
|
|
1312
|
+
const ipc = await listen$1(IpcChildWithWebSocket, {
|
|
1457
1313
|
handle,
|
|
1458
1314
|
request
|
|
1459
1315
|
});
|
|
@@ -1464,50 +1320,253 @@ const create$7 = async ({
|
|
|
1464
1320
|
const rpc = createRpc(ipc);
|
|
1465
1321
|
return rpc;
|
|
1466
1322
|
};
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
create: create$7
|
|
1470
|
-
};
|
|
1471
|
-
const create$6 = async ({
|
|
1323
|
+
|
|
1324
|
+
const create$2 = async ({
|
|
1472
1325
|
commandMap
|
|
1473
1326
|
}) => {
|
|
1474
1327
|
// TODO create a commandMap per rpc instance
|
|
1475
1328
|
register(commandMap);
|
|
1476
|
-
const ipc = await listen$
|
|
1329
|
+
const ipc = await listen$1(IpcChildWithNodeWorker$1);
|
|
1477
1330
|
handleIpc(ipc);
|
|
1478
1331
|
const rpc = createRpc(ipc);
|
|
1479
1332
|
return rpc;
|
|
1480
1333
|
};
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1334
|
+
|
|
1335
|
+
const createMockRpc = ({
|
|
1336
|
+
commandMap
|
|
1337
|
+
}) => {
|
|
1338
|
+
const invocations = [];
|
|
1339
|
+
const invoke = (method, ...params) => {
|
|
1340
|
+
invocations.push([method, ...params]);
|
|
1341
|
+
const command = commandMap[method];
|
|
1342
|
+
if (!command) {
|
|
1343
|
+
throw new Error(`command ${method} not found`);
|
|
1344
|
+
}
|
|
1345
|
+
return command(...params);
|
|
1346
|
+
};
|
|
1347
|
+
const mockRpc = {
|
|
1348
|
+
invocations,
|
|
1349
|
+
invoke,
|
|
1350
|
+
invokeAndTransfer: invoke
|
|
1351
|
+
};
|
|
1352
|
+
return mockRpc;
|
|
1353
|
+
};
|
|
1354
|
+
|
|
1355
|
+
const rpcs = Object.create(null);
|
|
1356
|
+
const set$2 = (id, rpc) => {
|
|
1357
|
+
rpcs[id] = rpc;
|
|
1358
|
+
};
|
|
1359
|
+
const get = id => {
|
|
1360
|
+
return rpcs[id];
|
|
1361
|
+
};
|
|
1362
|
+
const remove$1 = id => {
|
|
1363
|
+
delete rpcs[id];
|
|
1484
1364
|
};
|
|
1485
1365
|
|
|
1366
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
1367
|
+
const create$1 = rpcId => {
|
|
1368
|
+
return {
|
|
1369
|
+
async dispose() {
|
|
1370
|
+
const rpc = get(rpcId);
|
|
1371
|
+
await rpc.dispose();
|
|
1372
|
+
},
|
|
1373
|
+
// @ts-ignore
|
|
1374
|
+
invoke(method, ...params) {
|
|
1375
|
+
const rpc = get(rpcId);
|
|
1376
|
+
// @ts-ignore
|
|
1377
|
+
return rpc.invoke(method, ...params);
|
|
1378
|
+
},
|
|
1379
|
+
// @ts-ignore
|
|
1380
|
+
invokeAndTransfer(method, ...params) {
|
|
1381
|
+
const rpc = get(rpcId);
|
|
1382
|
+
// @ts-ignore
|
|
1383
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
1384
|
+
},
|
|
1385
|
+
registerMockRpc(commandMap) {
|
|
1386
|
+
const mockRpc = createMockRpc({
|
|
1387
|
+
commandMap
|
|
1388
|
+
});
|
|
1389
|
+
set$2(rpcId, mockRpc);
|
|
1390
|
+
// @ts-ignore
|
|
1391
|
+
mockRpc[Symbol.dispose] = () => {
|
|
1392
|
+
remove$1(rpcId);
|
|
1393
|
+
};
|
|
1394
|
+
// @ts-ignore
|
|
1395
|
+
return mockRpc;
|
|
1396
|
+
},
|
|
1397
|
+
set(rpc) {
|
|
1398
|
+
set$2(rpcId, rpc);
|
|
1399
|
+
}
|
|
1400
|
+
};
|
|
1401
|
+
};
|
|
1402
|
+
|
|
1403
|
+
const FileSystemProcess = 210;
|
|
1404
|
+
const MainProcess = -5;
|
|
1405
|
+
const SharedProcess = 1492;
|
|
1406
|
+
|
|
1486
1407
|
const {
|
|
1487
|
-
invoke: invoke$
|
|
1408
|
+
invoke: invoke$1,
|
|
1488
1409
|
set: set$1
|
|
1489
|
-
} = create$
|
|
1410
|
+
} = create$1(MainProcess);
|
|
1490
1411
|
|
|
1491
1412
|
const {
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
invokeAndTransfer: invokeAndTransfer$1,
|
|
1413
|
+
invoke,
|
|
1414
|
+
invokeAndTransfer,
|
|
1495
1415
|
set
|
|
1496
|
-
} = create$
|
|
1416
|
+
} = create$1(SharedProcess);
|
|
1497
1417
|
|
|
1498
|
-
const
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1418
|
+
const state = {
|
|
1419
|
+
id: 0
|
|
1420
|
+
};
|
|
1421
|
+
const create = () => {
|
|
1422
|
+
return ++state.id;
|
|
1423
|
+
};
|
|
1424
|
+
|
|
1425
|
+
const ports = Object.create(null);
|
|
1426
|
+
const getPortTuple$1 = async () => {
|
|
1427
|
+
const id1 = create();
|
|
1428
|
+
const id2 = create();
|
|
1429
|
+
await invoke('TemporaryMessagePort.getPortTuple3', id1, id2, FileSystemProcess);
|
|
1430
|
+
const port1 = ports[id1];
|
|
1431
|
+
const port2 = ports[id2];
|
|
1432
|
+
delete ports[id1];
|
|
1433
|
+
delete ports[id2];
|
|
1434
|
+
return {
|
|
1435
|
+
port1,
|
|
1436
|
+
port2
|
|
1437
|
+
};
|
|
1438
|
+
};
|
|
1439
|
+
const handlePorts = (port1, port2, id1, id2) => {
|
|
1440
|
+
number(id1);
|
|
1441
|
+
number(id2);
|
|
1442
|
+
object(port1);
|
|
1443
|
+
object(port2);
|
|
1444
|
+
ports[id1] = port1;
|
|
1445
|
+
ports[id2] = port2;
|
|
1446
|
+
};
|
|
1447
|
+
|
|
1448
|
+
const getPortTuple = async () => {
|
|
1449
|
+
const {
|
|
1450
|
+
port1,
|
|
1451
|
+
port2
|
|
1452
|
+
} = await getPortTuple$1();
|
|
1453
|
+
return {
|
|
1454
|
+
port1,
|
|
1455
|
+
port2
|
|
1456
|
+
};
|
|
1457
|
+
};
|
|
1458
|
+
|
|
1459
|
+
const initializeMainProcessRpc = async () => {
|
|
1460
|
+
const rpc = await create$5({
|
|
1461
|
+
commandMap: {},
|
|
1462
|
+
getPortTuple,
|
|
1463
|
+
async send(port) {
|
|
1464
|
+
await invokeAndTransfer('TemporaryMessagePort.sendToElectron', port, MainProcess, FileSystemProcess);
|
|
1465
|
+
}
|
|
1466
|
+
});
|
|
1467
|
+
set$1(rpc);
|
|
1468
|
+
};
|
|
1469
|
+
|
|
1470
|
+
const assertUri = uri => {
|
|
1471
|
+
if (!uri.startsWith('file://')) {
|
|
1472
|
+
throw new Error(`path must be a valid file uri`);
|
|
1473
|
+
}
|
|
1474
|
+
};
|
|
1475
|
+
|
|
1476
|
+
const Utf8 = 'utf8';
|
|
1477
|
+
|
|
1478
|
+
const ENOENT = 'ENOENT';
|
|
1479
|
+
const EXDEV = 'EXDEV';
|
|
1480
|
+
|
|
1481
|
+
const getDisplayPath = path => {
|
|
1482
|
+
if (path === '') {
|
|
1483
|
+
return '<empty string>';
|
|
1484
|
+
}
|
|
1485
|
+
return path;
|
|
1486
|
+
};
|
|
1487
|
+
class FileNotFoundError extends VError {
|
|
1488
|
+
constructor(path) {
|
|
1489
|
+
super(`File not found: '${getDisplayPath(path)}'`);
|
|
1490
|
+
this.code = ENOENT;
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
const BlockDevice = 1;
|
|
1495
|
+
const CharacterDevice = 2;
|
|
1496
|
+
const Directory = 3;
|
|
1497
|
+
const Fifo = 6;
|
|
1498
|
+
const File = 7;
|
|
1499
|
+
const Socket = 8;
|
|
1500
|
+
const Symlink = 9;
|
|
1501
|
+
const Unknown = 12;
|
|
1502
|
+
|
|
1503
|
+
const getDirentType = dirent => {
|
|
1504
|
+
if (dirent.isFile()) {
|
|
1505
|
+
return File;
|
|
1506
|
+
}
|
|
1507
|
+
if (dirent.isDirectory()) {
|
|
1508
|
+
return Directory;
|
|
1509
|
+
}
|
|
1510
|
+
if (dirent.isSymbolicLink()) {
|
|
1511
|
+
return Symlink;
|
|
1512
|
+
}
|
|
1513
|
+
if (dirent.isSocket()) {
|
|
1514
|
+
return Socket;
|
|
1515
|
+
}
|
|
1516
|
+
if (dirent.isBlockDevice()) {
|
|
1517
|
+
return BlockDevice;
|
|
1518
|
+
}
|
|
1519
|
+
if (dirent.isCharacterDevice()) {
|
|
1520
|
+
return CharacterDevice;
|
|
1521
|
+
}
|
|
1522
|
+
if (dirent.isFIFO()) {
|
|
1523
|
+
return Fifo;
|
|
1524
|
+
}
|
|
1525
|
+
return Unknown;
|
|
1526
|
+
};
|
|
1527
|
+
|
|
1528
|
+
const getFolderSizeInternal = async path => {
|
|
1529
|
+
if (path === '/') {
|
|
1530
|
+
throw new Error('Invalid path for folder size');
|
|
1531
|
+
}
|
|
1532
|
+
let total = 0;
|
|
1533
|
+
try {
|
|
1534
|
+
const stats = await fs.stat(path);
|
|
1535
|
+
total += stats.size;
|
|
1536
|
+
if (stats.isDirectory() && !stats.isSymbolicLink()) {
|
|
1537
|
+
const dirents = await fs.readdir(path);
|
|
1538
|
+
for (const dirent of dirents) {
|
|
1539
|
+
total += await getFolderSizeInternal(join(path, dirent));
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
} catch {
|
|
1543
|
+
return 0;
|
|
1544
|
+
}
|
|
1545
|
+
return total;
|
|
1546
|
+
};
|
|
1547
|
+
|
|
1548
|
+
const isEnoentErrorWindows = error => {
|
|
1549
|
+
if (!error || !error.message) {
|
|
1550
|
+
return false;
|
|
1551
|
+
}
|
|
1552
|
+
return error.message.includes('The system cannot find the path specified.');
|
|
1553
|
+
};
|
|
1554
|
+
|
|
1555
|
+
const isEnoentErrorLinux = error => {
|
|
1556
|
+
return Boolean(error && error.code === ENOENT);
|
|
1557
|
+
};
|
|
1558
|
+
const isEnoentError = error => {
|
|
1559
|
+
if (!error) {
|
|
1560
|
+
return false;
|
|
1561
|
+
}
|
|
1562
|
+
return isEnoentErrorLinux(error) || isEnoentErrorWindows(error);
|
|
1504
1563
|
};
|
|
1505
1564
|
|
|
1506
1565
|
const trash$2 = async path => {
|
|
1507
1566
|
if (!existsSync(path)) {
|
|
1508
1567
|
return;
|
|
1509
1568
|
}
|
|
1510
|
-
await invoke$
|
|
1569
|
+
await invoke$1('Trash.trash', path);
|
|
1511
1570
|
};
|
|
1512
1571
|
|
|
1513
1572
|
// @ts-ignore
|
|
@@ -1529,6 +1588,8 @@ const getElectronRunAsNode = () => {
|
|
|
1529
1588
|
const isElectron = Boolean(getElectronRunAsNode()) || 'electron' in process.versions;
|
|
1530
1589
|
|
|
1531
1590
|
const trash = async path => {
|
|
1591
|
+
// TODO pass iselectron as parameter
|
|
1592
|
+
// TODO only accept file uris
|
|
1532
1593
|
if (!path || path.trim() === '') {
|
|
1533
1594
|
throw new Error('Path cannot be empty');
|
|
1534
1595
|
}
|
|
@@ -1777,55 +1838,12 @@ const unwatchFile = uri => {
|
|
|
1777
1838
|
// TODO
|
|
1778
1839
|
};
|
|
1779
1840
|
|
|
1780
|
-
const NodeWorker = 1;
|
|
1781
|
-
const NodeForkedProcess = 2;
|
|
1782
|
-
const ElectronUtilityProcess = 3;
|
|
1783
|
-
const ElectronMessagePort = 4;
|
|
1784
|
-
const WebSocket = 6;
|
|
1785
|
-
const Auto = argv => {
|
|
1786
|
-
if (argv.includes('--ipc-type=node-worker')) {
|
|
1787
|
-
return NodeWorker;
|
|
1788
|
-
}
|
|
1789
|
-
if (argv.includes('--ipc-type=node-forked-process')) {
|
|
1790
|
-
return NodeForkedProcess;
|
|
1791
|
-
}
|
|
1792
|
-
if (argv.includes('--ipc-type=electron-utility-process')) {
|
|
1793
|
-
return ElectronUtilityProcess;
|
|
1794
|
-
}
|
|
1795
|
-
throw new Error(`[file-system-process] unknown ipc type`);
|
|
1796
|
-
};
|
|
1797
|
-
|
|
1798
|
-
const getModule = method => {
|
|
1799
|
-
switch (method) {
|
|
1800
|
-
case ElectronMessagePort:
|
|
1801
|
-
return ElectronMessagePortRpcClient.create;
|
|
1802
|
-
case ElectronUtilityProcess:
|
|
1803
|
-
return ElectronUtilityProcessRpcClient.create;
|
|
1804
|
-
case NodeForkedProcess:
|
|
1805
|
-
return NodeForkedProcessRpcClient.create;
|
|
1806
|
-
case NodeWorker:
|
|
1807
|
-
return NodeWorkerRpcClient.create;
|
|
1808
|
-
case WebSocket:
|
|
1809
|
-
return NodeWebSocketRpcClient.create;
|
|
1810
|
-
default:
|
|
1811
|
-
throw new Error('unexpected ipc type');
|
|
1812
|
-
}
|
|
1813
|
-
};
|
|
1814
|
-
|
|
1815
|
-
const listen$1 = async ({
|
|
1816
|
-
method,
|
|
1817
|
-
...params
|
|
1818
|
-
}) => {
|
|
1819
|
-
const create = getModule(method);
|
|
1820
|
-
const rpc = await create(params);
|
|
1821
|
-
return rpc;
|
|
1822
|
-
};
|
|
1823
|
-
|
|
1824
1841
|
const handleElectronMessagePort = async (messagePort, rpcId) => {
|
|
1825
1842
|
object(messagePort);
|
|
1826
|
-
const rpc = await
|
|
1843
|
+
const rpc = await create$8({
|
|
1844
|
+
commandMap: {},
|
|
1827
1845
|
messagePort,
|
|
1828
|
-
|
|
1846
|
+
requiresSocket: false
|
|
1829
1847
|
});
|
|
1830
1848
|
if (rpcId) {
|
|
1831
1849
|
set$2(rpcId, rpc);
|
|
@@ -1838,75 +1856,16 @@ const requiresSocket = method => {
|
|
|
1838
1856
|
const handleWebSocket = async (handle, request) => {
|
|
1839
1857
|
object(handle);
|
|
1840
1858
|
object(request);
|
|
1841
|
-
await
|
|
1859
|
+
await create$3({
|
|
1860
|
+
commandMap: {},
|
|
1842
1861
|
handle,
|
|
1843
|
-
method: WebSocket,
|
|
1844
1862
|
request,
|
|
1845
1863
|
requiresSocket
|
|
1846
1864
|
});
|
|
1847
1865
|
};
|
|
1848
1866
|
|
|
1849
|
-
const state = {
|
|
1850
|
-
id: 0
|
|
1851
|
-
};
|
|
1852
|
-
const create = () => {
|
|
1853
|
-
return ++state.id;
|
|
1854
|
-
};
|
|
1855
|
-
|
|
1856
|
-
const {
|
|
1857
|
-
invoke,
|
|
1858
|
-
invokeAndTransfer} = SharedProcess;
|
|
1859
|
-
|
|
1860
|
-
const ports = Object.create(null);
|
|
1861
|
-
const getPortTuple$1 = async () => {
|
|
1862
|
-
const id1 = create();
|
|
1863
|
-
const id2 = create();
|
|
1864
|
-
// @ts-ignore
|
|
1865
|
-
await invoke('TemporaryMessagePort.getPortTuple3', id1, id2, FileSystemProcess);
|
|
1866
|
-
const port1 = ports[id1];
|
|
1867
|
-
const port2 = ports[id2];
|
|
1868
|
-
delete ports[id1];
|
|
1869
|
-
delete ports[id2];
|
|
1870
|
-
return {
|
|
1871
|
-
port1,
|
|
1872
|
-
port2
|
|
1873
|
-
};
|
|
1874
|
-
};
|
|
1875
|
-
const handlePorts = (port1, port2, id1, id2) => {
|
|
1876
|
-
number(id1);
|
|
1877
|
-
number(id2);
|
|
1878
|
-
object(port1);
|
|
1879
|
-
object(port2);
|
|
1880
|
-
ports[id1] = port1;
|
|
1881
|
-
ports[id2] = port2;
|
|
1882
|
-
};
|
|
1883
|
-
|
|
1884
|
-
const getPortTuple = async () => {
|
|
1885
|
-
const {
|
|
1886
|
-
port1,
|
|
1887
|
-
port2
|
|
1888
|
-
} = await getPortTuple$1();
|
|
1889
|
-
return {
|
|
1890
|
-
port1,
|
|
1891
|
-
port2
|
|
1892
|
-
};
|
|
1893
|
-
};
|
|
1894
|
-
|
|
1895
|
-
const createMainProcessRpc = async () => {
|
|
1896
|
-
const rpc = await LazyTransferElectronMessagePortRpc.create({
|
|
1897
|
-
commandMap: {},
|
|
1898
|
-
getPortTuple,
|
|
1899
|
-
async send(port) {
|
|
1900
|
-
await invokeAndTransfer(
|
|
1901
|
-
// @ts-ignore
|
|
1902
|
-
'TemporaryMessagePort.sendToElectron', port, MainProcess, FileSystemProcess);
|
|
1903
|
-
}
|
|
1904
|
-
});
|
|
1905
|
-
set$1(rpc);
|
|
1906
|
-
};
|
|
1907
|
-
|
|
1908
1867
|
const initialize = async () => {
|
|
1909
|
-
|
|
1868
|
+
// TODO this function is not needed anymore
|
|
1910
1869
|
};
|
|
1911
1870
|
|
|
1912
1871
|
const commandMap = {
|
|
@@ -1933,11 +1892,32 @@ const commandMap = {
|
|
|
1933
1892
|
'TemporaryMessagePort.handlePorts': handlePorts
|
|
1934
1893
|
};
|
|
1935
1894
|
|
|
1895
|
+
const getRpc = argv => {
|
|
1896
|
+
if (argv.includes('--ipc-type=node-worker')) {
|
|
1897
|
+
return create$2({
|
|
1898
|
+
commandMap: commandMap
|
|
1899
|
+
});
|
|
1900
|
+
}
|
|
1901
|
+
if (argv.includes('--ipc-type=node-forked-process')) {
|
|
1902
|
+
return create$4({
|
|
1903
|
+
commandMap: commandMap
|
|
1904
|
+
});
|
|
1905
|
+
}
|
|
1906
|
+
if (argv.includes('--ipc-type=electron-utility-process')) {
|
|
1907
|
+
return create$7({
|
|
1908
|
+
commandMap: commandMap
|
|
1909
|
+
});
|
|
1910
|
+
}
|
|
1911
|
+
throw new Error(`[file-system-process] unknown ipc type`);
|
|
1912
|
+
};
|
|
1913
|
+
const initializeParentProcessRpc = async argv => {
|
|
1914
|
+
const rpc = await getRpc(argv);
|
|
1915
|
+
// TODO we don't know at this point if we have been launched by shared process or electron main process
|
|
1916
|
+
set(rpc);
|
|
1917
|
+
};
|
|
1918
|
+
|
|
1936
1919
|
const listen = async argv => {
|
|
1937
|
-
await
|
|
1938
|
-
commandMap: commandMap,
|
|
1939
|
-
method: Auto(argv)
|
|
1940
|
-
});
|
|
1920
|
+
await Promise.all([initializeParentProcessRpc(argv), initializeMainProcessRpc()]);
|
|
1941
1921
|
};
|
|
1942
1922
|
|
|
1943
1923
|
const main = async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/file-system-process",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "File System Process",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Lvce Editor",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
"file-system-process": "bin/fileSystemProcess.js"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"trash": "^10.
|
|
22
|
-
"ws": "^8.
|
|
21
|
+
"trash": "^10.1.1",
|
|
22
|
+
"ws": "^8.20.0"
|
|
23
23
|
},
|
|
24
24
|
"engines": {
|
|
25
|
-
"node": ">=
|
|
25
|
+
"node": ">=24"
|
|
26
26
|
}
|
|
27
27
|
}
|