@module-federation/data-prefetch 0.0.0-next-20240927195332 → 0.0.0-next-20240930091801

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 (77) hide show
  1. package/CHANGELOG.md +4 -3
  2. package/LICENSE +1 -1
  3. package/dist/{src/cli → cli}/babel.d.ts +4 -2
  4. package/dist/cli/babel.js +84 -0
  5. package/dist/{src/cli → cli}/index.d.ts +8 -5
  6. package/dist/cli/index.js +207 -0
  7. package/dist/esm/chunk-AJPO2B2T.js +30 -0
  8. package/dist/esm/chunk-BGNOVRH5.js +166 -0
  9. package/dist/esm/chunk-EZUCZHGV.js +11 -0
  10. package/dist/esm/chunk-ISF7VMBW.js +156 -0
  11. package/dist/esm/chunk-OCDMSRMZ.js +32 -0
  12. package/dist/esm/chunk-TTJJJ2WZ.js +7 -0
  13. package/dist/esm/cli/babel.js +57 -0
  14. package/dist/esm/cli/index.js +180 -0
  15. package/dist/esm/index.js +13 -0
  16. package/dist/esm/plugin.js +12 -0
  17. package/dist/esm/react/index.js +94 -0
  18. package/dist/esm/shared/index.js +27 -0
  19. package/dist/esm/universal/index.js +9 -0
  20. package/dist/index.d.ts +5 -0
  21. package/dist/index.js +351 -0
  22. package/dist/plugin.d.ts +5 -0
  23. package/dist/plugin.js +347 -0
  24. package/dist/{src/prefetch.d.ts → prefetch-c08be471.d.ts} +6 -4
  25. package/dist/react/index.d.ts +16 -0
  26. package/dist/react/index.js +287 -0
  27. package/dist/shared/index.d.ts +5 -0
  28. package/dist/shared/index.js +48 -0
  29. package/dist/universal/index.d.ts +8 -0
  30. package/dist/universal/index.js +205 -0
  31. package/package.json +28 -31
  32. package/project.json +4 -46
  33. package/src/cli/index.ts +2 -2
  34. package/tsconfig.json +1 -1
  35. package/dist/LICENSE +0 -21
  36. package/dist/babel.cjs.d.ts +0 -2
  37. package/dist/babel.cjs.js +0 -62
  38. package/dist/babel.esm.js +0 -56
  39. package/dist/cli.cjs.d.ts +0 -1
  40. package/dist/cli.cjs.js +0 -3579
  41. package/dist/cli.esm.js +0 -3565
  42. package/dist/index.cjs.d.ts +0 -1
  43. package/dist/index.cjs.js +0 -15
  44. package/dist/index.cjs2.js +0 -7
  45. package/dist/index.esm.js +0 -6
  46. package/dist/index.esm2.js +0 -5
  47. package/dist/package.json +0 -99
  48. package/dist/plugin.cjs.d.ts +0 -2
  49. package/dist/plugin.cjs.js +0 -362
  50. package/dist/plugin.esm.js +0 -357
  51. package/dist/prefetch.cjs.js +0 -351
  52. package/dist/prefetch.esm.js +0 -349
  53. package/dist/react.cjs.d.ts +0 -1
  54. package/dist/react.cjs.js +0 -163
  55. package/dist/react.esm.js +0 -159
  56. package/dist/runtime-utils.cjs.js +0 -31
  57. package/dist/runtime-utils.esm.js +0 -26
  58. package/dist/shared.cjs.d.ts +0 -2
  59. package/dist/shared.cjs.js +0 -26
  60. package/dist/shared.esm.js +0 -24
  61. package/dist/src/common/constant.d.ts +0 -1
  62. package/dist/src/common/index.d.ts +0 -1
  63. package/dist/src/common/node-utils.d.ts +0 -2
  64. package/dist/src/common/runtime-utils.d.ts +0 -5
  65. package/dist/src/index.d.ts +0 -2
  66. package/dist/src/logger/index.d.ts +0 -3
  67. package/dist/src/plugin.d.ts +0 -3
  68. package/dist/src/react/hooks.d.ts +0 -11
  69. package/dist/src/react/index.d.ts +0 -1
  70. package/dist/src/react/utils.d.ts +0 -1
  71. package/dist/src/shared/index.d.ts +0 -3
  72. package/dist/src/universal/index.d.ts +0 -2
  73. package/dist/universal.cjs.d.ts +0 -1
  74. package/dist/universal.cjs.js +0 -38
  75. package/dist/universal.esm.js +0 -34
  76. package/rollup.config.js +0 -25
  77. package/tsconfig.lib.json +0 -10
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @module-federation/data-prefetch
2
2
 
