@module-federation/data-prefetch 0.0.0-next-20240911074627 → 0.0.0-next-20240918080432

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,9 +1,9 @@
1
1
  @module-federation/data-prefetch
2
2
 
3
- ## 0.0.0-next-20240911074627
3
+ ## 0.0.0-next-20240918080432
4
4
 
5
5
  ### Patch Changes
6
6
 
7
7
  - 3ddab21: feat(@module-federation/data-prefetch): support data prefetch in Module Federation
8
- - @module-federation/runtime@0.0.0-next-20240911074627
9
- - @module-federation/sdk@0.0.0-next-20240911074627
8
+ - @module-federation/runtime@0.0.0-next-20240918080432
9
+ - @module-federation/sdk@0.0.0-next-20240918080432
package/dist/cli/index.js CHANGED
@@ -63,6 +63,7 @@ var fixPrefetchPath = (exposePath) => {
63
63
  };
64
64
 
65
65
  // src/common/runtime-utils.ts
66
+ var import_runtime = require("@module-federation/runtime");
66
67
  var import_sdk = require("@module-federation/sdk");
67
68
  var getPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/${import_sdk.MFPrefetchCommon.identifier}`);
68
69
 
@@ -77,6 +78,7 @@ var PrefetchPlugin = class {
77
78
  this._reWriteExports = "";
78
79
  }
79
80
  apply(compiler) {
81
+ var _a, _b;
80
82
  const { name, exposes } = this.options;
81
83
  if (!exposes) {
82
84
  return;
@@ -88,12 +90,14 @@ var PrefetchPlugin = class {
88
90
  if (!Array.isArray(runtimePlugins)) {
89
91
  this.options.runtimePlugins = [];
90
92
  }
91
- this.options.runtimePlugins.push(
92
- import_path2.default.resolve(__dirname, "../esm/plugin.js")
93
- );
94
- this.options.runtimePlugins.push(
95
- import_path2.default.resolve(__dirname, "../esm/shared/index.js")
96
- );
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
+ }
97
101
  const encodedName = (0, import_sdk2.encodeName)(name);
98
102
  const asyncEntryPath = import_path2.default.resolve(
99
103
  compiler.options.context,
@@ -1,15 +1,11 @@
1
1
  // src/common/runtime-utils.ts
2
+ import { getInstance } from "@module-federation/runtime";
2
3
  import {
3
4
  encodeName,
4
5
  MFPrefetchCommon
5
6
  } from "@module-federation/sdk";
6
- var getScope = (id) => {
7
- const idArray = id.split("/");
8
- if (idArray.length >= 2) {
9
- idArray.pop();
10
- }
11
- const name = idArray.join("/");
12
- return name;
7
+ var getScope = () => {
8
+ return getInstance().options.name;
13
9
  };
14
10
  var getPrefetchId = (id) => encodeName(`${id}/${MFPrefetchCommon.identifier}`);
15
11
  var compatGetPrefetchId = (id) => encodeName(`${id}/VmokPrefetch`);
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  compatGetPrefetchId,
3
3
  getPrefetchId
4
- } from "./chunk-VWDP6NMM.js";
4
+ } from "./chunk-AJPO2B2T.js";
5
5
 
6
6
  // src/prefetch.ts
7
7
  import {
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  MFDataPrefetch
3
- } from "./chunk-57ZXBP7D.js";
3
+ } from "./chunk-ISLXMAIA.js";
4
4
  import {
5
5
  getScope
6
- } from "./chunk-VWDP6NMM.js";
6
+ } from "./chunk-AJPO2B2T.js";
7
7
 
8
8
  // src/universal/index.ts
9
9
  function prefetch(options) {
10
- const { id, functionId } = options;
11
- const mfScope = getScope(id);
10
+ const { id, functionId = "default" } = options;
11
+ const mfScope = getScope();
12
12
  const prefetchInstance = MFDataPrefetch.getInstance(mfScope) || new MFDataPrefetch({
13
13
  name: mfScope
14
14
  });
@@ -3,10 +3,10 @@ import {
3
3
  } from "./chunk-TTJJJ2WZ.js";
4
4
  import {
5
5
  MFDataPrefetch
6
- } from "./chunk-57ZXBP7D.js";
6
+ } from "./chunk-ISLXMAIA.js";
7
7
  import {
8
8
  getSignalFromManifest
9
- } from "./chunk-VWDP6NMM.js";
9
+ } from "./chunk-AJPO2B2T.js";
10
10
 
11
11
  // src/plugin.ts
12
12
  import { getResourceUrl } from "@module-federation/sdk";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getPrefetchId
3
- } from "../chunk-VWDP6NMM.js";
3
+ } from "../chunk-AJPO2B2T.js";
4
4
  import {
5
5
  __require
6
6
  } from "../chunk-EZUCZHGV.js";
@@ -52,6 +52,7 @@ var PrefetchPlugin = class {
52
52
  this._reWriteExports = "";
53
53
  }
54
54
  apply(compiler) {
55
+ var _a, _b;
55
56
  const { name, exposes } = this.options;
56
57
  if (!exposes) {
57
58
  return;
@@ -63,12 +64,14 @@ var PrefetchPlugin = class {
63
64
  if (!Array.isArray(runtimePlugins)) {
64
65
  this.options.runtimePlugins = [];
65
66
  }
66
- this.options.runtimePlugins.push(
67
- path2.resolve(__dirname, "../esm/plugin.js")
68
- );
69
- this.options.runtimePlugins.push(
70
- path2.resolve(__dirname, "../esm/shared/index.js")
71
- );
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
+ }
72
75
  const encodedName = encodeName(name);
73
76
  const asyncEntryPath = path2.resolve(
74
77
  compiler.options.context,
package/dist/esm/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  prefetchPlugin
3
- } from "./chunk-YXTPJG2M.js";
3
+ } from "./chunk-VVZ6XIM6.js";
4
4
  import "./chunk-TTJJJ2WZ.js";
5
5
  import {
6
6
  MFDataPrefetch
7
- } from "./chunk-57ZXBP7D.js";
8
- import "./chunk-VWDP6NMM.js";
7
+ } from "./chunk-ISLXMAIA.js";
8
+ import "./chunk-AJPO2B2T.js";
9
9
  import "./chunk-EZUCZHGV.js";
10
10
  export {
11
11
  MFDataPrefetch,
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  plugin_default,
3
3
  prefetchPlugin
4
- } from "./chunk-YXTPJG2M.js";
4
+ } from "./chunk-VVZ6XIM6.js";
5
5
  import "./chunk-TTJJJ2WZ.js";
6
- import "./chunk-57ZXBP7D.js";
7
- import "./chunk-VWDP6NMM.js";
6
+ import "./chunk-ISLXMAIA.js";
7
+ import "./chunk-AJPO2B2T.js";
8
8
  import "./chunk-EZUCZHGV.js";
9
9
  export {
10
10
  plugin_default as default,
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  prefetch
3
- } from "../chunk-OIIVUMED.js";
3
+ } from "../chunk-KI4QGPIS.js";
4
4
  import {
5
5
  logger_default
6
6
  } from "../chunk-TTJJJ2WZ.js";
7
7
  import {
8
8
  MFDataPrefetch
9
- } from "../chunk-57ZXBP7D.js";
9
+ } from "../chunk-ISLXMAIA.js";
10
10
  import {
11
11
  getScope
12
- } from "../chunk-VWDP6NMM.js";
12
+ } from "../chunk-AJPO2B2T.js";
13
13
  import "../chunk-EZUCZHGV.js";
14
14
 
15
15
  // src/react/hooks.ts
@@ -39,7 +39,7 @@ var usePrefetch = (options) => {
39
39
  id,
40
40
  functionId
41
41
  };
42
- const mfScope = getScope(id);
42
+ const mfScope = getScope();
43
43
  let state;
44
44
  const prefetchResult = prefetch(options);
45
45
  if (deferId) {
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  prefetch
3
- } from "../chunk-OIIVUMED.js";
4
- import "../chunk-57ZXBP7D.js";
5
- import "../chunk-VWDP6NMM.js";
3
+ } from "../chunk-KI4QGPIS.js";
4
+ import "../chunk-ISLXMAIA.js";
5
+ import "../chunk-AJPO2B2T.js";
6
6
  import "../chunk-EZUCZHGV.js";
7
7
  export {
8
8
  prefetch
package/dist/index.js CHANGED
@@ -26,10 +26,11 @@ __export(src_exports, {
26
26
  module.exports = __toCommonJS(src_exports);
27
27
 
28
28
  // src/prefetch.ts
29
- var import_runtime = require("@module-federation/runtime");
29
+ var import_runtime2 = require("@module-federation/runtime");
30
30
  var import_sdk2 = require("@module-federation/sdk");
31
31
 
32
32
  // src/common/runtime-utils.ts
33
+ var import_runtime = require("@module-federation/runtime");
33
34
  var import_sdk = require("@module-federation/sdk");
34
35
  var getPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/${import_sdk.MFPrefetchCommon.identifier}`);
