@lvce-editor/extension-management-worker 4.9.0 → 4.11.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.
@@ -1578,21 +1578,21 @@ const invokeAndTransfer = (method, ...params) => {
1578
1578
  return invokeAndTransfer$1(method, ...params);
1579
1579
  };
1580
1580
 
1581
- const createIsolatedExtensionHostWorker = async (extensionId, absolutePath, createRpc, invokeAndTransfer) => {
1581
+ const createIsolatedExtensionHostWorker = async (extensionId, absolutePath, workerName, createRpc, invokeAndTransfer) => {
1582
1582
  return createRpc({
1583
1583
  commandMap: commandMapRef,
1584
1584
  isMessagePortOpen: true,
1585
1585
  send(port) {
1586
- return invokeAndTransfer('LaunchIsolatedExtensionHostWorker.launchIsolatedExtensionHostWorker', port, extensionId, absolutePath);
1586
+ return invokeAndTransfer('LaunchIsolatedExtensionHostWorker.launchIsolatedExtensionHostWorker', port, extensionId, absolutePath, workerName);
1587
1587
  }
1588
1588
  });
1589
1589
  };
1590
- const getOrCreateIsolatedExtensionHostWorker = async (extensionId, absolutePath) => {
1590
+ const getOrCreateIsolatedExtensionHostWorker = async (extensionId, absolutePath, workerName = '') => {
1591
1591
  const existingRpc = get$3(extensionId);
1592
1592
  if (existingRpc) {
1593
1593
  return existingRpc;
1594
1594
  }
1595
- const rpc = await createIsolatedExtensionHostWorker(extensionId, absolutePath, create$7, invokeAndTransfer);
1595
+ const rpc = await createIsolatedExtensionHostWorker(extensionId, absolutePath, workerName, create$7, invokeAndTransfer);
1596
1596
  set$3(extensionId, rpc);
1597
1597
  return rpc;
1598
1598
  };
@@ -1696,7 +1696,7 @@ const activateExtension3 = async (extension, absolutePath, activationEvent, plat
1696
1696
  handleRpcInfos(extension, platform);
1697
1697
  const extensionId = extension.id || interExtensionId(extension.uri);
1698
1698
  if (isExtensionIsolated(extension)) {
1699
- await getOrCreateIsolatedExtensionHostWorker(extensionId, absolutePath);
1699
+ await getOrCreateIsolatedExtensionHostWorker(extensionId, absolutePath, extension.workerName || '');
1700
1700
  return;
1701
1701
  }
1702
1702
  await importExtension(extensionId, absolutePath, activationEvent);
@@ -1947,6 +1947,10 @@ const getWebManifestPath = path => {
1947
1947
  return manifestPath;
1948
1948
  };
1949
1949
 
1950
+ const invalidateExtensionsCache = async () => {
1951
+ await invoke$3('ExtensionManagement.invalidateExtensionsCache');
1952
+ };
1953
+
1950
1954
  const state = {
1951
1955
  rpc: undefined
1952
1956
  };
@@ -1975,6 +1979,7 @@ const addWebExtension = async path => {
1975
1979
  const manifest = await getWebExtensionManifest(path, manifestPath);
1976
1980
  addWebExtension$1(manifest);
1977
1981
  clearCachedExtensions();
1982
+ await invalidateExtensionsCache();
1978
1983
  if (hasStatusBarItems(manifest)) {
1979
1984
  await handleChange(manifest.id || path);
1980
1985
  }
@@ -2112,10 +2117,6 @@ const enableExtension2$1 = async (id, platform) => {
2112
2117
  }
2113
2118
  };
2114
2119
 
2115
- const invalidateExtensionsCache = async () => {
2116
- await invoke$3('ExtensionManagement.invalidateExtensionsCache');
2117
- };
2118
-
2119
2120
  const disableExtension2 = async (id, platform) => {
2120
2121
  string(id);
2121
2122
  number(platform);
@@ -2159,6 +2160,7 @@ const enableExtension2 = async (id, platform) => {
2159
2160
  await writeFile(disabledExtensionsJsonPath, newContent);
2160
2161
  }
2161
2162
  await enableExtension2$1(id, platform);
2163
+ await invalidateExtensionsCache();
2162
2164
  };
2163
2165
 
2164
2166
  const enableExtension = async (id, isTest) => {
@@ -2245,7 +2247,7 @@ const getRpc$1 = async (extension, assetDir, platform) => {
2245
2247
  return existingRpc;
2246
2248
  }
2247
2249
  const absolutePath = getAbsolutePath(extension, assetDir, platform);
2248
- return getOrCreateIsolatedExtensionHostWorker(extensionId, absolutePath);
2250
+ return getOrCreateIsolatedExtensionHostWorker(extensionId, absolutePath, extension.workerName || '');
2249
2251
  };
2250
2252
 
2251
2253
  /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
@@ -2364,6 +2366,21 @@ const remove = uid => {
2364
2366
  delete instances[uid];
2365
2367
  };
2366
2368
 
2369
+ const serializeError = error => {
2370
+ if (error instanceof Error) {
2371
+ return {
2372
+ message: error.message,
2373
+ name: error.name,
2374
+ ...(error.stack && {
2375
+ stack: error.stack
2376
+ })
2377
+ };
2378
+ }
2379
+ return {
2380
+ message: String(error),
2381
+ name: 'Error'
2382
+ };
2383
+ };
2367
2384
  const hasView = (extension, viewId) => {
2368
2385
  return Array.isArray(extension.views) && extension.views.some(view => view.id === viewId);
2369
2386
  };
@@ -2381,36 +2398,69 @@ const getRpcForView = async (viewId, assetDir, platform) => {
2381
2398
  if (existingRpc) {
2382
2399
  return existingRpc;
2383
2400
  }
2384
- await activateByEvent(`onView:${viewId}`, assetDir, platform);
2401
+ const activationResult = await activateByEvent(`onView:${viewId}`, assetDir, platform);
2402
+ if (activationResult.error) {
2403
+ throw activationResult.error;
2404
+ }
2385
2405
  return getRpc$1(extension, assetDir, platform);
2386
2406
  };
2387
2407
  const getRpcForInstance = async (viewId, uid, assetDir, platform) => {
2388
2408
  const instance = get$1(uid);
2389
2409
  if (instance) {
2410
+ if (instance.status === 'error') {
2411
+ return undefined;
2412
+ }
2390
2413
  return instance.rpc;
2391
2414
  }
2392
2415
  return getRpcForView(viewId, assetDir, platform);
2393
2416
  };
2394
2417
  const createViewInstance = async (viewId, uid, context, assetDir, platform) => {
2395
- const rpc = await getRpcForView(viewId, assetDir, platform);
2396
- const result = await rpc.invoke('ExtensionApi.createViewInstance', viewId, uid, context);
2397
- set$1(uid, {
2398
- rpc,
2399
- viewId
2400
- });
2401
- return result;
2418
+ try {
2419
+ const rpc = await getRpcForView(viewId, assetDir, platform);
2420
+ const result = await rpc.invoke('ExtensionApi.createViewInstance', viewId, uid, context);
2421
+ set$1(uid, {
2422
+ rpc,
2423
+ status: 'ready',
2424
+ viewId
2425
+ });
2426
+ return {
2427
+ ok: true,
2428
+ result
2429
+ };
2430
+ } catch (error) {
2431
+ const serializedError = serializeError(error);
2432
+ set$1(uid, {
2433
+ error: serializedError,
2434
+ status: 'error',
2435
+ viewId
2436
+ });
2437
+ return {
2438
+ error: serializedError,
2439
+ ok: false
2440
+ };
2441
+ }
2402
2442
  };
2403
2443
  const dispatchViewEvent = async (viewId, uid, event, assetDir, platform) => {
2404
2444
  const rpc = await getRpcForInstance(viewId, uid, assetDir, platform);
2445
+ if (!rpc) {
2446
+ return undefined;
2447
+ }
2405
2448
  return rpc.invoke('ExtensionApi.dispatchViewEvent', uid, event);
2406
2449
  };
2407
2450
  const disposeViewInstance = async (viewId, uid, assetDir, platform) => {
2408
2451
  const rpc = await getRpcForInstance(viewId, uid, assetDir, platform);
2452
+ if (!rpc) {
2453
+ remove(uid);
2454
+ return;
2455
+ }
2409
2456
  await rpc.invoke('ExtensionApi.disposeViewInstance', uid);
2410
2457
  remove(uid);
2411
2458
  };
2412
2459
  const saveViewInstanceState = async (viewId, uid, assetDir, platform) => {
2413
2460
  const rpc = await getRpcForInstance(viewId, uid, assetDir, platform);
2461
+ if (!rpc) {
2462
+ return undefined;
2463
+ }
2414
2464
  return rpc.invoke('ExtensionApi.saveViewInstanceState', uid);
2415
2465
  };
2416
2466
 
@@ -2525,9 +2575,7 @@ const get = colorThemeId => {
2525
2575
  const set = (colorThemeId, data) => {
2526
2576
  // noop
2527
2577
  };
2528
-
2529
- const GetColorThemeCssCachedNoop = {
2530
- __proto__: null,
2578
+ const cache = {
2531
2579
  get,
2532
2580
  set
2533
2581
  };
@@ -2539,7 +2587,7 @@ const GetColorThemeCssCachedNoop = {
2539
2587
  const getCacheFn = config => {
2540
2588
  switch (config) {
2541
2589
  default:
2542
- return GetColorThemeCssCachedNoop;
2590
+ return cache;
2543
2591
  }
2544
2592
  };
2545
2593
  const getColorThemeCssCached = async (colorThemeId, platform, getData) => {
@@ -2753,6 +2801,16 @@ const contributesViews = extension => {
2753
2801
  const getManifestView = (extension, id) => {
2754
2802
  return extension.views?.find(view => view.id === id);
2755
2803
  };
2804
+ const getCss = (extension, manifestView, assetDir, platform) => {
2805
+ const css = manifestView?.css;
2806
+ if (typeof css !== 'string' || css.length === 0) {
2807
+ return '';
2808
+ }
2809
+ return getAbsolutePath({
2810
+ ...extension,
2811
+ browser: css
2812
+ }, assetDir, platform);
2813
+ };
2756
2814
  const getIframe = (extension, manifestView, assetDir, platform) => {
2757
2815
  const iframe = manifestView?.iframe;
2758
2816
  if (!iframe || typeof iframe.path !== 'string' || iframe.path.length === 0) {
@@ -2771,7 +2829,11 @@ const getIframe = (extension, manifestView, assetDir, platform) => {
2771
2829
  const toView = (extension, registeredView, assetDir, platform) => {
2772
2830
  const id = registeredView.id || '';
2773
2831
  const manifestView = getManifestView(extension, id);
2832
+ const css = getCss(extension, manifestView, assetDir, platform);
2774
2833
  return {
2834
+ ...(css && {
2835
+ css
2836
+ }),
2775
2837
  extensionId: getExtensionId(extension),
2776
2838
  icon: registeredView.icon || manifestView?.icon || '',
2777
2839
  id,
@@ -2853,6 +2915,7 @@ const initialize = async platform => {
2853
2915
 
2854
2916
  const installExtension = async () => {
2855
2917
  // TODO
2918
+ await invalidateExtensionsCache();
2856
2919
  };
2857
2920
 
2858
2921
  const getRemoteUrl = uri => {
@@ -2926,6 +2989,7 @@ const sendMessagePortToFileSystemWorker = async port => {
2926
2989
 
2927
2990
  const uninstallExtension = async () => {
2928
2991
  // TODO
2992
+ await invalidateExtensionsCache();
2929
2993
  };
2930
2994
 
2931
2995
  /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-management-worker",
3
- "version": "4.9.0",
3
+ "version": "4.11.0",
4
4
  "description": "Webworker for the Extension Management functionality in Lvce Editor.",
5
5
  "keywords": [
6
6
  "web-worker"