@module-federation/data-prefetch 0.6.6 → 0.6.8

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 (91) hide show
  1. package/.swcrc +29 -0
  2. package/CHANGELOG.md +28 -0
  3. package/LICENSE +1 -1
  4. package/__tests__/prefetch.spec.ts +3 -2
  5. package/__tests__/react.spec.ts +1 -1
  6. package/dist/LICENSE +21 -0
  7. package/dist/babel.cjs.d.ts +2 -0
  8. package/dist/babel.cjs.js +50 -0
  9. package/dist/babel.esm.d.ts +2 -0
  10. package/dist/babel.esm.js +48 -0
  11. package/dist/cli.cjs.d.ts +1 -0
  12. package/dist/cli.cjs.js +155 -0
  13. package/dist/cli.esm.d.ts +1 -0
  14. package/dist/cli.esm.js +152 -0
  15. package/dist/index.cjs.d.ts +1 -0
  16. package/dist/index.cjs.js +13 -0
  17. package/dist/index.cjs2.js +7 -0
  18. package/dist/index.esm.d.ts +1 -0
  19. package/dist/index.esm.js +6 -0
  20. package/dist/index.esm2.js +5 -0
  21. package/dist/package.json +100 -0
  22. package/dist/plugin.cjs.d.ts +2 -0
  23. package/dist/plugin.cjs.js +159 -0
  24. package/dist/plugin.esm.d.ts +2 -0
  25. package/dist/plugin.esm.js +154 -0
  26. package/dist/polyfills.cjs.js +14 -0
  27. package/dist/polyfills.esm.js +12 -0
  28. package/dist/prefetch.cjs.js +142 -0
  29. package/dist/prefetch.esm.js +140 -0
  30. package/dist/react.cjs.d.ts +1 -0
  31. package/dist/react.cjs.js +77 -0
  32. package/dist/react.esm.d.ts +1 -0
  33. package/dist/react.esm.js +75 -0
  34. package/dist/runtime-utils.cjs.js +27 -0
  35. package/dist/runtime-utils.esm.js +22 -0
  36. package/dist/shared.cjs.d.ts +2 -0
  37. package/dist/shared.cjs.js +24 -0
  38. package/dist/shared.esm.d.ts +2 -0
  39. package/dist/shared.esm.js +22 -0
  40. package/dist/{cli → src/cli}/babel.d.ts +2 -4
  41. package/dist/{cli → src/cli}/index.d.ts +5 -8
  42. package/dist/src/common/constant.d.ts +1 -0
  43. package/dist/src/common/index.d.ts +1 -0
  44. package/dist/src/common/node-utils.d.ts +2 -0
  45. package/dist/src/common/runtime-utils.d.ts +5 -0
  46. package/dist/src/index.d.ts +2 -0
  47. package/dist/src/logger/index.d.ts +3 -0
  48. package/dist/src/plugin.d.ts +3 -0
  49. package/dist/{prefetch-4e9646e4.d.ts → src/prefetch.d.ts} +5 -7
  50. package/dist/src/react/hooks.d.ts +11 -0
  51. package/dist/src/react/index.d.ts +1 -0
  52. package/dist/src/react/utils.d.ts +1 -0
  53. package/dist/src/shared/index.d.ts +3 -0
  54. package/dist/src/universal/index.d.ts +2 -0
  55. package/dist/universal.cjs.d.ts +1 -0
  56. package/dist/universal.cjs.js +29 -0
  57. package/dist/universal.esm.d.ts +1 -0
  58. package/dist/universal.esm.js +27 -0
  59. package/jest.config.js +2 -2
  60. package/package.json +33 -30
  61. package/project.json +48 -6
  62. package/rollup.config.js +46 -0
  63. package/src/cli/index.ts +12 -10
  64. package/src/prefetch.ts +6 -2
  65. package/tsconfig.json +1 -1
  66. package/tsconfig.lib.json +10 -0
  67. package/dist/cli/babel.js +0 -84
  68. package/dist/cli/index.js +0 -205
  69. package/dist/esm/chunk-AJPO2B2T.js +0 -30
  70. package/dist/esm/chunk-EZUCZHGV.js +0 -11
  71. package/dist/esm/chunk-ISLXMAIA.js +0 -155
  72. package/dist/esm/chunk-KI4QGPIS.js +0 -32
  73. package/dist/esm/chunk-TTJJJ2WZ.js +0 -7
  74. package/dist/esm/chunk-VVZ6XIM6.js +0 -166
  75. package/dist/esm/cli/babel.js +0 -57
  76. package/dist/esm/cli/index.js +0 -178
  77. package/dist/esm/index.js +0 -13
  78. package/dist/esm/plugin.js +0 -12
  79. package/dist/esm/react/index.js +0 -94
  80. package/dist/esm/shared/index.js +0 -27
  81. package/dist/esm/universal/index.js +0 -9
  82. package/dist/index.d.ts +0 -5
  83. package/dist/index.js +0 -350
  84. package/dist/plugin.d.ts +0 -5
  85. package/dist/plugin.js +0 -346
  86. package/dist/react/index.d.ts +0 -16
  87. package/dist/react/index.js +0 -286
  88. package/dist/shared/index.d.ts +0 -5
  89. package/dist/shared/index.js +0 -48
  90. package/dist/universal/index.d.ts +0 -8
  91. package/dist/universal/index.js +0 -204
