@module-federation/sdk 0.2.3 → 0.2.4
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.js +263 -985
- package/dist/index.esm.js +263 -985
- package/dist/normalize-webpack-path.cjs.js +9 -12
- package/dist/normalize-webpack-path.esm.js +9 -12
- package/dist/package.json +1 -1
- package/dist/src/dom.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -2,41 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
configurable: true,
|
|
11
|
-
writable: true
|
|
12
|
-
});
|
|
13
|
-
} else {
|
|
14
|
-
obj[key] = value;
|
|
15
|
-
}
|
|
16
|
-
return obj;
|
|
17
|
-
}
|
|
18
|
-
var FederationModuleManifest = 'federation-manifest.json';
|
|
19
|
-
var MANIFEST_EXT = '.json';
|
|
20
|
-
var BROWSER_LOG_KEY = 'FEDERATION_DEBUG';
|
|
21
|
-
var BROWSER_LOG_VALUE = '1';
|
|
22
|
-
var NameTransformSymbol = {
|
|
5
|
+
const FederationModuleManifest = 'federation-manifest.json';
|
|
6
|
+
const MANIFEST_EXT = '.json';
|
|
7
|
+
const BROWSER_LOG_KEY = 'FEDERATION_DEBUG';
|
|
8
|
+
const BROWSER_LOG_VALUE = '1';
|
|
9
|
+
const NameTransformSymbol = {
|
|
23
10
|
AT: '@',
|
|
24
11
|
HYPHEN: '-',
|
|
25
12
|
SLASH: '/'
|
|
26
13
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
14
|
+
const NameTransformMap = {
|
|
15
|
+
[NameTransformSymbol.AT]: 'scope_',
|
|
16
|
+
[NameTransformSymbol.HYPHEN]: '_',
|
|
17
|
+
[NameTransformSymbol.SLASH]: '__'
|
|
18
|
+
};
|
|
19
|
+
const EncodedNameTransformMap = {
|
|
20
|
+
[NameTransformMap[NameTransformSymbol.AT]]: NameTransformSymbol.AT,
|
|
21
|
+
[NameTransformMap[NameTransformSymbol.HYPHEN]]: NameTransformSymbol.HYPHEN,
|
|
22
|
+
[NameTransformMap[NameTransformSymbol.SLASH]]: NameTransformSymbol.SLASH
|
|
23
|
+
};
|
|
24
|
+
const SEPARATOR = ':';
|
|
25
|
+
const ManifestFileName = 'mf-manifest.json';
|
|
26
|
+
const StatsFileName = 'mf-stats.json';
|
|
27
|
+
const MFModuleType = {
|
|
35
28
|
NPM: 'npm',
|
|
36
29
|
APP: 'app'
|
|
37
30
|
};
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
const MODULE_DEVTOOL_IDENTIFIER = '__MF_DEVTOOLS_MODULE_INFO__';
|
|
32
|
+
const ENCODE_NAME_PREFIX = 'ENCODE_NAME_PREFIX';
|
|
40
33
|
|
|
41
34
|
var ContainerPlugin = /*#__PURE__*/Object.freeze({
|
|
42
35
|
__proto__: null
|
|
@@ -63,67 +56,10 @@ function isDebugMode() {
|
|
|
63
56
|
}
|
|
64
57
|
return typeof FEDERATION_DEBUG !== 'undefined' && Boolean(FEDERATION_DEBUG);
|
|
65
58
|
}
|
|
66
|
-
|
|
59
|
+
const getProcessEnv = function() {
|
|
67
60
|
return typeof process !== 'undefined' && process.env ? process.env : {};
|
|
68
61
|
};
|
|
69
62
|
|
|
70
|
-
function _array_like_to_array$2(arr, len) {
|
|
71
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
72
|
-
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
73
|
-
return arr2;
|
|
74
|
-
}
|
|
75
|
-
function _array_without_holes(arr) {
|
|
76
|
-
if (Array.isArray(arr)) return _array_like_to_array$2(arr);
|
|
77
|
-
}
|
|
78
|
-
function _class_call_check(instance, Constructor) {
|
|
79
|
-
if (!(instance instanceof Constructor)) {
|
|
80
|
-
throw new TypeError("Cannot call a class as a function");
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function _defineProperties(target, props) {
|
|
84
|
-
for(var i = 0; i < props.length; i++){
|
|
85
|
-
var descriptor = props[i];
|
|
86
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
87
|
-
descriptor.configurable = true;
|
|
88
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
89
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
function _create_class(Constructor, protoProps, staticProps) {
|
|
93
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
94
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
95
|
-
return Constructor;
|
|
96
|
-
}
|
|
97
|
-
function _define_property$3(obj, key, value) {
|
|
98
|
-
if (key in obj) {
|
|
99
|
-
Object.defineProperty(obj, key, {
|
|
100
|
-
value: value,
|
|
101
|
-
enumerable: true,
|
|
102
|
-
configurable: true,
|
|
103
|
-
writable: true
|
|
104
|
-
});
|
|
105
|
-
} else {
|
|
106
|
-
obj[key] = value;
|
|
107
|
-
}
|
|
108
|
-
return obj;
|
|
109
|
-
}
|
|
110
|
-
function _iterable_to_array$1(iter) {
|
|
111
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
112
|
-
}
|
|
113
|
-
function _non_iterable_spread() {
|
|
114
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
115
|
-
}
|
|
116
|
-
function _to_consumable_array(arr) {
|
|
117
|
-
return _array_without_holes(arr) || _iterable_to_array$1(arr) || _unsupported_iterable_to_array$2(arr) || _non_iterable_spread();
|
|
118
|
-
}
|
|
119
|
-
function _unsupported_iterable_to_array$2(o, minLen) {
|
|
120
|
-
if (!o) return;
|
|
121
|
-
if (typeof o === "string") return _array_like_to_array$2(o, minLen);
|
|
122
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
123
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
124
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
125
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$2(o, minLen);
|
|
126
|
-
}
|
|
127
63
|
function safeToString(info) {
|
|
128
64
|
try {
|
|
129
65
|
return JSON.stringify(info, null, 2);
|
|
@@ -131,7 +67,7 @@ function safeToString(info) {
|
|
|
131
67
|
return '';
|
|
132
68
|
}
|
|
133
69
|
}
|
|
134
|
-
|
|
70
|
+
const DEBUG_LOG = '[ FEDERATION DEBUG ]';
|
|
135
71
|
function safeGetLocalStorageItem() {
|
|
136
72
|
try {
|
|
137
73
|
if (typeof window !== 'undefined' && window.localStorage) {
|
|
@@ -142,11 +78,30 @@ function safeGetLocalStorageItem() {
|
|
|
142
78
|
}
|
|
143
79
|
return false;
|
|
144
80
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
81
|
+
let Logger = class Logger {
|
|
82
|
+
info(msg, info) {
|
|
83
|
+
if (this.enable) {
|
|
84
|
+
const argsToString = safeToString(info) || '';
|
|
85
|
+
if (isBrowserEnv()) {
|
|
86
|
+
console.info(`%c ${this.identifier}: ${msg} ${argsToString}`, 'color:#3300CC');
|
|
87
|
+
} else {
|
|
88
|
+
console.info('\x1b[34m%s', `${this.identifier}: ${msg} ${argsToString ? `\n${argsToString}` : ''}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
logOriginalInfo(...args) {
|
|
93
|
+
if (this.enable) {
|
|
94
|
+
if (isBrowserEnv()) {
|
|
95
|
+
console.info(`%c ${this.identifier}: OriginalInfo`, 'color:#3300CC');
|
|
96
|
+
console.log(...args);
|
|
97
|
+
} else {
|
|
98
|
+
console.info(`%c ${this.identifier}: OriginalInfo`, 'color:#3300CC');
|
|
99
|
+
console.log(...args);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
constructor(identifier){
|
|
104
|
+
this.enable = false;
|
|
150
105
|
this.identifier = identifier || DEBUG_LOG;
|
|
151
106
|
if (isBrowserEnv() && safeGetLocalStorageItem()) {
|
|
152
107
|
this.enable = true;
|
|
@@ -154,182 +109,88 @@ var Logger = /*#__PURE__*/ function() {
|
|
|
154
109
|
this.enable = true;
|
|
155
110
|
}
|
|
156
111
|
}
|
|
157
|
-
|
|
158
|
-
{
|
|
159
|
-
key: "info",
|
|
160
|
-
value: function info(msg, info) {
|
|
161
|
-
if (this.enable) {
|
|
162
|
-
var argsToString = safeToString(info) || '';
|
|
163
|
-
if (isBrowserEnv()) {
|
|
164
|
-
console.info("%c ".concat(this.identifier, ": ").concat(msg, " ").concat(argsToString), 'color:#3300CC');
|
|
165
|
-
} else {
|
|
166
|
-
console.info('\x1b[34m%s', "".concat(this.identifier, ": ").concat(msg, " ").concat(argsToString ? "\n".concat(argsToString) : ''));
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
key: "logOriginalInfo",
|
|
173
|
-
value: function logOriginalInfo() {
|
|
174
|
-
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
175
|
-
args[_key] = arguments[_key];
|
|
176
|
-
}
|
|
177
|
-
if (this.enable) {
|
|
178
|
-
if (isBrowserEnv()) {
|
|
179
|
-
var _console;
|
|
180
|
-
console.info("%c ".concat(this.identifier, ": OriginalInfo"), 'color:#3300CC');
|
|
181
|
-
(_console = console).log.apply(_console, _to_consumable_array(args));
|
|
182
|
-
} else {
|
|
183
|
-
var _console1;
|
|
184
|
-
console.info("%c ".concat(this.identifier, ": OriginalInfo"), 'color:#3300CC');
|
|
185
|
-
(_console1 = console).log.apply(_console1, _to_consumable_array(args));
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
]);
|
|
191
|
-
return Logger;
|
|
192
|
-
}();
|
|
112
|
+
};
|
|
193
113
|
|
|
194
|
-
|
|
195
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
196
|
-
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
197
|
-
return arr2;
|
|
198
|
-
}
|
|
199
|
-
function _array_with_holes$1(arr) {
|
|
200
|
-
if (Array.isArray(arr)) return arr;
|
|
201
|
-
}
|
|
202
|
-
function _iterable_to_array(iter) {
|
|
203
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
204
|
-
}
|
|
205
|
-
function _iterable_to_array_limit$1(arr, i) {
|
|
206
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
207
|
-
if (_i == null) return;
|
|
208
|
-
var _arr = [];
|
|
209
|
-
var _n = true;
|
|
210
|
-
var _d = false;
|
|
211
|
-
var _s, _e;
|
|
212
|
-
try {
|
|
213
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
214
|
-
_arr.push(_s.value);
|
|
215
|
-
if (i && _arr.length === i) break;
|
|
216
|
-
}
|
|
217
|
-
} catch (err) {
|
|
218
|
-
_d = true;
|
|
219
|
-
_e = err;
|
|
220
|
-
} finally{
|
|
221
|
-
try {
|
|
222
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
223
|
-
} finally{
|
|
224
|
-
if (_d) throw _e;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return _arr;
|
|
228
|
-
}
|
|
229
|
-
function _non_iterable_rest$1() {
|
|
230
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
231
|
-
}
|
|
232
|
-
function _sliced_to_array$1(arr, i) {
|
|
233
|
-
return _array_with_holes$1(arr) || _iterable_to_array_limit$1(arr, i) || _unsupported_iterable_to_array$1(arr, i) || _non_iterable_rest$1();
|
|
234
|
-
}
|
|
235
|
-
function _to_array(arr) {
|
|
236
|
-
return _array_with_holes$1(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array$1(arr) || _non_iterable_rest$1();
|
|
237
|
-
}
|
|
238
|
-
function _unsupported_iterable_to_array$1(o, minLen) {
|
|
239
|
-
if (!o) return;
|
|
240
|
-
if (typeof o === "string") return _array_like_to_array$1(o, minLen);
|
|
241
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
242
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
243
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
244
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
|
|
245
|
-
}
|
|
246
|
-
var LOG_CATEGORY = '[ Federation Runtime ]';
|
|
114
|
+
const LOG_CATEGORY = '[ Federation Runtime ]';
|
|
247
115
|
// entry: name:version version : 1.0.0 | ^1.2.3
|
|
248
116
|
// entry: name:entry entry: https://localhost:9000/federation-manifest.json
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
var isEntry = function(s) {
|
|
255
|
-
return s.startsWith('http') || s.includes(MANIFEST_EXT);
|
|
256
|
-
};
|
|
117
|
+
const parseEntry = (str, devVerOrUrl, separator = SEPARATOR)=>{
|
|
118
|
+
const strSplit = str.split(separator);
|
|
119
|
+
const devVersionOrUrl = getProcessEnv()['NODE_ENV'] === 'development' && devVerOrUrl;
|
|
120
|
+
const defaultVersion = '*';
|
|
121
|
+
const isEntry = (s)=>s.startsWith('http') || s.includes(MANIFEST_EXT);
|
|
257
122
|
// Check if the string starts with a type
|
|
258
123
|
if (strSplit.length >= 2) {
|
|
259
|
-
|
|
124
|
+
let [name, ...versionOrEntryArr] = strSplit;
|
|
260
125
|
if (str.startsWith(separator)) {
|
|
261
126
|
versionOrEntryArr = [
|
|
262
127
|
devVersionOrUrl || strSplit.slice(-1)[0]
|
|
263
128
|
];
|
|
264
129
|
name = strSplit.slice(0, -1).join(separator);
|
|
265
130
|
}
|
|
266
|
-
|
|
131
|
+
let versionOrEntry = devVersionOrUrl || versionOrEntryArr.join(separator);
|
|
267
132
|
if (isEntry(versionOrEntry)) {
|
|
268
133
|
return {
|
|
269
|
-
name
|
|
134
|
+
name,
|
|
270
135
|
entry: versionOrEntry
|
|
271
136
|
};
|
|
272
137
|
} else {
|
|
273
138
|
// Apply version rule
|
|
274
139
|
// devVersionOrUrl => inputVersion => defaultVersion
|
|
275
140
|
return {
|
|
276
|
-
name
|
|
141
|
+
name,
|
|
277
142
|
version: versionOrEntry || defaultVersion
|
|
278
143
|
};
|
|
279
144
|
}
|
|
280
145
|
} else if (strSplit.length === 1) {
|
|
281
|
-
|
|
146
|
+
const [name] = strSplit;
|
|
282
147
|
if (devVersionOrUrl && isEntry(devVersionOrUrl)) {
|
|
283
148
|
return {
|
|
284
|
-
name
|
|
149
|
+
name,
|
|
285
150
|
entry: devVersionOrUrl
|
|
286
151
|
};
|
|
287
152
|
}
|
|
288
153
|
return {
|
|
289
|
-
name
|
|
154
|
+
name,
|
|
290
155
|
version: devVersionOrUrl || defaultVersion
|
|
291
156
|
};
|
|
292
157
|
} else {
|
|
293
|
-
throw
|
|
158
|
+
throw `Invalid entry value: ${str}`;
|
|
294
159
|
}
|
|
295
160
|
};
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
299
|
-
args[_key] = arguments[_key];
|
|
300
|
-
}
|
|
161
|
+
const logger = new Logger();
|
|
162
|
+
const composeKeyWithSeparator = function(...args) {
|
|
301
163
|
if (!args.length) {
|
|
302
164
|
return '';
|
|
303
165
|
}
|
|
304
|
-
return args.reduce(
|
|
166
|
+
return args.reduce((sum, cur)=>{
|
|
305
167
|
if (!cur) {
|
|
306
168
|
return sum;
|
|
307
169
|
}
|
|
308
170
|
if (!sum) {
|
|
309
171
|
return cur;
|
|
310
172
|
}
|
|
311
|
-
return
|
|
173
|
+
return `${sum}${SEPARATOR}${cur}`;
|
|
312
174
|
}, '');
|
|
313
175
|
};
|
|
314
|
-
|
|
315
|
-
var prefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : '', withExt = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
|
|
176
|
+
const encodeName = function(name, prefix = '', withExt = false) {
|
|
316
177
|
try {
|
|
317
|
-
|
|
318
|
-
return
|
|
178
|
+
const ext = withExt ? '.js' : '';
|
|
179
|
+
return `${prefix}${name.replace(new RegExp(`${NameTransformSymbol.AT}`, 'g'), NameTransformMap[NameTransformSymbol.AT]).replace(new RegExp(`${NameTransformSymbol.HYPHEN}`, 'g'), NameTransformMap[NameTransformSymbol.HYPHEN]).replace(new RegExp(`${NameTransformSymbol.SLASH}`, 'g'), NameTransformMap[NameTransformSymbol.SLASH])}${ext}`;
|
|
319
180
|
} catch (err) {
|
|
320
181
|
throw err;
|
|
321
182
|
}
|
|
322
183
|
};
|
|
323
|
-
|
|
184
|
+
const decodeName = function(name, prefix, withExt) {
|
|
324
185
|
try {
|
|
325
|
-
|
|
186
|
+
let decodedName = name;
|
|
326
187
|
if (prefix) {
|
|
327
188
|
if (!decodedName.startsWith(prefix)) {
|
|
328
189
|
return decodedName;
|
|
329
190
|
}
|
|
330
191
|
decodedName = decodedName.replace(new RegExp(prefix, 'g'), '');
|
|
331
192
|
}
|
|
332
|
-
decodedName = decodedName.replace(new RegExp(
|
|
193
|
+
decodedName = decodedName.replace(new RegExp(`${NameTransformMap[NameTransformSymbol.AT]}`, 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.AT]]).replace(new RegExp(`${NameTransformMap[NameTransformSymbol.SLASH]}`, 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.SLASH]]).replace(new RegExp(`${NameTransformMap[NameTransformSymbol.HYPHEN]}`, 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.HYPHEN]]);
|
|
333
194
|
if (withExt) {
|
|
334
195
|
decodedName = decodedName.replace('.js', '');
|
|
335
196
|
}
|
|
@@ -338,11 +199,11 @@ var decodeName = function decodeName(name, prefix, withExt) {
|
|
|
338
199
|
throw err;
|
|
339
200
|
}
|
|
340
201
|
};
|
|
341
|
-
|
|
202
|
+
const generateExposeFilename = (exposeName, withExt)=>{
|
|
342
203
|
if (!exposeName) {
|
|
343
204
|
return '';
|
|
344
205
|
}
|
|
345
|
-
|
|
206
|
+
let expose = exposeName;
|
|
346
207
|
if (expose === '.') {
|
|
347
208
|
expose = 'default_export';
|
|
348
209
|
}
|
|
@@ -351,98 +212,57 @@ var generateExposeFilename = function(exposeName, withExt) {
|
|
|
351
212
|
}
|
|
352
213
|
return encodeName(expose, '__federation_expose_', withExt);
|
|
353
214
|
};
|
|
354
|
-
|
|
215
|
+
const generateShareFilename = (pkgName, withExt)=>{
|
|
355
216
|
if (!pkgName) {
|
|
356
217
|
return '';
|
|
357
218
|
}
|
|
358
219
|
return encodeName(pkgName, '__federation_shared_', withExt);
|
|
359
220
|
};
|
|
360
|
-
|
|
221
|
+
const getResourceUrl = (module, sourceUrl)=>{
|
|
361
222
|
if ('getPublicPath' in module) {
|
|
362
|
-
|
|
223
|
+
let publicPath;
|
|
363
224
|
if (!module.getPublicPath.startsWith('function')) {
|
|
364
225
|
publicPath = new Function(module.getPublicPath)();
|
|
365
226
|
} else {
|
|
366
227
|
publicPath = new Function('return ' + module.getPublicPath)()();
|
|
367
228
|
}
|
|
368
|
-
return
|
|
229
|
+
return `${publicPath}${sourceUrl}`;
|
|
369
230
|
} else if ('publicPath' in module) {
|
|
370
|
-
return
|
|
231
|
+
return `${module.publicPath}${sourceUrl}`;
|
|
371
232
|
} else {
|
|
372
233
|
console.warn('Cannot get resource URL. If in debug mode, please ignore.', module, sourceUrl);
|
|
373
234
|
return '';
|
|
374
235
|
}
|
|
375
236
|
};
|
|
376
237
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
377
|
-
|
|
238
|
+
const assert = (condition, msg)=>{
|
|
378
239
|
if (!condition) {
|
|
379
240
|
error(msg);
|
|
380
241
|
}
|
|
381
242
|
};
|
|
382
|
-
|
|
383
|
-
throw new Error(
|
|
243
|
+
const error = (msg)=>{
|
|
244
|
+
throw new Error(`${LOG_CATEGORY}: ${msg}`);
|
|
384
245
|
};
|
|
385
|
-
|
|
386
|
-
console.warn(
|
|
246
|
+
const warn = (msg)=>{
|
|
247
|
+
console.warn(`${LOG_CATEGORY}: ${msg}`);
|
|
387
248
|
};
|
|
388
249
|
|
|
389
|
-
function
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
configurable: true,
|
|
395
|
-
writable: true
|
|
396
|
-
});
|
|
397
|
-
} else {
|
|
398
|
-
obj[key] = value;
|
|
399
|
-
}
|
|
400
|
-
return obj;
|
|
401
|
-
}
|
|
402
|
-
function _object_spread$2(target) {
|
|
403
|
-
for(var i = 1; i < arguments.length; i++){
|
|
404
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
405
|
-
var ownKeys = Object.keys(source);
|
|
406
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
407
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
408
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
409
|
-
}));
|
|
250
|
+
function _extends() {
|
|
251
|
+
_extends = Object.assign || function assign(target) {
|
|
252
|
+
for(var i = 1; i < arguments.length; i++){
|
|
253
|
+
var source = arguments[i];
|
|
254
|
+
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
410
255
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
}
|
|
415
|
-
return target;
|
|
416
|
-
}
|
|
417
|
-
function ownKeys(object, enumerableOnly) {
|
|
418
|
-
var keys = Object.keys(object);
|
|
419
|
-
if (Object.getOwnPropertySymbols) {
|
|
420
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
421
|
-
if (enumerableOnly) {
|
|
422
|
-
symbols = symbols.filter(function(sym) {
|
|
423
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
keys.push.apply(keys, symbols);
|
|
427
|
-
}
|
|
428
|
-
return keys;
|
|
429
|
-
}
|
|
430
|
-
function _object_spread_props(target, source) {
|
|
431
|
-
source = source != null ? source : {};
|
|
432
|
-
if (Object.getOwnPropertyDescriptors) {
|
|
433
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
434
|
-
} else {
|
|
435
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
436
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
return target;
|
|
256
|
+
return target;
|
|
257
|
+
};
|
|
258
|
+
return _extends.apply(this, arguments);
|
|
440
259
|
}
|
|
441
|
-
|
|
260
|
+
|
|
261
|
+
const simpleJoinRemoteEntry = (rPath, rName)=>{
|
|
442
262
|
if (!rPath) {
|
|
443
263
|
return rName;
|
|
444
264
|
}
|
|
445
|
-
|
|
265
|
+
const transformPath = (str)=>{
|
|
446
266
|
if (str === '.') {
|
|
447
267
|
return '';
|
|
448
268
|
}
|
|
@@ -450,7 +270,7 @@ var simpleJoinRemoteEntry = function(rPath, rName) {
|
|
|
450
270
|
return str.replace('./', '');
|
|
451
271
|
}
|
|
452
272
|
if (str.startsWith('/')) {
|
|
453
|
-
|
|
273
|
+
const strWithoutSlash = str.slice(1);
|
|
454
274
|
if (strWithoutSlash.endsWith('/')) {
|
|
455
275
|
return strWithoutSlash.slice(0, -1);
|
|
456
276
|
}
|
|
@@ -458,26 +278,25 @@ var simpleJoinRemoteEntry = function(rPath, rName) {
|
|
|
458
278
|
}
|
|
459
279
|
return str;
|
|
460
280
|
};
|
|
461
|
-
|
|
281
|
+
const transformedPath = transformPath(rPath);
|
|
462
282
|
if (!transformedPath) {
|
|
463
283
|
return rName;
|
|
464
284
|
}
|
|
465
285
|
if (transformedPath.endsWith('/')) {
|
|
466
|
-
return
|
|
286
|
+
return `${transformedPath}${rName}`;
|
|
467
287
|
}
|
|
468
|
-
return
|
|
288
|
+
return `${transformedPath}/${rName}`;
|
|
469
289
|
};
|
|
470
290
|
function inferAutoPublicPath(url) {
|
|
471
291
|
return url.replace(/#.*$/, '').replace(/\?.*$/, '').replace(/\/[^\/]+$/, '/');
|
|
472
292
|
}
|
|
473
293
|
// Priority: overrides > remotes
|
|
474
294
|
// eslint-disable-next-line max-lines-per-function
|
|
475
|
-
function generateSnapshotFromManifest(manifest) {
|
|
476
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
295
|
+
function generateSnapshotFromManifest(manifest, options = {}) {
|
|
477
296
|
var _manifest_metaData, _manifest_metaData1;
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
297
|
+
const { remotes = {}, overrides = {}, version } = options;
|
|
298
|
+
let remoteSnapshot;
|
|
299
|
+
const getPublicPath = ()=>{
|
|
481
300
|
if ('publicPath' in manifest.metaData) {
|
|
482
301
|
if (manifest.metaData.publicPath === 'auto' && version) {
|
|
483
302
|
// use same implementation as publicPath auto runtime module implements
|
|
@@ -488,14 +307,14 @@ function generateSnapshotFromManifest(manifest) {
|
|
|
488
307
|
return manifest.metaData.getPublicPath;
|
|
489
308
|
}
|
|
490
309
|
};
|
|
491
|
-
|
|
492
|
-
|
|
310
|
+
const overridesKeys = Object.keys(overrides);
|
|
311
|
+
let remotesInfo = {};
|
|
493
312
|
// If remotes are not provided, only the remotes in the manifest will be read
|
|
494
313
|
if (!Object.keys(remotes).length) {
|
|
495
314
|
var _manifest_remotes;
|
|
496
|
-
remotesInfo = ((_manifest_remotes = manifest.remotes)
|
|
497
|
-
|
|
498
|
-
|
|
315
|
+
remotesInfo = ((_manifest_remotes = manifest.remotes) == null ? void 0 : _manifest_remotes.reduce((res, next)=>{
|
|
316
|
+
let matchedVersion;
|
|
317
|
+
const name = next.federationContainerName;
|
|
499
318
|
// overrides have higher priority
|
|
500
319
|
if (overridesKeys.includes(name)) {
|
|
501
320
|
matchedVersion = overrides[name];
|
|
@@ -507,64 +326,58 @@ function generateSnapshotFromManifest(manifest) {
|
|
|
507
326
|
}
|
|
508
327
|
}
|
|
509
328
|
res[name] = {
|
|
510
|
-
matchedVersion
|
|
329
|
+
matchedVersion
|
|
511
330
|
};
|
|
512
331
|
return res;
|
|
513
332
|
}, {})) || {};
|
|
514
333
|
}
|
|
515
334
|
// If remotes (deploy scenario) are specified, they need to be traversed again
|
|
516
|
-
Object.keys(remotes).forEach(
|
|
517
|
-
return remotesInfo[key] = {
|
|
335
|
+
Object.keys(remotes).forEach((key)=>remotesInfo[key] = {
|
|
518
336
|
// overrides will override dependencies
|
|
519
337
|
matchedVersion: overridesKeys.includes(key) ? overrides[key] : remotes[key]
|
|
520
|
-
};
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
var basicRemoteSnapshot = {
|
|
338
|
+
});
|
|
339
|
+
const { remoteEntry: { path: remoteEntryPath, name: remoteEntryName, type: remoteEntryType }, types: remoteTypes, buildInfo: { buildVersion }, globalName } = manifest.metaData;
|
|
340
|
+
const { exposes } = manifest;
|
|
341
|
+
let basicRemoteSnapshot = {
|
|
525
342
|
version: version ? version : '',
|
|
526
|
-
buildVersion
|
|
527
|
-
globalName
|
|
343
|
+
buildVersion,
|
|
344
|
+
globalName,
|
|
528
345
|
remoteEntry: simpleJoinRemoteEntry(remoteEntryPath, remoteEntryName),
|
|
529
|
-
remoteEntryType
|
|
346
|
+
remoteEntryType,
|
|
530
347
|
remoteTypes: simpleJoinRemoteEntry(remoteTypes.path, remoteTypes.name),
|
|
531
348
|
remoteTypesZip: remoteTypes.zip || '',
|
|
532
349
|
remoteTypesAPI: remoteTypes.api || '',
|
|
533
|
-
remotesInfo
|
|
534
|
-
shared: manifest
|
|
535
|
-
return {
|
|
350
|
+
remotesInfo,
|
|
351
|
+
shared: manifest == null ? void 0 : manifest.shared.map((item)=>({
|
|
536
352
|
assets: item.assets,
|
|
537
353
|
sharedName: item.name,
|
|
538
354
|
version: item.version
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
modules: exposes === null || exposes === void 0 ? void 0 : exposes.map(function(expose) {
|
|
542
|
-
return {
|
|
355
|
+
})),
|
|
356
|
+
modules: exposes == null ? void 0 : exposes.map((expose)=>({
|
|
543
357
|
moduleName: expose.name,
|
|
544
358
|
modulePath: expose.path,
|
|
545
359
|
assets: expose.assets
|
|
546
|
-
}
|
|
547
|
-
})
|
|
360
|
+
}))
|
|
548
361
|
};
|
|
549
|
-
if ((_manifest_metaData = manifest.metaData)
|
|
550
|
-
|
|
551
|
-
basicRemoteSnapshot =
|
|
552
|
-
prefetchInterface
|
|
362
|
+
if ((_manifest_metaData = manifest.metaData) == null ? void 0 : _manifest_metaData.prefetchInterface) {
|
|
363
|
+
const prefetchInterface = manifest.metaData.prefetchInterface;
|
|
364
|
+
basicRemoteSnapshot = _extends({}, basicRemoteSnapshot, {
|
|
365
|
+
prefetchInterface
|
|
553
366
|
});
|
|
554
367
|
}
|
|
555
|
-
if ((_manifest_metaData1 = manifest.metaData)
|
|
556
|
-
|
|
557
|
-
basicRemoteSnapshot =
|
|
368
|
+
if ((_manifest_metaData1 = manifest.metaData) == null ? void 0 : _manifest_metaData1.prefetchEntry) {
|
|
369
|
+
const { path, name, type } = manifest.metaData.prefetchEntry;
|
|
370
|
+
basicRemoteSnapshot = _extends({}, basicRemoteSnapshot, {
|
|
558
371
|
prefetchEntry: simpleJoinRemoteEntry(path, name),
|
|
559
372
|
prefetchEntryType: type
|
|
560
373
|
});
|
|
561
374
|
}
|
|
562
375
|
if ('publicPath' in manifest.metaData) {
|
|
563
|
-
remoteSnapshot =
|
|
376
|
+
remoteSnapshot = _extends({}, basicRemoteSnapshot, {
|
|
564
377
|
publicPath: getPublicPath()
|
|
565
378
|
});
|
|
566
379
|
} else {
|
|
567
|
-
remoteSnapshot =
|
|
380
|
+
remoteSnapshot = _extends({}, basicRemoteSnapshot, {
|
|
568
381
|
getPublicPath: getPublicPath()
|
|
569
382
|
});
|
|
570
383
|
}
|
|
@@ -578,228 +391,34 @@ function isManifestProvider(moduleInfo) {
|
|
|
578
391
|
}
|
|
579
392
|
}
|
|
580
393
|
|
|
581
|
-
|
|
394
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
395
|
+
async function safeWrapper(callback, disableWarn) {
|
|
582
396
|
try {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
} catch (
|
|
586
|
-
|
|
397
|
+
const res = await callback();
|
|
398
|
+
return res;
|
|
399
|
+
} catch (e) {
|
|
400
|
+
!disableWarn && warn(e);
|
|
587
401
|
return;
|
|
588
402
|
}
|
|
589
|
-
if (info.done) {
|
|
590
|
-
resolve(value);
|
|
591
|
-
} else {
|
|
592
|
-
Promise.resolve(value).then(_next, _throw);
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
function _async_to_generator$1(fn) {
|
|
596
|
-
return function() {
|
|
597
|
-
var self = this, args = arguments;
|
|
598
|
-
return new Promise(function(resolve, reject) {
|
|
599
|
-
var gen = fn.apply(self, args);
|
|
600
|
-
function _next(value) {
|
|
601
|
-
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
|
|
602
|
-
}
|
|
603
|
-
function _throw(err) {
|
|
604
|
-
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
|
|
605
|
-
}
|
|
606
|
-
_next(undefined);
|
|
607
|
-
});
|
|
608
|
-
};
|
|
609
|
-
}
|
|
610
|
-
function _define_property$1(obj, key, value) {
|
|
611
|
-
if (key in obj) {
|
|
612
|
-
Object.defineProperty(obj, key, {
|
|
613
|
-
value: value,
|
|
614
|
-
enumerable: true,
|
|
615
|
-
configurable: true,
|
|
616
|
-
writable: true
|
|
617
|
-
});
|
|
618
|
-
} else {
|
|
619
|
-
obj[key] = value;
|
|
620
|
-
}
|
|
621
|
-
return obj;
|
|
622
|
-
}
|
|
623
|
-
function _instanceof$1(left, right) {
|
|
624
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
625
|
-
return !!right[Symbol.hasInstance](left);
|
|
626
|
-
} else {
|
|
627
|
-
return left instanceof right;
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
function _object_spread$1(target) {
|
|
631
|
-
for(var i = 1; i < arguments.length; i++){
|
|
632
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
633
|
-
var ownKeys = Object.keys(source);
|
|
634
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
635
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
636
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
637
|
-
}));
|
|
638
|
-
}
|
|
639
|
-
ownKeys.forEach(function(key) {
|
|
640
|
-
_define_property$1(target, key, source[key]);
|
|
641
|
-
});
|
|
642
|
-
}
|
|
643
|
-
return target;
|
|
644
|
-
}
|
|
645
|
-
function _type_of$2(obj) {
|
|
646
|
-
"@swc/helpers - typeof";
|
|
647
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
648
|
-
}
|
|
649
|
-
function _ts_generator$1(thisArg, body) {
|
|
650
|
-
var f, y, t, g, _ = {
|
|
651
|
-
label: 0,
|
|
652
|
-
sent: function() {
|
|
653
|
-
if (t[0] & 1) throw t[1];
|
|
654
|
-
return t[1];
|
|
655
|
-
},
|
|
656
|
-
trys: [],
|
|
657
|
-
ops: []
|
|
658
|
-
};
|
|
659
|
-
return g = {
|
|
660
|
-
next: verb(0),
|
|
661
|
-
"throw": verb(1),
|
|
662
|
-
"return": verb(2)
|
|
663
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
664
|
-
return this;
|
|
665
|
-
}), g;
|
|
666
|
-
function verb(n) {
|
|
667
|
-
return function(v) {
|
|
668
|
-
return step([
|
|
669
|
-
n,
|
|
670
|
-
v
|
|
671
|
-
]);
|
|
672
|
-
};
|
|
673
|
-
}
|
|
674
|
-
function step(op) {
|
|
675
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
676
|
-
while(_)try {
|
|
677
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
678
|
-
if (y = 0, t) op = [
|
|
679
|
-
op[0] & 2,
|
|
680
|
-
t.value
|
|
681
|
-
];
|
|
682
|
-
switch(op[0]){
|
|
683
|
-
case 0:
|
|
684
|
-
case 1:
|
|
685
|
-
t = op;
|
|
686
|
-
break;
|
|
687
|
-
case 4:
|
|
688
|
-
_.label++;
|
|
689
|
-
return {
|
|
690
|
-
value: op[1],
|
|
691
|
-
done: false
|
|
692
|
-
};
|
|
693
|
-
case 5:
|
|
694
|
-
_.label++;
|
|
695
|
-
y = op[1];
|
|
696
|
-
op = [
|
|
697
|
-
0
|
|
698
|
-
];
|
|
699
|
-
continue;
|
|
700
|
-
case 7:
|
|
701
|
-
op = _.ops.pop();
|
|
702
|
-
_.trys.pop();
|
|
703
|
-
continue;
|
|
704
|
-
default:
|
|
705
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
706
|
-
_ = 0;
|
|
707
|
-
continue;
|
|
708
|
-
}
|
|
709
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
710
|
-
_.label = op[1];
|
|
711
|
-
break;
|
|
712
|
-
}
|
|
713
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
714
|
-
_.label = t[1];
|
|
715
|
-
t = op;
|
|
716
|
-
break;
|
|
717
|
-
}
|
|
718
|
-
if (t && _.label < t[2]) {
|
|
719
|
-
_.label = t[2];
|
|
720
|
-
_.ops.push(op);
|
|
721
|
-
break;
|
|
722
|
-
}
|
|
723
|
-
if (t[2]) _.ops.pop();
|
|
724
|
-
_.trys.pop();
|
|
725
|
-
continue;
|
|
726
|
-
}
|
|
727
|
-
op = body.call(thisArg, _);
|
|
728
|
-
} catch (e) {
|
|
729
|
-
op = [
|
|
730
|
-
6,
|
|
731
|
-
e
|
|
732
|
-
];
|
|
733
|
-
y = 0;
|
|
734
|
-
} finally{
|
|
735
|
-
f = t = 0;
|
|
736
|
-
}
|
|
737
|
-
if (op[0] & 5) throw op[1];
|
|
738
|
-
return {
|
|
739
|
-
value: op[0] ? op[1] : void 0,
|
|
740
|
-
done: true
|
|
741
|
-
};
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
745
|
-
function safeWrapper(callback, disableWarn) {
|
|
746
|
-
return _safeWrapper.apply(this, arguments);
|
|
747
|
-
}
|
|
748
|
-
function _safeWrapper() {
|
|
749
|
-
_safeWrapper = _async_to_generator$1(function(callback, disableWarn) {
|
|
750
|
-
var res, e;
|
|
751
|
-
return _ts_generator$1(this, function(_state) {
|
|
752
|
-
switch(_state.label){
|
|
753
|
-
case 0:
|
|
754
|
-
_state.trys.push([
|
|
755
|
-
0,
|
|
756
|
-
2,
|
|
757
|
-
,
|
|
758
|
-
3
|
|
759
|
-
]);
|
|
760
|
-
return [
|
|
761
|
-
4,
|
|
762
|
-
callback()
|
|
763
|
-
];
|
|
764
|
-
case 1:
|
|
765
|
-
res = _state.sent();
|
|
766
|
-
return [
|
|
767
|
-
2,
|
|
768
|
-
res
|
|
769
|
-
];
|
|
770
|
-
case 2:
|
|
771
|
-
e = _state.sent();
|
|
772
|
-
!disableWarn && warn(e);
|
|
773
|
-
return [
|
|
774
|
-
2
|
|
775
|
-
];
|
|
776
|
-
case 3:
|
|
777
|
-
return [
|
|
778
|
-
2
|
|
779
|
-
];
|
|
780
|
-
}
|
|
781
|
-
});
|
|
782
|
-
});
|
|
783
|
-
return _safeWrapper.apply(this, arguments);
|
|
784
403
|
}
|
|
785
404
|
function isStaticResourcesEqual(url1, url2) {
|
|
786
|
-
|
|
405
|
+
const REG_EXP = /^(https?:)?\/\//i;
|
|
787
406
|
// Transform url1 and url2 into relative paths
|
|
788
|
-
|
|
789
|
-
|
|
407
|
+
const relativeUrl1 = url1.replace(REG_EXP, '').replace(/\/$/, '');
|
|
408
|
+
const relativeUrl2 = url2.replace(REG_EXP, '').replace(/\/$/, '');
|
|
790
409
|
// Check if the relative paths are identical
|
|
791
410
|
return relativeUrl1 === relativeUrl2;
|
|
792
411
|
}
|
|
793
412
|
function createScript(info) {
|
|
794
413
|
// Retrieve the existing script element by its src attribute
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
for(
|
|
801
|
-
|
|
802
|
-
|
|
414
|
+
let script = null;
|
|
415
|
+
let needAttach = true;
|
|
416
|
+
let timeout = 20000;
|
|
417
|
+
let timeoutId;
|
|
418
|
+
const scripts = document.getElementsByTagName('script');
|
|
419
|
+
for(let i = 0; i < scripts.length; i++){
|
|
420
|
+
const s = scripts[i];
|
|
421
|
+
const scriptSrc = s.getAttribute('src');
|
|
803
422
|
if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {
|
|
804
423
|
script = s;
|
|
805
424
|
needAttach = false;
|
|
@@ -811,17 +430,17 @@ function createScript(info) {
|
|
|
811
430
|
script.type = 'text/javascript';
|
|
812
431
|
script.src = info.url;
|
|
813
432
|
if (info.createScriptHook) {
|
|
814
|
-
|
|
815
|
-
if (
|
|
433
|
+
const createScriptRes = info.createScriptHook(info.url, info.attrs);
|
|
434
|
+
if (createScriptRes instanceof HTMLScriptElement) {
|
|
816
435
|
script = createScriptRes;
|
|
817
|
-
} else if (
|
|
436
|
+
} else if (typeof createScriptRes === 'object') {
|
|
818
437
|
if (createScriptRes.script) script = createScriptRes.script;
|
|
819
438
|
if (createScriptRes.timeout) timeout = createScriptRes.timeout;
|
|
820
439
|
}
|
|
821
440
|
}
|
|
822
|
-
|
|
441
|
+
const attrs = info.attrs;
|
|
823
442
|
if (attrs) {
|
|
824
|
-
Object.keys(attrs).forEach(
|
|
443
|
+
Object.keys(attrs).forEach((name)=>{
|
|
825
444
|
if (script) {
|
|
826
445
|
if (name === 'async' || name === 'defer') {
|
|
827
446
|
script[name] = attrs[name];
|
|
@@ -833,50 +452,50 @@ function createScript(info) {
|
|
|
833
452
|
});
|
|
834
453
|
}
|
|
835
454
|
}
|
|
836
|
-
|
|
837
|
-
event)
|
|
455
|
+
const onScriptComplete = (prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
456
|
+
event)=>{
|
|
838
457
|
var _info_cb;
|
|
839
458
|
clearTimeout(timeoutId);
|
|
840
459
|
// Prevent memory leaks in IE.
|
|
841
460
|
if (script) {
|
|
842
461
|
script.onerror = null;
|
|
843
462
|
script.onload = null;
|
|
844
|
-
safeWrapper(
|
|
845
|
-
|
|
463
|
+
safeWrapper(()=>{
|
|
464
|
+
const { needDeleteScript = true } = info;
|
|
846
465
|
if (needDeleteScript) {
|
|
847
|
-
(script
|
|
466
|
+
(script == null ? void 0 : script.parentNode) && script.parentNode.removeChild(script);
|
|
848
467
|
}
|
|
849
468
|
});
|
|
850
469
|
if (prev) {
|
|
851
470
|
var _info_cb1;
|
|
852
471
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
853
|
-
|
|
854
|
-
info
|
|
472
|
+
const res = prev(event);
|
|
473
|
+
info == null ? void 0 : (_info_cb1 = info.cb) == null ? void 0 : _info_cb1.call(info);
|
|
855
474
|
return res;
|
|
856
475
|
}
|
|
857
476
|
}
|
|
858
|
-
info
|
|
477
|
+
info == null ? void 0 : (_info_cb = info.cb) == null ? void 0 : _info_cb.call(info);
|
|
859
478
|
};
|
|
860
479
|
script.onerror = onScriptComplete.bind(null, script.onerror);
|
|
861
480
|
script.onload = onScriptComplete.bind(null, script.onload);
|
|
862
|
-
timeoutId = setTimeout(
|
|
863
|
-
onScriptComplete(null, new Error(
|
|
481
|
+
timeoutId = setTimeout(()=>{
|
|
482
|
+
onScriptComplete(null, new Error(`Remote script "${info.url}" time-outed.`));
|
|
864
483
|
}, timeout);
|
|
865
484
|
return {
|
|
866
|
-
script
|
|
867
|
-
needAttach
|
|
485
|
+
script,
|
|
486
|
+
needAttach
|
|
868
487
|
};
|
|
869
488
|
}
|
|
870
489
|
function createLink(info) {
|
|
871
490
|
// <link rel="preload" href="script.js" as="script">
|
|
872
491
|
// Retrieve the existing script element by its src attribute
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
for(
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
492
|
+
let link = null;
|
|
493
|
+
let needAttach = true;
|
|
494
|
+
const links = document.getElementsByTagName('link');
|
|
495
|
+
for(let i = 0; i < links.length; i++){
|
|
496
|
+
const l = links[i];
|
|
497
|
+
const linkHref = l.getAttribute('href');
|
|
498
|
+
const linkRef = l.getAttribute('ref');
|
|
880
499
|
if (linkHref && isStaticResourcesEqual(linkHref, info.url) && linkRef === info.attrs['ref']) {
|
|
881
500
|
link = l;
|
|
882
501
|
needAttach = false;
|
|
@@ -887,35 +506,35 @@ function createLink(info) {
|
|
|
887
506
|
link = document.createElement('link');
|
|
888
507
|
link.setAttribute('href', info.url);
|
|
889
508
|
if (info.createLinkHook) {
|
|
890
|
-
|
|
891
|
-
if (
|
|
509
|
+
const createLinkRes = info.createLinkHook(info.url);
|
|
510
|
+
if (createLinkRes instanceof HTMLLinkElement) {
|
|
892
511
|
link = createLinkRes;
|
|
893
512
|
}
|
|
894
513
|
}
|
|
895
|
-
|
|
514
|
+
const attrs = info.attrs;
|
|
896
515
|
if (attrs) {
|
|
897
|
-
Object.keys(attrs).forEach(
|
|
516
|
+
Object.keys(attrs).forEach((name)=>{
|
|
898
517
|
if (link && !link.getAttribute(name)) {
|
|
899
518
|
link.setAttribute(name, attrs[name]);
|
|
900
519
|
}
|
|
901
520
|
});
|
|
902
521
|
}
|
|
903
522
|
}
|
|
904
|
-
|
|
905
|
-
event)
|
|
523
|
+
const onLinkComplete = (prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
524
|
+
event)=>{
|
|
906
525
|
// Prevent memory leaks in IE.
|
|
907
526
|
if (link) {
|
|
908
527
|
link.onerror = null;
|
|
909
528
|
link.onload = null;
|
|
910
|
-
safeWrapper(
|
|
911
|
-
|
|
529
|
+
safeWrapper(()=>{
|
|
530
|
+
const { needDeleteLink = true } = info;
|
|
912
531
|
if (needDeleteLink) {
|
|
913
|
-
(link
|
|
532
|
+
(link == null ? void 0 : link.parentNode) && link.parentNode.removeChild(link);
|
|
914
533
|
}
|
|
915
534
|
});
|
|
916
535
|
if (prev) {
|
|
917
536
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
918
|
-
|
|
537
|
+
const res = prev(event);
|
|
919
538
|
info.cb();
|
|
920
539
|
return res;
|
|
921
540
|
}
|
|
@@ -925,473 +544,132 @@ function createLink(info) {
|
|
|
925
544
|
link.onerror = onLinkComplete.bind(null, link.onerror);
|
|
926
545
|
link.onload = onLinkComplete.bind(null, link.onload);
|
|
927
546
|
return {
|
|
928
|
-
link
|
|
929
|
-
needAttach
|
|
547
|
+
link,
|
|
548
|
+
needAttach
|
|
930
549
|
};
|
|
931
550
|
}
|
|
932
551
|
function loadScript(url, info) {
|
|
933
|
-
|
|
934
|
-
return new Promise(
|
|
935
|
-
|
|
936
|
-
url
|
|
552
|
+
const { attrs = {}, createScriptHook } = info;
|
|
553
|
+
return new Promise((resolve, _reject)=>{
|
|
554
|
+
const { script, needAttach } = createScript({
|
|
555
|
+
url,
|
|
937
556
|
cb: resolve,
|
|
938
|
-
attrs:
|
|
557
|
+
attrs: _extends({
|
|
939
558
|
crossorigin: 'anonymous',
|
|
940
559
|
fetchpriority: 'high'
|
|
941
560
|
}, attrs),
|
|
942
|
-
createScriptHook
|
|
561
|
+
createScriptHook,
|
|
943
562
|
needDeleteScript: true
|
|
944
|
-
})
|
|
563
|
+
});
|
|
945
564
|
needAttach && document.head.appendChild(script);
|
|
946
565
|
});
|
|
947
566
|
}
|
|
948
567
|
|
|
949
|
-
function _array_like_to_array(arr, len) {
|
|
950
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
951
|
-
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
952
|
-
return arr2;
|
|
953
|
-
}
|
|
954
|
-
function _array_with_holes(arr) {
|
|
955
|
-
if (Array.isArray(arr)) return arr;
|
|
956
|
-
}
|
|
957
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
958
|
-
try {
|
|
959
|
-
var info = gen[key](arg);
|
|
960
|
-
var value = info.value;
|
|
961
|
-
} catch (error) {
|
|
962
|
-
reject(error);
|
|
963
|
-
return;
|
|
964
|
-
}
|
|
965
|
-
if (info.done) {
|
|
966
|
-
resolve(value);
|
|
967
|
-
} else {
|
|
968
|
-
Promise.resolve(value).then(_next, _throw);
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
function _async_to_generator(fn) {
|
|
972
|
-
return function() {
|
|
973
|
-
var self = this, args = arguments;
|
|
974
|
-
return new Promise(function(resolve, reject) {
|
|
975
|
-
var gen = fn.apply(self, args);
|
|
976
|
-
function _next(value) {
|
|
977
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
978
|
-
}
|
|
979
|
-
function _throw(err) {
|
|
980
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
981
|
-
}
|
|
982
|
-
_next(undefined);
|
|
983
|
-
});
|
|
984
|
-
};
|
|
985
|
-
}
|
|
986
|
-
function _instanceof(left, right) {
|
|
987
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
988
|
-
return !!right[Symbol.hasInstance](left);
|
|
989
|
-
} else {
|
|
990
|
-
return left instanceof right;
|
|
991
|
-
}
|
|
992
|
-
}
|
|
993
|
-
function _iterable_to_array_limit(arr, i) {
|
|
994
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
995
|
-
if (_i == null) return;
|
|
996
|
-
var _arr = [];
|
|
997
|
-
var _n = true;
|
|
998
|
-
var _d = false;
|
|
999
|
-
var _s, _e;
|
|
1000
|
-
try {
|
|
1001
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
1002
|
-
_arr.push(_s.value);
|
|
1003
|
-
if (i && _arr.length === i) break;
|
|
1004
|
-
}
|
|
1005
|
-
} catch (err) {
|
|
1006
|
-
_d = true;
|
|
1007
|
-
_e = err;
|
|
1008
|
-
} finally{
|
|
1009
|
-
try {
|
|
1010
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
1011
|
-
} finally{
|
|
1012
|
-
if (_d) throw _e;
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
return _arr;
|
|
1016
|
-
}
|
|
1017
|
-
function _non_iterable_rest() {
|
|
1018
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1019
|
-
}
|
|
1020
|
-
function _sliced_to_array(arr, i) {
|
|
1021
|
-
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
1022
|
-
}
|
|
1023
|
-
function _type_of$1(obj) {
|
|
1024
|
-
"@swc/helpers - typeof";
|
|
1025
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
1026
|
-
}
|
|
1027
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
1028
|
-
if (!o) return;
|
|
1029
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
1030
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
1031
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
1032
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
1033
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
1034
|
-
}
|
|
1035
|
-
function _ts_generator(thisArg, body) {
|
|
1036
|
-
var f, y, t, g, _ = {
|
|
1037
|
-
label: 0,
|
|
1038
|
-
sent: function() {
|
|
1039
|
-
if (t[0] & 1) throw t[1];
|
|
1040
|
-
return t[1];
|
|
1041
|
-
},
|
|
1042
|
-
trys: [],
|
|
1043
|
-
ops: []
|
|
1044
|
-
};
|
|
1045
|
-
return g = {
|
|
1046
|
-
next: verb(0),
|
|
1047
|
-
"throw": verb(1),
|
|
1048
|
-
"return": verb(2)
|
|
1049
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
1050
|
-
return this;
|
|
1051
|
-
}), g;
|
|
1052
|
-
function verb(n) {
|
|
1053
|
-
return function(v) {
|
|
1054
|
-
return step([
|
|
1055
|
-
n,
|
|
1056
|
-
v
|
|
1057
|
-
]);
|
|
1058
|
-
};
|
|
1059
|
-
}
|
|
1060
|
-
function step(op) {
|
|
1061
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
1062
|
-
while(_)try {
|
|
1063
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
1064
|
-
if (y = 0, t) op = [
|
|
1065
|
-
op[0] & 2,
|
|
1066
|
-
t.value
|
|
1067
|
-
];
|
|
1068
|
-
switch(op[0]){
|
|
1069
|
-
case 0:
|
|
1070
|
-
case 1:
|
|
1071
|
-
t = op;
|
|
1072
|
-
break;
|
|
1073
|
-
case 4:
|
|
1074
|
-
_.label++;
|
|
1075
|
-
return {
|
|
1076
|
-
value: op[1],
|
|
1077
|
-
done: false
|
|
1078
|
-
};
|
|
1079
|
-
case 5:
|
|
1080
|
-
_.label++;
|
|
1081
|
-
y = op[1];
|
|
1082
|
-
op = [
|
|
1083
|
-
0
|
|
1084
|
-
];
|
|
1085
|
-
continue;
|
|
1086
|
-
case 7:
|
|
1087
|
-
op = _.ops.pop();
|
|
1088
|
-
_.trys.pop();
|
|
1089
|
-
continue;
|
|
1090
|
-
default:
|
|
1091
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
1092
|
-
_ = 0;
|
|
1093
|
-
continue;
|
|
1094
|
-
}
|
|
1095
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
1096
|
-
_.label = op[1];
|
|
1097
|
-
break;
|
|
1098
|
-
}
|
|
1099
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
1100
|
-
_.label = t[1];
|
|
1101
|
-
t = op;
|
|
1102
|
-
break;
|
|
1103
|
-
}
|
|
1104
|
-
if (t && _.label < t[2]) {
|
|
1105
|
-
_.label = t[2];
|
|
1106
|
-
_.ops.push(op);
|
|
1107
|
-
break;
|
|
1108
|
-
}
|
|
1109
|
-
if (t[2]) _.ops.pop();
|
|
1110
|
-
_.trys.pop();
|
|
1111
|
-
continue;
|
|
1112
|
-
}
|
|
1113
|
-
op = body.call(thisArg, _);
|
|
1114
|
-
} catch (e) {
|
|
1115
|
-
op = [
|
|
1116
|
-
6,
|
|
1117
|
-
e
|
|
1118
|
-
];
|
|
1119
|
-
y = 0;
|
|
1120
|
-
} finally{
|
|
1121
|
-
f = t = 0;
|
|
1122
|
-
}
|
|
1123
|
-
if (op[0] & 5) throw op[1];
|
|
1124
|
-
return {
|
|
1125
|
-
value: op[0] ? op[1] : void 0,
|
|
1126
|
-
done: true
|
|
1127
|
-
};
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
568
|
function importNodeModule(name) {
|
|
1131
569
|
if (!name) {
|
|
1132
570
|
throw new Error('import specifier is required');
|
|
1133
571
|
}
|
|
1134
|
-
|
|
1135
|
-
return importModule(name).then(
|
|
1136
|
-
|
|
1137
|
-
}).catch(function(error) {
|
|
1138
|
-
console.error("Error importing module ".concat(name, ":"), error);
|
|
572
|
+
const importModule = new Function('name', `return import(name)`);
|
|
573
|
+
return importModule(name).then((res)=>res.default).catch((error)=>{
|
|
574
|
+
console.error(`Error importing module ${name}:`, error);
|
|
1139
575
|
throw error;
|
|
1140
576
|
});
|
|
1141
577
|
}
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
];
|
|
1152
|
-
case 1:
|
|
1153
|
-
fetchModule = _state.sent();
|
|
1154
|
-
return [
|
|
1155
|
-
2,
|
|
1156
|
-
fetchModule.default || fetchModule
|
|
1157
|
-
];
|
|
1158
|
-
}
|
|
1159
|
-
});
|
|
1160
|
-
});
|
|
1161
|
-
return function loadNodeFetch1() {
|
|
1162
|
-
return _ref.apply(this, arguments);
|
|
1163
|
-
};
|
|
1164
|
-
}();
|
|
1165
|
-
var lazyLoaderHookFetch = function() {
|
|
1166
|
-
var _ref = _async_to_generator(function(input, init) {
|
|
1167
|
-
var loaderHooks, hook, res, fetchFunction, _tmp;
|
|
1168
|
-
return _ts_generator(this, function(_state) {
|
|
1169
|
-
switch(_state.label){
|
|
1170
|
-
case 0:
|
|
1171
|
-
// @ts-ignore
|
|
1172
|
-
loaderHooks = __webpack_require__.federation.instance.loaderHook;
|
|
1173
|
-
hook = function(url, init) {
|
|
1174
|
-
return loaderHooks.lifecycle.fetch.emit(url, init);
|
|
1175
|
-
};
|
|
1176
|
-
return [
|
|
1177
|
-
4,
|
|
1178
|
-
hook(input, init || {})
|
|
1179
|
-
];
|
|
1180
|
-
case 1:
|
|
1181
|
-
res = _state.sent();
|
|
1182
|
-
if (!(!res || !_instanceof(res, Response))) return [
|
|
1183
|
-
3,
|
|
1184
|
-
5
|
|
1185
|
-
];
|
|
1186
|
-
if (!(typeof fetch === 'undefined')) return [
|
|
1187
|
-
3,
|
|
1188
|
-
3
|
|
1189
|
-
];
|
|
1190
|
-
return [
|
|
1191
|
-
4,
|
|
1192
|
-
loadNodeFetch()
|
|
1193
|
-
];
|
|
1194
|
-
case 2:
|
|
1195
|
-
_tmp = _state.sent();
|
|
1196
|
-
return [
|
|
1197
|
-
3,
|
|
1198
|
-
4
|
|
1199
|
-
];
|
|
1200
|
-
case 3:
|
|
1201
|
-
_tmp = fetch;
|
|
1202
|
-
_state.label = 4;
|
|
1203
|
-
case 4:
|
|
1204
|
-
fetchFunction = _tmp;
|
|
1205
|
-
return [
|
|
1206
|
-
2,
|
|
1207
|
-
fetchFunction(input, init || {})
|
|
1208
|
-
];
|
|
1209
|
-
case 5:
|
|
1210
|
-
return [
|
|
1211
|
-
2,
|
|
1212
|
-
res
|
|
1213
|
-
];
|
|
1214
|
-
}
|
|
1215
|
-
});
|
|
1216
|
-
});
|
|
1217
|
-
return function lazyLoaderHookFetch1(input, init) {
|
|
1218
|
-
return _ref.apply(this, arguments);
|
|
578
|
+
const loadNodeFetch = async ()=>{
|
|
579
|
+
const fetchModule = await importNodeModule('node-fetch');
|
|
580
|
+
return fetchModule.default || fetchModule;
|
|
581
|
+
};
|
|
582
|
+
const lazyLoaderHookFetch = async (input, init)=>{
|
|
583
|
+
// @ts-ignore
|
|
584
|
+
const loaderHooks = __webpack_require__.federation.instance.loaderHook;
|
|
585
|
+
const hook = (url, init)=>{
|
|
586
|
+
return loaderHooks.lifecycle.fetch.emit(url, init);
|
|
1219
587
|
};
|
|
1220
|
-
}
|
|
588
|
+
const res = await hook(input, init || {});
|
|
589
|
+
if (!res || !(res instanceof Response)) {
|
|
590
|
+
const fetchFunction = typeof fetch === 'undefined' ? await loadNodeFetch() : fetch;
|
|
591
|
+
return fetchFunction(input, init || {});
|
|
592
|
+
}
|
|
593
|
+
return res;
|
|
594
|
+
};
|
|
1221
595
|
function createScriptNode(url, cb, attrs, createScriptHook) {
|
|
1222
596
|
if (createScriptHook) {
|
|
1223
|
-
|
|
1224
|
-
if (hookResult &&
|
|
597
|
+
const hookResult = createScriptHook(url);
|
|
598
|
+
if (hookResult && typeof hookResult === 'object' && 'url' in hookResult) {
|
|
1225
599
|
url = hookResult.url;
|
|
1226
600
|
}
|
|
1227
601
|
}
|
|
1228
|
-
|
|
602
|
+
let urlObj;
|
|
1229
603
|
try {
|
|
1230
604
|
urlObj = new URL(url);
|
|
1231
605
|
} catch (e) {
|
|
1232
606
|
console.error('Error constructing URL:', e);
|
|
1233
|
-
cb(new Error(
|
|
607
|
+
cb(new Error(`Invalid URL: ${e}`));
|
|
1234
608
|
return;
|
|
1235
609
|
}
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
610
|
+
const getFetch = async ()=>{
|
|
611
|
+
//@ts-ignore
|
|
612
|
+
if (typeof __webpack_require__ !== 'undefined') {
|
|
613
|
+
try {
|
|
1240
614
|
//@ts-ignore
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
loaderHooks = __webpack_require__.federation.instance.loaderHook;
|
|
1245
|
-
if (loaderHooks.lifecycle.fetch) {
|
|
1246
|
-
return [
|
|
1247
|
-
2,
|
|
1248
|
-
lazyLoaderHookFetch
|
|
1249
|
-
];
|
|
1250
|
-
}
|
|
1251
|
-
} catch (e) {
|
|
1252
|
-
console.warn('federation.instance.loaderHook.lifecycle.fetch failed:', e);
|
|
1253
|
-
}
|
|
615
|
+
const loaderHooks = __webpack_require__.federation.instance.loaderHook;
|
|
616
|
+
if (loaderHooks.lifecycle.fetch) {
|
|
617
|
+
return lazyLoaderHookFetch;
|
|
1254
618
|
}
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
4,
|
|
1274
|
-
,
|
|
1275
|
-
5
|
|
1276
|
-
]);
|
|
1277
|
-
return [
|
|
1278
|
-
4,
|
|
1279
|
-
f(urlObj.href)
|
|
1280
|
-
];
|
|
1281
|
-
case 1:
|
|
1282
|
-
res = _state.sent();
|
|
1283
|
-
return [
|
|
1284
|
-
4,
|
|
1285
|
-
res.text()
|
|
1286
|
-
];
|
|
1287
|
-
case 2:
|
|
1288
|
-
data = _state.sent();
|
|
1289
|
-
return [
|
|
1290
|
-
4,
|
|
1291
|
-
Promise.all([
|
|
1292
|
-
importNodeModule('path'),
|
|
1293
|
-
importNodeModule('vm')
|
|
1294
|
-
])
|
|
1295
|
-
];
|
|
1296
|
-
case 3:
|
|
1297
|
-
_ref = _sliced_to_array.apply(void 0, [
|
|
1298
|
-
_state.sent(),
|
|
1299
|
-
2
|
|
1300
|
-
]), path = _ref[0], vm = _ref[1];
|
|
1301
|
-
scriptContext = {
|
|
1302
|
-
exports: {},
|
|
1303
|
-
module: {
|
|
1304
|
-
exports: {}
|
|
1305
|
-
}
|
|
1306
|
-
};
|
|
1307
|
-
urlDirname = urlObj.pathname.split('/').slice(0, -1).join('/');
|
|
1308
|
-
filename = path.basename(urlObj.pathname);
|
|
1309
|
-
script = new vm.Script("(function(exports, module, require, __dirname, __filename) {".concat(data, "\n})"), filename);
|
|
1310
|
-
script.runInThisContext()(scriptContext.exports, scriptContext.module, eval('require'), urlDirname, filename);
|
|
1311
|
-
exportedInterface = scriptContext.module.exports || scriptContext.exports;
|
|
1312
|
-
if (attrs && exportedInterface && attrs['globalName']) {
|
|
1313
|
-
container = exportedInterface[attrs['globalName']] || exportedInterface;
|
|
1314
|
-
cb(undefined, container);
|
|
1315
|
-
return [
|
|
1316
|
-
2
|
|
1317
|
-
];
|
|
1318
|
-
}
|
|
1319
|
-
cb(undefined, exportedInterface);
|
|
1320
|
-
return [
|
|
1321
|
-
3,
|
|
1322
|
-
5
|
|
1323
|
-
];
|
|
1324
|
-
case 4:
|
|
1325
|
-
e = _state.sent();
|
|
1326
|
-
cb(new Error("Script execution error: ".concat(e)));
|
|
1327
|
-
return [
|
|
1328
|
-
3,
|
|
1329
|
-
5
|
|
1330
|
-
];
|
|
1331
|
-
case 5:
|
|
1332
|
-
return [
|
|
1333
|
-
2
|
|
1334
|
-
];
|
|
619
|
+
} catch (e) {
|
|
620
|
+
console.warn('federation.instance.loaderHook.lifecycle.fetch failed:', e);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
return typeof fetch === 'undefined' ? loadNodeFetch() : fetch;
|
|
624
|
+
};
|
|
625
|
+
const handleScriptFetch = async (f, urlObj)=>{
|
|
626
|
+
try {
|
|
627
|
+
const res = await f(urlObj.href);
|
|
628
|
+
const data = await res.text();
|
|
629
|
+
const [path, vm] = await Promise.all([
|
|
630
|
+
importNodeModule('path'),
|
|
631
|
+
importNodeModule('vm')
|
|
632
|
+
]);
|
|
633
|
+
const scriptContext = {
|
|
634
|
+
exports: {},
|
|
635
|
+
module: {
|
|
636
|
+
exports: {}
|
|
1335
637
|
}
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
638
|
+
};
|
|
639
|
+
const urlDirname = urlObj.pathname.split('/').slice(0, -1).join('/');
|
|
640
|
+
const filename = path.basename(urlObj.pathname);
|
|
641
|
+
const script = new vm.Script(`(function(exports, module, require, __dirname, __filename) {${data}\n})`, filename);
|
|
642
|
+
script.runInThisContext()(scriptContext.exports, scriptContext.module, eval('require'), urlDirname, filename);
|
|
643
|
+
const exportedInterface = scriptContext.module.exports || scriptContext.exports;
|
|
644
|
+
if (attrs && exportedInterface && attrs['globalName']) {
|
|
645
|
+
const container = exportedInterface[attrs['globalName']] || exportedInterface;
|
|
646
|
+
cb(undefined, container);
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
cb(undefined, exportedInterface);
|
|
650
|
+
} catch (e) {
|
|
651
|
+
cb(new Error(`Script execution error: ${e}`));
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
getFetch().then((f)=>handleScriptFetch(f, urlObj)).catch((err)=>{
|
|
1345
655
|
cb(err);
|
|
1346
656
|
});
|
|
1347
657
|
}
|
|
1348
658
|
function loadScriptNode(url, info) {
|
|
1349
|
-
return new Promise(
|
|
1350
|
-
createScriptNode(url,
|
|
659
|
+
return new Promise((resolve, reject)=>{
|
|
660
|
+
createScriptNode(url, (error, scriptContext)=>{
|
|
1351
661
|
if (error) {
|
|
1352
662
|
reject(error);
|
|
1353
663
|
} else {
|
|
1354
664
|
var _info_attrs, _info_attrs1;
|
|
1355
|
-
|
|
1356
|
-
|
|
665
|
+
const remoteEntryKey = (info == null ? void 0 : (_info_attrs = info.attrs) == null ? void 0 : _info_attrs['globalName']) || `__FEDERATION_${info == null ? void 0 : (_info_attrs1 = info.attrs) == null ? void 0 : _info_attrs1['name']}:custom__`;
|
|
666
|
+
const entryExports = globalThis[remoteEntryKey] = scriptContext;
|
|
1357
667
|
resolve(entryExports);
|
|
1358
668
|
}
|
|
1359
669
|
}, info.attrs, info.createScriptHook);
|
|
1360
670
|
});
|
|
1361
671
|
}
|
|
1362
672
|
|
|
1363
|
-
function _define_property(obj, key, value) {
|
|
1364
|
-
if (key in obj) {
|
|
1365
|
-
Object.defineProperty(obj, key, {
|
|
1366
|
-
value: value,
|
|
1367
|
-
enumerable: true,
|
|
1368
|
-
configurable: true,
|
|
1369
|
-
writable: true
|
|
1370
|
-
});
|
|
1371
|
-
} else {
|
|
1372
|
-
obj[key] = value;
|
|
1373
|
-
}
|
|
1374
|
-
return obj;
|
|
1375
|
-
}
|
|
1376
|
-
function _object_spread(target) {
|
|
1377
|
-
for(var i = 1; i < arguments.length; i++){
|
|
1378
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
1379
|
-
var ownKeys = Object.keys(source);
|
|
1380
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
1381
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
1382
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
1383
|
-
}));
|
|
1384
|
-
}
|
|
1385
|
-
ownKeys.forEach(function(key) {
|
|
1386
|
-
_define_property(target, key, source[key]);
|
|
1387
|
-
});
|
|
1388
|
-
}
|
|
1389
|
-
return target;
|
|
1390
|
-
}
|
|
1391
|
-
function _type_of(obj) {
|
|
1392
|
-
"@swc/helpers - typeof";
|
|
1393
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
1394
|
-
}
|
|
1395
673
|
function normalizeOptions(enableDefault, defaultOptions, key) {
|
|
1396
674
|
return function(options) {
|
|
1397
675
|
if (options === false) {
|
|
@@ -1407,10 +685,10 @@ function normalizeOptions(enableDefault, defaultOptions, key) {
|
|
|
1407
685
|
if (options === true) {
|
|
1408
686
|
return defaultOptions;
|
|
1409
687
|
}
|
|
1410
|
-
if (options &&
|
|
1411
|
-
return
|
|
688
|
+
if (options && typeof options === 'object') {
|
|
689
|
+
return _extends({}, defaultOptions, options);
|
|
1412
690
|
}
|
|
1413
|
-
throw new Error(
|
|
691
|
+
throw new Error(`Unexpected type for \`${key}\`, expect boolean/undefined/object, got: ${typeof options}`);
|
|
1414
692
|
};
|
|
1415
693
|
}
|
|
1416
694
|
|