@module-federation/data-prefetch 0.17.0 → 0.18.0

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.
@@ -2,11 +2,9 @@
2
2
 
3
3
  var path = require('path');
4
4
 
5
- // no used now
6
5
  const attribute = 'id';
7
6
  const hookId = 'usePrefetch';
8
7
  const importPackage = '@module-federation/data-prefetch/react';
9
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
10
8
  var babel = ((babel, options)=>{
11
9
  const t = babel.types;
12
10
  let shouldHandle = false;
@@ -18,19 +16,16 @@ var babel = ((babel, options)=>{
18
16
  const exposesKey = Object.keys(exposes);
19
17
  const processedExposes = exposesKey.map((expose)=>({
20
18
  key: expose.replace('.', ''),
21
- value: path.resolve(// @ts-ignore
22
- typeof exposes[expose] === 'string' ? exposes[expose] : exposes[expose].import)
19
+ value: path.resolve(typeof exposes[expose] === 'string' ? exposes[expose] : exposes[expose].import)
23
20
  }));
24
21
  return {
25
22
  visitor: {
26
- ImportDeclaration (nodePath, // biome-ignore lint/suspicious/noExplicitAny: <explanation>
27
- state) {
23
+ ImportDeclaration (nodePath, state) {
28
24
  const source = nodePath.node.source.value;
29
25
  const { specifiers } = nodePath.node;
30
26
  const { filename } = state.file.opts;
31
27
  if (source === importPackage) {
32
- shouldHandle = specifiers.some((specifier)=>specifier.imported && specifier.imported.name === hookId && processedExposes.find(// biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
33
- (expose)=>expose.value === filename && (scope = expose.key)));
28
+ shouldHandle = specifiers.some((specifier)=>specifier.imported && specifier.imported.name === hookId && processedExposes.find((expose)=>expose.value === filename && (scope = expose.key)));
34
29
  }
35
30
  },
36
31
  CallExpression (nodePath) {
package/dist/babel.esm.js CHANGED
@@ -1,10 +1,8 @@
1
1
  import path from 'path';
2
2
 
3
- // no used now
4
3
  const attribute = 'id';
5
4
  const hookId = 'usePrefetch';
6
5
  const importPackage = '@module-federation/data-prefetch/react';
7
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
8
6
  var babel = ((babel, options)=>{
9
7
  const t = babel.types;
10
8
  let shouldHandle = false;
@@ -16,19 +14,16 @@ var babel = ((babel, options)=>{
16
14
  const exposesKey = Object.keys(exposes);
17
15
  const processedExposes = exposesKey.map((expose)=>({
18
16
  key: expose.replace('.', ''),
19
- value: path.resolve(// @ts-ignore
20
- typeof exposes[expose] === 'string' ? exposes[expose] : exposes[expose].import)
17
+ value: path.resolve(typeof exposes[expose] === 'string' ? exposes[expose] : exposes[expose].import)
21
18
  }));
22
19
  return {
23
20
  visitor: {
24
- ImportDeclaration (nodePath, // biome-ignore lint/suspicious/noExplicitAny: <explanation>
25
- state) {
21
+ ImportDeclaration (nodePath, state) {
26
22
  const source = nodePath.node.source.value;
27
23
  const { specifiers } = nodePath.node;
28
24
  const { filename } = state.file.opts;
29
25
  if (source === importPackage) {
30
- shouldHandle = specifiers.some((specifier)=>specifier.imported && specifier.imported.name === hookId && processedExposes.find(// biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
31
- (expose)=>expose.value === filename && (scope = expose.key)));
26
+ shouldHandle = specifiers.some((specifier)=>specifier.imported && specifier.imported.name === hookId && processedExposes.find((expose)=>expose.value === filename && (scope = expose.key)));
32
27
  }
33
28
  },
34
29
  CallExpression (nodePath) {
package/dist/cli.cjs.cjs CHANGED
@@ -38,9 +38,8 @@ function getFederationGlobalScope(runtimeGlobals) {
38
38
  return `${runtimeGlobals.require || '__webpack_require__'}.federation`;
39
39
  }
40
40
  class PrefetchPlugin {
41
- // eslint-disable-next-line max-lines-per-function
42
41
  apply(compiler) {
43
- var _this_options_runtimePlugins;
42
+ var _a;
44
43
  const { name, exposes } = this.options;
45
44
  if (!exposes) {
46
45
  return;
@@ -53,7 +52,7 @@ class PrefetchPlugin {
53
52
  this.options.runtimePlugins = [];
54
53
  }
55
54
  const runtimePath = path.resolve(__dirname, './plugin.esm.js');
56
- if (!((_this_options_runtimePlugins = this.options.runtimePlugins) == null ? void 0 : _this_options_runtimePlugins.includes(runtimePath))) {
55
+ if (!((_a = this.options.runtimePlugins) === null || _a === void 0 ? void 0 : _a.includes(runtimePath))) {
57
56
  this.options.runtimePlugins.push(runtimePath);
58
57
  }
59
58
  if (this.options.shareStrategy !== constant.SHARED_STRATEGY) {
@@ -71,7 +70,6 @@ class PrefetchPlugin {
71
70
  const exposeAlias = Object.keys(exposes);
72
71
  exposeAlias.forEach((alias)=>{
73
72
  let exposePath;
74
- // @ts-ignore
75
73
  const exposeValue = exposes[alias];
76
74
  if (typeof exposeValue === 'string') {
77
75
  exposePath = exposeValue;
package/dist/cli.esm.js CHANGED
@@ -36,9 +36,8 @@ function getFederationGlobalScope(runtimeGlobals) {
36
36
  return `${runtimeGlobals.require || '__webpack_require__'}.federation`;
37
37
  }
38
38
  class PrefetchPlugin {
39
- // eslint-disable-next-line max-lines-per-function
40
39
  apply(compiler) {
41
- var _this_options_runtimePlugins;
40
+ var _a;
42
41
  const { name, exposes } = this.options;
43
42
  if (!exposes) {
44
43
  return;
@@ -51,7 +50,7 @@ class PrefetchPlugin {
51
50
  this.options.runtimePlugins = [];
52
51
  }
53
52
  const runtimePath = path.resolve(__dirname, './plugin.esm.js');
54
- if (!((_this_options_runtimePlugins = this.options.runtimePlugins) == null ? void 0 : _this_options_runtimePlugins.includes(runtimePath))) {
53
+ if (!((_a = this.options.runtimePlugins) === null || _a === void 0 ? void 0 : _a.includes(runtimePath))) {
55
54
  this.options.runtimePlugins.push(runtimePath);
56
55
  }
57
56
  if (this.options.shareStrategy !== SHARED_STRATEGY) {
@@ -69,7 +68,6 @@ class PrefetchPlugin {
69
68
  const exposeAlias = Object.keys(exposes);
70
69
  exposeAlias.forEach((alias)=>{
71
70
  let exposePath;
72
- // @ts-ignore
73
71
  const exposeValue = exposes[alias];
74
72
  if (typeof exposeValue === 'string') {
75
73
  exposePath = exposeValue;
@@ -2,15 +2,14 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var prefetch = require('./prefetch.cjs.cjs');
5
6
  var sdk = require('@module-federation/sdk');
6
7
  var runtimeUtils = require('./runtime-utils.cjs.cjs');
7
- var prefetch = require('./prefetch.cjs.cjs');
8
8
  var index = require('./index.cjs2.cjs');
9
9
  var constant = require('./constant.cjs.cjs');
10
10
 
11
11
  const loadingArray = [];
12
12
  let sharedFlag = constant.SHARED_STRATEGY;
13
- // eslint-disable-next-line max-lines-per-function
14
13
  const prefetchPlugin = ()=>({
15
14
  name: 'data-prefetch-runtime-plugin',
16
15
  initContainer (options) {
@@ -32,37 +31,35 @@ const prefetchPlugin = ()=>({
32
31
  }
33
32
  const instance = prefetch.MFDataPrefetch.getInstance(name) || new prefetch.MFDataPrefetch(prefetchOptions);
34
33
  let prefetchUrl;
35
- // @ts-expect-error
36
34
  if (snapshot.prefetchEntry) {
37
- // @ts-expect-error
38
35
  prefetchUrl = sdk.getResourceUrl(snapshot, snapshot.prefetchEntry);
39
36
  }
40
37
  const exist = loadingArray.find((loading)=>loading.id === id);
41
38
  if (exist) {
42
39
  return options;
43
40
  }
44
- const promise = instance.loadEntry(prefetchUrl).then(async ()=>{
45
- const projectExports = instance.getProjectExports();
46
- if (projectExports instanceof Promise) {
47
- await projectExports;
48
- }
49
- return Promise.resolve().then(()=>{
50
- const exports = instance.getExposeExports(id);
51
- index.logger.info(`1. Start Prefetch initContainer: ${id} - ${performance.now()}`);
52
- const result = Object.keys(exports).map((k)=>{
53
- const value = instance.prefetch({
54
- id,
55
- functionId: k
41
+ const promise = instance.loadEntry(prefetchUrl).then(()=>prefetch.__awaiter(this, void 0, void 0, function*() {
42
+ const projectExports = instance.getProjectExports();
43
+ if (projectExports instanceof Promise) {
44
+ yield projectExports;
45
+ }
46
+ return Promise.resolve().then(()=>{
47
+ const exports = instance.getExposeExports(id);
48
+ index.logger.info(`1. Start Prefetch initContainer: ${id} - ${performance.now()}`);
49
+ const result = Object.keys(exports).map((k)=>{
50
+ const value = instance.prefetch({
51
+ id,
52
+ functionId: k
53
+ });
54
+ const functionId = k;
55
+ return {
56
+ value,
57
+ functionId
58
+ };
56
59
  });
57
- const functionId = k;
58
- return {
59
- value,
60
- functionId
61
- };
60
+ return result;
62
61
  });
63
- return result;
64
- });
65
- });
62
+ }));
66
63
  loadingArray.push({
67
64
  id,
68
65
  promise
@@ -92,64 +89,63 @@ const prefetchPlugin = ()=>({
92
89
  }
93
90
  const instance = prefetch.MFDataPrefetch.getInstance(name) || new prefetch.MFDataPrefetch(prefetchOptions);
94
91
  let prefetchUrl;
95
- // @ts-expect-error
96
92
  if (snapshot.prefetchEntry) {
97
- // @ts-expect-error
98
93
  prefetchUrl = sdk.getResourceUrl(snapshot, snapshot.prefetchEntry);
99
94
  }
100
95
  const index$1 = loadingArray.findIndex((loading)=>loading.id === id);
101
- // clear cache
102
96
  if (index$1 !== -1) {
103
97
  loadingArray.splice(index$1, 1);
104
98
  }
105
- const promise = instance.loadEntry(prefetchUrl).then(async ()=>{
106
- const projectExports = instance.getProjectExports();
107
- if (projectExports instanceof Promise) {
108
- await projectExports;
109
- }
110
- return Promise.resolve().then(()=>{
111
- const exports = instance.getExposeExports(id);
112
- index.logger.info(`1. Start Prefetch afterResolve: ${id} - ${performance.now()}`);
113
- const result = Object.keys(exports).map((k)=>{
114
- const value = instance.prefetch({
115
- id,
116
- functionId: k
99
+ const promise = instance.loadEntry(prefetchUrl).then(()=>prefetch.__awaiter(this, void 0, void 0, function*() {
100
+ const projectExports = instance.getProjectExports();
101
+ if (projectExports instanceof Promise) {
102
+ yield projectExports;
103
+ }
104
+ return Promise.resolve().then(()=>{
105
+ const exports = instance.getExposeExports(id);
106
+ index.logger.info(`1. Start Prefetch afterResolve: ${id} - ${performance.now()}`);
107
+ const result = Object.keys(exports).map((k)=>{
108
+ const value = instance.prefetch({
109
+ id,
110
+ functionId: k
111
+ });
112
+ const functionId = k;
113
+ return {
114
+ value,
115
+ functionId
116
+ };
117
117
  });
118
- const functionId = k;
119
- return {
120
- value,
121
- functionId
122
- };
118
+ return result;
123
119
  });
124
- return result;
125
- });
126
- });
120
+ }));
127
121
  loadingArray.push({
128
122
  id,
129
123
  promise
130
124
  });
131
125
  return options;
132
126
  },
133
- async onLoad (options) {
134
- var _loadingArray_find;
135
- const { remote, id } = options;
136
- const { name } = remote;
137
- const promise = (_loadingArray_find = loadingArray.find((loading)=>loading.id === id)) == null ? void 0 : _loadingArray_find.promise;
138
- if (promise) {
139
- const prefetch$1 = await promise;
140
- const prefetchValue = prefetch$1.map((result)=>result.value);
141
- await Promise.all(prefetchValue);
142
- const instance = prefetch.MFDataPrefetch.getInstance(name);
143
- prefetch$1.forEach((result)=>{
144
- const { value, functionId } = result;
145
- instance.memorize(id + functionId, value);
146
- });
147
- }
148
- return options;
127
+ onLoad (options) {
128
+ return prefetch.__awaiter(this, void 0, void 0, function*() {
129
+ var _a;
130
+ const { remote, id } = options;
131
+ const { name } = remote;
132
+ const promise = (_a = loadingArray.find((loading)=>loading.id === id)) === null || _a === void 0 ? void 0 : _a.promise;
133
+ if (promise) {
134
+ const prefetch$1 = yield promise;
135
+ const prefetchValue = prefetch$1.map((result)=>result.value);
136
+ yield Promise.all(prefetchValue);
137
+ const instance = prefetch.MFDataPrefetch.getInstance(name);
138
+ prefetch$1.forEach((result)=>{
139
+ const { value, functionId } = result;
140
+ instance.memorize(id + functionId, value);
141
+ });
142
+ }
143
+ return options;
144
+ });
149
145
  },
150
146
  beforeLoadShare (options) {
151
147
  const shareInfo = options.shareInfo;
152
- sharedFlag = (shareInfo == null ? void 0 : shareInfo.strategy) || sharedFlag;
148
+ sharedFlag = (shareInfo === null || shareInfo === void 0 ? void 0 : shareInfo.strategy) || sharedFlag;
153
149
  return options;
154
150
  }
155
151
  });
@@ -1,12 +1,11 @@
1
+ import { _ as __awaiter, M as MFDataPrefetch } from './prefetch.esm.js';
1
2
  import { getResourceUrl } from '@module-federation/sdk';
2
3
  import { a as getSignalFromManifest } from './runtime-utils.esm.js';
3
- import { M as MFDataPrefetch } from './prefetch.esm.js';
4
4
  import { l as logger } from './index.esm2.js';
5
5
  import { S as SHARED_STRATEGY } from './constant.esm.js';
6
6
 
7
7
  const loadingArray = [];
8
8
  let sharedFlag = SHARED_STRATEGY;
9
- // eslint-disable-next-line max-lines-per-function
10
9
  const prefetchPlugin = ()=>({
11
10
  name: 'data-prefetch-runtime-plugin',
12
11
  initContainer (options) {
@@ -28,37 +27,35 @@ const prefetchPlugin = ()=>({
28
27
  }
29
28
  const instance = MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions);
30
29
  let prefetchUrl;
31
- // @ts-expect-error
32
30
  if (snapshot.prefetchEntry) {
33
- // @ts-expect-error
34
31
  prefetchUrl = getResourceUrl(snapshot, snapshot.prefetchEntry);
35
32
  }
36
33
  const exist = loadingArray.find((loading)=>loading.id === id);
37
34
  if (exist) {
38
35
  return options;
39
36
  }
40
- const promise = instance.loadEntry(prefetchUrl).then(async ()=>{
41
- const projectExports = instance.getProjectExports();
42
- if (projectExports instanceof Promise) {
43
- await projectExports;
44
- }
45
- return Promise.resolve().then(()=>{
46
- const exports = instance.getExposeExports(id);
47
- logger.info(`1. Start Prefetch initContainer: ${id} - ${performance.now()}`);
48
- const result = Object.keys(exports).map((k)=>{
49
- const value = instance.prefetch({
50
- id,
51
- functionId: k
37
+ const promise = instance.loadEntry(prefetchUrl).then(()=>__awaiter(this, void 0, void 0, function*() {
38
+ const projectExports = instance.getProjectExports();
39
+ if (projectExports instanceof Promise) {
40
+ yield projectExports;
41
+ }
42
+ return Promise.resolve().then(()=>{
43
+ const exports = instance.getExposeExports(id);
44
+ logger.info(`1. Start Prefetch initContainer: ${id} - ${performance.now()}`);
45
+ const result = Object.keys(exports).map((k)=>{
46
+ const value = instance.prefetch({
47
+ id,
48
+ functionId: k
49
+ });
50
+ const functionId = k;
51
+ return {
52
+ value,
53
+ functionId
54
+ };
52
55
  });
53
- const functionId = k;
54
- return {
55
- value,
56
- functionId
57
- };
56
+ return result;
58
57
  });
59
- return result;
60
- });
61
- });
58
+ }));
62
59
  loadingArray.push({
63
60
  id,
64
61
  promise
@@ -88,64 +85,63 @@ const prefetchPlugin = ()=>({
88
85
  }
89
86
  const instance = MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions);
90
87
  let prefetchUrl;
91
- // @ts-expect-error
92
88
  if (snapshot.prefetchEntry) {
93
- // @ts-expect-error
94
89
  prefetchUrl = getResourceUrl(snapshot, snapshot.prefetchEntry);
95
90
  }
96
91
  const index = loadingArray.findIndex((loading)=>loading.id === id);
97
- // clear cache
98
92
  if (index !== -1) {
99
93
  loadingArray.splice(index, 1);
100
94
  }
101
- const promise = instance.loadEntry(prefetchUrl).then(async ()=>{
102
- const projectExports = instance.getProjectExports();
103
- if (projectExports instanceof Promise) {
104
- await projectExports;
105
- }
106
- return Promise.resolve().then(()=>{
107
- const exports = instance.getExposeExports(id);
108
- logger.info(`1. Start Prefetch afterResolve: ${id} - ${performance.now()}`);
109
- const result = Object.keys(exports).map((k)=>{
110
- const value = instance.prefetch({
111
- id,
112
- functionId: k
95
+ const promise = instance.loadEntry(prefetchUrl).then(()=>__awaiter(this, void 0, void 0, function*() {
96
+ const projectExports = instance.getProjectExports();
97
+ if (projectExports instanceof Promise) {
98
+ yield projectExports;
99
+ }
100
+ return Promise.resolve().then(()=>{
101
+ const exports = instance.getExposeExports(id);
102
+ logger.info(`1. Start Prefetch afterResolve: ${id} - ${performance.now()}`);
103
+ const result = Object.keys(exports).map((k)=>{
104
+ const value = instance.prefetch({
105
+ id,
106
+ functionId: k
107
+ });
108
+ const functionId = k;
109
+ return {
110
+ value,
111
+ functionId
112
+ };
113
113
  });
114
- const functionId = k;
115
- return {
116
- value,
117
- functionId
118
- };
114
+ return result;
119
115
  });
120
- return result;
121
- });
122
- });
116
+ }));
123
117
  loadingArray.push({
124
118
  id,
125
119
  promise
126
120
  });
127
121
  return options;
128
122
  },
129
- async onLoad (options) {
130
- var _loadingArray_find;
131
- const { remote, id } = options;
132
- const { name } = remote;
133
- const promise = (_loadingArray_find = loadingArray.find((loading)=>loading.id === id)) == null ? void 0 : _loadingArray_find.promise;
134
- if (promise) {
135
- const prefetch = await promise;
136
- const prefetchValue = prefetch.map((result)=>result.value);
137
- await Promise.all(prefetchValue);
138
- const instance = MFDataPrefetch.getInstance(name);
139
- prefetch.forEach((result)=>{
140
- const { value, functionId } = result;
141
- instance.memorize(id + functionId, value);
142
- });
143
- }
144
- return options;
123
+ onLoad (options) {
124
+ return __awaiter(this, void 0, void 0, function*() {
125
+ var _a;
126
+ const { remote, id } = options;
127
+ const { name } = remote;
128
+ const promise = (_a = loadingArray.find((loading)=>loading.id === id)) === null || _a === void 0 ? void 0 : _a.promise;
129
+ if (promise) {
130
+ const prefetch = yield promise;
131
+ const prefetchValue = prefetch.map((result)=>result.value);
132
+ yield Promise.all(prefetchValue);
133
+ const instance = MFDataPrefetch.getInstance(name);
134
+ prefetch.forEach((result)=>{
135
+ const { value, functionId } = result;
136
+ instance.memorize(id + functionId, value);
137
+ });
138
+ }
139
+ return options;
140
+ });
145
141
  },
146
142
  beforeLoadShare (options) {
147
143
  const shareInfo = options.shareInfo;
148
- sharedFlag = (shareInfo == null ? void 0 : shareInfo.strategy) || sharedFlag;
144
+ sharedFlag = (shareInfo === null || shareInfo === void 0 ? void 0 : shareInfo.strategy) || sharedFlag;
149
145
  return options;
150
146
  }
151
147
  });
@@ -4,12 +4,62 @@ var runtime = require('@module-federation/runtime');
4
4
  var sdk = require('@module-federation/sdk');
5
5
  var runtimeUtils = require('./runtime-utils.cjs.cjs');
6
6
 
7
- var // @ts-ignore init global variable for test
8
- _globalThis, _globalThis___FEDERATION__;
9
- var ___FEDERATION__;
10
- (___FEDERATION__ = (_globalThis = globalThis).__FEDERATION__) != null ? ___FEDERATION__ : _globalThis.__FEDERATION__ = {};
11
- var ___PREFETCH__;
12
- (___PREFETCH__ = (_globalThis___FEDERATION__ = globalThis.__FEDERATION__).__PREFETCH__) != null ? ___PREFETCH__ : _globalThis___FEDERATION__.__PREFETCH__ = {
7
+ /******************************************************************************
8
+ Copyright (c) Microsoft Corporation.
9
+
10
+ Permission to use, copy, modify, and/or distribute this software for any
11
+ purpose with or without fee is hereby granted.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
+ PERFORMANCE OF THIS SOFTWARE.
20
+ ***************************************************************************** */ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */ function _instanceof(left, right) {
21
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
22
+ return !!right[Symbol.hasInstance](left);
23
+ } else {
24
+ return left instanceof right;
25
+ }
26
+ }
27
+ function __awaiter(thisArg, _arguments, P, generator) {
28
+ function adopt(value) {
29
+ return _instanceof(value, P) ? value : new P(function(resolve) {
30
+ resolve(value);
31
+ });
32
+ }
33
+ return new (P || (P = Promise))(function(resolve, reject) {
34
+ function fulfilled(value) {
35
+ try {
36
+ step(generator.next(value));
37
+ } catch (e) {
38
+ reject(e);
39
+ }
40
+ }
41
+ function rejected(value) {
42
+ try {
43
+ step(generator["throw"](value));
44
+ } catch (e) {
45
+ reject(e);
46
+ }
47
+ }
48
+ function step(result) {
49
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
50
+ }
51
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
52
+ });
53
+ }
54
+ typeof SuppressedError === "function" ? SuppressedError : function _SuppressedError(error, suppressed, message) {
55
+ var e = new Error(message);
56
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
57
+ };
58
+
59
+ var _a, _b;
60
+ var _c;
61
+ (_a = globalThis.__FEDERATION__) !== null && _a !== void 0 ? _a : globalThis.__FEDERATION__ = {};
62
+ (_b = (_c = globalThis.__FEDERATION__).__PREFETCH__) !== null && _b !== void 0 ? _b : _c.__PREFETCH__ = {
13
63
  entryLoading: {},
14
64
  instance: new Map(),
15
65
  __PREFETCH_EXPORTS__: {}
@@ -21,36 +71,36 @@ class MFDataPrefetch {
21
71
  static getInstance(id) {
22
72
  return globalThis.__FEDERATION__.__PREFETCH__.instance.get(id);
23
73
  }
24
- async loadEntry(entry) {
25
- const { name, remoteSnapshot, remote, origin } = this._options;
26
- if (entry) {
27
- const { buildVersion, globalName } = remoteSnapshot;
28
- const uniqueKey = globalName || `${name}:${buildVersion}`;
29
- if (!this.global.entryLoading[uniqueKey]) {
30
- this.global.entryLoading[uniqueKey] = sdk.loadScript(entry, {});
74
+ loadEntry(entry) {
75
+ return __awaiter(this, void 0, void 0, function*() {
76
+ const { name, remoteSnapshot, remote, origin } = this._options;
77
+ if (entry) {
78
+ const { buildVersion, globalName } = remoteSnapshot;
79
+ const uniqueKey = globalName || `${name}:${buildVersion}`;
80
+ if (!this.global.entryLoading[uniqueKey]) {
81
+ this.global.entryLoading[uniqueKey] = sdk.loadScript(entry, {});
82
+ }
83
+ return this.global.entryLoading[uniqueKey];
84
+ } else {
85
+ const remoteInfo = runtime.getRemoteInfo(remote);
86
+ const module = origin.moduleCache.get(remoteInfo.name);
87
+ return runtime.getRemoteEntry({
88
+ origin: origin,
89
+ remoteInfo,
90
+ remoteEntryExports: module ? module.remoteEntryExports : undefined
91
+ });
31
92
  }
32
- return this.global.entryLoading[uniqueKey];
33
- } else {
34
- const remoteInfo = runtime.getRemoteInfo(remote);
35
- const module = origin.moduleCache.get(remoteInfo.name);
36
- return runtime.getRemoteEntry({
37
- origin: origin,
38
- remoteInfo,
39
- remoteEntryExports: module ? module.remoteEntryExports : undefined
40
- });
41
- }
93
+ });
42
94
  }
43
95
  getProjectExports() {
44
- var _globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__;
96
+ var _a;
45
97
  if (Object.keys(this._exports).length > 0) {
46
98
  return this._exports;
47
99
  }
48
100
  const { name } = this._options;
49
- const exportsPromiseFn = (_globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__ = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) == null ? void 0 : _globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__[name];
101
+ const exportsPromiseFn = (_a = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) === null || _a === void 0 ? void 0 : _a[name];
50
102
  const exportsPromise = typeof exportsPromiseFn === 'function' ? exportsPromiseFn() : exportsPromiseFn;
51
103
  const resolve = exportsPromise.then((exports = {})=>{
52
- // Match prefetch based on the function name suffix so that other capabilities can be expanded later.
53
- // Not all functions should be directly identified as prefetch functions
54
104
  const memory = {};
55
105
  Object.keys(exports).forEach((key)=>{
56
106
  memory[key] = {};
@@ -140,3 +190,4 @@ class MFDataPrefetch {
140
190
  }
141
191
 
142
192
  exports.MFDataPrefetch = MFDataPrefetch;
193
+ exports.__awaiter = __awaiter;
@@ -2,12 +2,62 @@ import { getRemoteInfo, getRemoteEntry } from '@module-federation/runtime';
2
2
  import { loadScript } from '@module-federation/sdk';
3
3
  import { b as getPrefetchId, c as compatGetPrefetchId } from './runtime-utils.esm.js';
4
4
 
5
- var // @ts-ignore init global variable for test
6
- _globalThis, _globalThis___FEDERATION__;
7
- var ___FEDERATION__;
8
- (___FEDERATION__ = (_globalThis = globalThis).__FEDERATION__) != null ? ___FEDERATION__ : _globalThis.__FEDERATION__ = {};
9
- var ___PREFETCH__;
10
- (___PREFETCH__ = (_globalThis___FEDERATION__ = globalThis.__FEDERATION__).__PREFETCH__) != null ? ___PREFETCH__ : _globalThis___FEDERATION__.__PREFETCH__ = {
5
+ /******************************************************************************
6
+ Copyright (c) Microsoft Corporation.
7
+
8
+ Permission to use, copy, modify, and/or distribute this software for any
9
+ purpose with or without fee is hereby granted.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ ***************************************************************************** */ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */ function _instanceof(left, right) {
19
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
20
+ return !!right[Symbol.hasInstance](left);
21
+ } else {
22
+ return left instanceof right;
23
+ }
24
+ }
25
+ function __awaiter(thisArg, _arguments, P, generator) {
26
+ function adopt(value) {
27
+ return _instanceof(value, P) ? value : new P(function(resolve) {
28
+ resolve(value);
29
+ });
30
+ }
31
+ return new (P || (P = Promise))(function(resolve, reject) {
32
+ function fulfilled(value) {
33
+ try {
34
+ step(generator.next(value));
35
+ } catch (e) {
36
+ reject(e);
37
+ }
38
+ }
39
+ function rejected(value) {
40
+ try {
41
+ step(generator["throw"](value));
42
+ } catch (e) {
43
+ reject(e);
44
+ }
45
+ }
46
+ function step(result) {
47
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
48
+ }
49
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
50
+ });
51
+ }
52
+ typeof SuppressedError === "function" ? SuppressedError : function _SuppressedError(error, suppressed, message) {
53
+ var e = new Error(message);
54
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
55
+ };
56
+
57
+ var _a, _b;
58
+ var _c;
59
+ (_a = globalThis.__FEDERATION__) !== null && _a !== void 0 ? _a : globalThis.__FEDERATION__ = {};
60
+ (_b = (_c = globalThis.__FEDERATION__).__PREFETCH__) !== null && _b !== void 0 ? _b : _c.__PREFETCH__ = {
11
61
  entryLoading: {},
12
62
  instance: new Map(),
13
63
  __PREFETCH_EXPORTS__: {}
@@ -19,36 +69,36 @@ class MFDataPrefetch {
19
69
  static getInstance(id) {
20
70
  return globalThis.__FEDERATION__.__PREFETCH__.instance.get(id);
21
71
  }
22
- async loadEntry(entry) {
23
- const { name, remoteSnapshot, remote, origin } = this._options;
24
- if (entry) {
25
- const { buildVersion, globalName } = remoteSnapshot;
26
- const uniqueKey = globalName || `${name}:${buildVersion}`;
27
- if (!this.global.entryLoading[uniqueKey]) {
28
- this.global.entryLoading[uniqueKey] = loadScript(entry, {});
72
+ loadEntry(entry) {
73
+ return __awaiter(this, void 0, void 0, function*() {
74
+ const { name, remoteSnapshot, remote, origin } = this._options;
75
+ if (entry) {
76
+ const { buildVersion, globalName } = remoteSnapshot;
77
+ const uniqueKey = globalName || `${name}:${buildVersion}`;
78
+ if (!this.global.entryLoading[uniqueKey]) {
79
+ this.global.entryLoading[uniqueKey] = loadScript(entry, {});
80
+ }
81
+ return this.global.entryLoading[uniqueKey];
82
+ } else {
83
+ const remoteInfo = getRemoteInfo(remote);
84
+ const module = origin.moduleCache.get(remoteInfo.name);
85
+ return getRemoteEntry({
86
+ origin: origin,
87
+ remoteInfo,
88
+ remoteEntryExports: module ? module.remoteEntryExports : undefined
89
+ });
29
90
  }
30
- return this.global.entryLoading[uniqueKey];
31
- } else {
32
- const remoteInfo = getRemoteInfo(remote);
33
- const module = origin.moduleCache.get(remoteInfo.name);
34
- return getRemoteEntry({
35
- origin: origin,
36
- remoteInfo,
37
- remoteEntryExports: module ? module.remoteEntryExports : undefined
38
- });
39
- }
91
+ });
40
92
  }
41
93
  getProjectExports() {
42
- var _globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__;
94
+ var _a;
43
95
  if (Object.keys(this._exports).length > 0) {
44
96
  return this._exports;
45
97
  }
46
98
  const { name } = this._options;
47
- const exportsPromiseFn = (_globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__ = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) == null ? void 0 : _globalThis___FEDERATION_____PREFETCH_____PREFETCH_EXPORTS__[name];
99
+ const exportsPromiseFn = (_a = globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__) === null || _a === void 0 ? void 0 : _a[name];
48
100
  const exportsPromise = typeof exportsPromiseFn === 'function' ? exportsPromiseFn() : exportsPromiseFn;
49
101
  const resolve = exportsPromise.then((exports = {})=>{
50
- // Match prefetch based on the function name suffix so that other capabilities can be expanded later.
51
- // Not all functions should be directly identified as prefetch functions
52
102
  const memory = {};
53
103
  Object.keys(exports).forEach((key)=>{
54
104
  memory[key] = {};
@@ -137,4 +187,4 @@ class MFDataPrefetch {
137
187
  }
138
188
  }
139
189
 
140
- export { MFDataPrefetch as M };
190
+ export { MFDataPrefetch as M, __awaiter as _ };
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var polyfills = require('./polyfills.cjs.cjs');
4
3
  var react = require('react');
5
4
  var index = require('./index.cjs2.cjs');
6
5
  var prefetch = require('./prefetch.cjs.cjs');
@@ -44,15 +43,15 @@ const usePrefetch = (options)=>{
44
43
  const useEffectTiming = performance.now();
45
44
  index.logger.info(`3. Start Execute UseEffect: ${options.id} - ${options.functionId || 'default'} - ${useEffectTiming}`);
46
45
  return ()=>{
47
- prefetchInstance == null ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
46
+ prefetchInstance === null || prefetchInstance === void 0 ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
48
47
  };
49
48
  }, []);
50
49
  const refreshExecutor = (refetchParams)=>{
51
- const refetchOptions = polyfills._extends({}, options);
50
+ const refetchOptions = Object.assign({}, options);
52
51
  if (refetchParams) {
53
52
  refetchOptions.refetchParams = refetchParams;
54
53
  }
55
- prefetchInstance == null ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
54
+ prefetchInstance === null || prefetchInstance === void 0 ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
56
55
  const newVal = universal.prefetch(refetchOptions);
57
56
  let newState;
58
57
  if (deferId) {
package/dist/react.esm.js CHANGED
@@ -1,4 +1,3 @@
1
- import { _ as _extends } from './polyfills.esm.js';
2
1
  import { useRef, useEffect, useState } from 'react';
3
2
  import { l as logger } from './index.esm2.js';
4
3
  import { M as MFDataPrefetch } from './prefetch.esm.js';
@@ -42,15 +41,15 @@ const usePrefetch = (options)=>{
42
41
  const useEffectTiming = performance.now();
43
42
  logger.info(`3. Start Execute UseEffect: ${options.id} - ${options.functionId || 'default'} - ${useEffectTiming}`);
44
43
  return ()=>{
45
- prefetchInstance == null ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
44
+ prefetchInstance === null || prefetchInstance === void 0 ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
46
45
  };
47
46
  }, []);
48
47
  const refreshExecutor = (refetchParams)=>{
49
- const refetchOptions = _extends({}, options);
48
+ const refetchOptions = Object.assign({}, options);
50
49
  if (refetchParams) {
51
50
  refetchOptions.refetchParams = refetchParams;
52
51
  }
53
- prefetchInstance == null ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
52
+ prefetchInstance === null || prefetchInstance === void 0 ? void 0 : prefetchInstance.markOutdate(prefetchInfo, true);
54
53
  const newVal = prefetch(refetchOptions);
55
54
  let newState;
56
55
  if (deferId) {
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.17.0",
4
+ "version": "0.18.0",
5
5
  "type": "module",
6
6
  "author": "nieyan <nyqykk@foxmail.com>",
7
7
  "homepage": "https://github.com/module-federation/core",
@@ -21,27 +21,27 @@
21
21
  ],
22
22
  "exports": {
23
23
  ".": {
24
- "types": "./dist/index.cjs.d.ts",
24
+ "types": "./dist/index.d.ts",
25
25
  "import": "./dist/index.esm.js",
26
26
  "require": "./dist/index.cjs.cjs"
27
27
  },
28
28
  "./react": {
29
- "types": "./dist/react.cjs.d.ts",
29
+ "types": "./dist/react.d.ts",
30
30
  "import": "./dist/react.esm.js",
31
31
  "require": "./dist/react.cjs.cjs"
32
32
  },
33
33
  "./cli": {
34
- "types": "./dist/cli.cjs.d.ts",
34
+ "types": "./dist/cli.d.ts",
35
35
  "import": "./dist/cli.esm.js",
36
36
  "require": "./dist/cli.cjs.cjs"
37
37
  },
38
38
  "./babel-plugin": {
39
- "types": "./dist/babel.cjs.d.ts",
39
+ "types": "./dist/babel.d.ts",
40
40
  "import": "./dist/babel.esm.js",
41
41
  "require": "./dist/babel.cjs.cjs"
42
42
  },
43
43
  "./universal": {
44
- "types": "./dist/universal.cjs.d.ts",
44
+ "types": "./dist/universal.d.ts",
45
45
  "import": "./dist/universal.esm.js",
46
46
  "require": "./dist/universal.cjs.cjs"
47
47
  }
@@ -49,19 +49,19 @@
49
49
  "typesVersions": {
50
50
  "*": {
51
51
  ".": [
52
- "./dist/index.cjs.d.ts"
52
+ "./dist/index.d.ts"
53
53
  ],
54
54
  "react": [
55
- "./dist/react.cjs.d.ts"
55
+ "./dist/react.d.ts"
56
56
  ],
57
57
  "cli": [
58
- "./dist/cli.cjs.d.ts"
58
+ "./dist/cli.d.ts"
59
59
  ],
60
60
  "universal": [
61
- "./dist/universal.cjs.d.ts"
61
+ "./dist/universal.d.ts"
62
62
  ],
63
63
  "babel-plugin": [
64
- "./dist/babel.cjs.d.ts"
64
+ "./dist/babel.d.ts"
65
65
  ]
66
66
  }
67
67
  },
@@ -89,8 +89,8 @@
89
89
  },
90
90
  "dependencies": {
91
91
  "fs-extra": "9.1.0",
92
- "@module-federation/runtime": "0.17.0",
93
- "@module-federation/sdk": "0.17.0"
92
+ "@module-federation/runtime": "0.18.0",
93
+ "@module-federation/sdk": "0.18.0"
94
94
  },
95
95
  "scripts": {
96
96
  "test": "jest"
@@ -1,14 +0,0 @@
1
- 'use strict';
2
-
3
- function _extends() {
4
- _extends = Object.assign || function assign(target) {
5
- for(var i = 1; i < arguments.length; i++){
6
- var source = arguments[i];
7
- for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
8
- }
9
- return target;
10
- };
11
- return _extends.apply(this, arguments);
12
- }
13
-
14
- exports._extends = _extends;
@@ -1,12 +0,0 @@
1
- function _extends() {
2
- _extends = Object.assign || function assign(target) {
3
- for(var i = 1; i < arguments.length; i++){
4
- var source = arguments[i];
5
- for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
6
- }
7
- return target;
8
- };
9
- return _extends.apply(this, arguments);
10
- }
11
-
12
- export { _extends as _ };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes