@module-federation/nextjs-mf 0.0.0-feat-node-support-1702694175665

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.
Files changed (91) hide show
  1. package/client/UrlNode.d.ts +17 -0
  2. package/client/UrlNode.js +150 -0
  3. package/client/UrlNode.js.map +1 -0
  4. package/node.d.ts +1 -0
  5. package/node.js +18 -0
  6. package/node.js.map +1 -0
  7. package/package.json +44 -0
  8. package/src/default-delegate.cjs +308 -0
  9. package/src/default-delegate.d.ts +1 -0
  10. package/src/default-delegate.js.map +1 -0
  11. package/src/federation-noop.cjs +15 -0
  12. package/src/federation-noop.d.ts +0 -0
  13. package/src/federation-noop.js.map +1 -0
  14. package/src/index.d.ts +3 -0
  15. package/src/index.js +12 -0
  16. package/src/index.js.map +1 -0
  17. package/src/internal.d.ts +48 -0
  18. package/src/internal.js +256 -0
  19. package/src/internal.js.map +1 -0
  20. package/src/loaders/delegateLoader.d.ts +10 -0
  21. package/src/loaders/delegateLoader.js +46 -0
  22. package/src/loaders/delegateLoader.js.map +1 -0
  23. package/src/loaders/fixImageLoader.d.ts +22 -0
  24. package/src/loaders/fixImageLoader.js +118 -0
  25. package/src/loaders/fixImageLoader.js.map +1 -0
  26. package/src/loaders/fixUrlLoader.d.ts +13 -0
  27. package/src/loaders/fixUrlLoader.js +25 -0
  28. package/src/loaders/fixUrlLoader.js.map +1 -0
  29. package/src/loaders/helpers.d.ts +17 -0
  30. package/src/loaders/helpers.js +60 -0
  31. package/src/loaders/helpers.js.map +1 -0
  32. package/src/loaders/nextPageMapLoader.d.ts +24 -0
  33. package/src/loaders/nextPageMapLoader.js +167 -0
  34. package/src/loaders/nextPageMapLoader.js.map +1 -0
  35. package/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.d.ts +5 -0
  36. package/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.js +19 -0
  37. package/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.js.map +1 -0
  38. package/src/plugins/CopyFederationPlugin.d.ts +20 -0
  39. package/src/plugins/CopyFederationPlugin.js +71 -0
  40. package/src/plugins/CopyFederationPlugin.js.map +1 -0
  41. package/src/plugins/NextFederationPlugin/apply-client-plugins.d.ts +23 -0
  42. package/src/plugins/NextFederationPlugin/apply-client-plugins.js +72 -0
  43. package/src/plugins/NextFederationPlugin/apply-client-plugins.js.map +1 -0
  44. package/src/plugins/NextFederationPlugin/apply-server-plugins.d.ts +60 -0
  45. package/src/plugins/NextFederationPlugin/apply-server-plugins.js +173 -0
  46. package/src/plugins/NextFederationPlugin/apply-server-plugins.js.map +1 -0
  47. package/src/plugins/NextFederationPlugin/index.d.ts +30 -0
  48. package/src/plugins/NextFederationPlugin/index.js +148 -0
  49. package/src/plugins/NextFederationPlugin/index.js.map +1 -0
  50. package/src/plugins/NextFederationPlugin/next-fragments.d.ts +18 -0
  51. package/src/plugins/NextFederationPlugin/next-fragments.js +65 -0
  52. package/src/plugins/NextFederationPlugin/next-fragments.js.map +1 -0
  53. package/src/plugins/NextFederationPlugin/regex-equal.d.ts +14 -0
  54. package/src/plugins/NextFederationPlugin/regex-equal.js +25 -0
  55. package/src/plugins/NextFederationPlugin/regex-equal.js.map +1 -0
  56. package/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.d.ts +8 -0
  57. package/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js +31 -0
  58. package/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js.map +1 -0
  59. package/src/plugins/NextFederationPlugin/set-options.d.ts +20 -0
  60. package/src/plugins/NextFederationPlugin/set-options.js +38 -0
  61. package/src/plugins/NextFederationPlugin/set-options.js.map +1 -0
  62. package/src/plugins/NextFederationPlugin/validate-options.d.ts +25 -0
  63. package/src/plugins/NextFederationPlugin/validate-options.js +46 -0
  64. package/src/plugins/NextFederationPlugin/validate-options.js.map +1 -0
  65. package/src/plugins/container/EmbeddedContainerPlugin.d.ts +40 -0
  66. package/src/plugins/container/EmbeddedContainerPlugin.js +73 -0
  67. package/src/plugins/container/EmbeddedContainerPlugin.js.map +1 -0
  68. package/src/plugins/container/HoistPseudoEagerModules.d.ts +19 -0
  69. package/src/plugins/container/HoistPseudoEagerModules.js +79 -0
  70. package/src/plugins/container/HoistPseudoEagerModules.js.map +1 -0
  71. package/src/plugins/container/InvertedContainerPlugin.d.ts +15 -0
  72. package/src/plugins/container/InvertedContainerPlugin.js +25 -0
  73. package/src/plugins/container/InvertedContainerPlugin.js.map +1 -0
  74. package/src/plugins/container/InvertedContainerRuntimeModule.d.ts +15 -0
  75. package/src/plugins/container/InvertedContainerRuntimeModule.js +65 -0
  76. package/src/plugins/container/InvertedContainerRuntimeModule.js.map +1 -0
  77. package/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.d.ts +39 -0
  78. package/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.js +72 -0
  79. package/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.js.map +1 -0
  80. package/src/plugins/container/runtimePlugin.d.ts +2 -0
  81. package/src/plugins/container/runtimePlugin.js +64 -0
  82. package/src/plugins/container/runtimePlugin.js.map +1 -0
  83. package/src/plugins/container/types.d.ts +2 -0
  84. package/src/plugins/container/types.js +3 -0
  85. package/src/plugins/container/types.js.map +1 -0
  86. package/src/types.d.ts +28 -0
  87. package/src/types.js +3 -0
  88. package/src/types.js.map +1 -0
  89. package/utilities.d.ts +1 -0
  90. package/utilities.js +18 -0
  91. package/utilities.js.map +1 -0
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.configureServerCompilerOptions = exports.handleServerExternals = exports.configureServerLibraryAndFilename = exports.applyServerPlugins = void 0;
7
+ const HoistContainerReferencesPlugin_1 = require("@module-federation/enhanced/src/lib/container/HoistContainerReferencesPlugin");
8
+ const path_1 = __importDefault(require("path"));
9
+ const InvertedContainerPlugin_1 = __importDefault(require("../container/InvertedContainerPlugin"));
10
+ const enhanced_1 = require("@module-federation/enhanced");
11
+ /**
12
+ * This function applies server-specific plugins to the webpack compiler.
13
+ *
14
+ * @param {Compiler} compiler - The Webpack compiler instance.
15
+ * @param {ModuleFederationPluginOptions} options - The ModuleFederationPluginOptions instance.
16
+ *
17
+ * @returns {void}
18
+ */
19
+ function applyServerPlugins(compiler, options) {
20
+ // Import the StreamingTargetPlugin from @module-federation/node
21
+ const { StreamingTargetPlugin } = require('@module-federation/node');
22
+ const chunkFileName = compiler.options?.output?.chunkFilename;
23
+ const uniqueName = compiler?.options?.output?.uniqueName || options.name;
24
+ if (typeof chunkFileName === 'string' &&
25
+ uniqueName &&
26
+ !chunkFileName.includes(uniqueName)) {
27
+ const suffix = `-[chunkhash].js`;
28
+ compiler.options.output.chunkFilename = chunkFileName.replace('.js', suffix);
29
+ }
30
+ // Hoist container references into runtime chunks
31
+ //@ts-ignore
32
+ new HoistContainerReferencesPlugin_1.HoistContainerReferences().apply(compiler);
33
+ // Add the StreamingTargetPlugin with the ModuleFederationPlugin from the webpack container
34
+ new StreamingTargetPlugin(options, {
35
+ ModuleFederationPlugin: enhanced_1.ModuleFederationPlugin,
36
+ }).apply(compiler);
37
+ // Add a new commonjs chunk loading plugin to the compiler
38
+ new InvertedContainerPlugin_1.default({
39
+ runtime: 'webpack-runtime',
40
+ container: options.name,
41
+ chunkToEmbed: 'host_inner_ctn',
42
+ remotes: options.remotes,
43
+ shared: options.shared,
44
+ shareScope: 'default',
45
+ exposes: options.exposes,
46
+ debug: false,
47
+ //@ts-ignore
48
+ }).apply(compiler);
49
+ }
50
+ exports.applyServerPlugins = applyServerPlugins;
51
+ /**
52
+ * This function configures server-specific library and filename options.
53
+ *
54
+ * @param {ModuleFederationPluginOptions} options - The ModuleFederationPluginOptions instance.
55
+ *
56
+ * @returns {void}
57
+ *
58
+ * @remarks
59
+ * This function configures the library and filename options for server builds. The library option is
60
+ * set to the commonjs-module format for chunks and the container, which allows them to be streamed over
61
+ * to hosts with the NodeFederationPlugin. The filename option is set to the basename of the current
62
+ * filename.
63
+ */
64
+ function configureServerLibraryAndFilename(options) {
65
+ // Configure the library option with type "commonjs-module" and the name from the options
66
+ options.library = {
67
+ type: 'commonjs-module',
68
+ name: options.name,
69
+ };
70
+ // Set the filename option to the basename of the current filename
71
+ options.filename = path_1.default.basename(options.filename);
72
+ }
73
+ exports.configureServerLibraryAndFilename = configureServerLibraryAndFilename;
74
+ /**
75
+ * This function patches Next.js' default externals function to make sure shared modules are bundled and not treated as external.
76
+ *
77
+ * @param {Compiler} compiler - The Webpack compiler instance.
78
+ * @param {ModuleFederationPluginOptions} options - The ModuleFederationPluginOptions instance.
79
+ *
80
+ * @returns {void}
81
+ *
82
+ * @remarks
83
+ * In server builds, all node modules are treated as external, which prevents them from being shared
84
+ * via module federation. To work around this limitation, we mark shared modules as internalizable
85
+ * modules that webpack puts into chunks that can be streamed to other runtimes as needed.
86
+ *
87
+ * This function replaces Next.js' default externals function with a new asynchronous function that
88
+ * checks whether a module should be treated as external. If the module should not be treated as
89
+ * external, the function returns without calling the original externals function. Otherwise, the
90
+ * function calls the original externals function and retrieves the result. If the result is null,
91
+ * the function returns without further processing. If the module is from Next.js or React, the
92
+ * function returns the original result. Otherwise, the function returns null.
93
+ */
94
+ function handleServerExternals(compiler, options) {
95
+ // Use a regex to match the required external modules
96
+ // const crittersRegex = 'critters';
97
+ // const reactRegex = /^react$/;
98
+ // const reactDomRegex = /^react-dom$/;
99
+ // const nextCompiledRegex = /next\/dist\/compiled\/(?!server|client|shared).*/;
100
+ if (Array.isArray(compiler.options.externals) &&
101
+ compiler.options.externals[0]) {
102
+ // Retrieve the original externals function
103
+ const originalExternals = compiler.options.externals[0];
104
+ // Replace the original externals function with a new asynchronous function
105
+ compiler.options.externals[0] = async function (ctx, callback) {
106
+ //@ts-ignore
107
+ const fromNext = await originalExternals(ctx, callback);
108
+ // If the result is null, return without further processing
109
+ if (!fromNext) {
110
+ return;
111
+ }
112
+ // If the module is from Next.js or React, return the original result
113
+ const req = fromNext.split(' ')[1];
114
+ // Check if the module should not be treated as external
115
+ if (ctx.request &&
116
+ (ctx.request.includes('@module-federation/utilities') ||
117
+ ctx.request.includes('internal-delegate-hoist') ||
118
+ Object.keys(options.shared || {}).some((key) => {
119
+ return (
120
+ //@ts-ignore
121
+ options.shared?.[key]?.import !== false &&
122
+ (key.endsWith('/') ? req.includes(key) : req === key));
123
+ }) ||
124
+ ctx.request.includes('@module-federation/dashboard-plugin'))) {
125
+ // If the module should not be treated as external, return without calling the original externals function
126
+ return;
127
+ }
128
+ if (req.startsWith('next') ||
129
+ // make sure we dont screw up package names that start with react
130
+ // like react-carousel or react-spring
131
+ req.startsWith('react/') ||
132
+ req.startsWith('react-dom/') ||
133
+ req === 'react' ||
134
+ req === 'styled-jsx/style' ||
135
+ req === 'react-dom') {
136
+ return fromNext;
137
+ }
138
+ // Otherwise, return (null) to treat the module as internalizable
139
+ return;
140
+ };
141
+ }
142
+ }
143
+ exports.handleServerExternals = handleServerExternals;
144
+ /**
145
+ * This function configures server-specific compiler options.
146
+ *
147
+ * @param {Compiler} compiler - The Webpack compiler instance.
148
+ *
149
+ * @returns {void}
150
+ *
151
+ * @remarks
152
+ * This function configures the compiler options for server builds. It turns off the compiler target on node
153
+ * builds because it adds its own chunk loading runtime module with NodeFederationPlugin and StreamingTargetPlugin.
154
+ * It also disables split chunks to prevent conflicts from occurring in the graph.
155
+ *
156
+ */
157
+ function configureServerCompilerOptions(compiler) {
158
+ // Turn off the compiler target on node builds because we add our own chunk loading runtime module
159
+ // with NodeFederationPlugin and StreamingTargetPlugin
160
+ compiler.options.node = {
161
+ ...compiler.options.node,
162
+ global: false,
163
+ };
164
+ // no custom chunk rules
165
+ compiler.options.optimization.splitChunks = undefined;
166
+ // solves strange issues where next doesnt create a runtime chunk
167
+ // might be related to if an api route exists or not
168
+ compiler.options.optimization.runtimeChunk = {
169
+ name: 'webpack-runtime',
170
+ };
171
+ }
172
+ exports.configureServerCompilerOptions = configureServerCompilerOptions;
173
+ //# sourceMappingURL=apply-server-plugins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply-server-plugins.js","sourceRoot":"","sources":["../../../../../../packages/nextjs-mf/src/plugins/NextFederationPlugin/apply-server-plugins.ts"],"names":[],"mappings":";;;;;;AAEA,iIAAwH;AACxH,gDAAwB;AACxB,mGAA2E;AAC3E,0DAGqC;AACrC;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAChC,QAAkB,EAClB,OAAsC;IAEtC,gEAAgE;IAChE,MAAM,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;IACrE,MAAM,aAAa,GAAG,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC;IAC9D,MAAM,UAAU,GAAG,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IACzE,IACE,OAAO,aAAa,KAAK,QAAQ;QACjC,UAAU;QACV,CAAC,aAAa,CAAC,QAAQ,CAAC,UAAU,CAAC,EACnC;QACA,MAAM,MAAM,GAAG,iBAAiB,CAAC;QACjC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,aAAa,GAAG,aAAa,CAAC,OAAO,CAC3D,KAAK,EACL,MAAM,CACP,CAAC;KACH;IACD,iDAAiD;IACjD,YAAY;IACZ,IAAI,yDAAwB,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAE/C,2FAA2F;IAC3F,IAAI,qBAAqB,CAAC,OAAO,EAAE;QACjC,sBAAsB,EAAE,iCAAsB;KAC/C,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAEnB,0DAA0D;IAC1D,IAAI,iCAAuB,CAAC;QAC1B,OAAO,EAAE,iBAAiB;QAC1B,SAAS,EAAE,OAAO,CAAC,IAAI;QACvB,YAAY,EAAE,gBAAgB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AQ,CAAC,OAAO,CAAC,IAAI;QACxB,MAAM,EAAE,KAAK;KACd,CAAC;IACF,wBAAwB;IACxB,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC,WAAW,GAAG,SAAS,CAAC;IAEtD,iEAAiE;IACjE,oDAAoD;IACpD,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC,YAAY,GAAG;QAC3C,IAAI,EAAE,iBAAiB;KACxB,CAAC;AACJ,CAAC;AAfD,wEAeC"}
@@ -0,0 +1,30 @@
1
+ import type { NextFederationPluginOptions } from '@module-federation/utilities';
2
+ import type { Compiler } from 'webpack';
3
+ /**
4
+ * NextFederationPlugin is a webpack plugin that handles Next.js application federation using Module Federation.
5
+ */
6
+ export declare class NextFederationPlugin {
7
+ private _options;
8
+ private _extraOptions;
9
+ name: string;
10
+ /**
11
+ * Constructs the NextFederationPlugin with the provided options.
12
+ *
13
+ * @param options The options to configure the plugin.
14
+ */
15
+ constructor(options: NextFederationPluginOptions);
16
+ /**
17
+ * The apply method is called by the webpack compiler and allows the plugin to hook into the webpack process.
18
+ * @param compiler The webpack compiler object.
19
+ */
20
+ apply(compiler: Compiler): void;
21
+ private validateOptions;
22
+ private isServerCompiler;
23
+ private applyConditionalPlugins;
24
+ private getNormalFederationPluginOptions;
25
+ private getNoopPath;
26
+ private applyClientFederationPlugins;
27
+ private applyServerFederationPlugins;
28
+ private applyModuleFederationPlugins;
29
+ }
30
+ export default NextFederationPlugin;
@@ -0,0 +1,148 @@
1
+ /**
2
+ * MIT License http://www.opensource.org/licenses/mit-license.php
3
+ * Author Zackary Jackson @ScriptedAlchemy
4
+ * This module contains the NextFederationPlugin class which is a webpack plugin that handles Next.js application federation using Module Federation.
5
+ */
6
+ 'use strict';
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.NextFederationPlugin = void 0;
12
+ const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
13
+ const CopyFederationPlugin_1 = __importDefault(require("../CopyFederationPlugin"));
14
+ const nextPageMapLoader_1 = require("../../loaders/nextPageMapLoader");
15
+ const next_fragments_1 = require("./next-fragments");
16
+ const set_options_1 = require("./set-options");
17
+ const validate_options_1 = require("./validate-options");
18
+ const apply_server_plugins_1 = require("./apply-server-plugins");
19
+ const apply_client_plugins_1 = require("./apply-client-plugins");
20
+ const enhanced_1 = require("@module-federation/enhanced");
21
+ const path_1 = __importDefault(require("path"));
22
+ /**
23
+ * NextFederationPlugin is a webpack plugin that handles Next.js application federation using Module Federation.
24
+ */
25
+ class NextFederationPlugin {
26
+ /**
27
+ * Constructs the NextFederationPlugin with the provided options.
28
+ *
29
+ * @param options The options to configure the plugin.
30
+ */
31
+ constructor(options) {
32
+ const { mainOptions, extraOptions } = (0, set_options_1.setOptions)(options);
33
+ this._options = mainOptions;
34
+ this._extraOptions = extraOptions;
35
+ this.name = 'ModuleFederationPlugin';
36
+ }
37
+ /**
38
+ * The apply method is called by the webpack compiler and allows the plugin to hook into the webpack process.
39
+ * @param compiler The webpack compiler object.
40
+ */
41
+ apply(compiler) {
42
+ process.env['FEDERATION_WEBPACK_PATH'] = (0, normalize_webpack_path_1.getWebpackPath)(compiler);
43
+ if (!this.validateOptions(compiler))
44
+ return;
45
+ const isServer = this.isServerCompiler(compiler);
46
+ new CopyFederationPlugin_1.default(isServer).apply(compiler);
47
+ this.applyConditionalPlugins(compiler, isServer);
48
+ const normalFederationPluginOptions = this.getNormalFederationPluginOptions(compiler, isServer);
49
+ this.applyModuleFederationPlugins(compiler, normalFederationPluginOptions, isServer);
50
+ }
51
+ validateOptions(compiler) {
52
+ const compilerValid = (0, validate_options_1.validateCompilerOptions)(compiler);
53
+ const pluginValid = (0, validate_options_1.validatePluginOptions)(this._options);
54
+ const envValid = process.env['NEXT_PRIVATE_LOCAL_WEBPACK'];
55
+ if (compilerValid === undefined)
56
+ console.error('Compiler validation failed');
57
+ if (pluginValid === undefined)
58
+ console.error('Plugin validation failed');
59
+ const validCompilerTarget = compiler.options.name === 'server' || compiler.options.name === 'client';
60
+ if (!envValid)
61
+ throw new Error('process.env.NEXT_PRIVATE_LOCAL_WEBPACK is not set to true, please set it to true, and "npm install webpack"');
62
+ return (compilerValid !== undefined &&
63
+ pluginValid !== undefined &&
64
+ validCompilerTarget);
65
+ }
66
+ isServerCompiler(compiler) {
67
+ return compiler.options.name === 'server';
68
+ }
69
+ applyConditionalPlugins(compiler, isServer) {
70
+ compiler.options.output.uniqueName = this._options.name;
71
+ (0, next_fragments_1.applyPathFixes)(compiler, this._extraOptions);
72
+ if (this._extraOptions.debug) {
73
+ compiler.options.devtool = false;
74
+ }
75
+ if (isServer) {
76
+ (0, apply_server_plugins_1.configureServerCompilerOptions)(compiler);
77
+ (0, apply_server_plugins_1.configureServerLibraryAndFilename)(this._options);
78
+ (0, apply_server_plugins_1.applyServerPlugins)(compiler, this._options);
79
+ (0, apply_server_plugins_1.handleServerExternals)(compiler, {
80
+ ...this._options,
81
+ shared: { ...(0, next_fragments_1.retrieveDefaultShared)(isServer), ...this._options.shared },
82
+ });
83
+ }
84
+ else {
85
+ (0, apply_client_plugins_1.applyClientPlugins)(compiler, this._options, this._extraOptions);
86
+ }
87
+ }
88
+ getNormalFederationPluginOptions(compiler, isServer) {
89
+ const defaultShared = (0, next_fragments_1.retrieveDefaultShared)(isServer);
90
+ const noop = this.getNoopPath();
91
+ return {
92
+ ...this._options,
93
+ runtime: false,
94
+ remoteType: 'script',
95
+ // @ts-ignore
96
+ runtimePlugins: [
97
+ //@ts-ignore
98
+ ...(this._options.runtimePlugins || []),
99
+ require.resolve(path_1.default.join(__dirname, '../container/runtimePlugin')),
100
+ ],
101
+ exposes: {
102
+ './noop': noop,
103
+ './react': require.resolve('react'),
104
+ './react-dom': require.resolve('react-dom'),
105
+ './next/router': require.resolve('next/router'),
106
+ ...this._options.exposes,
107
+ ...(this._extraOptions.exposePages
108
+ ? (0, nextPageMapLoader_1.exposeNextjsPages)(compiler.options.context)
109
+ : {}),
110
+ },
111
+ remotes: {
112
+ ...this._options.remotes,
113
+ // ...(this._options.name ? { [this._options.name]: `internal webpack/container/entry/${this._options.name}` } : {}),
114
+ },
115
+ shared: {
116
+ ...defaultShared,
117
+ ...this._options.shared,
118
+ },
119
+ };
120
+ }
121
+ getNoopPath() {
122
+ let noop;
123
+ try {
124
+ noop = require.resolve('../../federation-noop');
125
+ }
126
+ catch (e) {
127
+ noop = require.resolve('../../federation-noop.cjs');
128
+ }
129
+ return noop;
130
+ }
131
+ applyClientFederationPlugins(compiler, normalFederationPluginOptions) {
132
+ new enhanced_1.ModuleFederationPlugin(normalFederationPluginOptions).apply(compiler);
133
+ }
134
+ applyServerFederationPlugins(compiler, normalFederationPluginOptions) {
135
+ new enhanced_1.ModuleFederationPlugin(normalFederationPluginOptions).apply(compiler);
136
+ }
137
+ applyModuleFederationPlugins(compiler, normalFederationPluginOptions, isServer) {
138
+ if (!isServer) {
139
+ this.applyClientFederationPlugins(compiler, normalFederationPluginOptions);
140
+ }
141
+ else {
142
+ this.applyServerFederationPlugins(compiler, normalFederationPluginOptions);
143
+ }
144
+ }
145
+ }
146
+ exports.NextFederationPlugin = NextFederationPlugin;
147
+ exports.default = NextFederationPlugin;
148
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/nextjs-mf/src/plugins/NextFederationPlugin/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,YAAY,CAAC;;;;;;AAQb,0FAA+E;AAC/E,mFAA2D;AAC3D,uEAAoE;AACpE,qDAAyE;AACzE,+CAA2C;AAC3C,yDAG4B;AAC5B,iEAKgC;AAChC,iEAA4D;AAC5D,0DAAqE;AACrE,gDAAwB;AACxB;;GAEG;AACH,MAAa,oBAAoB;IAI/B;;;;OAIG;IACH,YAAY,OAAoC;QAC9C,MAAM,EAAE,WAAW,EAAE,Y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D,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,4BAA4B,CAClC,QAAkB,EAClB,6BAA4D;QAE5D,IAAI,iCAAsB,CACxB,6BAA6B,CAE9B,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACpB,CAAC;IAEO,4BAA4B,CAClC,QAAkB,EAClB,6BAA4D;QAE5D,IAAI,iCAAsB,CACxB,6BAA6B,CAE9B,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACpB,CAAC;IAEO,4BAA4B,CAClC,QAAkB,EAClB,6BAA4D,EAC5D,QAAiB;QAEjB,IAAI,CAAC,QAAQ,EAAE;YACb,IAAI,CAAC,4BAA4B,CAC/B,QAAQ,EACR,6BAA6B,CAC9B,CAAC;SACH;aAAM;YACL,IAAI,CAAC,4BAA4B,CAC/B,QAAQ,EACR,6BAA6B,CAC9B,CAAC;SACH;IACH,CAAC;CACF;AApKD,oDAoKC;AAED,kBAAe,oBAAoB,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { Compiler } from 'webpack';
2
+ import type { SharedObject } from '@module-federation/utilities';
3
+ /**
4
+ * Set up default shared values based on the environment.
5
+ * @param {boolean} isServer - Boolean indicating if the code is running on the server.
6
+ * @returns {SharedObject} The default share scope based on the environment.
7
+ */
8
+ export declare const retrieveDefaultShared: (isServer: boolean) => SharedObject;
9
+ /**
10
+ * Apply path fixes.
11
+ *
12
+ * This function applies fixes to the path for certain loaders. It checks if the fix is enabled in the options
13
+ * and if the loader is present in the rule. If both conditions are met, it injects the fix loader.
14
+ *
15
+ * @param {Compiler} compiler - The Webpack compiler instance.
16
+ * @param {any} options - The ModuleFederationPluginOptions instance.
17
+ */
18
+ export declare const applyPathFixes: (compiler: Compiler, options: any) => void;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyPathFixes = exports.retrieveDefaultShared = void 0;
4
+ const internal_1 = require("../../internal");
5
+ const helpers_1 = require("../../loaders/helpers");
6
+ /**
7
+ * Set up default shared values based on the environment.
8
+ * @param {boolean} isServer - Boolean indicating if the code is running on the server.
9
+ * @returns {SharedObject} The default share scope based on the environment.
10
+ */
11
+ const retrieveDefaultShared = (isServer) => {
12
+ // If the code is running on the server, treat some Next.js internals as import false to make them external
13
+ // This is because they will be provided by the server environment and not by the remote container
14
+ if (isServer) {
15
+ return internal_1.DEFAULT_SHARE_SCOPE;
16
+ }
17
+ // If the code is running on the client/browser, always bundle Next.js internals
18
+ return internal_1.DEFAULT_SHARE_SCOPE_BROWSER;
19
+ };
20
+ exports.retrieveDefaultShared = retrieveDefaultShared;
21
+ /**
22
+ * Apply path fixes.
23
+ *
24
+ * This function applies fixes to the path for certain loaders. It checks if the fix is enabled in the options
25
+ * and if the loader is present in the rule. If both conditions are met, it injects the fix loader.
26
+ *
27
+ * @param {Compiler} compiler - The Webpack compiler instance.
28
+ * @param {any} options - The ModuleFederationPluginOptions instance.
29
+ */
30
+ const applyPathFixes = (compiler, options) => {
31
+ //@ts-ignore
32
+ compiler.options.module.rules.forEach((rule) => {
33
+ // next-image-loader fix which adds remote's hostname to the assets url
34
+ //@ts-ignore
35
+ if (options.enableImageLoaderFix && (0, helpers_1.hasLoader)(rule, 'next-image-loader')) {
36
+ // childCompiler.options.module.parser.javascript?.url = 'relative';
37
+ //@ts-ignore
38
+ (0, helpers_1.injectRuleLoader)(rule, {
39
+ loader: require.resolve('../../loaders/fixImageLoader'),
40
+ });
41
+ }
42
+ // url-loader fix for which adds remote's hostname to the assets url
43
+ //@ts-ignore
44
+ if (options.enableUrlLoaderFix && (0, helpers_1.hasLoader)(rule, 'url-loader')) {
45
+ (0, helpers_1.injectRuleLoader)({
46
+ loader: require.resolve('../../loaders/fixUrlLoader'),
47
+ });
48
+ }
49
+ //@ts-ignore
50
+ if (rule?.oneOf) {
51
+ //@ts-ignore
52
+ rule.oneOf.forEach((oneOfRule) => {
53
+ if ((0, helpers_1.hasLoader)(oneOfRule, 'react-refresh-utils')) {
54
+ oneOfRule.exclude = [
55
+ oneOfRule.exclude,
56
+ /enhanced\/src/,
57
+ /nextjs-mf\/src/,
58
+ ];
59
+ }
60
+ });
61
+ }
62
+ });
63
+ };
64
+ exports.applyPathFixes = applyPathFixes;
65
+ //# sourceMappingURL=next-fragments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-fragments.js","sourceRoot":"","sources":["../../../../../../packages/nextjs-mf/src/plugins/NextFederationPlugin/next-fragments.ts"],"names":[],"mappings":";;;AAKA,6CAIwB;AACxB,mDAAoE;AAEpE;;;;GAIG;AACI,MAAM,qBAAqB,GAAG,CAAC,QAAiB,EAAgB,EAAE;IACvE,2GAA2G;IAC3G,kGAAkG;IAClG,IAAI,QAAQ,EAAE;QACZ,OAAO,8BAAmB,CAAC;KAC5B;IACD,gFAAgF;IAChF,OAAO,sCAA2B,CAAC;AACrC,CAAC,CAAC;AARW,QAAA,qBAAqB,yBAQhC;AAEF;;;;;;;;GAQG;AACI,MAAM,cAAc,GAAG,CAAC,QAAkB,EAAE,OAAY,EAAE,EAAE;IACjE,YAAY;IACZ,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC7C,uEAAuE;QACvE,YAAY;QACZ,IAAI,OAAO,CAAC,oBAAoB,IAAI,IAAA,mBAAS,EAAC,IAAI,EAAE,mBAAmB,CAAC,EAAE;YACxE,oEAAoE;YACpE,YAAY;YACZ,IAAA,0BAAgB,EAAC,IAAI,EAAE;gBACrB,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,8BAA8B,CAAC;aACxD,CAAC,CAAC;SACJ;QAED,oEAAoE;QACpE,YAAY;QACZ,IAAI,OAAO,CAAC,kBAAkB,IAAI,IAAA,mBAAS,EAAC,IAAI,EAAE,YAAY,CAAC,EAAE;YAC/D,IAAA,0BAAgB,EAAC;gBACf,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,4BAA4B,CAAC;aACtD,CAAC,CAAC;SACJ;QACD,YAAY;QACZ,IAAI,IAAI,EAAE,KAAK,EAAE;YACf,YAAY;YACZ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;gBAC/B,IAAI,IAAA,mBAAS,EAAC,SAAS,EAAE,qBAAqB,CAAC,EAAE;oBAC/C,SAAS,CAAC,OAAO,GAAG;wBAClB,SAAS,CAAC,OAAO;wBACjB,eAAe;wBACf,gBAAgB;qBACjB,CAAC;iBACH;YACH,CAAC,CAAC,CAAC;SACJ;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAlCW,QAAA,cAAc,kBAkCzB"}
@@ -0,0 +1,14 @@
1
+ import type { RuleSetConditionAbsolute } from 'webpack';
2
+ /**
3
+ * Compares two regular expressions or other types of conditions to see if they are equal.
4
+ *
5
+ * @param x - The first condition to compare. It can be a string, a RegExp, a function that takes a string and returns a boolean, an array of RuleSetConditionAbsolute, or undefined.
6
+ * @param y - The second condition to compare. It is always a RegExp.
7
+ * @returns True if the conditions are equal, false otherwise.
8
+ *
9
+ * @remarks
10
+ * This function compares two conditions to see if they are equal in terms of their source,
11
+ * global, ignoreCase, and multiline properties. It is used to check if two conditions match
12
+ * the same pattern. If the first condition is not a RegExp, the function will always return false.
13
+ */
14
+ export declare const regexEqual: (x: string | RegExp | ((value: string) => boolean) | RuleSetConditionAbsolute[] | undefined, y: RegExp) => boolean;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.regexEqual = void 0;
4
+ /**
5
+ * Compares two regular expressions or other types of conditions to see if they are equal.
6
+ *
7
+ * @param x - The first condition to compare. It can be a string, a RegExp, a function that takes a string and returns a boolean, an array of RuleSetConditionAbsolute, or undefined.
8
+ * @param y - The second condition to compare. It is always a RegExp.
9
+ * @returns True if the conditions are equal, false otherwise.
10
+ *
11
+ * @remarks
12
+ * This function compares two conditions to see if they are equal in terms of their source,
13
+ * global, ignoreCase, and multiline properties. It is used to check if two conditions match
14
+ * the same pattern. If the first condition is not a RegExp, the function will always return false.
15
+ */
16
+ const regexEqual = (x, y) => {
17
+ return (x instanceof RegExp &&
18
+ y instanceof RegExp &&
19
+ x.source === y.source &&
20
+ x.global === y.global &&
21
+ x.ignoreCase === y.ignoreCase &&
22
+ x.multiline === y.multiline);
23
+ };
24
+ exports.regexEqual = regexEqual;
25
+ //# sourceMappingURL=regex-equal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regex-equal.js","sourceRoot":"","sources":["../../../../../../packages/nextjs-mf/src/plugins/NextFederationPlugin/regex-equal.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;GAWG;AACI,MAAM,UAAU,GAAG,CACxB,CAKa,EACb,CAAS,EACA,EAAE;IACX,OAAO,CACL,CAAC,YAAY,MAAM;QACnB,CAAC,YAAY,MAAM;QACnB,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QACrB,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QACrB,CAAC,CAAC,UAAU,KAAK,CAAC,CAAC,UAAU;QAC7B,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,SAAS,CAC5B,CAAC;AACJ,CAAC,CAAC;AAjBW,QAAA,UAAU,cAiBrB"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Function to remove unnecessary shared keys from the default share scope.
3
+ * It iterates over each key in the shared object and checks against the default share scope.
4
+ * If a key is found in the default share scope, a warning is logged and the key is removed from the shared object.
5
+ *
6
+ * @param {Record<string, unknown>} shared - The shared object to be checked.
7
+ */
8
+ export declare function removeUnnecessarySharedKeys(shared: Record<string, unknown>): void;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeUnnecessarySharedKeys = void 0;
4
+ /**
5
+ * Utility function to remove unnecessary shared keys from the default share scope.
6
+ * It checks each key in the shared object against the default share scope.
7
+ * If a key is found in the default share scope, a warning is logged and the key is removed from the shared object.
8
+ *
9
+ * @param {Record<string, unknown>} shared - The shared object to be checked.
10
+ */
11
+ const internal_1 = require("../../internal");
12
+ /**
13
+ * Function to remove unnecessary shared keys from the default share scope.
14
+ * It iterates over each key in the shared object and checks against the default share scope.
15
+ * If a key is found in the default share scope, a warning is logged and the key is removed from the shared object.
16
+ *
17
+ * @param {Record<string, unknown>} shared - The shared object to be checked.
18
+ */
19
+ function removeUnnecessarySharedKeys(shared) {
20
+ Object.keys(shared).forEach((key) => {
21
+ /**
22
+ * If the key is found in the default share scope, log a warning and remove the key from the shared object.
23
+ */
24
+ if (internal_1.DEFAULT_SHARE_SCOPE[key]) {
25
+ console.warn(`%c[nextjs-mf] You are sharing ${key} from the default share scope. This is not necessary and can be removed.`, 'color: red');
26
+ delete shared[key];
27
+ }
28
+ });
29
+ }
30
+ exports.removeUnnecessarySharedKeys = removeUnnecessarySharedKeys;
31
+ //# sourceMappingURL=remove-unnecessary-shared-keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-unnecessary-shared-keys.js","sourceRoot":"","sources":["../../../../../../packages/nextjs-mf/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,6CAAqD;AAErD;;;;;;GAMG;AACH,SAAgB,2BAA2B,CACzC,MAA+B;IAE/B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,GAAW,EAAE,EAAE;QAC1C;;WAEG;QACH,IAAI,8BAAmB,CAAC,GAAG,CAAC,EAAE;YAC5B,OAAO,CAAC,IAAI,CACV,iCAAiC,GAAG,0EAA0E,EAC9G,YAAY,CACb,CAAC;YACF,OAAQ,MAAqC,CAAC,GAAG,CAAC,CAAC;SACpD;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAfD,kEAeC"}
@@ -0,0 +1,20 @@
1
+ import { ModuleFederationPluginOptions, NextFederationPluginExtraOptions, NextFederationPluginOptions } from '@module-federation/utilities';
2
+ /**
3
+ * This function sets the main and extra options for NextFederationPlugin. It splits the options object into
4
+ * the main options and extra options, and sets default values for any options that are not defined.
5
+ *
6
+ * @param {NextFederationPluginOptions} options - The options for NextFederationPlugin.
7
+ * @returns {Object} An object containing the main options and extra options.
8
+ *
9
+ * @remarks
10
+ * The default extra options are:
11
+ * - automaticPageStitching: false
12
+ * - enableImageLoaderFix: false
13
+ * - enableUrlLoaderFix: false
14
+ * - skipSharingNextInternals: false
15
+ * - debug: false
16
+ */
17
+ export declare function setOptions(options: NextFederationPluginOptions): {
18
+ mainOptions: ModuleFederationPluginOptions;
19
+ extraOptions: NextFederationPluginExtraOptions;
20
+ };
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setOptions = void 0;
4
+ /**
5
+ * This function sets the main and extra options for NextFederationPlugin. It splits the options object into
6
+ * the main options and extra options, and sets default values for any options that are not defined.
7
+ *
8
+ * @param {NextFederationPluginOptions} options - The options for NextFederationPlugin.
9
+ * @returns {Object} An object containing the main options and extra options.
10
+ *
11
+ * @remarks
12
+ * The default extra options are:
13
+ * - automaticPageStitching: false
14
+ * - enableImageLoaderFix: false
15
+ * - enableUrlLoaderFix: false
16
+ * - skipSharingNextInternals: false
17
+ * - debug: false
18
+ */
19
+ function setOptions(options) {
20
+ const { extraOptions, ...mainOpts } = options;
21
+ /**
22
+ * Default extra options for NextFederationPlugin.
23
+ * @type {NextFederationPluginExtraOptions}
24
+ */
25
+ const defaultExtraOptions = {
26
+ automaticPageStitching: false,
27
+ enableImageLoaderFix: false,
28
+ enableUrlLoaderFix: false,
29
+ skipSharingNextInternals: false,
30
+ debug: false,
31
+ };
32
+ return {
33
+ mainOptions: mainOpts,
34
+ extraOptions: { ...defaultExtraOptions, ...extraOptions },
35
+ };
36
+ }
37
+ exports.setOptions = setOptions;
38
+ //# sourceMappingURL=set-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set-options.js","sourceRoot":"","sources":["../../../../../../packages/nextjs-mf/src/plugins/NextFederationPlugin/set-options.ts"],"names":[],"mappings":";;;AAMA;;;;;;;;;;;;;;GAcG;AACH,SAAgB,UAAU,CAAC,OAAoC;IAI7D,MAAM,EAAE,YAAY,EAAE,GAAG,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE9C;;;OAGG;IACH,MAAM,mBAAmB,GAAqC;QAC5D,sBAAsB,EAAE,KAAK;QAC7B,oBAAoB,EAAE,KAAK;QAC3B,kBAAkB,EAAE,KAAK;QACzB,wBAAwB,EAAE,KAAK;QAC/B,KAAK,EAAE,KAAK;KACb,CAAC;IAEF,OAAO;QACL,WAAW,EAAE,QAAQ;QACrB,YAAY,EAAE,EAAE,GAAG,mBAAmB,EAAE,GAAG,YAAY,EAAE;KAC1D,CAAC;AACJ,CAAC;AAtBD,gCAsBC"}
@@ -0,0 +1,25 @@
1
+ import type { Compiler } from 'webpack';
2
+ import { ModuleFederationPluginOptions } from '@module-federation/utilities';
3
+ /**
4
+ * Validates the compiler options.
5
+ *
6
+ * @param {Compiler} compiler - The Webpack compiler instance.
7
+ * @returns {boolean} - Returns true if the compiler options are valid, false otherwise.
8
+ *
9
+ * @throws Will throw an error if the name option is not defined in the options.
10
+ * @remarks
11
+ * This function validates the options passed to the Webpack compiler. It checks if the name option is set to either "server" or
12
+ * "client", as Module Federation is only applied to the main server and client builds in Next.js.
13
+ */
14
+ export declare function validateCompilerOptions(compiler: Compiler): boolean;
15
+ /**
16
+ * Validates the NextFederationPlugin options.
17
+ *
18
+ * @param {ModuleFederationPluginOptions} options - The ModuleFederationPluginOptions instance.
19
+ *
20
+ * @throws Will throw an error if the filename option is not defined in the options or if the name option is not specified.
21
+ * @remarks
22
+ * This function validates the options passed to NextFederationPlugin. It ensures that the filename and name options are defined,
23
+ * as they are required for using Module Federation.
24
+ */
25
+ export declare function validatePluginOptions(options: ModuleFederationPluginOptions): boolean | void;