@module-federation/data-prefetch 0.6.7 → 0.6.9

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/dist/react.esm.js CHANGED
@@ -1,147 +1,63 @@
1
+ import { _ as _extends } from './polyfills.esm.js';
1
2
  import { useRef, useEffect, useState } from 'react';
2
3
  import { l as logger } from './index.esm2.js';
3
4
  import { M as MFDataPrefetch } from './prefetch.esm.js';
4
5
  import { prefetch } from './universal.esm.js';
5
- import { b as getScope } from './runtime-utils.esm.js';
6
+ import { g as getScope } from './runtime-utils.esm.js';
6
7
  import '@module-federation/sdk';
7
8
  import '@module-federation/runtime';
8
9
 
9
- var useFirstMounted = function() {
10
- var ref = useRef(true);
11
- useEffect(function() {
10
+ const useFirstMounted = ()=>{
11
+ const ref = useRef(true);
12
+ useEffect(()=>{
12
13
  ref.current = false;
13
14
  }, []);
14
15
  return ref.current;
15
16
  };
16
17
 
17
- function _array_like_to_array(arr, len) {
18
- if (len == null || len > arr.length) len = arr.length;
19
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
20
- return arr2;
21
- }
22
- function _array_with_holes(arr) {
23
- if (Array.isArray(arr)) return arr;
24
- }
25
- function _define_property(obj, key, value) {
26
- if (key in obj) {
27
- Object.defineProperty(obj, key, {
28
- value: value,
29
- enumerable: true,
30
- configurable: true,
31
- writable: true
32
- });
33
- } else {
34
- obj[key] = value;
35
- }
36
- return obj;
37
- }
38
- function _instanceof(left, right) {
39
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
40
- return !!right[Symbol.hasInstance](left);
41
- } else {
42
- return left instanceof right;
43
- }
44
- }
45
- function _iterable_to_array_limit(arr, i) {
46
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
47
- if (_i == null) return;
48
- var _arr = [];
49
- var _n = true;
50
- var _d = false;
51
- var _s, _e;
52
- try {
53
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
54
- _arr.push(_s.value);
55
- if (i && _arr.length === i) break;
56
- }
57
- } catch (err) {
58
- _d = true;
59
- _e = err;
60
- } finally{
61
- try {
62
- if (!_n && _i["return"] != null) _i["return"]();
63
- } finally{
64
- if (_d) throw _e;
65
- }
66
- }
67
- return _arr;
68
- }
69
- function _non_iterable_rest() {
70
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
71
- }
72
- function _object_spread(target) {
73
- for(var i = 1; i < arguments.length; i++){
74
- var source = arguments[i] != null ? arguments[i] : {};
75
- var ownKeys = Object.keys(source);
76
- if (typeof Object.getOwnPropertySymbols === "function") {
77
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
78
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
79
- }));
80
- }
81
- ownKeys.forEach(function(key) {
82
- _define_property(target, key, source[key]);
83
- });
84
- }
85
- return target;
86
- }
87
- function _sliced_to_array(arr, i) {
88
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
89
- }
90
- function _unsupported_iterable_to_array(o, minLen) {
91
- if (!o) return;
92
- if (typeof o === "string") return _array_like_to_array(o, minLen);
93
- var n = Object.prototype.toString.call(o).slice(8, -1);
94
- if (n === "Object" && o.constructor) n = o.constructor.name;
95
- if (n === "Map" || n === "Set") return Array.from(n);
96
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
97
- }
98
- var usePrefetch = function(options) {
99
- var isFirstMounted = useFirstMounted();
18
+ const usePrefetch = (options)=>{
19
+ const isFirstMounted = useFirstMounted();
100
20
  if (isFirstMounted) {
101
- var startTiming = performance.now();
102
- logger.info("2. Start Get Prefetch Data: ".concat(options.id, " - ").concat(options.functionId || 'default', " - ").concat(startTiming));
21
+ const startTiming = performance.now();
22
+ logger.info(`2. Start Get Prefetch Data: ${options.id} - ${options.functionId || 'default'} - ${startTiming}`);
103
23
  }
104
- var id = options.id, functionId = options.functionId, deferId = options.deferId;
105
- var prefetchInfo = {
106
- id: id,
107
- functionId: functionId
24
+ const { id, functionId, deferId } = options;
25
+ const prefetchInfo = {
26
+ id,
27
+ functionId
108
28
  };
109
- var mfScope = getScope();
110
- var state;
111
- var prefetchResult = prefetch(options);
29
+ const mfScope = getScope();
30
+ let state;
31
+ const prefetchResult = prefetch(options);
112
32
  if (deferId) {
113
- if (_instanceof(prefetchResult, Promise)) {
114
- state = prefetchResult.then(function(deferredData) {
115
- return deferredData.data[deferId];
116
- });
33
+ if (prefetchResult instanceof Promise) {
34
+ state = prefetchResult.then((deferredData)=>deferredData.data[deferId]);
117
35
  } else {
118
36
  state = prefetchResult.data[deferId];
119
37
  }
120
38
  } else {
121
39
  state = prefetchResult;
122
40
  }
123
- var _useState = _sliced_to_array(useState(state), 2), prefetchState = _useState[0], setPrefetchState = _useState[1];
124
- var prefetchInstance = MFDataPrefetch.getInstance(mfScope);
125
- useEffect(function() {
126
- var useEffectTiming = performance.now();
127
- logger.info("3. Start Execute UseEffect: ".concat(options.id, " - ").concat(options.functionId || 'default', " - ").concat(useEffectTiming));
128
- return function() {
129
- prefetchInstance === null || prefetchInstance === void 0 ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
41
+ const [prefetchState, setPrefetchState] = useState(state);
42
+ const prefetchInstance = MFDataPrefetch.getInstance(mfScope);
43
+ useEffect(()=>{
44
+ const useEffectTiming = performance.now();
45
+ logger.info(`3. Start Execute UseEffect: ${options.id} - ${options.functionId || 'default'} - ${useEffectTiming}`);
46
+ return ()=>{
47
+ prefetchInstance == null ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
130
48
  };
131
49
  }, []);
132
- var refreshExecutor = function(refetchParams) {
133
- var refetchOptions = _object_spread({}, options);
50
+ const refreshExecutor = (refetchParams)=>{
51
+ const refetchOptions = _extends({}, options);
134
52
  if (refetchParams) {
135
53
  refetchOptions.refetchParams = refetchParams;
136
54
  }
137
- prefetchInstance === null || prefetchInstance === void 0 ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
138
- var newVal = prefetch(refetchOptions);
139
- var newState;
55
+ prefetchInstance == null ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
56
+ const newVal = prefetch(refetchOptions);
57
+ let newState;
140
58
  if (deferId) {
141
- if (_instanceof(newVal, Promise)) {
142
- newState = newVal.then(function(deferredData) {
143
- return deferredData.data[deferId];
144
- });
59
+ if (newVal instanceof Promise) {
60
+ newState = newVal.then((deferredData)=>deferredData.data[deferId]);
145
61
  } else {
146
62
  newState = newVal.data[deferId];
147
63
  }
@@ -3,16 +3,12 @@
3
3
  var runtime = require('@module-federation/runtime');
4
4
  var sdk = require('@module-federation/sdk');
5
5
 
6
- var getScope = function() {
6
+ const getScope = ()=>{
7
7
  return runtime.getInstance().options.name;
8
8
  };
9
- var getPrefetchId = function(id) {
10
- return sdk.encodeName("".concat(id, "/").concat(sdk.MFPrefetchCommon.identifier));
11
- };
12
- var compatGetPrefetchId = function(id) {
13
- return sdk.encodeName("".concat(id, "/VmokPrefetch"));
14
- };
15
- var getSignalFromManifest = function(remoteSnapshot) {
9
+ const getPrefetchId = (id)=>sdk.encodeName(`${id}/${sdk.MFPrefetchCommon.identifier}`);
10
+ const compatGetPrefetchId = (id)=>sdk.encodeName(`${id}/VmokPrefetch`);
11
+ const getSignalFromManifest = (remoteSnapshot)=>{
16
12
  if (!remoteSnapshot) {
17
13
  return false;
18
14
  }
@@ -1,16 +1,12 @@
1
1
  import { getInstance } from '@module-federation/runtime';
2
2
  import { encodeName, MFPrefetchCommon } from '@module-federation/sdk';
3
3
 
4
- var getScope = function() {
4
+ const getScope = ()=>{
5
5
  return getInstance().options.name;
6
6
  };
7
- var getPrefetchId = function(id) {
8
- return encodeName("".concat(id, "/").concat(MFPrefetchCommon.identifier));
9
- };
10
- var compatGetPrefetchId = function(id) {
11
- return encodeName("".concat(id, "/VmokPrefetch"));
12
- };
13
- var getSignalFromManifest = function(remoteSnapshot) {
7
+ const getPrefetchId = (id)=>encodeName(`${id}/${MFPrefetchCommon.identifier}`);
8
+ const compatGetPrefetchId = (id)=>encodeName(`${id}/VmokPrefetch`);
9
+ const getSignalFromManifest = (remoteSnapshot)=>{
14
10
  if (!remoteSnapshot) {
15
11
  return false;
16
12
  }
@@ -23,4 +19,4 @@ var getSignalFromManifest = function(remoteSnapshot) {
23
19
  return true;
24
20
  };
25
21
 
26
- export { getSignalFromManifest as a, getScope as b, compatGetPrefetchId as c, getPrefetchId as g };
22
+ export { getSignalFromManifest as a, getPrefetchId as b, compatGetPrefetchId as c, getScope as g };
@@ -1,26 +1,24 @@
1
1
  'use strict';
2
2
 
3
- var sharedStrategy = function() {
4
- return {
3
+ const sharedStrategy = ()=>({
5
4
  name: 'shared-strategy',
6
- beforeInit: function beforeInit(args) {
7
- var userOptions = args.userOptions;
8
- var shared = userOptions.shared;
5
+ beforeInit (args) {
6
+ const { userOptions } = args;
7
+ const shared = userOptions.shared;
9
8
  if (shared) {
10
- Object.keys(shared).forEach(function(sharedKey) {
11
- var sharedConfigs = shared[sharedKey];
12
- var arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
9
+ Object.keys(shared).forEach((sharedKey)=>{
10
+ const sharedConfigs = shared[sharedKey];
11
+ const arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
13
12
  sharedConfigs
14
13
  ];
15
- arraySharedConfigs.forEach(function(s) {
14
+ arraySharedConfigs.forEach((s)=>{
16
15
  s.strategy = 'loaded-first';
17
16
  });
18
17
  });
19
- console.warn("[Module Federation Data Prefetch]: Your shared strategy is set to 'loaded-first', this is a necessary condition for data prefetch");
18
+ console.warn(`[Module Federation Data Prefetch]: Your shared strategy is set to 'loaded-first', this is a necessary condition for data prefetch`);
20
19
  }
21
20
  return args;
22
21
  }
23
- };
24
- };
22
+ });
25
23
 
26
24
  module.exports = sharedStrategy;
@@ -0,0 +1,2 @@
1
+ export * from "./src/shared/index";
2
+ export { default } from "./src/shared/index";
@@ -1,24 +1,22 @@
1
- var sharedStrategy = function() {
2
- return {
1
+ const sharedStrategy = ()=>({
3
2
  name: 'shared-strategy',
4
- beforeInit: function beforeInit(args) {
5
- var userOptions = args.userOptions;
6
- var shared = userOptions.shared;
3
+ beforeInit (args) {
4
+ const { userOptions } = args;
5
+ const shared = userOptions.shared;
7
6
  if (shared) {
8
- Object.keys(shared).forEach(function(sharedKey) {
9
- var sharedConfigs = shared[sharedKey];
10
- var arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
7
+ Object.keys(shared).forEach((sharedKey)=>{
8
+ const sharedConfigs = shared[sharedKey];
9
+ const arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
11
10
  sharedConfigs
12
11
  ];
13
- arraySharedConfigs.forEach(function(s) {
12
+ arraySharedConfigs.forEach((s)=>{
14
13
  s.strategy = 'loaded-first';
15
14
  });
16
15
  });
17
- console.warn("[Module Federation Data Prefetch]: Your shared strategy is set to 'loaded-first', this is a necessary condition for data prefetch");
16
+ console.warn(`[Module Federation Data Prefetch]: Your shared strategy is set to 'loaded-first', this is a necessary condition for data prefetch`);
18
17
  }
19
18
  return args;
20
19
  }
21
- };
22
- };
20
+ });
23
21
 
24
22
  export { sharedStrategy as default };
@@ -1,35 +1,26 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var prefetch$1 = require('./prefetch.cjs.js');
6
4
  var runtimeUtils = require('./runtime-utils.cjs.js');
7
5
  require('@module-federation/runtime');
8
6
  require('@module-federation/sdk');
9
7
 
10
- function _instanceof(left, right) {
11
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
12
- return !!right[Symbol.hasInstance](left);
13
- } else {
14
- return left instanceof right;
15
- }
16
- }
17
8
  function prefetch(options) {
18
- var id = options.id, _options_functionId = options.functionId, functionId = _options_functionId === void 0 ? 'default' : _options_functionId;
19
- var mfScope = runtimeUtils.getScope();
20
- var prefetchInstance = prefetch$1.MFDataPrefetch.getInstance(mfScope) || new prefetch$1.MFDataPrefetch({
9
+ const { id, functionId = 'default' } = options;
10
+ const mfScope = runtimeUtils.getScope();
11
+ const prefetchInstance = prefetch$1.MFDataPrefetch.getInstance(mfScope) || new prefetch$1.MFDataPrefetch({
21
12
  name: mfScope
22
13
  });
23
- var res = prefetchInstance.getProjectExports();
24
- if (_instanceof(res, Promise)) {
25
- var promise = res.then(function() {
26
- var result = prefetchInstance.prefetch(options);
14
+ const res = prefetchInstance.getProjectExports();
15
+ if (res instanceof Promise) {
16
+ const promise = res.then(()=>{
17
+ const result = prefetchInstance.prefetch(options);
27
18
  prefetchInstance.memorize(id + functionId, result);
28
19
  return result;
29
20
  });
30
21
  return promise;
31
22
  } else {
32
- var result = prefetchInstance.prefetch(options);
23
+ const result = prefetchInstance.prefetch(options);
33
24
  prefetchInstance.memorize(id + functionId, result);
34
25
  return result;
35
26
  }
@@ -0,0 +1 @@
1
+ export * from "./src/universal/index";
@@ -1,31 +1,24 @@
1
1
  import { M as MFDataPrefetch } from './prefetch.esm.js';
2
- import { b as getScope } from './runtime-utils.esm.js';
2
+ import { g as getScope } from './runtime-utils.esm.js';
3
3
  import '@module-federation/runtime';
4
4
  import '@module-federation/sdk';
5
5
 
6
- function _instanceof(left, right) {
7
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
8
- return !!right[Symbol.hasInstance](left);
9
- } else {
10
- return left instanceof right;
11
- }
12
- }
13
6
  function prefetch(options) {
14
- var id = options.id, _options_functionId = options.functionId, functionId = _options_functionId === void 0 ? 'default' : _options_functionId;
15
- var mfScope = getScope();
16
- var prefetchInstance = MFDataPrefetch.getInstance(mfScope) || new MFDataPrefetch({
7
+ const { id, functionId = 'default' } = options;
8
+ const mfScope = getScope();
9
+ const prefetchInstance = MFDataPrefetch.getInstance(mfScope) || new MFDataPrefetch({
17
10
  name: mfScope
18
11
  });
19
- var res = prefetchInstance.getProjectExports();
20
- if (_instanceof(res, Promise)) {
21
- var promise = res.then(function() {
22
- var result = prefetchInstance.prefetch(options);
12
+ const res = prefetchInstance.getProjectExports();
13
+ if (res instanceof Promise) {
14
+ const promise = res.then(()=>{
15
+ const result = prefetchInstance.prefetch(options);
23
16
  prefetchInstance.memorize(id + functionId, result);
24
17
  return result;
25
18
  });
26
19
  return promise;
27
20
  } else {
28
- var result = prefetchInstance.prefetch(options);
21
+ const result = prefetchInstance.prefetch(options);
29
22
  prefetchInstance.memorize(id + functionId, result);
30
23
  return result;
31
24
  }
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.6.7",
4
+ "version": "0.6.9",
5
5
  "author": "nieyan <nyqykk@foxmail.com>",
6
6
  "homepage": "https://github.com/module-federation/core",
7
7
  "license": "MIT",
@@ -78,8 +78,8 @@
78
78
  "jest": "^29.7.0",
79
79
  "jest-environment-jsdom": "^29.7.0",
80
80
  "minimist": "^1.2.8",
81
- "react": "^18.2.0",
82
- "react-dom": "^18.2.0",
81
+ "react": "^18.3.1",
82
+ "react-dom": "^18.3.1",
83
83
  "react-router": "^6.21.3",
84
84
  "react-test-renderer": "^18.2.0",
85
85
  "ts-jest": "29.0.1",
@@ -88,8 +88,8 @@
88
88
  },
89
89
  "dependencies": {
90
90
  "fs-extra": "9.1.0",
91
- "@module-federation/sdk": "0.6.7",
92
- "@module-federation/runtime": "0.6.7"
91
+ "@module-federation/runtime": "0.6.9",
92
+ "@module-federation/sdk": "0.6.9"
93
93
  },
94
94
  "scripts": {
95
95
  "dev": "cross-env WATCH=true tsup",
package/project.json CHANGED
@@ -3,6 +3,7 @@
3
3
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
4
  "sourceRoot": "packages/data-prefetch/src",
5
5
  "projectType": "library",
6
+ "tags": ["type:pkg"],
6
7
  "targets": {
7
8
  "build": {
8
9
  "executor": "@nx/rollup:rollup",
@@ -58,6 +59,5 @@
58
59
  ]
59
60
  }
60
61
  }
61
- },
62
- "tags": ["type:pkg"]
62
+ }
63
63
  }
package/rollup.config.js CHANGED
@@ -20,6 +20,27 @@ module.exports = (rollupConfig, _projectOptions) => {
20
20
  plugin: 'packages/data-prefetch/src/plugin.ts',
21
21
  shared: 'packages/data-prefetch/src/shared/index.ts',
22
22
  };
23
- rollupConfig.external = [/@module-federation/];
23
+
24
+ if (Array.isArray(rollupConfig.output)) {
25
+ rollupConfig.output = rollupConfig.output.map((c) => ({
26
+ ...c,
27
+ manualChunks: (id) => {
28
+ if (id.includes('@swc/helpers')) {
29
+ return 'polyfills';
30
+ }
31
+ },
32
+ }));
33
+ } else {
34
+ rollupConfig.output = {
35
+ ...rollupConfig.output,
36
+ manualChunks: (id) => {
37
+ if (id.includes('@swc/helpers')) {
38
+ return 'polyfills';
39
+ }
40
+ },
41
+ };
42
+ }
43
+
44
+ // rollupConfig.external = [/@module-federation/];
24
45
  return rollupConfig;
25
46
  };