@lvce-editor/file-system-process 2.1.0 → 2.3.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 +68 -29
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -130,6 +130,7 @@ const Socket = 8;
130
130
  const Symlink = 9;
131
131
  const Unknown = 12;
132
132
 
133
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
133
134
  const getDirentType = dirent => {
134
135
  if (dirent.isFile()) {
135
136
  return File;
@@ -177,12 +178,15 @@ const getFolderSizeInternal = async path => {
177
178
 
178
179
  // @ts-ignore
179
180
  const isEnoentErrorWindows = error => {
180
- return error && error.message && error.message.includes('The system cannot find the path specified.');
181
+ if (!error || !error.message) {
182
+ return false;
183
+ }
184
+ return error.message.includes('The system cannot find the path specified.');
181
185
  };
182
186
 
183
187
  // @ts-ignore
184
188
  const isEnoentErrorLinux = error => {
185
- return error.code === ENOENT;
189
+ return Boolean(error && error.code === ENOENT);
186
190
  };
187
191
 
188
192
  // @ts-ignore
@@ -194,7 +198,7 @@ const isEnoentError = error => {
194
198
  };
195
199
 
196
200
  const rpcs = Object.create(null);
197
- const set$7 = (id, rpc) => {
201
+ const set$f = (id, rpc) => {
198
202
  rpcs[id] = rpc;
199
203
  };
200
204
  const get$1 = id => {
@@ -218,19 +222,22 @@ const create$6 = rpcId => {
218
222
  return rpc.invokeAndTransfer(method, ...params);
219
223
  },
220
224
  set(rpc) {
221
- set$7(rpcId, rpc);
225
+ set$f(rpcId, rpc);
226
+ },
227
+ async dispose() {
228
+ const rpc = get$1(rpcId);
229
+ await rpc.dispose();
222
230
  }
223
231
  };
224
232
  };
225
233
  const MainProcess$1 = -5;
226
234
  const {
227
- invoke: invoke$3,
228
- set: set$3
229
- } = create$6(MainProcess$1);
235
+ invoke: invoke$6,
236
+ set: set$6} = create$6(MainProcess$1);
230
237
  const MainProcess = {
231
238
  __proto__: null,
232
- invoke: invoke$3,
233
- set: set$3
239
+ invoke: invoke$6,
240
+ set: set$6
234
241
  };
235
242
 
236
243
  const {
@@ -259,12 +266,15 @@ const getTrashFn = isElectron => {
259
266
  };
260
267
 
261
268
  const getElectronRunAsNode = () => {
262
- return process.env.ELECTRON_RUN_AS_NODE;
269
+ return process.env.ELECTRON_RUN_AS_NODE || '';
263
270
  };
264
271
 
265
272
  const isElectron = Boolean(getElectronRunAsNode()) || 'electron' in process.versions;
266
273
 
267
274
  const trash = async path => {
275
+ if (!path || path.trim() === '') {
276
+ throw new Error('Path cannot be empty');
277
+ }
268
278
  try {
269
279
  const fn = getTrashFn(isElectron);
270
280
  await fn(path);
@@ -865,7 +875,7 @@ const listen$3 = async () => {
865
875
  parentPort
866
876
  } = await import('node:worker_threads');
867
877
  if (!parentPort) {
868
- throw new IpcError('parentPort is required');
878
+ throw new IpcError('parentPort is required for node worker threads ipc');
869
879
  }
870
880
  return parentPort;
871
881
  };
@@ -1000,8 +1010,6 @@ const handleUpgrade$1 = async (...args) => {
1000
1010
  // @ts-ignore
1001
1011
  return module.handleUpgrade(...args);
1002
1012
  };
1003
-
1004
- // @ts-ignore
1005
1013
  const listen$1$1 = async ({
1006
1014
  request,
1007
1015
  handle
@@ -1022,8 +1030,6 @@ const listen$1$1 = async ({
1022
1030
  const signal$4 = webSocket => {
1023
1031
  webSocket.resume();
1024
1032
  };
1025
-
1026
- // @ts-ignore
1027
1033
  const wrap$9 = webSocket => {
1028
1034
  return {
1029
1035
  webSocket,
@@ -1178,6 +1184,16 @@ const constructError = (message, type, name) => {
1178
1184
  }
1179
1185
  return new ErrorConstructor(message);
1180
1186
  };
1187
+ const joinLines = lines => {
1188
+ return lines.join(NewLine);
1189
+ };
1190
+ const splitLines = lines => {
1191
+ return lines.split(NewLine);
1192
+ };
1193
+ const getCurrentStack = () => {
1194
+ const currentStack = joinLines(splitLines(new Error().stack || '').slice(2));
1195
+ return currentStack;
1196
+ };
1181
1197
  const getNewLineIndex = (string, startIndex = undefined) => {
1182
1198
  return string.indexOf(NewLine, startIndex);
1183
1199
  };
@@ -1188,19 +1204,16 @@ const getParentStack = error => {
1188
1204
  }
1189
1205
  return parentStack;
1190
1206
  };
1191
- const joinLines = lines => {
1192
- return lines.join(NewLine);
1193
- };
1194
1207
  const MethodNotFound = -32601;
1195
1208
  const Custom = -32001;
1196
- const splitLines = lines => {
1197
- return lines.split(NewLine);
1198
- };
1199
1209
  const restoreJsonRpcError = error => {
1210
+ const currentStack = getCurrentStack();
1200
1211
  if (error && error instanceof Error) {
1212
+ if (typeof error.stack === 'string') {
1213
+ error.stack = error.stack + NewLine + currentStack;
1214
+ }
1201
1215
  return error;
1202
1216
  }
1203
- const currentStack = joinLines(splitLines(new Error().stack || '').slice(1));
1204
1217
  if (error && error.code && error.code === MethodNotFound) {
1205
1218
  const restoredError = new JsonRpcError(error.message);
1206
1219
  const parentStack = getParentStack(error);
@@ -1281,6 +1294,17 @@ const getErrorType = prettyError => {
1281
1294
  }
1282
1295
  return undefined;
1283
1296
  };
1297
+ const isAlreadyStack = line => {
1298
+ return line.trim().startsWith('at ');
1299
+ };
1300
+ const getStack = prettyError => {
1301
+ const stackString = prettyError.stack || '';
1302
+ const newLineIndex = stackString.indexOf('\n');
1303
+ if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
1304
+ return stackString.slice(newLineIndex + 1);
1305
+ }
1306
+ return stackString;
1307
+ };
1284
1308
  const getErrorProperty = (error, prettyError) => {
1285
1309
  if (error && error.code === E_COMMAND_NOT_FOUND) {
1286
1310
  return {
@@ -1293,7 +1317,7 @@ const getErrorProperty = (error, prettyError) => {
1293
1317
  code: Custom,
1294
1318
  message: prettyError.message,
1295
1319
  data: {
1296
- stack: prettyError.stack,
1320
+ stack: getStack(prettyError),
1297
1321
  codeFrame: prettyError.codeFrame,
1298
1322
  type: getErrorType(prettyError),
1299
1323
  code: prettyError.code,
@@ -1301,18 +1325,18 @@ const getErrorProperty = (error, prettyError) => {
1301
1325
  }
1302
1326
  };
1303
1327
  };
1304
- const create$1 = (message, error) => {
1328
+ const create$1 = (id, error) => {
1305
1329
  return {
1306
1330
  jsonrpc: Two,
1307
- id: message.id,
1331
+ id,
1308
1332
  error
1309
1333
  };
1310
1334
  };
1311
- const getErrorResponse = (message, error, preparePrettyError, logError) => {
1335
+ const getErrorResponse = (id, error, preparePrettyError, logError) => {
1312
1336
  const prettyError = preparePrettyError(error);
1313
1337
  logError(error, prettyError);
1314
1338
  const errorProperty = getErrorProperty(error, prettyError);
1315
- return create$1(message, errorProperty);
1339
+ return create$1(id, errorProperty);
1316
1340
  };
1317
1341
  const create = (message, result) => {
1318
1342
  return {
@@ -1325,12 +1349,27 @@ const getSuccessResponse = (message, result) => {
1325
1349
  const resultProperty = result ?? null;
1326
1350
  return create(message, resultProperty);
1327
1351
  };
1352
+ const getErrorResponseSimple = (id, error) => {
1353
+ return {
1354
+ jsonrpc: Two,
1355
+ id,
1356
+ error: {
1357
+ code: Custom,
1358
+ // @ts-ignore
1359
+ message: error.message,
1360
+ data: error
1361
+ }
1362
+ };
1363
+ };
1328
1364
  const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
1329
1365
  try {
1330
1366
  const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
1331
1367
  return getSuccessResponse(message, result);
1332
1368
  } catch (error) {
1333
- return getErrorResponse(message, error, preparePrettyError, logError);
1369
+ if (ipc.canUseSimpleErrorResponse) {
1370
+ return getErrorResponseSimple(message.id, error);
1371
+ }
1372
+ return getErrorResponse(message.id, error, preparePrettyError, logError);
1334
1373
  }
1335
1374
  };
1336
1375
  const defaultPreparePrettyError = error => {
@@ -1385,7 +1424,7 @@ const handleJsonRpcMessage = async (...args) => {
1385
1424
  try {
1386
1425
  ipc.send(response);
1387
1426
  } catch (error) {
1388
- const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
1427
+ const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
1389
1428
  ipc.send(errorResponse);
1390
1429
  }
1391
1430
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-system-process",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "description": "File System Process",
5
5
  "keywords": [
6
6
  "Lvce Editor",