3
- ## 0.0.0-next-20240927195332
3
+ ## 0.0.0-next-20240930091801
4
4
 
5
5
  ### Patch Changes
6
6
 
@@ -14,8 +14,9 @@
14
14
  - Updated dependencies [9e32644]
15
15
  - Updated dependencies [9e32644]
16
16
  - Updated dependencies [9e32644]
17
- - @module-federation/runtime@0.0.0-next-20240927195332
18
- - @module-federation/sdk@0.0.0-next-20240927195332
17
+ - Updated dependencies [3082116]
18
+ - @module-federation/runtime@0.0.0-next-20240930091801
19
+ - @module-federation/sdk@0.0.0-next-20240930091801
19
20
 
20
21
  ## 0.6.6
21
22
 
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024-present nieyan(nyqykk)
3
+ Copyright (c) 2020 ScriptedAlchemy LLC (Zack Jackson) Zhou Shaw (zhouxiao)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,5 @@
1
- import type { moduleFederationPlugin } from '@module-federation/sdk';
1
+ import { moduleFederationPlugin } from '@module-federation/sdk';
2
+
2
3
  interface BabelPluginOptions {
3
4
  hook_id: string;
4
5
  import_pkg: string;
@@ -34,4 +35,5 @@ declare const _default: (babel: {
34
35
  }): void;
35
36
  };
36
37
  };
37
- export default _default;
38
+
39
+ export { _default as default };
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+
26
+ // src/cli/babel.ts
27
+ var babel_exports = {};
28
+ __export(babel_exports, {
29
+ default: () => babel_default
30
+ });
31
+ module.exports = __toCommonJS(babel_exports);
32
+ var import_path = __toESM(require("path"));
33
+ var attribute = "id";
34
+ var hookId = "usePrefetch";
35
+ var importPackage = "@module-federation/data-prefetch/react";
36
+ var babel_default = (babel, options) => {
37
+ const t = babel.types;
38
+ let shouldHandle = false;
39
+ let scope = "";
40
+ const { name, exposes } = options;
41
+ if (!exposes) {
42
+ return {};
43
+ }
44
+ const exposesKey = Object.keys(exposes);
45
+ const processedExposes = exposesKey.map((expose) => ({
46
+ key: expose.replace(".", ""),
47
+ value: import_path.default.resolve(
48
+ typeof exposes[expose] === "string" ? exposes[expose] : exposes[expose].import
49
+ )
50
+ }));
51
+ return {
52
+ visitor: {
53
+ ImportDeclaration(nodePath, state) {
54
+ const source = nodePath.node.source.value;
55
+ const { specifiers } = nodePath.node;
56
+ const { filename } = state.file.opts;
57
+ if (source === importPackage) {
58
+ shouldHandle = specifiers.some(
59
+ (specifier) => specifier.imported && specifier.imported.name === hookId && processedExposes.find(
60
+ (expose) => expose.value === filename && (scope = expose.key)
61
+ )
62
+ );
63
+ }
64
+ },
65
+ CallExpression(nodePath) {
66
+ if (shouldHandle && t.isIdentifier(nodePath.node.callee, { name: hookId }) && nodePath.node.arguments.length > 0) {
67
+ const objectExpression = nodePath.node.arguments[0];
68
+ if (objectExpression && t.isObjectExpression(objectExpression) && !objectExpression.properties.find(
69
+ (p) => p.key.name === attribute
70
+ )) {
71
+ objectExpression.properties.push(
72
+ t.objectProperty(
73
+ t.identifier(attribute),
74
+ t.stringLiteral(name + scope)
75
+ )
76
+ );
77
+ }
78
+ }
79
+ }
80
+ }
81
+ };
82
+ };
83
+ // Annotate the CommonJS export names for ESM import in node:
84
+ 0 && (module.exports = {});
@@ -1,8 +1,10 @@
1
+ import * as webpack from 'webpack';
2
+ import { WebpackPluginInstance, Compiler } from 'webpack';
1
3
  import { moduleFederationPlugin } from '@module-federation/sdk';
