@module-federation/runtime-core 0.19.0 → 0.20.0
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 +1003 -882
- package/dist/index.cjs.cjs.map +1 -1
- package/dist/index.esm.js +1004 -883
- package/dist/index.esm.js.map +1 -1
- package/dist/src/core.d.ts +1 -1
- package/dist/src/utils/load.d.ts +1 -0
- 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,7 +1,6 @@
|
|
|
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
|
-
import {
|
|
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';
|
|
5
4
|
|
|
6
5
|
const LOG_CATEGORY = '[ Federation Runtime ]';
|
|
7
6
|
// FIXME: pre-bundle ?
|
|
@@ -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.
|
|
203
|
+
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.20.0";
|
|
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 } = 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,56 +1266,83 @@ 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
|
-
|
|
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) => {
|
|
1293
|
+
const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
|
|
1294
|
+
const isScriptLoadError = err instanceof Error && err.message.includes(RUNTIME_008);
|
|
1295
|
+
if (isScriptLoadError && !_inErrorHandling) {
|
|
1296
|
+
const wrappedGetRemoteEntry = (params) => {
|
|
1297
|
+
return getRemoteEntry({ ...params, _inErrorHandling: true });
|
|
1298
|
+
};
|
|
1299
|
+
const RemoteEntryExports = await origin.loaderHook.lifecycle.loadEntryError.emit({
|
|
1300
|
+
getRemoteEntry: wrappedGetRemoteEntry,
|
|
1301
|
+
origin,
|
|
1302
|
+
remoteInfo: remoteInfo,
|
|
1303
|
+
remoteEntryExports,
|
|
1304
|
+
globalLoading,
|
|
1305
|
+
uniqueKey,
|
|
1306
|
+
});
|
|
1307
|
+
if (RemoteEntryExports) {
|
|
1308
|
+
return RemoteEntryExports;
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
throw err;
|
|
1220
1312
|
});
|
|
1221
1313
|
}
|
|
1222
1314
|
return globalLoading[uniqueKey];
|
|
1223
1315
|
}
|
|
1224
1316
|
function getRemoteInfo(remote) {
|
|
1225
|
-
return
|
|
1317
|
+
return {
|
|
1318
|
+
...remote,
|
|
1226
1319
|
entry: 'entry' in remote ? remote.entry : '',
|
|
1227
1320
|
type: remote.type || DEFAULT_REMOTE_TYPE,
|
|
1228
1321
|
entryGlobalName: remote.entryGlobalName || remote.name,
|
|
1229
|
-
shareScope: remote.shareScope || DEFAULT_SCOPE
|
|
1230
|
-
}
|
|
1322
|
+
shareScope: remote.shareScope || DEFAULT_SCOPE,
|
|
1323
|
+
};
|
|
1231
1324
|
}
|
|
1232
1325
|
|
|
1233
1326
|
function defaultPreloadArgs(preloadConfig) {
|
|
1234
|
-
return
|
|
1327
|
+
return {
|
|
1235
1328
|
resourceCategory: 'sync',
|
|
1236
1329
|
share: true,
|
|
1237
1330
|
depsRemote: true,
|
|
1238
|
-
prefetchInterface: false
|
|
1239
|
-
|
|
1331
|
+
prefetchInterface: false,
|
|
1332
|
+
...preloadConfig,
|
|
1333
|
+
};
|
|
1240
1334
|
}
|
|
1241
1335
|
function formatPreloadArgs(remotes, preloadArgs) {
|
|
1242
|
-
return preloadArgs.map((args)=>{
|
|
1336
|
+
return preloadArgs.map((args) => {
|
|
1243
1337
|
const remoteInfo = matchRemote(remotes, args.nameOrAlias);
|
|
1244
|
-
assert(remoteInfo, `Unable to preload ${args.nameOrAlias} as it is not included in ${!remoteInfo &&
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1338
|
+
assert(remoteInfo, `Unable to preload ${args.nameOrAlias} as it is not included in ${!remoteInfo &&
|
|
1339
|
+
safeToString({
|
|
1340
|
+
remoteInfo,
|
|
1341
|
+
remotes,
|
|
1342
|
+
})}`);
|
|
1248
1343
|
return {
|
|
1249
1344
|
remote: remoteInfo,
|
|
1250
|
-
preloadConfig: defaultPreloadArgs(args)
|
|
1345
|
+
preloadConfig: defaultPreloadArgs(args),
|
|
1251
1346
|
};
|
|
1252
1347
|
});
|
|
1253
1348
|
}
|
|
@@ -1255,7 +1350,7 @@ function normalizePreloadExposes(exposes) {
|
|
|
1255
1350
|
if (!exposes) {
|
|
1256
1351
|
return [];
|
|
1257
1352
|
}
|
|
1258
|
-
return exposes.map((expose)=>{
|
|
1353
|
+
return exposes.map((expose) => {
|
|
1259
1354
|
if (expose === '.') {
|
|
1260
1355
|
return expose;
|
|
1261
1356
|
}
|
|
@@ -1265,75 +1360,78 @@ function normalizePreloadExposes(exposes) {
|
|
|
1265
1360
|
return expose;
|
|
1266
1361
|
});
|
|
1267
1362
|
}
|
|
1268
|
-
function preloadAssets(remoteInfo, host, assets,
|
|
1363
|
+
function preloadAssets(remoteInfo, host, assets,
|
|
1364
|
+
// It is used to distinguish preload from load remote parallel loading
|
|
1269
1365
|
useLinkPreload = true) {
|
|
1270
1366
|
const { cssAssets, jsAssetsWithoutEntry, entryAssets } = assets;
|
|
1271
1367
|
if (host.options.inBrowser) {
|
|
1272
|
-
entryAssets.forEach((asset)=>{
|
|
1368
|
+
entryAssets.forEach((asset) => {
|
|
1273
1369
|
const { moduleInfo } = asset;
|
|
1274
1370
|
const module = host.moduleCache.get(remoteInfo.name);
|
|
1275
1371
|
if (module) {
|
|
1276
1372
|
getRemoteEntry({
|
|
1277
1373
|
origin: host,
|
|
1278
1374
|
remoteInfo: moduleInfo,
|
|
1279
|
-
remoteEntryExports: module.remoteEntryExports
|
|
1375
|
+
remoteEntryExports: module.remoteEntryExports,
|
|
1280
1376
|
});
|
|
1281
|
-
}
|
|
1377
|
+
}
|
|
1378
|
+
else {
|
|
1282
1379
|
getRemoteEntry({
|
|
1283
1380
|
origin: host,
|
|
1284
1381
|
remoteInfo: moduleInfo,
|
|
1285
|
-
remoteEntryExports: undefined
|
|
1382
|
+
remoteEntryExports: undefined,
|
|
1286
1383
|
});
|
|
1287
1384
|
}
|
|
1288
1385
|
});
|
|
1289
1386
|
if (useLinkPreload) {
|
|
1290
1387
|
const defaultAttrs = {
|
|
1291
1388
|
rel: 'preload',
|
|
1292
|
-
as: 'style'
|
|
1389
|
+
as: 'style',
|
|
1293
1390
|
};
|
|
1294
|
-
cssAssets.forEach((cssUrl)=>{
|
|
1391
|
+
cssAssets.forEach((cssUrl) => {
|
|
1295
1392
|
const { link: cssEl, needAttach } = createLink({
|
|
1296
1393
|
url: cssUrl,
|
|
1297
|
-
cb: ()=>{
|
|
1298
|
-
|
|
1394
|
+
cb: () => {
|
|
1395
|
+
// noop
|
|
1299
1396
|
},
|
|
1300
1397
|
attrs: defaultAttrs,
|
|
1301
|
-
createLinkHook: (url, attrs)=>{
|
|
1398
|
+
createLinkHook: (url, attrs) => {
|
|
1302
1399
|
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
1303
1400
|
url,
|
|
1304
|
-
attrs
|
|
1401
|
+
attrs,
|
|
1305
1402
|
});
|
|
1306
1403
|
if (res instanceof HTMLLinkElement) {
|
|
1307
1404
|
return res;
|
|
1308
1405
|
}
|
|
1309
1406
|
return;
|
|
1310
|
-
}
|
|
1407
|
+
},
|
|
1311
1408
|
});
|
|
1312
1409
|
needAttach && document.head.appendChild(cssEl);
|
|
1313
1410
|
});
|
|
1314
|
-
}
|
|
1411
|
+
}
|
|
1412
|
+
else {
|
|
1315
1413
|
const defaultAttrs = {
|
|
1316
1414
|
rel: 'stylesheet',
|
|
1317
|
-
type: 'text/css'
|
|
1415
|
+
type: 'text/css',
|
|
1318
1416
|
};
|
|
1319
|
-
cssAssets.forEach((cssUrl)=>{
|
|
1417
|
+
cssAssets.forEach((cssUrl) => {
|
|
1320
1418
|
const { link: cssEl, needAttach } = createLink({
|
|
1321
1419
|
url: cssUrl,
|
|
1322
|
-
cb: ()=>{
|
|
1323
|
-
|
|
1420
|
+
cb: () => {
|
|
1421
|
+
// noop
|
|
1324
1422
|
},
|
|
1325
1423
|
attrs: defaultAttrs,
|
|
1326
|
-
createLinkHook: (url, attrs)=>{
|
|
1424
|
+
createLinkHook: (url, attrs) => {
|
|
1327
1425
|
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
1328
1426
|
url,
|
|
1329
|
-
attrs
|
|
1427
|
+
attrs,
|
|
1330
1428
|
});
|
|
1331
1429
|
if (res instanceof HTMLLinkElement) {
|
|
1332
1430
|
return res;
|
|
1333
1431
|
}
|
|
1334
1432
|
return;
|
|
1335
1433
|
},
|
|
1336
|
-
needDeleteLink: false
|
|
1434
|
+
needDeleteLink: false,
|
|
1337
1435
|
});
|
|
1338
1436
|
needAttach && document.head.appendChild(cssEl);
|
|
1339
1437
|
});
|
|
@@ -1341,51 +1439,52 @@ useLinkPreload = true) {
|
|
|
1341
1439
|
if (useLinkPreload) {
|
|
1342
1440
|
const defaultAttrs = {
|
|
1343
1441
|
rel: 'preload',
|
|
1344
|
-
as: 'script'
|
|
1442
|
+
as: 'script',
|
|
1345
1443
|
};
|
|
1346
|
-
jsAssetsWithoutEntry.forEach((jsUrl)=>{
|
|
1444
|
+
jsAssetsWithoutEntry.forEach((jsUrl) => {
|
|
1347
1445
|
const { link: linkEl, needAttach } = createLink({
|
|
1348
1446
|
url: jsUrl,
|
|
1349
|
-
cb: ()=>{
|
|
1350
|
-
|
|
1447
|
+
cb: () => {
|
|
1448
|
+
// noop
|
|
1351
1449
|
},
|
|
1352
1450
|
attrs: defaultAttrs,
|
|
1353
|
-
createLinkHook: (url, attrs)=>{
|
|
1451
|
+
createLinkHook: (url, attrs) => {
|
|
1354
1452
|
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
1355
1453
|
url,
|
|
1356
|
-
attrs
|
|
1454
|
+
attrs,
|
|
1357
1455
|
});
|
|
1358
1456
|
if (res instanceof HTMLLinkElement) {
|
|
1359
1457
|
return res;
|
|
1360
1458
|
}
|
|
1361
1459
|
return;
|
|
1362
|
-
}
|
|
1460
|
+
},
|
|
1363
1461
|
});
|
|
1364
1462
|
needAttach && document.head.appendChild(linkEl);
|
|
1365
1463
|
});
|
|
1366
|
-
}
|
|
1464
|
+
}
|
|
1465
|
+
else {
|
|
1367
1466
|
const defaultAttrs = {
|
|
1368
1467
|
fetchpriority: 'high',
|
|
1369
|
-
type:
|
|
1468
|
+
type: remoteInfo?.type === 'module' ? 'module' : 'text/javascript',
|
|
1370
1469
|
};
|
|
1371
|
-
jsAssetsWithoutEntry.forEach((jsUrl)=>{
|
|
1470
|
+
jsAssetsWithoutEntry.forEach((jsUrl) => {
|
|
1372
1471
|
const { script: scriptEl, needAttach } = createScript({
|
|
1373
1472
|
url: jsUrl,
|
|
1374
|
-
cb: ()=>{
|
|
1375
|
-
|
|
1473
|
+
cb: () => {
|
|
1474
|
+
// noop
|
|
1376
1475
|
},
|
|
1377
1476
|
attrs: defaultAttrs,
|
|
1378
|
-
createScriptHook: (url, attrs)=>{
|
|
1477
|
+
createScriptHook: (url, attrs) => {
|
|
1379
1478
|
const res = host.loaderHook.lifecycle.createScript.emit({
|
|
1380
1479
|
url,
|
|
1381
|
-
attrs
|
|
1480
|
+
attrs,
|
|
1382
1481
|
});
|
|
1383
1482
|
if (res instanceof HTMLScriptElement) {
|
|
1384
1483
|
return res;
|
|
1385
1484
|
}
|
|
1386
1485
|
return;
|
|
1387
1486
|
},
|
|
1388
|
-
needDeleteScript: true
|
|
1487
|
+
needDeleteScript: true,
|
|
1389
1488
|
});
|
|
1390
1489
|
needAttach && document.head.appendChild(scriptEl);
|
|
1391
1490
|
});
|
|
@@ -1395,7 +1494,7 @@ useLinkPreload = true) {
|
|
|
1395
1494
|
|
|
1396
1495
|
const ShareUtils = {
|
|
1397
1496
|
getRegisteredShare,
|
|
1398
|
-
getGlobalShareScope
|
|
1497
|
+
getGlobalShareScope,
|
|
1399
1498
|
};
|
|
1400
1499
|
const GlobalUtils = {
|
|
1401
1500
|
Global,
|
|
@@ -1414,7 +1513,7 @@ const GlobalUtils = {
|
|
|
1414
1513
|
registerGlobalPlugins,
|
|
1415
1514
|
getGlobalHostPlugins,
|
|
1416
1515
|
getPreloaded,
|
|
1417
|
-
setPreloaded
|
|
1516
|
+
setPreloaded,
|
|
1418
1517
|
};
|
|
1419
1518
|
var helpers = {
|
|
1420
1519
|
global: GlobalUtils,
|
|
@@ -1422,56 +1521,45 @@ var helpers = {
|
|
|
1422
1521
|
utils: {
|
|
1423
1522
|
matchRemoteWithNameAndExpose,
|
|
1424
1523
|
preloadAssets,
|
|
1425
|
-
getRemoteInfo
|
|
1426
|
-
}
|
|
1524
|
+
getRemoteInfo,
|
|
1525
|
+
},
|
|
1427
1526
|
};
|
|
1428
1527
|
|
|
1429
|
-
|
|
1528
|
+
class Module {
|
|
1529
|
+
constructor({ remoteInfo, host, }) {
|
|
1530
|
+
this.inited = false;
|
|
1531
|
+
this.lib = undefined;
|
|
1532
|
+
this.remoteInfo = remoteInfo;
|
|
1533
|
+
this.host = host;
|
|
1534
|
+
}
|
|
1430
1535
|
async getEntry() {
|
|
1431
1536
|
if (this.remoteEntryExports) {
|
|
1432
1537
|
return this.remoteEntryExports;
|
|
1433
1538
|
}
|
|
1434
1539
|
let remoteEntryExports;
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
});
|
|
1441
|
-
} catch (err) {
|
|
1442
|
-
const uniqueKey = getRemoteEntryUniqueKey(this.remoteInfo);
|
|
1443
|
-
const isScriptLoadError = err instanceof Error && err.message.includes(RUNTIME_008);
|
|
1444
|
-
if (isScriptLoadError) {
|
|
1445
|
-
remoteEntryExports = await this.host.loaderHook.lifecycle.loadEntryError.emit({
|
|
1446
|
-
getRemoteEntry,
|
|
1447
|
-
origin: this.host,
|
|
1448
|
-
remoteInfo: this.remoteInfo,
|
|
1449
|
-
remoteEntryExports: this.remoteEntryExports,
|
|
1450
|
-
globalLoading,
|
|
1451
|
-
uniqueKey
|
|
1452
|
-
});
|
|
1453
|
-
}
|
|
1454
|
-
}
|
|
1540
|
+
remoteEntryExports = await getRemoteEntry({
|
|
1541
|
+
origin: this.host,
|
|
1542
|
+
remoteInfo: this.remoteInfo,
|
|
1543
|
+
remoteEntryExports: this.remoteEntryExports,
|
|
1544
|
+
});
|
|
1455
1545
|
assert(remoteEntryExports, `remoteEntryExports is undefined \n ${safeToString(this.remoteInfo)}`);
|
|
1456
1546
|
this.remoteEntryExports = remoteEntryExports;
|
|
1457
1547
|
return this.remoteEntryExports;
|
|
1458
1548
|
}
|
|
1459
1549
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
1460
1550
|
async get(id, expose, options, remoteSnapshot) {
|
|
1461
|
-
const { loadFactory = true } = options || {
|
|
1462
|
-
loadFactory: true
|
|
1463
|
-
};
|
|
1551
|
+
const { loadFactory = true } = options || { loadFactory: true };
|
|
1464
1552
|
// Get remoteEntry.js
|
|
1465
1553
|
const remoteEntryExports = await this.getEntry();
|
|
1466
1554
|
if (!this.inited) {
|
|
1467
1555
|
const localShareScopeMap = this.host.shareScopeMap;
|
|
1468
|
-
const shareScopeKeys = Array.isArray(this.remoteInfo.shareScope)
|
|
1469
|
-
this.remoteInfo.shareScope
|
|
1470
|
-
|
|
1556
|
+
const shareScopeKeys = Array.isArray(this.remoteInfo.shareScope)
|
|
1557
|
+
? this.remoteInfo.shareScope
|
|
1558
|
+
: [this.remoteInfo.shareScope];
|
|
1471
1559
|
if (!shareScopeKeys.length) {
|
|
1472
1560
|
shareScopeKeys.push('default');
|
|
1473
1561
|
}
|
|
1474
|
-
shareScopeKeys.forEach((shareScopeKey)=>{
|
|
1562
|
+
shareScopeKeys.forEach((shareScopeKey) => {
|
|
1475
1563
|
if (!localShareScopeMap[shareScopeKey]) {
|
|
1476
1564
|
localShareScopeMap[shareScopeKey] = {};
|
|
1477
1565
|
}
|
|
@@ -1481,13 +1569,15 @@ let Module = class Module {
|
|
|
1481
1569
|
const initScope = [];
|
|
1482
1570
|
const remoteEntryInitOptions = {
|
|
1483
1571
|
version: this.remoteInfo.version || '',
|
|
1484
|
-
shareScopeKeys: Array.isArray(this.remoteInfo.shareScope)
|
|
1572
|
+
shareScopeKeys: Array.isArray(this.remoteInfo.shareScope)
|
|
1573
|
+
? shareScopeKeys
|
|
1574
|
+
: this.remoteInfo.shareScope || 'default',
|
|
1485
1575
|
};
|
|
1486
1576
|
// Help to find host instance
|
|
1487
1577
|
Object.defineProperty(remoteEntryInitOptions, 'shareScopeMap', {
|
|
1488
1578
|
value: localShareScopeMap,
|
|
1489
1579
|
// remoteEntryInitOptions will be traversed and assigned during container init, ,so this attribute is not allowed to be traversed
|
|
1490
|
-
enumerable: false
|
|
1580
|
+
enumerable: false,
|
|
1491
1581
|
});
|
|
1492
1582
|
const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
|
|
1493
1583
|
shareScope,
|
|
@@ -1495,22 +1585,23 @@ let Module = class Module {
|
|
|
1495
1585
|
remoteEntryInitOptions,
|
|
1496
1586
|
initScope,
|
|
1497
1587
|
remoteInfo: this.remoteInfo,
|
|
1498
|
-
origin: this.host
|
|
1588
|
+
origin: this.host,
|
|
1499
1589
|
});
|
|
1500
|
-
if (typeof
|
|
1590
|
+
if (typeof remoteEntryExports?.init === 'undefined') {
|
|
1501
1591
|
error(getShortErrorMsg(RUNTIME_002, runtimeDescMap, {
|
|
1502
1592
|
hostName: this.host.name,
|
|
1503
1593
|
remoteName: this.remoteInfo.name,
|
|
1504
1594
|
remoteEntryUrl: this.remoteInfo.entry,
|
|
1505
|
-
remoteEntryKey: this.remoteInfo.entryGlobalName
|
|
1595
|
+
remoteEntryKey: this.remoteInfo.entryGlobalName,
|
|
1506
1596
|
}));
|
|
1507
1597
|
}
|
|
1508
1598
|
await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
|
|
1509
|
-
await this.host.hooks.lifecycle.initContainer.emit(
|
|
1599
|
+
await this.host.hooks.lifecycle.initContainer.emit({
|
|
1600
|
+
...initContainerOptions,
|
|
1510
1601
|
id,
|
|
1511
1602
|
remoteSnapshot,
|
|
1512
|
-
remoteEntryExports
|
|
1513
|
-
})
|
|
1603
|
+
remoteEntryExports,
|
|
1604
|
+
});
|
|
1514
1605
|
}
|
|
1515
1606
|
this.lib = remoteEntryExports;
|
|
1516
1607
|
this.inited = true;
|
|
@@ -1518,7 +1609,7 @@ let Module = class Module {
|
|
|
1518
1609
|
moduleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
|
|
1519
1610
|
remoteEntryExports,
|
|
1520
1611
|
expose,
|
|
1521
|
-
moduleInfo: this.remoteInfo
|
|
1612
|
+
moduleInfo: this.remoteInfo,
|
|
1522
1613
|
});
|
|
1523
1614
|
// get exposeGetter
|
|
1524
1615
|
if (!moduleFactory) {
|
|
@@ -1536,22 +1627,26 @@ let Module = class Module {
|
|
|
1536
1627
|
}
|
|
1537
1628
|
wraperFactory(moduleFactory, id) {
|
|
1538
1629
|
function defineModuleId(res, id) {
|
|
1539
|
-
if (res &&
|
|
1630
|
+
if (res &&
|
|
1631
|
+
typeof res === 'object' &&
|
|
1632
|
+
Object.isExtensible(res) &&
|
|
1633
|
+
!Object.getOwnPropertyDescriptor(res, Symbol.for('mf_module_id'))) {
|
|
1540
1634
|
Object.defineProperty(res, Symbol.for('mf_module_id'), {
|
|
1541
1635
|
value: id,
|
|
1542
|
-
enumerable: false
|
|
1636
|
+
enumerable: false,
|
|
1543
1637
|
});
|
|
1544
1638
|
}
|
|
1545
1639
|
}
|
|
1546
1640
|
if (moduleFactory instanceof Promise) {
|
|
1547
|
-
return async ()=>{
|
|
1641
|
+
return async () => {
|
|
1548
1642
|
const res = await moduleFactory();
|
|
1549
1643
|
// This parameter is used for bridge debugging
|
|
1550
1644
|
defineModuleId(res, id);
|
|
1551
1645
|
return res;
|
|
1552
1646
|
};
|
|
1553
|
-
}
|
|
1554
|
-
|
|
1647
|
+
}
|
|
1648
|
+
else {
|
|
1649
|
+
return () => {
|
|
1555
1650
|
const res = moduleFactory();
|
|
1556
1651
|
// This parameter is used for bridge debugging
|
|
1557
1652
|
defineModuleId(res, id);
|
|
@@ -1559,15 +1654,16 @@ let Module = class Module {
|
|
|
1559
1654
|
};
|
|
1560
1655
|
}
|
|
1561
1656
|
}
|
|
1562
|
-
|
|
1563
|
-
this.inited = false;
|
|
1564
|
-
this.lib = undefined;
|
|
1565
|
-
this.remoteInfo = remoteInfo;
|
|
1566
|
-
this.host = host;
|
|
1567
|
-
}
|
|
1568
|
-
};
|
|
1657
|
+
}
|
|
1569
1658
|
|
|
1570
1659
|
class SyncHook {
|
|
1660
|
+
constructor(type) {
|
|
1661
|
+
this.type = '';
|
|
1662
|
+
this.listeners = new Set();
|
|
1663
|
+
if (type) {
|
|
1664
|
+
this.type = type;
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1571
1667
|
on(fn) {
|
|
1572
1668
|
if (typeof fn === 'function') {
|
|
1573
1669
|
this.listeners.add(fn);
|
|
@@ -1586,7 +1682,7 @@ class SyncHook {
|
|
|
1586
1682
|
let result;
|
|
1587
1683
|
if (this.listeners.size > 0) {
|
|
1588
1684
|
// eslint-disable-next-line prefer-spread
|
|
1589
|
-
this.listeners.forEach((fn)=>{
|
|
1685
|
+
this.listeners.forEach((fn) => {
|
|
1590
1686
|
result = fn(...data);
|
|
1591
1687
|
});
|
|
1592
1688
|
}
|
|
@@ -1598,13 +1694,6 @@ class SyncHook {
|
|
|
1598
1694
|
removeAll() {
|
|
1599
1695
|
this.listeners.clear();
|
|
1600
1696
|
}
|
|
1601
|
-
constructor(type){
|
|
1602
|
-
this.type = '';
|
|
1603
|
-
this.listeners = new Set();
|
|
1604
|
-
if (type) {
|
|
1605
|
-
this.type = type;
|
|
1606
|
-
}
|
|
1607
|
-
}
|
|
1608
1697
|
}
|
|
1609
1698
|
|
|
1610
1699
|
class AsyncHook extends SyncHook {
|
|
@@ -1613,12 +1702,14 @@ class AsyncHook extends SyncHook {
|
|
|
1613
1702
|
const ls = Array.from(this.listeners);
|
|
1614
1703
|
if (ls.length > 0) {
|
|
1615
1704
|
let i = 0;
|
|
1616
|
-
const call = (prev)=>{
|
|
1705
|
+
const call = (prev) => {
|
|
1617
1706
|
if (prev === false) {
|
|
1618
1707
|
return false; // Abort process
|
|
1619
|
-
}
|
|
1708
|
+
}
|
|
1709
|
+
else if (i < ls.length) {
|
|
1620
1710
|
return Promise.resolve(ls[i++].apply(null, data)).then(call);
|
|
1621
|
-
}
|
|
1711
|
+
}
|
|
1712
|
+
else {
|
|
1622
1713
|
return prev;
|
|
1623
1714
|
}
|
|
1624
1715
|
};
|
|
@@ -1635,7 +1726,7 @@ function checkReturnData(originalData, returnedData) {
|
|
|
1635
1726
|
}
|
|
1636
1727
|
if (originalData !== returnedData) {
|
|
1637
1728
|
// eslint-disable-next-line no-restricted-syntax
|
|
1638
|
-
for(const key in originalData){
|
|
1729
|
+
for (const key in originalData) {
|
|
1639
1730
|
if (!(key in returnedData)) {
|
|
1640
1731
|
return false;
|
|
1641
1732
|
}
|
|
@@ -1644,34 +1735,41 @@ function checkReturnData(originalData, returnedData) {
|
|
|
1644
1735
|
return true;
|
|
1645
1736
|
}
|
|
1646
1737
|
class SyncWaterfallHook extends SyncHook {
|
|
1738
|
+
constructor(type) {
|
|
1739
|
+
super();
|
|
1740
|
+
this.onerror = error;
|
|
1741
|
+
this.type = type;
|
|
1742
|
+
}
|
|
1647
1743
|
emit(data) {
|
|
1648
1744
|
if (!isObject(data)) {
|
|
1649
1745
|
error(`The data for the "${this.type}" hook should be an object.`);
|
|
1650
1746
|
}
|
|
1651
|
-
for (const fn of this.listeners){
|
|
1747
|
+
for (const fn of this.listeners) {
|
|
1652
1748
|
try {
|
|
1653
1749
|
const tempData = fn(data);
|
|
1654
1750
|
if (checkReturnData(data, tempData)) {
|
|
1655
1751
|
data = tempData;
|
|
1656
|
-
}
|
|
1752
|
+
}
|
|
1753
|
+
else {
|
|
1657
1754
|
this.onerror(`A plugin returned an unacceptable value for the "${this.type}" type.`);
|
|
1658
1755
|
break;
|
|
1659
1756
|
}
|
|
1660
|
-
}
|
|
1757
|
+
}
|
|
1758
|
+
catch (e) {
|
|
1661
1759
|
warn(e);
|
|
1662
1760
|
this.onerror(e);
|
|
1663
1761
|
}
|
|
1664
1762
|
}
|
|
1665
1763
|
return data;
|
|
1666
1764
|
}
|
|
1667
|
-
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
class AsyncWaterfallHook extends SyncHook {
|
|
1768
|
+
constructor(type) {
|
|
1668
1769
|
super();
|
|
1669
1770
|
this.onerror = error;
|
|
1670
1771
|
this.type = type;
|
|
1671
1772
|
}
|
|
1672
|
-
}
|
|
1673
|
-
|
|
1674
|
-
class AsyncWaterfallHook extends SyncHook {
|
|
1675
1773
|
emit(data) {
|
|
1676
1774
|
if (!isObject(data)) {
|
|
1677
1775
|
error(`The response data for the "${this.type}" hook must be an object.`);
|
|
@@ -1679,22 +1777,24 @@ class AsyncWaterfallHook extends SyncHook {
|
|
|
1679
1777
|
const ls = Array.from(this.listeners);
|
|
1680
1778
|
if (ls.length > 0) {
|
|
1681
1779
|
let i = 0;
|
|
1682
|
-
const processError = (e)=>{
|
|
1780
|
+
const processError = (e) => {
|
|
1683
1781
|
warn(e);
|
|
1684
1782
|
this.onerror(e);
|
|
1685
1783
|
return data;
|
|
1686
1784
|
};
|
|
1687
|
-
const call = (prevData)=>{
|
|
1785
|
+
const call = (prevData) => {
|
|
1688
1786
|
if (checkReturnData(data, prevData)) {
|
|
1689
1787
|
data = prevData;
|
|
1690
1788
|
if (i < ls.length) {
|
|
1691
1789
|
try {
|
|
1692
1790
|
return Promise.resolve(ls[i++](data)).then(call, processError);
|
|
1693
|
-
}
|
|
1791
|
+
}
|
|
1792
|
+
catch (e) {
|
|
1694
1793
|
return processError(e);
|
|
1695
1794
|
}
|
|
1696
1795
|
}
|
|
1697
|
-
}
|
|
1796
|
+
}
|
|
1797
|
+
else {
|
|
1698
1798
|
this.onerror(`A plugin returned an incorrect value for the "${this.type}" type.`);
|
|
1699
1799
|
}
|
|
1700
1800
|
return data;
|
|
@@ -1703,14 +1803,14 @@ class AsyncWaterfallHook extends SyncHook {
|
|
|
1703
1803
|
}
|
|
1704
1804
|
return Promise.resolve(data);
|
|
1705
1805
|
}
|
|
1706
|
-
constructor(type){
|
|
1707
|
-
super();
|
|
1708
|
-
this.onerror = error;
|
|
1709
|
-
this.type = type;
|
|
1710
|
-
}
|
|
1711
1806
|
}
|
|
1712
1807
|
|
|
1713
1808
|
class PluginSystem {
|
|
1809
|
+
constructor(lifecycle) {
|
|
1810
|
+
this.registerPlugins = {};
|
|
1811
|
+
this.lifecycle = lifecycle;
|
|
1812
|
+
this.lifecycleKeys = Object.keys(lifecycle);
|
|
1813
|
+
}
|
|
1714
1814
|
applyPlugin(plugin, instance) {
|
|
1715
1815
|
assert(isPlainObject(plugin), 'Plugin configuration is invalid.');
|
|
1716
1816
|
// The plugin's name is mandatory and must be unique
|
|
@@ -1718,8 +1818,8 @@ class PluginSystem {
|
|
|
1718
1818
|
assert(pluginName, 'A name must be provided by the plugin.');
|
|
1719
1819
|
if (!this.registerPlugins[pluginName]) {
|
|
1720
1820
|
this.registerPlugins[pluginName] = plugin;
|
|
1721
|
-
plugin.apply
|
|
1722
|
-
Object.keys(this.lifecycle).forEach((key)=>{
|
|
1821
|
+
plugin.apply?.(instance);
|
|
1822
|
+
Object.keys(this.lifecycle).forEach((key) => {
|
|
1723
1823
|
const pluginLife = plugin[key];
|
|
1724
1824
|
if (pluginLife) {
|
|
1725
1825
|
this.lifecycle[key].on(pluginLife);
|
|
@@ -1731,17 +1831,12 @@ class PluginSystem {
|
|
|
1731
1831
|
assert(pluginName, 'A name is required.');
|
|
1732
1832
|
const plugin = this.registerPlugins[pluginName];
|
|
1733
1833
|
assert(plugin, `The plugin "${pluginName}" is not registered.`);
|
|
1734
|
-
Object.keys(plugin).forEach((key)=>{
|
|
1834
|
+
Object.keys(plugin).forEach((key) => {
|
|
1735
1835
|
if (key !== 'name') {
|
|
1736
1836
|
this.lifecycle[key].remove(plugin[key]);
|
|
1737
1837
|
}
|
|
1738
1838
|
});
|
|
1739
1839
|
}
|
|
1740
|
-
constructor(lifecycle){
|
|
1741
|
-
this.registerPlugins = {};
|
|
1742
|
-
this.lifecycle = lifecycle;
|
|
1743
|
-
this.lifecycleKeys = Object.keys(lifecycle);
|
|
1744
|
-
}
|
|
1745
1840
|
}
|
|
1746
1841
|
|
|
1747
1842
|
function assignRemoteInfo(remoteInfo, remoteSnapshot) {
|
|
@@ -1762,12 +1857,12 @@ function assignRemoteInfo(remoteInfo, remoteSnapshot) {
|
|
|
1762
1857
|
function snapshotPlugin() {
|
|
1763
1858
|
return {
|
|
1764
1859
|
name: 'snapshot-plugin',
|
|
1765
|
-
async afterResolve
|
|
1860
|
+
async afterResolve(args) {
|
|
1766
1861
|
const { remote, pkgNameOrAlias, expose, origin, remoteInfo, id } = args;
|
|
1767
1862
|
if (!isRemoteInfoWithEntry(remote) || !isPureRemoteEntry(remote)) {
|
|
1768
1863
|
const { remoteSnapshot, globalSnapshot } = await origin.snapshotHandler.loadRemoteSnapshotInfo({
|
|
1769
1864
|
moduleInfo: remote,
|
|
1770
|
-
id
|
|
1865
|
+
id,
|
|
1771
1866
|
});
|
|
1772
1867
|
assignRemoteInfo(remoteInfo, remoteSnapshot);
|
|
1773
1868
|
// preloading assets
|
|
@@ -1775,13 +1870,11 @@ function snapshotPlugin() {
|
|
|
1775
1870
|
remote,
|
|
1776
1871
|
preloadConfig: {
|
|
1777
1872
|
nameOrAlias: pkgNameOrAlias,
|
|
1778
|
-
exposes: [
|
|
1779
|
-
expose
|
|
1780
|
-
],
|
|
1873
|
+
exposes: [expose],
|
|
1781
1874
|
resourceCategory: 'sync',
|
|
1782
1875
|
share: false,
|
|
1783
|
-
depsRemote: false
|
|
1784
|
-
}
|
|
1876
|
+
depsRemote: false,
|
|
1877
|
+
},
|
|
1785
1878
|
};
|
|
1786
1879
|
const assets = await origin.remoteHandler.hooks.lifecycle.generatePreloadAssets.emit({
|
|
1787
1880
|
origin,
|
|
@@ -1789,17 +1882,18 @@ function snapshotPlugin() {
|
|
|
1789
1882
|
remoteInfo,
|
|
1790
1883
|
remote,
|
|
1791
1884
|
remoteSnapshot,
|
|
1792
|
-
globalSnapshot
|
|
1885
|
+
globalSnapshot,
|
|
1793
1886
|
});
|
|
1794
1887
|
if (assets) {
|
|
1795
1888
|
preloadAssets(remoteInfo, origin, assets, false);
|
|
1796
1889
|
}
|
|
1797
|
-
return
|
|
1798
|
-
|
|
1799
|
-
|
|
1890
|
+
return {
|
|
1891
|
+
...args,
|
|
1892
|
+
remoteSnapshot,
|
|
1893
|
+
};
|
|
1800
1894
|
}
|
|
1801
1895
|
return args;
|
|
1802
|
-
}
|
|
1896
|
+
},
|
|
1803
1897
|
};
|
|
1804
1898
|
}
|
|
1805
1899
|
|
|
@@ -1810,17 +1904,19 @@ function splitId(id) {
|
|
|
1810
1904
|
if (splitInfo.length === 1) {
|
|
1811
1905
|
return {
|
|
1812
1906
|
name: splitInfo[0],
|
|
1813
|
-
version: undefined
|
|
1907
|
+
version: undefined,
|
|
1814
1908
|
};
|
|
1815
|
-
}
|
|
1909
|
+
}
|
|
1910
|
+
else if (splitInfo.length === 2) {
|
|
1816
1911
|
return {
|
|
1817
1912
|
name: splitInfo[0],
|
|
1818
|
-
version: splitInfo[1]
|
|
1913
|
+
version: splitInfo[1],
|
|
1819
1914
|
};
|
|
1820
|
-
}
|
|
1915
|
+
}
|
|
1916
|
+
else {
|
|
1821
1917
|
return {
|
|
1822
1918
|
name: splitInfo[1],
|
|
1823
|
-
version: splitInfo[2]
|
|
1919
|
+
version: splitInfo[2],
|
|
1824
1920
|
};
|
|
1825
1921
|
}
|
|
1826
1922
|
}
|
|
@@ -1833,7 +1929,7 @@ function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo =
|
|
|
1833
1929
|
traverse(effectiveRemoteSnapshot, remoteInfo, isRoot);
|
|
1834
1930
|
if (effectiveRemoteSnapshot.remotesInfo) {
|
|
1835
1931
|
const remoteKeys = Object.keys(effectiveRemoteSnapshot.remotesInfo);
|
|
1836
|
-
for (const key of remoteKeys){
|
|
1932
|
+
for (const key of remoteKeys) {
|
|
1837
1933
|
if (memo[key]) {
|
|
1838
1934
|
continue;
|
|
1839
1935
|
}
|
|
@@ -1842,13 +1938,13 @@ function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo =
|
|
|
1842
1938
|
const remoteValue = effectiveRemoteSnapshot.remotesInfo[key];
|
|
1843
1939
|
traverseModuleInfo(globalSnapshot, {
|
|
1844
1940
|
name: subRemoteInfo.name,
|
|
1845
|
-
version: remoteValue.matchedVersion
|
|
1941
|
+
version: remoteValue.matchedVersion,
|
|
1846
1942
|
}, traverse, false, memo, undefined);
|
|
1847
1943
|
}
|
|
1848
1944
|
}
|
|
1849
1945
|
}
|
|
1850
1946
|
}
|
|
1851
|
-
const isExisted = (type, url)=>{
|
|
1947
|
+
const isExisted = (type, url) => {
|
|
1852
1948
|
return document.querySelector(`${type}[${type === 'link' ? 'href' : 'src'}="${url}"]`);
|
|
1853
1949
|
};
|
|
1854
1950
|
// eslint-disable-next-line max-lines-per-function
|
|
@@ -1862,15 +1958,17 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
1862
1958
|
const { preloadConfig: rootPreloadConfig } = preloadOptions;
|
|
1863
1959
|
const { depsRemote } = rootPreloadConfig;
|
|
1864
1960
|
const memo = {};
|
|
1865
|
-
traverseModuleInfo(globalSnapshot, remote, (moduleInfoSnapshot, remoteInfo, isRoot)=>{
|
|
1961
|
+
traverseModuleInfo(globalSnapshot, remote, (moduleInfoSnapshot, remoteInfo, isRoot) => {
|
|
1866
1962
|
let preloadConfig;
|
|
1867
1963
|
if (isRoot) {
|
|
1868
1964
|
preloadConfig = rootPreloadConfig;
|
|
1869
|
-
}
|
|
1965
|
+
}
|
|
1966
|
+
else {
|
|
1870
1967
|
if (Array.isArray(depsRemote)) {
|
|
1871
1968
|
// eslint-disable-next-line array-callback-return
|
|
1872
|
-
const findPreloadConfig = depsRemote.find((remoteConfig)=>{
|
|
1873
|
-
if (remoteConfig.nameOrAlias === remoteInfo.name ||
|
|
1969
|
+
const findPreloadConfig = depsRemote.find((remoteConfig) => {
|
|
1970
|
+
if (remoteConfig.nameOrAlias === remoteInfo.name ||
|
|
1971
|
+
remoteConfig.nameOrAlias === remoteInfo.alias) {
|
|
1874
1972
|
return true;
|
|
1875
1973
|
}
|
|
1876
1974
|
return false;
|
|
@@ -1879,9 +1977,11 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
1879
1977
|
return;
|
|
1880
1978
|
}
|
|
1881
1979
|
preloadConfig = defaultPreloadArgs(findPreloadConfig);
|
|
1882
|
-
}
|
|
1980
|
+
}
|
|
1981
|
+
else if (depsRemote === true) {
|
|
1883
1982
|
preloadConfig = rootPreloadConfig;
|
|
1884
|
-
}
|
|
1983
|
+
}
|
|
1984
|
+
else {
|
|
1885
1985
|
return;
|
|
1886
1986
|
}
|
|
1887
1987
|
}
|
|
@@ -1892,27 +1992,33 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
1892
1992
|
moduleInfo: {
|
|
1893
1993
|
name: remoteInfo.name,
|
|
1894
1994
|
entry: remoteEntryUrl,
|
|
1895
|
-
type: 'remoteEntryType' in moduleInfoSnapshot
|
|
1896
|
-
|
|
1995
|
+
type: 'remoteEntryType' in moduleInfoSnapshot
|
|
1996
|
+
? moduleInfoSnapshot.remoteEntryType
|
|
1997
|
+
: 'global',
|
|
1998
|
+
entryGlobalName: 'globalName' in moduleInfoSnapshot
|
|
1999
|
+
? moduleInfoSnapshot.globalName
|
|
2000
|
+
: remoteInfo.name,
|
|
1897
2001
|
shareScope: '',
|
|
1898
|
-
version: 'version' in moduleInfoSnapshot
|
|
2002
|
+
version: 'version' in moduleInfoSnapshot
|
|
2003
|
+
? moduleInfoSnapshot.version
|
|
2004
|
+
: undefined,
|
|
1899
2005
|
},
|
|
1900
|
-
url: remoteEntryUrl
|
|
2006
|
+
url: remoteEntryUrl,
|
|
1901
2007
|
});
|
|
1902
2008
|
}
|
|
1903
2009
|
let moduleAssetsInfo = 'modules' in moduleInfoSnapshot ? moduleInfoSnapshot.modules : [];
|
|
1904
2010
|
const normalizedPreloadExposes = normalizePreloadExposes(preloadConfig.exposes);
|
|
1905
2011
|
if (normalizedPreloadExposes.length && 'modules' in moduleInfoSnapshot) {
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
2012
|
+
moduleAssetsInfo = moduleInfoSnapshot?.modules?.reduce((assets, moduleAssetInfo) => {
|
|
2013
|
+
if (normalizedPreloadExposes?.indexOf(moduleAssetInfo.moduleName) !==
|
|
2014
|
+
-1) {
|
|
1909
2015
|
assets.push(moduleAssetInfo);
|
|
1910
2016
|
}
|
|
1911
2017
|
return assets;
|
|
1912
2018
|
}, []);
|
|
1913
2019
|
}
|
|
1914
2020
|
function handleAssets(assets) {
|
|
1915
|
-
const assetsRes = assets.map((asset)=>getResourceUrl(moduleInfoSnapshot, asset));
|
|
2021
|
+
const assetsRes = assets.map((asset) => getResourceUrl(moduleInfoSnapshot, asset));
|
|
1916
2022
|
if (preloadConfig.filter) {
|
|
1917
2023
|
return assetsRes.filter(preloadConfig.filter);
|
|
1918
2024
|
}
|
|
@@ -1920,7 +2026,7 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
1920
2026
|
}
|
|
1921
2027
|
if (moduleAssetsInfo) {
|
|
1922
2028
|
const assetsLength = moduleAssetsInfo.length;
|
|
1923
|
-
for(let index = 0; index < assetsLength; index++){
|
|
2029
|
+
for (let index = 0; index < assetsLength; index++) {
|
|
1924
2030
|
const assetsInfo = moduleAssetsInfo[index];
|
|
1925
2031
|
const exposeFullPath = `${remoteInfo.name}/${assetsInfo.moduleName}`;
|
|
1926
2032
|
origin.remoteHandler.hooks.lifecycle.handlePreloadModule.emit({
|
|
@@ -1929,7 +2035,7 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
1929
2035
|
remoteSnapshot: moduleInfoSnapshot,
|
|
1930
2036
|
preloadConfig,
|
|
1931
2037
|
remote: remoteInfo,
|
|
1932
|
-
origin
|
|
2038
|
+
origin,
|
|
1933
2039
|
});
|
|
1934
2040
|
const preloaded = getPreloaded(exposeFullPath);
|
|
1935
2041
|
if (preloaded) {
|
|
@@ -1940,8 +2046,9 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
1940
2046
|
cssAssets.push(...handleAssets(assetsInfo.assets.css.sync));
|
|
1941
2047
|
jsAssets.push(...handleAssets(assetsInfo.assets.js.async));
|
|
1942
2048
|
jsAssets.push(...handleAssets(assetsInfo.assets.js.sync));
|
|
1943
|
-
|
|
1944
|
-
}
|
|
2049
|
+
// eslint-disable-next-line no-constant-condition
|
|
2050
|
+
}
|
|
2051
|
+
else if ((preloadConfig.resourceCategory = 'sync')) {
|
|
1945
2052
|
cssAssets.push(...handleAssets(assetsInfo.assets.css.sync));
|
|
1946
2053
|
jsAssets.push(...handleAssets(assetsInfo.assets.js.sync));
|
|
1947
2054
|
}
|
|
@@ -1950,53 +2057,54 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
1950
2057
|
}
|
|
1951
2058
|
}, true, memo, remoteSnapshot);
|
|
1952
2059
|
if (remoteSnapshot.shared && remoteSnapshot.shared.length > 0) {
|
|
1953
|
-
const collectSharedAssets = (shareInfo, snapshotShared)=>{
|
|
2060
|
+
const collectSharedAssets = (shareInfo, snapshotShared) => {
|
|
1954
2061
|
const registeredShared = getRegisteredShare(origin.shareScopeMap, snapshotShared.sharedName, shareInfo, origin.sharedHandler.hooks.lifecycle.resolveShare);
|
|
1955
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.
|
|
1956
2063
|
if (registeredShared && typeof registeredShared.lib === 'function') {
|
|
1957
|
-
snapshotShared.assets.js.sync.forEach((asset)=>{
|
|
2064
|
+
snapshotShared.assets.js.sync.forEach((asset) => {
|
|
1958
2065
|
loadedSharedJsAssets.add(asset);
|
|
1959
2066
|
});
|
|
1960
|
-
snapshotShared.assets.css.sync.forEach((asset)=>{
|
|
2067
|
+
snapshotShared.assets.css.sync.forEach((asset) => {
|
|
1961
2068
|
loadedSharedCssAssets.add(asset);
|
|
1962
2069
|
});
|
|
1963
2070
|
}
|
|
1964
2071
|
};
|
|
1965
|
-
remoteSnapshot.shared.forEach((shared)=>{
|
|
1966
|
-
|
|
1967
|
-
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];
|
|
1968
2074
|
if (!shareInfos) {
|
|
1969
2075
|
return;
|
|
1970
2076
|
}
|
|
1971
2077
|
// if no version, preload all shared
|
|
1972
|
-
const sharedOptions = shared.version
|
|
2078
|
+
const sharedOptions = shared.version
|
|
2079
|
+
? shareInfos.find((s) => s.version === shared.version)
|
|
2080
|
+
: shareInfos;
|
|
1973
2081
|
if (!sharedOptions) {
|
|
1974
2082
|
return;
|
|
1975
2083
|
}
|
|
1976
2084
|
const arrayShareInfo = arrayOptions(sharedOptions);
|
|
1977
|
-
arrayShareInfo.forEach((s)=>{
|
|
2085
|
+
arrayShareInfo.forEach((s) => {
|
|
1978
2086
|
collectSharedAssets(s, shared);
|
|
1979
2087
|
});
|
|
1980
2088
|
});
|
|
1981
2089
|
}
|
|
1982
|
-
const needPreloadJsAssets = jsAssets.filter((asset)
|
|
1983
|
-
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));
|
|
1984
2092
|
return {
|
|
1985
2093
|
cssAssets: needPreloadCssAssets,
|
|
1986
2094
|
jsAssetsWithoutEntry: needPreloadJsAssets,
|
|
1987
|
-
entryAssets: entryAssets.filter((entry)
|
|
2095
|
+
entryAssets: entryAssets.filter((entry) => !isExisted('script', entry.url)),
|
|
1988
2096
|
};
|
|
1989
2097
|
}
|
|
1990
|
-
const generatePreloadAssetsPlugin = function() {
|
|
2098
|
+
const generatePreloadAssetsPlugin = function () {
|
|
1991
2099
|
return {
|
|
1992
2100
|
name: 'generate-preload-assets-plugin',
|
|
1993
|
-
async generatePreloadAssets
|
|
1994
|
-
const { origin, preloadOptions, remoteInfo, remote, globalSnapshot, remoteSnapshot } = args;
|
|
2101
|
+
async generatePreloadAssets(args) {
|
|
2102
|
+
const { origin, preloadOptions, remoteInfo, remote, globalSnapshot, remoteSnapshot, } = args;
|
|
1995
2103
|
if (!isBrowserEnv()) {
|
|
1996
2104
|
return {
|
|
1997
2105
|
cssAssets: [],
|
|
1998
2106
|
jsAssetsWithoutEntry: [],
|
|
1999
|
-
entryAssets: []
|
|
2107
|
+
entryAssets: [],
|
|
2000
2108
|
};
|
|
2001
2109
|
}
|
|
2002
2110
|
if (isRemoteInfoWithEntry(remote) && isPureRemoteEntry(remote)) {
|
|
@@ -2012,34 +2120,37 @@ const generatePreloadAssetsPlugin = function() {
|
|
|
2012
2120
|
entry: remote.entry,
|
|
2013
2121
|
type: remoteInfo.type || 'global',
|
|
2014
2122
|
entryGlobalName: '',
|
|
2015
|
-
shareScope: ''
|
|
2016
|
-
}
|
|
2017
|
-
}
|
|
2018
|
-
]
|
|
2123
|
+
shareScope: '',
|
|
2124
|
+
},
|
|
2125
|
+
},
|
|
2126
|
+
],
|
|
2019
2127
|
};
|
|
2020
2128
|
}
|
|
2021
2129
|
assignRemoteInfo(remoteInfo, remoteSnapshot);
|
|
2022
2130
|
const assets = generatePreloadAssets(origin, preloadOptions, remoteInfo, globalSnapshot, remoteSnapshot);
|
|
2023
2131
|
return assets;
|
|
2024
|
-
}
|
|
2132
|
+
},
|
|
2025
2133
|
};
|
|
2026
2134
|
};
|
|
2027
2135
|
|
|
2028
2136
|
function getGlobalRemoteInfo(moduleInfo, origin) {
|
|
2029
2137
|
const hostGlobalSnapshot = getGlobalSnapshotInfoByModuleInfo({
|
|
2030
2138
|
name: origin.name,
|
|
2031
|
-
version: origin.options.version
|
|
2139
|
+
version: origin.options.version,
|
|
2032
2140
|
});
|
|
2033
2141
|
// get remote detail info from global
|
|
2034
|
-
const globalRemoteInfo = hostGlobalSnapshot &&
|
|
2142
|
+
const globalRemoteInfo = hostGlobalSnapshot &&
|
|
2143
|
+
'remotesInfo' in hostGlobalSnapshot &&
|
|
2144
|
+
hostGlobalSnapshot.remotesInfo &&
|
|
2145
|
+
getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
|
|
2035
2146
|
if (globalRemoteInfo && globalRemoteInfo.matchedVersion) {
|
|
2036
2147
|
return {
|
|
2037
2148
|
hostGlobalSnapshot,
|
|
2038
2149
|
globalSnapshot: getGlobalSnapshot(),
|
|
2039
2150
|
remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
|
|
2040
2151
|
name: moduleInfo.name,
|
|
2041
|
-
version: globalRemoteInfo.matchedVersion
|
|
2042
|
-
})
|
|
2152
|
+
version: globalRemoteInfo.matchedVersion,
|
|
2153
|
+
}),
|
|
2043
2154
|
};
|
|
2044
2155
|
}
|
|
2045
2156
|
return {
|
|
@@ -2047,77 +2158,100 @@ function getGlobalRemoteInfo(moduleInfo, origin) {
|
|
|
2047
2158
|
globalSnapshot: getGlobalSnapshot(),
|
|
2048
2159
|
remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
|
|
2049
2160
|
name: moduleInfo.name,
|
|
2050
|
-
version: 'version' in moduleInfo ? moduleInfo.version : undefined
|
|
2051
|
-
})
|
|
2161
|
+
version: 'version' in moduleInfo ? moduleInfo.version : undefined,
|
|
2162
|
+
}),
|
|
2052
2163
|
};
|
|
2053
2164
|
}
|
|
2054
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
|
+
}
|
|
2055
2179
|
// eslint-disable-next-line max-lines-per-function
|
|
2056
|
-
async loadRemoteSnapshotInfo({ moduleInfo, id, expose }) {
|
|
2180
|
+
async loadRemoteSnapshotInfo({ moduleInfo, id, expose, }) {
|
|
2057
2181
|
const { options } = this.HostInstance;
|
|
2058
2182
|
await this.hooks.lifecycle.beforeLoadRemoteSnapshot.emit({
|
|
2059
2183
|
options,
|
|
2060
|
-
moduleInfo
|
|
2184
|
+
moduleInfo,
|
|
2061
2185
|
});
|
|
2062
2186
|
let hostSnapshot = getGlobalSnapshotInfoByModuleInfo({
|
|
2063
2187
|
name: this.HostInstance.options.name,
|
|
2064
|
-
version: this.HostInstance.options.version
|
|
2188
|
+
version: this.HostInstance.options.version,
|
|
2065
2189
|
});
|
|
2066
2190
|
if (!hostSnapshot) {
|
|
2067
2191
|
hostSnapshot = {
|
|
2068
2192
|
version: this.HostInstance.options.version || '',
|
|
2069
2193
|
remoteEntry: '',
|
|
2070
|
-
remotesInfo: {}
|
|
2194
|
+
remotesInfo: {},
|
|
2071
2195
|
};
|
|
2072
2196
|
addGlobalSnapshot({
|
|
2073
|
-
[this.HostInstance.options.name]: hostSnapshot
|
|
2197
|
+
[this.HostInstance.options.name]: hostSnapshot,
|
|
2074
2198
|
});
|
|
2075
2199
|
}
|
|
2076
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.
|
|
2077
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.
|
|
2078
|
-
if (hostSnapshot &&
|
|
2202
|
+
if (hostSnapshot &&
|
|
2203
|
+
'remotesInfo' in hostSnapshot &&
|
|
2204
|
+
!getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value) {
|
|
2079
2205
|
if ('version' in moduleInfo || 'entry' in moduleInfo) {
|
|
2080
|
-
hostSnapshot.remotesInfo =
|
|
2206
|
+
hostSnapshot.remotesInfo = {
|
|
2207
|
+
...hostSnapshot?.remotesInfo,
|
|
2081
2208
|
[moduleInfo.name]: {
|
|
2082
|
-
matchedVersion: 'version' in moduleInfo ? moduleInfo.version : moduleInfo.entry
|
|
2083
|
-
}
|
|
2084
|
-
}
|
|
2209
|
+
matchedVersion: 'version' in moduleInfo ? moduleInfo.version : moduleInfo.entry,
|
|
2210
|
+
},
|
|
2211
|
+
};
|
|
2085
2212
|
}
|
|
2086
2213
|
}
|
|
2087
2214
|
const { hostGlobalSnapshot, remoteSnapshot, globalSnapshot } = this.getGlobalRemoteInfo(moduleInfo);
|
|
2088
|
-
const { remoteSnapshot: globalRemoteSnapshot, globalSnapshot: globalSnapshotRes } = await this.hooks.lifecycle.loadSnapshot.emit({
|
|
2215
|
+
const { remoteSnapshot: globalRemoteSnapshot, globalSnapshot: globalSnapshotRes, } = await this.hooks.lifecycle.loadSnapshot.emit({
|
|
2089
2216
|
options,
|
|
2090
2217
|
moduleInfo,
|
|
2091
2218
|
hostGlobalSnapshot,
|
|
2092
2219
|
remoteSnapshot,
|
|
2093
|
-
globalSnapshot
|
|
2220
|
+
globalSnapshot,
|
|
2094
2221
|
});
|
|
2095
2222
|
let mSnapshot;
|
|
2096
2223
|
let gSnapshot;
|
|
2097
2224
|
// global snapshot includes manifest or module info includes manifest
|
|
2098
2225
|
if (globalRemoteSnapshot) {
|
|
2099
2226
|
if (isManifestProvider(globalRemoteSnapshot)) {
|
|
2100
|
-
const remoteEntry = isBrowserEnv()
|
|
2227
|
+
const remoteEntry = isBrowserEnv()
|
|
2228
|
+
? globalRemoteSnapshot.remoteEntry
|
|
2229
|
+
: globalRemoteSnapshot.ssrRemoteEntry ||
|
|
2230
|
+
globalRemoteSnapshot.remoteEntry ||
|
|
2231
|
+
'';
|
|
2101
2232
|
const moduleSnapshot = await this.getManifestJson(remoteEntry, moduleInfo, {});
|
|
2102
2233
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
2103
|
-
const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(
|
|
2234
|
+
const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo({
|
|
2235
|
+
...moduleInfo,
|
|
2104
2236
|
// The global remote may be overridden
|
|
2105
2237
|
// Therefore, set the snapshot key to the global address of the actual request
|
|
2106
|
-
entry: remoteEntry
|
|
2107
|
-
}
|
|
2238
|
+
entry: remoteEntry,
|
|
2239
|
+
}, moduleSnapshot);
|
|
2108
2240
|
mSnapshot = moduleSnapshot;
|
|
2109
2241
|
gSnapshot = globalSnapshotRes;
|
|
2110
|
-
}
|
|
2242
|
+
}
|
|
2243
|
+
else {
|
|
2111
2244
|
const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
|
|
2112
2245
|
options: this.HostInstance.options,
|
|
2113
2246
|
moduleInfo,
|
|
2114
2247
|
remoteSnapshot: globalRemoteSnapshot,
|
|
2115
|
-
from: 'global'
|
|
2248
|
+
from: 'global',
|
|
2116
2249
|
});
|
|
2117
2250
|
mSnapshot = remoteSnapshotRes;
|
|
2118
2251
|
gSnapshot = globalSnapshotRes;
|
|
2119
2252
|
}
|
|
2120
|
-
}
|
|
2253
|
+
}
|
|
2254
|
+
else {
|
|
2121
2255
|
if (isRemoteInfoWithEntry(moduleInfo)) {
|
|
2122
2256
|
// get from manifest.json and merge remote info from remote server
|
|
2123
2257
|
const moduleSnapshot = await this.getManifestJson(moduleInfo.entry, moduleInfo, {});
|
|
@@ -2127,15 +2261,16 @@ class SnapshotHandler {
|
|
|
2127
2261
|
options: this.HostInstance.options,
|
|
2128
2262
|
moduleInfo,
|
|
2129
2263
|
remoteSnapshot: moduleSnapshot,
|
|
2130
|
-
from: 'global'
|
|
2264
|
+
from: 'global',
|
|
2131
2265
|
});
|
|
2132
2266
|
mSnapshot = remoteSnapshotRes;
|
|
2133
2267
|
gSnapshot = globalSnapshotRes;
|
|
2134
|
-
}
|
|
2268
|
+
}
|
|
2269
|
+
else {
|
|
2135
2270
|
error(getShortErrorMsg(RUNTIME_007, runtimeDescMap, {
|
|
2136
2271
|
hostName: moduleInfo.name,
|
|
2137
2272
|
hostVersion: moduleInfo.version,
|
|
2138
|
-
globalSnapshot: JSON.stringify(globalSnapshotRes)
|
|
2273
|
+
globalSnapshot: JSON.stringify(globalSnapshotRes),
|
|
2139
2274
|
}));
|
|
2140
2275
|
}
|
|
2141
2276
|
}
|
|
@@ -2144,18 +2279,18 @@ class SnapshotHandler {
|
|
|
2144
2279
|
host: this.HostInstance,
|
|
2145
2280
|
options,
|
|
2146
2281
|
moduleInfo,
|
|
2147
|
-
remoteSnapshot: mSnapshot
|
|
2282
|
+
remoteSnapshot: mSnapshot,
|
|
2148
2283
|
});
|
|
2149
2284
|
return {
|
|
2150
2285
|
remoteSnapshot: mSnapshot,
|
|
2151
|
-
globalSnapshot: gSnapshot
|
|
2286
|
+
globalSnapshot: gSnapshot,
|
|
2152
2287
|
};
|
|
2153
2288
|
}
|
|
2154
2289
|
getGlobalRemoteInfo(moduleInfo) {
|
|
2155
2290
|
return getGlobalRemoteInfo(moduleInfo, this.HostInstance);
|
|
2156
2291
|
}
|
|
2157
2292
|
async getManifestJson(manifestUrl, moduleInfo, extraOptions) {
|
|
2158
|
-
const getManifest = async ()=>{
|
|
2293
|
+
const getManifest = async () => {
|
|
2159
2294
|
let manifestJson = this.manifestCache.get(manifestUrl);
|
|
2160
2295
|
if (manifestJson) {
|
|
2161
2296
|
return manifestJson;
|
|
@@ -2165,21 +2300,23 @@ class SnapshotHandler {
|
|
|
2165
2300
|
if (!res || !(res instanceof Response)) {
|
|
2166
2301
|
res = await fetch(manifestUrl, {});
|
|
2167
2302
|
}
|
|
2168
|
-
manifestJson = await res.json();
|
|
2169
|
-
}
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
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
|
+
}));
|
|
2177
2314
|
if (!manifestJson) {
|
|
2178
2315
|
delete this.manifestLoading[manifestUrl];
|
|
2179
2316
|
error(getShortErrorMsg(RUNTIME_003, runtimeDescMap, {
|
|
2180
2317
|
manifestUrl,
|
|
2181
2318
|
moduleName: moduleInfo.name,
|
|
2182
|
-
hostName: this.HostInstance.options.name
|
|
2319
|
+
hostName: this.HostInstance.options.name,
|
|
2183
2320
|
}, `${err}`));
|
|
2184
2321
|
}
|
|
2185
2322
|
}
|
|
@@ -2187,10 +2324,10 @@ class SnapshotHandler {
|
|
|
2187
2324
|
this.manifestCache.set(manifestUrl, manifestJson);
|
|
2188
2325
|
return manifestJson;
|
|
2189
2326
|
};
|
|
2190
|
-
const asyncLoadProcess = async ()=>{
|
|
2327
|
+
const asyncLoadProcess = async () => {
|
|
2191
2328
|
const manifestJson = await getManifest();
|
|
2192
2329
|
const remoteSnapshot = generateSnapshotFromManifest(manifestJson, {
|
|
2193
|
-
version: manifestUrl
|
|
2330
|
+
version: manifestUrl,
|
|
2194
2331
|
});
|
|
2195
2332
|
const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
|
|
2196
2333
|
options: this.HostInstance.options,
|
|
@@ -2198,38 +2335,40 @@ class SnapshotHandler {
|
|
|
2198
2335
|
manifestJson,
|
|
2199
2336
|
remoteSnapshot,
|
|
2200
2337
|
manifestUrl,
|
|
2201
|
-
from: 'manifest'
|
|
2338
|
+
from: 'manifest',
|
|
2202
2339
|
});
|
|
2203
2340
|
return remoteSnapshotRes;
|
|
2204
2341
|
};
|
|
2205
2342
|
if (!this.manifestLoading[manifestUrl]) {
|
|
2206
|
-
this.manifestLoading[manifestUrl] = asyncLoadProcess().then((res)=>res);
|
|
2343
|
+
this.manifestLoading[manifestUrl] = asyncLoadProcess().then((res) => res);
|
|
2207
2344
|
}
|
|
2208
2345
|
return this.manifestLoading[manifestUrl];
|
|
2209
2346
|
}
|
|
2210
|
-
constructor(HostInstance){
|
|
2211
|
-
this.loadingHostSnapshot = null;
|
|
2212
|
-
this.manifestCache = new Map();
|
|
2213
|
-
this.hooks = new PluginSystem({
|
|
2214
|
-
beforeLoadRemoteSnapshot: new AsyncHook('beforeLoadRemoteSnapshot'),
|
|
2215
|
-
loadSnapshot: new AsyncWaterfallHook('loadGlobalSnapshot'),
|
|
2216
|
-
loadRemoteSnapshot: new AsyncWaterfallHook('loadRemoteSnapshot'),
|
|
2217
|
-
afterLoadSnapshot: new AsyncWaterfallHook('afterLoadSnapshot')
|
|
2218
|
-
});
|
|
2219
|
-
this.manifestLoading = Global.__FEDERATION__.__MANIFEST_LOADING__;
|
|
2220
|
-
this.HostInstance = HostInstance;
|
|
2221
|
-
this.loaderHook = HostInstance.loaderHook;
|
|
2222
|
-
}
|
|
2223
2347
|
}
|
|
2224
2348
|
|
|
2225
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
|
+
}
|
|
2226
2365
|
// register shared in shareScopeMap
|
|
2227
2366
|
registerShared(globalOptions, userOptions) {
|
|
2228
2367
|
const { shareInfos, shared } = formatShareConfigs(globalOptions, userOptions);
|
|
2229
2368
|
const sharedKeys = Object.keys(shareInfos);
|
|
2230
|
-
sharedKeys.forEach((sharedKey)=>{
|
|
2369
|
+
sharedKeys.forEach((sharedKey) => {
|
|
2231
2370
|
const sharedVals = shareInfos[sharedKey];
|
|
2232
|
-
sharedVals.forEach((sharedVal)=>{
|
|
2371
|
+
sharedVals.forEach((sharedVal) => {
|
|
2233
2372
|
const registeredShared = getRegisteredShare(this.shareScopeMap, sharedKey, sharedVal, this.hooks.lifecycle.resolveShare);
|
|
2234
2373
|
if (!registeredShared && sharedVal && sharedVal.lib) {
|
|
2235
2374
|
this.setShared({
|
|
@@ -2238,14 +2377,14 @@ class SharedHandler {
|
|
|
2238
2377
|
get: sharedVal.get,
|
|
2239
2378
|
loaded: true,
|
|
2240
2379
|
shared: sharedVal,
|
|
2241
|
-
from: userOptions.name
|
|
2380
|
+
from: userOptions.name,
|
|
2242
2381
|
});
|
|
2243
2382
|
}
|
|
2244
2383
|
});
|
|
2245
2384
|
});
|
|
2246
2385
|
return {
|
|
2247
2386
|
shareInfos,
|
|
2248
|
-
shared
|
|
2387
|
+
shared,
|
|
2249
2388
|
};
|
|
2250
2389
|
}
|
|
2251
2390
|
async loadShare(pkgName, extraOptions) {
|
|
@@ -2257,12 +2396,12 @@ class SharedHandler {
|
|
|
2257
2396
|
const shareOptions = getTargetSharedOptions({
|
|
2258
2397
|
pkgName,
|
|
2259
2398
|
extraOptions,
|
|
2260
|
-
shareInfos: host.options.shared
|
|
2399
|
+
shareInfos: host.options.shared,
|
|
2261
2400
|
});
|
|
2262
|
-
if (shareOptions
|
|
2263
|
-
await Promise.all(shareOptions.scope.map(async (shareScope)=>{
|
|
2401
|
+
if (shareOptions?.scope) {
|
|
2402
|
+
await Promise.all(shareOptions.scope.map(async (shareScope) => {
|
|
2264
2403
|
await Promise.all(this.initializeSharing(shareScope, {
|
|
2265
|
-
strategy: shareOptions.strategy
|
|
2404
|
+
strategy: shareOptions.strategy,
|
|
2266
2405
|
}));
|
|
2267
2406
|
return;
|
|
2268
2407
|
}));
|
|
@@ -2271,14 +2410,14 @@ class SharedHandler {
|
|
|
2271
2410
|
pkgName,
|
|
2272
2411
|
shareInfo: shareOptions,
|
|
2273
2412
|
shared: host.options.shared,
|
|
2274
|
-
origin: host
|
|
2413
|
+
origin: host,
|
|
2275
2414
|
});
|
|
2276
2415
|
const { shareInfo: shareOptionsRes } = loadShareRes;
|
|
2277
2416
|
// Assert that shareInfoRes exists, if not, throw an error
|
|
2278
2417
|
assert(shareOptionsRes, `Cannot find ${pkgName} Share in the ${host.options.name}. Please ensure that the ${pkgName} Share parameters have been injected`);
|
|
2279
2418
|
// Retrieve from cache
|
|
2280
2419
|
const registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareOptionsRes, this.hooks.lifecycle.resolveShare);
|
|
2281
|
-
const addUseIn = (shared)=>{
|
|
2420
|
+
const addUseIn = (shared) => {
|
|
2282
2421
|
if (!shared.useIn) {
|
|
2283
2422
|
shared.useIn = [];
|
|
2284
2423
|
}
|
|
@@ -2287,7 +2426,10 @@ class SharedHandler {
|
|
|
2287
2426
|
if (registeredShared && registeredShared.lib) {
|
|
2288
2427
|
addUseIn(registeredShared);
|
|
2289
2428
|
return registeredShared.lib;
|
|
2290
|
-
}
|
|
2429
|
+
}
|
|
2430
|
+
else if (registeredShared &&
|
|
2431
|
+
registeredShared.loading &&
|
|
2432
|
+
!registeredShared.loaded) {
|
|
2291
2433
|
const factory = await registeredShared.loading;
|
|
2292
2434
|
registeredShared.loaded = true;
|
|
2293
2435
|
if (!registeredShared.lib) {
|
|
@@ -2295,8 +2437,9 @@ class SharedHandler {
|
|
|
2295
2437
|
}
|
|
2296
2438
|
addUseIn(registeredShared);
|
|
2297
2439
|
return factory;
|
|
2298
|
-
}
|
|
2299
|
-
|
|
2440
|
+
}
|
|
2441
|
+
else if (registeredShared) {
|
|
2442
|
+
const asyncLoadProcess = async () => {
|
|
2300
2443
|
const factory = await registeredShared.get();
|
|
2301
2444
|
addUseIn(registeredShared);
|
|
2302
2445
|
registeredShared.loaded = true;
|
|
@@ -2310,14 +2453,15 @@ class SharedHandler {
|
|
|
2310
2453
|
shared: registeredShared,
|
|
2311
2454
|
from: host.options.name,
|
|
2312
2455
|
lib: null,
|
|
2313
|
-
loading
|
|
2456
|
+
loading,
|
|
2314
2457
|
});
|
|
2315
2458
|
return loading;
|
|
2316
|
-
}
|
|
2317
|
-
|
|
2459
|
+
}
|
|
2460
|
+
else {
|
|
2461
|
+
if (extraOptions?.customShareInfo) {
|
|
2318
2462
|
return false;
|
|
2319
2463
|
}
|
|
2320
|
-
const asyncLoadProcess = async ()=>{
|
|
2464
|
+
const asyncLoadProcess = async () => {
|
|
2321
2465
|
const factory = await shareOptionsRes.get();
|
|
2322
2466
|
shareOptionsRes.lib = factory;
|
|
2323
2467
|
shareOptionsRes.loaded = true;
|
|
@@ -2337,7 +2481,7 @@ class SharedHandler {
|
|
|
2337
2481
|
shared: shareOptionsRes,
|
|
2338
2482
|
from: host.options.name,
|
|
2339
2483
|
lib: null,
|
|
2340
|
-
loading
|
|
2484
|
+
loading,
|
|
2341
2485
|
});
|
|
2342
2486
|
return loading;
|
|
2343
2487
|
}
|
|
@@ -2346,21 +2490,23 @@ class SharedHandler {
|
|
|
2346
2490
|
* This function initializes the sharing sequence (executed only once per share scope).
|
|
2347
2491
|
* It accepts one argument, the name of the share scope.
|
|
2348
2492
|
* If the share scope does not exist, it creates one.
|
|
2349
|
-
*/
|
|
2493
|
+
*/
|
|
2494
|
+
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
2350
2495
|
initializeSharing(shareScopeName = DEFAULT_SCOPE, extraOptions) {
|
|
2351
2496
|
const { host } = this;
|
|
2352
|
-
const from = extraOptions
|
|
2353
|
-
const strategy = extraOptions
|
|
2354
|
-
let initScope = extraOptions
|
|
2497
|
+
const from = extraOptions?.from;
|
|
2498
|
+
const strategy = extraOptions?.strategy;
|
|
2499
|
+
let initScope = extraOptions?.initScope;
|
|
2355
2500
|
const promises = [];
|
|
2356
2501
|
if (from !== 'build') {
|
|
2357
2502
|
const { initTokens } = this;
|
|
2358
|
-
if (!initScope)
|
|
2503
|
+
if (!initScope)
|
|
2504
|
+
initScope = [];
|
|
2359
2505
|
let initToken = initTokens[shareScopeName];
|
|
2360
|
-
if (!initToken)
|
|
2361
|
-
from: this.host.name
|
|
2362
|
-
|
|
2363
|
-
|
|
2506
|
+
if (!initToken)
|
|
2507
|
+
initToken = initTokens[shareScopeName] = { from: this.host.name };
|
|
2508
|
+
if (initScope.indexOf(initToken) >= 0)
|
|
2509
|
+
return promises;
|
|
2364
2510
|
initScope.push(initToken);
|
|
2365
2511
|
}
|
|
2366
2512
|
const shareScope = this.shareScopeMap;
|
|
@@ -2371,34 +2517,41 @@ class SharedHandler {
|
|
|
2371
2517
|
}
|
|
2372
2518
|
// Executes all initialization snippets from all accessible modules
|
|
2373
2519
|
const scope = shareScope[shareScopeName];
|
|
2374
|
-
const register = (name, shared)=>{
|
|
2375
|
-
var _activeVersion_shareConfig;
|
|
2520
|
+
const register = (name, shared) => {
|
|
2376
2521
|
const { version, eager } = shared;
|
|
2377
2522
|
scope[name] = scope[name] || {};
|
|
2378
2523
|
const versions = scope[name];
|
|
2379
2524
|
const activeVersion = versions[version];
|
|
2380
|
-
const activeVersionEager = Boolean(activeVersion &&
|
|
2381
|
-
|
|
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))) {
|
|
2382
2533
|
versions[version] = shared;
|
|
2383
2534
|
}
|
|
2384
2535
|
};
|
|
2385
|
-
const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName], initScope);
|
|
2386
|
-
const initRemoteModule = async (key)=>{
|
|
2536
|
+
const initFn = (mod) => mod && mod.init && mod.init(shareScope[shareScopeName], initScope);
|
|
2537
|
+
const initRemoteModule = async (key) => {
|
|
2387
2538
|
const { module } = await host.remoteHandler.getRemoteModuleAndOptions({
|
|
2388
|
-
id: key
|
|
2539
|
+
id: key,
|
|
2389
2540
|
});
|
|
2390
2541
|
if (module.getEntry) {
|
|
2391
2542
|
let remoteEntryExports;
|
|
2392
2543
|
try {
|
|
2393
2544
|
remoteEntryExports = await module.getEntry();
|
|
2394
|
-
}
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
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
|
+
}));
|
|
2402
2555
|
}
|
|
2403
2556
|
if (!module.inited) {
|
|
2404
2557
|
await initFn(remoteEntryExports);
|
|
@@ -2406,17 +2559,18 @@ class SharedHandler {
|
|
|
2406
2559
|
}
|
|
2407
2560
|
}
|
|
2408
2561
|
};
|
|
2409
|
-
Object.keys(host.options.shared).forEach((shareName)=>{
|
|
2562
|
+
Object.keys(host.options.shared).forEach((shareName) => {
|
|
2410
2563
|
const sharedArr = host.options.shared[shareName];
|
|
2411
|
-
sharedArr.forEach((shared)=>{
|
|
2564
|
+
sharedArr.forEach((shared) => {
|
|
2412
2565
|
if (shared.scope.includes(shareScopeName)) {
|
|
2413
2566
|
register(shareName, shared);
|
|
2414
2567
|
}
|
|
2415
2568
|
});
|
|
2416
2569
|
});
|
|
2417
2570
|
// TODO: strategy==='version-first' need to be removed in the future
|
|
2418
|
-
if (host.options.shareStrategy === 'version-first' ||
|
|
2419
|
-
|
|
2571
|
+
if (host.options.shareStrategy === 'version-first' ||
|
|
2572
|
+
strategy === 'version-first') {
|
|
2573
|
+
host.options.remotes.forEach((remote) => {
|
|
2420
2574
|
if (remote.shareScope === shareScopeName) {
|
|
2421
2575
|
promises.push(initRemoteModule(remote.name));
|
|
2422
2576
|
}
|
|
@@ -2433,17 +2587,15 @@ class SharedHandler {
|
|
|
2433
2587
|
const shareOptions = getTargetSharedOptions({
|
|
2434
2588
|
pkgName,
|
|
2435
2589
|
extraOptions,
|
|
2436
|
-
shareInfos: host.options.shared
|
|
2590
|
+
shareInfos: host.options.shared,
|
|
2437
2591
|
});
|
|
2438
|
-
if (shareOptions
|
|
2439
|
-
shareOptions.scope.forEach((shareScope)=>{
|
|
2440
|
-
this.initializeSharing(shareScope, {
|
|
2441
|
-
strategy: shareOptions.strategy
|
|
2442
|
-
});
|
|
2592
|
+
if (shareOptions?.scope) {
|
|
2593
|
+
shareOptions.scope.forEach((shareScope) => {
|
|
2594
|
+
this.initializeSharing(shareScope, { strategy: shareOptions.strategy });
|
|
2443
2595
|
});
|
|
2444
2596
|
}
|
|
2445
2597
|
const registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareOptions, this.hooks.lifecycle.resolveShare);
|
|
2446
|
-
const addUseIn = (shared)=>{
|
|
2598
|
+
const addUseIn = (shared) => {
|
|
2447
2599
|
if (!shared.useIn) {
|
|
2448
2600
|
shared.useIn = [];
|
|
2449
2601
|
}
|
|
@@ -2469,7 +2621,7 @@ class SharedHandler {
|
|
|
2469
2621
|
loaded: true,
|
|
2470
2622
|
from: host.options.name,
|
|
2471
2623
|
lib: module,
|
|
2472
|
-
shared: registeredShared
|
|
2624
|
+
shared: registeredShared,
|
|
2473
2625
|
});
|
|
2474
2626
|
return module;
|
|
2475
2627
|
}
|
|
@@ -2484,10 +2636,10 @@ class SharedHandler {
|
|
|
2484
2636
|
if (shareOptions.get) {
|
|
2485
2637
|
const module = shareOptions.get();
|
|
2486
2638
|
if (module instanceof Promise) {
|
|
2487
|
-
const errorCode =
|
|
2639
|
+
const errorCode = extraOptions?.from === 'build' ? RUNTIME_005 : RUNTIME_006;
|
|
2488
2640
|
throw new Error(getShortErrorMsg(errorCode, runtimeDescMap, {
|
|
2489
2641
|
hostName: host.options.name,
|
|
2490
|
-
sharedPkgName: pkgName
|
|
2642
|
+
sharedPkgName: pkgName,
|
|
2491
2643
|
}));
|
|
2492
2644
|
}
|
|
2493
2645
|
shareOptions.lib = module;
|
|
@@ -2496,13 +2648,13 @@ class SharedHandler {
|
|
|
2496
2648
|
loaded: true,
|
|
2497
2649
|
from: host.options.name,
|
|
2498
2650
|
lib: shareOptions.lib,
|
|
2499
|
-
shared: shareOptions
|
|
2651
|
+
shared: shareOptions,
|
|
2500
2652
|
});
|
|
2501
2653
|
return shareOptions.lib;
|
|
2502
2654
|
}
|
|
2503
2655
|
throw new Error(getShortErrorMsg(RUNTIME_006, runtimeDescMap, {
|
|
2504
2656
|
hostName: host.options.name,
|
|
2505
|
-
sharedPkgName: pkgName
|
|
2657
|
+
sharedPkgName: pkgName,
|
|
2506
2658
|
}));
|
|
2507
2659
|
}
|
|
2508
2660
|
initShareScopeMap(scopeName, shareScope, extraOptions = {}) {
|
|
@@ -2513,18 +2665,13 @@ class SharedHandler {
|
|
|
2513
2665
|
options: host.options,
|
|
2514
2666
|
origin: host,
|
|
2515
2667
|
scopeName,
|
|
2516
|
-
hostShareScopeMap: extraOptions.hostShareScopeMap
|
|
2668
|
+
hostShareScopeMap: extraOptions.hostShareScopeMap,
|
|
2517
2669
|
});
|
|
2518
2670
|
}
|
|
2519
|
-
setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
|
|
2520
|
-
const { version, scope = 'default'
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
]);
|
|
2524
|
-
const scopes = Array.isArray(scope) ? scope : [
|
|
2525
|
-
scope
|
|
2526
|
-
];
|
|
2527
|
-
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) => {
|
|
2528
2675
|
if (!this.shareScopeMap[sc]) {
|
|
2529
2676
|
this.shareScopeMap[sc] = {};
|
|
2530
2677
|
}
|
|
@@ -2532,16 +2679,14 @@ class SharedHandler {
|
|
|
2532
2679
|
this.shareScopeMap[sc][pkgName] = {};
|
|
2533
2680
|
}
|
|
2534
2681
|
if (!this.shareScopeMap[sc][pkgName][version]) {
|
|
2535
|
-
this.shareScopeMap[sc][pkgName][version] =
|
|
2682
|
+
this.shareScopeMap[sc][pkgName][version] = {
|
|
2536
2683
|
version,
|
|
2537
|
-
scope: [
|
|
2538
|
-
|
|
2539
|
-
]
|
|
2540
|
-
}, shareInfo, {
|
|
2684
|
+
scope: ['default'],
|
|
2685
|
+
...shareInfo,
|
|
2541
2686
|
lib,
|
|
2542
2687
|
loaded,
|
|
2543
|
-
loading
|
|
2544
|
-
}
|
|
2688
|
+
loading,
|
|
2689
|
+
};
|
|
2545
2690
|
if (get) {
|
|
2546
2691
|
this.shareScopeMap[sc][pkgName][version].get = get;
|
|
2547
2692
|
}
|
|
@@ -2566,54 +2711,45 @@ class SharedHandler {
|
|
|
2566
2711
|
globalShareScopeMap[identifier] = this.shareScopeMap;
|
|
2567
2712
|
}
|
|
2568
2713
|
}
|
|
2569
|
-
|
|
2714
|
+
}
|
|
2715
|
+
|
|
2716
|
+
class RemoteHandler {
|
|
2717
|
+
constructor(host) {
|
|
2570
2718
|
this.hooks = new PluginSystem({
|
|
2571
|
-
|
|
2572
|
-
|
|
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'),
|
|
2573
2727
|
// not used yet
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
// maybe will change, temporarily for internal use only
|
|
2577
|
-
initContainerShareScopeMap: new SyncWaterfallHook('initContainerShareScopeMap')
|
|
2728
|
+
afterPreloadRemote: new AsyncHook(),
|
|
2729
|
+
loadEntry: new AsyncHook(),
|
|
2578
2730
|
});
|
|
2579
2731
|
this.host = host;
|
|
2580
|
-
this.
|
|
2581
|
-
this.initTokens = {};
|
|
2582
|
-
this._setGlobalShareScopeMap(host.options);
|
|
2732
|
+
this.idToRemoteMap = {};
|
|
2583
2733
|
}
|
|
2584
|
-
}
|
|
2585
|
-
|
|
2586
|
-
class RemoteHandler {
|
|
2587
2734
|
formatAndRegisterRemote(globalOptions, userOptions) {
|
|
2588
2735
|
const userRemotes = userOptions.remotes || [];
|
|
2589
|
-
return userRemotes.reduce((res, remote)=>{
|
|
2590
|
-
this.registerRemote(remote, res, {
|
|
2591
|
-
force: false
|
|
2592
|
-
});
|
|
2736
|
+
return userRemotes.reduce((res, remote) => {
|
|
2737
|
+
this.registerRemote(remote, res, { force: false });
|
|
2593
2738
|
return res;
|
|
2594
2739
|
}, globalOptions.remotes);
|
|
2595
2740
|
}
|
|
2596
2741
|
setIdToRemoteMap(id, remoteMatchInfo) {
|
|
2597
2742
|
const { remote, expose } = remoteMatchInfo;
|
|
2598
2743
|
const { name, alias } = remote;
|
|
2599
|
-
this.idToRemoteMap[id] = {
|
|
2600
|
-
name: remote.name,
|
|
2601
|
-
expose
|
|
2602
|
-
};
|
|
2744
|
+
this.idToRemoteMap[id] = { name: remote.name, expose };
|
|
2603
2745
|
if (alias && id.startsWith(name)) {
|
|
2604
2746
|
const idWithAlias = id.replace(name, alias);
|
|
2605
|
-
this.idToRemoteMap[idWithAlias] = {
|
|
2606
|
-
name: remote.name,
|
|
2607
|
-
expose
|
|
2608
|
-
};
|
|
2747
|
+
this.idToRemoteMap[idWithAlias] = { name: remote.name, expose };
|
|
2609
2748
|
return;
|
|
2610
2749
|
}
|
|
2611
2750
|
if (alias && id.startsWith(alias)) {
|
|
2612
2751
|
const idWithName = id.replace(alias, name);
|
|
2613
|
-
this.idToRemoteMap[idWithName] = {
|
|
2614
|
-
name: remote.name,
|
|
2615
|
-
expose
|
|
2616
|
-
};
|
|
2752
|
+
this.idToRemoteMap[idWithName] = { name: remote.name, expose };
|
|
2617
2753
|
}
|
|
2618
2754
|
}
|
|
2619
2755
|
// eslint-disable-next-line max-lines-per-function
|
|
@@ -2622,7 +2758,7 @@ class RemoteHandler {
|
|
|
2622
2758
|
const { host } = this;
|
|
2623
2759
|
try {
|
|
2624
2760
|
const { loadFactory = true } = options || {
|
|
2625
|
-
loadFactory: true
|
|
2761
|
+
loadFactory: true,
|
|
2626
2762
|
};
|
|
2627
2763
|
// 1. Validate the parameters of the retrieved module. There are two module request methods: pkgName + expose and alias + expose.
|
|
2628
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.
|
|
@@ -2632,10 +2768,10 @@ class RemoteHandler {
|
|
|
2632
2768
|
// id: alias(app1) + expose(button) = app1/button
|
|
2633
2769
|
// id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort
|
|
2634
2770
|
const { module, moduleOptions, remoteMatchInfo } = await this.getRemoteModuleAndOptions({
|
|
2635
|
-
id
|
|
2771
|
+
id,
|
|
2636
2772
|
});
|
|
2637
|
-
const { pkgNameOrAlias, remote, expose, id: idRes, remoteSnapshot } = remoteMatchInfo;
|
|
2638
|
-
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));
|
|
2639
2775
|
const moduleWrapper = await this.hooks.lifecycle.onLoad.emit({
|
|
2640
2776
|
id: idRes,
|
|
2641
2777
|
pkgNameOrAlias,
|
|
@@ -2645,23 +2781,22 @@ class RemoteHandler {
|
|
|
2645
2781
|
remote,
|
|
2646
2782
|
options: moduleOptions,
|
|
2647
2783
|
moduleInstance: module,
|
|
2648
|
-
origin: host
|
|
2784
|
+
origin: host,
|
|
2649
2785
|
});
|
|
2650
2786
|
this.setIdToRemoteMap(id, remoteMatchInfo);
|
|
2651
2787
|
if (typeof moduleWrapper === 'function') {
|
|
2652
2788
|
return moduleWrapper;
|
|
2653
2789
|
}
|
|
2654
2790
|
return moduleOrFactory;
|
|
2655
|
-
}
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
};
|
|
2791
|
+
}
|
|
2792
|
+
catch (error) {
|
|
2793
|
+
const { from = 'runtime' } = options || { from: 'runtime' };
|
|
2659
2794
|
const failOver = await this.hooks.lifecycle.errorLoadRemote.emit({
|
|
2660
2795
|
id,
|
|
2661
2796
|
error,
|
|
2662
2797
|
from,
|
|
2663
2798
|
lifecycle: 'onLoad',
|
|
2664
|
-
origin: host
|
|
2799
|
+
origin: host,
|
|
2665
2800
|
});
|
|
2666
2801
|
if (!failOver) {
|
|
2667
2802
|
throw error;
|
|
@@ -2675,14 +2810,14 @@ class RemoteHandler {
|
|
|
2675
2810
|
await this.hooks.lifecycle.beforePreloadRemote.emit({
|
|
2676
2811
|
preloadOps: preloadOptions,
|
|
2677
2812
|
options: host.options,
|
|
2678
|
-
origin: host
|
|
2813
|
+
origin: host,
|
|
2679
2814
|
});
|
|
2680
2815
|
const preloadOps = formatPreloadArgs(host.options.remotes, preloadOptions);
|
|
2681
|
-
await Promise.all(preloadOps.map(async (ops)=>{
|
|
2816
|
+
await Promise.all(preloadOps.map(async (ops) => {
|
|
2682
2817
|
const { remote } = ops;
|
|
2683
2818
|
const remoteInfo = getRemoteInfo(remote);
|
|
2684
2819
|
const { globalSnapshot, remoteSnapshot } = await host.snapshotHandler.loadRemoteSnapshotInfo({
|
|
2685
|
-
moduleInfo: remote
|
|
2820
|
+
moduleInfo: remote,
|
|
2686
2821
|
});
|
|
2687
2822
|
const assets = await this.hooks.lifecycle.generatePreloadAssets.emit({
|
|
2688
2823
|
origin: host,
|
|
@@ -2690,7 +2825,7 @@ class RemoteHandler {
|
|
|
2690
2825
|
remote,
|
|
2691
2826
|
remoteInfo,
|
|
2692
2827
|
globalSnapshot,
|
|
2693
|
-
remoteSnapshot
|
|
2828
|
+
remoteSnapshot,
|
|
2694
2829
|
});
|
|
2695
2830
|
if (!assets) {
|
|
2696
2831
|
return;
|
|
@@ -2700,9 +2835,9 @@ class RemoteHandler {
|
|
|
2700
2835
|
}
|
|
2701
2836
|
registerRemotes(remotes, options) {
|
|
2702
2837
|
const { host } = this;
|
|
2703
|
-
remotes.forEach((remote)=>{
|
|
2838
|
+
remotes.forEach((remote) => {
|
|
2704
2839
|
this.registerRemote(remote, host.options.remotes, {
|
|
2705
|
-
force: options
|
|
2840
|
+
force: options?.force,
|
|
2706
2841
|
});
|
|
2707
2842
|
});
|
|
2708
2843
|
}
|
|
@@ -2714,17 +2849,18 @@ class RemoteHandler {
|
|
|
2714
2849
|
loadRemoteArgs = await this.hooks.lifecycle.beforeRequest.emit({
|
|
2715
2850
|
id,
|
|
2716
2851
|
options: host.options,
|
|
2717
|
-
origin: host
|
|
2852
|
+
origin: host,
|
|
2718
2853
|
});
|
|
2719
|
-
}
|
|
2720
|
-
|
|
2854
|
+
}
|
|
2855
|
+
catch (error) {
|
|
2856
|
+
loadRemoteArgs = (await this.hooks.lifecycle.errorLoadRemote.emit({
|
|
2721
2857
|
id,
|
|
2722
2858
|
options: host.options,
|
|
2723
2859
|
origin: host,
|
|
2724
2860
|
from: 'runtime',
|
|
2725
2861
|
error,
|
|
2726
|
-
lifecycle: 'beforeRequest'
|
|
2727
|
-
});
|
|
2862
|
+
lifecycle: 'beforeRequest',
|
|
2863
|
+
}));
|
|
2728
2864
|
if (!loadRemoteArgs) {
|
|
2729
2865
|
throw error;
|
|
2730
2866
|
}
|
|
@@ -2733,23 +2869,23 @@ class RemoteHandler {
|
|
|
2733
2869
|
const remoteSplitInfo = matchRemoteWithNameAndExpose(host.options.remotes, idRes);
|
|
2734
2870
|
assert(remoteSplitInfo, getShortErrorMsg(RUNTIME_004, runtimeDescMap, {
|
|
2735
2871
|
hostName: host.options.name,
|
|
2736
|
-
requestId: idRes
|
|
2872
|
+
requestId: idRes,
|
|
2737
2873
|
}));
|
|
2738
2874
|
const { remote: rawRemote } = remoteSplitInfo;
|
|
2739
2875
|
const remoteInfo = getRemoteInfo(rawRemote);
|
|
2740
|
-
const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit(
|
|
2741
|
-
id: idRes
|
|
2742
|
-
|
|
2876
|
+
const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit({
|
|
2877
|
+
id: idRes,
|
|
2878
|
+
...remoteSplitInfo,
|
|
2743
2879
|
options: host.options,
|
|
2744
2880
|
origin: host,
|
|
2745
|
-
remoteInfo
|
|
2746
|
-
})
|
|
2881
|
+
remoteInfo,
|
|
2882
|
+
});
|
|
2747
2883
|
const { remote, expose } = matchInfo;
|
|
2748
2884
|
assert(remote && expose, `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`);
|
|
2749
2885
|
let module = host.moduleCache.get(remote.name);
|
|
2750
2886
|
const moduleOptions = {
|
|
2751
2887
|
host: host,
|
|
2752
|
-
remoteInfo
|
|
2888
|
+
remoteInfo,
|
|
2753
2889
|
};
|
|
2754
2890
|
if (!module) {
|
|
2755
2891
|
module = new Module(moduleOptions);
|
|
@@ -2758,19 +2894,18 @@ class RemoteHandler {
|
|
|
2758
2894
|
return {
|
|
2759
2895
|
module,
|
|
2760
2896
|
moduleOptions,
|
|
2761
|
-
remoteMatchInfo: matchInfo
|
|
2897
|
+
remoteMatchInfo: matchInfo,
|
|
2762
2898
|
};
|
|
2763
2899
|
}
|
|
2764
2900
|
registerRemote(remote, targetRemotes, options) {
|
|
2765
2901
|
const { host } = this;
|
|
2766
|
-
const normalizeRemote = ()=>{
|
|
2902
|
+
const normalizeRemote = () => {
|
|
2767
2903
|
if (remote.alias) {
|
|
2768
2904
|
// Validate if alias equals the prefix of remote.name and remote.alias, if so, throw an error
|
|
2769
2905
|
// As multi-level path references cannot guarantee unique names, alias being a prefix of remote.name is not supported
|
|
2770
|
-
const findEqual = targetRemotes.find((item)=>
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
});
|
|
2906
|
+
const findEqual = targetRemotes.find((item) => remote.alias &&
|
|
2907
|
+
(item.name.startsWith(remote.alias) ||
|
|
2908
|
+
item.alias?.startsWith(remote.alias)));
|
|
2774
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`);
|
|
2775
2910
|
}
|
|
2776
2911
|
// Set the remote entry to a complete path
|
|
@@ -2786,32 +2921,24 @@ class RemoteHandler {
|
|
|
2786
2921
|
remote.type = DEFAULT_REMOTE_TYPE;
|
|
2787
2922
|
}
|
|
2788
2923
|
};
|
|
2789
|
-
this.hooks.lifecycle.beforeRegisterRemote.emit({
|
|
2790
|
-
|
|
2791
|
-
origin: host
|
|
2792
|
-
});
|
|
2793
|
-
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);
|
|
2794
2926
|
if (!registeredRemote) {
|
|
2795
2927
|
normalizeRemote();
|
|
2796
2928
|
targetRemotes.push(remote);
|
|
2797
|
-
this.hooks.lifecycle.registerRemote.emit({
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
});
|
|
2801
|
-
} else {
|
|
2929
|
+
this.hooks.lifecycle.registerRemote.emit({ remote, origin: host });
|
|
2930
|
+
}
|
|
2931
|
+
else {
|
|
2802
2932
|
const messages = [
|
|
2803
2933
|
`The remote "${remote.name}" is already registered.`,
|
|
2804
|
-
'Please note that overriding it may cause unexpected errors.'
|
|
2934
|
+
'Please note that overriding it may cause unexpected errors.',
|
|
2805
2935
|
];
|
|
2806
|
-
if (options
|
|
2936
|
+
if (options?.force) {
|
|
2807
2937
|
// remove registered remote
|
|
2808
2938
|
this.removeRemote(registeredRemote);
|
|
2809
2939
|
normalizeRemote();
|
|
2810
2940
|
targetRemotes.push(remote);
|
|
2811
|
-
this.hooks.lifecycle.registerRemote.emit({
|
|
2812
|
-
remote,
|
|
2813
|
-
origin: host
|
|
2814
|
-
});
|
|
2941
|
+
this.hooks.lifecycle.registerRemote.emit({ remote, origin: host });
|
|
2815
2942
|
warn$1(messages.join(' '));
|
|
2816
2943
|
}
|
|
2817
2944
|
}
|
|
@@ -2820,7 +2947,7 @@ class RemoteHandler {
|
|
|
2820
2947
|
try {
|
|
2821
2948
|
const { host } = this;
|
|
2822
2949
|
const { name } = remote;
|
|
2823
|
-
const remoteIndex = host.options.remotes.findIndex((item)=>item.name === name);
|
|
2950
|
+
const remoteIndex = host.options.remotes.findIndex((item) => item.name === name);
|
|
2824
2951
|
if (remoteIndex !== -1) {
|
|
2825
2952
|
host.options.remotes.splice(remoteIndex, 1);
|
|
2826
2953
|
}
|
|
@@ -2829,10 +2956,10 @@ class RemoteHandler {
|
|
|
2829
2956
|
const remoteInfo = loadedModule.remoteInfo;
|
|
2830
2957
|
const key = remoteInfo.entryGlobalName;
|
|
2831
2958
|
if (CurrentGlobal[key]) {
|
|
2832
|
-
|
|
2833
|
-
if ((_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(CurrentGlobal, key)) == null ? void 0 : _Object_getOwnPropertyDescriptor.configurable) {
|
|
2959
|
+
if (Object.getOwnPropertyDescriptor(CurrentGlobal, key)?.configurable) {
|
|
2834
2960
|
delete CurrentGlobal[key];
|
|
2835
|
-
}
|
|
2961
|
+
}
|
|
2962
|
+
else {
|
|
2836
2963
|
// @ts-ignore
|
|
2837
2964
|
CurrentGlobal[key] = undefined;
|
|
2838
2965
|
}
|
|
@@ -2843,11 +2970,14 @@ class RemoteHandler {
|
|
|
2843
2970
|
}
|
|
2844
2971
|
host.snapshotHandler.manifestCache.delete(remoteInfo.entry);
|
|
2845
2972
|
// delete unloaded shared and instance
|
|
2846
|
-
let remoteInsId = remoteInfo.buildVersion
|
|
2847
|
-
|
|
2973
|
+
let remoteInsId = remoteInfo.buildVersion
|
|
2974
|
+
? composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion)
|
|
2975
|
+
: remoteInfo.name;
|
|
2976
|
+
const remoteInsIndex = CurrentGlobal.__FEDERATION__.__INSTANCES__.findIndex((ins) => {
|
|
2848
2977
|
if (remoteInfo.buildVersion) {
|
|
2849
2978
|
return ins.options.id === remoteInsId;
|
|
2850
|
-
}
|
|
2979
|
+
}
|
|
2980
|
+
else {
|
|
2851
2981
|
return ins.name === remoteInsId;
|
|
2852
2982
|
}
|
|
2853
2983
|
});
|
|
@@ -2857,56 +2987,66 @@ class RemoteHandler {
|
|
|
2857
2987
|
const globalShareScopeMap = getGlobalShareScope();
|
|
2858
2988
|
let isAllSharedNotUsed = true;
|
|
2859
2989
|
const needDeleteKeys = [];
|
|
2860
|
-
Object.keys(globalShareScopeMap).forEach((instId)=>{
|
|
2990
|
+
Object.keys(globalShareScopeMap).forEach((instId) => {
|
|
2861
2991
|
const shareScopeMap = globalShareScopeMap[instId];
|
|
2862
|
-
shareScopeMap &&
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
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
|
+
});
|
|
2891
3029
|
});
|
|
2892
|
-
});
|
|
2893
3030
|
});
|
|
2894
3031
|
if (isAllSharedNotUsed) {
|
|
2895
3032
|
remoteIns.shareScopeMap = {};
|
|
2896
3033
|
delete globalShareScopeMap[remoteInsId];
|
|
2897
3034
|
}
|
|
2898
|
-
needDeleteKeys.forEach(([insId, shareScope, shareName, shareVersion])=>{
|
|
2899
|
-
|
|
2900
|
-
(_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];
|
|
2901
3037
|
});
|
|
2902
3038
|
CurrentGlobal.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1);
|
|
2903
3039
|
}
|
|
2904
3040
|
const { hostGlobalSnapshot } = getGlobalRemoteInfo(remote, host);
|
|
2905
3041
|
if (hostGlobalSnapshot) {
|
|
2906
|
-
const remoteKey = hostGlobalSnapshot &&
|
|
3042
|
+
const remoteKey = hostGlobalSnapshot &&
|
|
3043
|
+
'remotesInfo' in hostGlobalSnapshot &&
|
|
3044
|
+
hostGlobalSnapshot.remotesInfo &&
|
|
3045
|
+
getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;
|
|
2907
3046
|
if (remoteKey) {
|
|
2908
3047
|
delete hostGlobalSnapshot.remotesInfo[remoteKey];
|
|
2909
|
-
if (
|
|
3048
|
+
if (
|
|
3049
|
+
//eslint-disable-next-line no-extra-boolean-cast
|
|
2910
3050
|
Boolean(Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey])) {
|
|
2911
3051
|
delete Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey];
|
|
2912
3052
|
}
|
|
@@ -2914,31 +3054,68 @@ class RemoteHandler {
|
|
|
2914
3054
|
}
|
|
2915
3055
|
host.moduleCache.delete(remote.name);
|
|
2916
3056
|
}
|
|
2917
|
-
}
|
|
3057
|
+
}
|
|
3058
|
+
catch (err) {
|
|
2918
3059
|
logger.log('removeRemote fail: ', err);
|
|
2919
3060
|
}
|
|
2920
3061
|
}
|
|
2921
|
-
constructor(host){
|
|
2922
|
-
this.hooks = new PluginSystem({
|
|
2923
|
-
beforeRegisterRemote: new SyncWaterfallHook('beforeRegisterRemote'),
|
|
2924
|
-
registerRemote: new SyncWaterfallHook('registerRemote'),
|
|
2925
|
-
beforeRequest: new AsyncWaterfallHook('beforeRequest'),
|
|
2926
|
-
onLoad: new AsyncHook('onLoad'),
|
|
2927
|
-
handlePreloadModule: new SyncHook('handlePreloadModule'),
|
|
2928
|
-
errorLoadRemote: new AsyncHook('errorLoadRemote'),
|
|
2929
|
-
beforePreloadRemote: new AsyncHook('beforePreloadRemote'),
|
|
2930
|
-
generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
|
|
2931
|
-
// not used yet
|
|
2932
|
-
afterPreloadRemote: new AsyncHook(),
|
|
2933
|
-
loadEntry: new AsyncHook()
|
|
2934
|
-
});
|
|
2935
|
-
this.host = host;
|
|
2936
|
-
this.idToRemoteMap = {};
|
|
2937
|
-
}
|
|
2938
3062
|
}
|
|
2939
3063
|
|
|
2940
|
-
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
|
|
2941
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.20.0";
|
|
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
|
+
}
|
|
2942
3119
|
initOptions(userOptions) {
|
|
2943
3120
|
this.registerPlugins(userOptions.plugins);
|
|
2944
3121
|
const options = this.formatOptions(this.options, userOptions);
|
|
@@ -2959,14 +3136,8 @@ class ModuleFederation {
|
|
|
2959
3136
|
return this.sharedHandler.initializeSharing(shareScopeName, extraOptions);
|
|
2960
3137
|
}
|
|
2961
3138
|
initRawContainer(name, url, container) {
|
|
2962
|
-
const remoteInfo = getRemoteInfo({
|
|
2963
|
-
|
|
2964
|
-
entry: url
|
|
2965
|
-
});
|
|
2966
|
-
const module = new Module({
|
|
2967
|
-
host: this,
|
|
2968
|
-
remoteInfo
|
|
2969
|
-
});
|
|
3139
|
+
const remoteInfo = getRemoteInfo({ name, entry: url });
|
|
3140
|
+
const module = new Module({ host: this, remoteInfo });
|
|
2970
3141
|
module.remoteEntryExports = container;
|
|
2971
3142
|
this.moduleCache.set(name, module);
|
|
2972
3143
|
return module;
|
|
@@ -2989,37 +3160,38 @@ class ModuleFederation {
|
|
|
2989
3160
|
origin: this,
|
|
2990
3161
|
userOptions,
|
|
2991
3162
|
options: globalOptions,
|
|
2992
|
-
shareInfo: shared
|
|
3163
|
+
shareInfo: shared,
|
|
2993
3164
|
});
|
|
2994
3165
|
const remotes = this.remoteHandler.formatAndRegisterRemote(globalOptionsRes, userOptionsRes);
|
|
2995
3166
|
const { shared: handledShared } = this.sharedHandler.registerShared(globalOptionsRes, userOptionsRes);
|
|
2996
|
-
const plugins = [
|
|
2997
|
-
...globalOptionsRes.plugins
|
|
2998
|
-
];
|
|
3167
|
+
const plugins = [...globalOptionsRes.plugins];
|
|
2999
3168
|
if (userOptionsRes.plugins) {
|
|
3000
|
-
userOptionsRes.plugins.forEach((plugin)=>{
|
|
3169
|
+
userOptionsRes.plugins.forEach((plugin) => {
|
|
3001
3170
|
if (!plugins.includes(plugin)) {
|
|
3002
3171
|
plugins.push(plugin);
|
|
3003
3172
|
}
|
|
3004
3173
|
});
|
|
3005
3174
|
}
|
|
3006
|
-
const optionsRes =
|
|
3175
|
+
const optionsRes = {
|
|
3176
|
+
...globalOptions,
|
|
3177
|
+
...userOptions,
|
|
3007
3178
|
plugins,
|
|
3008
3179
|
remotes,
|
|
3009
|
-
shared: handledShared
|
|
3010
|
-
}
|
|
3180
|
+
shared: handledShared,
|
|
3181
|
+
};
|
|
3011
3182
|
this.hooks.lifecycle.init.emit({
|
|
3012
3183
|
origin: this,
|
|
3013
|
-
options: optionsRes
|
|
3184
|
+
options: optionsRes,
|
|
3014
3185
|
});
|
|
3015
3186
|
return optionsRes;
|
|
3016
3187
|
}
|
|
3017
3188
|
registerPlugins(plugins) {
|
|
3018
3189
|
const pluginRes = registerPlugins(plugins, this);
|
|
3019
3190
|
// Merge plugin
|
|
3020
|
-
this.options.plugins = this.options.plugins.reduce((res, plugin)=>{
|
|
3021
|
-
if (!plugin)
|
|
3022
|
-
|
|
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)) {
|
|
3023
3195
|
res.push(plugin);
|
|
3024
3196
|
}
|
|
3025
3197
|
return res;
|
|
@@ -3029,61 +3201,10 @@ class ModuleFederation {
|
|
|
3029
3201
|
return this.remoteHandler.registerRemotes(remotes, options);
|
|
3030
3202
|
}
|
|
3031
3203
|
registerShared(shared) {
|
|
3032
|
-
this.sharedHandler.registerShared(this.options,
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
}
|
|
3036
|
-
constructor(userOptions){
|
|
3037
|
-
this.hooks = new PluginSystem({
|
|
3038
|
-
beforeInit: new SyncWaterfallHook('beforeInit'),
|
|
3039
|
-
init: new SyncHook(),
|
|
3040
|
-
// maybe will change, temporarily for internal use only
|
|
3041
|
-
beforeInitContainer: new AsyncWaterfallHook('beforeInitContainer'),
|
|
3042
|
-
// maybe will change, temporarily for internal use only
|
|
3043
|
-
initContainer: new AsyncWaterfallHook('initContainer')
|
|
3044
|
-
});
|
|
3045
|
-
this.version = "0.19.0";
|
|
3046
|
-
this.moduleCache = new Map();
|
|
3047
|
-
this.loaderHook = new PluginSystem({
|
|
3048
|
-
// FIXME: may not be suitable , not open to the public yet
|
|
3049
|
-
getModuleInfo: new SyncHook(),
|
|
3050
|
-
createScript: new SyncHook(),
|
|
3051
|
-
createLink: new SyncHook(),
|
|
3052
|
-
fetch: new AsyncHook(),
|
|
3053
|
-
loadEntryError: new AsyncHook(),
|
|
3054
|
-
getModuleFactory: new AsyncHook()
|
|
3055
|
-
});
|
|
3056
|
-
this.bridgeHook = new PluginSystem({
|
|
3057
|
-
beforeBridgeRender: new SyncHook(),
|
|
3058
|
-
afterBridgeRender: new SyncHook(),
|
|
3059
|
-
beforeBridgeDestroy: new SyncHook(),
|
|
3060
|
-
afterBridgeDestroy: new SyncHook()
|
|
3204
|
+
this.sharedHandler.registerShared(this.options, {
|
|
3205
|
+
...this.options,
|
|
3206
|
+
shared,
|
|
3061
3207
|
});
|
|
3062
|
-
const plugins = USE_SNAPSHOT ? [
|
|
3063
|
-
snapshotPlugin(),
|
|
3064
|
-
generatePreloadAssetsPlugin()
|
|
3065
|
-
] : [];
|
|
3066
|
-
// TODO: Validate the details of the options
|
|
3067
|
-
// Initialize options with default values
|
|
3068
|
-
const defaultOptions = {
|
|
3069
|
-
id: getBuilderId(),
|
|
3070
|
-
name: userOptions.name,
|
|
3071
|
-
plugins,
|
|
3072
|
-
remotes: [],
|
|
3073
|
-
shared: {},
|
|
3074
|
-
inBrowser: isBrowserEnv()
|
|
3075
|
-
};
|
|
3076
|
-
this.name = userOptions.name;
|
|
3077
|
-
this.options = defaultOptions;
|
|
3078
|
-
this.snapshotHandler = new SnapshotHandler(this);
|
|
3079
|
-
this.sharedHandler = new SharedHandler(this);
|
|
3080
|
-
this.remoteHandler = new RemoteHandler(this);
|
|
3081
|
-
this.shareScopeMap = this.sharedHandler.shareScopeMap;
|
|
3082
|
-
this.registerPlugins([
|
|
3083
|
-
...defaultOptions.plugins,
|
|
3084
|
-
...userOptions.plugins || []
|
|
3085
|
-
]);
|
|
3086
|
-
this.options = this.formatOptions(defaultOptions, userOptions);
|
|
3087
3208
|
}
|
|
3088
3209
|
}
|
|
3089
3210
|
|