@module-federation/modern-js 0.11.2 → 0.11.4

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.
@@ -1,231 +1,4 @@
1
1
  import os from "os";
2
- import path from "path";
3
- import { encodeName } from "@module-federation/sdk";
4
- import { bundle } from "@modern-js/node-bundle-require";
5
- import { LOCALHOST, PLUGIN_IDENTIFIER } from "../constant";
6
- import logger from "./logger";
7
- import { autoDeleteSplitChunkCacheGroups } from "@module-federation/rsbuild-plugin/utils";
8
- const defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
9
- const isDev = process.env.NODE_ENV === "development";
10
- const getMFConfig = async (userConfig) => {
11
- const { config, configPath } = userConfig;
12
- if (config) {
13
- return config;
14
- }
15
- const mfConfigPath = configPath ? configPath : defaultPath;
16
- const preBundlePath = await bundle(mfConfigPath);
17
- const mfConfig = (await import(preBundlePath)).default;
18
- return mfConfig;
19
- };
20
- const injectRuntimePlugins = (runtimePlugin, runtimePlugins) => {
21
- if (!runtimePlugins.includes(runtimePlugin)) {
22
- runtimePlugins.push(runtimePlugin);
23
- }
24
- };
25
- const replaceRemoteUrl = (mfConfig, remoteIpStrategy) => {
26
- if (remoteIpStrategy && remoteIpStrategy === "inherit") {
27
- return;
28
- }
29
- if (!mfConfig.remotes) {
30
- return;
31
- }
32
- const ipv4 = getIPV4();
33
- const handleRemoteObject = (remoteObject) => {
34
- Object.keys(remoteObject).forEach((remoteKey) => {
35
- const remote = remoteObject[remoteKey];
36
- if (Array.isArray(remote)) {
37
- return;
38
- }
39
- if (typeof remote === "string" && remote.includes(LOCALHOST)) {
40
- remoteObject[remoteKey] = remote.replace(LOCALHOST, ipv4);
41
- }
42
- if (typeof remote === "object" && !Array.isArray(remote.external) && remote.external.includes(LOCALHOST)) {
43
- remote.external = remote.external.replace(LOCALHOST, ipv4);
44
- }
45
- });
46
- };
47
- if (Array.isArray(mfConfig.remotes)) {
48
- mfConfig.remotes.forEach((remoteObject) => {
49
- if (typeof remoteObject === "string") {
50
- return;
51
- }
52
- handleRemoteObject(remoteObject);
53
- });
54
- } else if (typeof mfConfig.remotes !== "string") {
55
- handleRemoteObject(mfConfig.remotes);
56
- }
57
- };
58
- const patchDTSConfig = (mfConfig, isServer) => {
59
- if (isServer) {
60
- return;
61
- }
62
- const ModernJSRuntime = "@modern-js/runtime/mf";
63
- if (mfConfig.dts !== false) {
64
- var _mfConfig_dts, _mfConfig_dts1;
65
- if (typeof mfConfig.dts === "boolean" || mfConfig.dts === void 0) {
66
- mfConfig.dts = {
67
- consumeTypes: {
68
- runtimePkgs: [
69
- ModernJSRuntime
70
- ]
71
- }
72
- };
73
- } else if (((_mfConfig_dts = mfConfig.dts) === null || _mfConfig_dts === void 0 ? void 0 : _mfConfig_dts.consumeTypes) || ((_mfConfig_dts1 = mfConfig.dts) === null || _mfConfig_dts1 === void 0 ? void 0 : _mfConfig_dts1.consumeTypes) === void 0) {
74
- var _mfConfig_dts2;
75
- if (typeof mfConfig.dts.consumeTypes === "boolean" || ((_mfConfig_dts2 = mfConfig.dts) === null || _mfConfig_dts2 === void 0 ? void 0 : _mfConfig_dts2.consumeTypes) === void 0) {
76
- mfConfig.dts.consumeTypes = {
77
- runtimePkgs: [
78
- ModernJSRuntime
79
- ]
80
- };
81
- } else {
82
- mfConfig.dts.consumeTypes.runtimePkgs = mfConfig.dts.consumeTypes.runtimePkgs || [];
83
- if (!mfConfig.dts.consumeTypes.runtimePkgs.includes(ModernJSRuntime)) {
84
- mfConfig.dts.consumeTypes.runtimePkgs.push(ModernJSRuntime);
85
- }
86
- }
87
- }
88
- }
89
- };
90
- const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
91
- replaceRemoteUrl(mfConfig, remoteIpStrategy);
92
- if (mfConfig.remoteType === void 0) {
93
- mfConfig.remoteType = "script";
94
- }
95
- if (!mfConfig.name) {
96
- throw new Error(`${PLUGIN_IDENTIFIER} mfConfig.name can not be empty!`);
97
- }
98
- const runtimePlugins = [
99
- ...mfConfig.runtimePlugins || []
100
- ];
101
- patchDTSConfig(mfConfig, isServer);
102
- injectRuntimePlugins(require.resolve("@module-federation/modern-js/shared-strategy"), runtimePlugins);
103
- if (isDev) {
104
- injectRuntimePlugins(require.resolve("@module-federation/modern-js/resolve-entry-ipv4"), runtimePlugins);
105
- }
106
- if (isServer) {
107
- injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
108
- if (isDev) {
109
- injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
110
- }
111
- injectRuntimePlugins(require.resolve("@module-federation/modern-js/inject-node-fetch"), runtimePlugins);
112
- if (!mfConfig.library) {
113
- mfConfig.library = {
114
- type: "commonjs-module",
115
- name: mfConfig.name
116
- };
117
- } else {
118
- if (!mfConfig.library.type) {
119
- mfConfig.library.type = "commonjs-module";
120
- }
121
- if (!mfConfig.library.name) {
122
- mfConfig.library.name = mfConfig.name;
123
- }
124
- }
125
- }
126
- mfConfig.runtimePlugins = runtimePlugins;
127
- if (!isServer) {
128
- var _mfConfig_library;
129
- if (((_mfConfig_library = mfConfig.library) === null || _mfConfig_library === void 0 ? void 0 : _mfConfig_library.type) === "commonjs-module") {
130
- mfConfig.library.type = "global";
131
- }
132
- return mfConfig;
133
- }
134
- mfConfig.dts = false;
135
- mfConfig.dev = false;
136
- return mfConfig;
137
- };
138
- function patchIgnoreWarning(chain) {
139
- const ignoreWarnings = chain.get("ignoreWarnings") || [];
140
- const ignoredMsgs = [
141
- "external script",
142
- "process.env.WS_NO_BUFFER_UTIL",
143
- `Can't resolve 'utf-8-validate`
144
- ];
145
- ignoreWarnings.push((warning) => {
146
- if (ignoredMsgs.some((msg) => warning.message.includes(msg))) {
147
- return true;
148
- }
149
- return false;
150
- });
151
- chain.ignoreWarnings(ignoreWarnings);
152
- }
153
- function addMyTypes2Ignored(chain, mfConfig) {
154
- const watchOptions = chain.get("watchOptions");
155
- if (!watchOptions || !watchOptions.ignored) {
156
- chain.watchOptions({
157
- ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
158
- });
159
- return;
160
- }
161
- const ignored = watchOptions.ignored;
162
- const DEFAULT_IGNORED_GLOB = "**/@mf-types/**";
163
- if (Array.isArray(ignored)) {
164
- if (mfConfig.dts !== false && typeof mfConfig.dts === "object" && typeof mfConfig.dts.consumeTypes === "object" && mfConfig.dts.consumeTypes.remoteTypesFolder) {
165
- chain.watchOptions({
166
- ...watchOptions,
167
- ignored: ignored.concat(`**/${mfConfig.dts.consumeTypes.remoteTypesFolder}/**`)
168
- });
169
- } else {
170
- chain.watchOptions({
171
- ...watchOptions,
172
- ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
173
- });
174
- }
175
- return;
176
- }
177
- if (typeof ignored !== "string") {
178
- chain.watchOptions({
179
- ...watchOptions,
180
- ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
181
- });
182
- return;
183
- }
184
- chain.watchOptions({
185
- ...watchOptions,
186
- ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
187
- });
188
- }
189
- function patchBundlerConfig(options) {
190
- var _modernjsConfig_deploy;
191
- const { chain, modernjsConfig, isServer, mfConfig, enableSSR } = options;
192
- chain.optimization.delete("runtimeChunk");
193
- patchIgnoreWarning(chain);
194
- if (!chain.output.get("chunkLoadingGlobal")) {
195
- chain.output.chunkLoadingGlobal(`chunk_${mfConfig.name}`);
196
- }
197
- if (!chain.output.get("uniqueName")) {
198
- chain.output.uniqueName(mfConfig.name);
199
- }
200
- const splitChunkConfig = chain.optimization.splitChunks.entries();
201
- if (!isServer) {
202
- autoDeleteSplitChunkCacheGroups(mfConfig, splitChunkConfig);
203
- }
204
- if (!isServer && enableSSR && splitChunkConfig && typeof splitChunkConfig === "object" && splitChunkConfig.cacheGroups) {
205
- splitChunkConfig.chunks = "async";
206
- logger.warn(`splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"`);
207
- }
208
- if (isDev && chain.output.get("publicPath") === "auto") {
209
- var _modernjsConfig_dev, _modernjsConfig_server;
210
- const port = ((_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.port) || ((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.port) || 8080;
211
- const publicPath = `http://localhost:${port}/`;
212
- chain.output.publicPath(publicPath);
213
- }
214
- if (isServer && enableSSR) {
215
- const uniqueName = mfConfig.name || chain.output.get("uniqueName");
216
- const chunkFileName = chain.output.get("chunkFilename");
217
- if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
218
- const suffix = `${encodeName(uniqueName)}-[chunkhash].js`;
219
- chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
220
- }
221
- }
222
- if (isDev && enableSSR && !isServer) {
223
- chain.resolve.fallback.set("crypto", false).set("stream", false).set("vm", false);
224
- }
225
- if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
226
- chain.optimization.usedExports(false);
227
- }
228
- }
229
2
  const localIpv4 = "127.0.0.1";
