@lvce-editor/extension-management-worker 4.31.2 → 4.31.4

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.
@@ -581,12 +581,12 @@ const IpcParentWithWebSocket$1 = {
581
581
  wrap
582
582
  };
583
583
 
584
- class CommandNotFoundError extends Error {
584
+ let CommandNotFoundError$1 = class CommandNotFoundError extends Error {
585
585
  constructor(command) {
586
586
  super(`Command not found ${command}`);
587
587
  this.name = 'CommandNotFoundError';
588
588
  }
589
- }
589
+ };
590
590
  const commands = Object.create(null);
591
591
  const register = commandMap => {
592
592
  Object.assign(commands, commandMap);
@@ -597,7 +597,7 @@ const getCommand = key => {
597
597
  const execute = (command, ...args) => {
598
598
  const fn = getCommand(command);
599
599
  if (!fn) {
600
- throw new CommandNotFoundError(command);
600
+ throw new CommandNotFoundError$1(command);
601
601
  }
602
602
  return fn(...args);
603
603
  };
@@ -1642,6 +1642,14 @@ const getNodeRpcInfo = async (extensionId, rpcId) => {
1642
1642
  };
1643
1643
  };
1644
1644
 
1645
+ class CommandNotFoundError extends Error {
1646
+ constructor(command) {
1647
+ super(`Command not found ${command}`);
1648
+ Object.defineProperty(this, 'name', {
1649
+ value: 'CommandNotFoundError'
1650
+ });
1651
+ }
1652
+ }
1645
1653
  const createExtensionCommandMap = extensionId => {
1646
1654
  return {
1647
1655
  ...commandMapRef,
@@ -1650,6 +1658,15 @@ const createExtensionCommandMap = extensionId => {
1650
1658
  }
1651
1659
  };
1652
1660
  };
1661
+ const createExtensionCommandExecutor = commandMap => {
1662
+ return (method, ...params) => {
1663
+ const command = commandMap[method];
1664
+ if (!command) {
1665
+ throw new CommandNotFoundError(method);
1666
+ }
1667
+ return command(...params);
1668
+ };
1669
+ };
1653
1670
 
1654
1671
  const rpcs$1 = Object.create(null);
1655
1672
  const get$3 = extensionId => {
@@ -1670,15 +1687,25 @@ const invokeAndTransfer = (method, ...params) => {
1670
1687
  return invokeAndTransfer$1(method, ...params);
1671
1688
  };
1672
1689
 
1690
+ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
1691
+
1673
1692
  const pendingRpcs = Object.create(null);
1693
+ const bindCommandMap = (rpc, commandMap) => {
1694
+ if (rpc.ipc) {
1695
+ rpc.ipc.execute = createExtensionCommandExecutor(commandMap);
1696
+ }
1697
+ return rpc;
1698
+ };
1674
1699
  const createIsolatedExtensionHostWorker = async (extensionId, absolutePath, workerName, createRpc, invokeAndTransfer) => {
1675
- return createRpc({
1676
- commandMap: createExtensionCommandMap(extensionId),
1700
+ const commandMap = createExtensionCommandMap(extensionId);
1701
+ const rpc = await createRpc({
1702
+ commandMap,
1677
1703
  isMessagePortOpen: true,
1678
1704
  send(port) {
1679
1705
  return invokeAndTransfer('LaunchIsolatedExtensionHostWorker.launchIsolatedExtensionHostWorker', port, extensionId, absolutePath, workerName);
1680
1706
  }
1681
1707
  });
1708
+ return bindCommandMap(rpc, commandMap);
1682
1709
  };
1683
1710
  const createWorker = (extensionId, absolutePath, workerName) => {
1684
1711
  return createIsolatedExtensionHostWorker(extensionId, absolutePath, workerName, create$7, invokeAndTransfer);
@@ -1868,6 +1895,88 @@ const getExtensionAbsolutePath = (id, isWeb, isBuiltin, path, relativePath, orig
1868
1895
  return new URL('/remote' + path + '/' + relativePath, origin).href;
1869
1896
  };
1870
1897
 
1898
+ const ContentType = 'Content-Type';
1899
+ const ContentLength = 'Content-Length';
1900
+
1901
+ const createResponseFromData = data => {
1902
+ const responseString = JSON.stringify(data);
1903
+ const response = new Response(responseString, {
1904
+ headers: {
1905
+ [ContentLength]: String(responseString.length),
1906
+ [ContentType]: 'application/json'
1907
+ }
1908
+ });
1909
+ return response;
1910
+ };
1911
+
1912
+ const cacheName = 'Extensions'; // TODO
1913
+
1914
+ const getJson$1 = async cacheKey => {
1915
+ const response = await caches.match(cacheKey, {
1916
+ cacheName
1917
+ });
1918
+ if (!response) {
1919
+ return undefined;
1920
+ }
1921
+ const json = await response.json();
1922
+ return json;
1923
+ };
1924
+ const setJson = async (cacheKey, data) => {
1925
+ try {
1926
+ const cache = await caches.open(cacheName);
1927
+ const response = createResponseFromData(data);
1928
+ await cache.put(cacheKey, response);
1929
+ } catch (error) {
1930
+ throw new VError(error, `Failed to add to cache`);
1931
+ }
1932
+ };
1933
+
1934
+ const disabledExtensionsCacheKey = '/cache/disabledExtensions.json';
1935
+
1936
+ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
1937
+
1938
+ const getDisabledExtensionIdsFromData = data => {
1939
+ const disabledExtensions = data?.disabledExtensions;
1940
+ if (!Array.isArray(disabledExtensions)) {
1941
+ return [];
1942
+ }
1943
+ return disabledExtensions.filter(id => typeof id === 'string');
1944
+ };
1945
+ const getWebDisabledExtensionIds = async () => {
1946
+ try {
1947
+ const cached = await getJson$1(disabledExtensionsCacheKey);
1948
+ return getDisabledExtensionIdsFromData(cached);
1949
+ } catch {
1950
+ return [];
1951
+ }
1952
+ };
1953
+ const getRemoteDisabledExtensionIds = async () => {
1954
+ try {
1955
+ const uri = await invoke$2('WebView.compatSharedProcessInvoke', 'PlatformPaths.getDisabledExtensionsJsonUri');
1956
+ const exists$1 = await exists(uri);
1957
+ if (!exists$1) {
1958
+ return [];
1959
+ }
1960
+ const content = await readFile$1(uri);
1961
+ const parsed = JSON.parse(content);
1962
+ return getDisabledExtensionIdsFromData(parsed);
1963
+ } catch {
1964
+ return [];
1965
+ }
1966
+ };
1967
+ const getDisabledExtensionIds = async (extensionsState, platform) => {
1968
+ if (platform === Test) {
1969
+ return extensionsState.disabledIds;
1970
+ }
1971
+ if (platform === Web) {
1972
+ return getWebDisabledExtensionIds();
1973
+ }
1974
+ if (platform === Remote || platform === Electron) {
1975
+ return getRemoteDisabledExtensionIds();
1976
+ }
1977
+ return [];
1978
+ };
1979
+
1871
1980
  const isMissingAssetDir = assetDir => {
1872
1981
  return typeof assetDir !== 'string' || assetDir.length === 0;
1873
1982
  };
@@ -1899,7 +2008,7 @@ const getRuntimeContext = async (assetDir, platform) => {
1899
2008
  const getResponseErrorMessage = response => {
1900
2009
  return response.statusText || String(response.status) || 'Request failed';
1901
2010
  };
1902
- const getJson$1 = async url => {
2011
+ const getJson = async url => {
1903
2012
  try {
1904
2013
  const response = await fetch(url);
1905
2014
  if (!response.ok) {
@@ -1918,7 +2027,7 @@ const getWebExtensionsUrl = assetDir => {
1918
2027
 
1919
2028
  const getWebExtensions = async assetDir => {
1920
2029
  try {
1921
- return await getJson$1(getWebExtensionsUrl(assetDir));
2030
+ return await getJson(getWebExtensionsUrl(assetDir));
1922
2031
  } catch {
1923
2032
  return [];
1924
2033
  }
@@ -2030,7 +2139,7 @@ const enableExtension$1 = async id => {
2030
2139
 
2031
2140
  /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
2032
2141
 
2033
- const withWorkspaceDisabledState = (extensions, disabledIds) => {
2142
+ const withDisabledState = (extensions, disabledIds) => {
2034
2143
  if (disabledIds.length === 0) {
2035
2144
  return extensions;
2036
2145
  }
@@ -2045,12 +2154,17 @@ const withWorkspaceDisabledState = (extensions, disabledIds) => {
2045
2154
  };
2046
2155
  });
2047
2156
  };
2048
- const getExtensionsWithWorkspaceState = async (extensions, platform) => {
2049
- if (extensions.length === 0 || platform === Test) {
2157
+ const getExtensionsWithState = async (extensions, extensionsState, platform) => {
2158
+ if (extensions.length === 0) {
2050
2159
  return extensions;
2051
2160
  }
2161
+ const disabledIds = await getDisabledExtensionIds(extensionsState, platform);
2162
+ const extensionsWithDisabledState = withDisabledState(extensions, disabledIds);
2163
+ if (platform === Test) {
2164
+ return extensionsWithDisabledState;
2165
+ }
2052
2166
  const workspaceDisabledIds = await readDisabledExtensionIdsSafe();
2053
- return withWorkspaceDisabledState(extensions, workspaceDisabledIds);
2167
+ return withDisabledState(extensionsWithDisabledState, workspaceDisabledIds);
2054
2168
  };
2055
2169
  const getAllExtensionsWithState = async (extensionsState, assetDir, platform) => {
2056
2170
  const {
@@ -2063,10 +2177,10 @@ const getAllExtensionsWithState = async (extensionsState, assetDir, platform) =>
2063
2177
  if (resolvedPlatform === Web) {
2064
2178
  const webExtensions = await getWebExtensions(resolvedAssetDir);
2065
2179
  const compatibleExtensions = [...webExtensions, ...meta].filter(extension => isExtensionCompatible(extension, resolvedPlatform));
2066
- return getExtensionsWithWorkspaceState(compatibleExtensions, resolvedPlatform);
2180
+ return getExtensionsWithState(compatibleExtensions, extensionsState, resolvedPlatform);
2067
2181
  }
2068
2182
  const local = await invoke$1('ExtensionManagement.getAllExtensions');
2069
- return getExtensionsWithWorkspaceState([...local, ...meta], resolvedPlatform);
2183
+ return getExtensionsWithState([...local, ...meta], extensionsState, resolvedPlatform);
2070
2184
  };
2071
2185
 
2072
2186
  const getAllExtensions = async (assetDir, platform) => {
@@ -2135,7 +2249,11 @@ const activateByEvent = async (event, assetDir, platform) => {
2135
2249
  };
2136
2250
 
2137
2251
  const invalidateExtensionsCache = async () => {
2138
- await invoke$2('ExtensionManagement.handleExtensionsCacheInvalidated');
2252
+ try {
2253
+ await invoke$2('ExtensionManagement.handleExtensionsCacheInvalidated');
2254
+ } catch {
2255
+ // Older renderer workers do not expose the cache invalidation notification.
2256
+ }
2139
2257
  };
2140
2258
 
2141
2259
  const handleChange = async _id => {
@@ -2161,7 +2279,7 @@ const addExtension = async extension => {
2161
2279
 
2162
2280
  const getWebExtensionManifest = async (path, manifestPath) => {
2163
2281
  try {
2164
- const manifest = await getJson$1(manifestPath);
2282
+ const manifest = await getJson(manifestPath);
2165
2283
  return {
2166
2284
  ...manifest,
2167
2285
  path,
@@ -2239,44 +2357,6 @@ const createWebViewWorkerRpc = async (rpcInfo, port) => {
2239
2357
  });
2240
2358
  };
2241
2359
 
2242
- const ContentType = 'Content-Type';
2243
- const ContentLength = 'Content-Length';
2244
-
2245
- const createResponseFromData = data => {
2246
- const responseString = JSON.stringify(data);
2247
- const response = new Response(responseString, {
2248
- headers: {
2249
- [ContentLength]: String(responseString.length),
2250
- [ContentType]: 'application/json'
2251
- }
2252
- });
2253
- return response;
2254
- };
2255
-
2256
- const cacheName = 'Extensions'; // TODO
2257
-
2258
- const getJson = async cacheKey => {
2259
- const response = await caches.match(cacheKey, {
2260
- cacheName
2261
- });
2262
- if (!response) {
2263
- return undefined;
2264
- }
2265
- const json = await response.json();
2266
- return json;
2267
- };
2268
- const setJson = async (cacheKey, data) => {
2269
- try {
2270
- const cache = await caches.open(cacheName);
2271
- const response = createResponseFromData(data);
2272
- await cache.put(cacheKey, response);
2273
- } catch (error) {
2274
- throw new VError(error, `Failed to add to cache`);
2275
- }
2276
- };
2277
-
2278
- const disabledExtensionsCacheKey = '/cache/disabledExtensions.json';
2279
-
2280
2360
  const disableExtension2$1 = async (id, platform) => {
2281
2361
  const isTest = platform === Test;
2282
2362
  const isWeb = platform === Web;
@@ -2288,7 +2368,7 @@ const disableExtension2$1 = async (id, platform) => {
2288
2368
  };
2289
2369
  set$4(newState);
2290
2370
  } else if (isWeb) {
2291
- const cached = await getJson(disabledExtensionsCacheKey);
2371
+ const cached = await getJson$1(disabledExtensionsCacheKey);
2292
2372
  const oldDisabled = cached?.disabledExtensions || [];
2293
2373
  const newDisabled = [...oldDisabled, id];
2294
2374
  const newData = {
@@ -2310,7 +2390,7 @@ const enableExtension2$1 = async (id, platform) => {
2310
2390
  };
2311
2391
  set$4(newState);
2312
2392
  } else if (isWeb) {
2313
- const cached = await getJson(disabledExtensionsCacheKey);
2393
+ const cached = await getJson$1(disabledExtensionsCacheKey);
2314
2394
  const oldDisabled = cached?.disabledExtensions || [];
2315
2395
  const newDisabled = oldDisabled.filter(item => item !== id);
2316
2396
  const newData = {
@@ -2532,6 +2612,7 @@ const getRpc$1 = async (extension, assetDir, platform) => {
2532
2612
  if (existingRpc) {
2533
2613
  return existingRpc;
2534
2614
  }
2615
+ handleRpcInfos(extension, platform);
2535
2616
  const absolutePath = getAbsolutePath(extension, assetDir, platform);
2536
2617
  return getOrCreateIsolatedExtensionHostWorker(extensionId, absolutePath, extension.workerName || '');
2537
2618
  };
@@ -3137,7 +3218,7 @@ const getColorThemeUrlWeb = (assetDir, colorThemeId) => {
3137
3218
  const getColorThemeJson$1 = (colorThemeId, assetDir) => {
3138
3219
  const url = getColorThemeUrlWeb(assetDir, colorThemeId);
3139
3220
  // TODO handle error ?
3140
- return getJson$1(url);
3221
+ return getJson(url);
3141
3222
  };
3142
3223
 
3143
3224
  const getColorThemeJson = (colorThemeId, platform, assetDir) => {
@@ -3162,6 +3243,9 @@ const getColorThemeCss = (colorThemeId, platform) => {
3162
3243
  };
3163
3244
 
3164
3245
  const getExtensionColorThemeNames = extension => {
3246
+ if (extension.disabled) {
3247
+ return [];
3248
+ }
3165
3249
  return extension.colorThemes || [];
3166
3250
  };
3167
3251
  const getColorThemeId = colorTheme => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-management-worker",
3
- "version": "4.31.2",
3
+ "version": "4.31.4",
4
4
  "description": "Webworker for the Extension Management functionality in Lvce Editor.",
5
5
  "keywords": [
6
6
  "web-worker"