@lvce-editor/extension-host-worker 1.16.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.
@@ -330,7 +330,7 @@ class NoProviderFoundError extends Error {
330
330
  }
331
331
  }
332
332
 
333
- const normalizeLine$1 = line => {
333
+ const normalizeLine = line => {
334
334
  if (line.startsWith('Error: ')) {
335
335
  return line.slice('Error: '.length);
336
336
  }
@@ -339,41 +339,41 @@ const normalizeLine$1 = line => {
339
339
  }
340
340
  return line;
341
341
  };
342
- const getCombinedMessage$1 = (error, message) => {
343
- const stringifiedError = normalizeLine$1(`${error}`);
342
+ const getCombinedMessage = (error, message) => {
343
+ const stringifiedError = normalizeLine(`${error}`);
344
344
  if (message) {
345
345
  return `${message}: ${stringifiedError}`;
346
346
  }
347
347
  return stringifiedError;
348
348
  };
349
- const NewLine$3 = '\n';
350
- const getNewLineIndex$2 = (string, startIndex = undefined) => {
351
- return string.indexOf(NewLine$3, startIndex);
349
+ const NewLine$2 = '\n';
350
+ const getNewLineIndex$1 = (string, startIndex = undefined) => {
351
+ return string.indexOf(NewLine$2, startIndex);
352
352
  };
353
- const mergeStacks$1 = (parent, child) => {
353
+ const mergeStacks = (parent, child) => {
354
354
  if (!child) {
355
355
  return parent;
356
356
  }
357
- const parentNewLineIndex = getNewLineIndex$2(parent);
358
- const childNewLineIndex = getNewLineIndex$2(child);
357
+ const parentNewLineIndex = getNewLineIndex$1(parent);
358
+ const childNewLineIndex = getNewLineIndex$1(child);
359
359
  if (childNewLineIndex === -1) {
360
360
  return parent;
361
361
  }
362
362
  const parentFirstLine = parent.slice(0, parentNewLineIndex);
363
363
  const childRest = child.slice(childNewLineIndex);
364
- const childFirstLine = normalizeLine$1(child.slice(0, childNewLineIndex));
364
+ const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
365
365
  if (parentFirstLine.includes(childFirstLine)) {
366
366
  return parentFirstLine + childRest;
367
367
  }
368
368
  return child;
369
369
  };
370
- let VError$1 = class VError extends Error {
370
+ class VError extends Error {
371
371
  constructor(error, message) {
372
- const combinedMessage = getCombinedMessage$1(error, message);
372
+ const combinedMessage = getCombinedMessage(error, message);
373
373
  super(combinedMessage);
374
374
  this.name = 'VError';
375
375
  if (error instanceof Error) {
376
- this.stack = mergeStacks$1(this.stack, error.stack);
376
+ this.stack = mergeStacks(this.stack, error.stack);
377
377
  }
378
378
  if (error.codeFrame) {
379
379
  // @ts-ignore
@@ -384,7 +384,7 @@ let VError$1 = class VError extends Error {
384
384
  this.code = error.code;
385
385
  }
386
386
  }
387
- };
387
+ }
388
388
 
389
389
  const getType = value => {
390
390
  switch (typeof value) {
@@ -552,7 +552,7 @@ const registerMethod = ({
552
552
  if (error) {
553
553
  const improvedError = improveValidationError(name, error);
554
554
  // @ts-ignore
555
- throw new VError$1(improvedError);
555
+ throw new VError(improvedError);
556
556
  }
557
557
  return result;
558
558
  } catch (error) {
@@ -562,7 +562,7 @@ const registerMethod = ({
562
562
  if (actualError.message === 'provider[methodName] is not a function') {
563
563
  const camelCaseName = toCamelCase(name);
564
564
  // @ts-ignore
565
- throw new VError$1(`Failed to execute ${spacedOutName} provider: VError: ${camelCaseName}Provider.${methodName} is not a function`);
565
+ throw new VError(`Failed to execute ${spacedOutName} provider: VError: ${camelCaseName}Provider.${methodName} is not a function`);
566
566
  }
567
567
  const message = actualError.name === 'Error' ? `${actualError.message}` : `${actualError.name}: ${actualError.message}`;
568
568
  actualError.message = `Failed to execute ${spacedOutName} provider: ${message}`;
@@ -704,7 +704,7 @@ const registerCommand = command => {
704
704
  state$9.commands[command.id] = command;
705
705
  } catch (error) {
706
706
  const commandDisplayId = getCommandDisplay(command);
707
- throw new VError$1(error, `Failed to register command${commandDisplayId}`);
707
+ throw new VError(error, `Failed to register command${commandDisplayId}`);
708
708
  }
709
709
  };
710
710
  const executeCommand = async (id, ...args) => {
@@ -720,7 +720,7 @@ const executeCommand = async (id, ...args) => {
720
720
  if (error && error.isExpected) {
721
721
  throw error;
722
722
  }
723
- throw new VError$1(error, 'Failed to execute command');
723
+ throw new VError(error, 'Failed to execute command');
724
724
  }
725
725
  };
726
726
 
@@ -827,7 +827,7 @@ class JsonRpcError extends Error {
827
827
  this.name = 'JsonRpcError';
828
828
  }
829
829
  }
830
- const NewLine$2 = '\n';
830
+ const NewLine$1 = '\n';
831
831
  const DomException = 'DOMException';
832
832
  const ReferenceError$1 = 'ReferenceError';
833
833
  const SyntaxError$1 = 'SyntaxError';
@@ -872,23 +872,23 @@ const constructError = (message, type, name) => {
872
872
  }
873
873
  return new ErrorConstructor(message);
874
874
  };
875
- const getNewLineIndex$1 = (string, startIndex = undefined) => {
876
- return string.indexOf(NewLine$2, startIndex);
875
+ const getNewLineIndex = (string, startIndex = undefined) => {
876
+ return string.indexOf(NewLine$1, startIndex);
877
877
  };
878
878
  const getParentStack = error => {
879
879
  let parentStack = error.stack || error.data || error.message || '';
880
880
  if (parentStack.startsWith(' at')) {
881
- parentStack = error.message + NewLine$2 + parentStack;
881
+ parentStack = error.message + NewLine$1 + parentStack;
882
882
  }
883
883
  return parentStack;
884
884
  };
885
885
  const joinLines$1 = lines => {
886
- return lines.join(NewLine$2);
886
+ return lines.join(NewLine$1);
887
887
  };
888
888
  const MethodNotFound = -32601;
889
889
  const Custom = -32001;
890
890
  const splitLines$2 = lines => {
891
- return lines.split(NewLine$2);
891
+ return lines.split(NewLine$1);
892
892
  };
893
893
  const restoreJsonRpcError = error => {
894
894
  if (error && error instanceof Error) {
@@ -898,14 +898,14 @@ const restoreJsonRpcError = error => {
898
898
  if (error && error.code && error.code === MethodNotFound) {
899
899
  const restoredError = new JsonRpcError(error.message);
900
900
  const parentStack = getParentStack(error);
901
- restoredError.stack = parentStack + NewLine$2 + currentStack;
901
+ restoredError.stack = parentStack + NewLine$1 + currentStack;
902
902
  return restoredError;
903
903
  }
904
904
  if (error && error.message) {
905
905
  const restoredError = constructError(error.message, error.type, error.name);
906
906
  if (error.data) {
907
907
  if (error.data.stack && error.data.type && error.message) {
908
- restoredError.stack = error.data.type + ': ' + error.message + NewLine$2 + error.data.stack + NewLine$2 + currentStack;
908
+ restoredError.stack = error.data.type + ': ' + error.message + NewLine$1 + error.data.stack + NewLine$1 + currentStack;
909
909
  } else if (error.data.stack) {
910
910
  restoredError.stack = error.data.stack;
911
911
  }
@@ -925,7 +925,7 @@ const restoreJsonRpcError = error => {
925
925
  if (error.stack) {
926
926
  const lowerStack = restoredError.stack || '';
927
927
  // @ts-ignore
928
- const indexNewLine = getNewLineIndex$1(lowerStack);
928
+ const indexNewLine = getNewLineIndex(lowerStack);
929
929
  const parentStack = getParentStack(error);
930
930
  // @ts-ignore
931
931
  restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
@@ -1161,7 +1161,7 @@ const invokeAndTransfer = (method, ...params) => {
1161
1161
  const ipc = get$4();
1162
1162
  return invokeAndTransfer$1(ipc, method, ...params);
1163
1163
  };
1164
- const listen$4 = ipc => {
1164
+ const listen$1 = ipc => {
1165
1165
  handleIpc(ipc);
1166
1166
  set$4(ipc);
1167
1167
  };
@@ -1173,7 +1173,7 @@ const getDebugProvider = id => {
1173
1173
  const provider = state$6.debugProviderMap[id];
1174
1174
  if (!provider) {
1175
1175
  // @ts-ignore
1176
- throw new VError$1(`no debug provider "${id}" found`);
1176
+ throw new VError(`no debug provider "${id}" found`);
1177
1177
  }
1178
1178
  return provider;
1179
1179
  };
@@ -1202,7 +1202,7 @@ const start = async (protocol, path) => {
1202
1202
  handleScriptParsed
1203
1203
  }, path);
1204
1204
  } catch (error) {
1205
- throw new VError$1(error, 'Failed to execute debug provider');
1205
+ throw new VError(error, 'Failed to execute debug provider');
1206
1206
  }
1207
1207
  };
1208
1208
  const listProcesses = async (protocol, path) => {
@@ -1212,7 +1212,7 @@ const listProcesses = async (protocol, path) => {
1212
1212
  array(processes);
1213
1213
  return processes;
1214
1214
  } catch (error) {
1215
- throw new VError$1(error, 'Failed to execute debug provider');
1215
+ throw new VError(error, 'Failed to execute debug provider');
1216
1216
  }
1217
1217
  };
1218
1218
  const resume = async protocol => {
@@ -1220,7 +1220,7 @@ const resume = async protocol => {
1220
1220
  const provider = getDebugProvider(protocol);
1221
1221
  return await provider.resume();
1222
1222
  } catch (error) {
1223
- throw new VError$1(error, 'Failed to execute debug provider');
1223
+ throw new VError(error, 'Failed to execute debug provider');
1224
1224
  }
1225
1225
  };
1226
1226
  const pause = async protocol => {
@@ -1228,7 +1228,7 @@ const pause = async protocol => {
1228
1228
  const provider = getDebugProvider(protocol);
1229
1229
  return await provider.pause();
1230
1230
  } catch (error) {
1231
- throw new VError$1(error, 'Failed to execute debug provider');
1231
+ throw new VError(error, 'Failed to execute debug provider');
1232
1232
  }
1233
1233
  };
1234
1234
  const stepInto = async protocol => {
@@ -1236,7 +1236,7 @@ const stepInto = async protocol => {
1236
1236
  const provider = getDebugProvider(protocol);
1237
1237
  return await provider.stepInto();
1238
1238
  } catch (error) {
1239
- throw new VError$1(error, 'Failed to execute debug provider');
1239
+ throw new VError(error, 'Failed to execute debug provider');
1240
1240
  }
1241
1241
  };
1242
1242
  const stepOut = async protocol => {
@@ -1244,7 +1244,7 @@ const stepOut = async protocol => {
1244
1244
  const provider = getDebugProvider(protocol);
1245
1245
  return await provider.stepOut();
1246
1246
  } catch (error) {
1247
- throw new VError$1(error, 'Failed to execute debug provider');
1247
+ throw new VError(error, 'Failed to execute debug provider');
1248
1248
  }
1249
1249
  };
1250
1250
  const stepOver = async protocol => {
@@ -1252,7 +1252,7 @@ const stepOver = async protocol => {
1252
1252
  const provider = getDebugProvider(protocol);
1253
1253
  return await provider.stepOver();
1254
1254
  } catch (error) {
1255
- throw new VError$1(error, 'Failed to execute debug provider');
1255
+ throw new VError(error, 'Failed to execute debug provider');
1256
1256
  }
1257
1257
  };
1258
1258
  const setPauseOnException = async (protocol, value) => {
@@ -1260,7 +1260,7 @@ const setPauseOnException = async (protocol, value) => {
1260
1260
  const provider = getDebugProvider(protocol);
1261
1261
  return await provider.setPauseOnExceptions(value);
1262
1262
  } catch (error) {
1263
- throw new VError$1(error, 'Failed to execute debug provider');
1263
+ throw new VError(error, 'Failed to execute debug provider');
1264
1264
  }
1265
1265
  };
1266
1266
  const getProperties = async (protocol, objectId) => {
@@ -1268,7 +1268,7 @@ const getProperties = async (protocol, objectId) => {
1268
1268
  const provider = getDebugProvider(protocol);
1269
1269
  return await provider.getProperties(objectId);
1270
1270
  } catch (error) {
1271
- throw new VError$1(error, 'Failed to execute debug provider');
1271
+ throw new VError(error, 'Failed to execute debug provider');
1272
1272
  }
1273
1273
  };
1274
1274
  const evaluate = async (protocol, expression, callFrameId) => {
@@ -1276,7 +1276,7 @@ const evaluate = async (protocol, expression, callFrameId) => {
1276
1276
  const provider = getDebugProvider(protocol);
1277
1277
  return await provider.evaluate(expression, callFrameId);
1278
1278
  } catch (error) {
1279
- throw new VError$1(error, 'Failed to execute debug provider');
1279
+ throw new VError(error, 'Failed to execute debug provider');
1280
1280
  }
1281
1281
  };
1282
1282
  const setPauseOnExceptions = async (protocol, value) => {
@@ -1284,7 +1284,7 @@ const setPauseOnExceptions = async (protocol, value) => {
1284
1284
  const provider = getDebugProvider(protocol);
1285
1285
  return await provider.setPauseOnExceptions(value);
1286
1286
  } catch (error) {
1287
- throw new VError$1(error, 'Failed to execute setPauseOnExceptions');
1287
+ throw new VError(error, 'Failed to execute setPauseOnExceptions');
1288
1288
  }
1289
1289
  };
1290
1290
 
@@ -1341,7 +1341,7 @@ const get$3 = protocol => {
1341
1341
  const provider = fileSystemProviderMap[protocol];
1342
1342
  if (!provider) {
1343
1343
  // @ts-ignore
1344
- throw new VError$1(`no file system provider for protocol "${protocol}" found`);
1344
+ throw new VError(`no file system provider for protocol "${protocol}" found`);
1345
1345
  }
1346
1346
  return provider;
1347
1347
  };
@@ -1363,7 +1363,7 @@ const readDirWithFileTypes = async (protocol, path) => {
1363
1363
  const provider = get$3(protocol);
1364
1364
  return await provider.readDirWithFileTypes(path);
1365
1365
  } catch (error) {
1366
- throw new VError$1(error, 'Failed to execute file system provider');
1366
+ throw new VError(error, 'Failed to execute file system provider');
1367
1367
  }
1368
1368
  };
1369
1369
  const readFile = async (protocol, path) => {
@@ -1371,7 +1371,7 @@ const readFile = async (protocol, path) => {
1371
1371
  const provider = get$3(protocol);
1372
1372
  return await provider.readFile(path);
1373
1373
  } catch (error) {
1374
- throw new VError$1(error, 'Failed to execute file system provider');
1374
+ throw new VError(error, 'Failed to execute file system provider');
1375
1375
  }
1376
1376
  };
1377
1377
  const readFileExternal = async path => {
@@ -1399,7 +1399,7 @@ const writeFile = async (protocol, uri, content) => {
1399
1399
  const provider = get$3(protocol);
1400
1400
  return await provider.writeFile(uri, content);
1401
1401
  } catch (error) {
1402
- throw new VError$1(error, 'Failed to execute file system provider');
1402
+ throw new VError(error, 'Failed to execute file system provider');
1403
1403
  }
1404
1404
  };
1405
1405
  const getPathSeparator = protocol => {
@@ -1407,7 +1407,7 @@ const getPathSeparator = protocol => {
1407
1407
  const provider = get$3(protocol);
1408
1408
  return provider.pathSeparator;
1409
1409
  } catch (error) {
1410
- throw new VError$1(error, 'Failed to execute file system provider');
1410
+ throw new VError(error, 'Failed to execute file system provider');
1411
1411
  }
1412
1412
  };
1413
1413
 
@@ -1529,7 +1529,7 @@ const create$7 = async ({
1529
1529
  const ipc = module.wrap(rawIpc);
1530
1530
  return ipc;
1531
1531
  } catch (error) {
1532
- throw new VError$1(error, `Failed to create ipc`);
1532
+ throw new VError(error, `Failed to create ipc`);
1533
1533
  }
1534
1534
  };
1535
1535
 
@@ -1578,7 +1578,7 @@ const createNodeRpc = async ({
1578
1578
  await rpc.invoke('LoadFile.loadFile', path);
1579
1579
  return rpc;
1580
1580
  } catch (error) {
1581
- throw new VError$1(error, `Failed to create node rpc`);
1581
+ throw new VError(error, `Failed to create node rpc`);
1582
1582
  }
1583
1583
  };
1584
1584
 
@@ -1782,7 +1782,7 @@ const createRpc = ({
1782
1782
  contentSecurityPolicy
1783
1783
  });
1784
1784
  } catch (error) {
1785
- throw new VError$1(error, `Failed to create webworker rpc`);
1785
+ throw new VError(error, `Failed to create webworker rpc`);
1786
1786
  }
1787
1787
  };
1788
1788
 
@@ -1919,7 +1919,7 @@ const registerTextSearchProvider = textSearchProvider => {
1919
1919
  }
1920
1920
  state$4.textSearchProviders[textSearchProvider.scheme] = textSearchProvider;
1921
1921
  } catch (error) {
1922
- throw new VError$1(error, 'Failed to register text search provider');
1922
+ throw new VError(error, 'Failed to register text search provider');
1923
1923
  }
1924
1924
  };
1925
1925
  const executeTextSearchProvider = async (scheme, query) => {
@@ -1931,7 +1931,7 @@ const executeTextSearchProvider = async (scheme, query) => {
1931
1931
  const results = await textSearchProvider.provideTextSearchResults(query);
1932
1932
  return results;
1933
1933
  } catch (error) {
1934
- throw new VError$1(error, 'Failed to execute text search provider');
1934
+ throw new VError(error, 'Failed to execute text search provider');
1935
1935
  }
1936
1936
  };
1937
1937
 
@@ -2098,6 +2098,16 @@ const getRemoteUrl = async (uri, options = {}) => {
2098
2098
  throw new Error(`unsupported platform for remote url`);
2099
2099
  };
2100
2100
 
2101
+ const waitForFirstMessage$1 = async port => {
2102
+ const {
2103
+ resolve,
2104
+ promise
2105
+ } = Promise.withResolvers();
2106
+ port.onmessage = resolve;
2107
+ const firstMessage = await promise;
2108
+ return firstMessage;
2109
+ };
2110
+
2101
2111
  // TODO pass uuid to allow having multiple webviews open at the same time
2102
2112
  const createWebView = async (providerId, port, uri, uid, origin) => {
2103
2113
  const provider = getProvider(providerId);
@@ -2108,9 +2118,7 @@ const createWebView = async (providerId, port, uri, uid, origin) => {
2108
2118
  // TODO cancel promise when webview is disposed before sending message
2109
2119
  // TODO handle case when webview doesn't send ready message
2110
2120
  // TODO handle error
2111
- await new Promise(resolve => {
2112
- port.onmessage = resolve;
2113
- });
2121
+ await waitForFirstMessage$1(port);
2114
2122
 
2115
2123
  // TODO use ipc module
2116
2124
  const handlePortMessage = async event => {
@@ -2123,10 +2131,14 @@ const createWebView = async (providerId, port, uri, uid, origin) => {
2123
2131
  params,
2124
2132
  id
2125
2133
  } = data;
2134
+ if (id && !method) {
2135
+ resolve(id, data);
2136
+ return;
2137
+ }
2126
2138
  if (provider && provider.commands && provider.commands[method]) {
2127
2139
  const fn = provider.commands[method];
2128
2140
  const result = await fn(...params);
2129
- if (id) {
2141
+ if (id && method) {
2130
2142
  target.postMessage({
2131
2143
  jsonrpc: '2.0',
2132
2144
  id,
@@ -2141,13 +2153,22 @@ const createWebView = async (providerId, port, uri, uid, origin) => {
2141
2153
  provider,
2142
2154
  uid,
2143
2155
  origin,
2144
- invoke(method, ...params) {
2145
- // TODO return promise with result
2156
+ async invoke(method, ...params) {
2157
+ const {
2158
+ id,
2159
+ promise
2160
+ } = registerPromise();
2146
2161
  port.postMessage({
2147
2162
  jsonrpc: '2.0',
2163
+ id,
2148
2164
  method,
2149
2165
  params
2150
2166
  });
2167
+ const result = await promise;
2168
+ if (result.error) {
2169
+ throw new Error(`Error: ${result.error.message}`);
2170
+ }
2171
+ return result.result;
2151
2172
  }
2152
2173
  };
2153
2174
  // TODO allow creating multiple webviews per provider
@@ -2164,6 +2185,14 @@ const disposeWebView = id => {
2164
2185
  const registerWebViewProvider = provider => {
2165
2186
  setProvider(provider.id, provider);
2166
2187
  };
2188
+ const getWebViewInfo = providerId => {
2189
+ const webView = getWebView(providerId);
2190
+ return {
2191
+ uid: webView.uid,
2192
+ origin: webView.origin,
2193
+ uri: webView.uri
2194
+ };
2195
+ };
2167
2196
 
2168
2197
  const createWorker = async ({
2169
2198
  method,
@@ -2243,7 +2272,7 @@ const api = {
2243
2272
  env: env,
2244
2273
  // Errors
2245
2274
  FormattingError,
2246
- VError: VError$1,
2275
+ VError,
2247
2276
  // Exec
2248
2277
  exec: exec,
2249
2278
  // File System
@@ -2799,7 +2828,7 @@ const activate = async (extension, absolutePath) => {
2799
2828
  }
2800
2829
  } catch (error) {
2801
2830
  const id = getExtensionId(extension);
2802
- throw new VError$1(error, `Failed to activate extension ${id}`);
2831
+ throw new VError(error, `Failed to activate extension ${id}`);
2803
2832
  }
2804
2833
  // console.info('activated', path)
2805
2834
  };
@@ -2837,7 +2866,7 @@ const mockExec = () => {
2837
2866
  };
2838
2867
  };
2839
2868
  } catch (error) {
2840
- throw new VError$1(error, 'Failed to mock exec function');
2869
+ throw new VError(error, 'Failed to mock exec function');
2841
2870
  }
2842
2871
  };
2843
2872
 
@@ -2852,7 +2881,7 @@ const mockRpc = () => {
2852
2881
  }
2853
2882
  };
2854
2883
  } catch (error) {
2855
- throw new VError$1(error, 'Failed to mock exec function');
2884
+ throw new VError(error, 'Failed to mock exec function');
2856
2885
  }
2857
2886
  };
2858
2887
  };
@@ -2889,30 +2918,6 @@ const Auto = () => {
2889
2918
  return ModuleWorkerWithMessagePort;
2890
2919
  };
2891
2920
 
2892
- const getData$1 = event => {
2893
- return event.data;
2894
- };
2895
- const attachEvents = that => {
2896
- const handleMessage = (...args) => {
2897
- const data = that.getData(...args);
2898
- that.dispatchEvent(new MessageEvent('message', {
2899
- data
2900
- }));
2901
- };
2902
- that.onMessage(handleMessage);
2903
- const handleClose = event => {
2904
- that.dispatchEvent(new Event('close'));
2905
- };
2906
- that.onClose(handleClose);
2907
- };
2908
- class Ipc extends EventTarget {
2909
- constructor(rawIpc) {
2910
- super();
2911
- this._rawIpc = rawIpc;
2912
- attachEvents(this);
2913
- }
2914
- }
2915
- const readyMessage = 'ready';
2916
2921
  const walkValue = (value, transferrables, isTransferrable) => {
2917
2922
  if (!value) {
2918
2923
  return;
@@ -2963,99 +2968,35 @@ const getTransferrables = value => {
2963
2968
  walkValue(value, transferrables, isTransferrable);
2964
2969
  return transferrables;
2965
2970
  };
2966
- const listen$3 = ({
2967
- port
2968
- }) => {
2969
- return port;
2970
- };
2971
- const signal$3 = port => {
2972
- port.postMessage(readyMessage);
2973
- };
2974
- class IpcChildWithMessagePort extends Ipc {
2975
- constructor(port) {
2976
- super(port);
2977
- }
2978
- getData(event) {
2979
- return getData$1(event);
2980
- }
2981
- send(message) {
2982
- this._rawIpc.postMessage(message);
2983
- }
2984
- sendAndTransfer(message) {
2985
- const transfer = getTransferrables(message);
2986
- this._rawIpc.postMessage(message, transfer);
2987
- }
2988
- dispose() {
2989
- // ignore
2990
- }
2991
- onClose(callback) {
2992
- // ignore
2993
- }
2994
- onMessage(callback) {
2995
- this._rawIpc.addEventListener('message', callback);
2996
- this._rawIpc.start();
2997
- }
2998
- }
2999
- const wrap$6 = port => {
3000
- return new IpcChildWithMessagePort(port);
3001
- };
3002
- const IpcChildWithMessagePort$1 = {
3003
- __proto__: null,
3004
- listen: listen$3,
3005
- signal: signal$3,
3006
- wrap: wrap$6
3007
- };
3008
- const listen$2 = () => {
3009
- // @ts-ignore
3010
- if (typeof WorkerGlobalScope === 'undefined') {
3011
- throw new TypeError('module is not in web worker scope');
3012
- }
3013
- return globalThis;
3014
- };
3015
- const signal$2 = global => {
3016
- global.postMessage(readyMessage);
2971
+ const attachEvents = that => {
2972
+ const handleMessage = (...args) => {
2973
+ const data = that.getData(...args);
2974
+ that.dispatchEvent(new MessageEvent('message', {
2975
+ data
2976
+ }));
2977
+ };
2978
+ that.onMessage(handleMessage);
2979
+ const handleClose = event => {
2980
+ that.dispatchEvent(new Event('close'));
2981
+ };
2982
+ that.onClose(handleClose);
3017
2983
  };
3018
- class IpcChildWithModuleWorker extends Ipc {
3019
- getData(event) {
3020
- return getData$1(event);
3021
- }
3022
- send(message) {
3023
- // @ts-ignore
3024
- this._rawIpc.postMessage(message);
3025
- }
3026
- sendAndTransfer(message) {
3027
- const transfer = getTransferrables(message);
3028
- // @ts-ignore
3029
- this._rawIpc.postMessage(message, transfer);
3030
- }
3031
- dispose() {
3032
- // ignore
3033
- }
3034
- onClose(callback) {
3035
- // ignore
3036
- }
3037
- onMessage(callback) {
3038
- this._rawIpc.addEventListener('message', callback);
2984
+ class Ipc extends EventTarget {
2985
+ constructor(rawIpc) {
2986
+ super();
2987
+ this._rawIpc = rawIpc;
2988
+ attachEvents(this);
3039
2989
  }
3040
2990
  }
3041
- const wrap$5 = global => {
3042
- return new IpcChildWithModuleWorker(global);
3043
- };
3044
- const IpcChildWithModuleWorker$1 = {
3045
- __proto__: null,
3046
- listen: listen$2,
3047
- signal: signal$2,
3048
- wrap: wrap$5
3049
- };
3050
2991
  const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
3051
2992
  const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
3052
2993
  const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
3053
- const NewLine$1 = '\n';
2994
+ const NewLine = '\n';
3054
2995
  const joinLines = lines => {
3055
- return lines.join(NewLine$1);
2996
+ return lines.join(NewLine);
3056
2997
  };
3057
2998
  const splitLines$1 = lines => {
3058
- return lines.split(NewLine$1);
2999
+ return lines.split(NewLine);
3059
3000
  };
3060
3001
  const isModuleNotFoundMessage = line => {
3061
3002
  return line.includes('[ERR_MODULE_NOT_FOUND]');
@@ -3160,61 +3101,6 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
3160
3101
  stack: rest
3161
3102
  };
3162
3103
  };
3163
- const normalizeLine = line => {
3164
- if (line.startsWith('Error: ')) {
3165
- return line.slice('Error: '.length);
3166
- }
3167
- if (line.startsWith('VError: ')) {
3168
- return line.slice('VError: '.length);
3169
- }
3170
- return line;
3171
- };
3172
- const getCombinedMessage = (error, message) => {
3173
- const stringifiedError = normalizeLine(`${error}`);
3174
- if (message) {
3175
- return `${message}: ${stringifiedError}`;
3176
- }
3177
- return stringifiedError;
3178
- };
3179
- const NewLine = '\n';
3180
- const getNewLineIndex = (string, startIndex = undefined) => {
3181
- return string.indexOf(NewLine, startIndex);
3182
- };
3183
- const mergeStacks = (parent, child) => {
3184
- if (!child) {
3185
- return parent;
3186
- }
3187
- const parentNewLineIndex = getNewLineIndex(parent);
3188
- const childNewLineIndex = getNewLineIndex(child);
3189
- if (childNewLineIndex === -1) {
3190
- return parent;
3191
- }
3192
- const parentFirstLine = parent.slice(0, parentNewLineIndex);
3193
- const childRest = child.slice(childNewLineIndex);
3194
- const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
3195
- if (parentFirstLine.includes(childFirstLine)) {
3196
- return parentFirstLine + childRest;
3197
- }
3198
- return child;
3199
- };
3200
- class VError extends Error {
3201
- constructor(error, message) {
3202
- const combinedMessage = getCombinedMessage(error, message);
3203
- super(combinedMessage);
3204
- this.name = 'VError';
3205
- if (error instanceof Error) {
3206
- this.stack = mergeStacks(this.stack, error.stack);
3207
- }
3208
- if (error.codeFrame) {
3209
- // @ts-ignore
3210
- this.codeFrame = error.codeFrame;
3211
- }
3212
- if (error.code) {
3213
- // @ts-ignore
3214
- this.code = error.code;
3215
- }
3216
- }
3217
- }
3218
3104
  let IpcError$1 = class IpcError extends VError {
3219
3105
  // @ts-ignore
3220
3106
  constructor(betterMessage, stdout = '', stderr = '') {
@@ -3241,6 +3127,94 @@ let IpcError$1 = class IpcError extends VError {
3241
3127
  this.stderr = stderr;
3242
3128
  }
3243
3129
  };
3130
+ const readyMessage = 'ready';
3131
+ const getData$2 = event => {
3132
+ return event.data;
3133
+ };
3134
+ const listen$8 = ({
3135
+ port
3136
+ }) => {
3137
+ return port;
3138
+ };
3139
+ const signal$8 = port => {
3140
+ port.postMessage(readyMessage);
3141
+ };
3142
+ class IpcChildWithMessagePort extends Ipc {
3143
+ constructor(port) {
3144
+ super(port);
3145
+ }
3146
+ getData(event) {
3147
+ return getData$2(event);
3148
+ }
3149
+ send(message) {
3150
+ this._rawIpc.postMessage(message);
3151
+ }
3152
+ sendAndTransfer(message) {
3153
+ const transfer = getTransferrables(message);
3154
+ this._rawIpc.postMessage(message, transfer);
3155
+ }
3156
+ dispose() {
3157
+ // ignore
3158
+ }
3159
+ onClose(callback) {
3160
+ // ignore
3161
+ }
3162
+ onMessage(callback) {
3163
+ this._rawIpc.addEventListener('message', callback);
3164
+ this._rawIpc.start();
3165
+ }
3166
+ }
3167
+ const wrap$f = port => {
3168
+ return new IpcChildWithMessagePort(port);
3169
+ };
3170
+ const IpcChildWithMessagePort$1 = {
3171
+ __proto__: null,
3172
+ listen: listen$8,
3173
+ signal: signal$8,
3174
+ wrap: wrap$f
3175
+ };
3176
+ const listen$7 = () => {
3177
+ // @ts-ignore
3178
+ if (typeof WorkerGlobalScope === 'undefined') {
3179
+ throw new TypeError('module is not in web worker scope');
3180
+ }
3181
+ return globalThis;
3182
+ };
3183
+ const signal$7 = global => {
3184
+ global.postMessage(readyMessage);
3185
+ };
3186
+ class IpcChildWithModuleWorker extends Ipc {
3187
+ getData(event) {
3188
+ return getData$2(event);
3189
+ }
3190
+ send(message) {
3191
+ // @ts-ignore
3192
+ this._rawIpc.postMessage(message);
3193
+ }
3194
+ sendAndTransfer(message) {
3195
+ const transfer = getTransferrables(message);
3196
+ // @ts-ignore
3197
+ this._rawIpc.postMessage(message, transfer);
3198
+ }
3199
+ dispose() {
3200
+ // ignore
3201
+ }
3202
+ onClose(callback) {
3203
+ // ignore
3204
+ }
3205
+ onMessage(callback) {
3206
+ this._rawIpc.addEventListener('message', callback);
3207
+ }
3208
+ }
3209
+ const wrap$e = global => {
3210
+ return new IpcChildWithModuleWorker(global);
3211
+ };
3212
+ const IpcChildWithModuleWorker$1 = {
3213
+ __proto__: null,
3214
+ listen: listen$7,
3215
+ signal: signal$7,
3216
+ wrap: wrap$e
3217
+ };
3244
3218
  const withResolvers$1 = () => {
3245
3219
  let _resolve;
3246
3220
  const promise = new Promise(resolve => {
@@ -3263,10 +3237,10 @@ const waitForFirstMessage = async port => {
3263
3237
  // @ts-ignore
3264
3238
  return event.data;
3265
3239
  };
3266
- const listen$1 = async () => {
3267
- const parentIpcRaw = listen$2();
3268
- signal$2(parentIpcRaw);
3269
- const parentIpc = wrap$5(parentIpcRaw);
3240
+ const listen$6 = async () => {
3241
+ const parentIpcRaw = listen$7();
3242
+ signal$7(parentIpcRaw);
3243
+ const parentIpc = wrap$e(parentIpcRaw);
3270
3244
  const firstMessage = await waitForFirstMessage(parentIpc);
3271
3245
  if (firstMessage.method !== 'initialize') {
3272
3246
  throw new IpcError$1('unexpected first message');
@@ -3289,7 +3263,7 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
3289
3263
  super(port);
3290
3264
  }
3291
3265
  getData(event) {
3292
- return getData$1(event);
3266
+ return getData$2(event);
3293
3267
  }
3294
3268
  send(message) {
3295
3269
  this._rawIpc.postMessage(message);
@@ -3311,13 +3285,13 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
3311
3285
  this._rawIpc.start();
3312
3286
  }
3313
3287
  }
3314
- const wrap$4$1 = port => {
3288
+ const wrap$d = port => {
3315
3289
  return new IpcChildWithModuleWorkerAndMessagePort(port);
3316
3290
  };
3317
3291
  const IpcChildWithModuleWorkerAndMessagePort$1 = {
3318
3292
  __proto__: null,
3319
- listen: listen$1,
3320
- wrap: wrap$4$1
3293
+ listen: listen$6,
3294
+ wrap: wrap$d
3321
3295
  };
3322
3296
 
3323
3297
  const getModule$1 = method => {
@@ -3371,7 +3345,7 @@ function promisifyRequest(request) {
3371
3345
  request.addEventListener('success', success);
3372
3346
  request.addEventListener('error', error);
3373
3347
  });
3374
- // This mapping exists in reverseTransformCache but doesn't doesn't exist in transformCache. This
3348
+ // This mapping exists in reverseTransformCache but doesn't exist in transformCache. This
3375
3349
  // is because we create many promises from a single IDBRequest.
3376
3350
  reverseTransformCache.set(promise, request);
3377
3351
  return promise;
@@ -3639,7 +3613,7 @@ const saveValue = async (storeId, value) => {
3639
3613
  // TODO
3640
3614
  return;
3641
3615
  }
3642
- throw new VError$1(error, 'Failed to save value to indexed db');
3616
+ throw new VError(error, 'Failed to save value to indexed db');
3643
3617
  }
3644
3618
  };
3645
3619
  const getValues = async storeId => {
@@ -3652,7 +3626,7 @@ const getValues = async storeId => {
3652
3626
  });
3653
3627
  return objects;
3654
3628
  } catch (error) {
3655
- throw new VError$1(error, 'Failed to get values from indexed db');
3629
+ throw new VError(error, 'Failed to get values from indexed db');
3656
3630
  }
3657
3631
  };
3658
3632
  const getValuesByIndexName = async (storeId, indexName, only) => {
@@ -3716,7 +3690,7 @@ const set = async (key, value) => {
3716
3690
  const db = await getDbMemoized();
3717
3691
  await db.put(storeId, value, key);
3718
3692
  } catch (error) {
3719
- throw new VError$1(error, 'Failed to save value to indexed db');
3693
+ throw new VError(error, 'Failed to save value to indexed db');
3720
3694
  }
3721
3695
  };
3722
3696
  const get = async key => {
@@ -3725,7 +3699,7 @@ const get = async key => {
3725
3699
  const value = db.get(storeId, key);
3726
3700
  return value;
3727
3701
  } catch (error) {
3728
- throw new VError$1(error, 'Failed to get value from indexed db');
3702
+ throw new VError(error, 'Failed to get value from indexed db');
3729
3703
  }
3730
3704
  };
3731
3705
 
@@ -3769,7 +3743,7 @@ const getJson = async url => {
3769
3743
  const json = await response.json();
3770
3744
  return json;
3771
3745
  } catch (error) {
3772
- throw new VError$1(error, `Failed to get json`);
3746
+ throw new VError(error, `Failed to get json`);
3773
3747
  }
3774
3748
  };
3775
3749
 
@@ -3845,7 +3819,7 @@ const getHandle = async uri => {
3845
3819
  const handle = await getHandle$1(uri);
3846
3820
  return handle;
3847
3821
  } catch (error) {
3848
- throw new VError$1(error, 'Failed to get handle');
3822
+ throw new VError(error, 'Failed to get handle');
3849
3823
  }
3850
3824
  };
3851
3825
 
@@ -3885,7 +3859,7 @@ const searchFile = async uri => {
3885
3859
  const handle = await getDirectoryHandle$1(path);
3886
3860
  if (!handle) {
3887
3861
  // @ts-ignore
3888
- throw new VError$1(`Folder not found ${uri}`);
3862
+ throw new VError(`Folder not found ${uri}`);
3889
3863
  }
3890
3864
  const all = [];
3891
3865
  await searchFilesRecursively(all, '', handle);
@@ -3901,7 +3875,7 @@ const getText = async url => {
3901
3875
  const text = await response.text();
3902
3876
  return text;
3903
3877
  } catch (error) {
3904
- throw new VError$1(error, `Failed to get text`);
3878
+ throw new VError(error, `Failed to get text`);
3905
3879
  }
3906
3880
  };
3907
3881
 
@@ -3966,7 +3940,7 @@ const getChildHandles = async handle => {
3966
3940
  try {
3967
3941
  return await getChildHandles$1(handle);
3968
3942
  } catch (error) {
3969
- throw new VError$1(error, 'failed to get child handles');
3943
+ throw new VError(error, 'failed to get child handles');
3970
3944
  }
3971
3945
  };
3972
3946
 
@@ -4066,6 +4040,7 @@ const commandMap = {
4066
4040
  ['ExtensionHostWebView.create']: createWebView,
4067
4041
  ['ExtensionHostWebView.dispose']: disposeWebView,
4068
4042
  ['ExtensionHostWebView.load']: load,
4043
+ ['ExtensionHostWebView.getWebViewInfo']: getWebViewInfo,
4069
4044
  ['HandleBeforeUnload.handleBeforeUnload']: handleBeforeUnload,
4070
4045
  ['HandleMessagePort.handleMessagePort']: handleMessagePort,
4071
4046
  ['SaveState.saveState']: saveState,
@@ -4184,7 +4159,7 @@ const main = async () => {
4184
4159
  const ipc = await listen({
4185
4160
  method: Auto()
4186
4161
  });
4187
- listen$4(ipc);
4162
+ listen$1(ipc);
4188
4163
  };
4189
4164
 
4190
4165
  main();
@@ -4315,7 +4290,7 @@ const wrap$3 = webSocket => {
4315
4290
  send(message) {
4316
4291
  if (this.webSocket.readyState !== webSocket.OPEN) {
4317
4292
  // @ts-ignore
4318
- throw new VError$1(`Failed to send message: WebSocket is not open`);
4293
+ throw new VError(`Failed to send message: WebSocket is not open`);
4319
4294
  }
4320
4295
  const stringifiedMessage = stringifyCompact(message);
4321
4296
  this.webSocket.send(stringifiedMessage);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-host-worker",
3
- "version": "1.16.0",
3
+ "version": "2.1.0",
4
4
  "description": "Webworker for the extension host functionality in Lvce Editor.",
5
5
  "main": "dist/extensionHostWorkerMain.js",
6
6
  "type": "module",