@module-federation/data-prefetch 0.0.0-next-20240701101956 → 0.0.0-next-20240702090143

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,11 +1,11 @@
1
1
  @module-federation/data-prefetch
2
2
 
3
- ## 0.0.0-next-20240701101956
3
+ ## 0.0.0-next-20240702090143
4
4
 
5
5
  ### Patch Changes
6
6
 
7
7
  - 3ddab21: feat(@module-federation/data-prefetch): support data prefetch in Module Federation
8
8
  - Updated dependencies [09b792d]
9
9
  - Updated dependencies [09b792d]
10
- - @module-federation/sdk@0.0.0-next-20240701101956
11
- - @module-federation/runtime@0.0.0-next-20240701101956
10
+ - @module-federation/sdk@0.0.0-next-20240702090143
11
+ - @module-federation/runtime@0.0.0-next-20240702090143
@@ -9,6 +9,7 @@ import {
9
9
  } from "./chunk-EWCGK4XA.js";
10
10
 
11
11
  // src/plugin.ts
12
+ import { Module } from "@module-federation/runtime";
12
13
  import { getResourceUrl } from "@module-federation/sdk";
13
14
  var loadingArray = [];
14
15
  var strategy = "loaded-first";
@@ -111,6 +112,21 @@ var prefetchPlugin = () => ({
111
112
  return options;
112
113
  }
113
114
  const promise = instance.loadEntry(prefetchUrl).then(async () => {
115
+ let module = origin.moduleCache.get(remote.name);
116
+ const moduleOptions = {
117
+ host: origin,
118
+ remoteInfo: remote
119
+ };
120
+ if (!module) {
121
+ module = new Module(moduleOptions);
122
+ origin.moduleCache.set(remote.name, module);
123
+ }
124
+ const idPart = id.split("/");
125
+ let expose = idPart[idPart.length - 1];
126
+ if (expose !== ".") {
127
+ expose = `./${expose}`;
128
+ }
129
+ await module.get(id, expose, {}, remoteSnapshot);
114
130
  const projectExports = instance.getProjectExports();
115
131
  if (projectExports instanceof Promise) {
116
132
  await projectExports;
package/dist/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  prefetchPlugin
3
- } from "./chunk-VJO2H3UO.js";
3
+ } from "./chunk-WLE6YNDH.js";
4
4
  import "./chunk-TTJJJ2WZ.js";
5
5
  import {
6
6
  MFDataPrefetch
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  plugin_default,
3
3
  prefetchPlugin
4
- } from "./chunk-VJO2H3UO.js";
4
+ } from "./chunk-WLE6YNDH.js";
5
5
  import "./chunk-TTJJJ2WZ.js";
6
6
  import "./chunk-JEPJP5O3.js";
7
7
  import "./chunk-EWCGK4XA.js";
package/dist/index.js CHANGED
@@ -192,6 +192,7 @@ var MFDataPrefetch = class {
192
192
  };
193
193
 
194
194
  // src/plugin.ts
195
+ var import_runtime2 = require("@module-federation/runtime");
195
196
  var import_sdk4 = require("@module-federation/sdk");
196
197
 
197
198
  // src/logger/index.ts
@@ -300,6 +301,21 @@ var prefetchPlugin = () => ({
300
301
  return options;
301
302
  }
302
303
  const promise = instance.loadEntry(prefetchUrl).then(async () => {
304
+ let module2 = origin.moduleCache.get(remote.name);
305
+ const moduleOptions = {
306
+ host: origin,
307
+ remoteInfo: remote
308
+ };
309
+ if (!module2) {
310
+ module2 = new import_runtime2.Module(moduleOptions);
311
+ origin.moduleCache.set(remote.name, module2);
312
+ }
313
+ const idPart = id.split("/");
314
+ let expose = idPart[idPart.length - 1];
315
+ if (expose !== ".") {
316
+ expose = `./${expose}`;
317
+ }
318
+ await module2.get(id, expose, {}, remoteSnapshot);
303
319
  const projectExports = instance.getProjectExports();
304
320
  if (projectExports instanceof Promise) {
305
321
  await projectExports;
package/dist/plugin.js CHANGED
@@ -24,6 +24,7 @@ __export(plugin_exports, {
24
24
  prefetchPlugin: () => prefetchPlugin
25
25
  });
26
26
  module.exports = __toCommonJS(plugin_exports);
27
+ var import_runtime2 = require("@module-federation/runtime");
27
28
  var import_sdk4 = require("@module-federation/sdk");
28
29
 
29
30
  // src/common/runtime-utils.ts
@@ -296,6 +297,21 @@ var prefetchPlugin = () => ({
296
297
  return options;
297
298
  }
298
299
  const promise = instance.loadEntry(prefetchUrl).then(async () => {
300
+ let module2 = origin.moduleCache.get(remote.name);
301
+ const moduleOptions = {
302
+ host: origin,
303
+ remoteInfo: remote
304
+ };
305
+ if (!module2) {
306
+ module2 = new import_runtime2.Module(moduleOptions);
307
+ origin.moduleCache.set(remote.name, module2);
308
+ }
309
+ const idPart = id.split("/");
310
+ let expose = idPart[idPart.length - 1];
311
+ if (expose !== ".") {
312
+ expose = `./${expose}`;
313
+ }
314
+ await module2.get(id, expose, {}, remoteSnapshot);
299
315
  const projectExports = instance.getProjectExports();
300
316
  if (projectExports instanceof Promise) {
301
317
  await projectExports;
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-20240701101956",
4
+ "version": "0.0.0-next-20240702090143",
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-20240701101956",
89
- "@module-federation/runtime": "0.0.0-next-20240701101956"
88
+ "@module-federation/sdk": "0.0.0-next-20240702090143",
89
+ "@module-federation/runtime": "0.0.0-next-20240702090143"
90
90
  },
91
91
  "scripts": {
92
92
  "dev": "cross-env WATCH=true tsup",
package/src/plugin.ts CHANGED
@@ -1,4 +1,8 @@
1
- import type { FederationRuntimePlugin } from '@module-federation/runtime/types';
1
+ import { Module } from '@module-federation/runtime';
2
+ import type {
3
+ FederationRuntimePlugin,
4
+ RemoteInfo,
5
+ } from '@module-federation/runtime/types';
2
6
  import { ModuleInfo, getResourceUrl } from '@module-federation/sdk';
3
7
 
4
8
  import { getSignalFromManifest } from './common/runtime-utils';
@@ -150,6 +154,22 @@ export const prefetchPlugin = (): FederationRuntimePlugin => ({
150
154
  }
151
155
 
152
156
  const promise = instance.loadEntry(prefetchUrl).then(async () => {
157
+ let module = origin.moduleCache.get(remote.name);
158
+ const moduleOptions = {
159
+ host: origin,
160
+ remoteInfo: remote as RemoteInfo,
161
+ };
162
+ if (!module) {
163
+ module = new Module(moduleOptions);
164
+ origin.moduleCache.set(remote.name, module);
165
+ }
166
+ const idPart = id.split('/');
167
+ let expose = idPart[idPart.length - 1];
168
+ if (expose !== '.') {
169
+ expose = `./${expose}`;
170
+ }
171
+ await module.get(id, expose, {}, remoteSnapshot);
172
+
153
173
  const projectExports = instance!.getProjectExports();
154
174
  if (projectExports instanceof Promise) {
155
175
  await projectExports;