@module-federation/runtime 1.0.0-canary.5 → 1.1.0-canary.1

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/index.esm.js CHANGED
@@ -1,18 +1,7 @@
1
- import { i as isStaticResourcesEqual, s as safeWrapper, g as getGlobalHostPlugins, _ as _extends, D as DEFAULT_REMOTE_TYPE, a as DEFAULT_SCOPE, b as globalLoading, c as getRemoteEntryExports, d as assert, e as safeToString$1, G as Global, f as getFMId, h as isObject, j as error, w as warn, k as isPlainObject, l as isRemoteInfoWithEntry, m as isPureRemoteEntry, n as getGlobalShare, o as getInfoWithoutType, p as getPreloaded, q as setPreloaded, r as getGlobalSnapshotInfoByModuleInfo, t as setGlobalSnapshotInfoByModuleInfo, u as getGlobalSnapshot, v as addUniqueItem, x as formatShareConfigs, y as isBrowserEnv$1, z as getGlobalShareScope, A as _object_without_properties_loose, B as getBuilderId, C as setGlobalFederationConstructor, E as getGlobalFederationInstance, F as getGlobalFederationConstructor, H as setGlobalFederationInstance } from './share.esm.js';
2
- export { I as registerGlobalPlugins } from './share.esm.js';
1
+ import { g as getGlobalHostPlugins, D as DEFAULT_REMOTE_TYPE, a as DEFAULT_SCOPE, b as globalLoading, c as getRemoteEntryExports, d as assert, s as safeToString, G as Global, e as getFMId, i as isObject, f as error, w as warn, h as isPlainObject, j as isRemoteInfoWithEntry, k as isPureRemoteEntry, l as getGlobalShare, m as getInfoWithoutType, n as getPreloaded, o as setPreloaded, p as getGlobalSnapshotInfoByModuleInfo, q as setGlobalSnapshotInfoByModuleInfo, r as getGlobalSnapshot, t as addUniqueItem, u as formatShareConfigs, v as isBrowserEnv, x as getGlobalShareScope, y as getBuilderId, z as setGlobalFederationConstructor, A as getGlobalFederationInstance, B as getGlobalFederationConstructor, C as setGlobalFederationInstance } from './share.esm.js';
2
+ export { E as registerGlobalPlugins } from './share.esm.js';
3
+ import { composeKeyWithSeparator, loadScript, createScript, getResourceUrl, isManifestProvider, generateSnapshotFromManifest } from '@module-federation/sdk';
3
4
 
4
- // Function to get the URL of a resource
5
- function getResourceUrl(module, sourceUrl) {
6
- if ('getPublicPath' in module) {
7
- const publicPath = new Function(module.getPublicPath)();
8
- return `${publicPath}${sourceUrl}`;
9
- } else if ('publicPath' in module) {
10
- return `${module.publicPath}${sourceUrl}`;
11
- } else {
12
- console.warn('Unable to retrieve resource URL. If in debug mode, this warning can be disregarded.', module, sourceUrl);
13
- return '';
14
- }
15
- }
16
5
  // Function to match a remote with its name and expose
17
6
  // id: pkgName(@federation/app1) + expose(button) = @federation/app1/button
18
7
  // id: alias(app1) + expose(button) = app1/button
@@ -77,75 +66,6 @@ function matchRemote(remotes, nameOrAlias) {
77
66
  return;
78
67
  }
79
68
 
