@module-federation/nextjs-mf 8.3.6 → 8.3.8

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 (92) hide show
  1. package/dist/client/UrlNode.d.ts +17 -0
  2. package/dist/client/UrlNode.js +150 -0
  3. package/dist/client/UrlNode.js.map +1 -0
  4. package/dist/node.d.ts +1 -0
  5. package/dist/node.js +18 -0
  6. package/dist/node.js.map +1 -0
  7. package/dist/package.json +99 -0
  8. package/dist/src/federation-noop.d.ts +0 -0
  9. package/dist/src/federation-noop.js +15 -0
  10. package/dist/src/federation-noop.js.map +1 -0
  11. package/dist/src/index.d.ts +3 -0
  12. package/dist/src/index.js +12 -0
  13. package/dist/src/index.js.map +1 -0
  14. package/dist/src/internal.d.ts +48 -0
  15. package/dist/src/internal.js +177 -0
  16. package/dist/src/internal.js.map +1 -0
  17. package/dist/src/loaders/fixImageLoader.d.ts +22 -0
  18. package/dist/src/loaders/fixImageLoader.js +114 -0
  19. package/dist/src/loaders/fixImageLoader.js.map +1 -0
  20. package/dist/src/loaders/fixUrlLoader.d.ts +13 -0
  21. package/dist/src/loaders/fixUrlLoader.js +25 -0
  22. package/dist/src/loaders/fixUrlLoader.js.map +1 -0
  23. package/dist/src/loaders/helpers.d.ts +17 -0
  24. package/dist/src/loaders/helpers.js +60 -0
  25. package/dist/src/loaders/helpers.js.map +1 -0
  26. package/dist/src/loaders/nextPageMapLoader.d.ts +24 -0
  27. package/dist/src/loaders/nextPageMapLoader.js +167 -0
  28. package/dist/src/loaders/nextPageMapLoader.js.map +1 -0
  29. package/dist/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.d.ts +5 -0
  30. package/dist/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.js +19 -0
  31. package/dist/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.js.map +1 -0
  32. package/dist/src/plugins/CopyFederationPlugin.d.ts +20 -0
  33. package/dist/src/plugins/CopyFederationPlugin.js +71 -0
  34. package/dist/src/plugins/CopyFederationPlugin.js.map +1 -0
  35. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.d.ts +23 -0
  36. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.js +73 -0
  37. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.js.map +1 -0
  38. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.d.ts +60 -0
  39. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.js +170 -0
  40. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.js.map +1 -0
  41. package/dist/src/plugins/NextFederationPlugin/index.d.ts +27 -0
  42. package/dist/src/plugins/NextFederationPlugin/index.js +160 -0
  43. package/dist/src/plugins/NextFederationPlugin/index.js.map +1 -0
  44. package/dist/src/plugins/NextFederationPlugin/next-fragments.d.ts +18 -0
  45. package/dist/src/plugins/NextFederationPlugin/next-fragments.js +61 -0
  46. package/dist/src/plugins/NextFederationPlugin/next-fragments.js.map +1 -0
  47. package/dist/src/plugins/NextFederationPlugin/regex-equal.d.ts +14 -0
  48. package/dist/src/plugins/NextFederationPlugin/regex-equal.js +25 -0
  49. package/dist/src/plugins/NextFederationPlugin/regex-equal.js.map +1 -0
  50. package/dist/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.d.ts +8 -0
  51. package/dist/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js +31 -0
  52. package/dist/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js.map +1 -0
  53. package/dist/src/plugins/NextFederationPlugin/set-options.d.ts +20 -0
  54. package/dist/src/plugins/NextFederationPlugin/set-options.js +38 -0
  55. package/dist/src/plugins/NextFederationPlugin/set-options.js.map +1 -0
  56. package/dist/src/plugins/NextFederationPlugin/validate-options.d.ts +25 -0
  57. package/dist/src/plugins/NextFederationPlugin/validate-options.js +46 -0
  58. package/dist/src/plugins/NextFederationPlugin/validate-options.js.map +1 -0
  59. package/dist/src/plugins/container/EmbeddedContainerPlugin.d.ts +11 -0
  60. package/dist/src/plugins/container/EmbeddedContainerPlugin.js +23 -0
  61. package/dist/src/plugins/container/EmbeddedContainerPlugin.js.map +1 -0
  62. package/dist/src/plugins/container/InvertedContainerPlugin.d.ts +15 -0
  63. package/dist/src/plugins/container/InvertedContainerPlugin.js +25 -0
  64. package/dist/src/plugins/container/InvertedContainerPlugin.js.map +1 -0
  65. package/dist/src/plugins/container/InvertedContainerRuntimeModule.d.ts +11 -0
  66. package/dist/src/plugins/container/InvertedContainerRuntimeModule.js +50 -0
  67. package/dist/src/plugins/container/InvertedContainerRuntimeModule.js.map +1 -0
  68. package/dist/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.d.ts +39 -0
  69. package/dist/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.js +72 -0
  70. package/dist/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.js.map +1 -0
  71. package/dist/src/plugins/container/runtimePlugin.d.ts +2 -0
  72. package/dist/src/plugins/container/runtimePlugin.js +173 -0
  73. package/dist/src/plugins/container/runtimePlugin.js.map +1 -0
  74. package/dist/src/plugins/container/types.d.ts +2 -0
  75. package/dist/src/plugins/container/types.js +3 -0
  76. package/dist/src/plugins/container/types.js.map +1 -0
  77. package/dist/src/types.d.ts +28 -0
  78. package/dist/src/types.js +3 -0
  79. package/dist/src/types.js.map +1 -0
  80. package/dist/utilities.d.ts +1 -0
  81. package/dist/utilities.js +18 -0
  82. package/dist/utilities.js.map +1 -0
  83. package/dist/utils/build-utils.d.ts +10 -0
  84. package/dist/utils/build-utils.js +24 -0
  85. package/dist/utils/build-utils.js.map +1 -0
  86. package/dist/utils/flushedChunks.d.ts +22 -0
  87. package/dist/utils/flushedChunks.js +67 -0
  88. package/dist/utils/flushedChunks.js.map +1 -0
  89. package/dist/utils/index.d.ts +27 -0
  90. package/dist/utils/index.js +69 -0
  91. package/dist/utils/index.js.map +1 -0
  92. package/package.json +6 -6
