@module-federation/data-prefetch 0.0.0-next-20241009075733 → 0.0.0-next-20241009081924

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,15 +1,12 @@
1
1
  # @module-federation/data-prefetch
2
2
 
3
- ## 0.0.0-next-20241009075733
3
+ ## 0.0.0-next-20241009081924
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - 5364c07: fix(data-prefetch): apply DataPrefetchPlugin on demand
8
- - 026c308: fix(data-prefetch): set sharedStrategy in build options instead of using runtime plugin
9
7
  - Updated dependencies [b704f30]
10
- - Updated dependencies [5364c07]
11
- - @module-federation/runtime@0.0.0-next-20241009075733
12
- - @module-federation/sdk@0.0.0-next-20241009075733
8
+ - @module-federation/runtime@0.0.0-next-20241009081924
9
+ - @module-federation/sdk@0.0.0-next-20241009081924
13
10
 
14
11
  ## 0.6.9
15
12
 
package/dist/cli.cjs.js CHANGED
@@ -5,7 +5,6 @@ var fs = require('fs-extra');
5
5
  var sdk = require('@module-federation/sdk');
6
6
  var normalizeWebpackPath = require('@module-federation/sdk/normalize-webpack-path');
7
7
  var runtimeUtils = require('./runtime-utils.cjs.js');
8
- var constant = require('./constant.cjs.js');
9
8
  require('@module-federation/runtime');
10
9
 
11
10
  const TEMP_DIR = '.mf';
