@module-federation/data-prefetch 0.0.0-next-20240923071822 → 0.0.0-next-20240924012324

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/CHANGELOG.md CHANGED
@@ -1,14 +1,21 @@
1
1
  # @module-federation/data-prefetch
2
2
 
3
- ## 0.0.0-next-20240923071822
3
+ ## 0.0.0-next-20240924012324
4
4
 
5
5
  ### Patch Changes
6
6
 
7
+ - f10cf55: Refactored the way prefetch entries are imported for improved dynamic loading handling.
8
+
9
+ - Changed the import of prefetch entries to use a function wrapper for more dynamic control.
10
+ - Updated data types to ensure consistency with the new function-based import approach.
11
+ - Modified the `injectPrefetch` function structure to incorporate the new import method.
12
+ - Modified the `MFDataPrefetch` class to handle the new import function when resolving exports.
13
+
7
14
  - Updated dependencies [3837c89]
8
15
  - Updated dependencies [3837c89]
9
16
  - Updated dependencies [59e0069]
10
- - @module-federation/runtime@0.0.0-next-20240923071822
11
- - @module-federation/sdk@0.0.0-next-20240923071822
17
+ - @module-federation/runtime@0.0.0-next-20240924012324
18
+ - @module-federation/sdk@0.0.0-next-20240924012324
12
19
 
13
20
  ## 0.6.6
14
21
 
package/dist/cli/index.js CHANGED
@@ -167,14 +167,16 @@ var PrefetchPlugin = class {
167
167
  return Template.asString([
168
168
  import_fs_extra2.default.existsSync(prefetchEntry) ? Template.indent([
169
169
  "function injectPrefetch() {",
170
- `globalThis.__FEDERATION__ = globalThis.__FEDERATION__ || {};`,
171
- `globalThis.__FEDERATION__['${import_sdk2.MFPrefetchCommon.globalKey}'] = globalThis.__FEDERATION__['${import_sdk2.MFPrefetchCommon.globalKey}'] || {`,
172
- `entryLoading: {},`,
173
- `instance: new Map(),`,
174
- `__PREFETCH_EXPORTS__: {},`,
175
- `};`,
176
- `globalThis.__FEDERATION__['${import_sdk2.MFPrefetchCommon.globalKey}']['${import_sdk2.MFPrefetchCommon.exportsKey}'] = globalThis.__FEDERATION__['${import_sdk2.MFPrefetchCommon.globalKey}']['${import_sdk2.MFPrefetchCommon.exportsKey}'] || {};`,
177
- `globalThis.__FEDERATION__['${import_sdk2.MFPrefetchCommon.globalKey}']['${import_sdk2.MFPrefetchCommon.exportsKey}']['${options.name}'] = import('${prefetchEntry}');`,
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
+ ]),
178
180
  "}",
179
181
  `${federationGlobal}.prefetch = injectPrefetch`
180
182
  ]) : "",
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-TTJJJ2WZ.js";
4
4
  import {
5
5
  MFDataPrefetch
6
- } from "./chunk-ISLXMAIA.js";
6
+ } from "./chunk-L7EVPWJ4.js";
7
7
  import {
8
8
  getSignalFromManifest
9
9
  } from "./chunk-AJPO2B2T.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  MFDataPrefetch
3
- } from "./chunk-ISLXMAIA.js";
3
+ } from "./chunk-L7EVPWJ4.js";
4
4
  import {
5
5
  getScope
6
6
  } from "./chunk-AJPO2B2T.js";
@@ -52,12 +52,12 @@ var MFDataPrefetch = class {
52
52
  }
53
53
  }
