@lvce-editor/file-system-worker 4.0.0 → 4.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.
@@ -96,12 +96,6 @@ const object = value => {
96
96
  throw new AssertionError('expected value to be of type object');
97
97
  }
98
98
  };
99
- const number = value => {
100
- const type = getType(value);
101
- if (type !== Number$1) {
102
- throw new AssertionError('expected value to be of type number');
103
- }
104
- };
105
99
 
106
100
  const isMessagePort = value => {
107
101
  return value && value instanceof MessagePort;
@@ -584,7 +578,7 @@ const create$4$1 = (method, params) => {
584
578
  };
585
579
  };
586
580
  const callbacks = Object.create(null);
587
- const set$5 = (id, fn) => {
581
+ const set$4 = (id, fn) => {
588
582
  callbacks[id] = fn;
589
583
  };
590
584
  const get$1 = id => {
@@ -603,7 +597,7 @@ const registerPromise = () => {
603
597
  resolve,
604
598
  promise
605
599
  } = Promise.withResolvers();
606
- set$5(id, resolve);
600
+ set$4(id, resolve);
607
601
  return {
608
602
  id,
609
603
  promise
@@ -948,10 +942,10 @@ const send = (transport, method, ...params) => {
948
942
  const message = create$4$1(method, params);
949
943
  transport.send(message);
950
944
  };
951
- const invoke$5 = (ipc, method, ...params) => {
945
+ const invoke$4 = (ipc, method, ...params) => {
952
946
  return invokeHelper(ipc, method, params, false);
953
947
  };
954
- const invokeAndTransfer$3 = (ipc, method, ...params) => {
948
+ const invokeAndTransfer$2 = (ipc, method, ...params) => {
955
949
  return invokeHelper(ipc, method, params, true);
956
950
  };
957
951
 
@@ -987,10 +981,10 @@ const createRpc = ipc => {
987
981
  send(ipc, method, ...params);
988
982
  },
989
983
  invoke(method, ...params) {
990
- return invoke$5(ipc, method, ...params);
984
+ return invoke$4(ipc, method, ...params);
991
985
  },
992
986
  invokeAndTransfer(method, ...params) {
993
- return invokeAndTransfer$3(ipc, method, ...params);
987
+ return invokeAndTransfer$2(ipc, method, ...params);
994
988
  },
995
989
  async dispose() {
996
990
  await ipc?.dispose();
@@ -1048,18 +1042,23 @@ const PlainMessagePortRpc = {
1048
1042
  __proto__: null,
1049
1043
  create: create$5
1050
1044
  };
1051
- const create$4 = async ({
1045
+ const create$3 = async ({
1052
1046
  commandMap,
1053
- messagePort
1047
+ send
1054
1048
  }) => {
1049
+ const {
1050
+ port1,
1051
+ port2
1052
+ } = new MessageChannel();
1053
+ await send(port1);
1055
1054
  return create$5({
1056
1055
  commandMap,
1057
- messagePort
1056
+ messagePort: port2
1058
1057
  });
1059
1058
  };
1060
- const PlainMessagePortRpcParent = {
1059
+ const TransferMessagePortRpcParent = {
1061
1060
  __proto__: null,
1062
- create: create$4
1061
+ create: create$3
1063
1062
  };
1064
1063
  const create$2 = async ({
1065
1064
  commandMap,
@@ -1109,7 +1108,7 @@ const WebSocketRpcParent2 = {
1109
1108
  __proto__: null,
1110
1109
  create: create$1
1111
1110
  };
1112
- const create$3 = async ({
1111
+ const create$4 = async ({
1113
1112
  commandMap
1114
1113
  }) => {
1115
1114
  // TODO create a commandMap per rpc instance
@@ -1121,7 +1120,7 @@ const create$3 = async ({
1121
1120
  };
1122
1121
  const WebWorkerRpcClient = {
1123
1122
  __proto__: null,
1124
- create: create$3
1123
+ create: create$4
1125
1124
  };
1126
1125
  const createMockRpc = ({
1127
1126
  commandMap
@@ -1143,6 +1142,173 @@ const createMockRpc = ({
1143
1142
  return mockRpc;
1144
1143
  };
1145
1144
 
1145
+ const DebugWorker = 55;
1146
+ const ExtensionHostWorker = 44;
1147
+ const FileSystemProcess$1 = 210;
1148
+ const FileSystemWorker = 209;
1149
+ const RendererProcess = 1670;
1150
+ const RendererWorker = 1;
1151
+
1152
+ const rpcs = Object.create(null);
1153
+ const set$3 = (id, rpc) => {
1154
+ rpcs[id] = rpc;
1155
+ };
1156
+ const get = id => {
1157
+ return rpcs[id];
1158
+ };
1159
+
1160
+ const create = rpcId => {
1161
+ return {
1162
+ // @ts-ignore
1163
+ invoke(method, ...params) {
1164
+ const rpc = get(rpcId);
1165
+ // @ts-ignore
1166
+ return rpc.invoke(method, ...params);
1167
+ },
1168
+ // @ts-ignore
1169
+ invokeAndTransfer(method, ...params) {
1170
+ const rpc = get(rpcId);
1171
+ // @ts-ignore
1172
+ return rpc.invokeAndTransfer(method, ...params);
1173
+ },
1174
+ set(rpc) {
1175
+ set$3(rpcId, rpc);
1176
+ },
1177
+ async dispose() {
1178
+ const rpc = get(rpcId);
1179
+ await rpc.dispose();
1180
+ }
1181
+ };
1182
+ };
1183
+
1184
+ const {
1185
+ invoke: invoke$3,
1186
+ invokeAndTransfer: invokeAndTransfer$1,
1187
+ set: set$2,
1188
+ dispose
1189
+ } = create(FileSystemProcess$1);
1190
+ const remove$3 = async uri => {
1191
+ return invoke$3('FileSystem.remove', uri);
1192
+ };
1193
+ const readFile$4 = async uri => {
1194
+ return invoke$3('FileSystem.readFile', uri);
1195
+ };
1196
+ const appendFile$2 = async (uri, text) => {
1197
+ // @ts-ignore
1198
+ return invoke$3('FileSystem.appendFile', uri, text);
1199
+ };
1200
+ const readDirWithFileTypes$2 = async uri => {
1201
+ return invoke$3('FileSystem.readDirWithFileTypes', uri);
1202
+ };
1203
+ const getPathSeparator$2 = async root => {
1204
+ // @ts-ignore
1205
+ return invoke$3('FileSystem.getPathSeparator', root);
1206
+ };
1207
+ const readJson$4 = async root => {
1208
+ // @ts-ignore
1209
+ return invoke$3('FileSystem.readJson', root);
1210
+ };
1211
+ const getRealPath$2 = async path => {
1212
+ // @ts-ignore
1213
+ return invoke$3('FileSystem.getRealPath', path);
1214
+ };
1215
+ const stat$2 = async path => {
1216
+ // @ts-ignore
1217
+ return invoke$3('FileSystem.stat', path);
1218
+ };
1219
+ const writeFile$3 = async (path, content) => {
1220
+ // @ts-ignore
1221
+ return invoke$3('FileSystem.writeFile', path, content);
1222
+ };
1223
+ const mkdir$2 = async path => {
1224
+ // @ts-ignore
1225
+ return invoke$3('FileSystem.mkdir', path);
1226
+ };
1227
+ const rename$3 = async (oldUri, newUri) => {
1228
+ // @ts-ignore
1229
+ return invoke$3('FileSystem.rename', oldUri, newUri);
1230
+ };
1231
+ const copy$2 = async (oldUri, newUri) => {
1232
+ // @ts-ignore
1233
+ return invoke$3('FileSystem.copy', oldUri, newUri);
1234
+ };
1235
+ const getFolderSize$2 = async uri => {
1236
+ // @ts-ignore
1237
+ return invoke$3('FileSystem.getFolderSize', uri);
1238
+ };
1239
+ const exists$3 = async uri => {
1240
+ // @ts-ignore
1241
+ return invoke$3('FileSystem.exists', uri);
1242
+ };
1243
+ const registerMockRpc = commandMap => {
1244
+ const mockRpc = createMockRpc({
1245
+ commandMap
1246
+ });
1247
+ set$2(mockRpc);
1248
+ return mockRpc;
1249
+ };
1250
+
1251
+ const FileSystemProcess = {
1252
+ __proto__: null,
1253
+ appendFile: appendFile$2,
1254
+ copy: copy$2,
1255
+ dispose,
1256
+ exists: exists$3,
1257
+ getFolderSize: getFolderSize$2,
1258
+ getPathSeparator: getPathSeparator$2,
1259
+ getRealPath: getRealPath$2,
1260
+ invoke: invoke$3,
1261
+ invokeAndTransfer: invokeAndTransfer$1,
1262
+ mkdir: mkdir$2,
1263
+ readDirWithFileTypes: readDirWithFileTypes$2,
1264
+ readFile: readFile$4,
1265
+ readJson: readJson$4,
1266
+ registerMockRpc,
1267
+ remove: remove$3,
1268
+ rename: rename$3,
1269
+ set: set$2,
1270
+ stat: stat$2,
1271
+ writeFile: writeFile$3
1272
+ };
1273
+
1274
+ const {
1275
+ invokeAndTransfer,
1276
+ set: set$1} = create(RendererWorker);
1277
+ const sendMessagePortToExtensionHostWorker = async (port, rpcId = 0) => {
1278
+ const command = 'HandleMessagePort.handleMessagePort2';
1279
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
1280
+ };
1281
+ const sendMessagePortToRendererProcess = async port => {
1282
+ const command = 'HandleMessagePort.handleMessagePort';
1283
+ // @ts-ignore
1284
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToRendererProcess', port, command, DebugWorker);
1285
+ };
1286
+
1287
+ const createLazyRpc = rpcId => {
1288
+ let rpcPromise;
1289
+ let factory;
1290
+ const createRpc = async () => {
1291
+ const rpc = await factory();
1292
+ set$3(rpcId, rpc);
1293
+ };
1294
+ const ensureRpc = async () => {
1295
+ if (!rpcPromise) {
1296
+ rpcPromise = createRpc();
1297
+ }
1298
+ await rpcPromise;
1299
+ };
1300
+ return {
1301
+ setFactory(value) {
1302
+ factory = value;
1303
+ },
1304
+ async invoke(method, ...params) {
1305
+ await ensureRpc();
1306
+ const rpc = get(rpcId);
1307
+ return rpc.invoke(method, ...params);
1308
+ }
1309
+ };
1310
+ };
1311
+
1146
1312
  // TODO: including these in blob-util.ts causes typedoc to generate docs for them,
1147
1313
  // even with --excludePrivate ¯\_(ツ)_/¯
1148
1314
  /** @private */
@@ -1310,7 +1476,6 @@ const normalizeBlobError = error => {
1310
1476
  return error;
1311
1477
  };
1312
1478
 
1313
- /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
1314
1479
  const binaryStringToBlob = async (string, type) => {
1315
1480
  try {
1316
1481
  return binaryStringToBlob$1(string, type);
@@ -1328,7 +1493,7 @@ const blobToBinaryString = async blob => {
1328
1493
  }
1329
1494
  };
1330
1495
 
1331
- const readFile$5 = async uri => {
1496
+ const readFile$3 = async uri => {
1332
1497
  const response = await fetch(uri);
1333
1498
  if (!response.ok) {
1334
1499
  throw new Error(response.statusText);
@@ -1344,14 +1509,14 @@ const readFileAsBlob$1 = async uri => {
1344
1509
  const result = await response.blob();
1345
1510
  return result;
1346
1511
  };
1347
- const exists$3 = async uri => {
1512
+ const exists$2 = async uri => {
1348
1513
  const response = await fetch(uri);
1349
1514
  if (response.ok) {
1350
1515
  return true;
1351
1516
  }
1352
1517
  return false;
1353
1518
  };
1354
- const readJson$4 = async uri => {
1519
+ const readJson$3 = async uri => {
1355
1520
  const response = await fetch(uri);
1356
1521
  if (!response.ok) {
1357
1522
  throw new Error(`${response.statusText}`);
@@ -1360,555 +1525,9 @@ const readJson$4 = async uri => {
1360
1525
  return json;
1361
1526
  };
1362
1527
 
1363
- const Script = 2;
1364
-
1365
- const DebugWorker = 55;
1366
- const ExtensionHostWorker = 44;
1367
- const FileSystemProcess$1 = 210;
1368
- const FileSystemWorker = 209;
1369
- const RendererWorker$1 = 1;
1370
-
1371
- const rpcs = Object.create(null);
1372
- const set$4 = (id, rpc) => {
1373
- rpcs[id] = rpc;
1374
- };
1375
- const get = id => {
1376
- return rpcs[id];
1377
- };
1378
-
1379
- const create = rpcId => {
1380
- return {
1381
- // @ts-ignore
1382
- invoke(method, ...params) {
1383
- const rpc = get(rpcId);
1384
- // @ts-ignore
1385
- return rpc.invoke(method, ...params);
1386
- },
1387
- // @ts-ignore
1388
- invokeAndTransfer(method, ...params) {
1389
- const rpc = get(rpcId);
1390
- // @ts-ignore
1391
- return rpc.invokeAndTransfer(method, ...params);
1392
- },
1393
- set(rpc) {
1394
- set$4(rpcId, rpc);
1395
- },
1396
- async dispose() {
1397
- const rpc = get(rpcId);
1398
- await rpc.dispose();
1399
- }
1400
- };
1401
- };
1402
-
1403
- const {
1404
- invoke: invoke$4,
1405
- invokeAndTransfer: invokeAndTransfer$2,
1406
- set: set$3,
1407
- dispose: dispose$1
1408
- } = create(FileSystemProcess$1);
1409
- const remove$3 = async uri => {
1410
- return invoke$4('FileSystem.remove', uri);
1411
- };
1412
- const readFile$4 = async uri => {
1413
- return invoke$4('FileSystem.readFile', uri);
1414
- };
1415
- const appendFile$2 = async (uri, text) => {
1416
- // @ts-ignore
1417
- return invoke$4('FileSystem.appendFile', uri, text);
1418
- };
1419
- const readDirWithFileTypes$2 = async uri => {
1420
- return invoke$4('FileSystem.readDirWithFileTypes', uri);
1421
- };
1422
- const getPathSeparator$2 = async root => {
1423
- // @ts-ignore
1424
- return invoke$4('FileSystem.getPathSeparator', root);
1425
- };
1426
- const readJson$3 = async root => {
1427
- // @ts-ignore
1428
- return invoke$4('FileSystem.readJson', root);
1429
- };
1430
- const getRealPath$2 = async path => {
1431
- // @ts-ignore
1432
- return invoke$4('FileSystem.getRealPath', path);
1433
- };
1434
- const stat$2 = async path => {
1435
- // @ts-ignore
1436
- return invoke$4('FileSystem.stat', path);
1437
- };
1438
- const writeFile$3 = async (path, content) => {
1439
- // @ts-ignore
1440
- return invoke$4('FileSystem.writeFile', path, content);
1441
- };
1442
- const mkdir$2 = async path => {
1443
- // @ts-ignore
1444
- return invoke$4('FileSystem.mkdir', path);
1445
- };
1446
- const rename$3 = async (oldUri, newUri) => {
1447
- // @ts-ignore
1448
- return invoke$4('FileSystem.rename', oldUri, newUri);
1449
- };
1450
- const copy$2 = async (oldUri, newUri) => {
1451
- // @ts-ignore
1452
- return invoke$4('FileSystem.copy', oldUri, newUri);
1453
- };
1454
- const getFolderSize$3 = async uri => {
1455
- // @ts-ignore
1456
- return invoke$4('FileSystem.getFolderSize', uri);
1457
- };
1458
- const exists$2 = async uri => {
1459
- // @ts-ignore
1460
- return invoke$4('FileSystem.exists', uri);
1461
- };
1462
- const registerMockRpc$1 = commandMap => {
1463
- const mockRpc = createMockRpc({
1464
- commandMap
1465
- });
1466
- set$3(mockRpc);
1467
- return mockRpc;
1468
- };
1469
-
1470
- const FileSystemProcess = {
1471
- __proto__: null,
1472
- appendFile: appendFile$2,
1473
- copy: copy$2,
1474
- dispose: dispose$1,
1475
- exists: exists$2,
1476
- getFolderSize: getFolderSize$3,
1477
- getPathSeparator: getPathSeparator$2,
1478
- getRealPath: getRealPath$2,
1479
- invoke: invoke$4,
1480
- invokeAndTransfer: invokeAndTransfer$2,
1481
- mkdir: mkdir$2,
1482
- readDirWithFileTypes: readDirWithFileTypes$2,
1483
- readFile: readFile$4,
1484
- readJson: readJson$3,
1485
- registerMockRpc: registerMockRpc$1,
1486
- remove: remove$3,
1487
- rename: rename$3,
1488
- set: set$3,
1489
- stat: stat$2,
1490
- writeFile: writeFile$3
1491
- };
1492
-
1493
- const {
1494
- invoke: invoke$3,
1495
- invokeAndTransfer: invokeAndTransfer$1,
1496
- set: set$2,
1497
- dispose
1498
- } = create(RendererWorker$1);
1499
- const searchFileHtml = async uri => {
1500
- return invoke$3('ExtensionHost.searchFileWithHtml', uri);
1501
- };
1502
- const getFilePathElectron = async file => {
1503
- return invoke$3('FileSystemHandle.getFilePathElectron', file);
1504
- };
1505
- /**
1506
- * @deprecated
1507
- */
1508
- const showContextMenu = async (x, y, id, ...args) => {
1509
- return invoke$3('ContextMenu.show', x, y, id, ...args);
1510
- };
1511
- const showContextMenu2 = async (uid, menuId, x, y, args) => {
1512
- number(uid);
1513
- number(menuId);
1514
- number(x);
1515
- number(y);
1516
- // @ts-ignore
1517
- await invoke$3('ContextMenu.show2', uid, menuId, x, y, args);
1518
- };
1519
- const getElectronVersion = async () => {
1520
- return invoke$3('Process.getElectronVersion');
1521
- };
1522
- const applyBulkReplacement = async bulkEdits => {
1523
- await invoke$3('BulkReplacement.applyBulkReplacement', bulkEdits);
1524
- };
1525
- const setColorTheme = async id => {
1526
- // @ts-ignore
1527
- return invoke$3(/* ColorTheme.setColorTheme */'ColorTheme.setColorTheme', /* colorThemeId */id);
1528
- };
1529
- const getNodeVersion = async () => {
1530
- return invoke$3('Process.getNodeVersion');
1531
- };
1532
- const getChromeVersion = async () => {
1533
- return invoke$3('Process.getChromeVersion');
1534
- };
1535
- const getV8Version = async () => {
1536
- return invoke$3('Process.getV8Version');
1537
- };
1538
- const getFileHandles = async fileIds => {
1539
- const files = await invoke$3('FileSystemHandle.getFileHandles', fileIds);
1540
- return files;
1541
- };
1542
- const setWorkspacePath = async path => {
1543
- await invoke$3('Workspace.setPath', path);
1544
- };
1545
- const registerWebViewInterceptor = async (id, port) => {
1546
- await invokeAndTransfer$1('WebView.registerInterceptor', id, port);
1547
- };
1548
- const unregisterWebViewInterceptor = async id => {
1549
- await invoke$3('WebView.unregisterInterceptor', id);
1550
- };
1551
- const sendMessagePortToEditorWorker = async (port, rpcId) => {
1552
- const command = 'HandleMessagePort.handleMessagePort';
1553
- // @ts-ignore
1554
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToEditorWorker', port, command, rpcId);
1555
- };
1556
- const sendMessagePortToErrorWorker = async (port, rpcId) => {
1557
- const command = 'Errors.handleMessagePort';
1558
- // @ts-ignore
1559
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToErrorWorker', port, command, rpcId);
1560
- };
1561
- const sendMessagePortToMarkdownWorker = async (port, rpcId) => {
1562
- const command = 'Markdown.handleMessagePort';
1563
- // @ts-ignore
1564
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToMarkdownWorker', port, command, rpcId);
1565
- };
1566
- const sendMessagePortToIconThemeWorker = async (port, rpcId) => {
1567
- const command = 'IconTheme.handleMessagePort';
1568
- // @ts-ignore
1569
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToIconThemeWorker', port, command, rpcId);
1570
- };
1571
- const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
1572
- const command = 'FileSystem.handleMessagePort';
1573
- // @ts-ignore
1574
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
1575
- };
1576
- const readFile$3 = async uri => {
1577
- return invoke$3('FileSystem.readFile', uri);
1578
- };
1579
- const getWebViewSecret = async key => {
1580
- // @ts-ignore
1581
- return invoke$3('WebView.getSecret', key);
1582
- };
1583
- const setWebViewPort = async (uid, port, origin, portType) => {
1584
- return invokeAndTransfer$1('WebView.setPort', uid, port, origin, portType);
1585
- };
1586
- const setFocus = key => {
1587
- return invoke$3('Focus.setFocus', key);
1588
- };
1589
- const getFileIcon = async options => {
1590
- return invoke$3('IconTheme.getFileIcon', options);
1591
- };
1592
- const getColorThemeNames = async () => {
1593
- return invoke$3('ColorTheme.getColorThemeNames');
1594
- };
1595
- const disableExtension = async id => {
1596
- // @ts-ignore
1597
- return invoke$3('ExtensionManagement.disable', id);
1598
- };
1599
- const enableExtension = async id => {
1600
- // @ts-ignore
1601
- return invoke$3('ExtensionManagement.enable', id);
1602
- };
1603
- const handleDebugChange = async params => {
1604
- // @ts-ignore
1605
- return invoke$3('Run And Debug.handleChange', params);
1606
- };
1607
- const getFolderIcon = async options => {
1608
- return invoke$3('IconTheme.getFolderIcon', options);
1609
- };
1610
- const handleWorkspaceRefresh = async () => {
1611
- return invoke$3('Layout.handleWorkspaceRefresh');
1612
- };
1613
- const closeWidget = async widgetId => {
1614
- return invoke$3('Viewlet.closeWidget', widgetId);
1615
- };
1616
- const sendMessagePortToExtensionHostWorker$1 = async (port, rpcId = 0) => {
1617
- const command = 'HandleMessagePort.handleMessagePort2';
1618
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
1619
- };
1620
- const sendMessagePortToSearchProcess = async port => {
1621
- await invokeAndTransfer$1('SendMessagePortToElectron.sendMessagePortToElectron', port, 'HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess');
1622
- };
1623
- const confirm = async (message, options) => {
1624
- // @ts-ignore
1625
- const result = await invoke$3('ConfirmPrompt.prompt', message, options);
1626
- return result;
1627
- };
1628
- const getRecentlyOpened = async () => {
1629
- return invoke$3(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
1630
- };
1631
- const getKeyBindings = async () => {
1632
- return invoke$3('KeyBindingsInitial.getKeyBindings');
1633
- };
1634
- const writeClipBoardText = async text => {
1635
- await invoke$3('ClipBoard.writeText', /* text */text);
1636
- };
1637
- const readClipBoardText = async () => {
1638
- return invoke$3('ClipBoard.readText');
1639
- };
1640
- const writeClipBoardImage = async blob => {
1641
- // @ts-ignore
1642
- await invoke$3('ClipBoard.writeImage', /* text */blob);
1643
- };
1644
- const searchFileMemory = async uri => {
1645
- // @ts-ignore
1646
- return invoke$3('ExtensionHost.searchFileWithMemory', uri);
1647
- };
1648
- const searchFileFetch = async uri => {
1649
- return invoke$3('ExtensionHost.searchFileWithFetch', uri);
1650
- };
1651
- const showMessageBox = async options => {
1652
- return invoke$3('ElectronDialog.showMessageBox', options);
1653
- };
1654
- const handleDebugResumed = async params => {
1655
- await invoke$3('Run And Debug.handleResumed', params);
1656
- };
1657
- const openWidget = async name => {
1658
- await invoke$3('Viewlet.openWidget', name);
1659
- };
1660
- const getIcons = async requests => {
1661
- const icons = await invoke$3('IconTheme.getIcons', requests);
1662
- return icons;
1663
- };
1664
- const activateByEvent = event => {
1665
- return invoke$3('ExtensionHostManagement.activateByEvent', event);
1666
- };
1667
- const setAdditionalFocus = focusKey => {
1668
- // @ts-ignore
1669
- return invoke$3('Focus.setAdditionalFocus', focusKey);
1670
- };
1671
- const getActiveEditorId = () => {
1672
- // @ts-ignore
1673
- return invoke$3('GetActiveEditor.getActiveEditorId');
1674
- };
1675
- const getWorkspacePath = () => {
1676
- return invoke$3('Workspace.getPath');
1677
- };
1678
- const sendMessagePortToRendererProcess = async port => {
1679
- const command = 'HandleMessagePort.handleMessagePort';
1680
- // @ts-ignore
1681
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToRendererProcess', port, command, DebugWorker);
1682
- };
1683
- const sendMessagePortToTextMeasurementWorker = async port => {
1684
- const command = 'TextMeasurement.handleMessagePort';
1685
- // @ts-ignore
1686
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToTextMeasurementWorker', port, command, 0);
1687
- };
1688
- const sendMessagePortToSourceControlWorker = async port => {
1689
- const command = 'SourceControl.handleMessagePort';
1690
- // @ts-ignore
1691
- await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToSourceControlWorker', port, command, 0);
1692
- };
1693
- const getPreference = async key => {
1694
- return await invoke$3('Preferences.get', key);
1695
- };
1696
- const getAllExtensions = async () => {
1697
- return invoke$3('ExtensionManagement.getAllExtensions');
1698
- };
1699
- const rerenderEditor = async key => {
1700
- // @ts-ignore
1701
- return invoke$3('Editor.rerender', key);
1702
- };
1703
- const handleDebugPaused = async params => {
1704
- await invoke$3('Run And Debug.handlePaused', params);
1705
- };
1706
- const openUri = async (uri, focus, options) => {
1707
- await invoke$3('Main.openUri', uri, focus, options);
1708
- };
1709
- const sendMessagePortToSyntaxHighlightingWorker = async port => {
1710
- await invokeAndTransfer$1(
1711
- // @ts-ignore
1712
- 'SendMessagePortToSyntaxHighlightingWorker.sendMessagePortToSyntaxHighlightingWorker', port, 'HandleMessagePort.handleMessagePort2');
1713
- };
1714
- const handleDebugScriptParsed = async script => {
1715
- await invoke$3('Run And Debug.handleScriptParsed', script);
1716
- };
1717
- const getWindowId = async () => {
1718
- return invoke$3('GetWindowId.getWindowId');
1719
- };
1720
- const getBlob = async uri => {
1721
- // @ts-ignore
1722
- return invoke$3('FileSystem.getBlob', uri);
1723
- };
1724
- const getExtensionCommands = async () => {
1725
- return invoke$3('ExtensionHost.getCommands');
1726
- };
1727
- const showErrorDialog = async errorInfo => {
1728
- // @ts-ignore
1729
- await invoke$3('ErrorHandling.showErrorDialog', errorInfo);
1730
- };
1731
- const getFolderSize$2 = async uri => {
1732
- // @ts-ignore
1733
- return await invoke$3('FileSystem.getFolderSize', uri);
1734
- };
1735
- const getExtension = async id => {
1736
- // @ts-ignore
1737
- return invoke$3('ExtensionManagement.getExtension', id);
1738
- };
1739
- const getMarkdownDom = async html => {
1740
- // @ts-ignore
1741
- return invoke$3('Markdown.getVirtualDom', html);
1742
- };
1743
- const renderMarkdown = async (markdown, options) => {
1744
- // @ts-ignore
1745
- return invoke$3('Markdown.renderMarkdown', markdown, options);
1746
- };
1747
- const openNativeFolder = async uri => {
1748
- // @ts-ignore
1749
- await invoke$3('OpenNativeFolder.openNativeFolder', uri);
1750
- };
1751
- const uninstallExtension = async id => {
1752
- return invoke$3('ExtensionManagement.uninstall', id);
1753
- };
1754
- const installExtension = async id => {
1755
- // @ts-ignore
1756
- return invoke$3('ExtensionManagement.install', id);
1757
- };
1758
- const openExtensionSearch = async () => {
1759
- // @ts-ignore
1760
- return invoke$3('SideBar.openViewlet', 'Extensions');
1761
- };
1762
- const setExtensionsSearchValue = async searchValue => {
1763
- // @ts-ignore
1764
- return invoke$3('Extensions.handleInput', searchValue, Script);
1765
- };
1766
- const openExternal = async uri => {
1767
- // @ts-ignore
1768
- await invoke$3('Open.openExternal', uri);
1769
- };
1770
- const openUrl = async uri => {
1771
- // @ts-ignore
1772
- await invoke$3('Open.openUrl', uri);
1773
- };
1774
- const getAllPreferences = async () => {
1775
- // @ts-ignore
1776
- return invoke$3('Preferences.getAll');
1777
- };
1778
- const showSaveFilePicker = async () => {
1779
- // @ts-ignore
1780
- return invoke$3('FilePicker.showSaveFilePicker');
1781
- };
1782
- const getLogsDir = async () => {
1783
- // @ts-ignore
1784
- return invoke$3('PlatformPaths.getLogsDir');
1785
- };
1786
- const measureTextBlockHeight = async (actualInput, fontFamily, fontSize, lineHeightPx, width) => {
1787
- return invoke$3(`MeasureTextHeight.measureTextBlockHeight`, actualInput, fontFamily, fontSize, lineHeightPx, width);
1788
- };
1789
- const registerMockRpc = commandMap => {
1790
- const mockRpc = createMockRpc({
1791
- commandMap
1792
- });
1793
- set$2(mockRpc);
1794
- return mockRpc;
1795
- };
1796
-
1797
- const RendererWorker = {
1798
- __proto__: null,
1799
- activateByEvent,
1800
- applyBulkReplacement,
1801
- closeWidget,
1802
- confirm,
1803
- disableExtension,
1804
- dispose,
1805
- enableExtension,
1806
- getActiveEditorId,
1807
- getAllExtensions,
1808
- getAllPreferences,
1809
- getBlob,
1810
- getChromeVersion,
1811
- getColorThemeNames,
1812
- getElectronVersion,
1813
- getExtension,
1814
- getExtensionCommands,
1815
- getFileHandles,
1816
- getFileIcon,
1817
- getFilePathElectron,
1818
- getFolderIcon,
1819
- getFolderSize: getFolderSize$2,
1820
- getIcons,
1821
- getKeyBindings,
1822
- getLogsDir,
1823
- getMarkdownDom,
1824
- getNodeVersion,
1825
- getPreference,
1826
- getRecentlyOpened,
1827
- getV8Version,
1828
- getWebViewSecret,
1829
- getWindowId,
1830
- getWorkspacePath,
1831
- handleDebugChange,
1832
- handleDebugPaused,
1833
- handleDebugResumed,
1834
- handleDebugScriptParsed,
1835
- handleWorkspaceRefresh,
1836
- installExtension,
1837
- invoke: invoke$3,
1838
- invokeAndTransfer: invokeAndTransfer$1,
1839
- measureTextBlockHeight,
1840
- openExtensionSearch,
1841
- openExternal,
1842
- openNativeFolder,
1843
- openUri,
1844
- openUrl,
1845
- openWidget,
1846
- readClipBoardText,
1847
- readFile: readFile$3,
1848
- registerMockRpc,
1849
- registerWebViewInterceptor,
1850
- renderMarkdown,
1851
- rerenderEditor,
1852
- searchFileFetch,
1853
- searchFileHtml,
1854
- searchFileMemory,
1855
- sendMessagePortToEditorWorker,
1856
- sendMessagePortToErrorWorker,
1857
- sendMessagePortToExtensionHostWorker: sendMessagePortToExtensionHostWorker$1,
1858
- sendMessagePortToFileSystemWorker,
1859
- sendMessagePortToIconThemeWorker,
1860
- sendMessagePortToMarkdownWorker,
1861
- sendMessagePortToRendererProcess,
1862
- sendMessagePortToSearchProcess,
1863
- sendMessagePortToSourceControlWorker,
1864
- sendMessagePortToSyntaxHighlightingWorker,
1865
- sendMessagePortToTextMeasurementWorker,
1866
- set: set$2,
1867
- setAdditionalFocus,
1868
- setColorTheme,
1869
- setExtensionsSearchValue,
1870
- setFocus,
1871
- setWebViewPort,
1872
- setWorkspacePath,
1873
- showContextMenu,
1874
- showContextMenu2,
1875
- showErrorDialog,
1876
- showMessageBox,
1877
- showSaveFilePicker,
1878
- uninstallExtension,
1879
- unregisterWebViewInterceptor,
1880
- writeClipBoardImage,
1881
- writeClipBoardText
1882
- };
1883
-
1884
- const createLazyRpc = rpcId => {
1885
- let rpcPromise;
1886
- let factory;
1887
- const createRpc = async () => {
1888
- const rpc = await factory();
1889
- set$4(rpcId, rpc);
1890
- };
1891
- const ensureRpc = async () => {
1892
- if (!rpcPromise) {
1893
- rpcPromise = createRpc();
1894
- }
1895
- await rpcPromise;
1896
- };
1897
- return {
1898
- setFactory(value) {
1899
- factory = value;
1900
- },
1901
- async invoke(method, ...params) {
1902
- await ensureRpc();
1903
- const rpc = get(rpcId);
1904
- return rpc.invoke(method, ...params);
1905
- }
1906
- };
1907
- };
1908
-
1909
1528
  const {
1910
1529
  invoke: invoke$2,
1911
- setFactory
1530
+ setFactory: setFactory$1
1912
1531
  } = createLazyRpc(ExtensionHostWorker);
1913
1532
 
1914
1533
  const RE_PROTOCOL = /^([a-z-]+):\/\//;
@@ -1920,22 +1539,22 @@ const assertUri = uri => {
1920
1539
  };
1921
1540
 
1922
1541
  const {
1923
- set: set$1,
1924
- rename: rename$2,
1542
+ appendFile: appendFile$1,
1925
1543
  copy: copy$1,
1926
- mkdir: mkdir$1,
1927
- invoke: invoke$1,
1544
+ exists: exists$1,
1928
1545
  getFolderSize: getFolderSize$1,
1929
- writeFile: writeFile$2,
1930
- stat: stat$1,
1931
- readJson: readJson$2,
1932
1546
  getPathSeparator: getPathSeparator$1,
1933
1547
  getRealPath: getRealPath$1,
1548
+ invoke: invoke$1,
1549
+ mkdir: mkdir$1,
1934
1550
  readDirWithFileTypes: readDirWithFileTypes$1,
1935
1551
  readFile: readFile$2,
1552
+ readJson: readJson$2,
1936
1553
  remove: remove$2,
1937
- exists: exists$1,
1938
- appendFile: appendFile$1
1554
+ rename: rename$2,
1555
+ set,
1556
+ stat: stat$1,
1557
+ writeFile: writeFile$2
1939
1558
  } = FileSystemProcess;
1940
1559
 
1941
1560
  const Http = 'http:';
@@ -1946,8 +1565,8 @@ const File$1 = 'file:';
1946
1565
  const watchCallbacks = Object.create(null);
1947
1566
  const registerWatchCallback = (id, rpcId, commandId, uri) => {
1948
1567
  watchCallbacks[id] = {
1949
- rpcId,
1950
1568
  commandId,
1569
+ rpcId,
1951
1570
  uri
1952
1571
  };
1953
1572
  };
@@ -1957,8 +1576,8 @@ const executeWatchCallBack = async id => {
1957
1576
  throw new Error(`watch callback ${id} not found`);
1958
1577
  }
1959
1578
  const {
1960
- rpcId,
1961
- commandId
1579
+ commandId,
1580
+ rpcId
1962
1581
  } = entry;
1963
1582
  const rpc = get(rpcId);
1964
1583
  await rpc.invoke(commandId, id);
@@ -2043,7 +1662,6 @@ const isMemory = uri => {
2043
1662
  return uri.startsWith(Memory);
2044
1663
  };
2045
1664
 
2046
- /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
2047
1665
  const remove = async dirent => {
2048
1666
  if (isMemory(dirent)) {
2049
1667
  return remove$1(dirent);
@@ -2052,7 +1670,7 @@ const remove = async dirent => {
2052
1670
  };
2053
1671
  const readFile = async uri => {
2054
1672
  if (isHttp(uri)) {
2055
- return readFile$5(uri);
1673
+ return readFile$3(uri);
2056
1674
  }
2057
1675
  if (isMemory(uri)) {
2058
1676
  return readFile$1(uri);
@@ -2070,7 +1688,7 @@ const getPathSeparator = async root => {
2070
1688
  };
2071
1689
  const readJson = async uri => {
2072
1690
  if (isHttp(uri)) {
2073
- return readJson$4(uri);
1691
+ return readJson$3(uri);
2074
1692
  }
2075
1693
  if (isMemory(uri)) {
2076
1694
  return readJson$1();
@@ -2101,7 +1719,7 @@ const stat = async dirent => {
2101
1719
  };
2102
1720
  const exists = async uri => {
2103
1721
  if (isHttp(uri)) {
2104
- return exists$3(uri);
1722
+ return exists$2(uri);
2105
1723
  }
2106
1724
  return exists$1(uri);
2107
1725
  };
@@ -2152,27 +1770,10 @@ const handleMessagePort = async (port, rpcId) => {
2152
1770
  messagePort: port
2153
1771
  });
2154
1772
  if (rpcId) {
2155
- set$4(rpcId, rpc);
1773
+ set$3(rpcId, rpc);
2156
1774
  }
2157
1775
  };
2158
1776
 
2159
- const getPortTuple = () => {
2160
- const {
2161
- port1,
2162
- port2
2163
- } = new MessageChannel();
2164
- return {
2165
- port1,
2166
- port2
2167
- };
2168
- };
2169
-
2170
- const {
2171
- invokeAndTransfer,
2172
- set,
2173
- sendMessagePortToExtensionHostWorker
2174
- } = RendererWorker;
2175
-
2176
1777
  const sendMessagePortToFileSystemProcess = async port => {
2177
1778
  const command = 'HandleMessagePortForFileSystemProcess.handleMessagePortForFileSystemProcess';
2178
1779
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port, command, FileSystemWorker);
@@ -2180,14 +1781,9 @@ const sendMessagePortToFileSystemProcess = async port => {
2180
1781
 
2181
1782
  const createFileSystemProcessRpcElectron = async () => {
2182
1783
  try {
2183
- const {
2184
- port1,
2185
- port2
2186
- } = getPortTuple();
2187
- await sendMessagePortToFileSystemProcess(port2);
2188
- const rpc = await PlainMessagePortRpcParent.create({
1784
+ const rpc = await TransferMessagePortRpcParent.create({
2189
1785
  commandMap: {},
2190
- messagePort: port1
1786
+ send: sendMessagePortToFileSystemProcess
2191
1787
  });
2192
1788
  return rpc;
2193
1789
  } catch (error) {
@@ -2200,8 +1796,8 @@ const commandMapRef = {};
2200
1796
  const createFileSystemProcessRpcNode = async () => {
2201
1797
  try {
2202
1798
  const rpc = await WebSocketRpcParent2.create({
2203
- type: 'file-system-process',
2204
- commandMap: commandMapRef
1799
+ commandMap: commandMapRef,
1800
+ type: 'file-system-process'
2205
1801
  });
2206
1802
  return rpc;
2207
1803
  } catch (error) {
@@ -2234,7 +1830,7 @@ const initializeFileSytemProcess = async platform => {
2234
1830
  return;
2235
1831
  }
2236
1832
  const rpc = await createFileSystemProcessRpc(platform);
2237
- set$1(rpc);
1833
+ set(rpc);
2238
1834
  };
2239
1835
 
2240
1836
  const initialize = async platform => {
@@ -2244,17 +1840,10 @@ const initialize = async platform => {
2244
1840
  const Directory = 'directory';
2245
1841
  const File = 'file';
2246
1842
 
2247
- let rpcPromise = undefined;
2248
- const getOrCreate = () => {
2249
- if (!rpcPromise) {
2250
- rpcPromise = Promise.resolve(get(RendererWorker$1));
2251
- }
2252
- return rpcPromise;
2253
- };
2254
- const invoke = async (method, ...params) => {
2255
- const rpc = await getOrCreate();
2256
- return rpc.invoke(method, ...params);
2257
- };
1843
+ const {
1844
+ invoke,
1845
+ setFactory
1846
+ } = createLazyRpc(RendererProcess);
2258
1847
 
2259
1848
  /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
2260
1849
 
@@ -2287,7 +1876,7 @@ const uploadDirectory = async (fileSystemHandle, pathSeparator, root, uploadHand
2287
1876
  };
2288
1877
 
2289
1878
  const getBinaryString$1 = file => {
2290
- return invoke('Blob.blobToBinaryString', file);
1879
+ return blobToBinaryString(file);
2291
1880
  };
2292
1881
 
2293
1882
  const getFile = handle => {
@@ -2314,10 +1903,10 @@ const uploadHandle = async (fileSystemHandle, pathSeparator, root, uploadHandles
2314
1903
  kind
2315
1904
  } = fileSystemHandle;
2316
1905
  switch (kind) {
2317
- case File:
2318
- return uploadFile(fileSystemHandle, pathSeparator, root);
2319
1906
  case Directory:
2320
1907
  return uploadDirectory(fileSystemHandle, pathSeparator, root, uploadHandles);
1908
+ case File:
1909
+ return uploadFile(fileSystemHandle, pathSeparator, root);
2321
1910
  default:
2322
1911
  throw new Error(`unsupported file system handle type ${kind}`);
2323
1912
  }
@@ -2332,8 +1921,8 @@ const uploadFileSystemHandles = async (root, pathSeparator, fileSystemHandles) =
2332
1921
  if (fileSystemHandles.length === 1) {
2333
1922
  const file = fileSystemHandles[0];
2334
1923
  const {
2335
- name,
2336
- kind
1924
+ kind,
1925
+ name
2337
1926
  } = file;
2338
1927
  if (kind === Directory) {
2339
1928
  await invoke('PersistentFileHandle.addHandle', `/${name}`, file);
@@ -2346,6 +1935,9 @@ const uploadFileSystemHandles = async (root, pathSeparator, fileSystemHandles) =
2346
1935
  };
2347
1936
 
2348
1937
  const commandMap = {
1938
+ 'Blob.base64StringToBlob': base64StringToBlob,
1939
+ 'Blob.binaryStringToBlob': binaryStringToBlob,
1940
+ 'Blob.blobToBinaryString': blobToBinaryString,
2349
1941
  'FileSystem.appendFile': appendFile,
2350
1942
  'FileSystem.copy': copy,
2351
1943
  'FileSystem.createFile': createFile,
@@ -2364,26 +1956,18 @@ const commandMap = {
2364
1956
  'FileSystem.rename': rename,
2365
1957
  'FileSystem.stat': stat,
2366
1958
  'FileSystem.unwatchFile': unwatchFile,
1959
+ 'FileSystem.uploadFileSystemHandles': uploadFileSystemHandles,
2367
1960
  'FileSystem.watchFile': watchFile,
2368
- 'FileSystem.writeFile': writeFile,
2369
1961
  'FileSystem.writeBlob': writeBlob,
2370
- 'FileSystem.uploadFileSystemHandles': uploadFileSystemHandles,
2371
- 'Blob.base64StringToBlob': base64StringToBlob,
2372
- 'Blob.binaryStringToBlob': binaryStringToBlob,
2373
- 'Blob.blobToBinaryString': blobToBinaryString,
1962
+ 'FileSystem.writeFile': writeFile,
2374
1963
  'Initialize.initialize': initialize
2375
1964
  };
2376
1965
 
2377
1966
  const createExtensionHostRpc = async () => {
2378
1967
  try {
2379
- const {
2380
- port1,
2381
- port2
2382
- } = getPortTuple();
2383
- await sendMessagePortToExtensionHostWorker(port2);
2384
- const rpc = await PlainMessagePortRpcParent.create({
1968
+ const rpc = await TransferMessagePortRpcParent.create({
2385
1969
  commandMap: {},
2386
- messagePort: port1
1970
+ send: sendMessagePortToExtensionHostWorker
2387
1971
  });
2388
1972
  return rpc;
2389
1973
  } catch (error) {
@@ -2391,13 +1975,26 @@ const createExtensionHostRpc = async () => {
2391
1975
  }
2392
1976
  };
2393
1977
 
1978
+ const createRendererProcessRpc = async () => {
1979
+ try {
1980
+ const rpc = await TransferMessagePortRpcParent.create({
1981
+ commandMap: {},
1982
+ send: sendMessagePortToRendererProcess
1983
+ });
1984
+ return rpc;
1985
+ } catch (error) {
1986
+ throw new VError(error, `Failed to create renderer process rpc`);
1987
+ }
1988
+ };
1989
+
2394
1990
  const listen = async () => {
2395
1991
  Object.assign(commandMapRef, commandMap);
2396
- setFactory(createExtensionHostRpc);
1992
+ setFactory$1(createExtensionHostRpc);
1993
+ setFactory(createRendererProcessRpc);
2397
1994
  const rpc = await WebWorkerRpcClient.create({
2398
1995
  commandMap: commandMap
2399
1996
  });
2400
- set(rpc);
1997
+ set$1(rpc);
2401
1998
  };
2402
1999
 
2403
2000
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-system-worker",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "File System Worker",
5
5
  "keywords": [
6
6
  "Lvce Editor"