80
- function createScript(url, cb, attrs, createScriptHook) {
81
- // Retrieve the existing script element by its src attribute
82
- let script = null;
83
- let needAttach = true;
84
- const scripts = document.getElementsByTagName('script');
85
- for(let i = 0; i < scripts.length; i++){
86
- const s = scripts[i];
87
- const scriptSrc = s.getAttribute('src');
88
- if (scriptSrc && isStaticResourcesEqual(scriptSrc, url)) {
89
- script = s;
90
- needAttach = false;
91
- break;
92
- }
93
- }
94
- if (!script) {
95
- script = document.createElement('script');
96
- script.type = 'text/javascript';
97
- script.src = url;
98
- if (createScriptHook) {
99
- const createScriptRes = createScriptHook(url);
100
- if (createScriptRes instanceof HTMLScriptElement) {
101
- script = createScriptRes;
102
- }
103
- }
104
- }
105
- if (attrs) {
106
- Object.keys(attrs).forEach((name)=>{
107
- if (script) {
108
- if (name === 'async' || name === 'defer') {
109
- script[name] = attrs[name];
110
- } else {
111
- script.setAttribute(name, attrs[name]);
112
- }
113
- }
114
- });
115
- }
116
- const onScriptComplete = (prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
117
- event)=>{
118
- // Prevent memory leaks in IE.
119
- if (script) {
120
- script.onerror = null;
121
- script.onload = null;
122
- safeWrapper(()=>{
123
- (script == null ? void 0 : script.parentNode) && script.parentNode.removeChild(script);
124
- });
125
- if (prev) {
126
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
127
- const res = prev(event);
128
- cb();
129
- return res;
130
- }
131
- }
132
- cb();
133
- };
134
- script.onerror = onScriptComplete.bind(null, script.onerror);
135
- script.onload = onScriptComplete.bind(null, script.onload);
136
- return {
137
- script,
138
- needAttach
139
- };
140
- }
141
- function loadScript(url, info) {
142
- const { attrs, createScriptHook } = info;
143
- return new Promise((resolve, _reject)=>{
144
- const { script, needAttach } = createScript(url, resolve, attrs, createScriptHook);
145
- needAttach && document.getElementsByTagName('head')[0].appendChild(script);
146
- });
147
- }
148
-
149
69
  function registerPlugins(plugins, hookInstances) {
150
70
  const globalPlugins = getGlobalHostPlugins();
151
71
  // Incorporate global plugins
@@ -165,347 +85,20 @@ function registerPlugins(plugins, hookInstances) {
165
85
  }
166
86
  }
167
87
 
