@module-federation/nextjs-mf 8.4.13 → 8.5.0

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 (37) hide show
  1. package/dist/package.json +3 -2
  2. package/dist/src/internal.d.ts +3 -3
  3. package/dist/src/internal.js.map +1 -1
  4. package/dist/src/loaders/fixImageLoader.js +4 -4
  5. package/dist/src/loaders/fixImageLoader.js.map +1 -1
  6. package/dist/src/loaders/helpers.d.ts +11 -11
  7. package/dist/src/loaders/helpers.js +84 -9
  8. package/dist/src/loaders/helpers.js.map +1 -1
  9. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.d.ts +6 -6
  10. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.js +9 -14
  11. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.js.map +1 -1
  12. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.d.ts +18 -42
  13. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.js +43 -63
  14. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.js.map +1 -1
  15. package/dist/src/plugins/NextFederationPlugin/index.js +24 -5
  16. package/dist/src/plugins/NextFederationPlugin/index.js.map +1 -1
  17. package/dist/src/plugins/NextFederationPlugin/next-fragments.d.ts +3 -12
  18. package/dist/src/plugins/NextFederationPlugin/next-fragments.js +90 -27
  19. package/dist/src/plugins/NextFederationPlugin/next-fragments.js.map +1 -1
  20. package/dist/src/plugins/NextFederationPlugin/set-options.d.ts +3 -2
  21. package/dist/src/plugins/NextFederationPlugin/set-options.js.map +1 -1
  22. package/dist/src/plugins/NextFederationPlugin/validate-options.d.ts +3 -3
  23. package/dist/src/plugins/NextFederationPlugin/validate-options.js +1 -1
  24. package/dist/src/plugins/NextFederationPlugin/validate-options.js.map +1 -1
  25. package/dist/src/plugins/container/InvertedContainerPlugin.js +0 -7
  26. package/dist/src/plugins/container/InvertedContainerPlugin.js.map +1 -1
  27. package/dist/src/plugins/container/InvertedContainerRuntimeModule.js +0 -1
  28. package/dist/src/plugins/container/InvertedContainerRuntimeModule.js.map +1 -1
  29. package/dist/src/plugins/container/runtimePlugin.js +70 -49
  30. package/dist/src/plugins/container/runtimePlugin.js.map +1 -1
  31. package/dist/utils/index.d.ts +0 -1
  32. package/dist/utils/index.js +7 -14
  33. package/dist/utils/index.js.map +1 -1
  34. package/package.json +7 -6
  35. package/dist/utils/build-utils.d.ts +0 -10
  36. package/dist/utils/build-utils.js +0 -24
  37. package/dist/utils/build-utils.js.map +0 -1
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/nextjs-mf",
3
- "version": "8.4.13",
3
+ "version": "8.5.0",
4
4
  "license": "MIT",
5
5
  "main": "./src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -43,7 +43,8 @@
43
43
  "@module-federation/runtime": "workspace:*",
44
44
  "@module-federation/sdk": "workspace:*",
45
45
  "@module-federation/enhanced": "workspace:*",
46
- "@module-federation/node": "workspace:*"
46
+ "@module-federation/node": "workspace:*",
47
+ "@module-federation/webpack-bundler-runtime": "workspace:*"
47
48
  },
