@lvce-editor/extension-management-worker 4.78.0 → 4.78.2

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.
@@ -35,6 +35,13 @@ const state$4 = {
35
35
  nextApplicationGeneration: 0
36
36
  };
37
37
  const applications$2 = new Map();
38
+ const webExtensionsCaches = new WeakMap();
39
+ const transferWebExtensionsCache = (current, next) => {
40
+ const cache = webExtensionsCaches.get(current);
41
+ if (cache) {
42
+ webExtensionsCaches.set(next, cache);
43
+ }
44
+ };
38
45
  const createApplication = (applicationId, platform, webExtensions) => {
39
46
  if (!applicationId || applications$2.has(applicationId)) {
40
47
  throw new Error(`Invalid or duplicate extension application: ${applicationId}`);
@@ -78,9 +85,11 @@ const set$d = newState => {
78
85
  if (newState.applicationGeneration !== currentState.applicationGeneration) {
79
86
  throw new Error(`Stale extension application state: ${newState.applicationId}`);
80
87
  }
88
+ transferWebExtensionsCache(currentState, newState);
81
89
  applications$2.set(newState.applicationId, newState);
82
90
  return;
83
91
  }
92
+ transferWebExtensionsCache(state$4.extensionsState, newState);
84
93
  state$4.extensionsState = newState;
85
94
  };
86
95
  const update = (newState, applicationId) => {
@@ -123,6 +132,15 @@ const clearCachedExtensions = applicationId => {
123
132
  cachedExtensions: undefined
124
133
  }, applicationId);
125
134
  };
135
+ const getOrCreateWebExtensionsCache = extensionsState => {
136
+ const existing = webExtensionsCaches.get(extensionsState);
137
+ if (existing) {
138
+ return existing;
139
+ }
140
+ const cache = new Map();
141
+ webExtensionsCaches.set(extensionsState, cache);
142
+ return cache;
143
+ };
126
144
  const setRuntimeStatus = (status, applicationId) => {
127
145
  update({
128
146
  runtimeStatuses: {
@@ -1769,10 +1787,29 @@ const getWebExtensionsUrl = assetDir => {
1769
1787
  return `${assetDir}/config/extensions.json`;
1770
1788
  };
1771
1789
 
1772
- const getWebExtensions = async assetDir => {
1790
+ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
1791
+
1792
+ const getWebExtensions = async (assetDir, cache) => {
1793
+ const url = getWebExtensionsUrl(assetDir);
1794
+ const cached = cache.get(url);
1795
+ if (cached) {
1796
+ try {
1797
+ return await cached;
1798
+ } catch {
1799
+ if (cache.get(url) === cached) {
1800
+ cache.delete(url);
1801
+ }
1802
+ return [];
1803
+ }
1804
+ }
1805
+ const promise = getJson(url);
1806
+ cache.set(url, promise);
1773
1807
  try {
1774
- return await getJson(getWebExtensionsUrl(assetDir));
1808
+ return await promise;
1775
1809
  } catch {
1810
+ if (cache.get(url) === promise) {
1811
+ cache.delete(url);
1812
+ }
1776
1813
  return [];
1777
1814
  }
1778
1815
  };
@@ -2088,7 +2125,8 @@ const getAllExtensionsWithState = async (extensionsState, assetDir, platform, fi
2088
2125
  const meta = extensionsState.webExtensions;
2089
2126
  let extensions;
2090
2127
  if (resolvedPlatform === Web) {
2091
- const webExtensions = await getWebExtensions(resolvedAssetDir);
2128
+ const cache = getOrCreateWebExtensionsCache(extensionsState);
2129
+ const webExtensions = await getWebExtensions(resolvedAssetDir, cache);
2092
2130
  const compatibleExtensions = [...webExtensions, ...meta].filter(extension => isExtensionCompatible(extension, resolvedPlatform));
2093
2131
  extensions = await getExtensionsWithState(compatibleExtensions, extensionsState, resolvedPlatform);
2094
2132
  } else {
@@ -3948,6 +3986,9 @@ const executeFileSystemProviderReadDirWithFileTypes = (extensionsState, provider
3948
3986
  const executeFileSystemProviderReadFile = (extensionsState, providerId, uri) => {
3949
3987
  return executeFileSystemProviderMethod(extensionsState, 'ExtensionApi.executeFileSystemProviderReadFile', providerId, uri);
3950
3988
  };
3989
+ const executeFileSystemProviderStat = (extensionsState, providerId, uri) => {
3990
+ return executeFileSystemProviderMethod(extensionsState, 'ExtensionApi.executeFileSystemProviderStat', providerId, uri);
3991
+ };
3951
3992
  const executeFileSystemProviderRemove = (extensionsState, providerId, uri) => {
3952
3993
  return executeFileSystemProviderMethod(extensionsState, 'ExtensionApi.executeFileSystemProviderRemove', providerId, uri);
3953
3994
  };
@@ -6184,6 +6225,7 @@ const commandMap = {
6184
6225
  'Extensions.executeFileSystemProviderReadFile': wrapCommand(executeFileSystemProviderReadFile),
6185
6226
  'Extensions.executeFileSystemProviderRemove': wrapCommand(executeFileSystemProviderRemove),
6186
6227
  'Extensions.executeFileSystemProviderRename': wrapCommand(executeFileSystemProviderRename),
6228
+ 'Extensions.executeFileSystemProviderStat': wrapCommand(executeFileSystemProviderStat),
6187
6229
  'Extensions.executeFileSystemProviderWriteFile': wrapCommand(executeFileSystemProviderWriteFile),
6188
6230
  'Extensions.executeFormattingProvider': wrapCommand(executeFormattingProvider),
6189
6231
  'Extensions.executeHoverProvider': wrapCommand(executeHoverProvider),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-management-worker",
3
- "version": "4.78.0",
3
+ "version": "4.78.2",
4
4
  "description": "Webworker for the Extension Management functionality in Lvce Editor.",
5
5
  "keywords": [
6
6
  "web-worker"