168
- function _instanceof(left, right) {
169
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
170
- return !!right[Symbol.hasInstance](left);
171
- } else {
172
- return left instanceof right;
173
- }
174
- }
175
- function _define_property$2(obj, key, value) {
176
- if (key in obj) {
177
- Object.defineProperty(obj, key, {
178
- value: value,
179
- enumerable: true,
180
- configurable: true,
181
- writable: true
182
- });
183
- } else {
184
- obj[key] = value;
185
- }
186
- return obj;
187
- }
188
- var MANIFEST_EXT = ".json";
189
- var BROWSER_LOG_KEY = "''";
190
- var BROWSER_LOG_VALUE = "1";
191
- var NameTransformSymbol = {
192
- AT: "@",
193
- HYPHEN: "-",
194
- SLASH: "/"
195
- };
196
- var _obj;
197
- var NameTransformMap = (_obj = {}, _define_property$2(_obj, NameTransformSymbol.AT, "scope_"), _define_property$2(_obj, NameTransformSymbol.HYPHEN, "_"), _define_property$2(_obj, NameTransformSymbol.SLASH, "__"), _obj);
198
- var _obj1;
199
- (_obj1 = {}, _define_property$2(_obj1, NameTransformMap[NameTransformSymbol.AT], NameTransformSymbol.AT), _define_property$2(_obj1, NameTransformMap[NameTransformSymbol.HYPHEN], NameTransformSymbol.HYPHEN), _define_property$2(_obj1, NameTransformMap[NameTransformSymbol.SLASH], NameTransformSymbol.SLASH), _obj1);
200
- var SEPARATOR = ":";
201
- function isBrowserEnv() {
202
- return typeof window !== "undefined";
203
- }
204
- function isDebugMode() {
205
- if (typeof process !== "undefined" && process.env && process.env["''"]) {
206
- return Boolean(process.env["''"]);
207
- }
208
- return Boolean('');
209
- }
210
- function _array_like_to_array$1(arr, len) {
211
- if (len == null || len > arr.length) len = arr.length;
212
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
213
- return arr2;
214
- }
215
- function _array_without_holes(arr) {
216
- if (Array.isArray(arr)) return _array_like_to_array$1(arr);
217
- }
218
- function _class_call_check(instance, Constructor) {
219
- if (!_instanceof(instance, Constructor)) {
220
- throw new TypeError("Cannot call a class as a function");
221
- }
222
- }
223
- function _defineProperties(target, props) {
224
- for(var i = 0; i < props.length; i++){
225
- var descriptor = props[i];
226
- descriptor.enumerable = descriptor.enumerable || false;
227
- descriptor.configurable = true;
228
- if ("value" in descriptor) descriptor.writable = true;
229
- Object.defineProperty(target, descriptor.key, descriptor);
230
- }
231
- }
232
- function _create_class(Constructor, protoProps, staticProps) {
233
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
234
- if (staticProps) _defineProperties(Constructor, staticProps);
235
- return Constructor;
236
- }
237
- function _define_property$1(obj, key, value) {
238
- if (key in obj) {
239
- Object.defineProperty(obj, key, {
240
- value: value,
241
- enumerable: true,
242
- configurable: true,
243
- writable: true
244
- });
245
- } else {
246
- obj[key] = value;
247
- }
248
- return obj;
249
- }
250
- function _iterable_to_array$1(iter) {
251
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
252
- }
253
- function _non_iterable_spread() {
254
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
255
- }
256
- function _to_consumable_array(arr) {
257
- return _array_without_holes(arr) || _iterable_to_array$1(arr) || _unsupported_iterable_to_array$1(arr) || _non_iterable_spread();
258
- }
259
- function _unsupported_iterable_to_array$1(o, minLen) {
260
- if (!o) return;
261
- if (typeof o === "string") return _array_like_to_array$1(o, minLen);
262
- var n = Object.prototype.toString.call(o).slice(8, -1);
263
- if (n === "Object" && o.constructor) n = o.constructor.name;
264
- if (n === "Map" || n === "Set") return Array.from(n);
265
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
266
- }
267
- function safeToString(info) {
268
- try {
269
- return JSON.stringify(info, null, 2);
270
- } catch (e) {
271
- return "";
272
- }
273
- }
274
- var DEBUG_LOG = "[ FEDERATION DEBUG ]";
275
- var Logger = /*#__PURE__*/ function() {
276
- function Logger(identifier) {
277
- _class_call_check(this, Logger);
278
- _define_property$1(this, "enable", false);
279
- _define_property$1(this, "identifier", void 0);
280
- this.identifier = identifier || DEBUG_LOG;
281
- if (isBrowserEnv() && localStorage.getItem(BROWSER_LOG_KEY) === BROWSER_LOG_VALUE) {
282
- this.enable = true;
283
- } else if (isDebugMode()) {
284
- this.enable = true;
285
- }
286
- }
287
- _create_class(Logger, [
288
- {
289
- key: "info",
290
- value: function info(msg, info) {
291
- if (this.enable) {
292
- var argsToString = safeToString(info) || "";
293
- if (isBrowserEnv()) {
294
- console.info("%c ".concat(this.identifier, ": ").concat(msg, " ").concat(argsToString), "color:#3300CC");
295
- } else {
296
- console.info("\x1b[34m%s", "".concat(this.identifier, ": ").concat(msg, " ").concat(argsToString ? "\n".concat(argsToString) : ""));
297
- }
298
- }
299
- }
300
- },
301
- {
302
- key: "logOriginalInfo",
303
- value: function logOriginalInfo() {
304
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
305
- args[_key] = arguments[_key];
88
+ function _extends$5() {
89
+ _extends$5 = Object.assign || function(target) {
90
+ for(var i = 1; i < arguments.length; i++){
91
+ var source = arguments[i];
92
+ for(var key in source){
93
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
94
+ target[key] = source[key];
306
95
  }
307
- if (this.enable) {
308
- if (isBrowserEnv()) {
309
- var _console;
310
- console.info("%c ".concat(this.identifier, ": OriginalInfo"), "color:#3300CC");
311
- (_console = console).log.apply(_console, _to_consumable_array(args));
312
- } else {
313
- var _console1;
314
- console.info("%c ".concat(this.identifier, ": OriginalInfo"), "color:#3300CC");
315
- (_console1 = console).log.apply(_console1, _to_consumable_array(args));
316
- }
317
- }
318
- }
319
- }
320
- ]);
321
- return Logger;
322
- }();
323
- new Logger();
324
- var composeKeyWithSeparator = function composeKeyWithSeparator() {
325
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
326
- args[_key] = arguments[_key];
327
- }
328
- if (!args.length) {
329
- return "";
330
- }
331
- return args.reduce(function(sum, cur) {
332
- if (!cur) {
333
- return sum;
334
- }
335
- if (!sum) {
336
- return cur;
337
- }
338
- return "".concat(sum).concat(SEPARATOR).concat(cur);
339
- }, "");
340
- };
341
- function _define_property(obj, key, value) {
342
- if (key in obj) {
343
- Object.defineProperty(obj, key, {
344
- value: value,
345
- enumerable: true,
346
- configurable: true,
347
- writable: true
348
- });
349
- } else {
350
- obj[key] = value;
351
- }
352
- return obj;
353
- }
354
- function _object_spread(target) {
355
- for(var i = 1; i < arguments.length; i++){
356
- var source = arguments[i] != null ? arguments[i] : {};
357
- var ownKeys = Object.keys(source);
358
- if (typeof Object.getOwnPropertySymbols === "function") {
359
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
360
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
361
- }));
362
- }
363
- ownKeys.forEach(function(key) {
364
- _define_property(target, key, source[key]);
365
- });
366
- }
367
- return target;
368
- }
369
- function ownKeys(object, enumerableOnly) {
370
- var keys = Object.keys(object);
371
- if (Object.getOwnPropertySymbols) {
372
- var symbols = Object.getOwnPropertySymbols(object);
373
- if (enumerableOnly) {
374
- symbols = symbols.filter(function(sym) {
375
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
376
- });
377
- }
378
- keys.push.apply(keys, symbols);
379
- }
380
- return keys;
381
- }
382
- function _object_spread_props(target, source) {
383
- source = source != null ? source : {};
384
- if (Object.getOwnPropertyDescriptors) {
385
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
386
- } else {
387
- ownKeys(Object(source)).forEach(function(key) {
388
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
389
- });
390
- }
391
- return target;
392
- }
393
- var simpleJoinRemoteEntry = function simpleJoinRemoteEntry(rPath, rName) {
394
- if (!rPath) {
395
- return rName;
396
- }
397
- var transformPath = function transformPath(str) {
398
- if (str === ".") {
399
- return "";
400
- }
401
- if (str.startsWith("./")) {
402
- return str.replace("./", "");
403
- }
404
- if (str.startsWith("/")) {
405
- var strWithoutSlash = str.slice(1);
406
- if (strWithoutSlash.endsWith("/")) {
407
- return strWithoutSlash.slice(0, -1);
408
96
  }
409
- return strWithoutSlash;
410
- }
411
- return str;
412
- };
413
- var transformedPath = transformPath(rPath);
414
- if (!transformedPath) {
415
- return rName;
416
- }
417
- if (transformedPath.endsWith("/")) {
418
- return "".concat(transformedPath).concat(rName);
419
- }
420
- return "".concat(transformedPath, "/").concat(rName);
421
- };
422
- // Priority: overrides > remotes
423
- // eslint-disable-next-line max-lines-per-function
424
- function generateSnapshotFromManifest(manifest) {
425
- var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
426
- var _options_remotes = options.remotes, remotes = _options_remotes === void 0 ? {} : _options_remotes, _options_overrides = options.overrides, overrides = _options_overrides === void 0 ? {} : _options_overrides, version = options.version;
427
- var remoteSnapshot;
428
- var getPublicPath = function getPublicPath() {
429
- if ("publicPath" in manifest.metaData) {
430
- return manifest.metaData.publicPath;
431
- } else {
432
- return manifest.metaData.getPublicPath;
433
97
  }
98
+ return target;
434
99
  };
435
- var overridesKeys = Object.keys(overrides);
436
- var remotesInfo = {};
437
- // If remotes are not provided, only the remotes in the manifest will be read
438
- if (!Object.keys(remotes).length) {
439
- var _manifest_remotes;
440
- remotesInfo = ((_manifest_remotes = manifest.remotes) === null || _manifest_remotes === void 0 ? void 0 : _manifest_remotes.reduce(function(res, next) {
441
- var matchedVersion;
442
- var name = next.federationContainerName;
443
- // overrides have higher priority
444
- if (overridesKeys.includes(name)) {
445
- matchedVersion = overrides[name];
446
- } else {
447
- if ("version" in next) {
448
- matchedVersion = next.version;
449
- } else {
450
- matchedVersion = next.entry;
451
- }
452
- }
453
- res[name] = {
454
- matchedVersion: matchedVersion
455
- };
456
- return res;
457
- }, {})) || {};
458
- }
459
- // If remotes (deploy scenario) are specified, they need to be traversed again
460
- Object.keys(remotes).forEach(function(key) {
461
- return remotesInfo[key] = {
462
- // overrides will override dependencies
463
- matchedVersion: overridesKeys.includes(key) ? overrides[key] : remotes[key]
464
- };
465
- });
466
- var _manifest_metaData = manifest.metaData, _manifest_metaData_remoteEntry = _manifest_metaData.remoteEntry, remoteEntryPath = _manifest_metaData_remoteEntry.path, remoteEntryName = _manifest_metaData_remoteEntry.name, remoteEntryType = _manifest_metaData_remoteEntry.type, remoteTypes = _manifest_metaData.types, buildVersion = _manifest_metaData.buildInfo.buildVersion, globalName = _manifest_metaData.globalName;
467
- var exposes = manifest.exposes;
468
- var basicRemoteSnapshot = {
469
- version: version ? version : "",
470
- buildVersion: buildVersion,
471
- globalName: globalName,
472
- remoteEntry: simpleJoinRemoteEntry(remoteEntryPath, remoteEntryName),
473
- remoteEntryType: remoteEntryType,
474
- remoteTypes: simpleJoinRemoteEntry(remoteTypes.path, remoteTypes.name),
475
- remotesInfo: remotesInfo,
476
- shared: manifest === null || manifest === void 0 ? void 0 : manifest.shared.map(function(item) {
477
- return {
478
- assets: item.assets,
479
- sharedName: item.name
480
- };
481
- }),
482
- modules: exposes === null || exposes === void 0 ? void 0 : exposes.map(function(expose) {
483
- return {
484
- moduleName: expose.name,
485
- modulePath: expose.path,
486
- assets: expose.assets
487
- };
488
- })
489
- };
490
- if ("publicPath" in manifest.metaData) {
491
- remoteSnapshot = _object_spread_props(_object_spread({}, basicRemoteSnapshot), {
492
- publicPath: getPublicPath()
493
- });
494
- } else {
495
- remoteSnapshot = _object_spread_props(_object_spread({}, basicRemoteSnapshot), {
496
- getPublicPath: getPublicPath()
497
- });
498
- }
499
- return remoteSnapshot;
100
+ return _extends$5.apply(this, arguments);
500
101
  }