54
54
  getProjectExports() {
55
- var _a2;
55
+ var _a2, _b;
56
56
  if (Object.keys(this._exports).length > 0) {
57
57
  return this._exports;
58
58
  }
59
59
  const { name } = this._options;
60
- const exportsPromise = (_a2 = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) == null ? void 0 : _a2[name];
60
+ const exportsPromise = (_b = (_a2 = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) == null ? void 0 : _a2[name]) == null ? void 0 : _b.call(_a2);
61
61
  const resolve = exportsPromise.then(
62
62
  (exports = {}) => {
63
63
  const memory = {};
@@ -141,14 +141,16 @@ var PrefetchPlugin = class {
141
141
  return Template.asString([
142
142
  fs2.existsSync(prefetchEntry) ? Template.indent([
143
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}');`,
144
+ Template.indent([
145
+ `globalThis.__FEDERATION__ = globalThis.__FEDERATION__ || {};`,
146
+ `globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}'] = globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}'] || {`,
147
+ `entryLoading: {},`,
148
+ `instance: new Map(),`,
149
+ `__PREFETCH_EXPORTS__: {},`,
150
+ `};`,
151
+ `globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}'] = globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}'] || {};`,
152
+ `globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}']['${options.name}'] = function(){ return import('${prefetchEntry}');}`
153
+ ]),
152
154
  "}",
153
155
  `${federationGlobal}.prefetch = injectPrefetch`
154
156
  ]) : "",
package/dist/esm/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  prefetchPlugin
3
- } from "./chunk-VVZ6XIM6.js";
3
+ } from "./chunk-EK6Q2YBB.js";
4
4
  import "./chunk-TTJJJ2WZ.js";
5
5
  import {
6
6
  MFDataPrefetch
7
- } from "./chunk-ISLXMAIA.js";
7
+ } from "./chunk-L7EVPWJ4.js";
8
8
  import "./chunk-AJPO2B2T.js";
9
9
  import "./chunk-EZUCZHGV.js";
10
10
  export {
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  plugin_default,
3
3
  prefetchPlugin
4
- } from "./chunk-VVZ6XIM6.js";
4
+ } from "./chunk-EK6Q2YBB.js";
5
5
  import "./chunk-TTJJJ2WZ.js";
6
- import "./chunk-ISLXMAIA.js";
6
+ import "./chunk-L7EVPWJ4.js";
7
7
  import "./chunk-AJPO2B2T.js";
8
8
  import "./chunk-EZUCZHGV.js";
9
9
  export {
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  prefetch
3
- } from "../chunk-KI4QGPIS.js";
3
+ } from "../chunk-FKXFJ2Y4.js";
4
4
  import {
5
5
  logger_default
6
6
  } from "../chunk-TTJJJ2WZ.js";
7
7
  import {
8
8
  MFDataPrefetch
9
- } from "../chunk-ISLXMAIA.js";
9
+ } from "../chunk-L7EVPWJ4.js";
10
10
  import {
11
11
  getScope
12
12
  } from "../chunk-AJPO2B2T.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  prefetch
3
- } from "../chunk-KI4QGPIS.js";
4
- import "../chunk-ISLXMAIA.js";
3
+ } from "../chunk-FKXFJ2Y4.js";
4
+ import "../chunk-L7EVPWJ4.js";
5
5
  import "../chunk-AJPO2B2T.js";
6
6
  import "../chunk-EZUCZHGV.js";
7
7
  export {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { D as DataPrefetchOptions, M as MFDataPrefetch, p as prefetchOptions } from './prefetch-4e9646e4.js';
1
+ export { D as DataPrefetchOptions, M as MFDataPrefetch, p as prefetchOptions } from './prefetch-c08be471.js';
2
2
  export { default as prefetchPlugin } from './plugin.js';
3
3
  import '@module-federation/runtime';
4
4
  import '@module-federation/sdk';
package/dist/index.js CHANGED
@@ -89,12 +89,12 @@ var MFDataPrefetch = class {
89
89
  }
90
90
  }