2
- import type { Compiler, WebpackPluginInstance } from 'webpack';
3
- declare const RuntimeGlobals: typeof import("webpack").RuntimeGlobals;
4
- export declare function getFederationGlobalScope(runtimeGlobals: typeof RuntimeGlobals): string;
5
- export declare class PrefetchPlugin implements WebpackPluginInstance {
4
+
5
+ declare const RuntimeGlobals: typeof webpack.RuntimeGlobals;
6
+ declare function getFederationGlobalScope(runtimeGlobals: typeof RuntimeGlobals): string;
7
+ declare class PrefetchPlugin implements WebpackPluginInstance {
6
8
  options: moduleFederationPlugin.ModuleFederationPluginOptions;
7
9
  private _reWriteExports;
8
10
  constructor(options: moduleFederationPlugin.ModuleFederationPluginOptions);
@@ -13,4 +15,5 @@ export declare class PrefetchPlugin implements WebpackPluginInstance {
13
15
  static setRemoteIdentifier(): string;
14
16
  static removeRemoteIdentifier(): string;
15
17
  }
16
- export {};
18
+
19
+ export { PrefetchPlugin, getFederationGlobalScope };
@@ -0,0 +1,207 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+
26
+ // src/cli/index.ts
27
+ var cli_exports = {};
28
+ __export(cli_exports, {
29
+ PrefetchPlugin: () => PrefetchPlugin,
30
+ getFederationGlobalScope: () => getFederationGlobalScope
31
+ });
32
+ module.exports = __toCommonJS(cli_exports);
33
+ var import_path2 = __toESM(require("path"));
34
+ var import_fs_extra2 = __toESM(require("fs-extra"));
35
+ var import_sdk2 = require("@module-federation/sdk");
36
+ var import_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
37
+
38
+ // src/common/constant.ts
39
+ var TEMP_DIR = ".mf";
40
+
41
+ // src/common/node-utils.ts
42
+ var import_path = __toESM(require("path"));
43
+ var import_fs_extra = __toESM(require("fs-extra"));
44
+ var fileExistsWithCaseSync = (filepath) => {
45
+ const dir = import_path.default.dirname(filepath);
46
+ if (filepath === "/" || filepath === ".") {
47
+ return true;
48
+ }
49
+ const filenames = import_fs_extra.default.readdirSync(dir);
50
+ if (filenames.indexOf(import_path.default.basename(filepath)) === -1) {
51
+ return false;
52
+ }
53
+ return fileExistsWithCaseSync(dir);
54
+ };
55
+ var fixPrefetchPath = (exposePath) => {
56
+ const pathExt = [".js", ".ts"];
57
+ const extReg = /\.(ts|js|tsx|jsx)$/;
58
+ if (extReg.test(exposePath)) {
59
+ return pathExt.map((ext) => exposePath.replace(extReg, `.prefetch${ext}`));
60
+ } else {
61
+ return pathExt.map((ext) => exposePath + `.prefetch${ext}`);
62
+ }
63
+ };
64
+
65
+ // src/common/runtime-utils.ts
66
+ var import_runtime = require("@module-federation/runtime");
67
+ var import_sdk = require("@module-federation/sdk");
68
+ var getPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/${import_sdk.MFPrefetchCommon.identifier}`);
69
+
70
+ // src/cli/index.ts
71
+ var { RuntimeGlobals, Template } = require((0, import_normalize_webpack_path.normalizeWebpackPath)("webpack"));
72
+ function getFederationGlobalScope(runtimeGlobals) {
73
+ return `${runtimeGlobals.require || "__webpack_require__"}.federation`;
74
+ }
75
+ var PrefetchPlugin = class {
76
+ constructor(options) {
77
+ this.options = options;
78
+ this._reWriteExports = "";
79
+ }
80
+ apply(compiler) {
81
+ var _a, _b;
82
+ const { name, exposes } = this.options;
83
+ if (!exposes) {
84
+ return;
85
+ }
86
+ if (!compiler.options.context) {
87
+ throw new Error("compiler.options.context is not defined");
88
+ }
89
+ const { runtimePlugins } = this.options;
90
+ if (!Array.isArray(runtimePlugins)) {
91
+ this.options.runtimePlugins = [];
92
+ }
93
+ const runtimePath = import_path2.default.resolve(__dirname, "../esm/plugin.js");
94
+ const sharedPath = import_path2.default.resolve(__dirname, "../esm/shared/index.js");
95
+ if (!((_a = this.options.runtimePlugins) == null ? void 0 : _a.includes(runtimePath))) {
96
+ this.options.runtimePlugins.push(runtimePath);
97
+ }
98
+ if (!((_b = this.options.runtimePlugins) == null ? void 0 : _b.includes(sharedPath))) {
99
+ this.options.runtimePlugins.push(sharedPath);
100
+ }
101
+ const encodedName = (0, import_sdk2.encodeName)(name);
102
+ const asyncEntryPath = import_path2.default.resolve(
103
+ compiler.options.context,
104
+ `node_modules/${TEMP_DIR}/${encodedName}/bootstrap.js`
105
+ );
106
+ if (import_fs_extra2.default.existsSync(asyncEntryPath)) {
107
+ import_fs_extra2.default.unlinkSync(asyncEntryPath);
108
+ }
109
+ if (!this.options.dataPrefetch) {
110
+ return;
111
+ }
112
+ const prefetchs = [];
113
+ const exposeAlias = Object.keys(exposes);
114
+ exposeAlias.forEach((alias) => {
115
+ let exposePath;
116
+ const exposeValue = exposes[alias];
117
+ if (typeof exposeValue === "string") {
118
+ exposePath = exposeValue;
119
+ } else {
120
+ exposePath = exposeValue.import[0];
121
+ }
122
+ const targetPaths = fixPrefetchPath(exposePath);
123
+ for (const pathItem of targetPaths) {
124
+ const absolutePath = import_path2.default.resolve(compiler.options.context, pathItem);
125
+ if (fileExistsWithCaseSync(absolutePath)) {
126
+ prefetchs.push(pathItem);
127
+ const absoluteAlias = alias.replace(".", "");
128
+ this._reWriteExports += `export * as ${getPrefetchId(
129
+ `${name}${absoluteAlias}`
130
+ )} from '${absolutePath}';
131
+ `;
132
+ break;
133
+ }
134
+ }
135
+ });
136
+ if (!this._reWriteExports) {
137
+ return;
138
+ }
139
+ const tempDirRealPath = import_path2.default.resolve(
140
+ compiler.options.context,
141
+ "node_modules",
142
+ TEMP_DIR
143
+ );
144
+ if (!import_fs_extra2.default.existsSync(tempDirRealPath)) {
145
+ import_fs_extra2.default.mkdirSync(tempDirRealPath);
146
+ }
147
+ if (!import_fs_extra2.default.existsSync(`${tempDirRealPath}/${encodedName}`)) {
148
+ import_fs_extra2.default.mkdirSync(`${tempDirRealPath}/${encodedName}`);
149
+ }
150
+ import_fs_extra2.default.writeFileSync(asyncEntryPath, this._reWriteExports);
151
+ new compiler.webpack.DefinePlugin({
152
+ FederationDataPrefetch: JSON.stringify(asyncEntryPath)
153
+ }).apply(compiler);
154
+ }
155
+ static addRuntime(compiler, options) {
156
+ const encodedName = (0, import_sdk2.encodeName)(options.name);
157
+ if (!compiler.options.context) {
158
+ throw new Error("compiler.options.context is not defined");
159
+ }
160
+ const prefetchEntry = import_path2.default.resolve(
161
+ compiler.options.context,
162
+ `node_modules/.mf/${encodedName}/bootstrap.js`
163
+ );
164
+ const federationGlobal = getFederationGlobalScope(
165
+ RuntimeGlobals || {}
166
+ );
167
+ return Template.asString([
168
+ import_fs_extra2.default.existsSync(prefetchEntry) ? Template.indent([
169
+ "function injectPrefetch() {",
170
+ Template.indent([
171
+ `globalThis.__FEDERATION__ = globalThis.__FEDERATION__ || {};`,
172
+ `globalThis.__FEDERATION__['${import_sdk2.MFPrefetchCommon.globalKey}'] = globalThis.__FEDERATION__['${import_sdk2.MFPrefetchCommon.globalKey}'] || {`,
173
+ `entryLoading: {},`,
174
+ `instance: new Map(),`,
175
+ `__PREFETCH_EXPORTS__: {},`,
176
+ `};`,
177
+ `globalThis.__FEDERATION__['${import_sdk2.MFPrefetchCommon.globalKey}']['${import_sdk2.MFPrefetchCommon.exportsKey}'] = globalThis.__FEDERATION__['${import_sdk2.MFPrefetchCommon.globalKey}']['${import_sdk2.MFPrefetchCommon.exportsKey}'] || {};`,
178
+ `globalThis.__FEDERATION__['${import_sdk2.MFPrefetchCommon.globalKey}']['${import_sdk2.MFPrefetchCommon.exportsKey}']['${options.name}'] = function(){ return import('${prefetchEntry}');}`
179
+ ]),
180
+ "}",
181
+ `${federationGlobal}.prefetch = injectPrefetch`
182
+ ]) : "",
183
+ Template.indent([
184
+ `if(!${federationGlobal}.isMFRemote && ${federationGlobal}.prefetch){`,
185
+ `${federationGlobal}.prefetch()`,
186
+ "}"
187
+ ])
188
+ ]);
189
+ }
190
+ static setRemoteIdentifier() {
191
+ const federationGlobal = getFederationGlobalScope(
192
+ RuntimeGlobals || {}
193
+ );
194
+ return Template.indent([`${federationGlobal}.isMFRemote = true;`]);
195
+ }
196
+ static removeRemoteIdentifier() {
197
+ const federationGlobal = getFederationGlobalScope(
198
+ RuntimeGlobals || {}
199
+ );
200
+ return Template.indent([`${federationGlobal}.isMFRemote = false;`]);
201
+ }
202
+ };
203
+ // Annotate the CommonJS export names for ESM import in node:
204
+ 0 && (module.exports = {
205
+ PrefetchPlugin,
206
+ getFederationGlobalScope
207
+ });
@@ -0,0 +1,30 @@
1
+ // src/common/runtime-utils.ts
2
+ import { getInstance } from "@module-federation/runtime";
3
+ import {
4
+ encodeName,
5
+ MFPrefetchCommon
6
+ } from "@module-federation/sdk";
7
+ var getScope = () => {
8
+ return getInstance().options.name;
9
+ };
10
+ var getPrefetchId = (id) => encodeName(`${id}/${MFPrefetchCommon.identifier}`);
11
+ var compatGetPrefetchId = (id) => encodeName(`${id}/VmokPrefetch`);
12
+ var getSignalFromManifest = (remoteSnapshot) => {
13
+ if (!remoteSnapshot) {
14
+ return false;
15
+ }
16
+ if (!("prefetchEntry" in remoteSnapshot) && !("prefetchInterface" in remoteSnapshot)) {
17
+ return false;
18
+ }
19
+ if (!remoteSnapshot.prefetchEntry && !remoteSnapshot.prefetchInterface) {
20
+ return false;
21
+ }
22
+ return true;
23
+ };
24
+
25
+ export {
26
+ getScope,
27
+ getPrefetchId,
28
+ compatGetPrefetchId,
29
+ getSignalFromManifest
30
+ };
@@ -0,0 +1,166 @@
1
+ import {
2
+ logger_default
3
+ } from "./chunk-TTJJJ2WZ.js";
4
+ import {
5
+ MFDataPrefetch
6
+ } from "./chunk-ISF7VMBW.js";
7
+ import {
8
+ getSignalFromManifest
9
+ } from "./chunk-AJPO2B2T.js";
10
+
11
+ // src/plugin.ts
12
+ import { getResourceUrl } from "@module-federation/sdk";
13
+ var loadingArray = [];
14
+ var strategy = "loaded-first";
15
+ var sharedFlag = strategy;
16
+ var prefetchPlugin = () => ({
17
+ name: "data-prefetch-runtime-plugin",
18
+ initContainer(options) {
19
+ const { remoteSnapshot, remoteInfo, id, origin } = options;
20
+ const snapshot = remoteSnapshot;
21
+ const { name } = remoteInfo;
22
+ const prefetchOptions = {
23
+ name,
24
+ remote: remoteInfo,
25
+ origin,
26
+ remoteSnapshot: snapshot
27
+ };
28
+ const signal = getSignalFromManifest(snapshot);
29
+ if (!signal) {
30
+ return options;
31
+ }
32
+ if (sharedFlag !== strategy) {
33
+ throw new Error(
34
+ `[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`
35
+ );
36
+ }
37
+ const instance = MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions);
38
+ let prefetchUrl;
39
+ if (snapshot.prefetchEntry) {
40
+ prefetchUrl = getResourceUrl(snapshot, snapshot.prefetchEntry);
41
+ }
42
+ const exist = loadingArray.find((loading) => loading.id === id);
43
+ if (exist) {
44
+ return options;
45
+ }
46
+ const promise = instance.loadEntry(prefetchUrl).then(async () => {
47
+ const projectExports = instance.getProjectExports();
48
+ if (projectExports instanceof Promise) {
49
+ await projectExports;
50
+ }
51
+ return Promise.resolve().then(() => {
52
+ const exports = instance.getExposeExports(id);
53
+ logger_default.info(
54
+ `1. Start Prefetch initContainer: ${id} - ${performance.now()}`
55
+ );
56
+ const result = Object.keys(exports).map((k) => {
57
+ const value = instance.prefetch({
58
+ id,
59
+ functionId: k
60
+ });
61
+ const functionId = k;
62
+ return {
63
+ value,
64
+ functionId
65
+ };
66
+ });
67
+ return result;
68
+ });
69
+ });
70
+ loadingArray.push({
71
+ id,
72
+ promise
73
+ });
74
+ return options;
75
+ },
76
+ afterResolve(options) {
77
+ const { remoteSnapshot, remoteInfo, id, origin } = options;
78
+ const snapshot = remoteSnapshot;
79
+ const { name } = remoteInfo;
80
+ const prefetchOptions = {
81
+ name,
82
+ remote: remoteInfo,
83
+ origin,
84
+ remoteSnapshot: snapshot
85
+ };
86
+ const signal = getSignalFromManifest(snapshot);
87
+ if (!signal) {
88
+ return options;
89
+ }
90
+ const inited = loadingArray.some((info) => info.id === id);
91
+ if (!inited) {
92
+ return options;
93
+ }
94
+ if (sharedFlag !== strategy) {
95
+ throw new Error(
96
+ `[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`
97
+ );
98
+ }
99
+ const instance = MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions);
100
+ let prefetchUrl;
101
+ if (snapshot.prefetchEntry) {
102
+ prefetchUrl = getResourceUrl(snapshot, snapshot.prefetchEntry);
103
+ }
104
+ const index = loadingArray.findIndex((loading) => loading.id === id);
105
+ if (index !== -1) {
106
+ loadingArray.splice(index, 1);
107
+ }
108
+ const promise = instance.loadEntry(prefetchUrl).then(async () => {
109
+ const projectExports = instance.getProjectExports();
110
+ if (projectExports instanceof Promise) {
111
+ await projectExports;
112
+ }
113
+ return Promise.resolve().then(() => {
114
+ const exports = instance.getExposeExports(id);
115
+ logger_default.info(
116
+ `1. Start Prefetch afterResolve: ${id} - ${performance.now()}`
117
+ );
118
+ const result = Object.keys(exports).map((k) => {
119
+ const value = instance.prefetch({
120
+ id,
121
+ functionId: k
122
+ });
123
+ const functionId = k;
124
+ return {
125
+ value,
126
+ functionId
127
+ };
128
+ });
129
+ return result;
130
+ });
131
+ });
132
+ loadingArray.push({
133
+ id,
134
+ promise
135
+ });
136
+ return options;
137
+ },
138
+ async onLoad(options) {
139
+ var _a;
140
+ const { remote, id } = options;
141
+ const { name } = remote;
142
+ const promise = (_a = loadingArray.find((loading) => loading.id === id)) == null ? void 0 : _a.promise;
143
+ if (promise) {
144
+ const prefetch = await promise;
145
+ const prefetchValue = prefetch.map((result) => result.value);
146
+ await Promise.all(prefetchValue);
147
+ const instance = MFDataPrefetch.getInstance(name);
148
+ prefetch.forEach((result) => {
149
+ const { value, functionId } = result;
150
+ instance.memorize(id + functionId, value);
151
+ });
152
+ }
153
+ return options;
154
+ },
155
+ beforeLoadShare(options) {
156
+ const shareInfo = options.shareInfo;
157
+ sharedFlag = (shareInfo == null ? void 0 : shareInfo.strategy) || sharedFlag;
158
+ return options;
159
+ }
160
+ });
161
+ var plugin_default = prefetchPlugin;
162
+
163
+ export {
164
+ prefetchPlugin,
165
+ plugin_default
166
+ };
@@ -0,0 +1,11 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined")
5
+ return require.apply(this, arguments);
6
+ throw new Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+
9
+ export {
10
+ __require
11
+ };