@module-federation/data-prefetch 0.0.0-next-20241008193232 → 0.0.0-next-20241009072306

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,14 @@
1
1
  # @module-federation/data-prefetch
2
2
 
3
- ## 0.0.0-next-20241008193232
3
+ ## 0.0.0-next-20241009072306
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - @module-federation/runtime@0.0.0-next-20241008193232
8
- - @module-federation/sdk@0.0.0-next-20241008193232
7
+ - 5364c07: fix(data-prefetch): apply DataPrefetchPlugin on demand
8
+ - Updated dependencies [b704f30]
9
+ - Updated dependencies [5364c07]
10
+ - @module-federation/runtime@0.0.0-next-20241009072306
11
+ - @module-federation/sdk@0.0.0-next-20241009072306
9
12
 
10
13
  ## 0.6.9
11
14
 
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ const SHARED_STRATEGY = 'loaded-first';
4
+
5
+ exports.SHARED_STRATEGY = SHARED_STRATEGY;
@@ -0,0 +1,3 @@
1
+ const SHARED_STRATEGY = 'loaded-first';
2
+
3
+ export { SHARED_STRATEGY as S };
package/dist/index.cjs.js CHANGED
@@ -6,6 +6,7 @@ require('@module-federation/runtime');
6
6
  require('@module-federation/sdk');
7
7
  require('./runtime-utils.cjs.js');
8
8
  require('./index.cjs2.js');
9
+ require('./constant.cjs.js');
9
10
 
10
11
 
11
12
 
package/dist/index.esm.js CHANGED
@@ -4,3 +4,4 @@ import '@module-federation/runtime';
4
4
  import '@module-federation/sdk';
5
5
  import './runtime-utils.esm.js';
6
6
  import './index.esm2.js';
7
+ import './constant.esm.js';
@@ -6,11 +6,11 @@ var sdk = require('@module-federation/sdk');
6
6
  var runtimeUtils = require('./runtime-utils.cjs.js');
7
7
  var prefetch = require('./prefetch.cjs.js');
8
8
  var index = require('./index.cjs2.js');
9
+ var constant = require('./constant.cjs.js');
9
10
  require('@module-federation/runtime');
10
11
 
11
12
  const loadingArray = [];
12
- const strategy = 'loaded-first';
13
- let sharedFlag = strategy;
13
+ let sharedFlag = constant.SHARED_STRATEGY;
14
14
  // eslint-disable-next-line max-lines-per-function