@@ -0,0 +1,114 @@
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.pitch = exports.fixImageLoader = void 0;
7
+ const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
8
+ const { Template } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack'));
9
+ const path_1 = __importDefault(require("path"));
10
+ /**
11
+ * This loader is specifically created for tuning the next-image-loader result.
12
+ * It modifies the regular string output of the next-image-loader.
13
+ * For server-side rendering (SSR), it injects the remote scope of a specific remote URL.
14
+ * For client-side rendering (CSR), it injects the document.currentScript.src.
15
+ * After these injections, it selects the full URI before _next.
16
+ *
17
+ * @example
18
+ * http://localhost:1234/test/test2/_next/static/media/ssl.e3019f0e.svg
19
+ * will become
20
+ * http://localhost:1234/test/test2
21
+ *
22
+ * @param {LoaderContext<Record<string, unknown>>} this - The loader context.
23
+ * @param {string} remaining - The remaining part of the resource path.
24
+ * @returns {string} The modified source code with the injected code.
25
+ */
26
+ async function fixImageLoader(remaining) {
27
+ this.cacheable(true);
28
+ const isServer = this._compiler?.options.name !== 'client';
29
+ //@ts-ignore
30
+ const { publicPath } = this._compiler.webpack.RuntimeGlobals;
31
+ const result = await this.importModule(`${this.resourcePath}.webpack[javascript/auto]!=!${remaining}`);
32
+ const content = (result.default || result);
33
+ const computedAssetPrefix = isServer
34
+ ? `${Template.asString([
35
+ 'function getSSRImagePath(){',
36
+ //TODO: use auto public path plugin instead
37
+ `const pubpath = ${publicPath};`,
38
+ Template.asString([
39
+ 'try {',
40
+ Template.indent([
41
+ "const globalThisVal = new Function('return globalThis')();",
42
+ 'const name = __webpack_require__.federation.instance.name',
43
+ `const container = globalThisVal['__FEDERATION__']['__INSTANCES__'].find(
44
+ (instance) => {
45
+ if (!instance.moduleCache.has(name)) return;
46
+ const container = instance.moduleCache.get(name);
47
+ if (!container.remoteInfo) return;
48
+ return container.remoteInfo.entry;
49
+ },
50
+ );`,
51
+ 'const cache = container.moduleCache',
52
+ 'const remote = cache.get(name).remoteInfo',
53
+ `const remoteEntry = remote.entry;`,
54
+ `if (remoteEntry) {`,
55
+ Template.indent([
56
+ `const splitted = remoteEntry.split('/_next')`,
57
+ `return splitted.length === 2 ? splitted[0] : '';`,
58
+ ]),
59
+ `}`,
60
+ `return '';`,
61
+ ]),
62
+ '} catch (e) {',
63
+ Template.indent([
64
+ `console.error('failed generating SSR image path', e);`,
65
+ 'return "";',
66
+ ]),
67
+ '}',
68
+ ]),
69
+ '}()',
70
+ ])}`
71
+ : `${Template.asString([
72
+ 'function getCSRImagePath(){',
73
+ Template.indent([
74
+ 'try {',
75
+ Template.indent([
76
+ Template.indent(`return ${publicPath} && ${publicPath}.indexOf('://') > 0 ? new URL(${publicPath}).origin : ''`),
77
+ ]),
78
+ '} catch (e) {',
79
+ Template.indent([
80
+ `const path = document.currentScript && document.currentScript.src;`,
81
+ `console.error('failed generating CSR image path', e, path);`,
82
+ 'return "";',
83
+ ]),
84
+ '}',
85
+ ]),
86
+ '}()',
87
+ ])}`;
88
+ const constructedObject = Object.entries(content).reduce((acc, [key, value]) => {
89
+ if (key === 'src') {
90
+ if (value && !value.includes('://')) {
91
+ value = path_1.default.join(value);
92
+ }
93
+ acc.push(`${key}: computedAssetsPrefixReference + ${JSON.stringify(value)}`);
94
+ return acc;
95
+ }
96
+ acc.push(`${key}: ${JSON.stringify(value)}`);
97
+ return acc;
98
+ }, []);
99
+ return Template.asString([
100
+ "let computedAssetsPrefixReference = '';",
101
+ 'try {',
102
+ Template.indent(`computedAssetsPrefixReference = ${computedAssetPrefix};`),
103
+ '} catch (e) {}',
104
+ 'export default {',
105
+ Template.indent(constructedObject.join(',\n')),
106
+ '}',
107
+ ]);
108
+ }
109
+ exports.fixImageLoader = fixImageLoader;
110
+ /**
111
+ * The pitch function of the loader, which is the same as the fixImageLoader function.
112
+ */
113
+ exports.pitch = fixImageLoader;
114
+ //# sourceMappingURL=fixImageLoader.js.map
@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AAkB;QAClB,QAAQ,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9C,GAAG;KACJ,CAAC,CAAC;AACL,CAAC;AApGD,wCAoGC;AAED;;GAEG;AACU,QAAA,KAAK,GAAG,cAAc,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `fixUrlLoader` is a custom loader designed to modify the output of the url-loader.
3
+ * It injects the PUBLIC_PATH from the webpack runtime into the output.
4
+ * The output format is: `export default __webpack_require__.p + "/static/media/ssl.e3019f0e.svg"`
5
+ *
6
+ * `__webpack_require__.p` is a global variable in the webpack container that contains the publicPath.
7
+ * For example, it could be: http://localhost:3000/_next
8
+ *
9
+ * @param {string} content - The original output from the url-loader.
10
+ * @returns {string} The modified output with the injected PUBLIC_PATH.
11
+ */
12
+ export declare function fixUrlLoader(content: string): string;
13
+ export default fixUrlLoader;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fixUrlLoader = void 0;
4
+ /**
5
+ * `fixUrlLoader` is a custom loader designed to modify the output of the url-loader.
6
+ * It injects the PUBLIC_PATH from the webpack runtime into the output.
7
+ * The output format is: `export default __webpack_require__.p + "/static/media/ssl.e3019f0e.svg"`
8
+ *
9
+ * `__webpack_require__.p` is a global variable in the webpack container that contains the publicPath.
10
+ * For example, it could be: http://localhost:3000/_next
11
+ *
12
+ * @param {string} content - The original output from the url-loader.
13
+ * @returns {string} The modified output with the injected PUBLIC_PATH.
14
+ */
15
+ function fixUrlLoader(content) {
16
+ // This regular expression extracts the hostname from the publicPath.
17
+ // For example, it transforms http://localhost:3000/_next/... into http://localhost:3000
18
+ const currentHostnameCode = "__webpack_require__.p.replace(/(.+\\:\\/\\/[^\\/]+){0,1}\\/.*/i, '$1')";
19
+ // Replace the default export path in the content with the modified path that includes the hostname.
20
+ return content.replace('export default "/', `export default ${currentHostnameCode}+"/`);
21
+ }
22
+ exports.fixUrlLoader = fixUrlLoader;
23
+ // Export the fixUrlLoader function as the default export of this module.
24
+ exports.default = fixUrlLoader;
25
+ //# sourceMappingURL=fixUrlLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixUrlLoader.js","sourceRoot":"","sources":["../../../src/loaders/fixUrlLoader.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;GAUG;AACH,SAAgB,YAAY,CAAC,OAAe;IAC1C,qEAAqE;IACrE,wFAAwF;IACxF,MAAM,mBAAmB,GACvB,wEAAwE,CAAC;IAE3E,oGAAoG;IACpG,OAAO,OAAO,CAAC,OAAO,CACpB,mBAAmB,EACnB,kBAAkB,mBAAmB,KAAK,CAC3C,CAAC;AACJ,CAAC;AAXD,oCAWC;AAED,yEAAyE;AACzE,kBAAe,YAAY,CAAC"}
@@ -0,0 +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;
10
+ /**
11
+ * This function checks if the current module rule has a loader with the provided name.
12
+ *
13
+ * @param {RuleSetRuleUnion} rule - The current module rule.
14
+ * @param {string} loaderName - The name of the loader to check.
15
+ * @returns {boolean} Returns true if the current module rule has a loader with the provided name, otherwise false.
16
+ */
17
+ export declare function hasLoader(rule: RuleSetRuleUnion, loaderName: string): boolean;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasLoader = exports.injectRuleLoader = void 0;
4
+ /**
5
+ * This function injects a loader into the current module rule.
6
+ * Note: This function mutates the `rule` argument.
7
+ *
8
+ * @param {RuleSetRuleUnion} rule - The current module rule.
9
+ * @param {Loader} [loader={}] - The loader to be injected.
10
+ */
11
+ function injectRuleLoader(rule, loader = {}) {
12
+ if (rule !== '...') {
13
+ const _rule = rule;
14
+ if (_rule.loader) {
15
+ _rule.use = [loader, { loader: _rule.loader, options: _rule.options }];
16
+ delete _rule.loader;
17
+ delete _rule.options;
18
+ }
19
+ else if (_rule.use) {
20
+ _rule.use = [loader, ..._rule.use];
21
+ }
22
+ }
23
+ }
24
+ exports.injectRuleLoader = injectRuleLoader;
25
+ /**
26
+ * This function checks if the current module rule has a loader with the provided name.
27
+ *
28
+ * @param {RuleSetRuleUnion} rule - The current module rule.
29
+ * @param {string} loaderName - The name of the loader to check.
30
+ * @returns {boolean} Returns true if the current module rule has a loader with the provided name, otherwise false.
31
+ */
32
+ function hasLoader(rule, loaderName) {
33
+ if (rule !== '...') {
34
+ const _rule = rule;
35
+ if (_rule.loader === loaderName) {
36
+ return true;
37
+ }
38
+ else if (_rule.use && Array.isArray(_rule.use)) {
39
+ for (let i = 0; i < _rule.use.length; i++) {
40
+ const loader = _rule.use[i];
41
+ // check exact name, eg "url-loader" or its path "node_modules/url-loader/dist/cjs.js"
42
+ if (typeof loader !== 'string' &&
43
+ typeof loader !== 'function' &&
44
+ loader.loader &&
45
+ (loader.loader === loaderName ||
46
+ loader.loader.includes(`/${loaderName}/`))) {
47
+ return true;
48
+ }
49
+ else if (typeof loader === 'string') {
50
+ if (loader === loaderName || loader.includes(`/${loaderName}/`)) {
51
+ return true;
52
+ }
53
+ }
54
+ }
55
+ }
56
+ }
57
+ return false;
58
+ }
59
+ exports.hasLoader = hasLoader;
60
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/loaders/helpers.ts"],"names":[],"mappings":";;;AAEA;;;;;;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,MAA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Q,EAAE,CAAC;oBACtC,IAAI,MAAM,KAAK,UAAU,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAU,GAAG,CAAC,EAAE,CAAC;wBAChE,OAAO,IAAI,CAAC;oBACd,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AA9BD,8BA8BC"}
@@ -0,0 +1,24 @@
1
+ import type { LoaderContext } from 'webpack';
2
+ /**
3
+ * Webpack loader which prepares MF map for NextJS pages.
4
+ * This function is the main entry point for the loader.
5
+ * It gets the options passed to the loader and prepares the pages map.
6
+ * If the 'v2' option is passed, it prepares the pages map using the 'preparePageMapV2' function.
7
+ * Otherwise, it uses the 'preparePageMap' function.
8
+ * Finally, it calls the loader's callback function with the prepared pages map.
9
+ *
10
+ * @param {LoaderContext<Record<string, unknown>>} this - The loader context.
11
+ */
12
+ export default function nextPageMapLoader(this: LoaderContext<Record<string, unknown>>): void;
13
+ /**
14
+ * Webpack config generator for `exposes` option.
15
+ * This function generates the webpack config for the 'exposes' option.
16
+ * It creates a map of pages to modules and returns an object with the pages map and the pages map v2.
17
+ *
18
+ * @param {string} cwd - The current working directory.
19
+ * @returns {Record<string, string>} The webpack config for the 'exposes' option.
20
+ */
21
+ export declare function exposeNextjsPages(cwd: string): {
22
+ './pages-map': string;
23
+ './pages-map-v2': string;
24
+ };
@@ -0,0 +1,167 @@
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.exposeNextjsPages = void 0;
7
+ const fast_glob_1 = __importDefault(require("fast-glob"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const UrlNode_1 = require("../../client/UrlNode");
10
+ /**
11
+ * Webpack loader which prepares MF map for NextJS pages.
12
+ * This function is the main entry point for the loader.
13
+ * It gets the options passed to the loader and prepares the pages map.
14
+ * If the 'v2' option is passed, it prepares the pages map using the 'preparePageMapV2' function.
15
+ * Otherwise, it uses the 'preparePageMap' function.
16
+ * Finally, it calls the loader's callback function with the prepared pages map.
17
+ *
18
+ * @param {LoaderContext<Record<string, unknown>>} this - The loader context.
19
+ */
20
+ function nextPageMapLoader() {
21
+ // const [pagesRoot] = getNextPagesRoot(this.rootContext);
22
+ // this.addContextDependency(pagesRoot);
23
+ const opts = this.getOptions();
24
+ const pages = getNextPages(this.rootContext);
25
+ let result = {};
26
+ if (Object.hasOwnProperty.call(opts, 'v2')) {
27
+ result = preparePageMapV2(pages);
28
+ }
29
+ else {
30
+ result = preparePageMap(pages);
31
+ }
32
+ this.callback(null, `module.exports = { default: ${JSON.stringify(result)} };`);
33
+ }
34
+ exports.default = nextPageMapLoader;
35
+ /**
36
+ * Webpack config generator for `exposes` option.
37
+ * This function generates the webpack config for the 'exposes' option.
38
+ * It creates a map of pages to modules and returns an object with the pages map and the pages map v2.
39
+ *
40
+ * @param {string} cwd - The current working directory.
41
+ * @returns {Record<string, string>} The webpack config for the 'exposes' option.
42
+ */
43
+ function exposeNextjsPages(cwd) {
44
+ const pages = getNextPages(cwd);
45
+ const pageModulesMap = {};
46
+ pages.forEach((page) => {
47
+ // Creating a map of pages to modules
48
+ // './pages/storage/index': './pages/storage/index.tsx',
49
+ // './pages/storage/[...slug]': './pages/storage/[...slug].tsx',
50
+ pageModulesMap['./' + sanitizePagePath(page)] = `./${page}`;
51
+ });
52
+ return {
53
+ './pages-map': `${__filename}!${__filename}`,
54
+ './pages-map-v2': `${__filename}?v2!${__filename}`,
55
+ ...pageModulesMap,
56
+ };
57
+ }
58
+ exports.exposeNextjsPages = exposeNextjsPages;
59
+ /**
60
+ * This function gets the root directory of the NextJS pages.
61
+ * It checks if the 'src/pages/' directory exists.
62
+ * If it does, it returns the absolute path and the relative path to this directory.
63
+ * If it doesn't, it returns the absolute path and the relative path to the 'pages/' directory.
64
+ *
65
+ * @param {string} appRoot - The root directory of the application.
66
+ * @returns {[string, string]} The absolute path and the relative path to the pages directory.
67
+ */
68
+ function getNextPagesRoot(appRoot) {
69
+ let pagesDir = 'src/pages/';
70
+ let absPageDir = `${appRoot}/${pagesDir}`;
71
+ if (!fs_1.default.existsSync(absPageDir)) {
72
+ pagesDir = 'pages/';
73
+ absPageDir = `${appRoot}/${pagesDir}`;
74
+ }
75
+ return [absPageDir, pagesDir];
76
+ }
77
+ /**
78
+ * This function scans the pages directory and returns a list of user defined pages.
79
+ * It excludes special pages like '_app', '_document', '_error', '404', '500', and federation pages.
80
+ *
81
+ * @param {string} rootDir - The root directory of the application.
82
+ * @returns {string[]} The list of user defined pages.
83
+ */
84
+ function getNextPages(rootDir) {
85
+ const [cwd, pagesDir] = getNextPagesRoot(rootDir);
86
+ // scan all files in pages folder except pages/api
87
+ let pageList = fast_glob_1.default.sync('**/*.{ts,tsx,js,jsx}', {
88
+ cwd,
89
+ onlyFiles: true,
90
+ ignore: ['api/**'],
91
+ });
92
+ // remove specific nextjs pages
93
+ const exclude = [
94
+ /^_app\..*/, // _app.tsx
95
+ /^_document\..*/, // _document.tsx
96
+ /^_error\..*/, // _error.tsx
97
+ /^404\..*/, // 404.tsx
98
+ /^500\..*/, // 500.tsx
99
+ /^\[\.\.\..*\]\..*/, // /[...federationPage].tsx
100
+ ];
101
+ pageList = pageList.filter((page) => {
102
+ return !exclude.some((r) => r.test(page));
103
+ });
104
+ pageList = pageList.map((page) => `${pagesDir}${page}`);
105
+ return pageList;
106
+ }
107
+ /**
108
+ * This function sanitizes a page path.
109
+ * It removes the 'src/pages/' prefix and the file extension.
110
+ *
111
+ * @param {string} item - The page path to sanitize.
112
+ * @returns {string} The sanitized page path.
113
+ */
114
+ function sanitizePagePath(item) {
115
+ return item
116
+ .replace(/^src\/pages\//i, 'pages/')
117
+ .replace(/\.(ts|tsx|js|jsx)$/, '');
118
+ }
119
+ /**
120
+ * This function creates a MF map from a list of NextJS pages.
121
+ * It sanitizes the page paths and sorts them using the 'UrlNode' class.
122
+ * Then, it creates a map with the sorted page paths as keys and the original page paths as values.
123
+ *
124
+ * @param {string[]} pages - The list of NextJS pages.
125
+ * @returns {Record<string, string>} The MF map.
126
+ */
127
+ function preparePageMap(pages) {
128
+ const result = {};
129
+ const clearedPages = pages.map((p) => `/${sanitizePagePath(p)}`);
130
+ // getSortedRoutes @see https://github.com/vercel/next.js/blob/canary/packages/next/shared/lib/router/utils/sorted-routes.ts
131
+ const root = new UrlNode_1.UrlNode();
132
+ clearedPages.forEach((pagePath) => root.insert(pagePath));
133
+ // Smoosh will then sort those sublevels up to the point where you get the correct route definition priority
134
+ const sortedPages = root.smoosh();
135
+ sortedPages.forEach((page) => {
136
+ let key = page
137
+ .replace(/\[\.\.\.[^\]]+\]/gi, '*')
138
+ .replace(/\[([^\]]+)\]/gi, ':$1');
139
+ key = key.replace(/^\/pages\//, '/').replace(/\/index$/, '') || '/';
140
+ result[key] = `.${page}`;
141
+ });
142
+ return result;
143
+ }
144
+ /**
145
+ * This function creates a MF list from a list of NextJS pages.
146
+ * It sanitizes the page paths and sorts them using the 'UrlNode' class.
147
+ * Then, it creates a map with the sorted page paths as keys and the original page paths as values.
148
+ * Unlike the 'preparePageMap' function, this function does not replace the '[...]' and '[]' parts in the page paths.
149
+ *
150
+ * @param {string[]} pages - The list of NextJS pages.
151
+ * @returns {Record<string, string>} The MF list.
152
+ */
153
+ function preparePageMapV2(pages) {
154
+ const result = {};
155
+ const clearedPages = pages.map((p) => `/${sanitizePagePath(p)}`);
156
+ // getSortedRoutes @see https://github.com/vercel/next.js/blob/canary/packages/next/shared/lib/router/utils/sorted-routes.ts
157
+ const root = new UrlNode_1.UrlNode();
158
+ clearedPages.forEach((pagePath) => root.insert(pagePath));
159
+ // Smoosh will then sort those sublevels up to the point where you get the correct route definition priority
160
+ const sortedPages = root.smoosh();
161
+ sortedPages.forEach((page) => {
162
+ const key = page.replace(/^\/pages\//, '/').replace(/\/index$/, '') || '/';
163
+ result[key] = `.${page}`;
164
+ });
165
+ return result;
166
+ }
167
+ //# sourceMappingURL=nextPageMapLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nextPageMapLoader.js","sourceRoot":"","sources":["../../../src/loaders/nextPageMapLoader.ts"],"names":[],"mappings":";;;;;;AAEA,0DAA2B;AAC3B,4CAAoB;AAEpB,kDAA+C;AAE/C;;;;;;;;;GASG;AACH,SAAwB,iBAAiB;IAGvC,0DAA0D;IAC1D,wCAAwC;IACxC,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IAC/B,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAE7C,IAAI,MAAM,GAAG,EAAE,CAAC;IAEhB,IAAI,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;QAC3C,MAAM,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,IAAI,CAAC,QAAQ,CACX,IAAI,EACJ,+BAA+B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAC3D,CAAC;AACJ,CAAC;AApBD,oCAoBC;AAED;;;;;;;GAOG;AACH,SAAgB,iBAAiB,CAAC,GAAW;IAC3C,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;IAEhC,MAAM,cAAc,GAAG,EAA4B,CAAC;IACpD,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACrB,qCAAqC;QACrC,0DAA0D;QAC1D,kEAAkE;QAClE,cAAc,CAAC,IAAI,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,IAAI,EAAE,CAAC;IAC9D,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,aAAa,EAAE,GAAG,UAAU,IAAI,UAAU,EAAE;QAC5C,gBAAgB,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MAAM,MAAM,GAAG,EAA4B,CAAC;IAE5C,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAEjE,4HAA4H;IAC5H,MAAM,IAAI,GAAG,IAAI,iBAAO,EAAE,CAAC;IAC3B,YAAY,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC1D,4GAA4G;IAC5G,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAElC,WAAW,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC;QAC3E,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Compiler, WebpackPluginInstance } from 'webpack';
2
+ export declare class AddRuntimeRequirementToPromiseExternal implements WebpackPluginInstance {
3
+ apply(compiler: Compiler): void;
4
+ }
5
+ export default AddRuntimeRequirementToPromiseExternal;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AddRuntimeRequirementToPromiseExternal = void 0;
4
+ class AddRuntimeRequirementToPromiseExternal {
5
+ apply(compiler) {
6
+ compiler.hooks.compilation.tap('AddRuntimeRequirementToPromiseExternal', (compilation) => {
7
+ const { RuntimeGlobals } = compiler.webpack;
8
+ compilation.hooks.additionalModuleRuntimeRequirements.tap('AddRuntimeRequirementToPromiseExternal', (module, set) => {
9
+ if (module.externalType === 'promise') {
10
+ set.add(RuntimeGlobals.loadScript);
11
+ set.add(RuntimeGlobals.require);
12
+ }
13
+ });
14
+ });
15
+ }
16
+ }
17
+ exports.AddRuntimeRequirementToPromiseExternal = AddRuntimeRequirementToPromiseExternal;
18
+ exports.default = AddRuntimeRequirementToPromiseExternal;
19
+ //# sourceMappingURL=AddRuntimeRequirementToPromiseExternalPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AddRuntimeRequirementToPromiseExternalPlugin.js","sourceRoot":"","sources":["../../../src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.ts"],"names":[],"mappings":";;;AAEA,MAAa,sCAAsC;IAGjD,KAAK,CAAC,QAAkB;QACtB,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAC5B,wCAAwC,EACxC,CAAC,WAAW,EAAE,EAAE;YACd,MAAM,EAAE,cAAc,EAAE,GAAG,QAAQ,CAAC,OAAO,CAAC;YAC5C,WAAW,CAAC,KAAK,CAAC,mCAAmC,CAAC,GAAG,CACvD,wCAAwC,EACxC,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;gBACd,IAAK,MAAc,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;oBAC/C,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;oBACnC,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;gBAClC,CAAC;YACH,CAAC,CACF,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AApBD,wFAoBC;AAED,kBAAe,sCAAsC,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { Compiler, WebpackPluginInstance } from 'webpack';
2
+ /**
3
+ * Plugin to copy build output files.
4
+ * @class
5
+ */
6
+ declare class CopyBuildOutputPlugin implements WebpackPluginInstance {
7
+ private isServer;
8
+ /**
9
+ * @param {boolean} isServer - Indicates if the current environment is server.
10
+ * @constructor
11
+ */
12
+ constructor(isServer: boolean);
13
+ /**
14
+ * Applies the plugin to the compiler.
15
+ * @param {Compiler} compiler - The webpack compiler object.
16
+ * @method
17
+ */
18
+ apply(compiler: Compiler): void;
19
+ }
20
+ export default CopyBuildOutputPlugin;
@@ -0,0 +1,71 @@
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
+ const fs_1 = require("fs");
7
+ const path_1 = __importDefault(require("path"));
8
+ /**
9
+ * Plugin to copy build output files.
10
+ * @class
11
+ */
12
+ class CopyBuildOutputPlugin {
13
+ /**
14
+ * @param {boolean} isServer - Indicates if the current environment is server.
15
+ * @constructor
16
+ */
17
+ constructor(isServer) {
18
+ this.isServer = isServer;
19
+ }
20
+ /**
21
+ * Applies the plugin to the compiler.
22
+ * @param {Compiler} compiler - The webpack compiler object.
23
+ * @method
24
+ */
25
+ apply(compiler) {
26
+ /**
27
+ * Copies files from source to destination.
28
+ * @param {string} source - The source directory.
29
+ * @param {string} destination - The destination directory.
30
+ * @async
31
+ * @function
32
+ */
33
+ const copyFiles = async (source, destination) => {
34
+ const files = await fs_1.promises.readdir(source);
35
+ await Promise.all(files.map(async (file) => {
36
+ const sourcePath = path_1.default.join(source, file);
37
+ const destinationPath = path_1.default.join(destination, file);
38
+ if ((await fs_1.promises.lstat(sourcePath)).isDirectory()) {
39
+ await fs_1.promises.mkdir(destinationPath, { recursive: true });
40
+ await copyFiles(sourcePath, destinationPath);
41
+ }
42
+ else {
43
+ await fs_1.promises.copyFile(sourcePath, destinationPath);
44
+ }
45
+ }));
46
+ };
47
+ compiler.hooks.afterEmit.tapPromise('CopyBuildOutputPlugin', async (compilation) => {
48
+ const { outputPath } = compiler;
49
+ const outputString = outputPath.split('server')[0];
50
+ const isProd = compiler.options.mode === 'production';
51
+ if (!isProd && !this.isServer) {
52
+ return;
53
+ }
54
+ const serverLoc = path_1.default.join(outputString, this.isServer && isProd ? '/ssr' : '/static/ssr');
55
+ const servingLoc = path_1.default.join(outputPath, 'ssr');
56
+ await fs_1.promises.mkdir(serverLoc, { recursive: true });
57
+ const sourcePath = this.isServer ? outputPath : servingLoc;
58
+ try {
59
+ await fs_1.promises.access(sourcePath);
60
+ // If the promise resolves, the file exists and you can proceed with copying.
61
+ await copyFiles(sourcePath, serverLoc);
62
+ }
63
+ catch (error) {
64
+ // If the promise rejects, the file does not exist.
65
+ console.error(`File at ${sourcePath} does not exist.`);
66
+ }
67
+ });
68
+ }
69
+ }
70
+ exports.default = CopyBuildOutputPlugin;
71
+ //# sourceMappingURL=CopyFederationPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CopyFederationPlugin.js","sourceRoot":"","sources":["../../../src/plugins/CopyFederationPlugin.ts"],"names":[],"mappings":";;;;;AAAA,2BAAoC;AACpC,gDAAwB;AAGxB;;;GAGG;AACH,MAAM,qBAAqB;IAGzB;;;OAGG;IACH,YAAY,QAAiB;QAC3B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,QAAkB;QACtB;;;;;;WAMG;QACH,MAAM,SAAS,GAAG,KAAK,EACrB,MAAc,EACd,WAAmB,EACJ,EAAE;YACjB,MAAM,KAAK,GAAG,MAAM,aAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAEvC,MAAM,OAAO,CAAC,GAAG,CACf,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;gBACvB,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBAC3C,MAAM,eAAe,GAAG,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;gBAErD,IAAI,CAAC,MAAM,aAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;oBAC/C,MAAM,aAAE,CAAC,KAAK,CAAC,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ACzC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,mDAAmD;gBACnD,OAAO,CAAC,KAAK,CAAC,WAAW,UAAU,kBAAkB,CAAC,CAAC;YACzD,CAAC;QACH,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAED,kBAAe,qBAAqB,CAAC"}
@@ -0,0 +1,23 @@
1
+ import type { Compiler } from 'webpack';
2
+ import { ModuleFederationPluginOptions, NextFederationPluginExtraOptions } from '@module-federation/utilities';
3
+ /**
4
+ * Applies client-specific plugins.
5
+ *
6
+ * @param compiler - The Webpack compiler instance.
7
+ * @param options - The ModuleFederationPluginOptions instance.
8
+ * @param extraOptions - The NextFederationPluginExtraOptions instance.
9
+ *
10
+ * @remarks
11
+ * This function applies plugins to the Webpack compiler instance that are specific to the client build of
12
+ * a Next.js application with Module Federation enabled. These plugins include the following:
13
+ *
14
+ * - DelegateModulesPlugin: Delegates modules to the webpack container runtime that can be streamed to other runtimes.
15
+ * - ChunkCorrelationPlugin: Collects metadata on chunks to enable proper module loading across different runtimes.
16
+ * - InvertedContainerPlugin: Adds custom runtime modules to the container runtime to allow a host to expose its
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
21
+ * also set to `{ type: 'window', name: options.name }`.
22
+ */
23
+ export declare function applyClientPlugins(compiler: Compiler, options: ModuleFederationPluginOptions, extraOptions: NextFederationPluginExtraOptions): void;