@lvce-editor/extension-management-worker 4.78.1 → 4.78.3
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 {
|
|
@@ -2237,6 +2275,11 @@ const getExtensionAbsolutePath = (id, isWeb, isBuiltin, path, relativePath, orig
|
|
|
2237
2275
|
}
|
|
2238
2276
|
return new URL(relativePath, path + '/').href;
|
|
2239
2277
|
}
|
|
2278
|
+
if (path.startsWith('file://')) {
|
|
2279
|
+
const baseUrl = path.endsWith('/') ? path : `${path}/`;
|
|
2280
|
+
const absolutePath = new URL(relativePath, baseUrl).pathname;
|
|
2281
|
+
return new URL('/remote' + absolutePath, origin).href;
|
|
2282
|
+
}
|
|
2240
2283
|
if (!path.startsWith('/')) {
|
|
2241
2284
|
path = '/' + path;
|
|
2242
2285
|
}
|
|
@@ -2269,10 +2312,12 @@ const getUrlPrefix = (platform, extensionPath) => {
|
|
|
2269
2312
|
if (platform === Web) {
|
|
2270
2313
|
return extensionPath;
|
|
2271
2314
|
}
|
|
2272
|
-
|
|
2273
|
-
|
|
2315
|
+
const withoutPrefix = extensionPath.startsWith('file://') ? extensionPath.slice('file://'.length) : extensionPath;
|
|
2316
|
+
const normalized = withoutPrefix.replaceAll('\\', '/');
|
|
2317
|
+
if (normalized.startsWith('/')) {
|
|
2318
|
+
return `/remote${normalized}`;
|
|
2274
2319
|
}
|
|
2275
|
-
return `/remote/${
|
|
2320
|
+
return `/remote/${normalized}`;
|
|
2276
2321
|
};
|
|
2277
2322
|
|
|
2278
2323
|
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
|
|
@@ -5922,10 +5967,12 @@ const getRemoteUrl = uri => {
|
|
|
5922
5967
|
if (uri.startsWith('http://') || uri.startsWith('https://')) {
|
|
5923
5968
|
return uri;
|
|
5924
5969
|
}
|
|
5925
|
-
|
|
5926
|
-
|
|
5970
|
+
const withoutPrefix = uri.startsWith('file://') ? uri.slice('file://'.length) : uri;
|
|
5971
|
+
const normalized = withoutPrefix.replaceAll('\\', '/');
|
|
5972
|
+
if (normalized.startsWith('/')) {
|
|
5973
|
+
return `/remote${normalized}`;
|
|
5927
5974
|
}
|
|
5928
|
-
return `/remote/${
|
|
5975
|
+
return `/remote/${normalized}`;
|
|
5929
5976
|
};
|
|
5930
5977
|
|
|
5931
5978
|
const getLanguagesFromExtension = (extension, platform) => {
|