@module-federation/bridge-react 0.24.1 → 2.0.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/base.cjs.js +4 -4
  3. package/dist/base.es.js +5 -5
  4. package/dist/{bridge-base-CIgEZf8X.mjs → bridge-base-BVX0EbsV.mjs} +1 -1
  5. package/dist/{bridge-base-1Grpgans.js → bridge-base-vSCG9ebE.js} +1 -1
  6. package/dist/{createHelpers-2UBGLdcA.js → createHelpers-12yCVhCu.js} +2 -2
  7. package/dist/{createHelpers-C9qvVTND.mjs → createHelpers-CGhHhtAd.mjs} +2 -2
  8. package/dist/data-fetch-server-middleware.cjs.js +2 -2
  9. package/dist/data-fetch-server-middleware.es.js +2 -2
  10. package/dist/data-fetch-utils.cjs.js +2 -2
  11. package/dist/data-fetch-utils.es.js +4 -4
  12. package/dist/{index-DRSBaSu3.js → index-DhFNWacm.js} +1 -1
  13. package/dist/{index-DyQNwY2M.mjs → index-DtXhorFI.mjs} +1 -1
  14. package/dist/index.cjs.js +5 -5
  15. package/dist/index.es.js +6 -6
  16. package/dist/{index.esm-CPwSeCvw.mjs → index.esm-BvTtsZnu.mjs} +3 -4
  17. package/dist/{index.esm-BWaKho-8.js → index.esm-CYiGJfQW.js} +0 -1
  18. package/dist/{lazy-load-component-plugin-DKejcTCw.js → lazy-load-component-plugin-C7jasFos.js} +2 -2
  19. package/dist/{lazy-load-component-plugin-Dk-ECNy-.mjs → lazy-load-component-plugin-CrSLH5YP.mjs} +2 -2
  20. package/dist/lazy-load-component-plugin.cjs.js +2 -2
  21. package/dist/lazy-load-component-plugin.es.js +2 -2
  22. package/dist/lazy-utils.cjs.js +2 -2
  23. package/dist/lazy-utils.es.js +2 -2
  24. package/dist/prefetch-CFRpPfZQ.js +632 -0
  25. package/dist/prefetch-DMJyBeIs.mjs +633 -0
  26. package/dist/router-v5.cjs.js +1 -1
  27. package/dist/router-v5.es.js +1 -1
  28. package/dist/router-v6.cjs.js +1 -1
  29. package/dist/router-v6.es.js +1 -1
  30. package/dist/router-v7.cjs.js +1 -1
  31. package/dist/router-v7.es.js +1 -1
  32. package/dist/router.cjs.js +1 -1
  33. package/dist/router.es.js +1 -1
  34. package/dist/{utils--qTri1IN.mjs → utils-DpoLOH_j.mjs} +1 -1
  35. package/dist/{utils-tM9yE73c.js → utils-TDonIHDD.js} +1 -1
  36. package/dist/v18.cjs.js +1 -1
  37. package/dist/v18.es.js +1 -1
  38. package/dist/v19.cjs.js +1 -1
  39. package/dist/v19.es.js +1 -1
  40. package/package.json +5 -5
  41. package/dist/prefetch-BiUqElFJ.mjs +0 -1391
  42. package/dist/prefetch-ebk8gbEI.js +0 -1390