48
49
  "peerDependencies": {
49
50
  "webpack": "^5.40.0",
@@ -1,4 +1,4 @@
1
- import type { SharedObject } from '@module-federation/utilities';
1
+ import type { sharePlugin } from '@module-federation/sdk';
2
2
  /**
3
3
  * @typedef SharedObject
4
4
  * @type {object}
@@ -8,7 +8,7 @@ import type { SharedObject } from '@module-federation/utilities';
8
8
  * @property {boolean} key.eager - Whether the shared object should be eagerly loaded.
9
9
  * @property {boolean} key.import - Whether the shared object should be imported or not.
10
10
  */
11
- export declare const DEFAULT_SHARE_SCOPE: SharedObject;
11
+ export declare const DEFAULT_SHARE_SCOPE: sharePlugin.SharedObject;
12
12
  /**
13
13
  * Defines a default share scope for the browser environment.
14
14
  * This function takes the DEFAULT_SHARE_SCOPE and sets eager to undefined and import to undefined for all entries.
@@ -18,7 +18,7 @@ export declare const DEFAULT_SHARE_SCOPE: SharedObject;
18
18
  * @type {SharedObject}
19
19
  * @returns {SharedObject} - The modified share scope for the browser environment.
20
20
  */
21
- export declare const DEFAULT_SHARE_SCOPE_BROWSER: SharedObject;
21
+ export declare const DEFAULT_SHARE_SCOPE_BROWSER: sharePlugin.SharedObject;
22
22
  /**
23
23
  * Parses the remotes object and checks if they are using a custom promise template or not.
24
24
  * If it's a custom promise template, the remote syntax is parsed to get the module name and version number.
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;GAQG;AACU,QAAA,mBAAmB,GAAiB;IAC/C,cAAc,EAAE;QACd,eAAe,EAAE,SAAS;QAC1B,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,SAAS;KAClB;IACD,WAAW,EAAE;QACX,eAAe,EAAE,SAAS;QAC1B,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,SAAS;KAClB;IACD,WAAW,EAAE;QACX,eAAe,EAAE,SAAS;QAC1B,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,SAAS;KAClB;IACD,aAAa,EAAE;QACb,eAAe,EAAE,KAAK;QACtB,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,SAAS;KAClB;IACD,YAAY,EAAE;QACZ,eAAe,EAAE,SAAS;QAC1B,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,SAAS;KAClB;IACD,aAAa,EAAE;QACb,eAAe,EAAE,SAAS;QAC1B,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,SAAS;KAClB;IACD,KAAK,EAAE;QACL,SAAS,EAAE,IAAI;QACf,eAAe,EAAE,KAAK;QACtB,MAAM,EAAE,KAAK;KACd;IACD,QAAQ,EAAE;QACR,SAAS,EAAE,IAAI;QACf,eAAe,EAAE,KAAK;QACtB,MAAM,EAAE,KAAK;KACd;IACD,YAAY,EAAE;QACZ,SAAS,EAAE,IAAI;QACf,eAAe,EAAE,KAAK;QACtB,MAAM,EAAE,KAAK;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G,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,EAC5D,EAAE,CACH,CAAC;AAPS,QAAA,YAAY,gBAOrB;AAEJ;;;;;;GAMG;AACH,MAAM,WAAW,GAAG,CAAC,KAAY,EAAU,EAAE;IAC3C,IAAI,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IACxB,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAChB,OAAO,IAAI,KAAK,KAAK,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF;;;;;;GAMG;AACI,MAAM,eAAe,GAAG,CAAC,GAAY,EAAU,EAAE;IACtD,OAAO,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzC,CAAC,CAAC;AAFW,QAAA,eAAe,mBAE1B"}
@@ -26,9 +26,8 @@ const path_1 = __importDefault(require("path"));
26
26
  */
27
27
  async function fixImageLoader(remaining) {
28
28
  this.cacheable(true);
29
- const isServer = this._compiler?.options.name !== 'client';
30
- //@ts-ignore
31
- const { publicPath } = this._compiler.webpack.RuntimeGlobals;
29
+ const isServer = this._compiler?.options?.name !== 'client';
30
+ const publicPath = this._compiler?.webpack?.RuntimeGlobals?.publicPath ?? '';
32
31
  const result = await this.importModule(`${this.resourcePath}.webpack[javascript/auto]!=!${remaining}`);
33
32
  const content = (result.default || result);
34
33
  const computedAssetPrefix = isServer
@@ -76,7 +75,8 @@ async function fixImageLoader(remaining) {
76
75
  Template.indent([
77
76
  'try {',
78
77
  Template.indent([
79
- Template.indent(`return ${publicPath} && ${publicPath}.indexOf('://') > 0 ? new URL(${publicPath}).origin : ''`),
78
+ `const splitted = ${publicPath} ? ${publicPath}.split('/_next') : '';`,
79
+ `return splitted.length === 2 ? splitted[0] : '';`,
80
80
  ]),
81
81
  '} catch (e) {',
82
82
  Template.indent([
@@ -1 +1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O,GAAG,CAAC;IACb,CAAC,EACD,EAAc,CACf,CAAC;IAEF,OAAO,QAAQ,CAAC,QAAQ,CAAC;QACvB,yCAAyC;QACzC,OAAO;QACP,QAAQ,CAAC,MAAM,CAAC,mCAAmC,mBAAmB,GAAG,CAAC;QAC1E,gBAAgB;QAChB,kBAAkB;QAClB,QAAQ,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9C,GAAG;KACJ,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACU,QAAA,KAAK,GAAG,cAAc,CAAC"}
@@ -1,17 +1,17 @@
1
- import type { RuleSetRuleUnion, Loader } from '@module-federation/utilities';
2
- /**
3
- * This function injects a loader into the current module rule.
4
- * Note: This function mutates the `rule` argument.
5
- *
6
- * @param {RuleSetRuleUnion} rule - The current module rule.
7
- * @param {Loader} [loader={}] - The loader to be injected.
8
- */
9
- export declare function injectRuleLoader(rule: RuleSetRuleUnion, loader?: Loader): void;
1
+ import type { RuleSetRule, RuleSetUseItem } from 'webpack';
2
+ export declare function injectRuleLoader(rule: any, loader?: RuleSetUseItem): void;
10
3
  /**
11
4
  * This function checks if the current module rule has a loader with the provided name.
12
5
  *
13
- * @param {RuleSetRuleUnion} rule - The current module rule.
6
+ * @param {RuleSetRule} rule - The current module rule.
14
7
  * @param {string} loaderName - The name of the loader to check.
15
8
  * @returns {boolean} Returns true if the current module rule has a loader with the provided name, otherwise false.
16
9
  */
17
- export declare function hasLoader(rule: RuleSetRuleUnion, loaderName: string): boolean;
10
+ export declare function hasLoader(rule: RuleSetRule, loaderName: string): boolean;
11
+ interface Resource {
12
+ path: string;
13
+ layer?: string;
14
+ issuerLayer?: string;
15
+ }
16
+ export declare function findLoaderForResource(rules: RuleSetRule[], resource: Resource, path?: string[]): RuleSetRule | null;
17
+ export {};
@@ -2,13 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.injectRuleLoader = injectRuleLoader;
4
4
  exports.hasLoader = hasLoader;
5
- /**
6
- * This function injects a loader into the current module rule.
7
- * Note: This function mutates the `rule` argument.
8
- *
9
- * @param {RuleSetRuleUnion} rule - The current module rule.
10
- * @param {Loader} [loader={}] - The loader to be injected.
11
- */
5
+ exports.findLoaderForResource = findLoaderForResource;
12
6
  function injectRuleLoader(rule, loader = {}) {
13
7
  if (rule !== '...') {
14
8
  const _rule = rule;
@@ -25,11 +19,12 @@ function injectRuleLoader(rule, loader = {}) {
25
19
  /**
26
20
  * This function checks if the current module rule has a loader with the provided name.
27
21
  *
28
- * @param {RuleSetRuleUnion} rule - The current module rule.
22
+ * @param {RuleSetRule} rule - The current module rule.
29
23
  * @param {string} loaderName - The name of the loader to check.
30
24
  * @returns {boolean} Returns true if the current module rule has a loader with the provided name, otherwise false.
31
25
  */
32
26
  function hasLoader(rule, loaderName) {
27
+ //@ts-ignore
33
28
  if (rule !== '...') {
34
29
  const _rule = rule;
35
30
  if (_rule.loader === loaderName) {
@@ -38,7 +33,6 @@ function hasLoader(rule, loaderName) {
38
33
  else if (_rule.use && Array.isArray(_rule.use)) {
39
34
  for (let i = 0; i < _rule.use.length; i++) {
40
35
  const loader = _rule.use[i];
41
- // check exact name, eg "url-loader" or its path "node_modules/url-loader/dist/cjs.js"
42
36
  if (typeof loader !== 'string' &&
43
37
  typeof loader !== 'function' &&
44
38
  loader.loader &&
@@ -56,4 +50,85 @@ function hasLoader(rule, loaderName) {
56
50
  }
57
51
  return false;
58
52
  }
53
+ function matchesCondition(condition, resource, currentPath) {
54
+ if (condition instanceof RegExp) {
55
+ return condition.test(resource.path);
56
+ }
57
+ else if (typeof condition === 'string') {
58
+ return resource.path.includes(condition);
59
+ }
60
+ else if (typeof condition === 'function') {
61
+ return condition(resource.path);
62
+ }
63
+ else if (typeof condition === 'object') {
64
+ if ('test' in condition && condition.test) {
65
+ const tests = Array.isArray(condition.test)
66
+ ? condition.test
67
+ : [condition.test];
68
+ if (!tests.some((test) => matchesCondition(test, resource, currentPath))) {
69
+ return false;
70
+ }
71
+ }
72
+ if ('include' in condition && condition.include) {
73
+ const includes = Array.isArray(condition.include)
74
+ ? condition.include
75
+ : [condition.include];
76
+ if (!includes.some((include) => matchesCondition(include, resource, currentPath))) {
77
+ return false;
78
+ }
79
+ }
80
+ if ('exclude' in condition && condition.exclude) {
81
+ const excludes = Array.isArray(condition.exclude)
82
+ ? condition.exclude
83
+ : [condition.exclude];
84
+ if (excludes.some((exclude) => matchesCondition(exclude, resource, currentPath))) {
85
+ return false;
86
+ }
87
+ }
88
+ if ('and' in condition && condition.and) {
89
+ return condition.and.every((cond) => matchesCondition(cond, resource, currentPath));
90
+ }
91
+ if ('or' in condition && condition.or) {
92
+ return condition.or.some((cond) => matchesCondition(cond, resource, currentPath));
93
+ }
94
+ if ('not' in condition && condition.not) {
95
+ return !matchesCondition(condition.not, resource, currentPath);
96
+ }
97
+ if ('layer' in condition && condition.layer) {
98
+ if (!resource.layer ||
99
+ !matchesCondition(condition.layer, { path: resource.layer }, currentPath)) {
100
+ return false;
101
+ }
102
+ }
103
+ if ('issuerLayer' in condition && condition.issuerLayer) {
104
+ if (!resource.issuerLayer ||
105
+ !matchesCondition(condition.issuerLayer, { path: resource.issuerLayer }, currentPath)) {
106
+ return false;
107
+ }
108
+ }
109
+ }
110
+ return true;
111
+ }
112
+ function findLoaderForResource(rules, resource, path = []) {
113
+ let lastMatchedRule = null;
114
+ for (let i = 0; i < rules.length; i++) {
115
+ const rule = rules[i];
116
+ const currentPath = [...path, `rules[${i}]`];
117
+ if (rule.oneOf) {
118
+ for (let j = 0; j < rule.oneOf.length; j++) {
119
+ const subRule = rule.oneOf[j];
120
+ const subPath = [...currentPath, `oneOf[${j}]`];
121
+ if (subRule &&
122
+ matchesCondition(subRule, resource, subPath.join('->'))) {
123
+ return subRule;
124
+ }
125
+ }
126
+ }
127
+ else if (rule &&
128
+ matchesCondition(rule, resource, currentPath.join(' -> '))) {
129
+ lastMatchedRule = rule;
130
+ }
131
+ }
132
+ return lastMatchedRule;
133
+ }
59
134
  //# sourceMappingURL=helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/loaders/helpers.ts"],"names":[],"mappings":";;AASA,4CAeC;AASD,8BA8BC;AA7DD;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAAC,IAAsB,EAAE,SAAiB,EAAE;IAC1E,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;QACnB,MAAM,KAAK,GAAG,IAIb,CAAC;QACF,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;YACjB,KAAK,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YACvE,OAAO,KAAK,CAAC,MAAM,CAAC;YACpB,OAAO,KAAK,CAAC,OAAO,CAAC;QACvB,CAAC;aAAM,IAAI,KAAK,CAAC,GAAG,EAAE,CAAC;YACrB,KAAK,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,GAAI,KAAK,CAAC,GAAa,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,SAAS,CAAC,IAAsB,EAAE,UAAkB;IAClE,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;QACnB,MAAM,KAAK,GAAG,IAIb,CAAC;QACF,IAAI,KAAK,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;YAChC,OAAO,IAAI,CAAC;QACd,CAAC;aAAM,IAAI,KAAK,CAAC,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YACjD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC1C,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,C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AG,IAAI,CAAC;QACzB,CAAC;IACH,CAAC;IACD,OAAO,eAAe,CAAC;AACzB,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import type { Compiler } from 'webpack';
2
- import { ModuleFederationPluginOptions, NextFederationPluginExtraOptions } from '@module-federation/utilities';
2
+ import { NextFederationPluginExtraOptions } from '@module-federation/utilities';
3
+ import type { moduleFederationPlugin } from '@module-federation/sdk';
3
4
  /**
4
5
  * Applies client-specific plugins.
5
6
  *
@@ -11,13 +12,12 @@ import { ModuleFederationPluginOptions, NextFederationPluginExtraOptions } from
11
12
  * This function applies plugins to the Webpack compiler instance that are specific to the client build of
12
13
  * a Next.js application with Module Federation enabled. These plugins include the following:
13
14
  *
14
- * - DelegateModulesPlugin: Delegates modules to the webpack container runtime that can be streamed to other runtimes.
15
15
  * - ChunkCorrelationPlugin: Collects metadata on chunks to enable proper module loading across different runtimes.
16
16
  * - InvertedContainerPlugin: Adds custom runtime modules to the container runtime to allow a host to expose its
17
17
  * own remote interface at startup.
18
- *
19
- * If automatic page stitching is enabled, a loader is added to process the `next/dist/client/page-loader.js`
20
- * file. If a custom library is specified in the options, an error is thrown. The options.library property is
18
+
19
+ * If automatic page stitching is enabled, a warning is logged indicating that it is disabled in v7.
20
+ * If a custom library is specified in the options, an error is logged. The options.library property is
21
21
  * also set to `{ type: 'window', name: options.name }`.
22
22
  */
23
- export declare function applyClientPlugins(compiler: Compiler, options: ModuleFederationPluginOptions, extraOptions: NextFederationPluginExtraOptions): void;
23
+ export declare function applyClientPlugins(compiler: Compiler, options: moduleFederationPlugin.ModuleFederationPluginOptions, extraOptions: NextFederationPluginExtraOptions): void;
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.applyClientPlugins = applyClientPlugins;
7
7
  const node_1 = require("@module-federation/node");
8
8
  const InvertedContainerPlugin_1 = __importDefault(require("../container/InvertedContainerPlugin"));
9
- const enhanced_1 = require("@module-federation/enhanced");
10
9
  /**
11
10
  * Applies client-specific plugins.
12
11
  *
@@ -18,26 +17,25 @@ const enhanced_1 = require("@module-federation/enhanced");
18
17
  * This function applies plugins to the Webpack compiler instance that are specific to the client build of
19
18
  * a Next.js application with Module Federation enabled. These plugins include the following:
20
19
  *
21
- * - DelegateModulesPlugin: Delegates modules to the webpack container runtime that can be streamed to other runtimes.
22
20
  * - ChunkCorrelationPlugin: Collects metadata on chunks to enable proper module loading across different runtimes.
23
21
  * - InvertedContainerPlugin: Adds custom runtime modules to the container runtime to allow a host to expose its
24
22
  * own remote interface at startup.
25
- *
26
- * If automatic page stitching is enabled, a loader is added to process the `next/dist/client/page-loader.js`
27
- * file. If a custom library is specified in the options, an error is thrown. The options.library property is
23
+
24
+ * If automatic page stitching is enabled, a warning is logged indicating that it is disabled in v7.
25
+ * If a custom library is specified in the options, an error is logged. The options.library property is
28
26
  * also set to `{ type: 'window', name: options.name }`.
29
27
  */
30
28
  function applyClientPlugins(compiler, options, extraOptions) {
31
- const { webpack } = compiler;
32
- const { remotes, name } = options;
29
+ const { name } = options;
30
+ // Adjust the public path if it is set to the default Next.js path
33
31
  if (compiler.options.output.publicPath === '/_next/') {
34
32
  compiler.options.output.publicPath = 'auto';
35
33
  }
36
- // If automatic page stitching is enabled, add a new rule to the compiler's module rules
34
+ // Log a warning if automatic page stitching is enabled, as it is disabled in v7
37
35
  if (extraOptions.automaticPageStitching) {
38
36
  console.warn('[nextjs-mf]', 'automatic page stitching is disabled in v7');
39
37
  }
40
- // If a custom library is set, log an error message
38
+ // Log an error if a custom library is set, as it is not allowed
41
39
  if (options.library) {
42
40
  console.error('[nextjs-mf] you cannot set custom library');
43
41
  }
@@ -46,22 +44,19 @@ function applyClientPlugins(compiler, options, extraOptions) {
46
44
  type: 'window',
47
45
  name,
48
46
  };
49
- // Add a new chunk correlation plugin to the compiler
47
+ // Apply the ChunkCorrelationPlugin to collect metadata on chunks
50
48
  new node_1.ChunkCorrelationPlugin({
51
49
  filename: [
52
50
  'static/chunks/federated-stats.json',
53
51
  'server/federated-stats.json',
54
52
  ],
55
- //@ts-ignore
56
53
  }).apply(compiler);
57
- new enhanced_1.HoistContainerReferencesPlugin(options.name).apply(compiler);
58
- // Add a new commonjs chunk loading plugin to the compiler
54
+ // Apply the InvertedContainerPlugin to add custom runtime modules to the container runtime
59
55
  new InvertedContainerPlugin_1.default({
60
56
  runtime: 'webpack',
61
57
  container: options.name,
62
58
  remotes: options.remotes,
63
59
  debug: extraOptions.debug,
64
- //@ts-ignore
65
60
  }).apply(compiler);
66
61
  }
67
62
  //# sourceMappingURL=apply-client-plugins.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"apply-client-plugins.js","sourceRoot":"","sources":["../../../../src/plugins/NextFederationPlugin/apply-client-plugins.ts"],"names":[],"mappings":";;;;;AA4BA,gDA+CC;AAtED,kDAAiE;AACjE,mGAA2E;AAC3E,0DAA6E;AAC7E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,kBAAkB,CAChC,QAAkB,EAClB,OAAsC,EACtC,YAA8C;IAE9C,MAAM,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;IAC7B,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IAElC,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QACrD,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC;IAC9C,CAAC;IAED,wFAAwF;IACxF,IAAI,YAAY,CAAC,sBAAsB,EAAE,CAAC;QACxC,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,4CAA4C,CAAC,CAAC;IAC5E,CAAC;IAED,mDAAmD;IACnD,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC7D,CAAC;IAED,6FAA6F;IAC7F,OAAO,CAAC,OAAO,GAAG;QAChB,IAAI,EAAE,QAAQ;QACd,IAAI;KACL,CAAC;IAEF,qDAAqD;IACrD,IAAI,6BAAsB,CAAC;QACzB,QAAQ,EAAE;YACR,oCAAoC;YACpC,6BAA6B;SAC9B;QACD,YAAY;KACb,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAEnB,IAAI,yCAA8B,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAEjE,0DAA0D;IAC1D,IAAI,iCAAuB,CAAC;QAC1B,OAAO,EAAE,SAAS;QAClB,SAAS,EAAE,OAAO,CAAC,IAAI;QACvB,OAAO,EAAE,OAAO,CAAC,OAAiC;QAClD,KAAK,EAAE,YAAY,CAAC,KAAK;QACzB,YAAY;KACb,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AACrB,CAAC"}
1
+ {"version":3,"file":"apply-client-plugins.js","sourceRoot":"","sources":["../../../../src/plugins/NextFederationPlugin/apply-client-plugins.ts"],"names":[],"mappings":";;;;;AAyBA,gDA2CC;AAlED,kDAAiE;AACjE,mGAA2E;AAG3E;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,kBAAkB,CAChC,QAAkB,EAClB,OAA6D,EAC7D,YAA8C;IAE9C,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IAEzB,kEAAkE;IAClE,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QACrD,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC;IAC9C,CAAC;IAED,gFAAgF;IAChF,IAAI,YAAY,CAAC,sBAAsB,EAAE,CAAC;QACxC,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,4CAA4C,CAAC,CAAC;IAC5E,CAAC;IAED,gEAAgE;IAChE,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC7D,CAAC;IAED,6FAA6F;IAC7F,OAAO,CAAC,OAAO,GAAG;QAChB,IAAI,EAAE,QAAQ;QACd,IAAI;KACL,CAAC;IAEF,iEAAiE;IACjE,IAAI,6BAAsB,CAAC;QACzB,QAAQ,EAAE;YACR,oCAAoC;YACpC,6BAA6B;SAC9B;KACF,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAEnB,2FAA2F;IAC3F,IAAI,iCAAuB,CAAC;QAC1B,OAAO,EAAE,SAAS;QAClB,SAAS,EAAE,OAAO,CAAC,IAAI;QACvB,OAAO,EAAE,OAAO,CAAC,OAAiC;QAClD,KAAK,EAAE,YAAY,CAAC,KAAK;KAC1B,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AACrB,CAAC"}
@@ -1,60 +1,36 @@
1
- import type { Compiler } from 'webpack';
2
- import { ModuleFederationPluginOptions } from '@module-federation/utilities';
1
+ import type { WebpackOptionsNormalized, Compiler } from 'webpack';
2
+ import type { moduleFederationPlugin } from '@module-federation/sdk';
3
+ type EntryStaticNormalized = Awaited<ReturnType<Extract<WebpackOptionsNormalized['entry'], () => any>>>;
4
+ interface ModifyEntryOptions {
5
+ compiler: Compiler;
6
+ prependEntry?: (entry: EntryStaticNormalized) => void;
7
+ staticEntry?: EntryStaticNormalized;
8
+ }
9
+ export declare function modifyEntry(options: ModifyEntryOptions): void;
3
10
  /**
4
- * This function applies server-specific plugins to the webpack compiler.
11
+ * Applies server-specific plugins to the webpack compiler.
5
12
  *
6
13
  * @param {Compiler} compiler - The Webpack compiler instance.
7
- * @param {ModuleFederationPluginOptions} options - The ModuleFederationPluginOptions instance.
8
- *
9
- * @returns {void}
14
+ * @param {moduleFederationPlugin.ModuleFederationPluginOptions} options - The ModuleFederationPluginOptions instance.
10
15
  */
11
- export declare function applyServerPlugins(compiler: Compiler, options: ModuleFederationPluginOptions): void;
16
+ export declare function applyServerPlugins(compiler: Compiler, options: moduleFederationPlugin.ModuleFederationPluginOptions): void;
12
17
  /**
13
- * This function configures server-specific library and filename options.
18
+ * Configures server-specific library and filename options.
14
19
  *
15
20
  * @param {ModuleFederationPluginOptions} options - The ModuleFederationPluginOptions instance.
16
- *
17
- * @returns {void}
18
- *
19
- * @remarks
20
- * This function configures the library and filename options for server builds. The library option is
21
- * set to the commonjs-module format for chunks and the container, which allows them to be streamed over
22
- * to hosts with the NodeFederationPlugin. The filename option is set to the basename of the current
23
- * filename.
24
21
  */
25
- export declare function configureServerLibraryAndFilename(options: ModuleFederationPluginOptions): void;
22
+ export declare function configureServerLibraryAndFilename(options: moduleFederationPlugin.ModuleFederationPluginOptions): void;
26
23
  /**
27
- * This function patches Next.js' default externals function to make sure shared modules are bundled and not treated as external.
24
+ * Patches Next.js' default externals function to ensure shared modules are bundled and not treated as external.
28
25
  *
29
26
  * @param {Compiler} compiler - The Webpack compiler instance.
30
27
  * @param {ModuleFederationPluginOptions} options - The ModuleFederationPluginOptions instance.
31
- *
32
- * @returns {void}
33
- *
34
- * @remarks
35
- * In server builds, all node modules are treated as external, which prevents them from being shared
36
- * via module federation. To work around this limitation, we mark shared modules as internalizable
37
- * modules that webpack puts into chunks that can be streamed to other runtimes as needed.
38
- *
39
- * This function replaces Next.js' default externals function with a new asynchronous function that
40
- * checks whether a module should be treated as external. If the module should not be treated as
41
- * external, the function returns without calling the original externals function. Otherwise, the
42
- * function calls the original externals function and retrieves the result. If the result is null,
43
- * the function returns without further processing. If the module is from Next.js or React, the
44
- * function returns the original result. Otherwise, the function returns null.
45
28
  */
46
- export declare function handleServerExternals(compiler: Compiler, options: ModuleFederationPluginOptions): void;
29
+ export declare function handleServerExternals(compiler: Compiler, options: moduleFederationPlugin.ModuleFederationPluginOptions): void;
47
30
  /**
48
- * This function configures server-specific compiler options.
31
+ * Configures server-specific compiler options.
49
32
  *
50
33
  * @param {Compiler} compiler - The Webpack compiler instance.
51
- *
52
- * @returns {void}
53
- *
54
- * @remarks
55
- * This function configures the compiler options for server builds. It turns off the compiler target on node
56
- * builds because it adds its own chunk loading runtime module with NodeFederationPlugin and StreamingTargetPlugin.
57
- * It also disables split chunks to prevent conflicts from occurring in the graph.
58
- *
59
34
  */
60
35
  export declare function configureServerCompilerOptions(compiler: Compiler): void;
36
+ export {};
@@ -3,55 +3,72 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.modifyEntry = modifyEntry;
6
7
  exports.applyServerPlugins = applyServerPlugins;
7
8
  exports.configureServerLibraryAndFilename = configureServerLibraryAndFilename;
8
9
  exports.handleServerExternals = handleServerExternals;
9
10
  exports.configureServerCompilerOptions = configureServerCompilerOptions;
10
- const enhanced_1 = require("@module-federation/enhanced");
11
11
  const path_1 = __importDefault(require("path"));
12
12
  const InvertedContainerPlugin_1 = __importDefault(require("../container/InvertedContainerPlugin"));
13
+ // Modifies the Webpack entry configuration
14
+ function modifyEntry(options) {
15
+ const { compiler, staticEntry, prependEntry } = options;
16
+ const operator = (oriEntry, newEntry) => Object.assign(oriEntry, newEntry);
17
+ // If the entry is a function, wrap it to modify the result
18
+ if (typeof compiler.options.entry === 'function') {
19
+ const prevEntryFn = compiler.options.entry;
20
+ compiler.options.entry = async () => {
21
+ let res = await prevEntryFn();
22
+ if (staticEntry) {
23
+ res = operator(res, staticEntry);
24
+ }
25
+ if (prependEntry) {
26
+ prependEntry(res);
27
+ }
28
+ return res;
29
+ };
30
+ }
31
+ else {
32
+ // If the entry is an object, directly modify it
33
+ if (staticEntry) {
34
+ compiler.options.entry = operator(compiler.options.entry, staticEntry);
35
+ }
36
+ if (prependEntry) {
37
+ prependEntry(compiler.options.entry);
38
+ }
39
+ }
40
+ }
13
41
  /**
14
- * This function applies server-specific plugins to the webpack compiler.
42
+ * Applies server-specific plugins to the webpack compiler.
15
43
  *
16
44
  * @param {Compiler} compiler - The Webpack compiler instance.
17
- * @param {ModuleFederationPluginOptions} options - The ModuleFederationPluginOptions instance.
18
- *
19
- * @returns {void}
45
+ * @param {moduleFederationPlugin.ModuleFederationPluginOptions} options - The ModuleFederationPluginOptions instance.
20
46
  */
21
47
  function applyServerPlugins(compiler, options) {
22
48
  const chunkFileName = compiler.options?.output?.chunkFilename;
23
49
  const uniqueName = compiler?.options?.output?.uniqueName || options.name;
50
+ const suffix = `-[chunkhash].js`;
51
+ // Modify chunk filename to include a unique suffix if not already present
24
52
  if (typeof chunkFileName === 'string' &&
25
53
  uniqueName &&
26
54
  !chunkFileName.includes(uniqueName)) {
27
- const suffix = `-[chunkhash].js`;
28
55
  compiler.options.output.chunkFilename = chunkFileName.replace('.js', suffix);
29
56
  }
30
- new enhanced_1.HoistContainerReferencesPlugin(options.name).apply(compiler);
31
- // Add a new commonjs chunk loading plugin to the compiler
57
+ // Apply the InvertedContainerPlugin to the compiler
32
58
  new InvertedContainerPlugin_1.default({
33
59
  runtime: 'webpack-runtime',
34
60
  container: options.name,
35
61
  remotes: options.remotes,
36
62
  debug: false,
37
- //@ts-ignore
38
63
  }).apply(compiler);
39
64
  }
40
65
  /**
41
- * This function configures server-specific library and filename options.
66
+ * Configures server-specific library and filename options.
42
67
  *
43
68
  * @param {ModuleFederationPluginOptions} options - The ModuleFederationPluginOptions instance.
44
- *
45
- * @returns {void}
46
- *
47
- * @remarks
48
- * This function configures the library and filename options for server builds. The library option is
49
- * set to the commonjs-module format for chunks and the container, which allows them to be streamed over
50
- * to hosts with the NodeFederationPlugin. The filename option is set to the basename of the current
51
- * filename.
52
69
  */
53
70
  function configureServerLibraryAndFilename(options) {
54
- // Configure the library option with type "commonjs-module" and the name from the options
71
+ // Set the library option to "commonjs-module" format with the name from the options
55
72
  options.library = {
56
73
  type: 'commonjs-module',
57
74
  name: options.name,
@@ -60,56 +77,32 @@ function configureServerLibraryAndFilename(options) {
60
77
  options.filename = path_1.default.basename(options.filename);
61
78
  }
62
79
  /**
63
- * This function patches Next.js' default externals function to make sure shared modules are bundled and not treated as external.
80
+ * Patches Next.js' default externals function to ensure shared modules are bundled and not treated as external.
64
81
  *
65
82
  * @param {Compiler} compiler - The Webpack compiler instance.
66
83
  * @param {ModuleFederationPluginOptions} options - The ModuleFederationPluginOptions instance.
67
- *
68
- * @returns {void}
69
- *
70
- * @remarks
71
- * In server builds, all node modules are treated as external, which prevents them from being shared
72
- * via module federation. To work around this limitation, we mark shared modules as internalizable
73
- * modules that webpack puts into chunks that can be streamed to other runtimes as needed.
74
- *
75
- * This function replaces Next.js' default externals function with a new asynchronous function that
76
- * checks whether a module should be treated as external. If the module should not be treated as
77
- * external, the function returns without calling the original externals function. Otherwise, the
78
- * function calls the original externals function and retrieves the result. If the result is null,
79
- * the function returns without further processing. If the module is from Next.js or React, the
80
- * function returns the original result. Otherwise, the function returns null.
81
84
  */
82
85
  function handleServerExternals(compiler, options) {
83
86
  if (Array.isArray(compiler.options.externals) &&
84
- compiler.options.externals[0]) {
85
- // Retrieve the original externals function
87
+ typeof compiler.options.externals[0] === 'function') {
86
88
  const originalExternals = compiler.options.externals[0];
87
- // Replace the original externals function with a new asynchronous function
88
89
  compiler.options.externals[0] = async function (ctx, callback) {
89
- //@ts-ignore
90
90
  const fromNext = await originalExternals(ctx, callback);
91
- // If the result is null, return without further processing
92
91
  if (!fromNext) {
93
92
  return;
94
93
  }
95
- // If the module is from Next.js or React, return the original result
96
94
  const req = fromNext.split(' ')[1];
97
- // Check if the module should not be treated as external
98
95
  if (ctx.request &&
99
96
  (ctx.request.includes('@module-federation/utilities') ||
100
97
  Object.keys(options.shared || {}).some((key) => {
101
- return (
102
- //@ts-ignore
103
- options.shared?.[key]?.import !== false &&
98
+ const sharedOptions = options.shared;
99
+ return (sharedOptions[key]?.import !== false &&
104
100
  (key.endsWith('/') ? req.includes(key) : req === key));
105
101
  }) ||
106
102
  ctx.request.includes('@module-federation/'))) {
107
- // If the module should not be treated as external, return without calling the original externals function
108
103
  return;
109
104
  }
110
105
  if (req.startsWith('next') ||
111
- // make sure we dont screw up package names that start with react
112
- // like react-carousel or react-spring
113
106
  req.startsWith('react/') ||
114
107
  req.startsWith('react-dom/') ||
115
108
  req === 'react' ||
@@ -117,36 +110,23 @@ function handleServerExternals(compiler, options) {
117
110
  req === 'react-dom') {
118
111
  return fromNext;
119
112
  }
120
- // Otherwise, return (null) to treat the module as internalizable
121
113
  return;
122
114
  };
123
115
  }
124
116
  }
125
117
  /**
126
- * This function configures server-specific compiler options.
118
+ * Configures server-specific compiler options.
127
119
  *
128
120
  * @param {Compiler} compiler - The Webpack compiler instance.
129
- *
130
- * @returns {void}
131
- *
132
- * @remarks
133
- * This function configures the compiler options for server builds. It turns off the compiler target on node
134
- * builds because it adds its own chunk loading runtime module with NodeFederationPlugin and StreamingTargetPlugin.
135
- * It also disables split chunks to prevent conflicts from occurring in the graph.
136
- *
137
121
  */
138
122
  function configureServerCompilerOptions(compiler) {
139
- // Turn off the compiler target on node builds because we add our own chunk loading runtime module
140
- // with NodeFederationPlugin and StreamingTargetPlugin
123
+ // Disable the global option in node builds and set the target to "async-node"
141
124
  compiler.options.node = {
142
125
  ...compiler.options.node,
143
126
  global: false,
144
127
  };
145
128
  compiler.options.target = 'async-node';
146
- // no custom chunk rules
147
- compiler.options.optimization.splitChunks = undefined;
148
- // solves strange issues where next doesnt create a runtime chunk
149
- // might be related to if an api route exists or not
129
+ // Ensure a runtime chunk is created
150
130
  compiler.options.optimization.runtimeChunk = {
151
131
  name: 'webpack-runtime',
152
132
  };