230
3
  const getIpv4Interfaces = () => {
231
4
  try {
@@ -270,11 +43,7 @@ const skipByTarget = (target) => {
270
43
  return false;
271
44
  };
272
45
  export {
273
- addMyTypes2Ignored,
274
46
  getIPV4,
275
- getMFConfig,
276
47
  isWebTarget,
277
- patchBundlerConfig,
278
- patchMFConfig,
279
48
  skipByTarget
280
49
  };
@@ -1,8 +1,6 @@
1
- const MODERN_JS_SERVER_DIR = "bundles";
2
1
  const LOCALHOST = "localhost";
3
2
  const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
4
3
  export {
5
4
  LOCALHOST,
6
- MODERN_JS_SERVER_DIR,
7
5
  PLUGIN_IDENTIFIER
8
6
  };
@@ -1,7 +1,21 @@
1
- import type { CliPluginFuture, AppTools } from '@modern-js/app-tools';
2
- import type { InternalModernPluginOptions } from '../types';
3
1
  import { isWebTarget, skipByTarget } from './utils';
2
+ import { moduleFederationPlugin } from '@module-federation/sdk';
3
+ import { PluginOptions } from '../types';
4
+ import type { InternalModernPluginOptions } from '../types';
5
+ import type { AppTools, webpack, UserConfig, Rspack, CliPluginFuture } from '@modern-js/app-tools';
6
+ import type { BundlerChainConfig } from '../interfaces/bundler';
7
+ export type ConfigType<T> = T extends 'webpack' ? webpack.Configuration : T extends 'rspack' ? Rspack.Configuration : never;
4
8
  export declare function setEnv(enableSSR: boolean): void;
9
+ export declare const getMFConfig: (userConfig: PluginOptions) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
10
+ export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean, remoteIpStrategy?: "ipv4" | "inherit") => moduleFederationPlugin.ModuleFederationPluginOptions;
11
+ export declare function addMyTypes2Ignored(chain: BundlerChainConfig, mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions): void;
12
+ export declare function patchBundlerConfig(options: {
13
+ chain: BundlerChainConfig;
14
+ isServer: boolean;
15
+ modernjsConfig: UserConfig<AppTools>;
16
+ mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions;
17
+ enableSSR: boolean;
18
+ }): void;
5
19
  export declare const moduleFederationConfigPlugin: (userConfig: InternalModernPluginOptions) => CliPluginFuture<AppTools>;
6
20
  export default moduleFederationConfigPlugin;
7
21
  export { isWebTarget, skipByTarget };
@@ -1,2 +1,2 @@
1
1
  import { BundlerPlugin } from '../types';
2
- export declare function updateStatsAndManifest(nodePlugin: BundlerPlugin, browserPlugin: BundlerPlugin, outputDir: string, ssrDir: string): void;
2
+ export declare function updateStatsAndManifest(nodePlugin: BundlerPlugin, browserPlugin: BundlerPlugin, outputDir: string): void;
@@ -1,18 +1,5 @@
1
- import { moduleFederationPlugin } from '@module-federation/sdk';
2
- import { PluginOptions } from '../types';
3
- import type { BundlerChainConfig } from '../interfaces/bundler';
4
- import type { webpack, UserConfig, AppTools, Rspack } from '@modern-js/app-tools';
1
+ import type { webpack, Rspack } from '@modern-js/app-tools';
5
2
  export type ConfigType<T> = T extends 'webpack' ? webpack.Configuration : T extends 'rspack' ? Rspack.Configuration : never;
6
- export declare const getMFConfig: (userConfig: PluginOptions) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
7
- export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean, remoteIpStrategy?: "ipv4" | "inherit") => moduleFederationPlugin.ModuleFederationPluginOptions;
8
- export declare function addMyTypes2Ignored(chain: BundlerChainConfig, mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions): void;
9
- export declare function patchBundlerConfig(options: {
10
- chain: BundlerChainConfig;
11
- isServer: boolean;
12
- modernjsConfig: UserConfig<AppTools>;
13
- mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions;
14
- enableSSR: boolean;
15
- }): void;
16
3
  export declare const getIPV4: () => string;