501
- function isManifestProvider(moduleInfo) {
502
- if ("remoteEntry" in moduleInfo && moduleInfo.remoteEntry.endsWith(MANIFEST_EXT)) {
503
- return true;
504
- } else {
505
- return false;
506
- }
507
- }
508
-
509
102
  async function loadEsmEntry({ entry, remoteEntryExports }) {
510
103
  return new Promise((resolve, reject)=>{
511
104
  try {
@@ -563,7 +156,7 @@ async function getRemoteEntry({ remoteEntryExports, remoteInfo, createScriptHook
563
156
  return globalLoading[uniqueKey];
564
157
  }
565
158
  function getRemoteInfo(remote) {
566
- return _extends({}, remote, {
159
+ return _extends$5({}, remote, {
567
160
  entry: 'entry' in remote ? remote.entry : '',
568
161
  type: remote.type || DEFAULT_REMOTE_TYPE,
569
162
  entryGlobalName: remote.entryGlobalName || remote.name,
@@ -571,6 +164,20 @@ function getRemoteInfo(remote) {
571
164
  });
572
165
  }
573
166
 
167
+ function _extends$4() {
168
+ _extends$4 = Object.assign || function(target) {
169
+ for(var i = 1; i < arguments.length; i++){
170
+ var source = arguments[i];
171
+ for(var key in source){
172
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
173
+ target[key] = source[key];
174
+ }
175
+ }
176
+ }
177
+ return target;
178
+ };
179
+ return _extends$4.apply(this, arguments);
180
+ }
574
181
  let Module = class Module {
575
182
  async getEntry() {
576
183
  if (this.remoteEntryExports) {
@@ -590,7 +197,7 @@ let Module = class Module {
590
197
  return;
591
198
  }
592
199
  });
593
- assert(remoteEntryExports, `remoteEntryExports is undefined \n ${safeToString$1(this.remoteInfo)}`);
200
+ assert(remoteEntryExports, `remoteEntryExports is undefined \n ${safeToString(this.remoteInfo)}`);
594
201
  this.remoteEntryExports = remoteEntryExports;
595
202
  return this.remoteEntryExports;
596
203
  }
@@ -617,7 +224,7 @@ let Module = class Module {
617
224
  remoteEntryExports.init(shareScope, [], remoteEntryInitOptions);
618
225
  const federationInstance = Global.__FEDERATION__.__INSTANCES__.find((i)=>i.options.id === composeKeyWithSeparator(this.remoteInfo.name, this.remoteInfo.buildVersion));
619
226
  if (federationInstance) {
620
- federationInstance.initOptions(_extends({}, remoteEntryInitOptions, {
227
+ federationInstance.initOptions(_extends$4({}, remoteEntryInitOptions, {
621
228
  remotes: [],
622
229
  name: this.remoteInfo.name
623
230
  }));
@@ -833,17 +440,32 @@ class PluginSystem {
833
440
  }
834
441
  }
835
442
 
443
+ function _extends$3() {
444
+ _extends$3 = Object.assign || function(target) {
445
+ for(var i = 1; i < arguments.length; i++){
446
+ var source = arguments[i];
447
+ for(var key in source){
448
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
449
+ target[key] = source[key];
450
+ }
451
+ }
452
+ }
453
+ return target;
454
+ };
455
+ return _extends$3.apply(this, arguments);
456
+ }
836
457
  function defaultPreloadArgs(preloadConfig) {
837
- return _extends({
458
+ return _extends$3({
838
459
  resourceCategory: 'sync',
839
460
  share: true,
840
- depsRemote: true
461
+ depsRemote: true,
462
+ prefetchInterface: false
841
463
  }, preloadConfig);
842
464
  }
843
465
  function formatPreloadArgs(remotes, preloadArgs) {
844
466
  return preloadArgs.map((args)=>{
845
467
  const remoteInfo = matchRemote(remotes, args.nameOrAlias);
846
- assert(remoteInfo, `Unable to preload ${args.nameOrAlias} as it is not included in ${!remoteInfo && safeToString$1({
468
+ assert(remoteInfo, `Unable to preload ${args.nameOrAlias} as it is not included in ${!remoteInfo && safeToString({
847
469
  remoteInfo,
848
470
  remotes
849
471
  })}`);
@@ -929,6 +551,20 @@ function preloadAssets(remoteInfo, host, assets) {
929
551
  }
930
552
  }
931
553
 
554
+ function _extends$2() {
555
+ _extends$2 = Object.assign || function(target) {
556
+ for(var i = 1; i < arguments.length; i++){
557
+ var source = arguments[i];
558
+ for(var key in source){
559
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
560
+ target[key] = source[key];
561
+ }
562
+ }
563
+ }
564
+ return target;
565
+ };
566
+ return _extends$2.apply(this, arguments);
567
+ }
932
568
  function assignRemoteInfo(remoteInfo, remoteSnapshot) {
933
569
  if (!('remoteEntry' in remoteSnapshot) || !remoteSnapshot.remoteEntry) {
934
570
  error(`The attribute remoteEntry of ${name} must not be undefined.`);
@@ -944,7 +580,7 @@ function assignRemoteInfo(remoteInfo, remoteSnapshot) {
944
580
  function snapshotPlugin() {
945
581
  return {
946
582
  name: 'snapshot-plugin',
947
- async loadRemoteMatch (args) {
583
+ async afterResolve (args) {
948
584
  const { remote, pkgNameOrAlias, expose, origin, remoteInfo } = args;
949
585
  if (!isRemoteInfoWithEntry(remote) || !isPureRemoteEntry(remote)) {
950
586
  const { remoteSnapshot, globalSnapshot } = await origin.snapshotHandler.loadRemoteSnapshotInfo(remote);
@@ -973,6 +609,9 @@ function snapshotPlugin() {
973
609
  if (assets) {
974
610
  preloadAssets(remoteInfo, origin, assets);
975
611
  }
612
+ return _extends$2({}, args, {
613
+ remoteSnapshot
614
+ });
976
615
  }
977
616
  return args;
978
617
  }
@@ -1096,6 +735,12 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
1096
735
  for(let index = 0; index < assetsLength; index++){
1097
736
  const assetsInfo = moduleAssetsInfo[index];
1098
737
  const exposeFullPath = `${remoteInfo.name}/${assetsInfo.moduleName}`;
738
+ origin.hooks.lifecycle.handlePreloadModule.emit({
739
+ id: assetsInfo.moduleName === '.' ? remoteInfo.name : exposeFullPath,
740
+ name: remoteInfo.name,
741
+ remoteSnapshot: moduleInfoSnapshot,
742
+ preloadConfig
743
+ });
1099
744
  const preloaded = getPreloaded(exposeFullPath);
1100
745
  if (preloaded) {
1101
746
  continue;
@@ -1182,6 +827,20 @@ const generatePreloadAssetsPlugin = function() {
1182
827
  };
1183
828
  };
1184
829
 
830
+ function _extends$1() {
831
+ _extends$1 = Object.assign || function(target) {
832
+ for(var i = 1; i < arguments.length; i++){
833
+ var source = arguments[i];
834
+ for(var key in source){
835
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
836
+ target[key] = source[key];
837
+ }
838
+ }
839
+ }
840
+ return target;
841
+ };
842
+ return _extends$1.apply(this, arguments);
843
+ }
1185
844
  class SnapshotHandler {
1186
845
  async loadSnapshot(moduleInfo) {
1187
846
  const { options } = this.HostInstance;
@@ -1233,7 +892,7 @@ class SnapshotHandler {
1233
892
  return;
1234
893
  }).value) {
1235
894
  if ('version' in moduleInfo || 'entry' in moduleInfo) {
1236
- hostSnapshot.remotesInfo = _extends({}, hostSnapshot == null ? void 0 : hostSnapshot.remotesInfo, {
895
+ hostSnapshot.remotesInfo = _extends$1({}, hostSnapshot == null ? void 0 : hostSnapshot.remotesInfo, {
1237
896
  [moduleInfo.name]: {
1238
897
  matchedVersion: 'version' in moduleInfo ? moduleInfo.version : moduleInfo.entry
1239
898
  }
@@ -1253,7 +912,7 @@ class SnapshotHandler {
1253
912
  if (isManifestProvider(globalRemoteSnapshot)) {
1254
913
  const moduleSnapshot = await this.getManifestJson(globalRemoteSnapshot.remoteEntry, moduleInfo, {});
1255
914
  // eslint-disable-next-line @typescript-eslint/no-shadow
1256
- const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(_extends({}, moduleInfo), moduleSnapshot);
915
+ const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(_extends$1({}, moduleInfo), moduleSnapshot);
1257
916
  return {
1258
917
  remoteSnapshot: moduleSnapshot,
1259
918
  globalSnapshot: globalSnapshotRes
@@ -1371,7 +1030,10 @@ class SnapshotHandler {
1371
1030
  return manifestJson;
1372
1031
  }
1373
1032
  try {
1374
- const res = await fetch(manifestUrl);
1033
+ let res = await this.loaderHook.lifecycle.fetch.emit(manifestUrl, {});
1034
+ if (!res || !(res instanceof Response)) {
1035
+ res = await fetch(manifestUrl, {});
1036
+ }
1375
1037
  manifestJson = await res.json();
1376
1038
  assert(manifestJson.metaData && manifestJson.exposes && manifestJson.shared, `${manifestUrl} is not a federation manifest`);
1377
1039
  this.manifestCache.set(manifestUrl, manifestJson);
@@ -1412,9 +1074,36 @@ class SnapshotHandler {
1412
1074
  });
1413
1075
  this.manifestLoading = Global.__FEDERATION__.__MANIFEST_LOADING__;
1414
1076
  this.HostInstance = HostInstance;
1077
+ this.loaderHook = HostInstance.loaderHook;
1415
1078
  }
1416
1079
  }
1417
1080
 
1081
+ function _extends() {
1082
+ _extends = Object.assign || function(target) {
1083
+ for(var i = 1; i < arguments.length; i++){
1084
+ var source = arguments[i];
1085
+ for(var key in source){
1086
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
1087
+ target[key] = source[key];
1088
+ }
1089
+ }
1090
+ }
1091
+ return target;
1092
+ };
1093
+ return _extends.apply(this, arguments);
1094
+ }
1095
+ function _object_without_properties_loose(source, excluded) {
1096
+ if (source == null) return {};
1097
+ var target = {};
1098
+ var sourceKeys = Object.keys(source);
1099
+ var key, i;
1100
+ for(i = 0; i < sourceKeys.length; i++){
1101
+ key = sourceKeys[i];
1102
+ if (excluded.indexOf(key) >= 0) continue;
1103
+ target[key] = source[key];
1104
+ }
1105
+ return target;
1106
+ }
1418
1107
  class FederationHost {
1419
1108
  initOptions(userOptions) {
1420
1109
  this.registerPlugins(userOptions.plugins);
@@ -1547,7 +1236,7 @@ class FederationHost {
1547
1236
  `);
1548
1237
  }
1549
1238
  async _getRemoteModuleAndOptions(id) {
1550
- const loadRemoteArgs = await this.hooks.lifecycle.beforeLoadRemote.emit({
1239
+ const loadRemoteArgs = await this.hooks.lifecycle.beforeRequest.emit({
1551
1240
  id,
1552
1241
  options: this.options,
1553
1242
  origin: this
@@ -1556,13 +1245,15 @@ class FederationHost {
1556
1245
  const remoteSplitInfo = matchRemoteWithNameAndExpose(this.options.remotes, idRes);
1557
1246
  assert(remoteSplitInfo, `
1558
1247
  Unable to locate ${idRes} in ${this.options.name}. Potential reasons for failure include:\n
1559
- 1. ${idRes} was not included in the 'remotes' parameter of ${this.options.name}.\n
1248
+ 1. ${idRes} was not included in the 'remotes' parameter of ${this.options.name || 'the host'}.\n
1560
1249
  2. ${idRes} could not be found in the 'remotes' of ${this.options.name} with either 'name' or 'alias' attributes.
1561
- 3. The 'beforeLoadRemote' hook was provided but did not return the correct 'remoteInfo' when attempting to load ${idRes}.
1250
+ 3. ${idRes} is not online, injected, or loaded.
1251
+ 4. ${idRes} cannot be accessed on the expected.
1252
+ 5. The 'beforeRequest' hook was provided but did not return the correct 'remoteInfo' when attempting to load ${idRes}.
1562
1253
  `);
1563
1254
  const { remote: rawRemote } = remoteSplitInfo;
1564
1255
  const remoteInfo = getRemoteInfo(rawRemote);
1565
- const matchInfo = await this.hooks.lifecycle.loadRemoteMatch.emit(_extends({
1256
+ const matchInfo = await this.hooks.lifecycle.afterResolve.emit(_extends({
1566
1257
  id: idRes
1567
1258
  }, remoteSplitInfo, {
1568
1259
  options: this.options,
@@ -1570,7 +1261,7 @@ class FederationHost {
1570
1261
  remoteInfo
1571
1262
  }));
1572
1263
  const { remote, expose } = matchInfo;
1573
- assert(remote && expose, `The 'beforeLoadRemote' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`);
1264
+ assert(remote && expose, `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`);
1574
1265
  let module = this.moduleCache.get(remote.name);
1575
1266
  const moduleOptions = {
1576
1267
  hostInfo: {
@@ -1609,7 +1300,7 @@ class FederationHost {
1609
1300
  const { module, moduleOptions, remoteMatchInfo } = await this._getRemoteModuleAndOptions(id);
1610
1301
  const { pkgNameOrAlias, remote, expose, id: idRes } = remoteMatchInfo;
1611
1302
  const moduleOrFactory = await module.get(expose, options);
1612
- await this.hooks.lifecycle.loadRemote.emit({
1303
+ await this.hooks.lifecycle.onLoad.emit({
1613
1304
  id: idRes,
1614
1305
  pkgNameOrAlias,
1615
1306
  expose,
@@ -1730,7 +1421,7 @@ class FederationHost {
1730
1421
  }
1731
1422
  // Set the remote entry to a complete path
1732
1423
  if ('entry' in remote) {
1733
- if (isBrowserEnv$1()) {
1424
+ if (isBrowserEnv()) {
1734
1425
  remote.entry = new URL(remote.entry, window.location.origin).href;
1735
1426
  }
1736
1427
  }
@@ -1806,7 +1497,7 @@ class FederationHost {
1806
1497
  }
1807
1498
  if (target[sc][pkgName][version]) {
1808
1499
  warn(// eslint-disable-next-line max-len
1809
- `The share \n ${safeToString$1({
1500
+ `The share \n ${safeToString({
1810
1501
  scope: sc,
1811
1502
  pkgName,
1812
1503
  version,
@@ -1833,9 +1524,10 @@ class FederationHost {
1833
1524
  this.hooks = new PluginSystem({
1834
1525
  beforeInit: new SyncWaterfallHook('beforeInit'),
1835
1526
  init: new SyncHook(),
1836
- beforeLoadRemote: new AsyncWaterfallHook('beforeLoadRemote'),
1837
- loadRemoteMatch: new AsyncWaterfallHook('loadRemoteMatch'),
1838
- loadRemote: new AsyncHook('loadRemote'),
1527
+ beforeRequest: new AsyncWaterfallHook('beforeRequest'),
1528
+ afterResolve: new AsyncWaterfallHook('afterResolve'),
1529
+ onLoad: new AsyncHook('onLoad'),
1530
+ handlePreloadModule: new SyncHook('handlePreloadModule'),
1839
1531
  errorLoadRemote: new AsyncHook('errorLoadRemote'),
1840
1532
  beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
1841
1533
  loadShare: new AsyncHook(),
@@ -1843,12 +1535,13 @@ class FederationHost {
1843
1535
  generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
1844
1536
  afterPreloadRemote: new AsyncHook()
1845
1537
  });
1846
- this.version = '1.0.0-canary.4';
1538
+ this.version = '1.0.1-canary.1';
1847
1539
  this.moduleCache = new Map();
1848
1540
  this.loaderHook = new PluginSystem({
1849
1541
  // FIXME: may not be suitable
1850
1542
  getModuleInfo: new SyncHook(),
1851
- createScript: new SyncHook()
1543
+ createScript: new SyncHook(),
1544
+ fetch: new AsyncHook('fetch')
1852
1545
  });
1853
1546
  this.loadingShare = {};
1854
1547
  // TODO: Validate the details of the options
@@ -1862,7 +1555,7 @@ class FederationHost {
1862
1555
  ],
1863
1556
  remotes: [],
1864
1557
  shared: {},
1865
- inBrowser: isBrowserEnv$1()
1558
+ inBrowser: isBrowserEnv()
1866
1559
  };
1867
1560
  this.name = userOptions.name;
1868
1561
  this.options = defaultOptions;
@@ -1914,4 +1607,4 @@ function preloadRemote(...args) {
1914
1607
  // Inject for debug
1915
1608
  setGlobalFederationConstructor(FederationHost);
1916
1609
 
1917
- export { FederationHost, init, loadRemote, loadScript, loadShare, loadShareSync, preloadRemote };
1610
+ export { FederationHost, init, loadRemote, loadShare, loadShareSync, preloadRemote };