@module-federation/modern-js 0.0.0-next-20240520135154 → 0.0.0-next-20240521123600

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.
@@ -52,15 +52,15 @@ const moduleFederationPlugin = (userConfig = {}) => ({
52
52
  const enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
53
53
  const mfConfig = await (0, import_utils2.getMFConfig)(userConfig);
54
54
  let outputDir = "";
55
+ const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
56
+ const WebpackPluginConstructor = userConfig.webpackPluginImplementation || import_enhanced.ModuleFederationPlugin;
57
+ const RspackPluginConstructor = userConfig.webpackPluginImplementation || import_rspack.ModuleFederationPlugin;
58
+ const MFBundlerPlugin = bundlerType === "rspack" ? RspackPluginConstructor : WebpackPluginConstructor;
55
59
  let browserPlugin;
56
60
  let nodePlugin;
57
61
  return {
58
62
  config: () => {
59
63
  var _modernjsConfig_dev;
60
- const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
61
- const WebpackPluginConstructor = userConfig.webpackPluginImplementation || import_enhanced.ModuleFederationPlugin;
62
- const RspackPluginConstructor = userConfig.rspackPluginImplementation || import_rspack.ModuleFederationPlugin;
63
- const MFBundlerPlugin = bundlerType === "rspack" ? RspackPluginConstructor : WebpackPluginConstructor;
64
64
  if (enableSSR) {
65
65
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
66
66
  process.env["MF_SSR_PRJ"] = "true";
@@ -72,15 +72,11 @@ const moduleFederationPlugin = (userConfig = {}) => ({
72
72
  nodePlugin = new MFBundlerPlugin(envConfig);
73
73
  (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(nodePlugin);
74
74
  (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new import_node.StreamingTargetPlugin(envConfig));
75
- if (isDev) {
76
- var _config_plugins2;
77
- (_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(new import_node.EntryChunkTrackerPlugin());
78
- }
79
75
  } else {
80
- var _config_output, _config_plugins3;
76
+ var _config_output, _config_plugins2;
81
77
  outputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || import_path.default.resolve(process.cwd(), "dist");
82
78
  browserPlugin = new MFBundlerPlugin(envConfig);
83
- (_config_plugins3 = config.plugins) === null || _config_plugins3 === void 0 ? void 0 : _config_plugins3.push(browserPlugin);
79
+ (_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(browserPlugin);
84
80
  }
85
81
  (0, import_utils2.patchWebpackConfig)({
86
82
  bundlerConfig: config,
@@ -51,21 +51,14 @@ const patchMFConfig = (mfConfig, isServer) => {
51
51
  const runtimePlugins = [
52
52
  ...mfConfig.runtimePlugins || []
53
53
  ];
54
- const sharedStrategyRuntimePluginPath = import_path.default.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js");
55
- if (!runtimePlugins.includes(sharedStrategyRuntimePluginPath)) {
56
- runtimePlugins.push(sharedStrategyRuntimePluginPath);
54
+ const runtimePluginPath = import_path.default.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js");
55
+ if (!runtimePlugins.includes(runtimePluginPath)) {
56
+ runtimePlugins.push(import_path.default.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"));
57
57
  }
58
58
  if (isServer) {
59
- const isDev = process.env.NODE_ENV === "development";
60
- if (isDev) {
61
- const nodeHmrPluginPath = require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin");
62
- if (!runtimePlugins.includes(nodeHmrPluginPath)) {
63
- runtimePlugins.push(nodeHmrPluginPath);
64
- }
65
- }
66
- const injectNodeFetchRuntimePluginPath = import_path.default.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js");
67
- if (!runtimePlugins.includes(injectNodeFetchRuntimePluginPath)) {
68
- runtimePlugins.push(injectNodeFetchRuntimePluginPath);
59
+ const nodeHmrPluginPath = require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin");
60
+ if (!runtimePlugins.includes(nodeHmrPluginPath)) {
61
+ runtimePlugins.push(nodeHmrPluginPath);
69
62
  }
70
63
  }
71
64
  if (typeof mfConfig.async === "undefined") {
@@ -4,7 +4,7 @@ import path from "path";
4
4
  import { fs } from "@modern-js/utils";
5
5
  import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryPlugin } from "@module-federation/enhanced";
6
6
  import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
7
- import { StreamingTargetPlugin, EntryChunkTrackerPlugin } from "@module-federation/node";
7
+ import { StreamingTargetPlugin } from "@module-federation/node";
8
8
  import { getMFConfig, getTargetEnvConfig, patchWebpackConfig } from "./utils";
9
9
  import { updateStatsAndManifest } from "./manifest";
10
10
  import { MODERN_JS_SERVER_DIR } from "../constant";
@@ -16,7 +16,7 @@ var moduleFederationPlugin = function() {
16
16
  name: "@modern-js/plugin-module-federation",
17
17
  setup: function() {
18
18
  var _ref = _async_to_generator(function(param) {
19
- var useConfigContext, useAppContext, _modernjsConfig_server, modernjsConfig, enableSSR, mfConfig, outputDir, browserPlugin, nodePlugin;
19
+ var useConfigContext, useAppContext, _modernjsConfig_server, modernjsConfig, enableSSR, mfConfig, outputDir, bundlerType, WebpackPluginConstructor, RspackPluginConstructor, MFBundlerPlugin, browserPlugin, nodePlugin;
20
20
  return _ts_generator(this, function(_state) {
21
21
  switch (_state.label) {
22
22
  case 0:
@@ -30,15 +30,15 @@ var moduleFederationPlugin = function() {
30
30
  case 1:
31
31
  mfConfig = _state.sent();
32
32
  outputDir = "";
33
+ bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
34
+ WebpackPluginConstructor = userConfig.webpackPluginImplementation || WebpackModuleFederationPlugin;
35
+ RspackPluginConstructor = userConfig.webpackPluginImplementation || RspackModuleFederationPlugin;
36
+ MFBundlerPlugin = bundlerType === "rspack" ? RspackPluginConstructor : WebpackPluginConstructor;
33
37
  return [
34
38
  2,
35
39
  {
36
40
  config: function() {
37
41
  var _modernjsConfig_dev;
38
- var bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
39
- var WebpackPluginConstructor = userConfig.webpackPluginImplementation || WebpackModuleFederationPlugin;
40
- var RspackPluginConstructor = userConfig.rspackPluginImplementation || RspackModuleFederationPlugin;
41
- var MFBundlerPlugin = bundlerType === "rspack" ? RspackPluginConstructor : WebpackPluginConstructor;
42
42
  if (enableSSR) {
43
43
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
44
44
  process.env["MF_SSR_PRJ"] = "true";
@@ -50,15 +50,11 @@ var moduleFederationPlugin = function() {
50
50
  nodePlugin = new MFBundlerPlugin(envConfig);
51
51
  (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(nodePlugin);
52
52
  (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new StreamingTargetPlugin(envConfig));
53
- if (isDev) {
54
- var _config_plugins2;
55
- (_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(new EntryChunkTrackerPlugin());
56
- }
57
53
  } else {
58
- var _config_output, _config_plugins3;
54
+ var _config_output, _config_plugins2;
59
55
  outputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
60
56
  browserPlugin = new MFBundlerPlugin(envConfig);
61
- (_config_plugins3 = config.plugins) === null || _config_plugins3 === void 0 ? void 0 : _config_plugins3.push(browserPlugin);
57
+ (_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(browserPlugin);
62
58
  }
63
59
  patchWebpackConfig({
64
60
  bundlerConfig: config,
@@ -45,21 +45,14 @@ var getMFConfig = function() {
45
45
  }();
46
46
  var patchMFConfig = function(mfConfig, isServer) {
47
47
  var runtimePlugins = _to_consumable_array(mfConfig.runtimePlugins || []);
48
- var sharedStrategyRuntimePluginPath = path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js");
49
- if (!runtimePlugins.includes(sharedStrategyRuntimePluginPath)) {
50
- runtimePlugins.push(sharedStrategyRuntimePluginPath);
48
+ var runtimePluginPath = path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js");
49
+ if (!runtimePlugins.includes(runtimePluginPath)) {
50
+ runtimePlugins.push(path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"));
51
51
  }
52
52
  if (isServer) {
53
- var isDev = process.env.NODE_ENV === "development";
54
- if (isDev) {
55
- var nodeHmrPluginPath = require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin");
56
- if (!runtimePlugins.includes(nodeHmrPluginPath)) {
57
- runtimePlugins.push(nodeHmrPluginPath);
58
- }
59
- }
60
- var injectNodeFetchRuntimePluginPath = path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js");
61
- if (!runtimePlugins.includes(injectNodeFetchRuntimePluginPath)) {
62
- runtimePlugins.push(injectNodeFetchRuntimePluginPath);
53
+ var nodeHmrPluginPath = require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin");
54
+ if (!runtimePlugins.includes(nodeHmrPluginPath)) {
55
+ runtimePlugins.push(nodeHmrPluginPath);
63
56
  }
64
57
  }
65
58
  if (typeof mfConfig.async === "undefined") {
@@ -2,7 +2,7 @@ import path from "path";
2
2
  import { fs } from "@modern-js/utils";
3
3
  import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryPlugin } from "@module-federation/enhanced";
4
4
  import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
5
- import { StreamingTargetPlugin, EntryChunkTrackerPlugin } from "@module-federation/node";
5
+ import { StreamingTargetPlugin } from "@module-federation/node";
6
6
  import { getMFConfig, getTargetEnvConfig, patchWebpackConfig } from "./utils";
7
7
  import { updateStatsAndManifest } from "./manifest";
8
8
  import { MODERN_JS_SERVER_DIR } from "../constant";
@@ -16,15 +16,15 @@ const moduleFederationPlugin = (userConfig = {}) => ({
16
16
  const enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
17
17
  const mfConfig = await getMFConfig(userConfig);
18
18
  let outputDir = "";
19
+ const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
20
+ const WebpackPluginConstructor = userConfig.webpackPluginImplementation || WebpackModuleFederationPlugin;
21
+ const RspackPluginConstructor = userConfig.webpackPluginImplementation || RspackModuleFederationPlugin;
22
+ const MFBundlerPlugin = bundlerType === "rspack" ? RspackPluginConstructor : WebpackPluginConstructor;
19
23
  let browserPlugin;
20
24
  let nodePlugin;
21
25
  return {
22
26
  config: () => {
23
27
  var _modernjsConfig_dev;
24
- const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
25
- const WebpackPluginConstructor = userConfig.webpackPluginImplementation || WebpackModuleFederationPlugin;
26
- const RspackPluginConstructor = userConfig.rspackPluginImplementation || RspackModuleFederationPlugin;
27
- const MFBundlerPlugin = bundlerType === "rspack" ? RspackPluginConstructor : WebpackPluginConstructor;
28
28
  if (enableSSR) {
29
29
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
30
30
  process.env["MF_SSR_PRJ"] = "true";
@@ -36,15 +36,11 @@ const moduleFederationPlugin = (userConfig = {}) => ({
36
36
  nodePlugin = new MFBundlerPlugin(envConfig);
37
37
  (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(nodePlugin);
38
38
  (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new StreamingTargetPlugin(envConfig));
39
- if (isDev) {
40
- var _config_plugins2;
41
- (_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(new EntryChunkTrackerPlugin());
42
- }
43
39
  } else {
44
- var _config_output, _config_plugins3;
40
+ var _config_output, _config_plugins2;
45
41
  outputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
46
42
  browserPlugin = new MFBundlerPlugin(envConfig);
47
- (_config_plugins3 = config.plugins) === null || _config_plugins3 === void 0 ? void 0 : _config_plugins3.push(browserPlugin);
43
+ (_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(browserPlugin);
48
44
  }
49
45
  patchWebpackConfig({
50
46
  bundlerConfig: config,
@@ -15,21 +15,14 @@ const patchMFConfig = (mfConfig, isServer) => {
15
15
  const runtimePlugins = [
16
16
  ...mfConfig.runtimePlugins || []
17
17
  ];
18
- const sharedStrategyRuntimePluginPath = path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js");
19
- if (!runtimePlugins.includes(sharedStrategyRuntimePluginPath)) {
20
- runtimePlugins.push(sharedStrategyRuntimePluginPath);
18
+ const runtimePluginPath = path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js");
19
+ if (!runtimePlugins.includes(runtimePluginPath)) {
20
+ runtimePlugins.push(path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"));
21
21
  }
22
22
  if (isServer) {
23
- const isDev = process.env.NODE_ENV === "development";
24
- if (isDev) {
25
- const nodeHmrPluginPath = require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin");
26
- if (!runtimePlugins.includes(nodeHmrPluginPath)) {
27
- runtimePlugins.push(nodeHmrPluginPath);
28
- }
29
- }
30
- const injectNodeFetchRuntimePluginPath = path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js");
31
- if (!runtimePlugins.includes(injectNodeFetchRuntimePluginPath)) {
32
- runtimePlugins.push(injectNodeFetchRuntimePluginPath);
23
+ const nodeHmrPluginPath = require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin");
24
+ if (!runtimePlugins.includes(nodeHmrPluginPath)) {
25
+ runtimePlugins.push(nodeHmrPluginPath);
33
26
  }
34
27
  }
35
28
  if (typeof mfConfig.async === "undefined") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/modern-js",
3
- "version": "0.0.0-next-20240520135154",
3
+ "version": "0.0.0-next-20240521123600",
4
4
  "files": [
5
5
  "dist/",
6
6
  "types.d.ts",
@@ -45,10 +45,9 @@
45
45
  "@swc/helpers": "0.5.3",
46
46
  "@modern-js/utils": "^2.49.2",
47
47
  "@modern-js/node-bundle-require": "^2.49.2",
48
- "node-fetch": "~3.3.0",
49
- "@module-federation/sdk": "0.0.0-next-20240520135154",
50
- "@module-federation/enhanced": "0.0.0-next-20240520135154",
51
- "@module-federation/node": "0.0.0-next-20240520135154"
48
+ "@module-federation/sdk": "0.0.0-next-20240521123600",
49
+ "@module-federation/enhanced": "0.0.0-next-20240521123600",
50
+ "@module-federation/node": "0.0.0-next-20240521123600"
52
51
  },
53
52
  "devDependencies": {
54
53
  "@modern-js/app-tools": "^2.49.2",
@@ -56,7 +55,11 @@
56
55
  "@modern-js/runtime": "^2.49.2",
57
56
  "@modern-js/module-tools": "^2.35.0",
58
57
  "@modern-js/tsconfig": "^2.35.0",
59
- "@module-federation/manifest": "0.0.0-next-20240520135154"
58
+ "@module-federation/manifest": "0.0.0-next-20240521123600"
59
+ },
60
+ "peerDependencies": {
61
+ "react": ">=17",
62
+ "react-dom": ">=17"
60
63
  },
61
64
  "scripts": {
62
65
  "build": "modern build"
@@ -1,44 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var inject_node_fetch_exports = {};
30
- __export(inject_node_fetch_exports, {
31
- default: () => inject_node_fetch_default
32
- });
33
- module.exports = __toCommonJS(inject_node_fetch_exports);
34
- var import_node_fetch = __toESM(require("node-fetch"));
35
- const injectNodeFetchPlugin = () => ({
36
- name: "inject-node-fetch-plugin",
37
- beforeInit(args) {
38
- if (!globalThis.fetch) {
39
- globalThis.fetch = import_node_fetch.default;
40
- }
41
- return args;
42
- }
43
- });
44
- var inject_node_fetch_default = injectNodeFetchPlugin;
@@ -1,16 +0,0 @@
1
- import nodeFetch from "node-fetch";
2
- var injectNodeFetchPlugin = function() {
3
- return {
4
- name: "inject-node-fetch-plugin",
5
- beforeInit: function beforeInit(args) {
6
- if (!globalThis.fetch) {
7
- globalThis.fetch = nodeFetch;
8
- }
9
- return args;
10
- }
11
- };
12
- };
13
- var inject_node_fetch_default = injectNodeFetchPlugin;
14
- export {
15
- inject_node_fetch_default as default
16
- };
@@ -1,14 +0,0 @@
1
- import nodeFetch from "node-fetch";
2
- const injectNodeFetchPlugin = () => ({
3
- name: "inject-node-fetch-plugin",
4
- beforeInit(args) {
5
- if (!globalThis.fetch) {
6
- globalThis.fetch = nodeFetch;
7
- }
8
- return args;
9
- }
10
- });
11
- var inject_node_fetch_default = injectNodeFetchPlugin;
12
- export {
13
- inject_node_fetch_default as default
14
- };
@@ -1,3 +0,0 @@
1
- import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
2
- declare const injectNodeFetchPlugin: () => FederationRuntimePlugin;
3
- export default injectNodeFetchPlugin;