@@ -1,155 +0,0 @@
1
- import {
2
- compatGetPrefetchId,
3
- getPrefetchId
4
- } from "./chunk-AJPO2B2T.js";
5
-
6
- // src/prefetch.ts
7
- import {
8
- getRemoteEntry,
9
- getRemoteInfo
10
- } from "@module-federation/runtime";
11
- import {
12
- loadScript
13
- } from "@module-federation/sdk";
14
- globalThis.__FEDERATION__ ?? (globalThis.__FEDERATION__ = {});
15
- var _a;
16
- (_a = globalThis.__FEDERATION__).__PREFETCH__ ?? (_a.__PREFETCH__ = {
17
- entryLoading: {},
18
- instance: /* @__PURE__ */ new Map(),
19
- __PREFETCH_EXPORTS__: {}
20
- });
21
- var MFDataPrefetch = class {
22
- constructor(options) {
23
- this.prefetchMemory = /* @__PURE__ */ new Map();
24
- this.recordOutdate = {};
25
- this._exports = {};
26
- this._options = options;
27
- this.global.instance.set(options.name, this);
28
- }
29
- get global() {
30
- return globalThis.__FEDERATION__.__PREFETCH__;
31
- }
32
- static getInstance(id) {
33
- return globalThis.__FEDERATION__.__PREFETCH__.instance.get(id);
34
- }
35
- async loadEntry(entry) {
36
- const { name, remoteSnapshot, remote, origin } = this._options;
37
- if (entry) {
38
- const { buildVersion, globalName } = remoteSnapshot;
39
- const uniqueKey = globalName || `${name}:${buildVersion}`;
40
- if (!this.global.entryLoading[uniqueKey]) {
41
- this.global.entryLoading[uniqueKey] = loadScript(entry, {});
42
- }
43
- return this.global.entryLoading[uniqueKey];
44
- } else {
45
- const remoteInfo = getRemoteInfo(remote);
46
- const module = origin.moduleCache.get(remoteInfo.name);
47
- return getRemoteEntry({
48
- origin,
49
- remoteInfo,
50
- remoteEntryExports: module ? module.remoteEntryExports : void 0
51
- });
52
- }
53
- }
54
- getProjectExports() {
55
- var _a2;
56
- if (Object.keys(this._exports).length > 0) {
57
- return this._exports;
58
- }
59
- const { name } = this._options;
60
- const exportsPromise = (_a2 = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) == null ? void 0 : _a2[name];
61
- const resolve = exportsPromise.then(
62
- (exports = {}) => {
63
- const memory = {};
64
- Object.keys(exports).forEach((key) => {
65
- memory[key] = {};
66
- const exportVal = exports[key];
67
- Object.keys(exportVal).reduce(
68
- (memo, current) => {
69
- if (current.toLocaleLowerCase().endsWith("prefetch") || current.toLocaleLowerCase() === "default") {
70
- memo[current] = exportVal[current];
71
- }
72
- return memo;
73
- },
74
- memory[key]
75
- );
76
- });
77
- this.memorizeExports(memory);
78
- }
79
- );
80
- return resolve;
81
- }
82
- memorizeExports(exports) {
83
- this._exports = exports;
84
- }
85
- getExposeExports(id) {
86
- const prefetchId = getPrefetchId(id);
87
- const compatId = compatGetPrefetchId(id);
88
- const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
89
- return prefetchExports || {};
90
- }
91
- prefetch(prefetchOptions) {
92
- const { id, functionId = "default", refetchParams } = prefetchOptions;
93
- let prefetchResult;
94
- const prefetchId = getPrefetchId(id);
95
- const compatId = compatGetPrefetchId(id);
96
- const memorizeId = id + functionId;
97
- const memory = this.prefetchMemory.get(memorizeId);
98
- if (!this.checkOutdate(prefetchOptions) && memory) {
99
- return memory;
100
- }
101
- const prefetchExports = this._exports[prefetchId] || this._exports[compatId];
102
- if (!prefetchExports) {
103
- return;
104
- }
105
- const executePrefetch = prefetchExports[functionId];
106
- if (typeof executePrefetch === "function") {
107
- if (refetchParams) {
108
- prefetchResult = executePrefetch(refetchParams);
109
- } else {
110
- prefetchResult = executePrefetch();
111
- }
112
- } else {
113
- throw new Error(
114
- `[Module Federation Data Prefetch]: No prefetch function called ${functionId} export in prefetch file`
115
- );
116
- }
117
- this.memorize(memorizeId, prefetchResult);
118
- return prefetchResult;
119
- }
120
- memorize(id, value) {
121
- this.prefetchMemory.set(id, value);
122
- }
123
- markOutdate(markOptions, isOutdate) {
124
- const { id, functionId = "default" } = markOptions;
125
- if (!this.recordOutdate[id]) {
126
- this.recordOutdate[id] = {};
127
- }
128
- this.recordOutdate[id][functionId] = isOutdate;
129
- }
130
- checkOutdate(outdateOptions) {
131
- const { id, functionId = "default", cacheStrategy } = outdateOptions;
132
- if (typeof cacheStrategy === "function") {
133
- return cacheStrategy();
134
- }
135
- if (!this.recordOutdate[id]) {
136
- this.recordOutdate[id] = {};
137
- }
138
- if (this.recordOutdate[id][functionId]) {
139
- this.markOutdate(
140
- {
141
- id,
142
- functionId
143
- },
144
- false
145
- );
146
- return true;
147
- } else {
148
- return false;
149
- }
150
- }
151
- };
152
-
153
- export {
154
- MFDataPrefetch
155
- };
@@ -1,32 +0,0 @@
1
- import {
2
- MFDataPrefetch
3
- } from "./chunk-ISLXMAIA.js";
4
- import {
5
- getScope
6
- } from "./chunk-AJPO2B2T.js";
7
-
8
- // src/universal/index.ts
9
- function prefetch(options) {
10
- const { id, functionId = "default" } = options;
11
- const mfScope = getScope();
12
- const prefetchInstance = MFDataPrefetch.getInstance(mfScope) || new MFDataPrefetch({
13
- name: mfScope
14
- });
15
- const res = prefetchInstance.getProjectExports();
16
- if (res instanceof Promise) {
17
- const promise = res.then(() => {
18
- const result = prefetchInstance.prefetch(options);
19
- prefetchInstance.memorize(id + functionId, result);
20
- return result;
21
- });
22
- return promise;
23
- } else {
24
- const result = prefetchInstance.prefetch(options);
25
- prefetchInstance.memorize(id + functionId, result);
26
- return result;
27
- }
28
- }
29
-
30
- export {
31
- prefetch
32
- };
@@ -1,7 +0,0 @@
1
- // src/logger/index.ts
2
- import { Logger } from "@module-federation/sdk";
3
- var logger_default = new Logger("[Module Federation Data Prefetch]");
4
-
5
- export {
6
- logger_default
7
- };
@@ -1,166 +0,0 @@
1
- import {
2
- logger_default
3
- } from "./chunk-TTJJJ2WZ.js";
4
- import {
5
- MFDataPrefetch
6
- } from "./chunk-ISLXMAIA.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
- };
@@ -1,57 +0,0 @@
1
- import "../chunk-EZUCZHGV.js";
2
-
3
- // src/cli/babel.ts
4
- import path from "path";
5
- var attribute = "id";
6
- var hookId = "usePrefetch";
7
- var importPackage = "@module-federation/data-prefetch/react";
8
- var babel_default = (babel, options) => {
9
- const t = babel.types;
10
- let shouldHandle = false;
11
- let scope = "";
12
- const { name, exposes } = options;
13
- if (!exposes) {
14
- return {};
15
- }
16
- const exposesKey = Object.keys(exposes);
17
- const processedExposes = exposesKey.map((expose) => ({
18
- key: expose.replace(".", ""),
19
- value: path.resolve(
20
- typeof exposes[expose] === "string" ? exposes[expose] : exposes[expose].import
21
- )
22
- }));
23
- return {
24
- visitor: {
25
- ImportDeclaration(nodePath, state) {
26
- const source = nodePath.node.source.value;
27
- const { specifiers } = nodePath.node;
28
- const { filename } = state.file.opts;
29
- if (source === importPackage) {
30
- shouldHandle = specifiers.some(
31
- (specifier) => specifier.imported && specifier.imported.name === hookId && processedExposes.find(
32
- (expose) => expose.value === filename && (scope = expose.key)
33
- )
34
- );
35
- }
36
- },
37
- CallExpression(nodePath) {
38
- if (shouldHandle && t.isIdentifier(nodePath.node.callee, { name: hookId }) && nodePath.node.arguments.length > 0) {
39
- const objectExpression = nodePath.node.arguments[0];
40
- if (objectExpression && t.isObjectExpression(objectExpression) && !objectExpression.properties.find(
41
- (p) => p.key.name === attribute
42
- )) {
43
- objectExpression.properties.push(
44
- t.objectProperty(
45
- t.identifier(attribute),
46
- t.stringLiteral(name + scope)
47
- )
48
- );
49
- }
50
- }
51
- }
52
- }
53
- };
54
- };
55
- export {
56
- babel_default as default
57
- };
@@ -1,178 +0,0 @@
1
- import {
2
- getPrefetchId
3
- } from "../chunk-AJPO2B2T.js";
4
- import {
5
- __require
6
- } from "../chunk-EZUCZHGV.js";
7
-
8
- // src/cli/index.ts
9
- import path2 from "path";
10
- import fs2 from "fs-extra";
11
- import {
12
- encodeName,
13
- MFPrefetchCommon
14
- } from "@module-federation/sdk";
15
- import { normalizeWebpackPath } from "@module-federation/sdk/normalize-webpack-path";
16
-
17
- // src/common/constant.ts
18
- var TEMP_DIR = ".mf";
19
-
20
- // src/common/node-utils.ts
21
- import path from "path";
22
- import fs from "fs-extra";
23
- var fileExistsWithCaseSync = (filepath) => {
24
- const dir = path.dirname(filepath);
25
- if (filepath === "/" || filepath === ".") {
26
- return true;
27
- }
28
- const filenames = fs.readdirSync(dir);
29
- if (filenames.indexOf(path.basename(filepath)) === -1) {
30
- return false;
31
- }
32
- return fileExistsWithCaseSync(dir);
33
- };
34
- var fixPrefetchPath = (exposePath) => {
35
- const pathExt = [".js", ".ts"];
36
- const extReg = /\.(ts|js|tsx|jsx)$/;
37
- if (extReg.test(exposePath)) {
38
- return pathExt.map((ext) => exposePath.replace(extReg, `.prefetch${ext}`));
39
- } else {
40
- return pathExt.map((ext) => exposePath + `.prefetch${ext}`);
41
- }
42
- };
43
-
44
- // src/cli/index.ts
45
- var { RuntimeGlobals, Template } = __require(normalizeWebpackPath("webpack"));
46
- function getFederationGlobalScope(runtimeGlobals) {
47
- return `${runtimeGlobals.require || "__webpack_require__"}.federation`;
48
- }
49
- var PrefetchPlugin = class {
50
- constructor(options) {
51
- this.options = options;
52
- this._reWriteExports = "";
53
- }
54
- apply(compiler) {
55
- var _a, _b;
56
- const { name, exposes } = this.options;
57
- if (!exposes) {
58
- return;
59
- }
60
- if (!compiler.options.context) {
61
- throw new Error("compiler.options.context is not defined");
62
- }
63
- const { runtimePlugins } = this.options;
64
- if (!Array.isArray(runtimePlugins)) {
65
- this.options.runtimePlugins = [];
66
- }
67
- const runtimePath = path2.resolve(__dirname, "../esm/plugin.js");
68
- const sharedPath = path2.resolve(__dirname, "../esm/shared/index.js");
69
- if (!((_a = this.options.runtimePlugins) == null ? void 0 : _a.includes(runtimePath))) {
70
- this.options.runtimePlugins.push(runtimePath);
71
- }
72
- if (!((_b = this.options.runtimePlugins) == null ? void 0 : _b.includes(sharedPath))) {
73
- this.options.runtimePlugins.push(sharedPath);
74
- }
75
- const encodedName = encodeName(name);
76
- const asyncEntryPath = path2.resolve(
77
- compiler.options.context,
78
- `node_modules/${TEMP_DIR}/${encodedName}/bootstrap.js`
79
- );
80
- if (fs2.existsSync(asyncEntryPath)) {
81
- fs2.unlinkSync(asyncEntryPath);
82
- }
83
- if (!this.options.dataPrefetch) {
84
- return;
85
- }
86
- const prefetchs = [];
87
- const exposeAlias = Object.keys(exposes);
88
- exposeAlias.forEach((alias) => {
89
- let exposePath;
90
- const exposeValue = exposes[alias];
91
- if (typeof exposeValue === "string") {
92
- exposePath = exposeValue;
93
- } else {
94
- exposePath = exposeValue.import[0];
95
- }
96
- const targetPaths = fixPrefetchPath(exposePath);
97
- for (const pathItem of targetPaths) {
98
- const absolutePath = path2.resolve(compiler.options.context, pathItem);
99
- if (fileExistsWithCaseSync(absolutePath)) {
100
- prefetchs.push(pathItem);
101
- const absoluteAlias = alias.replace(".", "");
102
- this._reWriteExports += `export * as ${getPrefetchId(
103
- `${name}${absoluteAlias}`
104
- )} from '${absolutePath}';
105
- `;
106
- break;
107
- }
108
- }
109
- });
110
- if (!this._reWriteExports) {
111
- return;
112
- }
113
- const tempDirRealPath = path2.resolve(
114
- compiler.options.context,
115
- "node_modules",
116
- TEMP_DIR
117
- );
118
- if (!fs2.existsSync(tempDirRealPath)) {
119
- fs2.mkdirSync(tempDirRealPath);
120
- }
121
- if (!fs2.existsSync(`${tempDirRealPath}/${encodedName}`)) {
122
- fs2.mkdirSync(`${tempDirRealPath}/${encodedName}`);
123
- }
124
- fs2.writeFileSync(asyncEntryPath, this._reWriteExports);
125
- new compiler.webpack.DefinePlugin({
126
- FederationDataPrefetch: JSON.stringify(asyncEntryPath)
127
- }).apply(compiler);
128
- }
129
- static addRuntime(compiler, options) {
130
- const encodedName = encodeName(options.name);
131
- if (!compiler.options.context) {
132
- throw new Error("compiler.options.context is not defined");
133
- }
134
- const prefetchEntry = path2.resolve(
135
- compiler.options.context,
136
- `node_modules/.mf/${encodedName}/bootstrap.js`
137
- );
138
- const federationGlobal = getFederationGlobalScope(
139
- RuntimeGlobals || {}
140
- );
141
- return Template.asString([
142
- fs2.existsSync(prefetchEntry) ? Template.indent([
143
- "function injectPrefetch() {",
144
- `globalThis.__FEDERATION__ = globalThis.__FEDERATION__ || {};`,
145
- `globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}'] = globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}'] || {`,
146
- `entryLoading: {},`,
147
- `instance: new Map(),`,
148
- `__PREFETCH_EXPORTS__: {},`,
149
- `};`,
150
- `globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}'] = globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}'] || {};`,
151
- `globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}']['${options.name}'] = import('${prefetchEntry}');`,
152
- "}",
153
- `${federationGlobal}.prefetch = injectPrefetch`
154
- ]) : "",
155
- Template.indent([
156
- `if(!${federationGlobal}.isMFRemote && ${federationGlobal}.prefetch){`,
157
- `${federationGlobal}.prefetch()`,
158
- "}"
159
- ])
160
- ]);
161
- }
162
- static setRemoteIdentifier() {
163
- const federationGlobal = getFederationGlobalScope(
164
- RuntimeGlobals || {}
165
- );
166
- return Template.indent([`${federationGlobal}.isMFRemote = true;`]);
167
- }
168
- static removeRemoteIdentifier() {
169
- const federationGlobal = getFederationGlobalScope(
170
- RuntimeGlobals || {}
171
- );
172
- return Template.indent([`${federationGlobal}.isMFRemote = false;`]);
173
- }
174
- };
175
- export {
176
- PrefetchPlugin,
177
- getFederationGlobalScope
178
- };
package/dist/esm/index.js DELETED
@@ -1,13 +0,0 @@
1
- import {
2
- prefetchPlugin
3
- } from "./chunk-VVZ6XIM6.js";
4
- import "./chunk-TTJJJ2WZ.js";
5
- import {
6
- MFDataPrefetch
7
- } from "./chunk-ISLXMAIA.js";
8
- import "./chunk-AJPO2B2T.js";
9
- import "./chunk-EZUCZHGV.js";
10
- export {
11
- MFDataPrefetch,
12
- prefetchPlugin
13
- };
@@ -1,12 +0,0 @@
1
- import {
2
- plugin_default,
3
- prefetchPlugin
4
- } from "./chunk-VVZ6XIM6.js";
5
- import "./chunk-TTJJJ2WZ.js";
6
- import "./chunk-ISLXMAIA.js";
7
- import "./chunk-AJPO2B2T.js";
8
- import "./chunk-EZUCZHGV.js";
9
- export {
10
- plugin_default as default,
11
- prefetchPlugin
12
- };