@lvce-editor/file-system-worker 5.10.1 → 5.11.1

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/README.md CHANGED
@@ -10,7 +10,3 @@ cd file-system-worker &&
10
10
  npm ci &&
11
11
  npm test
12
12
  ```
13
-
14
- ## Gitpod
15
-
16
- [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/lvce-editor/file-system-worker)
@@ -324,7 +324,6 @@ const walkValue = (value, transferrables, isTransferrable) => {
324
324
  for (const property of Object.values(value)) {
325
325
  walkValue(property, transferrables, isTransferrable);
326
326
  }
327
- return;
328
327
  }
329
328
  };
330
329
  const getTransferrables = value => {
@@ -478,7 +477,14 @@ class IpcError extends VError {
478
477
  const cause = new Error(message);
479
478
  // @ts-ignore
480
479
  cause.code = code;
481
- cause.stack = stack;
480
+ if (stack) {
481
+ Object.defineProperty(cause, 'stack', {
482
+ configurable: true,
483
+ enumerable: false,
484
+ value: stack,
485
+ writable: true
486
+ });
487
+ }
482
488
  super(cause, betterMessage);
483
489
  } else {
484
490
  super(betterMessage);
@@ -1353,28 +1359,72 @@ const create$3 = async ({
1353
1359
  }) => {
1354
1360
  // TODO create a commandMap per rpc instance
1355
1361
  register$1(commandMap);
1356
- const rawIpc = await IpcParentWithWebSocket$1.create({
1357
- webSocket
1358
- });
1362
+ let rawIpc;
1363
+ try {
1364
+ rawIpc = await IpcParentWithWebSocket$1.create({
1365
+ webSocket
1366
+ });
1367
+ } catch (error) {
1368
+ throw new VError(error, 'Failed to create rpc connection');
1369
+ }
1359
1370
  const ipc = IpcParentWithWebSocket$1.wrap(rawIpc);
1360
1371
  handleIpc(ipc);
1361
1372
  const rpc = createRpc(ipc);
1362
1373
  return rpc;
1363
1374
  };
1364
1375
 
1376
+ const reconnectDelay = 2000;
1377
+ const waitForReconnect = async () => {
1378
+ await new Promise(resolve => {
1379
+ setTimeout(resolve, reconnectDelay);
1380
+ });
1381
+ };
1382
+ const connect = async ({
1383
+ commandMap,
1384
+ wsUrl
1385
+ }) => {
1386
+ const webSocket = new WebSocket(wsUrl);
1387
+ try {
1388
+ const rpc = await create$3({
1389
+ commandMap,
1390
+ webSocket
1391
+ });
1392
+ return {
1393
+ rpc,
1394
+ webSocket
1395
+ };
1396
+ } catch (error) {
1397
+ webSocket.close();
1398
+ throw error;
1399
+ }
1400
+ };
1365
1401
  const create$2 = async ({
1366
1402
  commandMap,
1403
+ onClose,
1367
1404
  type
1368
1405
  }) => {
1369
1406
  const host = getHost();
1370
1407
  const protocol = getProtocol();
1371
1408
  const wsUrl = getWebSocketUrl(type, host, protocol);
1372
- const webSocket = new WebSocket(wsUrl);
1373
- const rpc = await create$3({
1374
- commandMap,
1375
- webSocket
1376
- });
1377
- return rpc;
1409
+ let connection;
1410
+ try {
1411
+ connection = await connect({
1412
+ commandMap,
1413
+ wsUrl
1414
+ });
1415
+ } catch {
1416
+ await waitForReconnect();
1417
+ connection = await connect({
1418
+ commandMap,
1419
+ wsUrl
1420
+ });
1421
+ }
1422
+ if (onClose) {
1423
+ connection.webSocket.addEventListener('close', onClose, {
1424
+ once: true
1425
+ });
1426
+ }
1427
+ return connection.rpc;
1378
1428
  };
1379
1429
 
1380
1430
  const create$1 = async ({
@@ -1714,6 +1764,7 @@ const Memory = 'memfs:';
1714
1764
  const Https = 'https:';
1715
1765
  const File$2 = 'file:';
1716
1766
  const Fetch$1 = 'fetch:';
1767
+ const Html = 'html:';
1717
1768
 
1718
1769
  const watchCallbacks = Object.create(null);
1719
1770
  const registerWatchCallback = (id, rpcId, commandId, uri) => {
@@ -1901,6 +1952,10 @@ const isFetch = uri => {
1901
1952
  return uri.startsWith(Fetch$1);
1902
1953
  };
1903
1954
 
1955
+ const isHtml = uri => {
1956
+ return uri.startsWith(Html);
1957
+ };
1958
+
1904
1959
  const isHttp = uri => {
1905
1960
  return uri.startsWith(Http) || uri.startsWith(Https);
1906
1961
  };
@@ -1916,7 +1971,7 @@ const remove = async dirent => {
1916
1971
  return remove$2(dirent);
1917
1972
  };
1918
1973
  const readFile = async uri => {
1919
- if (isFetch(uri)) {
1974
+ if (isFetch(uri) || isHtml(uri)) {
1920
1975
  return invoke$2('FileSystem.readFile', uri);
1921
1976
  }
1922
1977
  if (isHttp(uri)) {
@@ -1934,7 +1989,7 @@ const appendFile = async (uri, text) => {
1934
1989
  return appendFile$1(uri, text);
1935
1990
  };
1936
1991
  const readDirWithFileTypes = async uri => {
1937
- if (isFetch(uri)) {
1992
+ if (isFetch(uri) || isHtml(uri)) {
1938
1993
  return invoke$2('FileSystem.readDirWithFileTypes', uri);
1939
1994
  }
1940
1995
  if (isMemory(uri)) {
@@ -1983,7 +2038,7 @@ const stat = async dirent => {
1983
2038
  return stat$2(dirent);
1984
2039
  };
1985
2040
  const exists = async uri => {
1986
- if (isFetch(uri)) {
2041
+ if (isFetch(uri) || isHtml(uri)) {
1987
2042
  return invoke$2('FileSystem.exists', uri);
1988
2043
  }
1989
2044
  if (isHttp(uri)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-system-worker",
3
- "version": "5.10.1",
3
+ "version": "5.11.1",
4
4
  "description": "File System Worker",
5
5
  "keywords": [
6
6
  "Lvce Editor"