17
4
  export declare const isWebTarget: (target: string[] | string) => boolean;
18
5
  export declare const skipByTarget: (target: string[] | string) => boolean;
@@ -1,3 +1,2 @@
1
- export declare const MODERN_JS_SERVER_DIR = "bundles";
2
1
  export declare const LOCALHOST = "localhost";
3
2
  export declare const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
@@ -4,7 +4,9 @@ import type { ModuleFederationPlugin as RspackModuleFederationPlugin } from '@mo
4
4
  export interface PluginOptions {
5
5
  config?: moduleFederationPlugin.ModuleFederationPluginOptions;
6
6
  configPath?: string;
7
- ssr?: boolean;
7
+ ssr?: {
8
+ distOutputDir?: string;
9
+ } | boolean;
8
10
  remoteIpStrategy?: 'ipv4' | 'inherit';
9
11
  }
10
12
  export interface InternalModernPluginOptions {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/modern-js",
3
- "version": "0.11.2",
3
+ "version": "0.11.4",
4
4
  "files": [
5
5
  "dist/",
6
6
  "types.d.ts",
@@ -89,19 +89,20 @@
89
89
  "@swc/helpers": "0.5.13",
90
90
  "node-fetch": "~3.3.0",
91
91
  "react-error-boundary": "4.1.2",
92
- "@module-federation/rsbuild-plugin": "0.11.2",
93
- "@module-federation/enhanced": "0.11.2",
94
- "@module-federation/node": "2.6.31",
95
- "@module-federation/sdk": "0.11.2",
96
- "@module-federation/cli": "0.11.2"
92
+ "@module-federation/rsbuild-plugin": "0.11.4",
93
+ "@module-federation/enhanced": "0.11.4",
94
+ "@module-federation/node": "2.6.33",
95
+ "@module-federation/sdk": "0.11.4",
96
+ "@module-federation/cli": "0.11.4"
97
97
  },
98
98
  "devDependencies": {
99
+ "@rsbuild/core": "1.2.8",
99
100
  "@modern-js/app-tools": "2.65.1",
100
101
  "@modern-js/core": "2.65.1",
101
102
  "@modern-js/module-tools": "2.65.1",
102
103
  "@modern-js/runtime": "2.65.1",
103
104
  "@modern-js/tsconfig": "2.65.1",
104
- "@module-federation/manifest": "0.11.2"
105
+ "@module-federation/manifest": "0.11.4"
105
106
  },
106
107
  "peerDependencies": {
107
108
  "react": ">=17",