@module-federation/runtime-core 0.0.0-next-20250926024003 → 0.0.0-refactor-manifest-20251013103938
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.
- package/dist/index.cjs.cjs +983 -869
- package/dist/index.cjs.cjs.map +1 -1
- package/dist/index.esm.js +983 -869
- package/dist/index.esm.js.map +1 -1
- package/package.json +3 -3
- package/dist/polyfills.cjs.cjs +0 -29
- package/dist/polyfills.cjs.cjs.map +0 -1
- package/dist/polyfills.esm.js +0 -26
- package/dist/polyfills.esm.js.map +0 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { _ as _extends, a as _object_without_properties_loose } from './polyfills.esm.js';
|
|
2
1
|
import { createLogger, isBrowserEnv, isReactNativeEnv, isDebugMode, composeKeyWithSeparator, loadScriptNode, loadScript, createLink, createScript, safeToString, getResourceUrl, isManifestProvider, generateSnapshotFromManifest, warn as warn$1 } from '@module-federation/sdk';
|
|
3
2
|
export { loadScript, loadScriptNode } from '@module-federation/sdk';
|
|
4
3
|
import { RUNTIME_008, getShortErrorMsg, runtimeDescMap, RUNTIME_001, RUNTIME_002, RUNTIME_007, RUNTIME_003, RUNTIME_005, RUNTIME_006, RUNTIME_004 } from '@module-federation/error-codes';
|
|
@@ -29,13 +28,14 @@ function warn(msg) {
|
|
|
29
28
|
msg.message = `${LOG_CATEGORY}: ${msg.message}`;
|
|
30
29
|
}
|
|
31
30
|
logger.warn(msg);
|
|
32
|
-
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
33
|
logger.warn(msg);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
function addUniqueItem(arr, item) {
|
|
38
|
-
if (arr.findIndex((name)=>name === item) === -1) {
|
|
38
|
+
if (arr.findIndex((name) => name === item) === -1) {
|
|
39
39
|
arr.push(item);
|
|
40
40
|
}
|
|
41
41
|
return arr;
|
|
@@ -43,9 +43,11 @@ function addUniqueItem(arr, item) {
|
|
|
43
43
|
function getFMId(remoteInfo) {
|
|
44
44
|
if ('version' in remoteInfo && remoteInfo.version) {
|
|
45
45
|
return `${remoteInfo.name}:${remoteInfo.version}`;
|
|
46
|
-
}
|
|
46
|
+
}
|
|
47
|
+
else if ('entry' in remoteInfo && remoteInfo.entry) {
|
|
47
48
|
return `${remoteInfo.name}:${remoteInfo.entry}`;
|
|
48
|
-
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
49
51
|
return `${remoteInfo.name}`;
|
|
50
52
|
}
|
|
51
53
|
}
|
|
@@ -60,7 +62,8 @@ async function safeWrapper(callback, disableWarn) {
|
|
|
60
62
|
try {
|
|
61
63
|
const res = await callback();
|
|
62
64
|
return res;
|
|
63
|
-
}
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
64
67
|
!disableWarn && warn(e);
|
|
65
68
|
return;
|
|
66
69
|
}
|
|
@@ -82,38 +85,39 @@ function isStaticResourcesEqual(url1, url2) {
|
|
|
82
85
|
return relativeUrl1 === relativeUrl2;
|
|
83
86
|
}
|
|
84
87
|
function arrayOptions(options) {
|
|
85
|
-
return Array.isArray(options) ? options : [
|
|
86
|
-
options
|
|
87
|
-
];
|
|
88
|
+
return Array.isArray(options) ? options : [options];
|
|
88
89
|
}
|
|
89
90
|
function getRemoteEntryInfoFromSnapshot(snapshot) {
|
|
90
91
|
const defaultRemoteEntryInfo = {
|
|
91
92
|
url: '',
|
|
92
93
|
type: 'global',
|
|
93
|
-
globalName: ''
|
|
94
|
+
globalName: '',
|
|
94
95
|
};
|
|
95
96
|
if (isBrowserEnv() || isReactNativeEnv()) {
|
|
96
|
-
return 'remoteEntry' in snapshot
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
97
|
+
return 'remoteEntry' in snapshot
|
|
98
|
+
? {
|
|
99
|
+
url: snapshot.remoteEntry,
|
|
100
|
+
type: snapshot.remoteEntryType,
|
|
101
|
+
globalName: snapshot.globalName,
|
|
102
|
+
}
|
|
103
|
+
: defaultRemoteEntryInfo;
|
|
101
104
|
}
|
|
102
105
|
if ('ssrRemoteEntry' in snapshot) {
|
|
103
106
|
return {
|
|
104
107
|
url: snapshot.ssrRemoteEntry || defaultRemoteEntryInfo.url,
|
|
105
108
|
type: snapshot.ssrRemoteEntryType || defaultRemoteEntryInfo.type,
|
|
106
|
-
globalName: snapshot.globalName
|
|
109
|
+
globalName: snapshot.globalName,
|
|
107
110
|
};
|
|
108
111
|
}
|
|
109
112
|
return defaultRemoteEntryInfo;
|
|
110
113
|
}
|
|
111
|
-
const processModuleAlias = (name, subPath)=>{
|
|
114
|
+
const processModuleAlias = (name, subPath) => {
|
|
112
115
|
// @host/ ./button -> @host/button
|
|
113
116
|
let moduleName;
|
|
114
117
|
if (name.endsWith('/')) {
|
|
115
118
|
moduleName = name.slice(0, -1);
|
|
116
|
-
}
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
117
121
|
moduleName = name;
|
|
118
122
|
}
|
|
119
123
|
if (subPath.startsWith('.')) {
|
|
@@ -124,11 +128,12 @@ const processModuleAlias = (name, subPath)=>{
|
|
|
124
128
|
};
|
|
125
129
|
|
|
126
130
|
const CurrentGlobal = typeof globalThis === 'object' ? globalThis : window;
|
|
127
|
-
const nativeGlobal = (()=>{
|
|
131
|
+
const nativeGlobal = (() => {
|
|
128
132
|
try {
|
|
129
133
|
// get real window (incase of sandbox)
|
|
130
134
|
return document.defaultView;
|
|
131
|
-
}
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
132
137
|
// node env
|
|
133
138
|
return CurrentGlobal;
|
|
134
139
|
}
|
|
@@ -138,7 +143,7 @@ function definePropertyGlobalVal(target, key, val) {
|
|
|
138
143
|
Object.defineProperty(target, key, {
|
|
139
144
|
value: val,
|
|
140
145
|
configurable: false,
|
|
141
|
-
writable: true
|
|
146
|
+
writable: true,
|
|
142
147
|
});
|
|
143
148
|
}
|
|
144
149
|
function includeOwnProperty(target, key) {
|
|
@@ -152,8 +157,8 @@ if (!includeOwnProperty(CurrentGlobal, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {
|
|
|
152
157
|
}
|
|
153
158
|
const globalLoading = CurrentGlobal.__GLOBAL_LOADING_REMOTE_ENTRY__;
|
|
154
159
|
function setGlobalDefaultVal(target) {
|
|
155
|
-
|
|
156
|
-
|
|
160
|
+
if (includeOwnProperty(target, '__VMOK__') &&
|
|
161
|
+
!includeOwnProperty(target, '__FEDERATION__')) {
|
|
157
162
|
definePropertyGlobalVal(target, '__FEDERATION__', target.__VMOK__);
|
|
158
163
|
}
|
|
159
164
|
if (!includeOwnProperty(target, '__FEDERATION__')) {
|
|
@@ -163,22 +168,16 @@ function setGlobalDefaultVal(target) {
|
|
|
163
168
|
moduleInfo: {},
|
|
164
169
|
__SHARE__: {},
|
|
165
170
|
__MANIFEST_LOADING__: {},
|
|
166
|
-
__PRELOADED_MAP__: new Map()
|
|
171
|
+
__PRELOADED_MAP__: new Map(),
|
|
167
172
|
});
|
|
168
173
|
definePropertyGlobalVal(target, '__VMOK__', target.__FEDERATION__);
|
|
169
174
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
var ___SHARE__;
|
|
177
|
-
(___SHARE__ = (_target___FEDERATION__3 = target.__FEDERATION__).__SHARE__) != null ? ___SHARE__ : _target___FEDERATION__3.__SHARE__ = {};
|
|
178
|
-
var ___MANIFEST_LOADING__;
|
|
179
|
-
(___MANIFEST_LOADING__ = (_target___FEDERATION__4 = target.__FEDERATION__).__MANIFEST_LOADING__) != null ? ___MANIFEST_LOADING__ : _target___FEDERATION__4.__MANIFEST_LOADING__ = {};
|
|
180
|
-
var ___PRELOADED_MAP__;
|
|
181
|
-
(___PRELOADED_MAP__ = (_target___FEDERATION__5 = target.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _target___FEDERATION__5.__PRELOADED_MAP__ = new Map();
|
|
175
|
+
target.__FEDERATION__.__GLOBAL_PLUGIN__ ??= [];
|
|
176
|
+
target.__FEDERATION__.__INSTANCES__ ??= [];
|
|
177
|
+
target.__FEDERATION__.moduleInfo ??= {};
|
|
178
|
+
target.__FEDERATION__.__SHARE__ ??= {};
|
|
179
|
+
target.__FEDERATION__.__MANIFEST_LOADING__ ??= {};
|
|
180
|
+
target.__FEDERATION__.__PRELOADED_MAP__ ??= new Map();
|
|
182
181
|
}
|
|
183
182
|
setGlobalDefaultVal(CurrentGlobal);
|
|
184
183
|
setGlobalDefaultVal(nativeGlobal);
|
|
@@ -188,7 +187,7 @@ function resetFederationGlobalInfo() {
|
|
|
188
187
|
CurrentGlobal.__FEDERATION__.moduleInfo = {};
|
|
189
188
|
CurrentGlobal.__FEDERATION__.__SHARE__ = {};
|
|
190
189
|
CurrentGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {};
|
|
191
|
-
Object.keys(globalLoading).forEach((key)=>{
|
|
190
|
+
Object.keys(globalLoading).forEach((key) => {
|
|
192
191
|
delete globalLoading[key];
|
|
193
192
|
});
|
|
194
193
|
}
|
|
@@ -201,7 +200,7 @@ function getGlobalFederationConstructor() {
|
|
|
201
200
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
|
|
202
201
|
if (isDebug) {
|
|
203
202
|
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
204
|
-
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.0-
|
|
203
|
+
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.0-refactor-manifest-20251013103938";
|
|
205
204
|
}
|
|
206
205
|
}
|
|
207
206
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -211,37 +210,42 @@ function getInfoWithoutType(target, key) {
|
|
|
211
210
|
if (keyRes) {
|
|
212
211
|
return {
|
|
213
212
|
value: target[key],
|
|
214
|
-
key: key
|
|
213
|
+
key: key,
|
|
215
214
|
};
|
|
216
|
-
}
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
217
|
const targetKeys = Object.keys(target);
|
|
218
|
-
for (const targetKey of targetKeys){
|
|
218
|
+
for (const targetKey of targetKeys) {
|
|
219
219
|
const [targetTypeOrName, _] = targetKey.split(':');
|
|
220
220
|
const nKey = `${targetTypeOrName}:${key}`;
|
|
221
221
|
const typeWithKeyRes = target[nKey];
|
|
222
222
|
if (typeWithKeyRes) {
|
|
223
223
|
return {
|
|
224
224
|
value: typeWithKeyRes,
|
|
225
|
-
key: nKey
|
|
225
|
+
key: nKey,
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
229
|
return {
|
|
230
230
|
value: undefined,
|
|
231
|
-
key: key
|
|
231
|
+
key: key,
|
|
232
232
|
};
|
|
233
233
|
}
|
|
234
|
-
}
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
235
236
|
throw new Error('key must be string');
|
|
236
237
|
}
|
|
237
238
|
}
|
|
238
|
-
const getGlobalSnapshot = ()=>nativeGlobal.__FEDERATION__.moduleInfo;
|
|
239
|
-
const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot)=>{
|
|
239
|
+
const getGlobalSnapshot = () => nativeGlobal.__FEDERATION__.moduleInfo;
|
|
240
|
+
const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot) => {
|
|
240
241
|
// Check if the remote is included in the hostSnapshot
|
|
241
242
|
const moduleKey = getFMId(moduleInfo);
|
|
242
243
|
const getModuleInfo = getInfoWithoutType(snapshot, moduleKey).value;
|
|
243
244
|
// The remoteSnapshot might not include a version
|
|
244
|
-
if (getModuleInfo &&
|
|
245
|
+
if (getModuleInfo &&
|
|
246
|
+
!getModuleInfo.version &&
|
|
247
|
+
'version' in moduleInfo &&
|
|
248
|
+
moduleInfo['version']) {
|
|
245
249
|
getModuleInfo.version = moduleInfo['version'];
|
|
246
250
|
}
|
|
247
251
|
if (getModuleInfo) {
|
|
@@ -249,57 +253,59 @@ const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot)=>{
|
|
|
249
253
|
}
|
|
250
254
|
// If the remote is not included in the hostSnapshot, deploy a micro app snapshot
|
|
251
255
|
if ('version' in moduleInfo && moduleInfo['version']) {
|
|
252
|
-
const { version
|
|
253
|
-
"version"
|
|
254
|
-
]);
|
|
256
|
+
const { version, ...resModuleInfo } = moduleInfo;
|
|
255
257
|
const moduleKeyWithoutVersion = getFMId(resModuleInfo);
|
|
256
258
|
const getModuleInfoWithoutVersion = getInfoWithoutType(nativeGlobal.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion).value;
|
|
257
|
-
if (
|
|
259
|
+
if (getModuleInfoWithoutVersion?.version === version) {
|
|
258
260
|
return getModuleInfoWithoutVersion;
|
|
259
261
|
}
|
|
260
262
|
}
|
|
261
263
|
return;
|
|
262
264
|
};
|
|
263
|
-
const getGlobalSnapshotInfoByModuleInfo = (moduleInfo)=>getTargetSnapshotInfoByModuleInfo(moduleInfo, nativeGlobal.__FEDERATION__.moduleInfo);
|
|
264
|
-
const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo)=>{
|
|
265
|
+
const getGlobalSnapshotInfoByModuleInfo = (moduleInfo) => getTargetSnapshotInfoByModuleInfo(moduleInfo, nativeGlobal.__FEDERATION__.moduleInfo);
|
|
266
|
+
const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo) => {
|
|
265
267
|
const moduleKey = getFMId(remoteInfo);
|
|
266
268
|
nativeGlobal.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;
|
|
267
269
|
return nativeGlobal.__FEDERATION__.moduleInfo;
|
|
268
270
|
};
|
|
269
|
-
const addGlobalSnapshot = (moduleInfos)=>{
|
|
270
|
-
nativeGlobal.__FEDERATION__.moduleInfo =
|
|
271
|
-
|
|
271
|
+
const addGlobalSnapshot = (moduleInfos) => {
|
|
272
|
+
nativeGlobal.__FEDERATION__.moduleInfo = {
|
|
273
|
+
...nativeGlobal.__FEDERATION__.moduleInfo,
|
|
274
|
+
...moduleInfos,
|
|
275
|
+
};
|
|
276
|
+
return () => {
|
|
272
277
|
const keys = Object.keys(moduleInfos);
|
|
273
|
-
for (const key of keys){
|
|
278
|
+
for (const key of keys) {
|
|
274
279
|
delete nativeGlobal.__FEDERATION__.moduleInfo[key];
|
|
275
280
|
}
|
|
276
281
|
};
|
|
277
282
|
};
|
|
278
|
-
const getRemoteEntryExports = (name, globalName)=>{
|
|
283
|
+
const getRemoteEntryExports = (name, globalName) => {
|
|
279
284
|
const remoteEntryKey = globalName || `__FEDERATION_${name}:custom__`;
|
|
280
285
|
const entryExports = CurrentGlobal[remoteEntryKey];
|
|
281
286
|
return {
|
|
282
287
|
remoteEntryKey,
|
|
283
|
-
entryExports
|
|
288
|
+
entryExports,
|
|
284
289
|
};
|
|
285
290
|
};
|
|
286
291
|
// This function is used to register global plugins.
|
|
287
292
|
// It iterates over the provided plugins and checks if they are already registered.
|
|
288
293
|
// If a plugin is not registered, it is added to the global plugins.
|
|
289
294
|
// If a plugin is already registered, a warning message is logged.
|
|
290
|
-
const registerGlobalPlugins = (plugins)=>{
|
|
295
|
+
const registerGlobalPlugins = (plugins) => {
|
|
291
296
|
const { __GLOBAL_PLUGIN__ } = nativeGlobal.__FEDERATION__;
|
|
292
|
-
plugins.forEach((plugin)=>{
|
|
293
|
-
if (__GLOBAL_PLUGIN__.findIndex((p)=>p.name === plugin.name) === -1) {
|
|
297
|
+
plugins.forEach((plugin) => {
|
|
298
|
+
if (__GLOBAL_PLUGIN__.findIndex((p) => p.name === plugin.name) === -1) {
|
|
294
299
|
__GLOBAL_PLUGIN__.push(plugin);
|
|
295
|
-
}
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
296
302
|
warn(`The plugin ${plugin.name} has been registered.`);
|
|
297
303
|
}
|
|
298
304
|
});
|
|
299
305
|
};
|
|
300
|
-
const getGlobalHostPlugins = ()=>nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__;
|
|
301
|
-
const getPreloaded = (id)=>CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.get(id);
|
|
302
|
-
const setPreloaded = (id)=>CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.set(id, true);
|
|
306
|
+
const getGlobalHostPlugins = () => nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__;
|
|
307
|
+
const getPreloaded = (id) => CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.get(id);
|
|
308
|
+
const setPreloaded = (id) => CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.set(id, true);
|
|
303
309
|
|
|
304
310
|
const DEFAULT_SCOPE = 'default';
|
|
305
311
|
const DEFAULT_REMOTE_TYPE = 'global';
|
|
@@ -358,7 +364,7 @@ function isXVersion(version) {
|
|
|
358
364
|
return !version || version.toLowerCase() === 'x' || version === '*';
|
|
359
365
|
}
|
|
360
366
|
function pipe(...fns) {
|
|
361
|
-
return (x)=>fns.reduce((v, f)=>f(v), x);
|
|
367
|
+
return (x) => fns.reduce((v, f) => f(v), x);
|
|
362
368
|
}
|
|
363
369
|
function extractComparator(comparatorString) {
|
|
364
370
|
return comparatorString.match(parseRegex(comparator));
|
|
@@ -380,25 +386,32 @@ function combineVersion(major, minor, patch, preRelease) {
|
|
|
380
386
|
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
381
387
|
// See the Mulan PSL v2 for more details.
|
|
382
388
|
function parseHyphen(range) {
|
|
383
|
-
return range.replace(parseRegex(hyphenRange), (_range, from, fromMajor, fromMinor, fromPatch, _fromPreRelease, _fromBuild, to, toMajor, toMinor, toPatch, toPreRelease)=>{
|
|
389
|
+
return range.replace(parseRegex(hyphenRange), (_range, from, fromMajor, fromMinor, fromPatch, _fromPreRelease, _fromBuild, to, toMajor, toMinor, toPatch, toPreRelease) => {
|
|
384
390
|
if (isXVersion(fromMajor)) {
|
|
385
391
|
from = '';
|
|
386
|
-
}
|
|
392
|
+
}
|
|
393
|
+
else if (isXVersion(fromMinor)) {
|
|
387
394
|
from = `>=${fromMajor}.0.0`;
|
|
388
|
-
}
|
|
395
|
+
}
|
|
396
|
+
else if (isXVersion(fromPatch)) {
|
|
389
397
|
from = `>=${fromMajor}.${fromMinor}.0`;
|
|
390
|
-
}
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
391
400
|
from = `>=${from}`;
|
|
392
401
|
}
|
|
393
402
|
if (isXVersion(toMajor)) {
|
|
394
403
|
to = '';
|
|
395
|
-
}
|
|
404
|
+
}
|
|
405
|
+
else if (isXVersion(toMinor)) {
|
|
396
406
|
to = `<${Number(toMajor) + 1}.0.0-0`;
|
|
397
|
-
}
|
|
407
|
+
}
|
|
408
|
+
else if (isXVersion(toPatch)) {
|
|
398
409
|
to = `<${toMajor}.${Number(toMinor) + 1}.0-0`;
|
|
399
|
-
}
|
|
410
|
+
}
|
|
411
|
+
else if (toPreRelease) {
|
|
400
412
|
to = `<=${toMajor}.${toMinor}.${toPatch}-${toPreRelease}`;
|
|
401
|
-
}
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
402
415
|
to = `<=${to}`;
|
|
403
416
|
}
|
|
404
417
|
return `${from} ${to}`.trim();
|
|
@@ -414,109 +427,140 @@ function parseCaretTrim(range) {
|
|
|
414
427
|
return range.replace(parseRegex(caretTrim), '$1^');
|
|
415
428
|
}
|
|
416
429
|
function parseCarets(range) {
|
|
417
|
-
return range
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
430
|
+
return range
|
|
431
|
+
.trim()
|
|
432
|
+
.split(/\s+/)
|
|
433
|
+
.map((rangeVersion) => rangeVersion.replace(parseRegex(caret), (_, major, minor, patch, preRelease) => {
|
|
434
|
+
if (isXVersion(major)) {
|
|
435
|
+
return '';
|
|
436
|
+
}
|
|
437
|
+
else if (isXVersion(minor)) {
|
|
438
|
+
return `>=${major}.0.0 <${Number(major) + 1}.0.0-0`;
|
|
439
|
+
}
|
|
440
|
+
else if (isXVersion(patch)) {
|
|
441
|
+
if (major === '0') {
|
|
442
|
+
return `>=${major}.${minor}.0 <${major}.${Number(minor) + 1}.0-0`;
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
return `>=${major}.${minor}.0 <${Number(major) + 1}.0.0-0`;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
else if (preRelease) {
|
|
449
|
+
if (major === '0') {
|
|
450
|
+
if (minor === '0') {
|
|
451
|
+
return `>=${major}.${minor}.${patch}-${preRelease} <${major}.${minor}.${Number(patch) + 1}-0`;
|
|
427
452
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
if (minor === '0') {
|
|
431
|
-
return `>=${major}.${minor}.${patch}-${preRelease} <${major}.${minor}.${Number(patch) + 1}-0`;
|
|
432
|
-
} else {
|
|
433
|
-
return `>=${major}.${minor}.${patch}-${preRelease} <${major}.${Number(minor) + 1}.0-0`;
|
|
434
|
-
}
|
|
435
|
-
} else {
|
|
436
|
-
return `>=${major}.${minor}.${patch}-${preRelease} <${Number(major) + 1}.0.0-0`;
|
|
453
|
+
else {
|
|
454
|
+
return `>=${major}.${minor}.${patch}-${preRelease} <${major}.${Number(minor) + 1}.0-0`;
|
|
437
455
|
}
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
return `>=${major}.${minor}.${patch}-${preRelease} <${Number(major) + 1}.0.0-0`;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
if (major === '0') {
|
|
463
|
+
if (minor === '0') {
|
|
464
|
+
return `>=${major}.${minor}.${patch} <${major}.${minor}.${Number(patch) + 1}-0`;
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
return `>=${major}.${minor}.${patch} <${major}.${Number(minor) + 1}.0-0`;
|
|
445
468
|
}
|
|
446
|
-
return `>=${major}.${minor}.${patch} <${Number(major) + 1}.0.0-0`;
|
|
447
469
|
}
|
|
448
|
-
|
|
470
|
+
return `>=${major}.${minor}.${patch} <${Number(major) + 1}.0.0-0`;
|
|
471
|
+
}
|
|
472
|
+
}))
|
|
473
|
+
.join(' ');
|
|
449
474
|
}
|
|
450
475
|
function parseTildes(range) {
|
|
451
|
-
return range
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
476
|
+
return range
|
|
477
|
+
.trim()
|
|
478
|
+
.split(/\s+/)
|
|
479
|
+
.map((rangeVersion) => rangeVersion.replace(parseRegex(tilde), (_, major, minor, patch, preRelease) => {
|
|
480
|
+
if (isXVersion(major)) {
|
|
481
|
+
return '';
|
|
482
|
+
}
|
|
483
|
+
else if (isXVersion(minor)) {
|
|
484
|
+
return `>=${major}.0.0 <${Number(major) + 1}.0.0-0`;
|
|
485
|
+
}
|
|
486
|
+
else if (isXVersion(patch)) {
|
|
487
|
+
return `>=${major}.${minor}.0 <${major}.${Number(minor) + 1}.0-0`;
|
|
488
|
+
}
|
|
489
|
+
else if (preRelease) {
|
|
490
|
+
return `>=${major}.${minor}.${patch}-${preRelease} <${major}.${Number(minor) + 1}.0-0`;
|
|
491
|
+
}
|
|
492
|
+
return `>=${major}.${minor}.${patch} <${major}.${Number(minor) + 1}.0-0`;
|
|
493
|
+
}))
|
|
494
|
+
.join(' ');
|
|
463
495
|
}
|
|
464
496
|
function parseXRanges(range) {
|
|
465
|
-
return range
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
}
|
|
482
|
-
|
|
497
|
+
return range
|
|
498
|
+
.split(/\s+/)
|
|
499
|
+
.map((rangeVersion) => rangeVersion
|
|
500
|
+
.trim()
|
|
501
|
+
.replace(parseRegex(xRange), (ret, gtlt, major, minor, patch, preRelease) => {
|
|
502
|
+
const isXMajor = isXVersion(major);
|
|
503
|
+
const isXMinor = isXMajor || isXVersion(minor);
|
|
504
|
+
const isXPatch = isXMinor || isXVersion(patch);
|
|
505
|
+
if (gtlt === '=' && isXPatch) {
|
|
506
|
+
gtlt = '';
|
|
507
|
+
}
|
|
508
|
+
preRelease = '';
|
|
509
|
+
if (isXMajor) {
|
|
510
|
+
if (gtlt === '>' || gtlt === '<') {
|
|
511
|
+
// nothing is allowed
|
|
512
|
+
return '<0.0.0-0';
|
|
513
|
+
}
|
|
514
|
+
else {
|
|
515
|
+
// nothing is forbidden
|
|
516
|
+
return '*';
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
else if (gtlt && isXPatch) {
|
|
520
|
+
// replace X with 0
|
|
521
|
+
if (isXMinor) {
|
|
522
|
+
minor = 0;
|
|
523
|
+
}
|
|
524
|
+
patch = 0;
|
|
525
|
+
if (gtlt === '>') {
|
|
526
|
+
// >1 => >=2.0.0
|
|
527
|
+
// >1.2 => >=1.3.0
|
|
528
|
+
gtlt = '>=';
|
|
483
529
|
if (isXMinor) {
|
|
530
|
+
major = Number(major) + 1;
|
|
484
531
|
minor = 0;
|
|
532
|
+
patch = 0;
|
|
485
533
|
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
// >1.2 => >=1.3.0
|
|
490
|
-
gtlt = '>=';
|
|
491
|
-
if (isXMinor) {
|
|
492
|
-
major = Number(major) + 1;
|
|
493
|
-
minor = 0;
|
|
494
|
-
patch = 0;
|
|
495
|
-
} else {
|
|
496
|
-
minor = Number(minor) + 1;
|
|
497
|
-
patch = 0;
|
|
498
|
-
}
|
|
499
|
-
} else if (gtlt === '<=') {
|
|
500
|
-
// <=0.7.x is actually <0.8.0, since any 0.7.x should pass
|
|
501
|
-
// Similarly, <=7.x is actually <8.0.0, etc.
|
|
502
|
-
gtlt = '<';
|
|
503
|
-
if (isXMinor) {
|
|
504
|
-
major = Number(major) + 1;
|
|
505
|
-
} else {
|
|
506
|
-
minor = Number(minor) + 1;
|
|
507
|
-
}
|
|
534
|
+
else {
|
|
535
|
+
minor = Number(minor) + 1;
|
|
536
|
+
patch = 0;
|
|
508
537
|
}
|
|
509
|
-
|
|
510
|
-
|
|
538
|
+
}
|
|
539
|
+
else if (gtlt === '<=') {
|
|
540
|
+
// <=0.7.x is actually <0.8.0, since any 0.7.x should pass
|
|
541
|
+
// Similarly, <=7.x is actually <8.0.0, etc.
|
|
542
|
+
gtlt = '<';
|
|
543
|
+
if (isXMinor) {
|
|
544
|
+
major = Number(major) + 1;
|
|
511
545
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
}
|
|
516
|
-
|
|
546
|
+
else {
|
|
547
|
+
minor = Number(minor) + 1;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
if (gtlt === '<') {
|
|
551
|
+
preRelease = '-0';
|
|
517
552
|
}
|
|
518
|
-
return
|
|
519
|
-
}
|
|
553
|
+
return `${gtlt + major}.${minor}.${patch}${preRelease}`;
|
|
554
|
+
}
|
|
555
|
+
else if (isXMinor) {
|
|
556
|
+
return `>=${major}.0.0${preRelease} <${Number(major) + 1}.0.0-0`;
|
|
557
|
+
}
|
|
558
|
+
else if (isXPatch) {
|
|
559
|
+
return `>=${major}.${minor}.0${preRelease} <${major}.${Number(minor) + 1}.0-0`;
|
|
560
|
+
}
|
|
561
|
+
return ret;
|
|
562
|
+
}))
|
|
563
|
+
.join(' ');
|
|
520
564
|
}
|
|
521
565
|
function parseStar(range) {
|
|
522
566
|
return range.trim().replace(parseRegex(star), '');
|
|
@@ -556,7 +600,7 @@ function comparePreRelease(rangeAtom, versionAtom) {
|
|
|
556
600
|
if (rangePreRelease === undefined && versionPreRelease === undefined) {
|
|
557
601
|
return 0;
|
|
558
602
|
}
|
|
559
|
-
for(let i = 0, n = rangePreRelease.length; i <= n; i++){
|
|
603
|
+
for (let i = 0, n = rangePreRelease.length; i <= n; i++) {
|
|
560
604
|
const rangeElement = rangePreRelease[i];
|
|
561
605
|
const versionElement = versionPreRelease[i];
|
|
562
606
|
if (rangeElement === versionElement) {
|
|
@@ -576,29 +620,31 @@ function comparePreRelease(rangeAtom, versionAtom) {
|
|
|
576
620
|
return 0;
|
|
577
621
|
}
|
|
578
622
|
function compareVersion(rangeAtom, versionAtom) {
|
|
579
|
-
return compareAtom(rangeAtom.major, versionAtom.major) ||
|
|
623
|
+
return (compareAtom(rangeAtom.major, versionAtom.major) ||
|
|
624
|
+
compareAtom(rangeAtom.minor, versionAtom.minor) ||
|
|
625
|
+
compareAtom(rangeAtom.patch, versionAtom.patch) ||
|
|
626
|
+
comparePreRelease(rangeAtom, versionAtom));
|
|
580
627
|
}
|
|
581
628
|
function eq(rangeAtom, versionAtom) {
|
|
582
629
|
return rangeAtom.version === versionAtom.version;
|
|
583
630
|
}
|
|
584
631
|
function compare(rangeAtom, versionAtom) {
|
|
585
|
-
switch(rangeAtom.operator){
|
|
632
|
+
switch (rangeAtom.operator) {
|
|
586
633
|
case '':
|
|
587
634
|
case '=':
|
|
588
635
|
return eq(rangeAtom, versionAtom);
|
|
589
636
|
case '>':
|
|
590
637
|
return compareVersion(rangeAtom, versionAtom) < 0;
|
|
591
638
|
case '>=':
|
|
592
|
-
return eq(rangeAtom, versionAtom) || compareVersion(rangeAtom, versionAtom) < 0;
|
|
639
|
+
return (eq(rangeAtom, versionAtom) || compareVersion(rangeAtom, versionAtom) < 0);
|
|
593
640
|
case '<':
|
|
594
641
|
return compareVersion(rangeAtom, versionAtom) > 0;
|
|
595
642
|
case '<=':
|
|
596
|
-
return eq(rangeAtom, versionAtom) || compareVersion(rangeAtom, versionAtom) > 0;
|
|
597
|
-
case undefined:
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
}
|
|
643
|
+
return (eq(rangeAtom, versionAtom) || compareVersion(rangeAtom, versionAtom) > 0);
|
|
644
|
+
case undefined: {
|
|
645
|
+
// mean * or x -> all versions
|
|
646
|
+
return true;
|
|
647
|
+
}
|
|
602
648
|
default:
|
|
603
649
|
return false;
|
|
604
650
|
}
|
|
@@ -613,14 +659,16 @@ function compare(rangeAtom, versionAtom) {
|
|
|
613
659
|
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
614
660
|
// See the Mulan PSL v2 for more details.
|
|
615
661
|
function parseComparatorString(range) {
|
|
616
|
-
return pipe(
|
|
662
|
+
return pipe(
|
|
663
|
+
// handle caret
|
|
617
664
|
// ^ --> * (any, kinda silly)
|
|
618
665
|
// ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0-0
|
|
619
666
|
// ^2.0, ^2.0.x --> >=2.0.0 <3.0.0-0
|
|
620
667
|
// ^1.2, ^1.2.x --> >=1.2.0 <2.0.0-0
|
|
621
668
|
// ^1.2.3 --> >=1.2.3 <2.0.0-0
|
|
622
669
|
// ^1.2.0 --> >=1.2.0 <2.0.0-0
|
|
623
|
-
parseCarets,
|
|
670
|
+
parseCarets,
|
|
671
|
+
// handle tilde
|
|
624
672
|
// ~, ~> --> * (any, kinda silly)
|
|
625
673
|
// ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0-0
|
|
626
674
|
// ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0-0
|
|
@@ -630,15 +678,21 @@ function parseComparatorString(range) {
|
|
|
630
678
|
parseTildes, parseXRanges, parseStar)(range);
|
|
631
679
|
}
|
|
632
680
|
function parseRange(range) {
|
|
633
|
-
return pipe(
|
|
681
|
+
return pipe(
|
|
682
|
+
// handle hyphenRange
|
|
634
683
|
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
|
|
635
|
-
parseHyphen,
|
|
684
|
+
parseHyphen,
|
|
685
|
+
// handle trim comparator
|
|
636
686
|
// `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
|
|
637
|
-
parseComparatorTrim,
|
|
687
|
+
parseComparatorTrim,
|
|
688
|
+
// handle trim tilde
|
|
638
689
|
// `~ 1.2.3` => `~1.2.3`
|
|
639
|
-
parseTildeTrim,
|
|
690
|
+
parseTildeTrim,
|
|
691
|
+
// handle trim caret
|
|
640
692
|
// `^ 1.2.3` => `^1.2.3`
|
|
641
|
-
parseCaretTrim)(range.trim())
|
|
693
|
+
parseCaretTrim)(range.trim())
|
|
694
|
+
.split(/\s+/)
|
|
695
|
+
.join(' ');
|
|
642
696
|
}
|
|
643
697
|
function satisfy(version, range) {
|
|
644
698
|
if (!version) {
|
|
@@ -650,18 +704,18 @@ function satisfy(version, range) {
|
|
|
650
704
|
// If the version string is invalid, it can't satisfy any range
|
|
651
705
|
return false;
|
|
652
706
|
}
|
|
653
|
-
const [, versionOperator, , versionMajor, versionMinor, versionPatch, versionPreRelease] = extractedVersion;
|
|
707
|
+
const [, versionOperator, , versionMajor, versionMinor, versionPatch, versionPreRelease,] = extractedVersion;
|
|
654
708
|
const versionAtom = {
|
|
655
709
|
operator: versionOperator,
|
|
656
|
-
version: combineVersion(versionMajor, versionMinor, versionPatch, versionPreRelease),
|
|
710
|
+
version: combineVersion(versionMajor, versionMinor, versionPatch, versionPreRelease), // exclude build atom
|
|
657
711
|
major: versionMajor,
|
|
658
712
|
minor: versionMinor,
|
|
659
713
|
patch: versionPatch,
|
|
660
|
-
preRelease: versionPreRelease
|
|
714
|
+
preRelease: versionPreRelease?.split('.'),
|
|
661
715
|
};
|
|
662
716
|
// Split the range by || to handle OR conditions
|
|
663
717
|
const orRanges = range.split('||');
|
|
664
|
-
for (const orRange of orRanges){
|
|
718
|
+
for (const orRange of orRanges) {
|
|
665
719
|
const trimmedOrRange = orRange.trim();
|
|
666
720
|
if (!trimmedOrRange) {
|
|
667
721
|
// An empty range string signifies wildcard *, satisfy any valid version
|
|
@@ -682,36 +736,41 @@ function satisfy(version, range) {
|
|
|
682
736
|
// If parsing results in empty string, treat as wildcard match
|
|
683
737
|
return true;
|
|
684
738
|
}
|
|
685
|
-
const parsedComparatorString = parsedSubRange
|
|
686
|
-
|
|
739
|
+
const parsedComparatorString = parsedSubRange
|
|
740
|
+
.split(' ')
|
|
741
|
+
.map((rangeVersion) => parseComparatorString(rangeVersion)) // Expands ^, ~
|
|
742
|
+
.join(' ');
|
|
687
743
|
// Check again if the comparator string became empty after specific parsing like ^ or ~
|
|
688
744
|
if (!parsedComparatorString.trim()) {
|
|
689
745
|
return true;
|
|
690
746
|
}
|
|
691
747
|
// Split the sub-range by space for implicit AND conditions
|
|
692
|
-
const comparators = parsedComparatorString
|
|
693
|
-
|
|
748
|
+
const comparators = parsedComparatorString
|
|
749
|
+
.split(/\s+/)
|
|
750
|
+
.map((comparator) => parseGTE0(comparator))
|
|
751
|
+
// Filter out empty strings that might result from multiple spaces
|
|
752
|
+
.filter(Boolean);
|
|
694
753
|
// If a sub-range becomes empty after parsing (e.g., invalid characters),
|
|
695
754
|
// it cannot be satisfied. This check might be redundant now but kept for safety.
|
|
696
755
|
if (comparators.length === 0) {
|
|
697
756
|
continue;
|
|
698
757
|
}
|
|
699
758
|
let subRangeSatisfied = true;
|
|
700
|
-
for (const comparator of comparators){
|
|
759
|
+
for (const comparator of comparators) {
|
|
701
760
|
const extractedComparator = extractComparator(comparator);
|
|
702
761
|
// If any part of the AND sub-range is invalid, the sub-range is not satisfied
|
|
703
762
|
if (!extractedComparator) {
|
|
704
763
|
subRangeSatisfied = false;
|
|
705
764
|
break;
|
|
706
765
|
}
|
|
707
|
-
const [, rangeOperator, , rangeMajor, rangeMinor, rangePatch, rangePreRelease] = extractedComparator;
|
|
766
|
+
const [, rangeOperator, , rangeMajor, rangeMinor, rangePatch, rangePreRelease,] = extractedComparator;
|
|
708
767
|
const rangeAtom = {
|
|
709
768
|
operator: rangeOperator,
|
|
710
769
|
version: combineVersion(rangeMajor, rangeMinor, rangePatch, rangePreRelease),
|
|
711
770
|
major: rangeMajor,
|
|
712
771
|
minor: rangeMinor,
|
|
713
772
|
patch: rangePatch,
|
|
714
|
-
preRelease: rangePreRelease
|
|
773
|
+
preRelease: rangePreRelease?.split('.'),
|
|
715
774
|
};
|
|
716
775
|
// Check if the version satisfies this specific comparator in the AND chain
|
|
717
776
|
if (!compare(rangeAtom, versionAtom)) {
|
|
@@ -723,7 +782,8 @@ function satisfy(version, range) {
|
|
|
723
782
|
if (subRangeSatisfied) {
|
|
724
783
|
return true;
|
|
725
784
|
}
|
|
726
|
-
}
|
|
785
|
+
}
|
|
786
|
+
catch (e) {
|
|
727
787
|
// Log error and treat this sub-range as unsatisfied
|
|
728
788
|
console.error(`[semver] Error processing range part "${trimmedOrRange}":`, e);
|
|
729
789
|
continue;
|
|
@@ -738,71 +798,73 @@ function formatShare(shareArgs, from, name, shareStrategy) {
|
|
|
738
798
|
if ('get' in shareArgs) {
|
|
739
799
|
// eslint-disable-next-line prefer-destructuring
|
|
740
800
|
get = shareArgs.get;
|
|
741
|
-
} else if ('lib' in shareArgs) {
|
|
742
|
-
get = ()=>Promise.resolve(shareArgs.lib);
|
|
743
|
-
} else {
|
|
744
|
-
get = ()=>Promise.resolve(()=>{
|
|
745
|
-
throw new Error(`Can not get shared '${name}'!`);
|
|
746
|
-
});
|
|
747
801
|
}
|
|
748
|
-
|
|
749
|
-
|
|
802
|
+
else if ('lib' in shareArgs) {
|
|
803
|
+
get = () => Promise.resolve(shareArgs.lib);
|
|
804
|
+
}
|
|
805
|
+
else {
|
|
806
|
+
get = () => Promise.resolve(() => {
|
|
807
|
+
throw new Error(`Can not get shared '${name}'!`);
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
return {
|
|
750
811
|
deps: [],
|
|
751
812
|
useIn: [],
|
|
752
813
|
from,
|
|
753
|
-
loading: null
|
|
754
|
-
|
|
755
|
-
shareConfig:
|
|
814
|
+
loading: null,
|
|
815
|
+
...shareArgs,
|
|
816
|
+
shareConfig: {
|
|
756
817
|
requiredVersion: `^${shareArgs.version}`,
|
|
757
818
|
singleton: false,
|
|
758
819
|
eager: false,
|
|
759
|
-
strictVersion: false
|
|
760
|
-
|
|
820
|
+
strictVersion: false,
|
|
821
|
+
...shareArgs.shareConfig,
|
|
822
|
+
},
|
|
761
823
|
get,
|
|
762
|
-
loaded:
|
|
763
|
-
version:
|
|
764
|
-
scope: Array.isArray(shareArgs.scope)
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
strategy: (
|
|
768
|
-
}
|
|
824
|
+
loaded: shareArgs?.loaded || 'lib' in shareArgs ? true : undefined,
|
|
825
|
+
version: shareArgs.version ?? '0',
|
|
826
|
+
scope: Array.isArray(shareArgs.scope)
|
|
827
|
+
? shareArgs.scope
|
|
828
|
+
: [shareArgs.scope ?? 'default'],
|
|
829
|
+
strategy: (shareArgs.strategy ?? shareStrategy) || 'version-first',
|
|
830
|
+
};
|
|
769
831
|
}
|
|
770
832
|
function formatShareConfigs(globalOptions, userOptions) {
|
|
771
833
|
const shareArgs = userOptions.shared || {};
|
|
772
834
|
const from = userOptions.name;
|
|
773
|
-
const shareInfos = Object.keys(shareArgs).reduce((res, pkgName)=>{
|
|
835
|
+
const shareInfos = Object.keys(shareArgs).reduce((res, pkgName) => {
|
|
774
836
|
const arrayShareArgs = arrayOptions(shareArgs[pkgName]);
|
|
775
837
|
res[pkgName] = res[pkgName] || [];
|
|
776
|
-
arrayShareArgs.forEach((shareConfig)=>{
|
|
838
|
+
arrayShareArgs.forEach((shareConfig) => {
|
|
777
839
|
res[pkgName].push(formatShare(shareConfig, from, pkgName, userOptions.shareStrategy));
|
|
778
840
|
});
|
|
779
841
|
return res;
|
|
780
842
|
}, {});
|
|
781
|
-
const shared =
|
|
782
|
-
|
|
843
|
+
const shared = {
|
|
844
|
+
...globalOptions.shared,
|
|
845
|
+
};
|
|
846
|
+
Object.keys(shareInfos).forEach((shareKey) => {
|
|
783
847
|
if (!shared[shareKey]) {
|
|
784
848
|
shared[shareKey] = shareInfos[shareKey];
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
|
|
849
|
+
}
|
|
850
|
+
else {
|
|
851
|
+
shareInfos[shareKey].forEach((newUserSharedOptions) => {
|
|
852
|
+
const isSameVersion = shared[shareKey].find((sharedVal) => sharedVal.version === newUserSharedOptions.version);
|
|
788
853
|
if (!isSameVersion) {
|
|
789
854
|
shared[shareKey].push(newUserSharedOptions);
|
|
790
855
|
}
|
|
791
856
|
});
|
|
792
857
|
}
|
|
793
858
|
});
|
|
794
|
-
return {
|
|
795
|
-
shared,
|
|
796
|
-
shareInfos
|
|
797
|
-
};
|
|
859
|
+
return { shared, shareInfos };
|
|
798
860
|
}
|
|
799
861
|
function versionLt(a, b) {
|
|
800
|
-
const transformInvalidVersion = (version)=>{
|
|
862
|
+
const transformInvalidVersion = (version) => {
|
|
801
863
|
const isNumberVersion = !Number.isNaN(Number(version));
|
|
802
864
|
if (isNumberVersion) {
|
|
803
865
|
const splitArr = version.split('.');
|
|
804
866
|
let validVersion = version;
|
|
805
|
-
for(let i = 0; i < 3 - splitArr.length; i++){
|
|
867
|
+
for (let i = 0; i < 3 - splitArr.length; i++) {
|
|
806
868
|
validVersion += '.0';
|
|
807
869
|
}
|
|
808
870
|
return validVersion;
|
|
@@ -811,15 +873,17 @@ function versionLt(a, b) {
|
|
|
811
873
|
};
|
|
812
874
|
if (satisfy(transformInvalidVersion(a), `<=${transformInvalidVersion(b)}`)) {
|
|
813
875
|
return true;
|
|
814
|
-
}
|
|
876
|
+
}
|
|
877
|
+
else {
|
|
815
878
|
return false;
|
|
816
879
|
}
|
|
817
880
|
}
|
|
818
|
-
const findVersion = (shareVersionMap, cb)=>{
|
|
819
|
-
const callback = cb ||
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
881
|
+
const findVersion = (shareVersionMap, cb) => {
|
|
882
|
+
const callback = cb ||
|
|
883
|
+
function (prev, cur) {
|
|
884
|
+
return versionLt(prev, cur);
|
|
885
|
+
};
|
|
886
|
+
return Object.keys(shareVersionMap).reduce((prev, cur) => {
|
|
823
887
|
if (!prev) {
|
|
824
888
|
return cur;
|
|
825
889
|
}
|
|
@@ -833,29 +897,30 @@ const findVersion = (shareVersionMap, cb)=>{
|
|
|
833
897
|
return prev;
|
|
834
898
|
}, 0);
|
|
835
899
|
};
|
|
836
|
-
const isLoaded = (shared)=>{
|
|
900
|
+
const isLoaded = (shared) => {
|
|
837
901
|
return Boolean(shared.loaded) || typeof shared.lib === 'function';
|
|
838
902
|
};
|
|
839
|
-
const isLoading = (shared)=>{
|
|
903
|
+
const isLoading = (shared) => {
|
|
840
904
|
return Boolean(shared.loading);
|
|
841
905
|
};
|
|
842
906
|
function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
|
|
843
907
|
const versions = shareScopeMap[scope][pkgName];
|
|
844
|
-
const callback = function(prev, cur) {
|
|
908
|
+
const callback = function (prev, cur) {
|
|
845
909
|
return !isLoaded(versions[prev]) && versionLt(prev, cur);
|
|
846
910
|
};
|
|
847
911
|
return findVersion(shareScopeMap[scope][pkgName], callback);
|
|
848
912
|
}
|
|
849
913
|
function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
|
|
850
914
|
const versions = shareScopeMap[scope][pkgName];
|
|
851
|
-
const callback = function(prev, cur) {
|
|
852
|
-
const isLoadingOrLoaded = (shared)=>{
|
|
915
|
+
const callback = function (prev, cur) {
|
|
916
|
+
const isLoadingOrLoaded = (shared) => {
|
|
853
917
|
return isLoaded(shared) || isLoading(shared);
|
|
854
918
|
};
|
|
855
919
|
if (isLoadingOrLoaded(versions[cur])) {
|
|
856
920
|
if (isLoadingOrLoaded(versions[prev])) {
|
|
857
921
|
return Boolean(versionLt(prev, cur));
|
|
858
|
-
}
|
|
922
|
+
}
|
|
923
|
+
else {
|
|
859
924
|
return true;
|
|
860
925
|
}
|
|
861
926
|
}
|
|
@@ -877,34 +942,38 @@ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare
|
|
|
877
942
|
return;
|
|
878
943
|
}
|
|
879
944
|
const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
|
|
880
|
-
const scopes = Array.isArray(scope) ? scope : [
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
945
|
+
const scopes = Array.isArray(scope) ? scope : [scope];
|
|
946
|
+
for (const sc of scopes) {
|
|
947
|
+
if (shareConfig &&
|
|
948
|
+
localShareScopeMap[sc] &&
|
|
949
|
+
localShareScopeMap[sc][pkgName]) {
|
|
885
950
|
const { requiredVersion } = shareConfig;
|
|
886
951
|
const findShareFunction = getFindShareFunction(strategy);
|
|
887
952
|
const maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName);
|
|
888
953
|
//@ts-ignore
|
|
889
|
-
const defaultResolver = ()=>{
|
|
954
|
+
const defaultResolver = () => {
|
|
890
955
|
if (shareConfig.singleton) {
|
|
891
|
-
if (typeof requiredVersion === 'string' &&
|
|
892
|
-
|
|
956
|
+
if (typeof requiredVersion === 'string' &&
|
|
957
|
+
!satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
958
|
+
const msg = `Version ${maxOrSingletonVersion} from ${maxOrSingletonVersion &&
|
|
959
|
+
localShareScopeMap[sc][pkgName][maxOrSingletonVersion].from} of shared singleton module ${pkgName} does not satisfy the requirement of ${shareInfo.from} which needs ${requiredVersion})`;
|
|
893
960
|
if (shareConfig.strictVersion) {
|
|
894
961
|
error(msg);
|
|
895
|
-
}
|
|
962
|
+
}
|
|
963
|
+
else {
|
|
896
964
|
warn(msg);
|
|
897
965
|
}
|
|
898
966
|
}
|
|
899
967
|
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
900
|
-
}
|
|
968
|
+
}
|
|
969
|
+
else {
|
|
901
970
|
if (requiredVersion === false || requiredVersion === '*') {
|
|
902
971
|
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
903
972
|
}
|
|
904
973
|
if (satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
905
974
|
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
906
975
|
}
|
|
907
|
-
for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])){
|
|
976
|
+
for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])) {
|
|
908
977
|
if (satisfy(versionKey, requiredVersion)) {
|
|
909
978
|
return versionValue;
|
|
910
979
|
}
|
|
@@ -917,7 +986,7 @@ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare
|
|
|
917
986
|
pkgName,
|
|
918
987
|
version: maxOrSingletonVersion,
|
|
919
988
|
GlobalFederation: Global.__FEDERATION__,
|
|
920
|
-
resolver: defaultResolver
|
|
989
|
+
resolver: defaultResolver,
|
|
921
990
|
};
|
|
922
991
|
const resolveShared = resolveShare.emit(params) || params;
|
|
923
992
|
return resolveShared.resolver();
|
|
@@ -929,28 +998,30 @@ function getGlobalShareScope() {
|
|
|
929
998
|
}
|
|
930
999
|
function getTargetSharedOptions(options) {
|
|
931
1000
|
const { pkgName, extraOptions, shareInfos } = options;
|
|
932
|
-
const defaultResolver = (sharedOptions)=>{
|
|
1001
|
+
const defaultResolver = (sharedOptions) => {
|
|
933
1002
|
if (!sharedOptions) {
|
|
934
1003
|
return undefined;
|
|
935
1004
|
}
|
|
936
1005
|
const shareVersionMap = {};
|
|
937
|
-
sharedOptions.forEach((shared)=>{
|
|
1006
|
+
sharedOptions.forEach((shared) => {
|
|
938
1007
|
shareVersionMap[shared.version] = shared;
|
|
939
1008
|
});
|
|
940
|
-
const callback = function(prev, cur) {
|
|
1009
|
+
const callback = function (prev, cur) {
|
|
941
1010
|
return !isLoaded(shareVersionMap[prev]) && versionLt(prev, cur);
|
|
942
1011
|
};
|
|
943
1012
|
const maxVersion = findVersion(shareVersionMap, callback);
|
|
944
1013
|
return shareVersionMap[maxVersion];
|
|
945
1014
|
};
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
return Object.assign({}, resolver(shareInfos[pkgName]), extraOptions == null ? void 0 : extraOptions.customShareInfo);
|
|
1015
|
+
const resolver = extraOptions?.resolver ?? defaultResolver;
|
|
1016
|
+
return Object.assign({}, resolver(shareInfos[pkgName]), extraOptions?.customShareInfo);
|
|
949
1017
|
}
|
|
950
1018
|
|
|
951
1019
|
function getBuilderId() {
|
|
952
1020
|
//@ts-ignore
|
|
953
|
-
return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined'
|
|
1021
|
+
return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined'
|
|
1022
|
+
? //@ts-ignore
|
|
1023
|
+
FEDERATION_BUILD_IDENTIFIER
|
|
1024
|
+
: '';
|
|
954
1025
|
}
|
|
955
1026
|
|
|
956
1027
|
// Function to match a remote with its name and expose
|
|
@@ -958,7 +1029,7 @@ function getBuilderId() {
|
|
|
958
1029
|
// id: alias(app1) + expose(button) = app1/button
|
|
959
1030
|
// id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort
|
|
960
1031
|
function matchRemoteWithNameAndExpose(remotes, id) {
|
|
961
|
-
for (const remote of remotes){
|
|
1032
|
+
for (const remote of remotes) {
|
|
962
1033
|
// match pkgName
|
|
963
1034
|
const isNameMatched = id.startsWith(remote.name);
|
|
964
1035
|
let expose = id.replace(remote.name, '');
|
|
@@ -969,13 +1040,14 @@ function matchRemoteWithNameAndExpose(remotes, id) {
|
|
|
969
1040
|
return {
|
|
970
1041
|
pkgNameOrAlias,
|
|
971
1042
|
expose,
|
|
972
|
-
remote
|
|
1043
|
+
remote,
|
|
973
1044
|
};
|
|
974
|
-
}
|
|
1045
|
+
}
|
|
1046
|
+
else if (expose === '') {
|
|
975
1047
|
return {
|
|
976
1048
|
pkgNameOrAlias: remote.name,
|
|
977
1049
|
expose: '.',
|
|
978
|
-
remote
|
|
1050
|
+
remote,
|
|
979
1051
|
};
|
|
980
1052
|
}
|
|
981
1053
|
}
|
|
@@ -989,13 +1061,14 @@ function matchRemoteWithNameAndExpose(remotes, id) {
|
|
|
989
1061
|
return {
|
|
990
1062
|
pkgNameOrAlias,
|
|
991
1063
|
expose: exposeWithAlias,
|
|
992
|
-
remote
|
|
1064
|
+
remote,
|
|
993
1065
|
};
|
|
994
|
-
}
|
|
1066
|
+
}
|
|
1067
|
+
else if (exposeWithAlias === '') {
|
|
995
1068
|
return {
|
|
996
1069
|
pkgNameOrAlias: remote.alias,
|
|
997
1070
|
expose: '.',
|
|
998
|
-
remote
|
|
1071
|
+
remote,
|
|
999
1072
|
};
|
|
1000
1073
|
}
|
|
1001
1074
|
}
|
|
@@ -1004,7 +1077,7 @@ function matchRemoteWithNameAndExpose(remotes, id) {
|
|
|
1004
1077
|
}
|
|
1005
1078
|
// Function to match a remote with its name or alias
|
|
1006
1079
|
function matchRemote(remotes, nameOrAlias) {
|
|
1007
|
-
for (const remote of remotes){
|
|
1080
|
+
for (const remote of remotes) {
|
|
1008
1081
|
const isNameMatched = nameOrAlias === remote.name;
|
|
1009
1082
|
if (isNameMatched) {
|
|
1010
1083
|
return remote;
|
|
@@ -1025,19 +1098,19 @@ function registerPlugins(plugins, instance) {
|
|
|
1025
1098
|
instance.sharedHandler.hooks,
|
|
1026
1099
|
instance.snapshotHandler.hooks,
|
|
1027
1100
|
instance.loaderHook,
|
|
1028
|
-
instance.bridgeHook
|
|
1101
|
+
instance.bridgeHook,
|
|
1029
1102
|
];
|
|
1030
1103
|
// Incorporate global plugins
|
|
1031
1104
|
if (globalPlugins.length > 0) {
|
|
1032
|
-
globalPlugins.forEach((plugin)=>{
|
|
1033
|
-
if (plugins
|
|
1105
|
+
globalPlugins.forEach((plugin) => {
|
|
1106
|
+
if (plugins?.find((item) => item.name !== plugin.name)) {
|
|
1034
1107
|
plugins.push(plugin);
|
|
1035
1108
|
}
|
|
1036
1109
|
});
|
|
1037
1110
|
}
|
|
1038
1111
|
if (plugins && plugins.length > 0) {
|
|
1039
|
-
plugins.forEach((plugin)=>{
|
|
1040
|
-
hookInstances.forEach((hookInstance)=>{
|
|
1112
|
+
plugins.forEach((plugin) => {
|
|
1113
|
+
hookInstances.forEach((hookInstance) => {
|
|
1041
1114
|
hookInstance.applyPlugin(plugin, instance);
|
|
1042
1115
|
});
|
|
1043
1116
|
});
|
|
@@ -1046,44 +1119,49 @@ function registerPlugins(plugins, instance) {
|
|
|
1046
1119
|
}
|
|
1047
1120
|
|
|
1048
1121
|
const importCallback = '.then(callbacks[0]).catch(callbacks[1])';
|
|
1049
|
-
async function loadEsmEntry({ entry, remoteEntryExports }) {
|
|
1050
|
-
return new Promise((resolve, reject)=>{
|
|
1122
|
+
async function loadEsmEntry({ entry, remoteEntryExports, }) {
|
|
1123
|
+
return new Promise((resolve, reject) => {
|
|
1051
1124
|
try {
|
|
1052
1125
|
if (!remoteEntryExports) {
|
|
1053
1126
|
if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== 'undefined') {
|
|
1054
1127
|
new Function('callbacks', `import("${entry}")${importCallback}`)([
|
|
1055
1128
|
resolve,
|
|
1056
|
-
reject
|
|
1129
|
+
reject,
|
|
1057
1130
|
]);
|
|
1058
|
-
} else {
|
|
1059
|
-
import(/* webpackIgnore: true */ /* @vite-ignore */ entry).then(resolve).catch(reject);
|
|
1060
1131
|
}
|
|
1061
|
-
|
|
1132
|
+
else {
|
|
1133
|
+
import(/* webpackIgnore: true */ /* @vite-ignore */ entry)
|
|
1134
|
+
.then(resolve)
|
|
1135
|
+
.catch(reject);
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
else {
|
|
1062
1139
|
resolve(remoteEntryExports);
|
|
1063
1140
|
}
|
|
1064
|
-
}
|
|
1141
|
+
}
|
|
1142
|
+
catch (e) {
|
|
1065
1143
|
reject(e);
|
|
1066
1144
|
}
|
|
1067
1145
|
});
|
|
1068
1146
|
}
|
|
1069
|
-
async function loadSystemJsEntry({ entry, remoteEntryExports }) {
|
|
1070
|
-
return new Promise((resolve, reject)=>{
|
|
1147
|
+
async function loadSystemJsEntry({ entry, remoteEntryExports, }) {
|
|
1148
|
+
return new Promise((resolve, reject) => {
|
|
1071
1149
|
try {
|
|
1072
1150
|
if (!remoteEntryExports) {
|
|
1073
1151
|
//@ts-ignore
|
|
1074
1152
|
if (typeof __system_context__ === 'undefined') {
|
|
1075
1153
|
//@ts-ignore
|
|
1076
1154
|
System.import(entry).then(resolve).catch(reject);
|
|
1077
|
-
} else {
|
|
1078
|
-
new Function('callbacks', `System.import("${entry}")${importCallback}`)([
|
|
1079
|
-
resolve,
|
|
1080
|
-
reject
|
|
1081
|
-
]);
|
|
1082
1155
|
}
|
|
1083
|
-
|
|
1156
|
+
else {
|
|
1157
|
+
new Function('callbacks', `System.import("${entry}")${importCallback}`)([resolve, reject]);
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
else {
|
|
1084
1161
|
resolve(remoteEntryExports);
|
|
1085
1162
|
}
|
|
1086
|
-
}
|
|
1163
|
+
}
|
|
1164
|
+
catch (e) {
|
|
1087
1165
|
reject(e);
|
|
1088
1166
|
}
|
|
1089
1167
|
});
|
|
@@ -1093,11 +1171,11 @@ function handleRemoteEntryLoaded(name, globalName, entry) {
|
|
|
1093
1171
|
assert(entryExports, getShortErrorMsg(RUNTIME_001, runtimeDescMap, {
|
|
1094
1172
|
remoteName: name,
|
|
1095
1173
|
remoteEntryUrl: entry,
|
|
1096
|
-
remoteEntryKey
|
|
1174
|
+
remoteEntryKey,
|
|
1097
1175
|
}));
|
|
1098
1176
|
return entryExports;
|
|
1099
1177
|
}
|
|
1100
|
-
async function loadEntryScript({ name, globalName, entry, loaderHook, getEntryUrl }) {
|
|
1178
|
+
async function loadEntryScript({ name, globalName, entry, loaderHook, getEntryUrl, }) {
|
|
1101
1179
|
const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
|
|
1102
1180
|
if (remoteEntryExports) {
|
|
1103
1181
|
return remoteEntryExports;
|
|
@@ -1106,12 +1184,10 @@ async function loadEntryScript({ name, globalName, entry, loaderHook, getEntryUr
|
|
|
1106
1184
|
const url = getEntryUrl ? getEntryUrl(entry) : entry;
|
|
1107
1185
|
return loadScript(url, {
|
|
1108
1186
|
attrs: {},
|
|
1109
|
-
createScriptHook: (url, attrs)=>{
|
|
1110
|
-
const res = loaderHook.lifecycle.createScript.emit({
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
});
|
|
1114
|
-
if (!res) return;
|
|
1187
|
+
createScriptHook: (url, attrs) => {
|
|
1188
|
+
const res = loaderHook.lifecycle.createScript.emit({ url, attrs });
|
|
1189
|
+
if (!res)
|
|
1190
|
+
return;
|
|
1115
1191
|
if (res instanceof HTMLScriptElement) {
|
|
1116
1192
|
return res;
|
|
1117
1193
|
}
|
|
@@ -1119,69 +1195,61 @@ async function loadEntryScript({ name, globalName, entry, loaderHook, getEntryUr
|
|
|
1119
1195
|
return res;
|
|
1120
1196
|
}
|
|
1121
1197
|
return;
|
|
1122
|
-
}
|
|
1123
|
-
})
|
|
1198
|
+
},
|
|
1199
|
+
})
|
|
1200
|
+
.then(() => {
|
|
1124
1201
|
return handleRemoteEntryLoaded(name, globalName, entry);
|
|
1125
|
-
})
|
|
1202
|
+
})
|
|
1203
|
+
.catch((e) => {
|
|
1126
1204
|
assert(undefined, getShortErrorMsg(RUNTIME_008, runtimeDescMap, {
|
|
1127
1205
|
remoteName: name,
|
|
1128
|
-
resourceUrl: entry
|
|
1206
|
+
resourceUrl: entry,
|
|
1129
1207
|
}));
|
|
1130
1208
|
throw e;
|
|
1131
1209
|
});
|
|
1132
1210
|
}
|
|
1133
|
-
async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEntryUrl }) {
|
|
1211
|
+
async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEntryUrl, }) {
|
|
1134
1212
|
const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
|
|
1135
|
-
switch(type){
|
|
1213
|
+
switch (type) {
|
|
1136
1214
|
case 'esm':
|
|
1137
1215
|
case 'module':
|
|
1138
|
-
return loadEsmEntry({
|
|
1139
|
-
entry,
|
|
1140
|
-
remoteEntryExports
|
|
1141
|
-
});
|
|
1216
|
+
return loadEsmEntry({ entry, remoteEntryExports });
|
|
1142
1217
|
case 'system':
|
|
1143
|
-
return loadSystemJsEntry({
|
|
1144
|
-
entry,
|
|
1145
|
-
remoteEntryExports
|
|
1146
|
-
});
|
|
1218
|
+
return loadSystemJsEntry({ entry, remoteEntryExports });
|
|
1147
1219
|
default:
|
|
1148
1220
|
return loadEntryScript({
|
|
1149
1221
|
entry,
|
|
1150
1222
|
globalName,
|
|
1151
1223
|
name,
|
|
1152
1224
|
loaderHook,
|
|
1153
|
-
getEntryUrl
|
|
1225
|
+
getEntryUrl,
|
|
1154
1226
|
});
|
|
1155
1227
|
}
|
|
1156
1228
|
}
|
|
1157
|
-
async function loadEntryNode({ remoteInfo, loaderHook }) {
|
|
1229
|
+
async function loadEntryNode({ remoteInfo, loaderHook, }) {
|
|
1158
1230
|
const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
|
|
1159
1231
|
const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
|
|
1160
1232
|
if (remoteEntryExports) {
|
|
1161
1233
|
return remoteEntryExports;
|
|
1162
1234
|
}
|
|
1163
1235
|
return loadScriptNode(entry, {
|
|
1164
|
-
attrs: {
|
|
1165
|
-
name,
|
|
1166
|
-
globalName,
|
|
1167
|
-
type
|
|
1168
|
-
},
|
|
1236
|
+
attrs: { name, globalName, type },
|
|
1169
1237
|
loaderHook: {
|
|
1170
|
-
createScriptHook: (url, attrs = {})=>{
|
|
1171
|
-
const res = loaderHook.lifecycle.createScript.emit({
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
});
|
|
1175
|
-
if (!res) return;
|
|
1238
|
+
createScriptHook: (url, attrs = {}) => {
|
|
1239
|
+
const res = loaderHook.lifecycle.createScript.emit({ url, attrs });
|
|
1240
|
+
if (!res)
|
|
1241
|
+
return;
|
|
1176
1242
|
if ('url' in res) {
|
|
1177
1243
|
return res;
|
|
1178
1244
|
}
|
|
1179
1245
|
return;
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
})
|
|
1246
|
+
},
|
|
1247
|
+
},
|
|
1248
|
+
})
|
|
1249
|
+
.then(() => {
|
|
1183
1250
|
return handleRemoteEntryLoaded(name, globalName, entry);
|
|
1184
|
-
})
|
|
1251
|
+
})
|
|
1252
|
+
.catch((e) => {
|
|
1185
1253
|
throw e;
|
|
1186
1254
|
});
|
|
1187
1255
|
}
|
|
@@ -1190,7 +1258,7 @@ function getRemoteEntryUniqueKey(remoteInfo) {
|
|
|
1190
1258
|
return composeKeyWithSeparator(name, entry);
|
|
1191
1259
|
}
|
|
1192
1260
|
async function getRemoteEntry(params) {
|
|
1193
|
-
const { origin, remoteEntryExports, remoteInfo, getEntryUrl, _inErrorHandling = false } = params;
|
|
1261
|
+
const { origin, remoteEntryExports, remoteInfo, getEntryUrl, _inErrorHandling = false, } = params;
|
|
1194
1262
|
const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
|
|
1195
1263
|
if (remoteEntryExports) {
|
|
1196
1264
|
return remoteEntryExports;
|
|
@@ -1198,33 +1266,35 @@ async function getRemoteEntry(params) {
|
|
|
1198
1266
|
if (!globalLoading[uniqueKey]) {
|
|
1199
1267
|
const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
|
|
1200
1268
|
const loaderHook = origin.loaderHook;
|
|
1201
|
-
globalLoading[uniqueKey] = loadEntryHook
|
|
1269
|
+
globalLoading[uniqueKey] = loadEntryHook
|
|
1270
|
+
.emit({
|
|
1202
1271
|
loaderHook,
|
|
1203
1272
|
remoteInfo,
|
|
1204
|
-
remoteEntryExports
|
|
1205
|
-
})
|
|
1273
|
+
remoteEntryExports,
|
|
1274
|
+
})
|
|
1275
|
+
.then((res) => {
|
|
1206
1276
|
if (res) {
|
|
1207
1277
|
return res;
|
|
1208
1278
|
}
|
|
1209
1279
|
// Use ENV_TARGET if defined, otherwise fallback to isBrowserEnv, must keep this
|
|
1210
|
-
const isWebEnvironment = typeof ENV_TARGET !== 'undefined'
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1280
|
+
const isWebEnvironment = typeof ENV_TARGET !== 'undefined'
|
|
1281
|
+
? ENV_TARGET === 'web'
|
|
1282
|
+
: isBrowserEnv();
|
|
1283
|
+
return isWebEnvironment
|
|
1284
|
+
? loadEntryDom({
|
|
1285
|
+
remoteInfo,
|
|
1286
|
+
remoteEntryExports,
|
|
1287
|
+
loaderHook,
|
|
1288
|
+
getEntryUrl,
|
|
1289
|
+
})
|
|
1290
|
+
: loadEntryNode({ remoteInfo, loaderHook });
|
|
1291
|
+
})
|
|
1292
|
+
.catch(async (err) => {
|
|
1221
1293
|
const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
|
|
1222
1294
|
const isScriptLoadError = err instanceof Error && err.message.includes(RUNTIME_008);
|
|
1223
1295
|
if (isScriptLoadError && !_inErrorHandling) {
|
|
1224
|
-
const wrappedGetRemoteEntry = (params)=>{
|
|
1225
|
-
return getRemoteEntry(
|
|
1226
|
-
_inErrorHandling: true
|
|
1227
|
-
}));
|
|
1296
|
+
const wrappedGetRemoteEntry = (params) => {
|
|
1297
|
+
return getRemoteEntry({ ...params, _inErrorHandling: true });
|
|
1228
1298
|
};
|
|
1229
1299
|
const RemoteEntryExports = await origin.loaderHook.lifecycle.loadEntryError.emit({
|
|
1230
1300
|
getRemoteEntry: wrappedGetRemoteEntry,
|
|
@@ -1232,7 +1302,7 @@ async function getRemoteEntry(params) {
|
|
|
1232
1302
|
remoteInfo: remoteInfo,
|
|
1233
1303
|
remoteEntryExports,
|
|
1234
1304
|
globalLoading,
|
|
1235
|
-
uniqueKey
|
|
1305
|
+
uniqueKey,
|
|
1236
1306
|
});
|
|
1237
1307
|
if (RemoteEntryExports) {
|
|
1238
1308
|
return RemoteEntryExports;
|
|
@@ -1244,32 +1314,35 @@ async function getRemoteEntry(params) {
|
|
|
1244
1314
|
return globalLoading[uniqueKey];
|
|
1245
1315
|
}
|
|
1246
1316
|
function getRemoteInfo(remote) {
|
|
1247
|
-
return
|
|
1317
|
+
return {
|
|
1318
|
+
...remote,
|
|
1248
1319
|
entry: 'entry' in remote ? remote.entry : '',
|
|
1249
1320
|
type: remote.type || DEFAULT_REMOTE_TYPE,
|
|
1250
1321
|
entryGlobalName: remote.entryGlobalName || remote.name,
|
|
1251
|
-
shareScope: remote.shareScope || DEFAULT_SCOPE
|
|
1252
|
-
}
|
|
1322
|
+
shareScope: remote.shareScope || DEFAULT_SCOPE,
|
|
1323
|
+
};
|
|
1253
1324
|
}
|
|
1254
1325
|
|
|
1255
1326
|
function defaultPreloadArgs(preloadConfig) {
|
|
1256
|
-
return
|
|
1327
|
+
return {
|
|
1257
1328
|
resourceCategory: 'sync',
|
|
1258
1329
|
share: true,
|
|
1259
1330
|
depsRemote: true,
|
|
1260
|
-
prefetchInterface: false
|
|
1261
|
-
|
|
1331
|
+
prefetchInterface: false,
|
|
1332
|
+
...preloadConfig,
|
|
1333
|
+
};
|
|
1262
1334
|
}
|
|
1263
1335
|
function formatPreloadArgs(remotes, preloadArgs) {
|
|
1264
|
-
return preloadArgs.map((args)=>{
|
|
1336
|
+
return preloadArgs.map((args) => {
|
|
1265
1337
|
const remoteInfo = matchRemote(remotes, args.nameOrAlias);
|
|
1266
|
-
assert(remoteInfo, `Unable to preload ${args.nameOrAlias} as it is not included in ${!remoteInfo &&
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1338
|
+
assert(remoteInfo, `Unable to preload ${args.nameOrAlias} as it is not included in ${!remoteInfo &&
|
|
1339
|
+
safeToString({
|
|
1340
|
+
remoteInfo,
|
|
1341
|
+
remotes,
|
|
1342
|
+
})}`);
|
|
1270
1343
|
return {
|
|
1271
1344
|
remote: remoteInfo,
|
|
1272
|
-
preloadConfig: defaultPreloadArgs(args)
|
|
1345
|
+
preloadConfig: defaultPreloadArgs(args),
|
|
1273
1346
|
};
|
|
1274
1347
|
});
|
|
1275
1348
|
}
|
|
@@ -1277,7 +1350,7 @@ function normalizePreloadExposes(exposes) {
|
|
|
1277
1350
|
if (!exposes) {
|
|
1278
1351
|
return [];
|
|
1279
1352
|
}
|
|
1280
|
-
return exposes.map((expose)=>{
|
|
1353
|
+
return exposes.map((expose) => {
|
|
1281
1354
|
if (expose === '.') {
|
|
1282
1355
|
return expose;
|
|
1283
1356
|
}
|
|
@@ -1287,75 +1360,78 @@ function normalizePreloadExposes(exposes) {
|
|
|
1287
1360
|
return expose;
|
|
1288
1361
|
});
|
|
1289
1362
|
}
|
|
1290
|
-
function preloadAssets(remoteInfo, host, assets,
|
|
1363
|
+
function preloadAssets(remoteInfo, host, assets,
|
|
1364
|
+
// It is used to distinguish preload from load remote parallel loading
|
|
1291
1365
|
useLinkPreload = true) {
|
|
1292
1366
|
const { cssAssets, jsAssetsWithoutEntry, entryAssets } = assets;
|
|
1293
1367
|
if (host.options.inBrowser) {
|
|
1294
|
-
entryAssets.forEach((asset)=>{
|
|
1368
|
+
entryAssets.forEach((asset) => {
|
|
1295
1369
|
const { moduleInfo } = asset;
|
|
1296
1370
|
const module = host.moduleCache.get(remoteInfo.name);
|
|
1297
1371
|
if (module) {
|
|
1298
1372
|
getRemoteEntry({
|
|
1299
1373
|
origin: host,
|
|
1300
1374
|
remoteInfo: moduleInfo,
|
|
1301
|
-
remoteEntryExports: module.remoteEntryExports
|
|
1375
|
+
remoteEntryExports: module.remoteEntryExports,
|
|
1302
1376
|
});
|
|
1303
|
-
}
|
|
1377
|
+
}
|
|
1378
|
+
else {
|
|
1304
1379
|
getRemoteEntry({
|
|
1305
1380
|
origin: host,
|
|
1306
1381
|
remoteInfo: moduleInfo,
|
|
1307
|
-
remoteEntryExports: undefined
|
|
1382
|
+
remoteEntryExports: undefined,
|
|
1308
1383
|
});
|
|
1309
1384
|
}
|
|
1310
1385
|
});
|
|
1311
1386
|
if (useLinkPreload) {
|
|
1312
1387
|
const defaultAttrs = {
|
|
1313
1388
|
rel: 'preload',
|
|
1314
|
-
as: 'style'
|
|
1389
|
+
as: 'style',
|
|
1315
1390
|
};
|
|
1316
|
-
cssAssets.forEach((cssUrl)=>{
|
|
1391
|
+
cssAssets.forEach((cssUrl) => {
|
|
1317
1392
|
const { link: cssEl, needAttach } = createLink({
|
|
1318
1393
|
url: cssUrl,
|
|
1319
|
-
cb: ()=>{
|
|
1320
|
-
|
|
1394
|
+
cb: () => {
|
|
1395
|
+
// noop
|
|
1321
1396
|
},
|
|
1322
1397
|
attrs: defaultAttrs,
|
|
1323
|
-
createLinkHook: (url, attrs)=>{
|
|
1398
|
+
createLinkHook: (url, attrs) => {
|
|
1324
1399
|
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
1325
1400
|
url,
|
|
1326
|
-
attrs
|
|
1401
|
+
attrs,
|
|
1327
1402
|
});
|
|
1328
1403
|
if (res instanceof HTMLLinkElement) {
|
|
1329
1404
|
return res;
|
|
1330
1405
|
}
|
|
1331
1406
|
return;
|
|
1332
|
-
}
|
|
1407
|
+
},
|
|
1333
1408
|
});
|
|
1334
1409
|
needAttach && document.head.appendChild(cssEl);
|
|
1335
1410
|
});
|
|
1336
|
-
}
|
|
1411
|
+
}
|
|
1412
|
+
else {
|
|
1337
1413
|
const defaultAttrs = {
|
|
1338
1414
|
rel: 'stylesheet',
|
|
1339
|
-
type: 'text/css'
|
|
1415
|
+
type: 'text/css',
|
|
1340
1416
|
};
|
|
1341
|
-
cssAssets.forEach((cssUrl)=>{
|
|
1417
|
+
cssAssets.forEach((cssUrl) => {
|
|
1342
1418
|
const { link: cssEl, needAttach } = createLink({
|
|
1343
1419
|
url: cssUrl,
|
|
1344
|
-
cb: ()=>{
|
|
1345
|
-
|
|
1420
|
+
cb: () => {
|
|
1421
|
+
// noop
|
|
1346
1422
|
},
|
|
1347
1423
|
attrs: defaultAttrs,
|
|
1348
|
-
createLinkHook: (url, attrs)=>{
|
|
1424
|
+
createLinkHook: (url, attrs) => {
|
|
1349
1425
|
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
1350
1426
|
url,
|
|
1351
|
-
attrs
|
|
1427
|
+
attrs,
|
|
1352
1428
|
});
|
|
1353
1429
|
if (res instanceof HTMLLinkElement) {
|
|
1354
1430
|
return res;
|
|
1355
1431
|
}
|
|
1356
1432
|
return;
|
|
1357
1433
|
},
|
|
1358
|
-
needDeleteLink: false
|
|
1434
|
+
needDeleteLink: false,
|
|
1359
1435
|
});
|
|
1360
1436
|
needAttach && document.head.appendChild(cssEl);
|
|
1361
1437
|
});
|
|
@@ -1363,51 +1439,52 @@ useLinkPreload = true) {
|
|
|
1363
1439
|
if (useLinkPreload) {
|
|
1364
1440
|
const defaultAttrs = {
|
|
1365
1441
|
rel: 'preload',
|
|
1366
|
-
as: 'script'
|
|
1442
|
+
as: 'script',
|
|
1367
1443
|
};
|
|
1368
|
-
jsAssetsWithoutEntry.forEach((jsUrl)=>{
|
|
1444
|
+
jsAssetsWithoutEntry.forEach((jsUrl) => {
|
|
1369
1445
|
const { link: linkEl, needAttach } = createLink({
|
|
1370
1446
|
url: jsUrl,
|
|
1371
|
-
cb: ()=>{
|
|
1372
|
-
|
|
1447
|
+
cb: () => {
|
|
1448
|
+
// noop
|
|
1373
1449
|
},
|
|
1374
1450
|
attrs: defaultAttrs,
|
|
1375
|
-
createLinkHook: (url, attrs)=>{
|
|
1451
|
+
createLinkHook: (url, attrs) => {
|
|
1376
1452
|
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
1377
1453
|
url,
|
|
1378
|
-
attrs
|
|
1454
|
+
attrs,
|
|
1379
1455
|
});
|
|
1380
1456
|
if (res instanceof HTMLLinkElement) {
|
|
1381
1457
|
return res;
|
|
1382
1458
|
}
|
|
1383
1459
|
return;
|
|
1384
|
-
}
|
|
1460
|
+
},
|
|
1385
1461
|
});
|
|
1386
1462
|
needAttach && document.head.appendChild(linkEl);
|
|
1387
1463
|
});
|
|
1388
|
-
}
|
|
1464
|
+
}
|
|
1465
|
+
else {
|
|
1389
1466
|
const defaultAttrs = {
|
|
1390
1467
|
fetchpriority: 'high',
|
|
1391
|
-
type:
|
|
1468
|
+
type: remoteInfo?.type === 'module' ? 'module' : 'text/javascript',
|
|
1392
1469
|
};
|
|
1393
|
-
jsAssetsWithoutEntry.forEach((jsUrl)=>{
|
|
1470
|
+
jsAssetsWithoutEntry.forEach((jsUrl) => {
|
|
1394
1471
|
const { script: scriptEl, needAttach } = createScript({
|
|
1395
1472
|
url: jsUrl,
|
|
1396
|
-
cb: ()=>{
|
|
1397
|
-
|
|
1473
|
+
cb: () => {
|
|
1474
|
+
// noop
|
|
1398
1475
|
},
|
|
1399
1476
|
attrs: defaultAttrs,
|
|
1400
|
-
createScriptHook: (url, attrs)=>{
|
|
1477
|
+
createScriptHook: (url, attrs) => {
|
|
1401
1478
|
const res = host.loaderHook.lifecycle.createScript.emit({
|
|
1402
1479
|
url,
|
|
1403
|
-
attrs
|
|
1480
|
+
attrs,
|
|
1404
1481
|
});
|
|
1405
1482
|
if (res instanceof HTMLScriptElement) {
|
|
1406
1483
|
return res;
|
|
1407
1484
|
}
|
|
1408
1485
|
return;
|
|
1409
1486
|
},
|
|
1410
|
-
needDeleteScript: true
|
|
1487
|
+
needDeleteScript: true,
|
|
1411
1488
|
});
|
|
1412
1489
|
needAttach && document.head.appendChild(scriptEl);
|
|
1413
1490
|
});
|
|
@@ -1417,7 +1494,7 @@ useLinkPreload = true) {
|
|
|
1417
1494
|
|
|
1418
1495
|
const ShareUtils = {
|
|
1419
1496
|
getRegisteredShare,
|
|
1420
|
-
getGlobalShareScope
|
|
1497
|
+
getGlobalShareScope,
|
|
1421
1498
|
};
|
|
1422
1499
|
const GlobalUtils = {
|
|
1423
1500
|
Global,
|
|
@@ -1436,7 +1513,7 @@ const GlobalUtils = {
|
|
|
1436
1513
|
registerGlobalPlugins,
|
|
1437
1514
|
getGlobalHostPlugins,
|
|
1438
1515
|
getPreloaded,
|
|
1439
|
-
setPreloaded
|
|
1516
|
+
setPreloaded,
|
|
1440
1517
|
};
|
|
1441
1518
|
var helpers = {
|
|
1442
1519
|
global: GlobalUtils,
|
|
@@ -1444,11 +1521,17 @@ var helpers = {
|
|
|
1444
1521
|
utils: {
|
|
1445
1522
|
matchRemoteWithNameAndExpose,
|
|
1446
1523
|
preloadAssets,
|
|
1447
|
-
getRemoteInfo
|
|
1448
|
-
}
|
|
1524
|
+
getRemoteInfo,
|
|
1525
|
+
},
|
|
1449
1526
|
};
|
|
1450
1527
|
|
|
1451
|
-
|
|
1528
|
+
class Module {
|
|
1529
|
+
constructor({ remoteInfo, host, }) {
|
|
1530
|
+
this.inited = false;
|
|
1531
|
+
this.lib = undefined;
|
|
1532
|
+
this.remoteInfo = remoteInfo;
|
|
1533
|
+
this.host = host;
|
|
1534
|
+
}
|
|
1452
1535
|
async getEntry() {
|
|
1453
1536
|
if (this.remoteEntryExports) {
|
|
1454
1537
|
return this.remoteEntryExports;
|
|
@@ -1457,7 +1540,7 @@ let Module = class Module {
|
|
|
1457
1540
|
remoteEntryExports = await getRemoteEntry({
|
|
1458
1541
|
origin: this.host,
|
|
1459
1542
|
remoteInfo: this.remoteInfo,
|
|
1460
|
-
remoteEntryExports: this.remoteEntryExports
|
|
1543
|
+
remoteEntryExports: this.remoteEntryExports,
|
|
1461
1544
|
});
|
|
1462
1545
|
assert(remoteEntryExports, `remoteEntryExports is undefined \n ${safeToString(this.remoteInfo)}`);
|
|
1463
1546
|
this.remoteEntryExports = remoteEntryExports;
|
|
@@ -1465,20 +1548,18 @@ let Module = class Module {
|
|
|
1465
1548
|
}
|
|
1466
1549
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
1467
1550
|
async get(id, expose, options, remoteSnapshot) {
|
|
1468
|
-
const { loadFactory = true } = options || {
|
|
1469
|
-
loadFactory: true
|
|
1470
|
-
};
|
|
1551
|
+
const { loadFactory = true } = options || { loadFactory: true };
|
|
1471
1552
|
// Get remoteEntry.js
|
|
1472
1553
|
const remoteEntryExports = await this.getEntry();
|
|
1473
1554
|
if (!this.inited) {
|
|
1474
1555
|
const localShareScopeMap = this.host.shareScopeMap;
|
|
1475
|
-
const shareScopeKeys = Array.isArray(this.remoteInfo.shareScope)
|
|
1476
|
-
this.remoteInfo.shareScope
|
|
1477
|
-
|
|
1556
|
+
const shareScopeKeys = Array.isArray(this.remoteInfo.shareScope)
|
|
1557
|
+
? this.remoteInfo.shareScope
|
|
1558
|
+
: [this.remoteInfo.shareScope];
|
|
1478
1559
|
if (!shareScopeKeys.length) {
|
|
1479
1560
|
shareScopeKeys.push('default');
|
|
1480
1561
|
}
|
|
1481
|
-
shareScopeKeys.forEach((shareScopeKey)=>{
|
|
1562
|
+
shareScopeKeys.forEach((shareScopeKey) => {
|
|
1482
1563
|
if (!localShareScopeMap[shareScopeKey]) {
|
|
1483
1564
|
localShareScopeMap[shareScopeKey] = {};
|
|
1484
1565
|
}
|
|
@@ -1488,13 +1569,15 @@ let Module = class Module {
|
|
|
1488
1569
|
const initScope = [];
|
|
1489
1570
|
const remoteEntryInitOptions = {
|
|
1490
1571
|
version: this.remoteInfo.version || '',
|
|
1491
|
-
shareScopeKeys: Array.isArray(this.remoteInfo.shareScope)
|
|
1572
|
+
shareScopeKeys: Array.isArray(this.remoteInfo.shareScope)
|
|
1573
|
+
? shareScopeKeys
|
|
1574
|
+
: this.remoteInfo.shareScope || 'default',
|
|
1492
1575
|
};
|
|
1493
1576
|
// Help to find host instance
|
|
1494
1577
|
Object.defineProperty(remoteEntryInitOptions, 'shareScopeMap', {
|
|
1495
1578
|
value: localShareScopeMap,
|
|
1496
1579
|
// remoteEntryInitOptions will be traversed and assigned during container init, ,so this attribute is not allowed to be traversed
|
|
1497
|
-
enumerable: false
|
|
1580
|
+
enumerable: false,
|
|
1498
1581
|
});
|
|
1499
1582
|
const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
|
|
1500
1583
|
shareScope,
|
|
@@ -1502,22 +1585,23 @@ let Module = class Module {
|
|
|
1502
1585
|
remoteEntryInitOptions,
|
|
1503
1586
|
initScope,
|
|
1504
1587
|
remoteInfo: this.remoteInfo,
|
|
1505
|
-
origin: this.host
|
|
1588
|
+
origin: this.host,
|
|
1506
1589
|
});
|
|
1507
|
-
if (typeof
|
|
1590
|
+
if (typeof remoteEntryExports?.init === 'undefined') {
|
|
1508
1591
|
error(getShortErrorMsg(RUNTIME_002, runtimeDescMap, {
|
|
1509
1592
|
hostName: this.host.name,
|
|
1510
1593
|
remoteName: this.remoteInfo.name,
|
|
1511
1594
|
remoteEntryUrl: this.remoteInfo.entry,
|
|
1512
|
-
remoteEntryKey: this.remoteInfo.entryGlobalName
|
|
1595
|
+
remoteEntryKey: this.remoteInfo.entryGlobalName,
|
|
1513
1596
|
}));
|
|
1514
1597
|
}
|
|
1515
1598
|
await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
|
|
1516
|
-
await this.host.hooks.lifecycle.initContainer.emit(
|
|
1599
|
+
await this.host.hooks.lifecycle.initContainer.emit({
|
|
1600
|
+
...initContainerOptions,
|
|
1517
1601
|
id,
|
|
1518
1602
|
remoteSnapshot,
|
|
1519
|
-
remoteEntryExports
|
|
1520
|
-
})
|
|
1603
|
+
remoteEntryExports,
|
|
1604
|
+
});
|
|
1521
1605
|
}
|
|
1522
1606
|
this.lib = remoteEntryExports;
|
|
1523
1607
|
this.inited = true;
|
|
@@ -1525,7 +1609,7 @@ let Module = class Module {
|
|
|
1525
1609
|
moduleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
|
|
1526
1610
|
remoteEntryExports,
|
|
1527
1611
|
expose,
|
|
1528
|
-
moduleInfo: this.remoteInfo
|
|
1612
|
+
moduleInfo: this.remoteInfo,
|
|
1529
1613
|
});
|
|
1530
1614
|
// get exposeGetter
|
|
1531
1615
|
if (!moduleFactory) {
|
|
@@ -1543,22 +1627,26 @@ let Module = class Module {
|
|
|
1543
1627
|
}
|
|
1544
1628
|
wraperFactory(moduleFactory, id) {
|
|
1545
1629
|
function defineModuleId(res, id) {
|
|
1546
|
-
if (res &&
|
|
1630
|
+
if (res &&
|
|
1631
|
+
typeof res === 'object' &&
|
|
1632
|
+
Object.isExtensible(res) &&
|
|
1633
|
+
!Object.getOwnPropertyDescriptor(res, Symbol.for('mf_module_id'))) {
|
|
1547
1634
|
Object.defineProperty(res, Symbol.for('mf_module_id'), {
|
|
1548
1635
|
value: id,
|
|
1549
|
-
enumerable: false
|
|
1636
|
+
enumerable: false,
|
|
1550
1637
|
});
|
|
1551
1638
|
}
|
|
1552
1639
|
}
|
|
1553
1640
|
if (moduleFactory instanceof Promise) {
|
|
1554
|
-
return async ()=>{
|
|
1641
|
+
return async () => {
|
|
1555
1642
|
const res = await moduleFactory();
|
|
1556
1643
|
// This parameter is used for bridge debugging
|
|
1557
1644
|
defineModuleId(res, id);
|
|
1558
1645
|
return res;
|
|
1559
1646
|
};
|
|
1560
|
-
}
|
|
1561
|
-
|
|
1647
|
+
}
|
|
1648
|
+
else {
|
|
1649
|
+
return () => {
|
|
1562
1650
|
const res = moduleFactory();
|
|
1563
1651
|
// This parameter is used for bridge debugging
|
|
1564
1652
|
defineModuleId(res, id);
|
|
@@ -1566,15 +1654,16 @@ let Module = class Module {
|
|
|
1566
1654
|
};
|
|
1567
1655
|
}
|
|
1568
1656
|
}
|
|
1569
|
-
|
|
1570
|
-
this.inited = false;
|
|
1571
|
-
this.lib = undefined;
|
|
1572
|
-
this.remoteInfo = remoteInfo;
|
|
1573
|
-
this.host = host;
|
|
1574
|
-
}
|
|
1575
|
-
};
|
|
1657
|
+
}
|
|
1576
1658
|
|
|
1577
1659
|
class SyncHook {
|
|
1660
|
+
constructor(type) {
|
|
1661
|
+
this.type = '';
|
|
1662
|
+
this.listeners = new Set();
|
|
1663
|
+
if (type) {
|
|
1664
|
+
this.type = type;
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1578
1667
|
on(fn) {
|
|
1579
1668
|
if (typeof fn === 'function') {
|
|
1580
1669
|
this.listeners.add(fn);
|
|
@@ -1593,7 +1682,7 @@ class SyncHook {
|
|
|
1593
1682
|
let result;
|
|
1594
1683
|
if (this.listeners.size > 0) {
|
|
1595
1684
|
// eslint-disable-next-line prefer-spread
|
|
1596
|
-
this.listeners.forEach((fn)=>{
|
|
1685
|
+
this.listeners.forEach((fn) => {
|
|
1597
1686
|
result = fn(...data);
|
|
1598
1687
|
});
|
|
1599
1688
|
}
|
|
@@ -1605,13 +1694,6 @@ class SyncHook {
|
|
|
1605
1694
|
removeAll() {
|
|
1606
1695
|
this.listeners.clear();
|
|
1607
1696
|
}
|
|
1608
|
-
constructor(type){
|
|
1609
|
-
this.type = '';
|
|
1610
|
-
this.listeners = new Set();
|
|
1611
|
-
if (type) {
|
|
1612
|
-
this.type = type;
|
|
1613
|
-
}
|
|
1614
|
-
}
|
|
1615
1697
|
}
|
|
1616
1698
|
|
|
1617
1699
|
class AsyncHook extends SyncHook {
|
|
@@ -1620,12 +1702,14 @@ class AsyncHook extends SyncHook {
|
|
|
1620
1702
|
const ls = Array.from(this.listeners);
|
|
1621
1703
|
if (ls.length > 0) {
|
|
1622
1704
|
let i = 0;
|
|
1623
|
-
const call = (prev)=>{
|
|
1705
|
+
const call = (prev) => {
|
|
1624
1706
|
if (prev === false) {
|
|
1625
1707
|
return false; // Abort process
|
|
1626
|
-
}
|
|
1708
|
+
}
|
|
1709
|
+
else if (i < ls.length) {
|
|
1627
1710
|
return Promise.resolve(ls[i++].apply(null, data)).then(call);
|
|
1628
|
-
}
|
|
1711
|
+
}
|
|
1712
|
+
else {
|
|
1629
1713
|
return prev;
|
|
1630
1714
|
}
|
|
1631
1715
|
};
|
|
@@ -1642,7 +1726,7 @@ function checkReturnData(originalData, returnedData) {
|
|
|
1642
1726
|
}
|
|
1643
1727
|
if (originalData !== returnedData) {
|
|
1644
1728
|
// eslint-disable-next-line no-restricted-syntax
|
|
1645
|
-
for(const key in originalData){
|
|
1729
|
+
for (const key in originalData) {
|
|
1646
1730
|
if (!(key in returnedData)) {
|
|
1647
1731
|
return false;
|
|
1648
1732
|
}
|
|
@@ -1651,34 +1735,41 @@ function checkReturnData(originalData, returnedData) {
|
|
|
1651
1735
|
return true;
|
|
1652
1736
|
}
|
|
1653
1737
|
class SyncWaterfallHook extends SyncHook {
|
|
1738
|
+
constructor(type) {
|
|
1739
|
+
super();
|
|
1740
|
+
this.onerror = error;
|
|
1741
|
+
this.type = type;
|
|
1742
|
+
}
|
|
1654
1743
|
emit(data) {
|
|
1655
1744
|
if (!isObject(data)) {
|
|
1656
1745
|
error(`The data for the "${this.type}" hook should be an object.`);
|
|
1657
1746
|
}
|
|
1658
|
-
for (const fn of this.listeners){
|
|
1747
|
+
for (const fn of this.listeners) {
|
|
1659
1748
|
try {
|
|
1660
1749
|
const tempData = fn(data);
|
|
1661
1750
|
if (checkReturnData(data, tempData)) {
|
|
1662
1751
|
data = tempData;
|
|
1663
|
-
}
|
|
1752
|
+
}
|
|
1753
|
+
else {
|
|
1664
1754
|
this.onerror(`A plugin returned an unacceptable value for the "${this.type}" type.`);
|
|
1665
1755
|
break;
|
|
1666
1756
|
}
|
|
1667
|
-
}
|
|
1757
|
+
}
|
|
1758
|
+
catch (e) {
|
|
1668
1759
|
warn(e);
|
|
1669
1760
|
this.onerror(e);
|
|
1670
1761
|
}
|
|
1671
1762
|
}
|
|
1672
1763
|
return data;
|
|
1673
1764
|
}
|
|
1674
|
-
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
class AsyncWaterfallHook extends SyncHook {
|
|
1768
|
+
constructor(type) {
|
|
1675
1769
|
super();
|
|
1676
1770
|
this.onerror = error;
|
|
1677
1771
|
this.type = type;
|
|
1678
1772
|
}
|
|
1679
|
-
}
|
|
1680
|
-
|
|
1681
|
-
class AsyncWaterfallHook extends SyncHook {
|
|
1682
1773
|
emit(data) {
|
|
1683
1774
|
if (!isObject(data)) {
|
|
1684
1775
|
error(`The response data for the "${this.type}" hook must be an object.`);
|
|
@@ -1686,22 +1777,24 @@ class AsyncWaterfallHook extends SyncHook {
|
|
|
1686
1777
|
const ls = Array.from(this.listeners);
|
|
1687
1778
|
if (ls.length > 0) {
|
|
1688
1779
|
let i = 0;
|
|
1689
|
-
const processError = (e)=>{
|
|
1780
|
+
const processError = (e) => {
|
|
1690
1781
|
warn(e);
|
|
1691
1782
|
this.onerror(e);
|
|
1692
1783
|
return data;
|
|
1693
1784
|
};
|
|
1694
|
-
const call = (prevData)=>{
|
|
1785
|
+
const call = (prevData) => {
|
|
1695
1786
|
if (checkReturnData(data, prevData)) {
|
|
1696
1787
|
data = prevData;
|
|
1697
1788
|
if (i < ls.length) {
|
|
1698
1789
|
try {
|
|
1699
1790
|
return Promise.resolve(ls[i++](data)).then(call, processError);
|
|
1700
|
-
}
|
|
1791
|
+
}
|
|
1792
|
+
catch (e) {
|
|
1701
1793
|
return processError(e);
|
|
1702
1794
|
}
|
|
1703
1795
|
}
|
|
1704
|
-
}
|
|
1796
|
+
}
|
|
1797
|
+
else {
|
|
1705
1798
|
this.onerror(`A plugin returned an incorrect value for the "${this.type}" type.`);
|
|
1706
1799
|
}
|
|
1707
1800
|
return data;
|
|
@@ -1710,14 +1803,14 @@ class AsyncWaterfallHook extends SyncHook {
|
|
|
1710
1803
|
}
|
|
1711
1804
|
return Promise.resolve(data);
|
|
1712
1805
|
}
|
|
1713
|
-
constructor(type){
|
|
1714
|
-
super();
|
|
1715
|
-
this.onerror = error;
|
|
1716
|
-
this.type = type;
|
|
1717
|
-
}
|
|
1718
1806
|
}
|
|
1719
1807
|
|
|
1720
1808
|
class PluginSystem {
|
|
1809
|
+
constructor(lifecycle) {
|
|
1810
|
+
this.registerPlugins = {};
|
|
1811
|
+
this.lifecycle = lifecycle;
|
|
1812
|
+
this.lifecycleKeys = Object.keys(lifecycle);
|
|
1813
|
+
}
|
|
1721
1814
|
applyPlugin(plugin, instance) {
|
|
1722
1815
|
assert(isPlainObject(plugin), 'Plugin configuration is invalid.');
|
|
1723
1816
|
// The plugin's name is mandatory and must be unique
|
|
@@ -1725,8 +1818,8 @@ class PluginSystem {
|
|
|
1725
1818
|
assert(pluginName, 'A name must be provided by the plugin.');
|
|
1726
1819
|
if (!this.registerPlugins[pluginName]) {
|
|
1727
1820
|
this.registerPlugins[pluginName] = plugin;
|
|
1728
|
-
plugin.apply
|
|
1729
|
-
Object.keys(this.lifecycle).forEach((key)=>{
|
|
1821
|
+
plugin.apply?.(instance);
|
|
1822
|
+
Object.keys(this.lifecycle).forEach((key) => {
|
|
1730
1823
|
const pluginLife = plugin[key];
|
|
1731
1824
|
if (pluginLife) {
|
|
1732
1825
|
this.lifecycle[key].on(pluginLife);
|
|
@@ -1738,17 +1831,12 @@ class PluginSystem {
|
|
|
1738
1831
|
assert(pluginName, 'A name is required.');
|
|
1739
1832
|
const plugin = this.registerPlugins[pluginName];
|
|
1740
1833
|
assert(plugin, `The plugin "${pluginName}" is not registered.`);
|
|
1741
|
-
Object.keys(plugin).forEach((key)=>{
|
|
1834
|
+
Object.keys(plugin).forEach((key) => {
|
|
1742
1835
|
if (key !== 'name') {
|
|
1743
1836
|
this.lifecycle[key].remove(plugin[key]);
|
|
1744
1837
|
}
|
|
1745
1838
|
});
|
|
1746
1839
|
}
|
|
1747
|
-
constructor(lifecycle){
|
|
1748
|
-
this.registerPlugins = {};
|
|
1749
|
-
this.lifecycle = lifecycle;
|
|
1750
|
-
this.lifecycleKeys = Object.keys(lifecycle);
|
|
1751
|
-
}
|
|
1752
1840
|
}
|
|
1753
1841
|
|
|
1754
1842
|
function assignRemoteInfo(remoteInfo, remoteSnapshot) {
|
|
@@ -1769,12 +1857,12 @@ function assignRemoteInfo(remoteInfo, remoteSnapshot) {
|
|
|
1769
1857
|
function snapshotPlugin() {
|
|
1770
1858
|
return {
|
|
1771
1859
|
name: 'snapshot-plugin',
|
|
1772
|
-
async afterResolve
|
|
1860
|
+
async afterResolve(args) {
|
|
1773
1861
|
const { remote, pkgNameOrAlias, expose, origin, remoteInfo, id } = args;
|
|
1774
1862
|
if (!isRemoteInfoWithEntry(remote) || !isPureRemoteEntry(remote)) {
|
|
1775
1863
|
const { remoteSnapshot, globalSnapshot } = await origin.snapshotHandler.loadRemoteSnapshotInfo({
|
|
1776
1864
|
moduleInfo: remote,
|
|
1777
|
-
id
|
|
1865
|
+
id,
|
|
1778
1866
|
});
|
|
1779
1867
|
assignRemoteInfo(remoteInfo, remoteSnapshot);
|
|
1780
1868
|
// preloading assets
|
|
@@ -1782,13 +1870,11 @@ function snapshotPlugin() {
|
|
|
1782
1870
|
remote,
|
|
1783
1871
|
preloadConfig: {
|
|
1784
1872
|
nameOrAlias: pkgNameOrAlias,
|
|
1785
|
-
exposes: [
|
|
1786
|
-
expose
|
|
1787
|
-
],
|
|
1873
|
+
exposes: [expose],
|
|
1788
1874
|
resourceCategory: 'sync',
|
|
1789
1875
|
share: false,
|
|
1790
|
-
depsRemote: false
|
|
1791
|
-
}
|
|
1876
|
+
depsRemote: false,
|
|
1877
|
+
},
|
|
1792
1878
|
};
|
|
1793
1879
|
const assets = await origin.remoteHandler.hooks.lifecycle.generatePreloadAssets.emit({
|
|
1794
1880
|
origin,
|
|
@@ -1796,17 +1882,18 @@ function snapshotPlugin() {
|
|
|
1796
1882
|
remoteInfo,
|
|
1797
1883
|
remote,
|
|
1798
1884
|
remoteSnapshot,
|
|
1799
|
-
globalSnapshot
|
|
1885
|
+
globalSnapshot,
|
|
1800
1886
|
});
|
|
1801
1887
|
if (assets) {
|
|
1802
1888
|
preloadAssets(remoteInfo, origin, assets, false);
|
|
1803
1889
|
}
|
|
1804
|
-
return
|
|
1805
|
-
|
|
1806
|
-
|
|
1890
|
+
return {
|
|
1891
|
+
...args,
|
|
1892
|
+
remoteSnapshot,
|
|
1893
|
+
};
|
|
1807
1894
|
}
|
|
1808
1895
|
return args;
|
|
1809
|
-
}
|
|
1896
|
+
},
|
|
1810
1897
|
};
|
|
1811
1898
|
}
|
|
1812
1899
|
|
|
@@ -1817,17 +1904,19 @@ function splitId(id) {
|
|
|
1817
1904
|
if (splitInfo.length === 1) {
|
|
1818
1905
|
return {
|
|
1819
1906
|
name: splitInfo[0],
|
|
1820
|
-
version: undefined
|
|
1907
|
+
version: undefined,
|
|
1821
1908
|
};
|
|
1822
|
-
}
|
|
1909
|
+
}
|
|
1910
|
+
else if (splitInfo.length === 2) {
|
|
1823
1911
|
return {
|
|
1824
1912
|
name: splitInfo[0],
|
|
1825
|
-
version: splitInfo[1]
|
|
1913
|
+
version: splitInfo[1],
|
|
1826
1914
|
};
|
|
1827
|
-
}
|
|
1915
|
+
}
|
|
1916
|
+
else {
|
|
1828
1917
|
return {
|
|
1829
1918
|
name: splitInfo[1],
|
|
1830
|
-
version: splitInfo[2]
|
|
1919
|
+
version: splitInfo[2],
|
|
1831
1920
|
};
|
|
1832
1921
|
}
|
|
1833
1922
|
}
|
|
@@ -1840,7 +1929,7 @@ function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo =
|
|
|
1840
1929
|
traverse(effectiveRemoteSnapshot, remoteInfo, isRoot);
|
|
1841
1930
|
if (effectiveRemoteSnapshot.remotesInfo) {
|
|
1842
1931
|
const remoteKeys = Object.keys(effectiveRemoteSnapshot.remotesInfo);
|
|
1843
|
-
for (const key of remoteKeys){
|
|
1932
|
+
for (const key of remoteKeys) {
|
|
1844
1933
|
if (memo[key]) {
|
|
1845
1934
|
continue;
|
|
1846
1935
|
}
|
|
@@ -1849,13 +1938,13 @@ function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo =
|
|
|
1849
1938
|
const remoteValue = effectiveRemoteSnapshot.remotesInfo[key];
|
|
1850
1939
|
traverseModuleInfo(globalSnapshot, {
|
|
1851
1940
|
name: subRemoteInfo.name,
|
|
1852
|
-
version: remoteValue.matchedVersion
|
|
1941
|
+
version: remoteValue.matchedVersion,
|
|
1853
1942
|
}, traverse, false, memo, undefined);
|
|
1854
1943
|
}
|
|
1855
1944
|
}
|
|
1856
1945
|
}
|
|
1857
1946
|
}
|
|
1858
|
-
const isExisted = (type, url)=>{
|
|
1947
|
+
const isExisted = (type, url) => {
|
|
1859
1948
|
return document.querySelector(`${type}[${type === 'link' ? 'href' : 'src'}="${url}"]`);
|
|
1860
1949
|
};
|
|
1861
1950
|
// eslint-disable-next-line max-lines-per-function
|
|
@@ -1869,15 +1958,17 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
1869
1958
|
const { preloadConfig: rootPreloadConfig } = preloadOptions;
|
|
1870
1959
|
const { depsRemote } = rootPreloadConfig;
|
|
1871
1960
|
const memo = {};
|
|
1872
|
-
traverseModuleInfo(globalSnapshot, remote, (moduleInfoSnapshot, remoteInfo, isRoot)=>{
|
|
1961
|
+
traverseModuleInfo(globalSnapshot, remote, (moduleInfoSnapshot, remoteInfo, isRoot) => {
|
|
1873
1962
|
let preloadConfig;
|
|
1874
1963
|
if (isRoot) {
|
|
1875
1964
|
preloadConfig = rootPreloadConfig;
|
|
1876
|
-
}
|
|
1965
|
+
}
|
|
1966
|
+
else {
|
|
1877
1967
|
if (Array.isArray(depsRemote)) {
|
|
1878
1968
|
// eslint-disable-next-line array-callback-return
|
|
1879
|
-
const findPreloadConfig = depsRemote.find((remoteConfig)=>{
|
|
1880
|
-
if (remoteConfig.nameOrAlias === remoteInfo.name ||
|
|
1969
|
+
const findPreloadConfig = depsRemote.find((remoteConfig) => {
|
|
1970
|
+
if (remoteConfig.nameOrAlias === remoteInfo.name ||
|
|
1971
|
+
remoteConfig.nameOrAlias === remoteInfo.alias) {
|
|
1881
1972
|
return true;
|
|
1882
1973
|
}
|
|
1883
1974
|
return false;
|
|
@@ -1886,9 +1977,11 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
1886
1977
|
return;
|
|
1887
1978
|
}
|
|
1888
1979
|
preloadConfig = defaultPreloadArgs(findPreloadConfig);
|
|
1889
|
-
}
|
|
1980
|
+
}
|
|
1981
|
+
else if (depsRemote === true) {
|
|
1890
1982
|
preloadConfig = rootPreloadConfig;
|
|
1891
|
-
}
|
|
1983
|
+
}
|
|
1984
|
+
else {
|
|
1892
1985
|
return;
|
|
1893
1986
|
}
|
|
1894
1987
|
}
|
|
@@ -1899,27 +1992,33 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
1899
1992
|
moduleInfo: {
|
|
1900
1993
|
name: remoteInfo.name,
|
|
1901
1994
|
entry: remoteEntryUrl,
|
|
1902
|
-
type: 'remoteEntryType' in moduleInfoSnapshot
|
|
1903
|
-
|
|
1995
|
+
type: 'remoteEntryType' in moduleInfoSnapshot
|
|
1996
|
+
? moduleInfoSnapshot.remoteEntryType
|
|
1997
|
+
: 'global',
|
|
1998
|
+
entryGlobalName: 'globalName' in moduleInfoSnapshot
|
|
1999
|
+
? moduleInfoSnapshot.globalName
|
|
2000
|
+
: remoteInfo.name,
|
|
1904
2001
|
shareScope: '',
|
|
1905
|
-
version: 'version' in moduleInfoSnapshot
|
|
2002
|
+
version: 'version' in moduleInfoSnapshot
|
|
2003
|
+
? moduleInfoSnapshot.version
|
|
2004
|
+
: undefined,
|
|
1906
2005
|
},
|
|
1907
|
-
url: remoteEntryUrl
|
|
2006
|
+
url: remoteEntryUrl,
|
|
1908
2007
|
});
|
|
1909
2008
|
}
|
|
1910
2009
|
let moduleAssetsInfo = 'modules' in moduleInfoSnapshot ? moduleInfoSnapshot.modules : [];
|
|
1911
2010
|
const normalizedPreloadExposes = normalizePreloadExposes(preloadConfig.exposes);
|
|
1912
2011
|
if (normalizedPreloadExposes.length && 'modules' in moduleInfoSnapshot) {
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
2012
|
+
moduleAssetsInfo = moduleInfoSnapshot?.modules?.reduce((assets, moduleAssetInfo) => {
|
|
2013
|
+
if (normalizedPreloadExposes?.indexOf(moduleAssetInfo.moduleName) !==
|
|
2014
|
+
-1) {
|
|
1916
2015
|
assets.push(moduleAssetInfo);
|
|
1917
2016
|
}
|
|
1918
2017
|
return assets;
|
|
1919
2018
|
}, []);
|
|
1920
2019
|
}
|
|
1921
2020
|
function handleAssets(assets) {
|
|
1922
|
-
const assetsRes = assets.map((asset)=>getResourceUrl(moduleInfoSnapshot, asset));
|
|
2021
|
+
const assetsRes = assets.map((asset) => getResourceUrl(moduleInfoSnapshot, asset));
|
|
1923
2022
|
if (preloadConfig.filter) {
|
|
1924
2023
|
return assetsRes.filter(preloadConfig.filter);
|
|
1925
2024
|
}
|
|
@@ -1927,7 +2026,7 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
1927
2026
|
}
|
|
1928
2027
|
if (moduleAssetsInfo) {
|
|
1929
2028
|
const assetsLength = moduleAssetsInfo.length;
|
|
1930
|
-
for(let index = 0; index < assetsLength; index++){
|
|
2029
|
+
for (let index = 0; index < assetsLength; index++) {
|
|
1931
2030
|
const assetsInfo = moduleAssetsInfo[index];
|
|
1932
2031
|
const exposeFullPath = `${remoteInfo.name}/${assetsInfo.moduleName}`;
|
|
1933
2032
|
origin.remoteHandler.hooks.lifecycle.handlePreloadModule.emit({
|
|
@@ -1936,7 +2035,7 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
1936
2035
|
remoteSnapshot: moduleInfoSnapshot,
|
|
1937
2036
|
preloadConfig,
|
|
1938
2037
|
remote: remoteInfo,
|
|
1939
|
-
origin
|
|
2038
|
+
origin,
|
|
1940
2039
|
});
|
|
1941
2040
|
const preloaded = getPreloaded(exposeFullPath);
|
|
1942
2041
|
if (preloaded) {
|
|
@@ -1947,8 +2046,9 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
1947
2046
|
cssAssets.push(...handleAssets(assetsInfo.assets.css.sync));
|
|
1948
2047
|
jsAssets.push(...handleAssets(assetsInfo.assets.js.async));
|
|
1949
2048
|
jsAssets.push(...handleAssets(assetsInfo.assets.js.sync));
|
|
1950
|
-
|
|
1951
|
-
}
|
|
2049
|
+
// eslint-disable-next-line no-constant-condition
|
|
2050
|
+
}
|
|
2051
|
+
else if ((preloadConfig.resourceCategory = 'sync')) {
|
|
1952
2052
|
cssAssets.push(...handleAssets(assetsInfo.assets.css.sync));
|
|
1953
2053
|
jsAssets.push(...handleAssets(assetsInfo.assets.js.sync));
|
|
1954
2054
|
}
|
|
@@ -1957,53 +2057,54 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
1957
2057
|
}
|
|
1958
2058
|
}, true, memo, remoteSnapshot);
|
|
1959
2059
|
if (remoteSnapshot.shared && remoteSnapshot.shared.length > 0) {
|
|
1960
|
-
const collectSharedAssets = (shareInfo, snapshotShared)=>{
|
|
2060
|
+
const collectSharedAssets = (shareInfo, snapshotShared) => {
|
|
1961
2061
|
const registeredShared = getRegisteredShare(origin.shareScopeMap, snapshotShared.sharedName, shareInfo, origin.sharedHandler.hooks.lifecycle.resolveShare);
|
|
1962
2062
|
// If the global share does not exist, or the lib function does not exist, it means that the shared has not been loaded yet and can be preloaded.
|
|
1963
2063
|
if (registeredShared && typeof registeredShared.lib === 'function') {
|
|
1964
|
-
snapshotShared.assets.js.sync.forEach((asset)=>{
|
|
2064
|
+
snapshotShared.assets.js.sync.forEach((asset) => {
|
|
1965
2065
|
loadedSharedJsAssets.add(asset);
|
|
1966
2066
|
});
|
|
1967
|
-
snapshotShared.assets.css.sync.forEach((asset)=>{
|
|
2067
|
+
snapshotShared.assets.css.sync.forEach((asset) => {
|
|
1968
2068
|
loadedSharedCssAssets.add(asset);
|
|
1969
2069
|
});
|
|
1970
2070
|
}
|
|
1971
2071
|
};
|
|
1972
|
-
remoteSnapshot.shared.forEach((shared)=>{
|
|
1973
|
-
|
|
1974
|
-
const shareInfos = (_options_shared = options.shared) == null ? void 0 : _options_shared[shared.sharedName];
|
|
2072
|
+
remoteSnapshot.shared.forEach((shared) => {
|
|
2073
|
+
const shareInfos = options.shared?.[shared.sharedName];
|
|
1975
2074
|
if (!shareInfos) {
|
|
1976
2075
|
return;
|
|
1977
2076
|
}
|
|
1978
2077
|
// if no version, preload all shared
|
|
1979
|
-
const sharedOptions = shared.version
|
|
2078
|
+
const sharedOptions = shared.version
|
|
2079
|
+
? shareInfos.find((s) => s.version === shared.version)
|
|
2080
|
+
: shareInfos;
|
|
1980
2081
|
if (!sharedOptions) {
|
|
1981
2082
|
return;
|
|
1982
2083
|
}
|
|
1983
2084
|
const arrayShareInfo = arrayOptions(sharedOptions);
|
|
1984
|
-
arrayShareInfo.forEach((s)=>{
|
|
2085
|
+
arrayShareInfo.forEach((s) => {
|
|
1985
2086
|
collectSharedAssets(s, shared);
|
|
1986
2087
|
});
|
|
1987
2088
|
});
|
|
1988
2089
|
}
|
|
1989
|
-
const needPreloadJsAssets = jsAssets.filter((asset)
|
|
1990
|
-
const needPreloadCssAssets = cssAssets.filter((asset)
|
|
2090
|
+
const needPreloadJsAssets = jsAssets.filter((asset) => !loadedSharedJsAssets.has(asset) && !isExisted('script', asset));
|
|
2091
|
+
const needPreloadCssAssets = cssAssets.filter((asset) => !loadedSharedCssAssets.has(asset) && !isExisted('link', asset));
|
|
1991
2092
|
return {
|
|
1992
2093
|
cssAssets: needPreloadCssAssets,
|
|
1993
2094
|
jsAssetsWithoutEntry: needPreloadJsAssets,
|
|
1994
|
-
entryAssets: entryAssets.filter((entry)
|
|
2095
|
+
entryAssets: entryAssets.filter((entry) => !isExisted('script', entry.url)),
|
|
1995
2096
|
};
|
|
1996
2097
|
}
|
|
1997
|
-
const generatePreloadAssetsPlugin = function() {
|
|
2098
|
+
const generatePreloadAssetsPlugin = function () {
|
|
1998
2099
|
return {
|
|
1999
2100
|
name: 'generate-preload-assets-plugin',
|
|
2000
|
-
async generatePreloadAssets
|
|
2001
|
-
const { origin, preloadOptions, remoteInfo, remote, globalSnapshot, remoteSnapshot } = args;
|
|
2101
|
+
async generatePreloadAssets(args) {
|
|
2102
|
+
const { origin, preloadOptions, remoteInfo, remote, globalSnapshot, remoteSnapshot, } = args;
|
|
2002
2103
|
if (!isBrowserEnv()) {
|
|
2003
2104
|
return {
|
|
2004
2105
|
cssAssets: [],
|
|
2005
2106
|
jsAssetsWithoutEntry: [],
|
|
2006
|
-
entryAssets: []
|
|
2107
|
+
entryAssets: [],
|
|
2007
2108
|
};
|
|
2008
2109
|
}
|
|
2009
2110
|
if (isRemoteInfoWithEntry(remote) && isPureRemoteEntry(remote)) {
|
|
@@ -2019,34 +2120,37 @@ const generatePreloadAssetsPlugin = function() {
|
|
|
2019
2120
|
entry: remote.entry,
|
|
2020
2121
|
type: remoteInfo.type || 'global',
|
|
2021
2122
|
entryGlobalName: '',
|
|
2022
|
-
shareScope: ''
|
|
2023
|
-
}
|
|
2024
|
-
}
|
|
2025
|
-
]
|
|
2123
|
+
shareScope: '',
|
|
2124
|
+
},
|
|
2125
|
+
},
|
|
2126
|
+
],
|
|
2026
2127
|
};
|
|
2027
2128
|
}
|
|
2028
2129
|
assignRemoteInfo(remoteInfo, remoteSnapshot);
|
|
2029
2130
|
const assets = generatePreloadAssets(origin, preloadOptions, remoteInfo, globalSnapshot, remoteSnapshot);
|
|
2030
2131
|
return assets;
|
|
2031
|
-
}
|
|
2132
|
+
},
|
|
2032
2133
|
};
|
|
2033
2134
|
};
|
|
2034
2135
|
|
|
2035
2136
|
function getGlobalRemoteInfo(moduleInfo, origin) {
|
|
2036
2137
|
const hostGlobalSnapshot = getGlobalSnapshotInfoByModuleInfo({
|
|
2037
2138
|
name: origin.name,
|
|
2038
|
-
version: origin.options.version
|
|
2139
|
+
version: origin.options.version,
|
|
2039
2140
|
});
|
|
2040
2141
|
// get remote detail info from global
|
|
2041
|
-
const globalRemoteInfo = hostGlobalSnapshot &&
|
|
2142
|
+
const globalRemoteInfo = hostGlobalSnapshot &&
|
|
2143
|
+
'remotesInfo' in hostGlobalSnapshot &&
|
|
2144
|
+
hostGlobalSnapshot.remotesInfo &&
|
|
2145
|
+
getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
|
|
2042
2146
|
if (globalRemoteInfo && globalRemoteInfo.matchedVersion) {
|
|
2043
2147
|
return {
|
|
2044
2148
|
hostGlobalSnapshot,
|
|
2045
2149
|
globalSnapshot: getGlobalSnapshot(),
|
|
2046
2150
|
remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
|
|
2047
2151
|
name: moduleInfo.name,
|
|
2048
|
-
version: globalRemoteInfo.matchedVersion
|
|
2049
|
-
})
|
|
2152
|
+
version: globalRemoteInfo.matchedVersion,
|
|
2153
|
+
}),
|
|
2050
2154
|
};
|
|
2051
2155
|
}
|
|
2052
2156
|
return {
|
|
@@ -2054,77 +2158,100 @@ function getGlobalRemoteInfo(moduleInfo, origin) {
|
|
|
2054
2158
|
globalSnapshot: getGlobalSnapshot(),
|
|
2055
2159
|
remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
|
|
2056
2160
|
name: moduleInfo.name,
|
|
2057
|
-
version: 'version' in moduleInfo ? moduleInfo.version : undefined
|
|
2058
|
-
})
|
|
2161
|
+
version: 'version' in moduleInfo ? moduleInfo.version : undefined,
|
|
2162
|
+
}),
|
|
2059
2163
|
};
|
|
2060
2164
|
}
|
|
2061
2165
|
class SnapshotHandler {
|
|
2166
|
+
constructor(HostInstance) {
|
|
2167
|
+
this.loadingHostSnapshot = null;
|
|
2168
|
+
this.manifestCache = new Map();
|
|
2169
|
+
this.hooks = new PluginSystem({
|
|
2170
|
+
beforeLoadRemoteSnapshot: new AsyncHook('beforeLoadRemoteSnapshot'),
|
|
2171
|
+
loadSnapshot: new AsyncWaterfallHook('loadGlobalSnapshot'),
|
|
2172
|
+
loadRemoteSnapshot: new AsyncWaterfallHook('loadRemoteSnapshot'),
|
|
2173
|
+
afterLoadSnapshot: new AsyncWaterfallHook('afterLoadSnapshot'),
|
|
2174
|
+
});
|
|
2175
|
+
this.manifestLoading = Global.__FEDERATION__.__MANIFEST_LOADING__;
|
|
2176
|
+
this.HostInstance = HostInstance;
|
|
2177
|
+
this.loaderHook = HostInstance.loaderHook;
|
|
2178
|
+
}
|
|
2062
2179
|
// eslint-disable-next-line max-lines-per-function
|
|
2063
|
-
async loadRemoteSnapshotInfo({ moduleInfo, id, expose }) {
|
|
2180
|
+
async loadRemoteSnapshotInfo({ moduleInfo, id, expose, }) {
|
|
2064
2181
|
const { options } = this.HostInstance;
|
|
2065
2182
|
await this.hooks.lifecycle.beforeLoadRemoteSnapshot.emit({
|
|
2066
2183
|
options,
|
|
2067
|
-
moduleInfo
|
|
2184
|
+
moduleInfo,
|
|
2068
2185
|
});
|
|
2069
2186
|
let hostSnapshot = getGlobalSnapshotInfoByModuleInfo({
|
|
2070
2187
|
name: this.HostInstance.options.name,
|
|
2071
|
-
version: this.HostInstance.options.version
|
|
2188
|
+
version: this.HostInstance.options.version,
|
|
2072
2189
|
});
|
|
2073
2190
|
if (!hostSnapshot) {
|
|
2074
2191
|
hostSnapshot = {
|
|
2075
2192
|
version: this.HostInstance.options.version || '',
|
|
2076
2193
|
remoteEntry: '',
|
|
2077
|
-
remotesInfo: {}
|
|
2194
|
+
remotesInfo: {},
|
|
2078
2195
|
};
|
|
2079
2196
|
addGlobalSnapshot({
|
|
2080
|
-
[this.HostInstance.options.name]: hostSnapshot
|
|
2197
|
+
[this.HostInstance.options.name]: hostSnapshot,
|
|
2081
2198
|
});
|
|
2082
2199
|
}
|
|
2083
2200
|
// In dynamic loadRemote scenarios, incomplete remotesInfo delivery may occur. In such cases, the remotesInfo in the host needs to be completed in the snapshot at runtime.
|
|
2084
2201
|
// This ensures the snapshot's integrity and helps the chrome plugin correctly identify all producer modules, ensuring that proxyable producer modules will not be missing.
|
|
2085
|
-
if (hostSnapshot &&
|
|
2202
|
+
if (hostSnapshot &&
|
|
2203
|
+
'remotesInfo' in hostSnapshot &&
|
|
2204
|
+
!getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value) {
|
|
2086
2205
|
if ('version' in moduleInfo || 'entry' in moduleInfo) {
|
|
2087
|
-
hostSnapshot.remotesInfo =
|
|
2206
|
+
hostSnapshot.remotesInfo = {
|
|
2207
|
+
...hostSnapshot?.remotesInfo,
|
|
2088
2208
|
[moduleInfo.name]: {
|
|
2089
|
-
matchedVersion: 'version' in moduleInfo ? moduleInfo.version : moduleInfo.entry
|
|
2090
|
-
}
|
|
2091
|
-
}
|
|
2209
|
+
matchedVersion: 'version' in moduleInfo ? moduleInfo.version : moduleInfo.entry,
|
|
2210
|
+
},
|
|
2211
|
+
};
|
|
2092
2212
|
}
|
|
2093
2213
|
}
|
|
2094
2214
|
const { hostGlobalSnapshot, remoteSnapshot, globalSnapshot } = this.getGlobalRemoteInfo(moduleInfo);
|
|
2095
|
-
const { remoteSnapshot: globalRemoteSnapshot, globalSnapshot: globalSnapshotRes } = await this.hooks.lifecycle.loadSnapshot.emit({
|
|
2215
|
+
const { remoteSnapshot: globalRemoteSnapshot, globalSnapshot: globalSnapshotRes, } = await this.hooks.lifecycle.loadSnapshot.emit({
|
|
2096
2216
|
options,
|
|
2097
2217
|
moduleInfo,
|
|
2098
2218
|
hostGlobalSnapshot,
|
|
2099
2219
|
remoteSnapshot,
|
|
2100
|
-
globalSnapshot
|
|
2220
|
+
globalSnapshot,
|
|
2101
2221
|
});
|
|
2102
2222
|
let mSnapshot;
|
|
2103
2223
|
let gSnapshot;
|
|
2104
2224
|
// global snapshot includes manifest or module info includes manifest
|
|
2105
2225
|
if (globalRemoteSnapshot) {
|
|
2106
2226
|
if (isManifestProvider(globalRemoteSnapshot)) {
|
|
2107
|
-
const remoteEntry = isBrowserEnv()
|
|
2227
|
+
const remoteEntry = isBrowserEnv()
|
|
2228
|
+
? globalRemoteSnapshot.remoteEntry
|
|
2229
|
+
: globalRemoteSnapshot.ssrRemoteEntry ||
|
|
2230
|
+
globalRemoteSnapshot.remoteEntry ||
|
|
2231
|
+
'';
|
|
2108
2232
|
const moduleSnapshot = await this.getManifestJson(remoteEntry, moduleInfo, {});
|
|
2109
2233
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
2110
|
-
const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(
|
|
2234
|
+
const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo({
|
|
2235
|
+
...moduleInfo,
|
|
2111
2236
|
// The global remote may be overridden
|
|
2112
2237
|
// Therefore, set the snapshot key to the global address of the actual request
|
|
2113
|
-
entry: remoteEntry
|
|
2114
|
-
}
|
|
2238
|
+
entry: remoteEntry,
|
|
2239
|
+
}, moduleSnapshot);
|
|
2115
2240
|
mSnapshot = moduleSnapshot;
|
|
2116
2241
|
gSnapshot = globalSnapshotRes;
|
|
2117
|
-
}
|
|
2242
|
+
}
|
|
2243
|
+
else {
|
|
2118
2244
|
const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
|
|
2119
2245
|
options: this.HostInstance.options,
|
|
2120
2246
|
moduleInfo,
|
|
2121
2247
|
remoteSnapshot: globalRemoteSnapshot,
|
|
2122
|
-
from: 'global'
|
|
2248
|
+
from: 'global',
|
|
2123
2249
|
});
|
|
2124
2250
|
mSnapshot = remoteSnapshotRes;
|
|
2125
2251
|
gSnapshot = globalSnapshotRes;
|
|
2126
2252
|
}
|
|
2127
|
-
}
|
|
2253
|
+
}
|
|
2254
|
+
else {
|
|
2128
2255
|
if (isRemoteInfoWithEntry(moduleInfo)) {
|
|
2129
2256
|
// get from manifest.json and merge remote info from remote server
|
|
2130
2257
|
const moduleSnapshot = await this.getManifestJson(moduleInfo.entry, moduleInfo, {});
|
|
@@ -2134,15 +2261,16 @@ class SnapshotHandler {
|
|
|
2134
2261
|
options: this.HostInstance.options,
|
|
2135
2262
|
moduleInfo,
|
|
2136
2263
|
remoteSnapshot: moduleSnapshot,
|
|
2137
|
-
from: 'global'
|
|
2264
|
+
from: 'global',
|
|
2138
2265
|
});
|
|
2139
2266
|
mSnapshot = remoteSnapshotRes;
|
|
2140
2267
|
gSnapshot = globalSnapshotRes;
|
|
2141
|
-
}
|
|
2268
|
+
}
|
|
2269
|
+
else {
|
|
2142
2270
|
error(getShortErrorMsg(RUNTIME_007, runtimeDescMap, {
|
|
2143
2271
|
hostName: moduleInfo.name,
|
|
2144
2272
|
hostVersion: moduleInfo.version,
|
|
2145
|
-
globalSnapshot: JSON.stringify(globalSnapshotRes)
|
|
2273
|
+
globalSnapshot: JSON.stringify(globalSnapshotRes),
|
|
2146
2274
|
}));
|
|
2147
2275
|
}
|
|
2148
2276
|
}
|
|
@@ -2151,18 +2279,18 @@ class SnapshotHandler {
|
|
|
2151
2279
|
host: this.HostInstance,
|
|
2152
2280
|
options,
|
|
2153
2281
|
moduleInfo,
|
|
2154
|
-
remoteSnapshot: mSnapshot
|
|
2282
|
+
remoteSnapshot: mSnapshot,
|
|
2155
2283
|
});
|
|
2156
2284
|
return {
|
|
2157
2285
|
remoteSnapshot: mSnapshot,
|
|
2158
|
-
globalSnapshot: gSnapshot
|
|
2286
|
+
globalSnapshot: gSnapshot,
|
|
2159
2287
|
};
|
|
2160
2288
|
}
|
|
2161
2289
|
getGlobalRemoteInfo(moduleInfo) {
|
|
2162
2290
|
return getGlobalRemoteInfo(moduleInfo, this.HostInstance);
|
|
2163
2291
|
}
|
|
2164
2292
|
async getManifestJson(manifestUrl, moduleInfo, extraOptions) {
|
|
2165
|
-
const getManifest = async ()=>{
|
|
2293
|
+
const getManifest = async () => {
|
|
2166
2294
|
let manifestJson = this.manifestCache.get(manifestUrl);
|
|
2167
2295
|
if (manifestJson) {
|
|
2168
2296
|
return manifestJson;
|
|
@@ -2172,21 +2300,23 @@ class SnapshotHandler {
|
|
|
2172
2300
|
if (!res || !(res instanceof Response)) {
|
|
2173
2301
|
res = await fetch(manifestUrl, {});
|
|
2174
2302
|
}
|
|
2175
|
-
manifestJson = await res.json();
|
|
2176
|
-
}
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2303
|
+
manifestJson = (await res.json());
|
|
2304
|
+
}
|
|
2305
|
+
catch (err) {
|
|
2306
|
+
manifestJson =
|
|
2307
|
+
(await this.HostInstance.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
|
|
2308
|
+
id: manifestUrl,
|
|
2309
|
+
error: err,
|
|
2310
|
+
from: 'runtime',
|
|
2311
|
+
lifecycle: 'afterResolve',
|
|
2312
|
+
origin: this.HostInstance,
|
|
2313
|
+
}));
|
|
2184
2314
|
if (!manifestJson) {
|
|
2185
2315
|
delete this.manifestLoading[manifestUrl];
|
|
2186
2316
|
error(getShortErrorMsg(RUNTIME_003, runtimeDescMap, {
|
|
2187
2317
|
manifestUrl,
|
|
2188
2318
|
moduleName: moduleInfo.name,
|
|
2189
|
-
hostName: this.HostInstance.options.name
|
|
2319
|
+
hostName: this.HostInstance.options.name,
|
|
2190
2320
|
}, `${err}`));
|
|
2191
2321
|
}
|
|
2192
2322
|
}
|
|
@@ -2194,10 +2324,10 @@ class SnapshotHandler {
|
|
|
2194
2324
|
this.manifestCache.set(manifestUrl, manifestJson);
|
|
2195
2325
|
return manifestJson;
|
|
2196
2326
|
};
|
|
2197
|
-
const asyncLoadProcess = async ()=>{
|
|
2327
|
+
const asyncLoadProcess = async () => {
|
|
2198
2328
|
const manifestJson = await getManifest();
|
|
2199
2329
|
const remoteSnapshot = generateSnapshotFromManifest(manifestJson, {
|
|
2200
|
-
version: manifestUrl
|
|
2330
|
+
version: manifestUrl,
|
|
2201
2331
|
});
|
|
2202
2332
|
const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
|
|
2203
2333
|
options: this.HostInstance.options,
|
|
@@ -2205,38 +2335,40 @@ class SnapshotHandler {
|
|
|
2205
2335
|
manifestJson,
|
|
2206
2336
|
remoteSnapshot,
|
|
2207
2337
|
manifestUrl,
|
|
2208
|
-
from: 'manifest'
|
|
2338
|
+
from: 'manifest',
|
|
2209
2339
|
});
|
|
2210
2340
|
return remoteSnapshotRes;
|
|
2211
2341
|
};
|
|
2212
2342
|
if (!this.manifestLoading[manifestUrl]) {
|
|
2213
|
-
this.manifestLoading[manifestUrl] = asyncLoadProcess().then((res)=>res);
|
|
2343
|
+
this.manifestLoading[manifestUrl] = asyncLoadProcess().then((res) => res);
|
|
2214
2344
|
}
|
|
2215
2345
|
return this.manifestLoading[manifestUrl];
|
|
2216
2346
|
}
|
|
2217
|
-
constructor(HostInstance){
|
|
2218
|
-
this.loadingHostSnapshot = null;
|
|
2219
|
-
this.manifestCache = new Map();
|
|
2220
|
-
this.hooks = new PluginSystem({
|
|
2221
|
-
beforeLoadRemoteSnapshot: new AsyncHook('beforeLoadRemoteSnapshot'),
|
|
2222
|
-
loadSnapshot: new AsyncWaterfallHook('loadGlobalSnapshot'),
|
|
2223
|
-
loadRemoteSnapshot: new AsyncWaterfallHook('loadRemoteSnapshot'),
|
|
2224
|
-
afterLoadSnapshot: new AsyncWaterfallHook('afterLoadSnapshot')
|
|
2225
|
-
});
|
|
2226
|
-
this.manifestLoading = Global.__FEDERATION__.__MANIFEST_LOADING__;
|
|
2227
|
-
this.HostInstance = HostInstance;
|
|
2228
|
-
this.loaderHook = HostInstance.loaderHook;
|
|
2229
|
-
}
|
|
2230
2347
|
}
|
|
2231
2348
|
|
|
2232
2349
|
class SharedHandler {
|
|
2350
|
+
constructor(host) {
|
|
2351
|
+
this.hooks = new PluginSystem({
|
|
2352
|
+
afterResolve: new AsyncWaterfallHook('afterResolve'),
|
|
2353
|
+
beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
|
|
2354
|
+
// not used yet
|
|
2355
|
+
loadShare: new AsyncHook(),
|
|
2356
|
+
resolveShare: new SyncWaterfallHook('resolveShare'),
|
|
2357
|
+
// maybe will change, temporarily for internal use only
|
|
2358
|
+
initContainerShareScopeMap: new SyncWaterfallHook('initContainerShareScopeMap'),
|
|
2359
|
+
});
|
|
2360
|
+
this.host = host;
|
|
2361
|
+
this.shareScopeMap = {};
|
|
2362
|
+
this.initTokens = {};
|
|
2363
|
+
this._setGlobalShareScopeMap(host.options);
|
|
2364
|
+
}
|
|
2233
2365
|
// register shared in shareScopeMap
|
|
2234
2366
|
registerShared(globalOptions, userOptions) {
|
|
2235
2367
|
const { shareInfos, shared } = formatShareConfigs(globalOptions, userOptions);
|
|
2236
2368
|
const sharedKeys = Object.keys(shareInfos);
|
|
2237
|
-
sharedKeys.forEach((sharedKey)=>{
|
|
2369
|
+
sharedKeys.forEach((sharedKey) => {
|
|
2238
2370
|
const sharedVals = shareInfos[sharedKey];
|
|
2239
|
-
sharedVals.forEach((sharedVal)=>{
|
|
2371
|
+
sharedVals.forEach((sharedVal) => {
|
|
2240
2372
|
const registeredShared = getRegisteredShare(this.shareScopeMap, sharedKey, sharedVal, this.hooks.lifecycle.resolveShare);
|
|
2241
2373
|
if (!registeredShared && sharedVal && sharedVal.lib) {
|
|
2242
2374
|
this.setShared({
|
|
@@ -2245,14 +2377,14 @@ class SharedHandler {
|
|
|
2245
2377
|
get: sharedVal.get,
|
|
2246
2378
|
loaded: true,
|
|
2247
2379
|
shared: sharedVal,
|
|
2248
|
-
from: userOptions.name
|
|
2380
|
+
from: userOptions.name,
|
|
2249
2381
|
});
|
|
2250
2382
|
}
|
|
2251
2383
|
});
|
|
2252
2384
|
});
|
|
2253
2385
|
return {
|
|
2254
2386
|
shareInfos,
|
|
2255
|
-
shared
|
|
2387
|
+
shared,
|
|
2256
2388
|
};
|
|
2257
2389
|
}
|
|
2258
2390
|
async loadShare(pkgName, extraOptions) {
|
|
@@ -2264,12 +2396,12 @@ class SharedHandler {
|
|
|
2264
2396
|
const shareOptions = getTargetSharedOptions({
|
|
2265
2397
|
pkgName,
|
|
2266
2398
|
extraOptions,
|
|
2267
|
-
shareInfos: host.options.shared
|
|
2399
|
+
shareInfos: host.options.shared,
|
|
2268
2400
|
});
|
|
2269
|
-
if (shareOptions
|
|
2270
|
-
await Promise.all(shareOptions.scope.map(async (shareScope)=>{
|
|
2401
|
+
if (shareOptions?.scope) {
|
|
2402
|
+
await Promise.all(shareOptions.scope.map(async (shareScope) => {
|
|
2271
2403
|
await Promise.all(this.initializeSharing(shareScope, {
|
|
2272
|
-
strategy: shareOptions.strategy
|
|
2404
|
+
strategy: shareOptions.strategy,
|
|
2273
2405
|
}));
|
|
2274
2406
|
return;
|
|
2275
2407
|
}));
|
|
@@ -2278,14 +2410,14 @@ class SharedHandler {
|
|
|
2278
2410
|
pkgName,
|
|
2279
2411
|
shareInfo: shareOptions,
|
|
2280
2412
|
shared: host.options.shared,
|
|
2281
|
-
origin: host
|
|
2413
|
+
origin: host,
|
|
2282
2414
|
});
|
|
2283
2415
|
const { shareInfo: shareOptionsRes } = loadShareRes;
|
|
2284
2416
|
// Assert that shareInfoRes exists, if not, throw an error
|
|
2285
2417
|
assert(shareOptionsRes, `Cannot find ${pkgName} Share in the ${host.options.name}. Please ensure that the ${pkgName} Share parameters have been injected`);
|
|
2286
2418
|
// Retrieve from cache
|
|
2287
2419
|
const registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareOptionsRes, this.hooks.lifecycle.resolveShare);
|
|
2288
|
-
const addUseIn = (shared)=>{
|
|
2420
|
+
const addUseIn = (shared) => {
|
|
2289
2421
|
if (!shared.useIn) {
|
|
2290
2422
|
shared.useIn = [];
|
|
2291
2423
|
}
|
|
@@ -2294,7 +2426,10 @@ class SharedHandler {
|
|
|
2294
2426
|
if (registeredShared && registeredShared.lib) {
|
|
2295
2427
|
addUseIn(registeredShared);
|
|
2296
2428
|
return registeredShared.lib;
|
|
2297
|
-
}
|
|
2429
|
+
}
|
|
2430
|
+
else if (registeredShared &&
|
|
2431
|
+
registeredShared.loading &&
|
|
2432
|
+
!registeredShared.loaded) {
|
|
2298
2433
|
const factory = await registeredShared.loading;
|
|
2299
2434
|
registeredShared.loaded = true;
|
|
2300
2435
|
if (!registeredShared.lib) {
|
|
@@ -2302,8 +2437,9 @@ class SharedHandler {
|
|
|
2302
2437
|
}
|
|
2303
2438
|
addUseIn(registeredShared);
|
|
2304
2439
|
return factory;
|
|
2305
|
-
}
|
|
2306
|
-
|
|
2440
|
+
}
|
|
2441
|
+
else if (registeredShared) {
|
|
2442
|
+
const asyncLoadProcess = async () => {
|
|
2307
2443
|
const factory = await registeredShared.get();
|
|
2308
2444
|
addUseIn(registeredShared);
|
|
2309
2445
|
registeredShared.loaded = true;
|
|
@@ -2317,14 +2453,15 @@ class SharedHandler {
|
|
|
2317
2453
|
shared: registeredShared,
|
|
2318
2454
|
from: host.options.name,
|
|
2319
2455
|
lib: null,
|
|
2320
|
-
loading
|
|
2456
|
+
loading,
|
|
2321
2457
|
});
|
|
2322
2458
|
return loading;
|
|
2323
|
-
}
|
|
2324
|
-
|
|
2459
|
+
}
|
|
2460
|
+
else {
|
|
2461
|
+
if (extraOptions?.customShareInfo) {
|
|
2325
2462
|
return false;
|
|
2326
2463
|
}
|
|
2327
|
-
const asyncLoadProcess = async ()=>{
|
|
2464
|
+
const asyncLoadProcess = async () => {
|
|
2328
2465
|
const factory = await shareOptionsRes.get();
|
|
2329
2466
|
shareOptionsRes.lib = factory;
|
|
2330
2467
|
shareOptionsRes.loaded = true;
|
|
@@ -2344,7 +2481,7 @@ class SharedHandler {
|
|
|
2344
2481
|
shared: shareOptionsRes,
|
|
2345
2482
|
from: host.options.name,
|
|
2346
2483
|
lib: null,
|
|
2347
|
-
loading
|
|
2484
|
+
loading,
|
|
2348
2485
|
});
|
|
2349
2486
|
return loading;
|
|
2350
2487
|
}
|
|
@@ -2353,21 +2490,23 @@ class SharedHandler {
|
|
|
2353
2490
|
* This function initializes the sharing sequence (executed only once per share scope).
|
|
2354
2491
|
* It accepts one argument, the name of the share scope.
|
|
2355
2492
|
* If the share scope does not exist, it creates one.
|
|
2356
|
-
*/
|
|
2493
|
+
*/
|
|
2494
|
+
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
2357
2495
|
initializeSharing(shareScopeName = DEFAULT_SCOPE, extraOptions) {
|
|
2358
2496
|
const { host } = this;
|
|
2359
|
-
const from = extraOptions
|
|
2360
|
-
const strategy = extraOptions
|
|
2361
|
-
let initScope = extraOptions
|
|
2497
|
+
const from = extraOptions?.from;
|
|
2498
|
+
const strategy = extraOptions?.strategy;
|
|
2499
|
+
let initScope = extraOptions?.initScope;
|
|
2362
2500
|
const promises = [];
|
|
2363
2501
|
if (from !== 'build') {
|
|
2364
2502
|
const { initTokens } = this;
|
|
2365
|
-
if (!initScope)
|
|
2503
|
+
if (!initScope)
|
|
2504
|
+
initScope = [];
|
|
2366
2505
|
let initToken = initTokens[shareScopeName];
|
|
2367
|
-
if (!initToken)
|
|
2368
|
-
from: this.host.name
|
|
2369
|
-
|
|
2370
|
-
|
|
2506
|
+
if (!initToken)
|
|
2507
|
+
initToken = initTokens[shareScopeName] = { from: this.host.name };
|
|
2508
|
+
if (initScope.indexOf(initToken) >= 0)
|
|
2509
|
+
return promises;
|
|
2371
2510
|
initScope.push(initToken);
|
|
2372
2511
|
}
|
|
2373
2512
|
const shareScope = this.shareScopeMap;
|
|
@@ -2378,34 +2517,41 @@ class SharedHandler {
|
|
|
2378
2517
|
}
|
|
2379
2518
|
// Executes all initialization snippets from all accessible modules
|
|
2380
2519
|
const scope = shareScope[shareScopeName];
|
|
2381
|
-
const register = (name, shared)=>{
|
|
2382
|
-
var _activeVersion_shareConfig;
|
|
2520
|
+
const register = (name, shared) => {
|
|
2383
2521
|
const { version, eager } = shared;
|
|
2384
2522
|
scope[name] = scope[name] || {};
|
|
2385
2523
|
const versions = scope[name];
|
|
2386
2524
|
const activeVersion = versions[version];
|
|
2387
|
-
const activeVersionEager = Boolean(activeVersion &&
|
|
2388
|
-
|
|
2525
|
+
const activeVersionEager = Boolean(activeVersion &&
|
|
2526
|
+
(activeVersion.eager || activeVersion.shareConfig?.eager));
|
|
2527
|
+
if (!activeVersion ||
|
|
2528
|
+
(activeVersion.strategy !== 'loaded-first' &&
|
|
2529
|
+
!activeVersion.loaded &&
|
|
2530
|
+
(Boolean(!eager) !== !activeVersionEager
|
|
2531
|
+
? eager
|
|
2532
|
+
: hostName > activeVersion.from))) {
|
|
2389
2533
|
versions[version] = shared;
|
|
2390
2534
|
}
|
|
2391
2535
|
};
|
|
2392
|
-
const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName], initScope);
|
|
2393
|
-
const initRemoteModule = async (key)=>{
|
|
2536
|
+
const initFn = (mod) => mod && mod.init && mod.init(shareScope[shareScopeName], initScope);
|
|
2537
|
+
const initRemoteModule = async (key) => {
|
|
2394
2538
|
const { module } = await host.remoteHandler.getRemoteModuleAndOptions({
|
|
2395
|
-
id: key
|
|
2539
|
+
id: key,
|
|
2396
2540
|
});
|
|
2397
2541
|
if (module.getEntry) {
|
|
2398
2542
|
let remoteEntryExports;
|
|
2399
2543
|
try {
|
|
2400
2544
|
remoteEntryExports = await module.getEntry();
|
|
2401
|
-
}
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2545
|
+
}
|
|
2546
|
+
catch (error) {
|
|
2547
|
+
remoteEntryExports =
|
|
2548
|
+
(await host.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
|
|
2549
|
+
id: key,
|
|
2550
|
+
error,
|
|
2551
|
+
from: 'runtime',
|
|
2552
|
+
lifecycle: 'beforeLoadShare',
|
|
2553
|
+
origin: host,
|
|
2554
|
+
}));
|
|
2409
2555
|
}
|
|
2410
2556
|
if (!module.inited) {
|
|
2411
2557
|
await initFn(remoteEntryExports);
|
|
@@ -2413,17 +2559,18 @@ class SharedHandler {
|
|
|
2413
2559
|
}
|
|
2414
2560
|
}
|
|
2415
2561
|
};
|
|
2416
|
-
Object.keys(host.options.shared).forEach((shareName)=>{
|
|
2562
|
+
Object.keys(host.options.shared).forEach((shareName) => {
|
|
2417
2563
|
const sharedArr = host.options.shared[shareName];
|
|
2418
|
-
sharedArr.forEach((shared)=>{
|
|
2564
|
+
sharedArr.forEach((shared) => {
|
|
2419
2565
|
if (shared.scope.includes(shareScopeName)) {
|
|
2420
2566
|
register(shareName, shared);
|
|
2421
2567
|
}
|
|
2422
2568
|
});
|
|
2423
2569
|
});
|
|
2424
2570
|
// TODO: strategy==='version-first' need to be removed in the future
|
|
2425
|
-
if (host.options.shareStrategy === 'version-first' ||
|
|
2426
|
-
|
|
2571
|
+
if (host.options.shareStrategy === 'version-first' ||
|
|
2572
|
+
strategy === 'version-first') {
|
|
2573
|
+
host.options.remotes.forEach((remote) => {
|
|
2427
2574
|
if (remote.shareScope === shareScopeName) {
|
|
2428
2575
|
promises.push(initRemoteModule(remote.name));
|
|
2429
2576
|
}
|
|
@@ -2440,17 +2587,15 @@ class SharedHandler {
|
|
|
2440
2587
|
const shareOptions = getTargetSharedOptions({
|
|
2441
2588
|
pkgName,
|
|
2442
2589
|
extraOptions,
|
|
2443
|
-
shareInfos: host.options.shared
|
|
2590
|
+
shareInfos: host.options.shared,
|
|
2444
2591
|
});
|
|
2445
|
-
if (shareOptions
|
|
2446
|
-
shareOptions.scope.forEach((shareScope)=>{
|
|
2447
|
-
this.initializeSharing(shareScope, {
|
|
2448
|
-
strategy: shareOptions.strategy
|
|
2449
|
-
});
|
|
2592
|
+
if (shareOptions?.scope) {
|
|
2593
|
+
shareOptions.scope.forEach((shareScope) => {
|
|
2594
|
+
this.initializeSharing(shareScope, { strategy: shareOptions.strategy });
|
|
2450
2595
|
});
|
|
2451
2596
|
}
|
|
2452
2597
|
const registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareOptions, this.hooks.lifecycle.resolveShare);
|
|
2453
|
-
const addUseIn = (shared)=>{
|
|
2598
|
+
const addUseIn = (shared) => {
|
|
2454
2599
|
if (!shared.useIn) {
|
|
2455
2600
|
shared.useIn = [];
|
|
2456
2601
|
}
|
|
@@ -2476,7 +2621,7 @@ class SharedHandler {
|
|
|
2476
2621
|
loaded: true,
|
|
2477
2622
|
from: host.options.name,
|
|
2478
2623
|
lib: module,
|
|
2479
|
-
shared: registeredShared
|
|
2624
|
+
shared: registeredShared,
|
|
2480
2625
|
});
|
|
2481
2626
|
return module;
|
|
2482
2627
|
}
|
|
@@ -2491,10 +2636,10 @@ class SharedHandler {
|
|
|
2491
2636
|
if (shareOptions.get) {
|
|
2492
2637
|
const module = shareOptions.get();
|
|
2493
2638
|
if (module instanceof Promise) {
|
|
2494
|
-
const errorCode =
|
|
2639
|
+
const errorCode = extraOptions?.from === 'build' ? RUNTIME_005 : RUNTIME_006;
|
|
2495
2640
|
throw new Error(getShortErrorMsg(errorCode, runtimeDescMap, {
|
|
2496
2641
|
hostName: host.options.name,
|
|
2497
|
-
sharedPkgName: pkgName
|
|
2642
|
+
sharedPkgName: pkgName,
|
|
2498
2643
|
}));
|
|
2499
2644
|
}
|
|
2500
2645
|
shareOptions.lib = module;
|
|
@@ -2503,13 +2648,13 @@ class SharedHandler {
|
|
|
2503
2648
|
loaded: true,
|
|
2504
2649
|
from: host.options.name,
|
|
2505
2650
|
lib: shareOptions.lib,
|
|
2506
|
-
shared: shareOptions
|
|
2651
|
+
shared: shareOptions,
|
|
2507
2652
|
});
|
|
2508
2653
|
return shareOptions.lib;
|
|
2509
2654
|
}
|
|
2510
2655
|
throw new Error(getShortErrorMsg(RUNTIME_006, runtimeDescMap, {
|
|
2511
2656
|
hostName: host.options.name,
|
|
2512
|
-
sharedPkgName: pkgName
|
|
2657
|
+
sharedPkgName: pkgName,
|
|
2513
2658
|
}));
|
|
2514
2659
|
}
|
|
2515
2660
|
initShareScopeMap(scopeName, shareScope, extraOptions = {}) {
|
|
@@ -2520,18 +2665,13 @@ class SharedHandler {
|
|
|
2520
2665
|
options: host.options,
|
|
2521
2666
|
origin: host,
|
|
2522
2667
|
scopeName,
|
|
2523
|
-
hostShareScopeMap: extraOptions.hostShareScopeMap
|
|
2668
|
+
hostShareScopeMap: extraOptions.hostShareScopeMap,
|
|
2524
2669
|
});
|
|
2525
2670
|
}
|
|
2526
|
-
setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
|
|
2527
|
-
const { version, scope = 'default'
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
]);
|
|
2531
|
-
const scopes = Array.isArray(scope) ? scope : [
|
|
2532
|
-
scope
|
|
2533
|
-
];
|
|
2534
|
-
scopes.forEach((sc)=>{
|
|
2671
|
+
setShared({ pkgName, shared, from, lib, loading, loaded, get, }) {
|
|
2672
|
+
const { version, scope = 'default', ...shareInfo } = shared;
|
|
2673
|
+
const scopes = Array.isArray(scope) ? scope : [scope];
|
|
2674
|
+
scopes.forEach((sc) => {
|
|
2535
2675
|
if (!this.shareScopeMap[sc]) {
|
|
2536
2676
|
this.shareScopeMap[sc] = {};
|
|
2537
2677
|
}
|
|
@@ -2539,16 +2679,14 @@ class SharedHandler {
|
|
|
2539
2679
|
this.shareScopeMap[sc][pkgName] = {};
|
|
2540
2680
|
}
|
|
2541
2681
|
if (!this.shareScopeMap[sc][pkgName][version]) {
|
|
2542
|
-
this.shareScopeMap[sc][pkgName][version] =
|
|
2682
|
+
this.shareScopeMap[sc][pkgName][version] = {
|
|
2543
2683
|
version,
|
|
2544
|
-
scope: [
|
|
2545
|
-
|
|
2546
|
-
]
|
|
2547
|
-
}, shareInfo, {
|
|
2684
|
+
scope: ['default'],
|
|
2685
|
+
...shareInfo,
|
|
2548
2686
|
lib,
|
|
2549
2687
|
loaded,
|
|
2550
|
-
loading
|
|
2551
|
-
}
|
|
2688
|
+
loading,
|
|
2689
|
+
};
|
|
2552
2690
|
if (get) {
|
|
2553
2691
|
this.shareScopeMap[sc][pkgName][version].get = get;
|
|
2554
2692
|
}
|
|
@@ -2573,54 +2711,45 @@ class SharedHandler {
|
|
|
2573
2711
|
globalShareScopeMap[identifier] = this.shareScopeMap;
|
|
2574
2712
|
}
|
|
2575
2713
|
}
|
|
2576
|
-
|
|
2714
|
+
}
|
|
2715
|
+
|
|
2716
|
+
class RemoteHandler {
|
|
2717
|
+
constructor(host) {
|
|
2577
2718
|
this.hooks = new PluginSystem({
|
|
2578
|
-
|
|
2579
|
-
|
|
2719
|
+
beforeRegisterRemote: new SyncWaterfallHook('beforeRegisterRemote'),
|
|
2720
|
+
registerRemote: new SyncWaterfallHook('registerRemote'),
|
|
2721
|
+
beforeRequest: new AsyncWaterfallHook('beforeRequest'),
|
|
2722
|
+
onLoad: new AsyncHook('onLoad'),
|
|
2723
|
+
handlePreloadModule: new SyncHook('handlePreloadModule'),
|
|
2724
|
+
errorLoadRemote: new AsyncHook('errorLoadRemote'),
|
|
2725
|
+
beforePreloadRemote: new AsyncHook('beforePreloadRemote'),
|
|
2726
|
+
generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
|
|
2580
2727
|
// not used yet
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
// maybe will change, temporarily for internal use only
|
|
2584
|
-
initContainerShareScopeMap: new SyncWaterfallHook('initContainerShareScopeMap')
|
|
2728
|
+
afterPreloadRemote: new AsyncHook(),
|
|
2729
|
+
loadEntry: new AsyncHook(),
|
|
2585
2730
|
});
|
|
2586
2731
|
this.host = host;
|
|
2587
|
-
this.
|
|
2588
|
-
this.initTokens = {};
|
|
2589
|
-
this._setGlobalShareScopeMap(host.options);
|
|
2732
|
+
this.idToRemoteMap = {};
|
|
2590
2733
|
}
|
|
2591
|
-
}
|
|
2592
|
-
|
|
2593
|
-
class RemoteHandler {
|
|
2594
2734
|
formatAndRegisterRemote(globalOptions, userOptions) {
|
|
2595
2735
|
const userRemotes = userOptions.remotes || [];
|
|
2596
|
-
return userRemotes.reduce((res, remote)=>{
|
|
2597
|
-
this.registerRemote(remote, res, {
|
|
2598
|
-
force: false
|
|
2599
|
-
});
|
|
2736
|
+
return userRemotes.reduce((res, remote) => {
|
|
2737
|
+
this.registerRemote(remote, res, { force: false });
|
|
2600
2738
|
return res;
|
|
2601
2739
|
}, globalOptions.remotes);
|
|
2602
2740
|
}
|
|
2603
2741
|
setIdToRemoteMap(id, remoteMatchInfo) {
|
|
2604
2742
|
const { remote, expose } = remoteMatchInfo;
|
|
2605
2743
|
const { name, alias } = remote;
|
|
2606
|
-
this.idToRemoteMap[id] = {
|
|
2607
|
-
name: remote.name,
|
|
2608
|
-
expose
|
|
2609
|
-
};
|
|
2744
|
+
this.idToRemoteMap[id] = { name: remote.name, expose };
|
|
2610
2745
|
if (alias && id.startsWith(name)) {
|
|
2611
2746
|
const idWithAlias = id.replace(name, alias);
|
|
2612
|
-
this.idToRemoteMap[idWithAlias] = {
|
|
2613
|
-
name: remote.name,
|
|
2614
|
-
expose
|
|
2615
|
-
};
|
|
2747
|
+
this.idToRemoteMap[idWithAlias] = { name: remote.name, expose };
|
|
2616
2748
|
return;
|
|
2617
2749
|
}
|
|
2618
2750
|
if (alias && id.startsWith(alias)) {
|
|
2619
2751
|
const idWithName = id.replace(alias, name);
|
|
2620
|
-
this.idToRemoteMap[idWithName] = {
|
|
2621
|
-
name: remote.name,
|
|
2622
|
-
expose
|
|
2623
|
-
};
|
|
2752
|
+
this.idToRemoteMap[idWithName] = { name: remote.name, expose };
|
|
2624
2753
|
}
|
|
2625
2754
|
}
|
|
2626
2755
|
// eslint-disable-next-line max-lines-per-function
|
|
@@ -2629,7 +2758,7 @@ class RemoteHandler {
|
|
|
2629
2758
|
const { host } = this;
|
|
2630
2759
|
try {
|
|
2631
2760
|
const { loadFactory = true } = options || {
|
|
2632
|
-
loadFactory: true
|
|
2761
|
+
loadFactory: true,
|
|
2633
2762
|
};
|
|
2634
2763
|
// 1. Validate the parameters of the retrieved module. There are two module request methods: pkgName + expose and alias + expose.
|
|
2635
2764
|
// 2. Request the snapshot information of the current host and globally store the obtained snapshot information. The retrieved module information is partially offline and partially online. The online module information will retrieve the modules used online.
|
|
@@ -2639,10 +2768,10 @@ class RemoteHandler {
|
|
|
2639
2768
|
// id: alias(app1) + expose(button) = app1/button
|
|
2640
2769
|
// id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort
|
|
2641
2770
|
const { module, moduleOptions, remoteMatchInfo } = await this.getRemoteModuleAndOptions({
|
|
2642
|
-
id
|
|
2771
|
+
id,
|
|
2643
2772
|
});
|
|
2644
|
-
const { pkgNameOrAlias, remote, expose, id: idRes, remoteSnapshot } = remoteMatchInfo;
|
|
2645
|
-
const moduleOrFactory = await module.get(idRes, expose, options, remoteSnapshot);
|
|
2773
|
+
const { pkgNameOrAlias, remote, expose, id: idRes, remoteSnapshot, } = remoteMatchInfo;
|
|
2774
|
+
const moduleOrFactory = (await module.get(idRes, expose, options, remoteSnapshot));
|
|
2646
2775
|
const moduleWrapper = await this.hooks.lifecycle.onLoad.emit({
|
|
2647
2776
|
id: idRes,
|
|
2648
2777
|
pkgNameOrAlias,
|
|
@@ -2652,23 +2781,22 @@ class RemoteHandler {
|
|
|
2652
2781
|
remote,
|
|
2653
2782
|
options: moduleOptions,
|
|
2654
2783
|
moduleInstance: module,
|
|
2655
|
-
origin: host
|
|
2784
|
+
origin: host,
|
|
2656
2785
|
});
|
|
2657
2786
|
this.setIdToRemoteMap(id, remoteMatchInfo);
|
|
2658
2787
|
if (typeof moduleWrapper === 'function') {
|
|
2659
2788
|
return moduleWrapper;
|
|
2660
2789
|
}
|
|
2661
2790
|
return moduleOrFactory;
|
|
2662
|
-
}
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
};
|
|
2791
|
+
}
|
|
2792
|
+
catch (error) {
|
|
2793
|
+
const { from = 'runtime' } = options || { from: 'runtime' };
|
|
2666
2794
|
const failOver = await this.hooks.lifecycle.errorLoadRemote.emit({
|
|
2667
2795
|
id,
|
|
2668
2796
|
error,
|
|
2669
2797
|
from,
|
|
2670
2798
|
lifecycle: 'onLoad',
|
|
2671
|
-
origin: host
|
|
2799
|
+
origin: host,
|
|
2672
2800
|
});
|
|
2673
2801
|
if (!failOver) {
|
|
2674
2802
|
throw error;
|
|
@@ -2682,14 +2810,14 @@ class RemoteHandler {
|
|
|
2682
2810
|
await this.hooks.lifecycle.beforePreloadRemote.emit({
|
|
2683
2811
|
preloadOps: preloadOptions,
|
|
2684
2812
|
options: host.options,
|
|
2685
|
-
origin: host
|
|
2813
|
+
origin: host,
|
|
2686
2814
|
});
|
|
2687
2815
|
const preloadOps = formatPreloadArgs(host.options.remotes, preloadOptions);
|
|
2688
|
-
await Promise.all(preloadOps.map(async (ops)=>{
|
|
2816
|
+
await Promise.all(preloadOps.map(async (ops) => {
|
|
2689
2817
|
const { remote } = ops;
|
|
2690
2818
|
const remoteInfo = getRemoteInfo(remote);
|
|
2691
2819
|
const { globalSnapshot, remoteSnapshot } = await host.snapshotHandler.loadRemoteSnapshotInfo({
|
|
2692
|
-
moduleInfo: remote
|
|
2820
|
+
moduleInfo: remote,
|
|
2693
2821
|
});
|
|
2694
2822
|
const assets = await this.hooks.lifecycle.generatePreloadAssets.emit({
|
|
2695
2823
|
origin: host,
|
|
@@ -2697,7 +2825,7 @@ class RemoteHandler {
|
|
|
2697
2825
|
remote,
|
|
2698
2826
|
remoteInfo,
|
|
2699
2827
|
globalSnapshot,
|
|
2700
|
-
remoteSnapshot
|
|
2828
|
+
remoteSnapshot,
|
|
2701
2829
|
});
|
|
2702
2830
|
if (!assets) {
|
|
2703
2831
|
return;
|
|
@@ -2707,9 +2835,9 @@ class RemoteHandler {
|
|
|
2707
2835
|
}
|
|
2708
2836
|
registerRemotes(remotes, options) {
|
|
2709
2837
|
const { host } = this;
|
|
2710
|
-
remotes.forEach((remote)=>{
|
|
2838
|
+
remotes.forEach((remote) => {
|
|
2711
2839
|
this.registerRemote(remote, host.options.remotes, {
|
|
2712
|
-
force: options
|
|
2840
|
+
force: options?.force,
|
|
2713
2841
|
});
|
|
2714
2842
|
});
|
|
2715
2843
|
}
|
|
@@ -2721,17 +2849,18 @@ class RemoteHandler {
|
|
|
2721
2849
|
loadRemoteArgs = await this.hooks.lifecycle.beforeRequest.emit({
|
|
2722
2850
|
id,
|
|
2723
2851
|
options: host.options,
|
|
2724
|
-
origin: host
|
|
2852
|
+
origin: host,
|
|
2725
2853
|
});
|
|
2726
|
-
}
|
|
2727
|
-
|
|
2854
|
+
}
|
|
2855
|
+
catch (error) {
|
|
2856
|
+
loadRemoteArgs = (await this.hooks.lifecycle.errorLoadRemote.emit({
|
|
2728
2857
|
id,
|
|
2729
2858
|
options: host.options,
|
|
2730
2859
|
origin: host,
|
|
2731
2860
|
from: 'runtime',
|
|
2732
2861
|
error,
|
|
2733
|
-
lifecycle: 'beforeRequest'
|
|
2734
|
-
});
|
|
2862
|
+
lifecycle: 'beforeRequest',
|
|
2863
|
+
}));
|
|
2735
2864
|
if (!loadRemoteArgs) {
|
|
2736
2865
|
throw error;
|
|
2737
2866
|
}
|
|
@@ -2740,23 +2869,23 @@ class RemoteHandler {
|
|
|
2740
2869
|
const remoteSplitInfo = matchRemoteWithNameAndExpose(host.options.remotes, idRes);
|
|
2741
2870
|
assert(remoteSplitInfo, getShortErrorMsg(RUNTIME_004, runtimeDescMap, {
|
|
2742
2871
|
hostName: host.options.name,
|
|
2743
|
-
requestId: idRes
|
|
2872
|
+
requestId: idRes,
|
|
2744
2873
|
}));
|
|
2745
2874
|
const { remote: rawRemote } = remoteSplitInfo;
|
|
2746
2875
|
const remoteInfo = getRemoteInfo(rawRemote);
|
|
2747
|
-
const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit(
|
|
2748
|
-
id: idRes
|
|
2749
|
-
|
|
2876
|
+
const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit({
|
|
2877
|
+
id: idRes,
|
|
2878
|
+
...remoteSplitInfo,
|
|
2750
2879
|
options: host.options,
|
|
2751
2880
|
origin: host,
|
|
2752
|
-
remoteInfo
|
|
2753
|
-
})
|
|
2881
|
+
remoteInfo,
|
|
2882
|
+
});
|
|
2754
2883
|
const { remote, expose } = matchInfo;
|
|
2755
2884
|
assert(remote && expose, `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`);
|
|
2756
2885
|
let module = host.moduleCache.get(remote.name);
|
|
2757
2886
|
const moduleOptions = {
|
|
2758
2887
|
host: host,
|
|
2759
|
-
remoteInfo
|
|
2888
|
+
remoteInfo,
|
|
2760
2889
|
};
|
|
2761
2890
|
if (!module) {
|
|
2762
2891
|
module = new Module(moduleOptions);
|
|
@@ -2765,19 +2894,18 @@ class RemoteHandler {
|
|
|
2765
2894
|
return {
|
|
2766
2895
|
module,
|
|
2767
2896
|
moduleOptions,
|
|
2768
|
-
remoteMatchInfo: matchInfo
|
|
2897
|
+
remoteMatchInfo: matchInfo,
|
|
2769
2898
|
};
|
|
2770
2899
|
}
|
|
2771
2900
|
registerRemote(remote, targetRemotes, options) {
|
|
2772
2901
|
const { host } = this;
|
|
2773
|
-
const normalizeRemote = ()=>{
|
|
2902
|
+
const normalizeRemote = () => {
|
|
2774
2903
|
if (remote.alias) {
|
|
2775
2904
|
// Validate if alias equals the prefix of remote.name and remote.alias, if so, throw an error
|
|
2776
2905
|
// As multi-level path references cannot guarantee unique names, alias being a prefix of remote.name is not supported
|
|
2777
|
-
const findEqual = targetRemotes.find((item)=>
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
});
|
|
2906
|
+
const findEqual = targetRemotes.find((item) => remote.alias &&
|
|
2907
|
+
(item.name.startsWith(remote.alias) ||
|
|
2908
|
+
item.alias?.startsWith(remote.alias)));
|
|
2781
2909
|
assert(!findEqual, `The alias ${remote.alias} of remote ${remote.name} is not allowed to be the prefix of ${findEqual && findEqual.name} name or alias`);
|
|
2782
2910
|
}
|
|
2783
2911
|
// Set the remote entry to a complete path
|
|
@@ -2793,32 +2921,24 @@ class RemoteHandler {
|
|
|
2793
2921
|
remote.type = DEFAULT_REMOTE_TYPE;
|
|
2794
2922
|
}
|
|
2795
2923
|
};
|
|
2796
|
-
this.hooks.lifecycle.beforeRegisterRemote.emit({
|
|
2797
|
-
|
|
2798
|
-
origin: host
|
|
2799
|
-
});
|
|
2800
|
-
const registeredRemote = targetRemotes.find((item)=>item.name === remote.name);
|
|
2924
|
+
this.hooks.lifecycle.beforeRegisterRemote.emit({ remote, origin: host });
|
|
2925
|
+
const registeredRemote = targetRemotes.find((item) => item.name === remote.name);
|
|
2801
2926
|
if (!registeredRemote) {
|
|
2802
2927
|
normalizeRemote();
|
|
2803
2928
|
targetRemotes.push(remote);
|
|
2804
|
-
this.hooks.lifecycle.registerRemote.emit({
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
});
|
|
2808
|
-
} else {
|
|
2929
|
+
this.hooks.lifecycle.registerRemote.emit({ remote, origin: host });
|
|
2930
|
+
}
|
|
2931
|
+
else {
|
|
2809
2932
|
const messages = [
|
|
2810
2933
|
`The remote "${remote.name}" is already registered.`,
|
|
2811
|
-
'Please note that overriding it may cause unexpected errors.'
|
|
2934
|
+
'Please note that overriding it may cause unexpected errors.',
|
|
2812
2935
|
];
|
|
2813
|
-
if (options
|
|
2936
|
+
if (options?.force) {
|
|
2814
2937
|
// remove registered remote
|
|
2815
2938
|
this.removeRemote(registeredRemote);
|
|
2816
2939
|
normalizeRemote();
|
|
2817
2940
|
targetRemotes.push(remote);
|
|
2818
|
-
this.hooks.lifecycle.registerRemote.emit({
|
|
2819
|
-
remote,
|
|
2820
|
-
origin: host
|
|
2821
|
-
});
|
|
2941
|
+
this.hooks.lifecycle.registerRemote.emit({ remote, origin: host });
|
|
2822
2942
|
warn$1(messages.join(' '));
|
|
2823
2943
|
}
|
|
2824
2944
|
}
|
|
@@ -2827,7 +2947,7 @@ class RemoteHandler {
|
|
|
2827
2947
|
try {
|
|
2828
2948
|
const { host } = this;
|
|
2829
2949
|
const { name } = remote;
|
|
2830
|
-
const remoteIndex = host.options.remotes.findIndex((item)=>item.name === name);
|
|
2950
|
+
const remoteIndex = host.options.remotes.findIndex((item) => item.name === name);
|
|
2831
2951
|
if (remoteIndex !== -1) {
|
|
2832
2952
|
host.options.remotes.splice(remoteIndex, 1);
|
|
2833
2953
|
}
|
|
@@ -2836,10 +2956,10 @@ class RemoteHandler {
|
|
|
2836
2956
|
const remoteInfo = loadedModule.remoteInfo;
|
|
2837
2957
|
const key = remoteInfo.entryGlobalName;
|
|
2838
2958
|
if (CurrentGlobal[key]) {
|
|
2839
|
-
|
|
2840
|
-
if ((_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(CurrentGlobal, key)) == null ? void 0 : _Object_getOwnPropertyDescriptor.configurable) {
|
|
2959
|
+
if (Object.getOwnPropertyDescriptor(CurrentGlobal, key)?.configurable) {
|
|
2841
2960
|
delete CurrentGlobal[key];
|
|
2842
|
-
}
|
|
2961
|
+
}
|
|
2962
|
+
else {
|
|
2843
2963
|
// @ts-ignore
|
|
2844
2964
|
CurrentGlobal[key] = undefined;
|
|
2845
2965
|
}
|
|
@@ -2850,11 +2970,14 @@ class RemoteHandler {
|
|
|
2850
2970
|
}
|
|
2851
2971
|
host.snapshotHandler.manifestCache.delete(remoteInfo.entry);
|
|
2852
2972
|
// delete unloaded shared and instance
|
|
2853
|
-
let remoteInsId = remoteInfo.buildVersion
|
|
2854
|
-
|
|
2973
|
+
let remoteInsId = remoteInfo.buildVersion
|
|
2974
|
+
? composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion)
|
|
2975
|
+
: remoteInfo.name;
|
|
2976
|
+
const remoteInsIndex = CurrentGlobal.__FEDERATION__.__INSTANCES__.findIndex((ins) => {
|
|
2855
2977
|
if (remoteInfo.buildVersion) {
|
|
2856
2978
|
return ins.options.id === remoteInsId;
|
|
2857
|
-
}
|
|
2979
|
+
}
|
|
2980
|
+
else {
|
|
2858
2981
|
return ins.name === remoteInsId;
|
|
2859
2982
|
}
|
|
2860
2983
|
});
|
|
@@ -2864,56 +2987,66 @@ class RemoteHandler {
|
|
|
2864
2987
|
const globalShareScopeMap = getGlobalShareScope();
|
|
2865
2988
|
let isAllSharedNotUsed = true;
|
|
2866
2989
|
const needDeleteKeys = [];
|
|
2867
|
-
Object.keys(globalShareScopeMap).forEach((instId)=>{
|
|
2990
|
+
Object.keys(globalShareScopeMap).forEach((instId) => {
|
|
2868
2991
|
const shareScopeMap = globalShareScopeMap[instId];
|
|
2869
|
-
shareScopeMap &&
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2992
|
+
shareScopeMap &&
|
|
2993
|
+
Object.keys(shareScopeMap).forEach((shareScope) => {
|
|
2994
|
+
const shareScopeVal = shareScopeMap[shareScope];
|
|
2995
|
+
shareScopeVal &&
|
|
2996
|
+
Object.keys(shareScopeVal).forEach((shareName) => {
|
|
2997
|
+
const sharedPkgs = shareScopeVal[shareName];
|
|
2998
|
+
sharedPkgs &&
|
|
2999
|
+
Object.keys(sharedPkgs).forEach((shareVersion) => {
|
|
3000
|
+
const shared = sharedPkgs[shareVersion];
|
|
3001
|
+
if (shared &&
|
|
3002
|
+
typeof shared === 'object' &&
|
|
3003
|
+
shared.from === remoteInfo.name) {
|
|
3004
|
+
if (shared.loaded || shared.loading) {
|
|
3005
|
+
shared.useIn = shared.useIn.filter((usedHostName) => usedHostName !== remoteInfo.name);
|
|
3006
|
+
if (shared.useIn.length) {
|
|
3007
|
+
isAllSharedNotUsed = false;
|
|
3008
|
+
}
|
|
3009
|
+
else {
|
|
3010
|
+
needDeleteKeys.push([
|
|
3011
|
+
instId,
|
|
3012
|
+
shareScope,
|
|
3013
|
+
shareName,
|
|
3014
|
+
shareVersion,
|
|
3015
|
+
]);
|
|
3016
|
+
}
|
|
3017
|
+
}
|
|
3018
|
+
else {
|
|
3019
|
+
needDeleteKeys.push([
|
|
3020
|
+
instId,
|
|
3021
|
+
shareScope,
|
|
3022
|
+
shareName,
|
|
3023
|
+
shareVersion,
|
|
3024
|
+
]);
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
});
|
|
3028
|
+
});
|
|
2898
3029
|
});
|
|
2899
|
-
});
|
|
2900
3030
|
});
|
|
2901
3031
|
if (isAllSharedNotUsed) {
|
|
2902
3032
|
remoteIns.shareScopeMap = {};
|
|
2903
3033
|
delete globalShareScopeMap[remoteInsId];
|
|
2904
3034
|
}
|
|
2905
|
-
needDeleteKeys.forEach(([insId, shareScope, shareName, shareVersion])=>{
|
|
2906
|
-
|
|
2907
|
-
(_globalShareScopeMap_insId = globalShareScopeMap[insId]) == null ? true : (_globalShareScopeMap_insId_shareScope = _globalShareScopeMap_insId[shareScope]) == null ? true : (_globalShareScopeMap_insId_shareScope_shareName = _globalShareScopeMap_insId_shareScope[shareName]) == null ? true : delete _globalShareScopeMap_insId_shareScope_shareName[shareVersion];
|
|
3035
|
+
needDeleteKeys.forEach(([insId, shareScope, shareName, shareVersion]) => {
|
|
3036
|
+
delete globalShareScopeMap[insId]?.[shareScope]?.[shareName]?.[shareVersion];
|
|
2908
3037
|
});
|
|
2909
3038
|
CurrentGlobal.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
|
|
2910
3039
|
}
|
|
2911
3040
|
const { hostGlobalSnapshot } = getGlobalRemoteInfo(remote, host);
|
|
2912
3041
|
if (hostGlobalSnapshot) {
|
|
2913
|
-
const remoteKey = hostGlobalSnapshot &&
|
|
3042
|
+
const remoteKey = hostGlobalSnapshot &&
|
|
3043
|
+
'remotesInfo' in hostGlobalSnapshot &&
|
|
3044
|
+
hostGlobalSnapshot.remotesInfo &&
|
|
3045
|
+
getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;
|
|
2914
3046
|
if (remoteKey) {
|
|
2915
3047
|
delete hostGlobalSnapshot.remotesInfo[remoteKey];
|
|
2916
|
-
if (
|
|
3048
|
+
if (
|
|
3049
|
+
//eslint-disable-next-line no-extra-boolean-cast
|
|
2917
3050
|
Boolean(Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey])) {
|
|
2918
3051
|
delete Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey];
|
|
2919
3052
|
}
|
|
@@ -2921,31 +3054,68 @@ class RemoteHandler {
|
|
|
2921
3054
|
}
|
|
2922
3055
|
host.moduleCache.delete(remote.name);
|
|
2923
3056
|
}
|
|
2924
|
-
}
|
|
3057
|
+
}
|
|
3058
|
+
catch (err) {
|
|
2925
3059
|
logger.log('removeRemote fail: ', err);
|
|
2926
3060
|
}
|
|
2927
3061
|
}
|
|
2928
|
-
constructor(host){
|
|
2929
|
-
this.hooks = new PluginSystem({
|
|
2930
|
-
beforeRegisterRemote: new SyncWaterfallHook('beforeRegisterRemote'),
|
|
2931
|
-
registerRemote: new SyncWaterfallHook('registerRemote'),
|
|
2932
|
-
beforeRequest: new AsyncWaterfallHook('beforeRequest'),
|
|
2933
|
-
onLoad: new AsyncHook('onLoad'),
|
|
2934
|
-
handlePreloadModule: new SyncHook('handlePreloadModule'),
|
|
2935
|
-
errorLoadRemote: new AsyncHook('errorLoadRemote'),
|
|
2936
|
-
beforePreloadRemote: new AsyncHook('beforePreloadRemote'),
|
|
2937
|
-
generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
|
|
2938
|
-
// not used yet
|
|
2939
|
-
afterPreloadRemote: new AsyncHook(),
|
|
2940
|
-
loadEntry: new AsyncHook()
|
|
2941
|
-
});
|
|
2942
|
-
this.host = host;
|
|
2943
|
-
this.idToRemoteMap = {};
|
|
2944
|
-
}
|
|
2945
3062
|
}
|
|
2946
3063
|
|
|
2947
|
-
const USE_SNAPSHOT = typeof FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN === 'boolean'
|
|
3064
|
+
const USE_SNAPSHOT = typeof FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN === 'boolean'
|
|
3065
|
+
? !FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN
|
|
3066
|
+
: true; // Default to true (use snapshot) when not explicitly defined
|
|
2948
3067
|
class ModuleFederation {
|
|
3068
|
+
constructor(userOptions) {
|
|
3069
|
+
this.hooks = new PluginSystem({
|
|
3070
|
+
beforeInit: new SyncWaterfallHook('beforeInit'),
|
|
3071
|
+
init: new SyncHook(),
|
|
3072
|
+
// maybe will change, temporarily for internal use only
|
|
3073
|
+
beforeInitContainer: new AsyncWaterfallHook('beforeInitContainer'),
|
|
3074
|
+
// maybe will change, temporarily for internal use only
|
|
3075
|
+
initContainer: new AsyncWaterfallHook('initContainer'),
|
|
3076
|
+
});
|
|
3077
|
+
this.version = "0.0.0-refactor-manifest-20251013103938";
|
|
3078
|
+
this.moduleCache = new Map();
|
|
3079
|
+
this.loaderHook = new PluginSystem({
|
|
3080
|
+
// FIXME: may not be suitable , not open to the public yet
|
|
3081
|
+
getModuleInfo: new SyncHook(),
|
|
3082
|
+
createScript: new SyncHook(),
|
|
3083
|
+
createLink: new SyncHook(),
|
|
3084
|
+
fetch: new AsyncHook(),
|
|
3085
|
+
loadEntryError: new AsyncHook(),
|
|
3086
|
+
getModuleFactory: new AsyncHook(),
|
|
3087
|
+
});
|
|
3088
|
+
this.bridgeHook = new PluginSystem({
|
|
3089
|
+
beforeBridgeRender: new SyncHook(),
|
|
3090
|
+
afterBridgeRender: new SyncHook(),
|
|
3091
|
+
beforeBridgeDestroy: new SyncHook(),
|
|
3092
|
+
afterBridgeDestroy: new SyncHook(),
|
|
3093
|
+
});
|
|
3094
|
+
const plugins = USE_SNAPSHOT
|
|
3095
|
+
? [snapshotPlugin(), generatePreloadAssetsPlugin()]
|
|
3096
|
+
: [];
|
|
3097
|
+
// TODO: Validate the details of the options
|
|
3098
|
+
// Initialize options with default values
|
|
3099
|
+
const defaultOptions = {
|
|
3100
|
+
id: getBuilderId(),
|
|
3101
|
+
name: userOptions.name,
|
|
3102
|
+
plugins,
|
|
3103
|
+
remotes: [],
|
|
3104
|
+
shared: {},
|
|
3105
|
+
inBrowser: isBrowserEnv(),
|
|
3106
|
+
};
|
|
3107
|
+
this.name = userOptions.name;
|
|
3108
|
+
this.options = defaultOptions;
|
|
3109
|
+
this.snapshotHandler = new SnapshotHandler(this);
|
|
3110
|
+
this.sharedHandler = new SharedHandler(this);
|
|
3111
|
+
this.remoteHandler = new RemoteHandler(this);
|
|
3112
|
+
this.shareScopeMap = this.sharedHandler.shareScopeMap;
|
|
3113
|
+
this.registerPlugins([
|
|
3114
|
+
...defaultOptions.plugins,
|
|
3115
|
+
...(userOptions.plugins || []),
|
|
3116
|
+
]);
|
|
3117
|
+
this.options = this.formatOptions(defaultOptions, userOptions);
|
|
3118
|
+
}
|
|
2949
3119
|
initOptions(userOptions) {
|
|
2950
3120
|
this.registerPlugins(userOptions.plugins);
|
|
2951
3121
|
const options = this.formatOptions(this.options, userOptions);
|
|
@@ -2966,14 +3136,8 @@ class ModuleFederation {
|
|
|
2966
3136
|
return this.sharedHandler.initializeSharing(shareScopeName, extraOptions);
|
|
2967
3137
|
}
|
|
2968
3138
|
initRawContainer(name, url, container) {
|
|
2969
|
-
const remoteInfo = getRemoteInfo({
|
|
2970
|
-
|
|
2971
|
-
entry: url
|
|
2972
|
-
});
|
|
2973
|
-
const module = new Module({
|
|
2974
|
-
host: this,
|
|
2975
|
-
remoteInfo
|
|
2976
|
-
});
|
|
3139
|
+
const remoteInfo = getRemoteInfo({ name, entry: url });
|
|
3140
|
+
const module = new Module({ host: this, remoteInfo });
|
|
2977
3141
|
module.remoteEntryExports = container;
|
|
2978
3142
|
this.moduleCache.set(name, module);
|
|
2979
3143
|
return module;
|
|
@@ -2996,37 +3160,38 @@ class ModuleFederation {
|
|
|
2996
3160
|
origin: this,
|
|
2997
3161
|
userOptions,
|
|
2998
3162
|
options: globalOptions,
|
|
2999
|
-
shareInfo: shared
|
|
3163
|
+
shareInfo: shared,
|
|
3000
3164
|
});
|
|
3001
3165
|
const remotes = this.remoteHandler.formatAndRegisterRemote(globalOptionsRes, userOptionsRes);
|
|
3002
3166
|
const { shared: handledShared } = this.sharedHandler.registerShared(globalOptionsRes, userOptionsRes);
|
|
3003
|
-
const plugins = [
|
|
3004
|
-
...globalOptionsRes.plugins
|
|
3005
|
-
];
|
|
3167
|
+
const plugins = [...globalOptionsRes.plugins];
|
|
3006
3168
|
if (userOptionsRes.plugins) {
|
|
3007
|
-
userOptionsRes.plugins.forEach((plugin)=>{
|
|
3169
|
+
userOptionsRes.plugins.forEach((plugin) => {
|
|
3008
3170
|
if (!plugins.includes(plugin)) {
|
|
3009
3171
|
plugins.push(plugin);
|
|
3010
3172
|
}
|
|
3011
3173
|
});
|
|
3012
3174
|
}
|
|
3013
|
-
const optionsRes =
|
|
3175
|
+
const optionsRes = {
|
|
3176
|
+
...globalOptions,
|
|
3177
|
+
...userOptions,
|
|
3014
3178
|
plugins,
|
|
3015
3179
|
remotes,
|
|
3016
|
-
shared: handledShared
|
|
3017
|
-
}
|
|
3180
|
+
shared: handledShared,
|
|
3181
|
+
};
|
|
3018
3182
|
this.hooks.lifecycle.init.emit({
|
|
3019
3183
|
origin: this,
|
|
3020
|
-
options: optionsRes
|
|
3184
|
+
options: optionsRes,
|
|
3021
3185
|
});
|
|
3022
3186
|
return optionsRes;
|
|
3023
3187
|
}
|
|
3024
3188
|
registerPlugins(plugins) {
|
|
3025
3189
|
const pluginRes = registerPlugins(plugins, this);
|
|
3026
3190
|
// Merge plugin
|
|
3027
|
-
this.options.plugins = this.options.plugins.reduce((res, plugin)=>{
|
|
3028
|
-
if (!plugin)
|
|
3029
|
-
|
|
3191
|
+
this.options.plugins = this.options.plugins.reduce((res, plugin) => {
|
|
3192
|
+
if (!plugin)
|
|
3193
|
+
return res;
|
|
3194
|
+
if (res && !res.find((item) => item.name === plugin.name)) {
|
|
3030
3195
|
res.push(plugin);
|
|
3031
3196
|
}
|
|
3032
3197
|
return res;
|
|
@@ -3036,61 +3201,10 @@ class ModuleFederation {
|
|
|
3036
3201
|
return this.remoteHandler.registerRemotes(remotes, options);
|
|
3037
3202
|
}
|
|
3038
3203
|
registerShared(shared) {
|
|
3039
|
-
this.sharedHandler.registerShared(this.options,
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
}
|
|
3043
|
-
constructor(userOptions){
|
|
3044
|
-
this.hooks = new PluginSystem({
|
|
3045
|
-
beforeInit: new SyncWaterfallHook('beforeInit'),
|
|
3046
|
-
init: new SyncHook(),
|
|
3047
|
-
// maybe will change, temporarily for internal use only
|
|
3048
|
-
beforeInitContainer: new AsyncWaterfallHook('beforeInitContainer'),
|
|
3049
|
-
// maybe will change, temporarily for internal use only
|
|
3050
|
-
initContainer: new AsyncWaterfallHook('initContainer')
|
|
3051
|
-
});
|
|
3052
|
-
this.version = "0.0.0-next-20250926024003";
|
|
3053
|
-
this.moduleCache = new Map();
|
|
3054
|
-
this.loaderHook = new PluginSystem({
|
|
3055
|
-
// FIXME: may not be suitable , not open to the public yet
|
|
3056
|
-
getModuleInfo: new SyncHook(),
|
|
3057
|
-
createScript: new SyncHook(),
|
|
3058
|
-
createLink: new SyncHook(),
|
|
3059
|
-
fetch: new AsyncHook(),
|
|
3060
|
-
loadEntryError: new AsyncHook(),
|
|
3061
|
-
getModuleFactory: new AsyncHook()
|
|
3062
|
-
});
|
|
3063
|
-
this.bridgeHook = new PluginSystem({
|
|
3064
|
-
beforeBridgeRender: new SyncHook(),
|
|
3065
|
-
afterBridgeRender: new SyncHook(),
|
|
3066
|
-
beforeBridgeDestroy: new SyncHook(),
|
|
3067
|
-
afterBridgeDestroy: new SyncHook()
|
|
3204
|
+
this.sharedHandler.registerShared(this.options, {
|
|
3205
|
+
...this.options,
|
|
3206
|
+
shared,
|
|
3068
3207
|
});
|
|
3069
|
-
const plugins = USE_SNAPSHOT ? [
|
|
3070
|
-
snapshotPlugin(),
|
|
3071
|
-
generatePreloadAssetsPlugin()
|
|
3072
|
-
] : [];
|
|
3073
|
-
// TODO: Validate the details of the options
|
|
3074
|
-
// Initialize options with default values
|
|
3075
|
-
const defaultOptions = {
|
|
3076
|
-
id: getBuilderId(),
|
|
3077
|
-
name: userOptions.name,
|
|
3078
|
-
plugins,
|
|
3079
|
-
remotes: [],
|
|
3080
|
-
shared: {},
|
|
3081
|
-
inBrowser: isBrowserEnv()
|
|
3082
|
-
};
|
|
3083
|
-
this.name = userOptions.name;
|
|
3084
|
-
this.options = defaultOptions;
|
|
3085
|
-
this.snapshotHandler = new SnapshotHandler(this);
|
|
3086
|
-
this.sharedHandler = new SharedHandler(this);
|
|
3087
|
-
this.remoteHandler = new RemoteHandler(this);
|
|
3088
|
-
this.shareScopeMap = this.sharedHandler.shareScopeMap;
|
|
3089
|
-
this.registerPlugins([
|
|
3090
|
-
...defaultOptions.plugins,
|
|
3091
|
-
...userOptions.plugins || []
|
|
3092
|
-
]);
|
|
3093
|
-
this.options = this.formatOptions(defaultOptions, userOptions);
|
|
3094
3208
|
}
|
|
3095
3209
|
}
|
|
3096
3210
|
|