@@ -0,0 +1,632 @@
1
+ "use strict";
2
+ const lazyUtils = require("./utils-TDonIHDD.js");
3
+ const index_esm = require("./index.esm-CYiGJfQW.js");
4
+ const dataFetchFunction = async function(options) {
5
+ var _a, _b;
6
+ const [id, data, downgrade] = options;
7
+ lazyUtils.logger.debug("==========call data fetch function!");
8
+ if (data) {
9
+ if (!id) {
10
+ throw new Error("id is required!");
11
+ }
12
+ if (!lazyUtils.getDataFetchMap()) {
13
+ lazyUtils.initDataFetchMap();
14
+ }
15
+ const dataFetchItem = lazyUtils.getDataFetchItem(id);
16
+ if (dataFetchItem) {
17
+ (_b = (_a = dataFetchItem[1]) == null ? void 0 : _a[1]) == null ? void 0 : _b.call(_a, data);
18
+ dataFetchItem[2] = lazyUtils.MF_DATA_FETCH_STATUS.LOADED;
19
+ return;
20
+ }
21
+ if (!dataFetchItem) {
22
+ const dataFetchMap = lazyUtils.getDataFetchMap();
23
+ let res;
24
+ let rej;
25
+ const p = new Promise((resolve, reject) => {
26
+ res = resolve;
27
+ rej = reject;
28
+ });
29
+ dataFetchMap[id] = [
30
+ [
31
+ async () => async () => {
32
+ return "";
33
+ },
34
+ lazyUtils.MF_DATA_FETCH_TYPE.FETCH_SERVER
35
+ ],
36
+ [p, res, rej],
37
+ lazyUtils.MF_DATA_FETCH_STATUS.LOADED
38
+ ];
39
+ res && res(data);
40
+ return;
41
+ }
42
+ }
43
+ if (downgrade) {
44
+ const mfDowngrade2 = lazyUtils.getDowngradeTag();
45
+ if (!mfDowngrade2) {
46
+ globalThis[lazyUtils.DOWNGRADE_KEY] = id ? [id] : true;
47
+ } else if (Array.isArray(mfDowngrade2) && id && !mfDowngrade2.includes(id)) {
48
+ mfDowngrade2.push(id);
49
+ }
50
+ }
51
+ const mfDowngrade = lazyUtils.getDowngradeTag();
52
+ if (typeof mfDowngrade === "boolean") {
53
+ return lazyUtils.callAllDowngrade();
54
+ }
55
+ if (Array.isArray(mfDowngrade)) {
56
+ if (!id) {
57
+ globalThis[lazyUtils.DOWNGRADE_KEY] = true;
58
+ return lazyUtils.callAllDowngrade();
59
+ }
60
+ if (!mfDowngrade.includes(id)) {
61
+ mfDowngrade.push(id);
62
+ }
63
+ return lazyUtils.callDowngrade(id);
64
+ }
65
+ };
66
+ function injectDataFetch() {
67
+ var _a;
68
+ globalThis[_a = lazyUtils.DATA_FETCH_FUNCTION] || (globalThis[_a] = []);
69
+ const dataFetch = globalThis[lazyUtils.DATA_FETCH_FUNCTION];
70
+ if (dataFetch.push === dataFetchFunction) {
71
+ return;
72
+ }
73
+ if (typeof window === "undefined") {
74
+ return;
75
+ }
76
+ globalThis[lazyUtils.FS_HREF] = window.location.href;
77
+ dataFetch.push = dataFetchFunction;
78
+ }
79
+ const RUNTIME_001 = "RUNTIME-001";
80
+ const RUNTIME_002 = "RUNTIME-002";
81
+ const RUNTIME_003 = "RUNTIME-003";
82
+ const RUNTIME_004 = "RUNTIME-004";
83
+ const RUNTIME_005 = "RUNTIME-005";
84
+ const RUNTIME_006 = "RUNTIME-006";
85
+ const RUNTIME_007 = "RUNTIME-007";
86
+ const RUNTIME_008 = "RUNTIME-008";
87
+ const RUNTIME_009 = "RUNTIME-009";
88
+ const getDocsUrl = (errorCode) => {
89
+ const type = errorCode.split("-")[0].toLowerCase();
90
+ return `View the docs to see how to solve: https://module-federation.io/guide/troubleshooting/${type}#${errorCode.toLowerCase()}`;
91
+ };
92
+ const getShortErrorMsg = (errorCode, errorDescMap, args, originalErrorMsg) => {
93
+ const msg = [`${[errorDescMap[errorCode]]} #${errorCode}`];
94
+ args && msg.push(`args: ${JSON.stringify(args)}`);
95
+ msg.push(getDocsUrl(errorCode));
96
+ return msg.join("\n");
97
+ };
98
+ const runtimeDescMap = {
99
+ [RUNTIME_001]: "Failed to get remoteEntry exports.",
100
+ [RUNTIME_002]: 'The remote entry interface does not contain "init"',
101
+ [RUNTIME_003]: "Failed to get manifest.",
102
+ [RUNTIME_004]: "Failed to locate remote.",
103
+ [RUNTIME_005]: "Invalid loadShareSync function call from bundler runtime",
104
+ [RUNTIME_006]: "Invalid loadShareSync function call from runtime",
105
+ [RUNTIME_007]: "Failed to get remote snapshot.",
106
+ [RUNTIME_008]: "Failed to load script resources.",
107
+ [RUNTIME_009]: "Please call createInstance first."
108
+ };
109
+ ({
110
+ ...runtimeDescMap
111
+ });
112
+ const LOG_CATEGORY = "[ Federation Runtime ]";
113
+ function assert(condition, msg) {
114
+ if (!condition) {
115
+ error(msg);
116
+ }
117
+ }
118
+ function error(msg) {
119
+ if (msg instanceof Error) {
120
+ if (!msg.message.startsWith(LOG_CATEGORY)) {
121
+ msg.message = `${LOG_CATEGORY}: ${msg.message}`;
122
+ }
123
+ throw msg;
124
+ }
125
+ throw new Error(`${LOG_CATEGORY}: ${msg}`);
126
+ }
127
+ const CurrentGlobal = typeof globalThis === "object" ? globalThis : window;
128
+ const nativeGlobal = (() => {
129
+ try {
130
+ return document.defaultView;
131
+ } catch {
132
+ return CurrentGlobal;
133
+ }
134
+ })();
135
+ function definePropertyGlobalVal(target, key, val) {
136
+ Object.defineProperty(target, key, {
137
+ value: val,
138
+ configurable: false,
139
+ writable: true
140
+ });
141
+ }
142
+ function includeOwnProperty(target, key) {
143
+ return Object.hasOwnProperty.call(target, key);
144
+ }
145
+ if (!includeOwnProperty(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__")) {
146
+ definePropertyGlobalVal(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__", {});
147
+ }
148
+ const globalLoading = CurrentGlobal.__GLOBAL_LOADING_REMOTE_ENTRY__;
149
+ function setGlobalDefaultVal(target) {
150
+ var _a, _b, _c, _d, _e, _f;
151
+ if (includeOwnProperty(target, "__VMOK__") && !includeOwnProperty(target, "__FEDERATION__")) {
152
+ definePropertyGlobalVal(target, "__FEDERATION__", target.__VMOK__);
153
+ }
154
+ if (!includeOwnProperty(target, "__FEDERATION__")) {
155
+ definePropertyGlobalVal(target, "__FEDERATION__", {
156
+ __GLOBAL_PLUGIN__: [],
157
+ __INSTANCES__: [],
158
+ moduleInfo: {},
159
+ __SHARE__: {},
160
+ __MANIFEST_LOADING__: {},
161
+ __PRELOADED_MAP__: /* @__PURE__ */ new Map()
162
+ });
163
+ definePropertyGlobalVal(target, "__VMOK__", target.__FEDERATION__);
164
+ }
165
+ (_a = target.__FEDERATION__).__GLOBAL_PLUGIN__ ?? (_a.__GLOBAL_PLUGIN__ = []);
166
+ (_b = target.__FEDERATION__).__INSTANCES__ ?? (_b.__INSTANCES__ = []);
167
+ (_c = target.__FEDERATION__).moduleInfo ?? (_c.moduleInfo = {});
168
+ (_d = target.__FEDERATION__).__SHARE__ ?? (_d.__SHARE__ = {});
169
+ (_e = target.__FEDERATION__).__MANIFEST_LOADING__ ?? (_e.__MANIFEST_LOADING__ = {});
170
+ (_f = target.__FEDERATION__).__PRELOADED_MAP__ ?? (_f.__PRELOADED_MAP__ = /* @__PURE__ */ new Map());
171
+ }
172
+ setGlobalDefaultVal(CurrentGlobal);
173
+ setGlobalDefaultVal(nativeGlobal);
174
+ const getRemoteEntryExports = (name, globalName) => {
175
+ const remoteEntryKey = globalName || `__FEDERATION_${name}:custom__`;
176
+ const entryExports = CurrentGlobal[remoteEntryKey];
177
+ return {
178
+ remoteEntryKey,
179
+ entryExports
180
+ };
181
+ };
182
+ const DEFAULT_SCOPE = "default";
183
+ const DEFAULT_REMOTE_TYPE = "global";
184
+ function matchRemoteWithNameAndExpose(remotes, id) {
185
+ for (const remote of remotes) {
186
+ const isNameMatched = id.startsWith(remote.name);
187
+ let expose = id.replace(remote.name, "");
188
+ if (isNameMatched) {
189
+ if (expose.startsWith("/")) {
190
+ const pkgNameOrAlias = remote.name;
191
+ expose = `.${expose}`;
192
+ return {
193
+ pkgNameOrAlias,
194
+ expose,
195
+ remote
196
+ };
197
+ } else if (expose === "") {
198
+ return {
199
+ pkgNameOrAlias: remote.name,
200
+ expose: ".",
201
+ remote
202
+ };
203
+ }
204
+ }
205
+ const isAliasMatched = remote.alias && id.startsWith(remote.alias);
206
+ let exposeWithAlias = remote.alias && id.replace(remote.alias, "");
207
+ if (remote.alias && isAliasMatched) {
208
+ if (exposeWithAlias && exposeWithAlias.startsWith("/")) {
209
+ const pkgNameOrAlias = remote.alias;
210
+ exposeWithAlias = `.${exposeWithAlias}`;
211
+ return {
212
+ pkgNameOrAlias,
213
+ expose: exposeWithAlias,
214
+ remote
215
+ };
216
+ } else if (exposeWithAlias === "") {
217
+ return {
218
+ pkgNameOrAlias: remote.alias,
219
+ expose: ".",
220
+ remote
221
+ };
222
+ }
223
+ }
224
+ }
225
+ return;
226
+ }
227
+ const importCallback = ".then(callbacks[0]).catch(callbacks[1])";
228
+ async function loadEsmEntry({ entry, remoteEntryExports }) {
229
+ return new Promise((resolve, reject) => {
230
+ try {
231
+ if (!remoteEntryExports) {
232
+ if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== "undefined") {
233
+ new Function("callbacks", `import("${entry}")${importCallback}`)([
234
+ resolve,
235
+ reject
236
+ ]);
237
+ } else {
238
+ import(
239
+ /* webpackIgnore: true */
240
+ /* @vite-ignore */
241
+ entry
242
+ ).then(resolve).catch(reject);
243
+ }
244
+ } else {
245
+ resolve(remoteEntryExports);
246
+ }
247
+ } catch (e) {
248
+ reject(e);
249
+ }
250
+ });
251
+ }
252
+ async function loadSystemJsEntry({ entry, remoteEntryExports }) {
253
+ return new Promise((resolve, reject) => {
254
+ try {
255
+ if (!remoteEntryExports) {
256
+ if (typeof __system_context__ === "undefined") {
257
+ System.import(entry).then(resolve).catch(reject);
258
+ } else {
259
+ new Function("callbacks", `System.import("${entry}")${importCallback}`)([resolve, reject]);
260
+ }
261
+ } else {
262
+ resolve(remoteEntryExports);
263
+ }
264
+ } catch (e) {
265
+ reject(e);
266
+ }
267
+ });
268
+ }
269
+ function handleRemoteEntryLoaded(name, globalName, entry) {
270
+ const { remoteEntryKey, entryExports } = getRemoteEntryExports(name, globalName);
271
+ assert(entryExports, getShortErrorMsg(RUNTIME_001, runtimeDescMap, {
272
+ remoteName: name,
273
+ remoteEntryUrl: entry,
274
+ remoteEntryKey
275
+ }));
276
+ return entryExports;
277
+ }
278
+ async function loadEntryScript({ name, globalName, entry, loaderHook, getEntryUrl }) {
279
+ const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
280
+ if (remoteEntryExports) {
281
+ return remoteEntryExports;
282
+ }
283
+ const url = getEntryUrl ? getEntryUrl(entry) : entry;
284
+ return index_esm.loadScript(url, {
285
+ attrs: {},
286
+ createScriptHook: (url2, attrs) => {
287
+ const res = loaderHook.lifecycle.createScript.emit({ url: url2, attrs });
288
+ if (!res)
289
+ return;
290
+ if (res instanceof HTMLScriptElement) {
291
+ return res;
292
+ }
293
+ if ("script" in res || "timeout" in res) {
294
+ return res;
295
+ }
296
+ return;
297
+ }
298
+ }).then(() => {
299
+ return handleRemoteEntryLoaded(name, globalName, entry);
300
+ }).catch((e) => {
301
+ assert(void 0, getShortErrorMsg(RUNTIME_008, runtimeDescMap, {
302
+ remoteName: name,
303
+ resourceUrl: entry
304
+ }));
305
+ throw e;
306
+ });
307
+ }
308
+ async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEntryUrl }) {
309
+ const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
310
+ switch (type) {
311
+ case "esm":
312
+ case "module":
313
+ return loadEsmEntry({ entry, remoteEntryExports });
314
+ case "system":
315
+ return loadSystemJsEntry({ entry, remoteEntryExports });
316
+ default:
317
+ return loadEntryScript({
318
+ entry,
319
+ globalName,
320
+ name,
321
+ loaderHook,
322
+ getEntryUrl
323
+ });
324
+ }
325
+ }
326
+ async function loadEntryNode({ remoteInfo, loaderHook }) {
327
+ const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
328
+ const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
329
+ if (remoteEntryExports) {
330
+ return remoteEntryExports;
331
+ }
332
+ return index_esm.loadScriptNode(entry, {
333
+ attrs: { name, globalName, type },
334
+ loaderHook: {
335
+ createScriptHook: (url, attrs = {}) => {
336
+ const res = loaderHook.lifecycle.createScript.emit({ url, attrs });
337
+ if (!res)
338
+ return;
339
+ if ("url" in res) {
340
+ return res;
341
+ }
342
+ return;
343
+ }
344
+ }
345
+ }).then(() => {
346
+ return handleRemoteEntryLoaded(name, globalName, entry);
347
+ }).catch((e) => {
348
+ throw e;
349
+ });
350
+ }
351
+ function getRemoteEntryUniqueKey(remoteInfo) {
352
+ const { entry, name } = remoteInfo;
353
+ return index_esm.composeKeyWithSeparator(name, entry);
354
+ }
355
+ async function getRemoteEntry(params) {
356
+ const { origin, remoteEntryExports, remoteInfo, getEntryUrl, _inErrorHandling = false } = params;
357
+ const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
358
+ if (remoteEntryExports) {
359
+ return remoteEntryExports;
360
+ }
361
+ if (!globalLoading[uniqueKey]) {
362
+ const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
363
+ const loaderHook = origin.loaderHook;
364
+ globalLoading[uniqueKey] = loadEntryHook.emit({
365
+ loaderHook,
366
+ remoteInfo,
367
+ remoteEntryExports
368
+ }).then((res) => {
369
+ if (res) {
370
+ return res;
371
+ }
372
+ const isWebEnvironment = typeof ENV_TARGET !== "undefined" ? ENV_TARGET === "web" : index_esm.isBrowserEnv();
373
+ return isWebEnvironment ? loadEntryDom({
374
+ remoteInfo,
375
+ remoteEntryExports,
376
+ loaderHook,
377
+ getEntryUrl
378
+ }) : loadEntryNode({ remoteInfo, loaderHook });
379
+ }).catch(async (err) => {
380
+ const uniqueKey2 = getRemoteEntryUniqueKey(remoteInfo);
381
+ const isScriptLoadError = err instanceof Error && err.message.includes(RUNTIME_008);
382
+ if (isScriptLoadError && !_inErrorHandling) {
383
+ const wrappedGetRemoteEntry = (params2) => {
384
+ return getRemoteEntry({ ...params2, _inErrorHandling: true });
385
+ };
386
+ const RemoteEntryExports = await origin.loaderHook.lifecycle.loadEntryError.emit({
387
+ getRemoteEntry: wrappedGetRemoteEntry,
388
+ origin,
389
+ remoteInfo,
390
+ remoteEntryExports,
391
+ globalLoading,
392
+ uniqueKey: uniqueKey2
393
+ });
394
+ if (RemoteEntryExports) {
395
+ return RemoteEntryExports;
396
+ }
397
+ }
398
+ throw err;
399
+ });
400
+ }
401
+ return globalLoading[uniqueKey];
402
+ }
403
+ function getRemoteInfo(remote) {
404
+ return {
405
+ ...remote,
406
+ entry: "entry" in remote ? remote.entry : "",
407
+ type: remote.type || DEFAULT_REMOTE_TYPE,
408
+ entryGlobalName: remote.entryGlobalName || remote.name,
409
+ shareScope: remote.shareScope || DEFAULT_SCOPE
410
+ };
411
+ }
412
+ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true) {
413
+ const { cssAssets, jsAssetsWithoutEntry, entryAssets } = assets;
414
+ if (host.options.inBrowser) {
415
+ entryAssets.forEach((asset) => {
416
+ const { moduleInfo } = asset;
417
+ const module2 = host.moduleCache.get(remoteInfo.name);
418
+ if (module2) {
419
+ getRemoteEntry({
420
+ origin: host,
421
+ remoteInfo: moduleInfo,
422
+ remoteEntryExports: module2.remoteEntryExports
423
+ });
424
+ } else {
425
+ getRemoteEntry({
426
+ origin: host,
427
+ remoteInfo: moduleInfo,
428
+ remoteEntryExports: void 0
429
+ });
430
+ }
431
+ });
432
+ if (useLinkPreload) {
433
+ const defaultAttrs = {
434
+ rel: "preload",
435
+ as: "style"
436
+ };
437
+ cssAssets.forEach((cssUrl) => {
438
+ const { link: cssEl, needAttach } = index_esm.createLink({
439
+ url: cssUrl,
440
+ cb: () => {
441
+ },
442
+ attrs: defaultAttrs,
443
+ createLinkHook: (url, attrs) => {
444
+ const res = host.loaderHook.lifecycle.createLink.emit({
445
+ url,
446
+ attrs
447
+ });
448
+ if (res instanceof HTMLLinkElement) {
449
+ return res;
450
+ }
451
+ return;
452
+ }
453
+ });
454
+ needAttach && document.head.appendChild(cssEl);
455
+ });
456
+ } else {
457
+ const defaultAttrs = {
458
+ rel: "stylesheet",
459
+ type: "text/css"
460
+ };
461
+ cssAssets.forEach((cssUrl) => {
462
+ const { link: cssEl, needAttach } = index_esm.createLink({
463
+ url: cssUrl,
464
+ cb: () => {
465
+ },
466
+ attrs: defaultAttrs,
467
+ createLinkHook: (url, attrs) => {
468
+ const res = host.loaderHook.lifecycle.createLink.emit({
469
+ url,
470
+ attrs
471
+ });
472
+ if (res instanceof HTMLLinkElement) {
473
+ return res;
474
+ }
475
+ return;
476
+ },
477
+ needDeleteLink: false
478
+ });
479
+ needAttach && document.head.appendChild(cssEl);
480
+ });
481
+ }
482
+ if (useLinkPreload) {
483
+ const defaultAttrs = {
484
+ rel: "preload",
485
+ as: "script"
486
+ };
487
+ jsAssetsWithoutEntry.forEach((jsUrl) => {
488
+ const { link: linkEl, needAttach } = index_esm.createLink({
489
+ url: jsUrl,
490
+ cb: () => {
491
+ },
492
+ attrs: defaultAttrs,
493
+ createLinkHook: (url, attrs) => {
494
+ const res = host.loaderHook.lifecycle.createLink.emit({
495
+ url,
496
+ attrs
497
+ });
498
+ if (res instanceof HTMLLinkElement) {
499
+ return res;
500
+ }
501
+ return;
502
+ }
503
+ });
504
+ needAttach && document.head.appendChild(linkEl);
505
+ });
506
+ } else {
507
+ const defaultAttrs = {
508
+ fetchpriority: "high",
509
+ type: (remoteInfo == null ? void 0 : remoteInfo.type) === "module" ? "module" : "text/javascript"
510
+ };
511
+ jsAssetsWithoutEntry.forEach((jsUrl) => {
512
+ const { script: scriptEl, needAttach } = index_esm.createScript({
513
+ url: jsUrl,
514
+ cb: () => {
515
+ },
516
+ attrs: defaultAttrs,
517
+ createScriptHook: (url, attrs) => {
518
+ const res = host.loaderHook.lifecycle.createScript.emit({
519
+ url,
520
+ attrs
521
+ });
522
+ if (res instanceof HTMLScriptElement) {
523
+ return res;
524
+ }
525
+ return;
526
+ },
527
+ needDeleteScript: true
528
+ });
529
+ needAttach && document.head.appendChild(scriptEl);
530
+ });
531
+ }
532
+ }
533
+ }
534
+ var helpers = {
535
+ utils: {
536
+ matchRemoteWithNameAndExpose,
537
+ preloadAssets,
538
+ getRemoteInfo
539
+ }
540
+ };
541
+ typeof FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN === "boolean" ? !FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN : true;
542
+ const utils = helpers.utils;
543
+ const runtimeHelpers = {
544
+ utils
545
+ };
546
+ async function prefetch(options) {
547
+ const { instance, id, dataFetchParams, preloadComponentResource } = options;
548
+ if (!id) {
549
+ lazyUtils.logger.error("id is required for prefetch!");
550
+ return;
551
+ }
552
+ if (!instance) {
553
+ lazyUtils.logger.error("instance is required for prefetch!");
554
+ return;
555
+ }
556
+ const matchedRemoteInfo = runtimeHelpers.utils.matchRemoteWithNameAndExpose(
557
+ instance.options.remotes,
558
+ id
559
+ );
560
+ if (!matchedRemoteInfo) {
561
+ lazyUtils.logger.error(`Can not found '${id}' in instance.options.remotes!`);
562
+ return;
563
+ }
564
+ const { remote, expose } = matchedRemoteInfo;
565
+ const { remoteSnapshot, globalSnapshot } = await instance.snapshotHandler.loadRemoteSnapshotInfo({
566
+ moduleInfo: remote,
567
+ id,
568
+ expose
569
+ });
570
+ if (preloadComponentResource) {
571
+ const remoteInfo = runtimeHelpers.utils.getRemoteInfo(remote);
572
+ Promise.resolve(
573
+ instance.remoteHandler.hooks.lifecycle.generatePreloadAssets.emit({
574
+ origin: instance,
575
+ preloadOptions: {
576
+ remote,
577
+ preloadConfig: {
578
+ nameOrAlias: remote.name,
579
+ exposes: [expose]
580
+ }
581
+ },
582
+ remote,
583
+ remoteInfo,
584
+ globalSnapshot,
585
+ remoteSnapshot
586
+ })
587
+ ).then((assets) => {
588
+ if (assets) {
589
+ runtimeHelpers.utils.preloadAssets(remoteInfo, instance, assets);
590
+ }
591
+ });
592
+ }
593
+ const dataFetchMap = lazyUtils.getDataFetchMap();
594
+ if (!dataFetchMap) {
595
+ return;
596
+ }
597
+ const dataFetchInfo = lazyUtils.getDataFetchInfo({
598
+ name: remote.name,
599
+ alias: remote.alias,
600
+ id,
601
+ remoteSnapshot
602
+ });
603
+ const dataFetchMapKey = lazyUtils.getDataFetchMapKey(dataFetchInfo, {
604
+ name: instance.name,
605
+ version: instance.options.version
606
+ });
607
+ if (!dataFetchMapKey) {
608
+ return;
609
+ }
610
+ const dataFetchItem = dataFetchMap[dataFetchMapKey];
611
+ if (!dataFetchItem) {
612
+ return;
613
+ }
614
+ const [getDataFetchGetter, _type, getDataFetchPromise] = dataFetchItem[0];
615
+ let _getDataFetchPromise = getDataFetchPromise;
616
+ if (!getDataFetchPromise) {
617
+ if (!getDataFetchGetter) {
618
+ return;
619
+ }
620
+ _getDataFetchPromise = getDataFetchGetter();
621
+ }
622
+ _getDataFetchPromise.then((dataFetchFn) => {
623
+ return dataFetchFn({
624
+ ...dataFetchParams,
625
+ _id: dataFetchMapKey,
626
+ isDowngrade: false
627
+ });
628
+ });
629
+ }
630
+ exports.dataFetchFunction = dataFetchFunction;
631
+ exports.injectDataFetch = injectDataFetch;
632
+ exports.prefetch = prefetch;