35
36
  var compatGetPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/VmokPrefetch`);
@@ -78,9 +79,9 @@ var MFDataPrefetch = class {
78
79
  }
79
80
  return this.global.entryLoading[uniqueKey];
80
81
  } else {
81
- const remoteInfo = (0, import_runtime.getRemoteInfo)(remote);
82
+ const remoteInfo = (0, import_runtime2.getRemoteInfo)(remote);
82
83
  const module2 = origin.moduleCache.get(remoteInfo.name);
83
- return (0, import_runtime.getRemoteEntry)({
84
+ return (0, import_runtime2.getRemoteEntry)({
84
85
  origin,
85
86
  remoteInfo,
86
87
  remoteEntryExports: module2 ? module2.remoteEntryExports : void 0
package/dist/plugin.js CHANGED
@@ -27,6 +27,7 @@ module.exports = __toCommonJS(plugin_exports);
27
27
  var import_sdk4 = require("@module-federation/sdk");
28
28
 
29
29
  // src/common/runtime-utils.ts
30
+ var import_runtime = require("@module-federation/runtime");
30
31
  var import_sdk = require("@module-federation/sdk");
31
32
  var getPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/${import_sdk.MFPrefetchCommon.identifier}`);
32
33
  var compatGetPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/VmokPrefetch`);
@@ -44,7 +45,7 @@ var getSignalFromManifest = (remoteSnapshot) => {
44
45
  };
45
46
 
46
47
  // src/prefetch.ts
47
- var import_runtime = require("@module-federation/runtime");
48
+ var import_runtime2 = require("@module-federation/runtime");
48
49
  var import_sdk2 = require("@module-federation/sdk");
49
50
  globalThis.__FEDERATION__ ?? (globalThis.__FEDERATION__ = {});
50
51
  var _a;
@@ -77,9 +78,9 @@ var MFDataPrefetch = class {
77
78
  }
78
79
  return this.global.entryLoading[uniqueKey];
79
80
  } else {
80
- const remoteInfo = (0, import_runtime.getRemoteInfo)(remote);
81
+ const remoteInfo = (0, import_runtime2.getRemoteInfo)(remote);
81
82
  const module2 = origin.moduleCache.get(remoteInfo.name);
82
- return (0, import_runtime.getRemoteEntry)({
83
+ return (0, import_runtime2.getRemoteEntry)({
83
84
  origin,
84
85
  remoteInfo,
85
86
  remoteEntryExports: module2 ? module2.remoteEntryExports : void 0
@@ -32,18 +32,14 @@ var import_sdk = require("@module-federation/sdk");
32
32
  var logger_default = new import_sdk.Logger("[Module Federation Data Prefetch]");
33
33
 
34
34
  // src/prefetch.ts
35
- var import_runtime = require("@module-federation/runtime");
35
+ var import_runtime2 = require("@module-federation/runtime");
36
36
  var import_sdk3 = require("@module-federation/sdk");
37
37
 
38
38
  // src/common/runtime-utils.ts
39
+ var import_runtime = require("@module-federation/runtime");
39
40
  var import_sdk2 = require("@module-federation/sdk");
40
- var getScope = (id) => {
41
- const idArray = id.split("/");
42
- if (idArray.length >= 2) {
43
- idArray.pop();
44
- }
45
- const name = idArray.join("/");
46
- return name;
41
+ var getScope = () => {
42
+ return (0, import_runtime.getInstance)().options.name;
47
43
  };
48
44
  var getPrefetchId = (id) => (0, import_sdk2.encodeName)(`${id}/${import_sdk2.MFPrefetchCommon.identifier}`);
49
45
  var compatGetPrefetchId = (id) => (0, import_sdk2.encodeName)(`${id}/VmokPrefetch`);
@@ -80,9 +76,9 @@ var MFDataPrefetch = class {
80
76
  }
81
77
  return this.global.entryLoading[uniqueKey];
82
78
  } else {
83
- const remoteInfo = (0, import_runtime.getRemoteInfo)(remote);
79
+ const remoteInfo = (0, import_runtime2.getRemoteInfo)(remote);
84
80
  const module2 = origin.moduleCache.get(remoteInfo.name);
85
- return (0, import_runtime.getRemoteEntry)({
81
+ return (0, import_runtime2.getRemoteEntry)({
86
82
  origin,
87
83
  remoteInfo,
88
84
  remoteEntryExports: module2 ? module2.remoteEntryExports : void 0
@@ -190,8 +186,8 @@ var MFDataPrefetch = class {
190
186
 
191
187
  // src/universal/index.ts
192
188
  function prefetch(options) {
193
- const { id, functionId } = options;
194
- const mfScope = getScope(id);
189
+ const { id, functionId = "default" } = options;
190
+ const mfScope = getScope();
195
191
  const prefetchInstance = MFDataPrefetch.getInstance(mfScope) || new MFDataPrefetch({
196
192
  name: mfScope
197
193
  });
@@ -234,7 +230,7 @@ var usePrefetch = (options) => {
234
230
  id,
235
231
  functionId
236
232
  };
237
- const mfScope = getScope(id);
233
+ const mfScope = getScope();
238
234
  let state;
239
235
  const prefetchResult = prefetch(options);
240
236
  if (deferId) {
@@ -25,18 +25,14 @@ __export(universal_exports, {
25
25
  module.exports = __toCommonJS(universal_exports);
26
26
 
27
27
  // src/prefetch.ts
28
- var import_runtime = require("@module-federation/runtime");
28
+ var import_runtime2 = require("@module-federation/runtime");
29
29
  var import_sdk2 = require("@module-federation/sdk");
30
30
 
31
31
  // src/common/runtime-utils.ts
32
+ var import_runtime = require("@module-federation/runtime");
32
33
  var import_sdk = require("@module-federation/sdk");
33
- var getScope = (id) => {
34
- const idArray = id.split("/");
35
- if (idArray.length >= 2) {
36
- idArray.pop();
37
- }
38
- const name = idArray.join("/");
39
- return name;
34
+ var getScope = () => {
35
+ return (0, import_runtime.getInstance)().options.name;
40
36
  };
41
37
  var getPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/${import_sdk.MFPrefetchCommon.identifier}`);