@@ -41,7 +40,7 @@ function getFederationGlobalScope(runtimeGlobals) {
41
40
  class PrefetchPlugin {
42
41
  // eslint-disable-next-line max-lines-per-function
43
42
  apply(compiler) {
44
- var _this_options_runtimePlugins;
43
+ var _this_options_runtimePlugins, _this_options_runtimePlugins1;
45
44
  const { name, exposes } = this.options;
46
45
  if (!exposes) {
47
46
  return;
@@ -54,12 +53,12 @@ class PrefetchPlugin {
54
53
  this.options.runtimePlugins = [];
55
54
  }
56
55
  const runtimePath = path.resolve(__dirname, './plugin.esm.js');
56
+ const sharedPath = path.resolve(__dirname, './shared.esm.js');
57
57
  if (!((_this_options_runtimePlugins = this.options.runtimePlugins) == null ? void 0 : _this_options_runtimePlugins.includes(runtimePath))) {
58
58
  this.options.runtimePlugins.push(runtimePath);
59
59
  }
60
- if (this.options.shareStrategy !== constant.SHARED_STRATEGY) {
61
- this.options.shareStrategy = constant.SHARED_STRATEGY;
62
- console.warn(`[Module Federation Data Prefetch]: Your shared strategy is set to '${constant.SHARED_STRATEGY}', this is a necessary condition for data prefetch`);
60
+ if (!((_this_options_runtimePlugins1 = this.options.runtimePlugins) == null ? void 0 : _this_options_runtimePlugins1.includes(sharedPath))) {
61
+ this.options.runtimePlugins.push(sharedPath);
63
62
  }
64
63
  const encodedName = sdk.encodeName(name);
65
64
  const asyncEntryPath = path.resolve(compiler.options.context, `node_modules/${TEMP_DIR}/${encodedName}/bootstrap.js`);
package/dist/cli.esm.js CHANGED
@@ -3,7 +3,6 @@ import fs from 'fs-extra';
3
3
  import { encodeName, MFPrefetchCommon } from '@module-federation/sdk';
4
4
  import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';
5
5
  import { b as getPrefetchId } from './runtime-utils.esm.js';
6
- import { S as SHARED_STRATEGY } from './constant.esm.js';
7
6
  import '@module-federation/runtime';
8
7
 
9
8
  const TEMP_DIR = '.mf';
@@ -39,7 +38,7 @@ function getFederationGlobalScope(runtimeGlobals) {
39
38
  class PrefetchPlugin {
40
39
  // eslint-disable-next-line max-lines-per-function
41
40
  apply(compiler) {
42
- var _this_options_runtimePlugins;
41
+ var _this_options_runtimePlugins, _this_options_runtimePlugins1;
43
42
  const { name, exposes } = this.options;
44
43
  if (!exposes) {
45
44
  return;
@@ -52,12 +51,12 @@ class PrefetchPlugin {
52
51
  this.options.runtimePlugins = [];
53
52
  }
54
53
  const runtimePath = path.resolve(__dirname, './plugin.esm.js');
54
+ const sharedPath = path.resolve(__dirname, './shared.esm.js');
55
55
  if (!((_this_options_runtimePlugins = this.options.runtimePlugins) == null ? void 0 : _this_options_runtimePlugins.includes(runtimePath))) {
56
56
  this.options.runtimePlugins.push(runtimePath);
57
57
  }
58
- if (this.options.shareStrategy !== SHARED_STRATEGY) {
59
- this.options.shareStrategy = SHARED_STRATEGY;
60
- console.warn(`[Module Federation Data Prefetch]: Your shared strategy is set to '${SHARED_STRATEGY}', this is a necessary condition for data prefetch`);
58
+ if (!((_this_options_runtimePlugins1 = this.options.runtimePlugins) == null ? void 0 : _this_options_runtimePlugins1.includes(sharedPath))) {
59
+ this.options.runtimePlugins.push(sharedPath);
61
60
  }
62
61
  const encodedName = encodeName(name);
63
62
  const asyncEntryPath = path.resolve(compiler.options.context, `node_modules/${TEMP_DIR}/${encodedName}/bootstrap.js`);
package/dist/index.cjs.js CHANGED
@@ -6,7 +6,6 @@ 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');
10
9
 
11
10
 
12
11
 
package/dist/index.esm.js CHANGED
@@ -4,4 +4,3 @@ 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';
package/dist/package.json CHANGED
@@ -6,6 +6,8 @@
6
6
  "homepage": "https://github.com/module-federation/core",
7
7
  "license": "MIT",
8
8
  "scripts": {
9
+ "dev": "cross-env WATCH=true tsup",
10
+ "build": "rm -rf dist && tsup",
9
11
  "test": "jest"
10
12
  },
11
13
  "publishConfig": {
@@ -36,6 +38,11 @@
36
38
  "import": "./dist/universal.esm.js",
37
39
  "require": "./dist/universal.cjs.js",
38
40
  "types": "./dist/universal.cjs.d.ts"
41
+ },
42
+ "./shared": {
43
+ "import": "./dist/shared.esm.js",
44
+ "require": "./dist/shared.cjs.js",
45
+ "types": "./dist/shared/.cjs.d.ts"
39
46
  }
40
47
  },
41
48
  "typesVersions": {
@@ -52,6 +59,9 @@
52
59
  "universal": [
53
60
  "./dist/universal.cjs.d.ts"
54
61
  ],
62
+ "shared": [
63
+ "./dist/shared.cjs.d.ts"
64
+ ],
55
65
  "babel-plugin": [
56
66
  "./dist/babel.cjs.d.ts"
57
67
  ]
@@ -69,6 +79,7 @@
69
79
  "@types/jest": "^29.5.11",
70
80
  "@types/node": "^17.0.45",
71
81
  "@types/react": "~18.0.38",
82
+ "esbuild-plugin-replace": "^1.4.0",
72
83
  "jest": "^29.7.0",
73
84
  "jest-environment-jsdom": "^29.7.0",
74
85
  "minimist": "^1.2.8",
@@ -77,6 +88,7 @@
77
88
  "react-router": "^6.21.3",
78
89
  "react-test-renderer": "^18.2.0",
79
90
  "ts-jest": "29.0.1",
91
+ "tsup": "6.2.0",
80
92
  "webpack": "5.75.0"
81
93
  },
82
94
  "dependencies": {
@@ -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');
10
9
  require('@module-federation/runtime');
11
10
 
12
11
  const loadingArray = [];
13
- let sharedFlag = constant.SHARED_STRATEGY;
12
+ const strategy = 'loaded-first';
13
+ let sharedFlag = 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 !== constant.SHARED_STRATEGY) {
31
+ if (sharedFlag !== 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 !== constant.SHARED_STRATEGY) {
91
+ if (sharedFlag !== 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';
6
5
  import '@module-federation/runtime';
7
6
 
8
7
  const loadingArray = [];
9
- let sharedFlag = SHARED_STRATEGY;
8
+ const strategy = 'loaded-first';
9
+ let sharedFlag = 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 !== SHARED_STRATEGY) {
27
+ if (sharedFlag !== 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 !== SHARED_STRATEGY) {
87
+ if (sharedFlag !== 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);
@@ -0,0 +1,2 @@
1
+ export * from "./src/shared/index";
2
+ export { default } from "./src/shared/index";
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ const sharedStrategy = ()=>({
4
+ name: 'shared-strategy',
5
+ 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
+ });
18
+ console.warn(`[Module Federation Data Prefetch]: Your shared strategy is set to 'loaded-first', this is a necessary condition for data prefetch`);
19
+ }
20
+ return args;
21
+ }
22
+ });
23
+
24
+ module.exports = sharedStrategy;
@@ -0,0 +1,2 @@
1
+ export * from "./src/shared/index";
2
+ export { default } from "./src/shared/index";
@@ -0,0 +1,22 @@
1
+ const sharedStrategy = ()=>({
2
+ name: 'shared-strategy',
3
+ 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
+ });
16
+ console.warn(`[Module Federation Data Prefetch]: Your shared strategy is set to 'loaded-first', this is a necessary condition for data prefetch`);
17
+ }
18
+ return args;
19
+ }
20
+ });
21
+
22
+ export { sharedStrategy as default };
@@ -0,0 +1,3 @@
1
+ import type { FederationRuntimePlugin } from '@module-federation/runtime';
2
+ declare const sharedStrategy: () => FederationRuntimePlugin;
3
+ export default sharedStrategy;
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-20241009075733",
4
+ "version": "0.0.0-next-20241009081924",
5
5
  "author": "nieyan <nyqykk@foxmail.com>",
6
6
  "homepage": "https://github.com/module-federation/core",
7
7
  "license": "MIT",
@@ -33,6 +33,11 @@
33
33
  "import": "./dist/universal.esm.js",
34
34
  "require": "./dist/universal.cjs.js",
35
35
  "types": "./dist/universal.cjs.d.ts"
36
+ },
37
+ "./shared": {
38
+ "import": "./dist/shared.esm.js",
39
+ "require": "./dist/shared.cjs.js",
40
+ "types": "./dist/shared/.cjs.d.ts"
36
41
  }
37
42
  },
38
43
  "typesVersions": {
@@ -49,6 +54,9 @@
49
54
  "universal": [
50
55
  "./dist/universal.cjs.d.ts"
51
56
  ],
57
+ "shared": [
58
+ "./dist/shared.cjs.d.ts"
59
+ ],
52
60
  "babel-plugin": [
53
61
  "./dist/babel.cjs.d.ts"
54
62
  ]
@@ -66,6 +74,7 @@
66
74
  "@types/jest": "^29.5.11",
67
75
  "@types/node": "^17.0.45",
68
76
  "@types/react": "~18.0.38",
77
+ "esbuild-plugin-replace": "^1.4.0",
69
78
  "jest": "^29.7.0",
70
79
  "jest-environment-jsdom": "^29.7.0",
71
80
  "minimist": "^1.2.8",
@@ -74,14 +83,17 @@
74
83
  "react-router": "^6.21.3",
75
84
  "react-test-renderer": "^18.2.0",
76
85
  "ts-jest": "29.0.1",
86
+ "tsup": "6.2.0",
77
87
  "webpack": "5.75.0"
78
88
  },
79
89
  "dependencies": {
80
90
  "fs-extra": "9.1.0",
81
- "@module-federation/runtime": "0.0.0-next-20241009075733",
82
- "@module-federation/sdk": "0.0.0-next-20241009075733"
91
+ "@module-federation/runtime": "0.0.0-next-20241009081924",
92
+ "@module-federation/sdk": "0.0.0-next-20241009081924"
83
93
  },
84
94
  "scripts": {
95
+ "dev": "cross-env WATCH=true tsup",
96
+ "build": "rm -rf dist && tsup",
85
97
  "test": "jest"
86
98
  }
87
99
  }
package/rollup.config.js CHANGED
@@ -18,6 +18,7 @@ module.exports = (rollupConfig, _projectOptions) => {
18
18
  babel: 'packages/data-prefetch/src/cli/babel.ts',
19
19
  universal: 'packages/data-prefetch/src/universal/index.ts',
20
20
  plugin: 'packages/data-prefetch/src/plugin.ts',
21
+ shared: 'packages/data-prefetch/src/shared/index.ts',
21
22
  };
22
23
 
23
24
  if (Array.isArray(rollupConfig.output)) {
package/src/cli/index.ts CHANGED
@@ -12,7 +12,6 @@ import type { Compiler, WebpackPluginInstance } from 'webpack';
12
12
  import { TEMP_DIR } from '../common/constant';
13
13
  import { fileExistsWithCaseSync, fixPrefetchPath } from '../common/node-utils';
14
14
  import { getPrefetchId } from '../common/runtime-utils';
15
- import { SHARED_STRATEGY } from '../constant';
16
15
 
17
16
  const { RuntimeGlobals, Template } = require(
18
17
  normalizeWebpackPath('webpack'),
@@ -49,14 +48,12 @@ export class PrefetchPlugin implements WebpackPluginInstance {
49
48
  }
50
49
 
51
50
  const runtimePath = path.resolve(__dirname, './plugin.esm.js');
51
+ const sharedPath = path.resolve(__dirname, './shared.esm.js');
52
52
  if (!this.options.runtimePlugins?.includes(runtimePath)) {
53
53
  this.options.runtimePlugins!.push(runtimePath);
54
54
  }
55
- if (this.options.shareStrategy !== SHARED_STRATEGY) {
56
- this.options.shareStrategy = SHARED_STRATEGY;
57
- console.warn(
58
- `[Module Federation Data Prefetch]: Your shared strategy is set to '${SHARED_STRATEGY}', this is a necessary condition for data prefetch`,
59
- );
55
+ if (!this.options.runtimePlugins?.includes(sharedPath)) {
56
+ this.options.runtimePlugins!.push(sharedPath);
60
57
  }
61
58
 
62
59
  const encodedName = encodeName(name as string);
package/src/plugin.ts CHANGED
@@ -4,7 +4,6 @@ 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';
8
7
 
9
8
  interface Loading {
10
9
  id: string;
@@ -16,7 +15,8 @@ interface Loading {
16
15
  >;
17
16
  }
18
17
  const loadingArray: Array<Loading> = [];
19
- let sharedFlag = SHARED_STRATEGY;
18
+ const strategy = 'loaded-first';
19
+ let sharedFlag = 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 !== SHARED_STRATEGY) {
38
+ if (sharedFlag !== 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 !== SHARED_STRATEGY) {
112
+ if (sharedFlag !== 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
  );
@@ -0,0 +1,26 @@
1
+ import type { FederationRuntimePlugin } from '@module-federation/runtime';
2
+
3
+ const sharedStrategy: () => FederationRuntimePlugin = () => ({
4
+ name: 'shared-strategy',
5
+ 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)
12
+ ? sharedConfigs
13
+ : [sharedConfigs];
14
+ arraySharedConfigs.forEach((s) => {
15
+ s.strategy = 'loaded-first';
16
+ });
17
+ });
18
+ console.warn(
19
+ `[Module Federation Data Prefetch]: Your shared strategy is set to 'loaded-first', this is a necessary condition for data prefetch`,
20
+ );
21
+ }
22
+ return args;
23
+ },
24
+ });
25
+
26
+ export default sharedStrategy;
package/tsup.config.ts ADDED
@@ -0,0 +1,35 @@
1
+ import { replace } from 'esbuild-plugin-replace';
2
+ import minimist from 'minimist';
3
+ import type { Options } from 'tsup';
4
+
5
+ import pkg from './package.json';
6
+
7
+ const args = minimist(process.argv.slice(2));
8
+ const watch = process.env.WATCH;
9
+ const sourceMap = args.sourcemap || args.s;
10
+
11
+ export const tsup: Options = {
12
+ entry: [
13
+ 'src/index.ts',
14
+ 'src/react/index.ts',
15
+ 'src/cli/index.ts',
16
+ 'src/cli/babel.ts',
17
+ 'src/universal/index.ts',
18
+ 'src/plugin.ts',
19
+ 'src/shared/index.ts',
20
+ ],
21
+ sourcemap: sourceMap,
22
+ clean: true,
23
+ dts: true,
24
+ watch: watch ? 'src/' : false,
25
+ format: ['esm', 'cjs'],
26
+ legacyOutput: true,
27
+ esbuildPlugins: [
28
+ replace({
29
+ __VERSION__: `'${pkg.version}'`,
30
+ __DEV__:
31
+ '(typeof process !== "undefined" && process.env && process.env.NODE_ENV ? (process.env.NODE_ENV !== "production") : false)',
32
+ __TEST__: 'false',
33
+ }),
34
+ ],
35
+ };
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- const SHARED_STRATEGY = 'loaded-first';
4
-
5
- exports.SHARED_STRATEGY = SHARED_STRATEGY;
@@ -1,3 +0,0 @@
1
- const SHARED_STRATEGY = 'loaded-first';
2
-
3
- export { SHARED_STRATEGY as S };
@@ -1 +0,0 @@
1
- export declare const SHARED_STRATEGY = "loaded-first";
package/src/constant.ts DELETED
@@ -1 +0,0 @@
1
- export const SHARED_STRATEGY = 'loaded-first';