15
15
  const prefetchPlugin = ()=>({
16
16
  name: 'data-prefetch-runtime-plugin',
@@ -28,7 +28,7 @@ const prefetchPlugin = ()=>({
28
28
  if (!signal) {
29
29
  return options;
30
30
  }
31
- if (sharedFlag !== strategy) {
31
+ if (sharedFlag !== constant.SHARED_STRATEGY) {
32
32
  throw new Error(`[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`);
33
33
  }
34
34
  const instance = prefetch.MFDataPrefetch.getInstance(name) || new prefetch.MFDataPrefetch(prefetchOptions);
@@ -88,7 +88,7 @@ const prefetchPlugin = ()=>({
88
88
  if (!inited) {
89
89
  return options;
90
90
  }
91
- if (sharedFlag !== strategy) {
91
+ if (sharedFlag !== constant.SHARED_STRATEGY) {
92
92
  throw new Error(`[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`);
93
93
  }
94
94
  const instance = prefetch.MFDataPrefetch.getInstance(name) || new prefetch.MFDataPrefetch(prefetchOptions);
@@ -2,11 +2,11 @@ import { getResourceUrl } from '@module-federation/sdk';
2
2
  import { a as getSignalFromManifest } from './runtime-utils.esm.js';
3
3
  import { M as MFDataPrefetch } from './prefetch.esm.js';
4
4
  import { l as logger } from './index.esm2.js';
5
+ import { S as SHARED_STRATEGY } from './constant.esm.js';
5
6
  import '@module-federation/runtime';
6
7
 
7
8
  const loadingArray = [];
8
- const strategy = 'loaded-first';
9
- let sharedFlag = strategy;
9
+ let sharedFlag = SHARED_STRATEGY;
10
10
  // eslint-disable-next-line max-lines-per-function
11
11
  const prefetchPlugin = ()=>({
12
12
  name: 'data-prefetch-runtime-plugin',
@@ -24,7 +24,7 @@ const prefetchPlugin = ()=>({
24
24
  if (!signal) {
25
25
  return options;
26
26
  }
27
- if (sharedFlag !== strategy) {
27
+ if (sharedFlag !== SHARED_STRATEGY) {
28
28
  throw new Error(`[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`);
29
29
  }
30
30
  const instance = MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions);
@@ -84,7 +84,7 @@ const prefetchPlugin = ()=>({
84
84
  if (!inited) {
85
85
  return options;
86
86
  }
87
- if (sharedFlag !== strategy) {
87
+ if (sharedFlag !== SHARED_STRATEGY) {
88
88
  throw new Error(`[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`);
89
89
  }
90
90
  const instance = MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions);
@@ -1,20 +1,12 @@
1
1
  'use strict';
2
2
 
3
+ var constant = require('./constant.cjs.js');
4
+
3
5
  const sharedStrategy = ()=>({
4
6
  name: 'shared-strategy',
5
7
  beforeInit (args) {
6
- const { userOptions } = args;
7
- const shared = userOptions.shared;
8
- if (shared) {
9
- Object.keys(shared).forEach((sharedKey)=>{
10
- const sharedConfigs = shared[sharedKey];
11
- const arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
12
- sharedConfigs
13
- ];
14
- arraySharedConfigs.forEach((s)=>{
15
- s.strategy = 'loaded-first';
16
- });
17
- });
8
+ if (args.options.shareStrategy == constant.SHARED_STRATEGY) {
9
+ args.options.shareStrategy = 'loaded-first';
18
10
  console.warn(`[Module Federation Data Prefetch]: Your shared strategy is set to 'loaded-first', this is a necessary condition for data prefetch`);
19
11
  }
20
12
  return args;
@@ -1,18 +1,10 @@
1
+ import { S as SHARED_STRATEGY } from './constant.esm.js';
2
+
1
3
  const sharedStrategy = ()=>({
2
4
  name: 'shared-strategy',
3
5
  beforeInit (args) {
4
- const { userOptions } = args;
5
- const shared = userOptions.shared;
6
- if (shared) {
7
- Object.keys(shared).forEach((sharedKey)=>{
8
- const sharedConfigs = shared[sharedKey];
9
- const arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
10
- sharedConfigs
11
- ];
12
- arraySharedConfigs.forEach((s)=>{
13
- s.strategy = 'loaded-first';
14
- });
15
- });
6
+ if (args.options.shareStrategy == SHARED_STRATEGY) {
7
+ args.options.shareStrategy = 'loaded-first';
16
8
  console.warn(`[Module Federation Data Prefetch]: Your shared strategy is set to 'loaded-first', this is a necessary condition for data prefetch`);
17
9
  }
18
10
  return args;
@@ -0,0 +1 @@
1
+ export declare const SHARED_STRATEGY = "loaded-first";
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-20241008193232",
4
+ "version": "0.0.0-next-20241009072306",
5
5
  "author": "nieyan <nyqykk@foxmail.com>",
6
6
  "homepage": "https://github.com/module-federation/core",
7
7
  "license": "MIT",
@@ -88,8 +88,8 @@
88
88
  },
89
89
  "dependencies": {
90
90
  "fs-extra": "9.1.0",
91
- "@module-federation/runtime": "0.0.0-next-20241008193232",
92
- "@module-federation/sdk": "0.0.0-next-20241008193232"
91
+ "@module-federation/runtime": "0.0.0-next-20241009072306",
92
+ "@module-federation/sdk": "0.0.0-next-20241009072306"
93
93
  },
94
94
  "scripts": {
95
95
  "dev": "cross-env WATCH=true tsup",
@@ -0,0 +1 @@
1
+ export const SHARED_STRATEGY = 'loaded-first';
package/src/plugin.ts CHANGED
@@ -4,6 +4,7 @@ import { ModuleInfo, getResourceUrl } from '@module-federation/sdk';
4
4
  import { getSignalFromManifest } from './common/runtime-utils';
5
5
  import { MFDataPrefetch } from './prefetch';
6
6
  import logger from './logger';
7
+ import { SHARED_STRATEGY } from './constant';
7
8
 
8
9
  interface Loading {
9
10
  id: string;
@@ -15,8 +16,7 @@ interface Loading {
15
16
  >;
16
17
  }
17
18
  const loadingArray: Array<Loading> = [];
18
- const strategy = 'loaded-first';
19
- let sharedFlag = strategy;
19
+ let sharedFlag = SHARED_STRATEGY;
20
20
  // eslint-disable-next-line max-lines-per-function
21
21
  export const prefetchPlugin = (): FederationRuntimePlugin => ({
22
22
  name: 'data-prefetch-runtime-plugin',
@@ -35,7 +35,7 @@ export const prefetchPlugin = (): FederationRuntimePlugin => ({
35
35
  if (!signal) {
36
36
  return options;
37
37
  }
38
- if (sharedFlag !== strategy) {
38
+ if (sharedFlag !== SHARED_STRATEGY) {
39
39
  throw new Error(
40
40
  `[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`,
41
41
  );
@@ -109,7 +109,7 @@ export const prefetchPlugin = (): FederationRuntimePlugin => ({
109
109
  return options;
110
110
  }
111
111
 
112
- if (sharedFlag !== strategy) {
112
+ if (sharedFlag !== SHARED_STRATEGY) {
113
113
  throw new Error(
114
114
  `[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`,
115
115
  );
@@ -1,20 +1,12 @@
1
1
  import type { FederationRuntimePlugin } from '@module-federation/runtime';
2
+ import { SHARED_STRATEGY } from '../constant';
2
3
 
3
4
  const sharedStrategy: () => FederationRuntimePlugin = () => ({
4
5
  name: 'shared-strategy',
5
6
  beforeInit(args) {
6
7
  const { userOptions } = args;
7
- const shared = userOptions.shared;
8
- if (shared) {
9
- Object.keys(shared).forEach((sharedKey) => {
10
- const sharedConfigs = shared[sharedKey];
11
- const arraySharedConfigs = Array.isArray(sharedConfigs)
12
- ? sharedConfigs
13
- : [sharedConfigs];
14
- arraySharedConfigs.forEach((s) => {
15
- s.strategy = 'loaded-first';
16
- });
17
- });
8
+ if (args.options.shareStrategy! == SHARED_STRATEGY) {
9
+ args.options.shareStrategy = 'loaded-first';
18
10
  console.warn(
19
11
  `[Module Federation Data Prefetch]: Your shared strategy is set to 'loaded-first', this is a necessary condition for data prefetch`,
20
12
  );