42
38
  var compatGetPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/VmokPrefetch`);
@@ -73,9 +69,9 @@ var MFDataPrefetch = class {
73
69
  }
74
70
  return this.global.entryLoading[uniqueKey];
75
71
  } else {
76
- const remoteInfo = (0, import_runtime.getRemoteInfo)(remote);
72
+ const remoteInfo = (0, import_runtime2.getRemoteInfo)(remote);
77
73
  const module2 = origin.moduleCache.get(remoteInfo.name);
78
- return (0, import_runtime.getRemoteEntry)({
74
+ return (0, import_runtime2.getRemoteEntry)({
79
75
  origin,
80
76
  remoteInfo,
81
77
  remoteEntryExports: module2 ? module2.remoteEntryExports : void 0
@@ -183,8 +179,8 @@ var MFDataPrefetch = class {
183
179
 
184
180
  // src/universal/index.ts
185
181
  function prefetch(options) {
186
- const { id, functionId } = options;
187
- const mfScope = getScope(id);
182
+ const { id, functionId = "default" } = options;
183
+ const mfScope = getScope();
188
184
  const prefetchInstance = MFDataPrefetch.getInstance(mfScope) || new MFDataPrefetch({
189
185
  name: mfScope
190
186
  });
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-20240911074627",
4
+ "version": "0.0.0-next-20240918080432",
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-20240911074627",
89
- "@module-federation/runtime": "0.0.0-next-20240911074627"
88
+ "@module-federation/sdk": "0.0.0-next-20240918080432",
89
+ "@module-federation/runtime": "0.0.0-next-20240918080432"
90
90
  },
91
91
  "scripts": {
92
92
  "dev": "cross-env WATCH=true tsup",
package/src/cli/index.ts CHANGED
@@ -46,12 +46,16 @@ export class PrefetchPlugin implements WebpackPluginInstance {
46
46
  if (!Array.isArray(runtimePlugins)) {
47
47
  this.options.runtimePlugins = [];
48
48
  }
49
- this.options.runtimePlugins!.push(
50
- path.resolve(__dirname, '../esm/plugin.js'),
51
- );
52
- this.options.runtimePlugins!.push(
53
- path.resolve(__dirname, '../esm/shared/index.js'),
54
- );
49
+
50
+ const runtimePath = path.resolve(__dirname, '../esm/plugin.js');
51
+ const sharedPath = path.resolve(__dirname, '../esm/shared/index.js');
52
+ if (!this.options.runtimePlugins?.includes(runtimePath)) {
53
+ this.options.runtimePlugins!.push(runtimePath);
54
+ }
55
+ if (!this.options.runtimePlugins?.includes(sharedPath)) {
56
+ this.options.runtimePlugins!.push(sharedPath);
57
+ }
58
+
55
59
  const encodedName = encodeName(name as string);
56
60
  const asyncEntryPath = path.resolve(
57
61
  compiler.options.context,
@@ -1,16 +1,12 @@
1
+ import { getInstance } from '@module-federation/runtime';
1
2
  import {
2
3
  encodeName,
3
4
  ModuleInfo,
4
5
  MFPrefetchCommon,
5
6
  } from '@module-federation/sdk';
6
7
 
7
- export const getScope = (id: string): string => {
8
- const idArray = id.split('/');
9
- if (idArray.length >= 2) {
10
- idArray.pop();
11
- }
12
- const name = idArray.join('/');
13
- return name;
8
+ export const getScope = (): string => {
9
+ return getInstance()!.options.name;
14
10
  };
15
11
 
16
12
  export const getPrefetchId = (id: string): string =>
@@ -35,7 +35,7 @@ export const usePrefetch = <T>(
35
35
  id,
36
36
  functionId,
37
37
  };
38
- const mfScope = getScope(id);
38
+ const mfScope = getScope();
39
39
 
40
40
  let state;
41
41
  const prefetchResult = prefetch(options);
@@ -2,8 +2,8 @@ import { MFDataPrefetch, type prefetchOptions } from '../prefetch';
2
2
  import { getScope } from '../common/runtime-utils';
3
3
 
4
4
  export function prefetch(options: prefetchOptions): Promise<any> {
5
- const { id, functionId } = options;
6
- const mfScope = getScope(id);
5
+ const { id, functionId = 'default' } = options;
6
+ const mfScope = getScope();
7
7
 
8
8
  const prefetchInstance =
9
9
  MFDataPrefetch.getInstance(mfScope) ||