@lvce-editor/extension-management-worker 4.78.1 → 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
|
-
|
|
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
|
|
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
|
|
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 {
|