91
91
  getProjectExports() {
92
- var _a2;
92
+ var _a2, _b;
93
93
  if (Object.keys(this._exports).length > 0) {
94
94
  return this._exports;
95
95
  }
96
96
  const { name } = this._options;
97
- const exportsPromise = (_a2 = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) == null ? void 0 : _a2[name];
97
+ const exportsPromise = (_b = (_a2 = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) == null ? void 0 : _a2[name]) == null ? void 0 : _b.call(_a2);
98
98
  const resolve = exportsPromise.then(
99
99
  (exports = {}) => {
100
100
  const memory = {};
package/dist/plugin.js CHANGED
@@ -88,12 +88,12 @@ var MFDataPrefetch = class {
88
88
  }
89
89
  }
90
90
  getProjectExports() {
91
- var _a2;
91
+ var _a2, _b;
92
92
  if (Object.keys(this._exports).length > 0) {
93
93
  return this._exports;
94
94
  }
95
95
  const { name } = this._options;
96
- const exportsPromise = (_a2 = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) == null ? void 0 : _a2[name];
96
+ const exportsPromise = (_b = (_a2 = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) == null ? void 0 : _a2[name]) == null ? void 0 : _b.call(_a2);
97
97
  const resolve = exportsPromise.then(
98
98
  (exports = {}) => {
99
99
  const memory = {};
@@ -7,7 +7,7 @@ declare module '@module-federation/runtime' {
7
7
  __PREFETCH__: {
8
8
  entryLoading: Record<string, undefined | Promise<void>>;
9
9
  instance: Map<string, MFDataPrefetch>;
10
- __PREFETCH_EXPORTS__: Record<string, Promise<Record<string, any>>>;
10
+ __PREFETCH_EXPORTS__: Record<string, () => Promise<Record<string, any>>>;
11
11
  };
12
12
  }
13
13
  }
@@ -1,4 +1,4 @@
1
- import { p as prefetchOptions } from '../prefetch-4e9646e4.js';
1
+ import { p as prefetchOptions } from '../prefetch-c08be471.js';
2
2
  import '@module-federation/runtime';
3
3
  import '@module-federation/sdk';
4
4
  import '@module-federation/runtime/types';
@@ -86,12 +86,12 @@ var MFDataPrefetch = class {
86
86
  }
87
87
  }
88
88
  getProjectExports() {
89
- var _a2;
89
+ var _a2, _b;
90
90
  if (Object.keys(this._exports).length > 0) {
91
91
  return this._exports;
92
92
  }
93
93
  const { name } = this._options;
94
- const exportsPromise = (_a2 = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) == null ? void 0 : _a2[name];
94
+ const exportsPromise = (_b = (_a2 = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) == null ? void 0 : _a2[name]) == null ? void 0 : _b.call(_a2);
95
95
  const resolve = exportsPromise.then(
96
96
  (exports = {}) => {
97
97
  const memory = {};
@@ -1,4 +1,4 @@
1
- import { p as prefetchOptions } from '../prefetch-4e9646e4.js';
1
+ import { p as prefetchOptions } from '../prefetch-c08be471.js';
2
2
  import '@module-federation/runtime';
3
3
  import '@module-federation/sdk';
4
4
  import '@module-federation/runtime/types';
@@ -79,12 +79,12 @@ var MFDataPrefetch = class {
79
79
  }
80
80
  }
81
81
  getProjectExports() {
82
- var _a2;
82
+ var _a2, _b;
83
83
  if (Object.keys(this._exports).length > 0) {
84
84
  return this._exports;
85
85
  }
86
86
  const { name } = this._options;
87
- const exportsPromise = (_a2 = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) == null ? void 0 : _a2[name];
87
+ const exportsPromise = (_b = (_a2 = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) == null ? void 0 : _a2[name]) == null ? void 0 : _b.call(_a2);
88
88
  const resolve = exportsPromise.then(
89
89
  (exports = {}) => {
90
90
  const memory = {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@module-federation/data-prefetch",
3
3
  "description": "Module Federation Data Prefetch",
4
- "version": "0.0.0-next-20240923071822",
4
+ "version": "0.0.0-next-20240924012324",
5
5
  "author": "nieyan <nyqykk@foxmail.com>",
6
6
  "homepage": "https://github.com/module-federation/core",
7
7
  "license": "MIT",
@@ -85,8 +85,8 @@
85
85
  },
86
86
  "dependencies": {
87
87
  "fs-extra": "9.1.0",
88
- "@module-federation/sdk": "0.0.0-next-20240923071822",
89
- "@module-federation/runtime": "0.0.0-next-20240923071822"
88
+ "@module-federation/sdk": "0.0.0-next-20240924012324",
89
+ "@module-federation/runtime": "0.0.0-next-20240924012324"
90
90
  },
91
91
  "scripts": {
92
92
  "dev": "cross-env WATCH=true tsup",
package/src/cli/index.ts CHANGED
@@ -135,14 +135,16 @@ export class PrefetchPlugin implements WebpackPluginInstance {
135
135
  fs.existsSync(prefetchEntry)
136
136
  ? Template.indent([
137
137
  'function injectPrefetch() {',
138
- `globalThis.__FEDERATION__ = globalThis.__FEDERATION__ || {};`,
139
- `globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}'] = globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}'] || {`,
140
- `entryLoading: {},`,
141
- `instance: new Map(),`,
142
- `__PREFETCH_EXPORTS__: {},`,
143
- `};`,
144
- `globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}'] = globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}'] || {};`,
145
- `globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}']['${options.name}'] = import('${prefetchEntry}');`,
138
+ Template.indent([
139
+ `globalThis.__FEDERATION__ = globalThis.__FEDERATION__ || {};`,
140
+ `globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}'] = globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}'] || {`,
141
+ `entryLoading: {},`,
142
+ `instance: new Map(),`,
143
+ `__PREFETCH_EXPORTS__: {},`,
144
+ `};`,
145
+ `globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}'] = globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}'] || {};`,
146
+ `globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}']['${options.name}'] = function(){ return import('${prefetchEntry}');}`,
147
+ ]),
146
148
  '}',
147
149
  `${federationGlobal}.prefetch = injectPrefetch`,
148
150
  ])
package/src/prefetch.ts CHANGED
@@ -17,7 +17,7 @@ declare module '@module-federation/runtime' {
17
17
  __PREFETCH__: {
18
18
  entryLoading: Record<string, undefined | Promise<void>>;
19
19
  instance: Map<string, MFDataPrefetch>;
20
- __PREFETCH_EXPORTS__: Record<string, Promise<Record<string, any>>>;
20
+ __PREFETCH_EXPORTS__: Record<string, () => Promise<Record<string, any>>>;
21
21
  };
22
22
  }
23
23
  }
@@ -95,7 +95,7 @@ export class MFDataPrefetch {
95
95
  }
96
96
  const { name } = this._options;
97
97
  const exportsPromise =
98
- globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__?.[name];
98
+ globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__?.[name]?.();
99
99
  const resolve = exportsPromise.then(
100
100
  (exports: Record<string, Record<string, any>> = {}) => {
101
101
  // Match prefetch based on the function name suffix so that other capabilities can be expanded later.