@module-federation/nextjs-mf 8.8.56 → 8.8.58

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 (143) hide show
  1. package/dist/LICENSE +21 -0
  2. package/dist/_virtual/_rolldown/runtime.js +29 -0
  3. package/dist/_virtual/_rolldown/runtime.mjs +8 -0
  4. package/dist/client/UrlNode.js +89 -147
  5. package/dist/client/UrlNode.js.map +1 -1
  6. package/dist/client/UrlNode.mjs +91 -0
  7. package/dist/client/UrlNode.mjs.map +1 -0
  8. package/dist/src/federation-noop.d.mts +1 -0
  9. package/dist/src/federation-noop.d.ts +1 -0
  10. package/dist/src/federation-noop.js +17 -0
  11. package/dist/src/federation-noop.js.map +1 -1
  12. package/dist/src/federation-noop.mjs +23 -0
  13. package/dist/src/federation-noop.mjs.map +1 -0
  14. package/dist/src/index.d.mts +2 -0
  15. package/dist/src/index.d.ts +2 -3
  16. package/dist/src/index.js +13 -11
  17. package/dist/src/index.js.map +1 -1
  18. package/dist/src/index.mjs +8 -0
  19. package/dist/src/index.mjs.map +1 -0
  20. package/dist/src/internal.js +140 -243
  21. package/dist/src/internal.js.map +1 -1
  22. package/dist/src/internal.mjs +152 -0
  23. package/dist/src/internal.mjs.map +1 -0
  24. package/dist/src/loaders/fixImageLoader.d.mts +27 -0
  25. package/dist/src/loaders/fixImageLoader.d.ts +8 -3
  26. package/dist/src/loaders/fixImageLoader.js +91 -103
  27. package/dist/src/loaders/fixImageLoader.js.map +1 -1
  28. package/dist/src/loaders/fixImageLoader.mjs +101 -0
  29. package/dist/src/loaders/fixImageLoader.mjs.map +1 -0
  30. package/dist/src/loaders/fixUrlLoader.d.mts +16 -0
  31. package/dist/src/loaders/fixUrlLoader.d.ts +5 -2
  32. package/dist/src/loaders/fixUrlLoader.js +17 -19
  33. package/dist/src/loaders/fixUrlLoader.js.map +1 -1
  34. package/dist/src/loaders/fixUrlLoader.mjs +19 -0
  35. package/dist/src/loaders/fixUrlLoader.mjs.map +1 -0
  36. package/dist/src/loaders/helpers.js +72 -124
  37. package/dist/src/loaders/helpers.js.map +1 -1
  38. package/dist/src/loaders/helpers.mjs +79 -0
  39. package/dist/src/loaders/helpers.mjs.map +1 -0
  40. package/dist/src/loaders/nextPageMapLoader.d.mts +29 -0
  41. package/dist/src/loaders/nextPageMapLoader.d.ts +10 -5
  42. package/dist/src/loaders/nextPageMapLoader.js +126 -144
  43. package/dist/src/loaders/nextPageMapLoader.js.map +1 -1
  44. package/dist/src/loaders/nextPageMapLoader.mjs +143 -0
  45. package/dist/src/loaders/nextPageMapLoader.mjs.map +1 -0
  46. package/dist/src/logger.js +7 -7
  47. package/dist/src/logger.js.map +1 -1
  48. package/dist/src/logger.mjs +8 -0
  49. package/dist/src/logger.mjs.map +1 -0
  50. package/dist/src/plugins/CopyFederationPlugin.js +64 -71
  51. package/dist/src/plugins/CopyFederationPlugin.js.map +1 -1
  52. package/dist/src/plugins/CopyFederationPlugin.mjs +65 -0
  53. package/dist/src/plugins/CopyFederationPlugin.mjs.map +1 -0
  54. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.js +36 -53
  55. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.js.map +1 -1
  56. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.mjs +40 -0
  57. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.mjs.map +1 -0
  58. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.js +103 -121
  59. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.js.map +1 -1
  60. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.mjs +111 -0
  61. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.mjs.map +1 -0
  62. package/dist/src/plugins/NextFederationPlugin/index.d.mts +31 -0
  63. package/dist/src/plugins/NextFederationPlugin/index.d.ts +27 -23
  64. package/dist/src/plugins/NextFederationPlugin/index.js +151 -181
  65. package/dist/src/plugins/NextFederationPlugin/index.js.map +1 -1
  66. package/dist/src/plugins/NextFederationPlugin/index.mjs +153 -0
  67. package/dist/src/plugins/NextFederationPlugin/index.mjs.map +1 -0
  68. package/dist/src/plugins/NextFederationPlugin/next-fragments.d.mts +18 -0
  69. package/dist/src/plugins/NextFederationPlugin/next-fragments.d.ts +16 -18
  70. package/dist/src/plugins/NextFederationPlugin/next-fragments.js +58 -93
  71. package/dist/src/plugins/NextFederationPlugin/next-fragments.js.map +1 -1
  72. package/dist/src/plugins/NextFederationPlugin/next-fragments.mjs +63 -0
  73. package/dist/src/plugins/NextFederationPlugin/next-fragments.mjs.map +1 -0
  74. package/dist/src/plugins/NextFederationPlugin/set-options.js +17 -19
  75. package/dist/src/plugins/NextFederationPlugin/set-options.js.map +1 -1
  76. package/dist/src/plugins/NextFederationPlugin/set-options.mjs +19 -0
  77. package/dist/src/plugins/NextFederationPlugin/set-options.mjs.map +1 -0
  78. package/dist/src/plugins/NextFederationPlugin/validate-options.js +30 -38
  79. package/dist/src/plugins/NextFederationPlugin/validate-options.js.map +1 -1
  80. package/dist/src/plugins/NextFederationPlugin/validate-options.mjs +35 -0
  81. package/dist/src/plugins/NextFederationPlugin/validate-options.mjs.map +1 -0
  82. package/dist/src/plugins/container/InvertedContainerPlugin.js +23 -25
  83. package/dist/src/plugins/container/InvertedContainerPlugin.js.map +1 -1
  84. package/dist/src/plugins/container/InvertedContainerPlugin.mjs +27 -0
  85. package/dist/src/plugins/container/InvertedContainerPlugin.mjs.map +1 -0
  86. package/dist/src/plugins/container/InvertedContainerRuntimeModule.js +55 -67
  87. package/dist/src/plugins/container/InvertedContainerRuntimeModule.js.map +1 -1
  88. package/dist/src/plugins/container/InvertedContainerRuntimeModule.mjs +57 -0
  89. package/dist/src/plugins/container/InvertedContainerRuntimeModule.mjs.map +1 -0
  90. package/dist/src/plugins/container/runtimePlugin.d.mts +7 -0
  91. package/dist/src/plugins/container/runtimePlugin.d.ts +6 -2
  92. package/dist/src/plugins/container/runtimePlugin.js +167 -0
  93. package/dist/src/plugins/container/runtimePlugin.js.map +1 -1
  94. package/dist/src/plugins/container/runtimePlugin.mjs +166 -0
  95. package/dist/src/plugins/container/runtimePlugin.mjs.map +1 -0
  96. package/dist/utils/flushedChunks.d.mts +29 -0
  97. package/dist/utils/flushedChunks.d.ts +12 -5
  98. package/dist/utils/flushedChunks.js +32 -72
  99. package/dist/utils/flushedChunks.js.map +1 -1
  100. package/dist/utils/flushedChunks.mjs +35 -0
  101. package/dist/utils/flushedChunks.mjs.map +1 -0
  102. package/dist/utils/index.d.mts +14 -0
  103. package/dist/utils/index.d.ts +8 -14
  104. package/dist/utils/index.js +27 -62
  105. package/dist/utils/index.js.map +1 -1
  106. package/dist/utils/index.mjs +22 -0
  107. package/dist/utils/index.mjs.map +1 -0
  108. package/package.json +34 -10
  109. package/dist/client/UrlNode.d.ts +0 -17
  110. package/dist/node.d.ts +0 -1
  111. package/dist/node.js +0 -18
  112. package/dist/node.js.map +0 -1
  113. package/dist/package.json +0 -80
  114. package/dist/src/federation-noop.cjs +0 -15
  115. package/dist/src/internal.d.ts +0 -50
  116. package/dist/src/loaders/helpers.d.ts +0 -17
  117. package/dist/src/logger.d.ts +0 -2
  118. package/dist/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.d.ts +0 -5
  119. package/dist/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.js +0 -19
  120. package/dist/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.js.map +0 -1
  121. package/dist/src/plugins/CopyFederationPlugin.d.ts +0 -20
  122. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.d.ts +0 -23
  123. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.d.ts +0 -36
  124. package/dist/src/plugins/NextFederationPlugin/regex-equal.d.ts +0 -14
  125. package/dist/src/plugins/NextFederationPlugin/regex-equal.js +0 -25
  126. package/dist/src/plugins/NextFederationPlugin/regex-equal.js.map +0 -1
  127. package/dist/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.d.ts +0 -8
  128. package/dist/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js +0 -34
  129. package/dist/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js.map +0 -1
  130. package/dist/src/plugins/NextFederationPlugin/set-options.d.ts +0 -16
  131. package/dist/src/plugins/NextFederationPlugin/validate-options.d.ts +0 -25
  132. package/dist/src/plugins/container/InvertedContainerPlugin.d.ts +0 -5
  133. package/dist/src/plugins/container/InvertedContainerRuntimeModule.d.ts +0 -11
  134. package/dist/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.d.ts +0 -39
  135. package/dist/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.js +0 -78
  136. package/dist/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.js.map +0 -1
  137. package/dist/src/plugins/container/runtimePlugin.cjs +0 -219
  138. package/dist/src/plugins/container/types.d.ts +0 -2
  139. package/dist/src/plugins/container/types.js +0 -3
  140. package/dist/src/plugins/container/types.js.map +0 -1
  141. package/dist/src/types.d.ts +0 -28
  142. package/dist/src/types.js +0 -3
  143. package/dist/src/types.js.map +0 -1
@@ -1,166 +1,148 @@
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.default = nextPageMapLoader;
7
- exports.exposeNextjsPages = exposeNextjsPages;
8
- const fast_glob_1 = __importDefault(require("fast-glob"));
9
- const fs_1 = __importDefault(require("fs"));
10
- const UrlNode_1 = require("../../client/UrlNode");
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ const require_runtime = require('../../_virtual/_rolldown/runtime.js');
3
+ const require_UrlNode = require('../../client/UrlNode.js');
4
+ let fs = require("fs");
5
+ fs = require_runtime.__toESM(fs);
6
+ let fast_glob = require("fast-glob");
7
+ fast_glob = require_runtime.__toESM(fast_glob);
8
+
9
+ //#region src/loaders/nextPageMapLoader.ts
11
10
  /**
12
- * Webpack loader which prepares MF map for NextJS pages.
13
- * This function is the main entry point for the loader.
14
- * It gets the options passed to the loader and prepares the pages map.
15
- * If the 'v2' option is passed, it prepares the pages map using the 'preparePageMapV2' function.
16
- * Otherwise, it uses the 'preparePageMap' function.
17
- * Finally, it calls the loader's callback function with the prepared pages map.
18
- *
19
- * @param {LoaderContext<Record<string, unknown>>} this - The loader context.
20
- */
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
+ */
21
20
  function nextPageMapLoader() {
22
- // const [pagesRoot] = getNextPagesRoot(this.rootContext);
23
- // this.addContextDependency(pagesRoot);
24
- const opts = this.getOptions();
25
- const pages = getNextPages(this.rootContext);
26
- let result = {};
27
- if (Object.hasOwnProperty.call(opts, 'v2')) {
28
- result = preparePageMapV2(pages);
29
- }
30
- else {
31
- result = preparePageMap(pages);
32
- }
33
- this.callback(null, `module.exports = { default: ${JSON.stringify(result)} };`);
21
+ const opts = this.getOptions();
22
+ const pages = getNextPages(this.rootContext);
23
+ let result = {};
24
+ if (Object.hasOwnProperty.call(opts, "v2")) result = preparePageMapV2(pages);
25
+ else result = preparePageMap(pages);
26
+ this.callback(null, `module.exports = { default: ${JSON.stringify(result)} };`);
34
27
  }
35
28
  /**
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
- */
29
+ * Webpack config generator for `exposes` option.
30
+ * This function generates the webpack config for the 'exposes' option.
31
+ * It creates a map of pages to modules and returns an object with the pages map and the pages map v2.
32
+ *
33
+ * @param {string} cwd - The current working directory.
34
+ * @returns {Record<string, string>} The webpack config for the 'exposes' option.
35
+ */
43
36
  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
- };
37
+ const pages = getNextPages(cwd);
38
+ const pageModulesMap = {};
39
+ pages.forEach((page) => {
40
+ pageModulesMap["./" + sanitizePagePath(page)] = `./${page}`;
41
+ });
42
+ return {
43
+ "./pages-map": `${__filename}!${__filename}`,
44
+ "./pages-map-v2": `${__filename}?v2!${__filename}`,
45
+ ...pageModulesMap
46
+ };
57
47
  }
58
48
  /**
59
- * This function gets the root directory of the NextJS pages.
60
- * It checks if the 'src/pages/' directory exists.
61
- * If it does, it returns the absolute path and the relative path to this directory.
62
- * If it doesn't, it returns the absolute path and the relative path to the 'pages/' directory.
63
- *
64
- * @param {string} appRoot - The root directory of the application.
65
- * @returns {[string, string]} The absolute path and the relative path to the pages directory.
66
- */
49
+ * This function gets the root directory of the NextJS pages.
50
+ * It checks if the 'src/pages/' directory exists.
51
+ * If it does, it returns the absolute path and the relative path to this directory.
52
+ * If it doesn't, it returns the absolute path and the relative path to the 'pages/' directory.
53
+ *
54
+ * @param {string} appRoot - The root directory of the application.
55
+ * @returns {[string, string]} The absolute path and the relative path to the pages directory.
56
+ */
67
57
  function getNextPagesRoot(appRoot) {
68
- let pagesDir = 'src/pages/';
69
- let absPageDir = `${appRoot}/${pagesDir}`;
70
- if (!fs_1.default.existsSync(absPageDir)) {
71
- pagesDir = 'pages/';
72
- absPageDir = `${appRoot}/${pagesDir}`;
73
- }
74
- return [absPageDir, pagesDir];
58
+ let pagesDir = "src/pages/";
59
+ let absPageDir = `${appRoot}/${pagesDir}`;
60
+ if (!fs.default.existsSync(absPageDir)) {
61
+ pagesDir = "pages/";
62
+ absPageDir = `${appRoot}/${pagesDir}`;
63
+ }
64
+ return [absPageDir, pagesDir];
75
65
  }
76
66
  /**
77
- * This function scans the pages directory and returns a list of user defined pages.
78
- * It excludes special pages like '_app', '_document', '_error', '404', '500', and federation pages.
79
- *
80
- * @param {string} rootDir - The root directory of the application.
81
- * @returns {string[]} The list of user defined pages.
82
- */
67
+ * This function scans the pages directory and returns a list of user defined pages.
68
+ * It excludes special pages like '_app', '_document', '_error', '404', '500', and federation pages.
69
+ *
70
+ * @param {string} rootDir - The root directory of the application.
71
+ * @returns {string[]} The list of user defined pages.
72
+ */
83
73
  function getNextPages(rootDir) {
84
- const [cwd, pagesDir] = getNextPagesRoot(rootDir);
85
- // scan all files in pages folder except pages/api
86
- let pageList = fast_glob_1.default.sync('**/*.{ts,tsx,js,jsx}', {
87
- cwd,
88
- onlyFiles: true,
89
- ignore: ['api/**'],
90
- });
91
- // remove specific nextjs pages
92
- const exclude = [
93
- /^_app\..*/, // _app.tsx
94
- /^_document\..*/, // _document.tsx
95
- /^_error\..*/, // _error.tsx
96
- /^404\..*/, // 404.tsx
97
- /^500\..*/, // 500.tsx
98
- /^\[\.\.\..*\]\..*/, // /[...federationPage].tsx
99
- ];
100
- pageList = pageList.filter((page) => {
101
- return !exclude.some((r) => r.test(page));
102
- });
103
- pageList = pageList.map((page) => `${pagesDir}${page}`);
104
- return pageList;
74
+ const [cwd, pagesDir] = getNextPagesRoot(rootDir);
75
+ let pageList = fast_glob.default.sync("**/*.{ts,tsx,js,jsx}", {
76
+ cwd,
77
+ onlyFiles: true,
78
+ ignore: ["api/**"]
79
+ });
80
+ const exclude = [
81
+ /^_app\..*/,
82
+ /^_document\..*/,
83
+ /^_error\..*/,
84
+ /^404\..*/,
85
+ /^500\..*/,
86
+ /^\[\.\.\..*\]\..*/
87
+ ];
88
+ pageList = pageList.filter((page) => {
89
+ return !exclude.some((r) => r.test(page));
90
+ });
91
+ pageList = pageList.map((page) => `${pagesDir}${page}`);
92
+ return pageList;
105
93
  }
106
94
  /**
107
- * This function sanitizes a page path.
108
- * It removes the 'src/pages/' prefix and the file extension.
109
- *
110
- * @param {string} item - The page path to sanitize.
111
- * @returns {string} The sanitized page path.
112
- */
95
+ * This function sanitizes a page path.
96
+ * It removes the 'src/pages/' prefix and the file extension.
97
+ *
98
+ * @param {string} item - The page path to sanitize.
99
+ * @returns {string} The sanitized page path.
100
+ */
113
101
  function sanitizePagePath(item) {
114
- return item
115
- .replace(/^src\/pages\//i, 'pages/')
116
- .replace(/\.(ts|tsx|js|jsx)$/, '');
102
+ return item.replace(/^src\/pages\//i, "pages/").replace(/\.(ts|tsx|js|jsx)$/, "");
117
103
  }
118
104
  /**
119
- * This function creates a MF map from a list of NextJS pages.
120
- * It sanitizes the page paths and sorts them using the 'UrlNode' class.
121
- * Then, it creates a map with the sorted page paths as keys and the original page paths as values.
122
- *
123
- * @param {string[]} pages - The list of NextJS pages.
124
- * @returns {Record<string, string>} The MF map.
125
- */
105
+ * This function creates a MF map from a list of NextJS pages.
106
+ * It sanitizes the page paths and sorts them using the 'UrlNode' class.
107
+ * Then, it creates a map with the sorted page paths as keys and the original page paths as values.
108
+ *
109
+ * @param {string[]} pages - The list of NextJS pages.
110
+ * @returns {Record<string, string>} The MF map.
111
+ */
126
112
  function preparePageMap(pages) {
127
- const result = {};
128
- const clearedPages = pages.map((p) => `/${sanitizePagePath(p)}`);
129
- // getSortedRoutes @see https://github.com/vercel/next.js/blob/canary/packages/next/shared/lib/router/utils/sorted-routes.ts
130
- const root = new UrlNode_1.UrlNode();
131
- clearedPages.forEach((pagePath) => root.insert(pagePath));
132
- // Smoosh will then sort those sublevels up to the point where you get the correct route definition priority
133
- const sortedPages = root.smoosh();
134
- sortedPages.forEach((page) => {
135
- let key = page
136
- .replace(/\[\.\.\.[^\]]+\]/gi, '*')
137
- .replace(/\[([^\]]+)\]/gi, ':$1');
138
- key = key.replace(/^\/pages\//, '/').replace(/\/index$/, '') || '/';
139
- result[key] = `.${page}`;
140
- });
141
- return result;
113
+ const result = {};
114
+ const clearedPages = pages.map((p) => `/${sanitizePagePath(p)}`);
115
+ const root = new require_UrlNode.UrlNode();
116
+ clearedPages.forEach((pagePath) => root.insert(pagePath));
117
+ root.smoosh().forEach((page) => {
118
+ let key = page.replace(/\[\.\.\.[^\]]+\]/gi, "*").replace(/\[([^\]]+)\]/gi, ":$1");
119
+ key = key.replace(/^\/pages\//, "/").replace(/\/index$/, "") || "/";
120
+ result[key] = `.${page}`;
121
+ });
122
+ return result;
142
123
  }
143
124
  /**
144
- * This function creates a MF list from a list of NextJS pages.
145
- * It sanitizes the page paths and sorts them using the 'UrlNode' class.
146
- * Then, it creates a map with the sorted page paths as keys and the original page paths as values.
147
- * Unlike the 'preparePageMap' function, this function does not replace the '[...]' and '[]' parts in the page paths.
148
- *
149
- * @param {string[]} pages - The list of NextJS pages.
150
- * @returns {Record<string, string>} The MF list.
151
- */
125
+ * This function creates a MF list from a list of NextJS pages.
126
+ * It sanitizes the page paths and sorts them using the 'UrlNode' class.
127
+ * Then, it creates a map with the sorted page paths as keys and the original page paths as values.
128
+ * Unlike the 'preparePageMap' function, this function does not replace the '[...]' and '[]' parts in the page paths.
129
+ *
130
+ * @param {string[]} pages - The list of NextJS pages.
131
+ * @returns {Record<string, string>} The MF list.
132
+ */
152
133
  function preparePageMapV2(pages) {
153
- const result = {};
154
- const clearedPages = pages.map((p) => `/${sanitizePagePath(p)}`);
155
- // getSortedRoutes @see https://github.com/vercel/next.js/blob/canary/packages/next/shared/lib/router/utils/sorted-routes.ts
156
- const root = new UrlNode_1.UrlNode();
157
- clearedPages.forEach((pagePath) => root.insert(pagePath));
158
- // Smoosh will then sort those sublevels up to the point where you get the correct route definition priority
159
- const sortedPages = root.smoosh();
160
- sortedPages.forEach((page) => {
161
- const key = page.replace(/^\/pages\//, '/').replace(/\/index$/, '') || '/';
162
- result[key] = `.${page}`;
163
- });
164
- return result;
134
+ const result = {};
135
+ const clearedPages = pages.map((p) => `/${sanitizePagePath(p)}`);
136
+ const root = new require_UrlNode.UrlNode();
137
+ clearedPages.forEach((pagePath) => root.insert(pagePath));
138
+ root.smoosh().forEach((page) => {
139
+ const key = page.replace(/^\/pages\//, "/").replace(/\/index$/, "") || "/";
140
+ result[key] = `.${page}`;
141
+ });
142
+ return result;
165
143
  }
144
+
145
+ //#endregion
146
+ exports.default = nextPageMapLoader;
147
+ exports.exposeNextjsPages = exposeNextjsPages;
166
148
  //# sourceMappingURL=nextPageMapLoader.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"nextPageMapLoader.js","sourceRoot":"","sources":["../../../src/loaders/nextPageMapLoader.ts"],"names":[],"mappings":";;;;;AAiBA,oCAoBC;AAUD,8CAgBC;AA7DD,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;AAED;;;;;;;GA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from 'webpack';\n\nimport fg from 'fast-glob';\nimport fs from 'fs';\n\nimport { UrlNode } from '../../client/UrlNode';\n\n/**\n * Webpack loader which prepares MF map for NextJS pages.\n * This function is the main entry point for the loader.\n * It gets the options passed to the loader and prepares the pages map.\n * If the 'v2' option is passed, it prepares the pages map using the 'preparePageMapV2' function.\n * Otherwise, it uses the 'preparePageMap' function.\n * Finally, it calls the loader's callback function with the prepared pages map.\n *\n * @param {LoaderContext<Record<string, unknown>>} this - The loader context.\n */\nexport default function nextPageMapLoader(\n this: LoaderContext<Record<string, unknown>>,\n) {\n // const [pagesRoot] = getNextPagesRoot(this.rootContext);\n // this.addContextDependency(pagesRoot);\n const opts = this.getOptions();\n const pages = getNextPages(this.rootContext);\n\n let result = {};\n\n if (Object.hasOwnProperty.call(opts, 'v2')) {\n result = preparePageMapV2(pages);\n } else {\n result = preparePageMap(pages);\n }\n\n this.callback(\n null,\n `module.exports = { default: ${JSON.stringify(result)} };`,\n );\n}\n\n/**\n * Webpack config generator for `exposes` option.\n * This function generates the webpack config for the 'exposes' option.\n * It creates a map of pages to modules and returns an object with the pages map and the pages map v2.\n *\n * @param {string} cwd - The current working directory.\n * @returns {Record<string, string>} The webpack config for the 'exposes' option.\n */\nexport function exposeNextjsPages(cwd: string) {\n const pages = getNextPages(cwd);\n\n const pageModulesMap = {} as Record<string, string>;\n pages.forEach((page) => {\n // Creating a map of pages to modules\n // './pages/storage/index': './pages/storage/index.tsx',\n // './pages/storage/[...slug]': './pages/storage/[...slug].tsx',\n pageModulesMap['./' + sanitizePagePath(page)] = `./${page}`;\n });\n\n return {\n './pages-map': `${__filename}!${__filename}`,\n './pages-map-v2': `${__filename}?v2!${__filename}`,\n ...pageModulesMap,\n };\n}\n\n/**\n * This function gets the root directory of the NextJS pages.\n * It checks if the 'src/pages/' directory exists.\n * If it does, it returns the absolute path and the relative path to this directory.\n * If it doesn't, it returns the absolute path and the relative path to the 'pages/' directory.\n *\n * @param {string} appRoot - The root directory of the application.\n * @returns {[string, string]} The absolute path and the relative path to the pages directory.\n */\nfunction getNextPagesRoot(appRoot: string) {\n let pagesDir = 'src/pages/';\n let absPageDir = `${appRoot}/${pagesDir}`;\n if (!fs.existsSync(absPageDir)) {\n pagesDir = 'pages/';\n absPageDir = `${appRoot}/${pagesDir}`;\n }\n\n return [absPageDir, pagesDir];\n}\n\n/**\n * This function scans the pages directory and returns a list of user defined pages.\n * It excludes special pages like '_app', '_document', '_error', '404', '500', and federation pages.\n *\n * @param {string} rootDir - The root directory of the application.\n * @returns {string[]} The list of user defined pages.\n */\nfunction getNextPages(rootDir: string) {\n const [cwd, pagesDir] = getNextPagesRoot(rootDir);\n\n // scan all files in pages folder except pages/api\n let pageList = fg.sync('**/*.{ts,tsx,js,jsx}', {\n cwd,\n onlyFiles: true,\n ignore: ['api/**'],\n });\n\n // remove specific nextjs pages\n const exclude = [\n /^_app\\..*/, // _app.tsx\n /^_document\\..*/, // _document.tsx\n /^_error\\..*/, // _error.tsx\n /^404\\..*/, // 404.tsx\n /^500\\..*/, // 500.tsx\n /^\\[\\.\\.\\..*\\]\\..*/, // /[...federationPage].tsx\n ];\n pageList = pageList.filter((page) => {\n return !exclude.some((r) => r.test(page));\n });\n\n pageList = pageList.map((page) => `${pagesDir}${page}`);\n\n return pageList;\n}\n\n/**\n * This function sanitizes a page path.\n * It removes the 'src/pages/' prefix and the file extension.\n *\n * @param {string} item - The page path to sanitize.\n * @returns {string} The sanitized page path.\n */\nfunction sanitizePagePath(item: string) {\n return item\n .replace(/^src\\/pages\\//i, 'pages/')\n .replace(/\\.(ts|tsx|js|jsx)$/, '');\n}\n\n/**\n * This function creates a MF map from a list of NextJS pages.\n * It sanitizes the page paths and sorts them using the 'UrlNode' class.\n * Then, it creates a map with the sorted page paths as keys and the original page paths as values.\n *\n * @param {string[]} pages - The list of NextJS pages.\n * @returns {Record<string, string>} The MF map.\n */\nfunction preparePageMap(pages: string[]) {\n const result = {} as Record<string, string>;\n\n const clearedPages = pages.map((p) => `/${sanitizePagePath(p)}`);\n\n // getSortedRoutes @see https://github.com/vercel/next.js/blob/canary/packages/next/shared/lib/router/utils/sorted-routes.ts\n const root = new UrlNode();\n clearedPages.forEach((pagePath) => root.insert(pagePath));\n // Smoosh will then sort those sublevels up to the point where you get the correct route definition priority\n const sortedPages = root.smoosh();\n\n sortedPages.forEach((page) => {\n let key = page\n .replace(/\\[\\.\\.\\.[^\\]]+\\]/gi, '*')\n .replace(/\\[([^\\]]+)\\]/gi, ':$1');\n key = key.replace(/^\\/pages\\//, '/').replace(/\\/index$/, '') || '/';\n result[key] = `.${page}`;\n });\n\n return result;\n}\n\n/**\n * This function creates a MF list from a list of NextJS pages.\n * It sanitizes the page paths and sorts them using the 'UrlNode' class.\n * Then, it creates a map with the sorted page paths as keys and the original page paths as values.\n * Unlike the 'preparePageMap' function, this function does not replace the '[...]' and '[]' parts in the page paths.\n *\n * @param {string[]} pages - The list of NextJS pages.\n * @returns {Record<string, string>} The MF list.\n */\nfunction preparePageMapV2(pages: string[]) {\n const result = {} as Record<string, string>;\n\n const clearedPages = pages.map((p) => `/${sanitizePagePath(p)}`);\n\n // getSortedRoutes @see https://github.com/vercel/next.js/blob/canary/packages/next/shared/lib/router/utils/sorted-routes.ts\n const root = new UrlNode();\n clearedPages.forEach((pagePath) => root.insert(pagePath));\n // Smoosh will then sort those sublevels up to the point where you get the correct route definition priority\n const sortedPages = root.smoosh();\n\n sortedPages.forEach((page) => {\n const key = page.replace(/^\\/pages\\//, '/').replace(/\\/index$/, '') || '/';\n result[key] = `.${page}`;\n });\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiBA,SAAwB,oBAEtB;CAGA,MAAM,OAAO,KAAK,YAAY;CAC9B,MAAM,QAAQ,aAAa,KAAK,YAAY;CAE5C,IAAI,SAAS,EAAE;AAEf,KAAI,OAAO,eAAe,KAAK,MAAM,KAAK,CACxC,UAAS,iBAAiB,MAAM;KAEhC,UAAS,eAAe,MAAM;AAGhC,MAAK,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D,CAFoB,KAAK,QAAQ,CAErB,SAAS,SAAS;EAC5B,IAAI,MAAM,KACP,QAAQ,sBAAsB,IAAI,CAClC,QAAQ,kBAAkB,MAAM;AACnC,QAAM,IAAI,QAAQ,cAAc,IAAI,CAAC,QAAQ,YAAY,GAAG,IAAI;AAChE,SAAO,OAAO,IAAI;GAClB;AAEF,QAAO;;;;;;;;;;;AAYT,SAAS,iBAAiB,OAAiB;CACzC,MAAM,SAAS,EAAE;CAEjB,MAAM,eAAe,MAAM,KAAK,MAAM,IAAI,iBAAiB,EAAE,GAAG;CAGhE,MAAM,OAAO,IAAIA,yBAAS;AAC1B,cAAa,SAAS,aAAa,KAAK,OAAO,SAAS,CAAC;AAIzD,CAFoB,KAAK,QAAQ,CAErB,SAAS,SAAS;EAC5B,MAAM,MAAM,KAAK,QAAQ,cAAc,IAAI,CAAC,QAAQ,YAAY,GAAG,IAAI;AACvE,SAAO,OAAO,IAAI;GAClB;AAEF,QAAO"}
@@ -0,0 +1,143 @@
1
+ import { UrlNode } from "../../client/UrlNode.mjs";
2
+ import fs from "fs";
3
+ import fg from "fast-glob";
4
+
5
+ //#region src/loaders/nextPageMapLoader.ts
6
+ /**
7
+ * Webpack loader which prepares MF map for NextJS pages.
8
+ * This function is the main entry point for the loader.
9
+ * It gets the options passed to the loader and prepares the pages map.
10
+ * If the 'v2' option is passed, it prepares the pages map using the 'preparePageMapV2' function.
11
+ * Otherwise, it uses the 'preparePageMap' function.
12
+ * Finally, it calls the loader's callback function with the prepared pages map.
13
+ *
14
+ * @param {LoaderContext<Record<string, unknown>>} this - The loader context.
15
+ */
16
+ function nextPageMapLoader() {
17
+ const opts = this.getOptions();
18
+ const pages = getNextPages(this.rootContext);
19
+ let result = {};
20
+ if (Object.hasOwnProperty.call(opts, "v2")) result = preparePageMapV2(pages);
21
+ else result = preparePageMap(pages);
22
+ this.callback(null, `module.exports = { default: ${JSON.stringify(result)} };`);
23
+ }
24
+ /**
25
+ * Webpack config generator for `exposes` option.
26
+ * This function generates the webpack config for the 'exposes' option.
27
+ * It creates a map of pages to modules and returns an object with the pages map and the pages map v2.
28
+ *
29
+ * @param {string} cwd - The current working directory.
30
+ * @returns {Record<string, string>} The webpack config for the 'exposes' option.
31
+ */
32
+ function exposeNextjsPages(cwd) {
33
+ const pages = getNextPages(cwd);
34
+ const pageModulesMap = {};
35
+ pages.forEach((page) => {
36
+ pageModulesMap["./" + sanitizePagePath(page)] = `./${page}`;
37
+ });
38
+ return {
39
+ "./pages-map": `${__filename}!${__filename}`,
40
+ "./pages-map-v2": `${__filename}?v2!${__filename}`,
41
+ ...pageModulesMap
42
+ };
43
+ }
44
+ /**
45
+ * This function gets the root directory of the NextJS pages.
46
+ * It checks if the 'src/pages/' directory exists.
47
+ * If it does, it returns the absolute path and the relative path to this directory.
48
+ * If it doesn't, it returns the absolute path and the relative path to the 'pages/' directory.
49
+ *
50
+ * @param {string} appRoot - The root directory of the application.
51
+ * @returns {[string, string]} The absolute path and the relative path to the pages directory.
52
+ */
53
+ function getNextPagesRoot(appRoot) {
54
+ let pagesDir = "src/pages/";
55
+ let absPageDir = `${appRoot}/${pagesDir}`;
56
+ if (!fs.existsSync(absPageDir)) {
57
+ pagesDir = "pages/";
58
+ absPageDir = `${appRoot}/${pagesDir}`;
59
+ }
60
+ return [absPageDir, pagesDir];
61
+ }
62
+ /**
63
+ * This function scans the pages directory and returns a list of user defined pages.
64
+ * It excludes special pages like '_app', '_document', '_error', '404', '500', and federation pages.
65
+ *
66
+ * @param {string} rootDir - The root directory of the application.
67
+ * @returns {string[]} The list of user defined pages.
68
+ */
69
+ function getNextPages(rootDir) {
70
+ const [cwd, pagesDir] = getNextPagesRoot(rootDir);
71
+ let pageList = fg.sync("**/*.{ts,tsx,js,jsx}", {
72
+ cwd,
73
+ onlyFiles: true,
74
+ ignore: ["api/**"]
75
+ });
76
+ const exclude = [
77
+ /^_app\..*/,
78
+ /^_document\..*/,
79
+ /^_error\..*/,
80
+ /^404\..*/,
81
+ /^500\..*/,
82
+ /^\[\.\.\..*\]\..*/
83
+ ];
84
+ pageList = pageList.filter((page) => {
85
+ return !exclude.some((r) => r.test(page));
86
+ });
87
+ pageList = pageList.map((page) => `${pagesDir}${page}`);
88
+ return pageList;
89
+ }
90
+ /**
91
+ * This function sanitizes a page path.
92
+ * It removes the 'src/pages/' prefix and the file extension.
93
+ *
94
+ * @param {string} item - The page path to sanitize.
95
+ * @returns {string} The sanitized page path.
96
+ */
97
+ function sanitizePagePath(item) {
98
+ return item.replace(/^src\/pages\//i, "pages/").replace(/\.(ts|tsx|js|jsx)$/, "");
99
+ }
100
+ /**
101
+ * This function creates a MF map from a list of NextJS pages.
102
+ * It sanitizes the page paths and sorts them using the 'UrlNode' class.
103
+ * Then, it creates a map with the sorted page paths as keys and the original page paths as values.
104
+ *
105
+ * @param {string[]} pages - The list of NextJS pages.
106
+ * @returns {Record<string, string>} The MF map.
107
+ */
108
+ function preparePageMap(pages) {
109
+ const result = {};
110
+ const clearedPages = pages.map((p) => `/${sanitizePagePath(p)}`);
111
+ const root = new UrlNode();
112
+ clearedPages.forEach((pagePath) => root.insert(pagePath));
113
+ root.smoosh().forEach((page) => {
114
+ let key = page.replace(/\[\.\.\.[^\]]+\]/gi, "*").replace(/\[([^\]]+)\]/gi, ":$1");
115
+ key = key.replace(/^\/pages\//, "/").replace(/\/index$/, "") || "/";
116
+ result[key] = `.${page}`;
117
+ });
118
+ return result;
119
+ }
120
+ /**
121
+ * This function creates a MF list from a list of NextJS pages.
122
+ * It sanitizes the page paths and sorts them using the 'UrlNode' class.
123
+ * Then, it creates a map with the sorted page paths as keys and the original page paths as values.
124
+ * Unlike the 'preparePageMap' function, this function does not replace the '[...]' and '[]' parts in the page paths.
125
+ *
126
+ * @param {string[]} pages - The list of NextJS pages.
127
+ * @returns {Record<string, string>} The MF list.
128
+ */
129
+ function preparePageMapV2(pages) {
130
+ const result = {};
131
+ const clearedPages = pages.map((p) => `/${sanitizePagePath(p)}`);
132
+ const root = new UrlNode();
133
+ clearedPages.forEach((pagePath) => root.insert(pagePath));
134
+ root.smoosh().forEach((page) => {
135
+ const key = page.replace(/^\/pages\//, "/").replace(/\/index$/, "") || "/";
136
+ result[key] = `.${page}`;
137
+ });
138
+ return result;
139
+ }
140
+
141
+ //#endregion
142
+ export { nextPageMapLoader as default, exposeNextjsPages };
143
+ //# sourceMappingURL=nextPageMapLoader.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nextPageMapLoader.mjs","names":[],"sources":["../../../src/loaders/nextPageMapLoader.ts"],"sourcesContent":["import type { LoaderContext } from 'webpack';\n\nimport fg from 'fast-glob';\nimport fs from 'fs';\n\nimport { UrlNode } from '../../client/UrlNode';\n\n/**\n * Webpack loader which prepares MF map for NextJS pages.\n * This function is the main entry point for the loader.\n * It gets the options passed to the loader and prepares the pages map.\n * If the 'v2' option is passed, it prepares the pages map using the 'preparePageMapV2' function.\n * Otherwise, it uses the 'preparePageMap' function.\n * Finally, it calls the loader's callback function with the prepared pages map.\n *\n * @param {LoaderContext<Record<string, unknown>>} this - The loader context.\n */\nexport default function nextPageMapLoader(\n this: LoaderContext<Record<string, unknown>>,\n) {\n // const [pagesRoot] = getNextPagesRoot(this.rootContext);\n // this.addContextDependency(pagesRoot);\n const opts = this.getOptions();\n const pages = getNextPages(this.rootContext);\n\n let result = {};\n\n if (Object.hasOwnProperty.call(opts, 'v2')) {\n result = preparePageMapV2(pages);\n } else {\n result = preparePageMap(pages);\n }\n\n this.callback(\n null,\n `module.exports = { default: ${JSON.stringify(result)} };`,\n );\n}\n\n/**\n * Webpack config generator for `exposes` option.\n * This function generates the webpack config for the 'exposes' option.\n * It creates a map of pages to modules and returns an object with the pages map and the pages map v2.\n *\n * @param {string} cwd - The current working directory.\n * @returns {Record<string, string>} The webpack config for the 'exposes' option.\n */\nexport function exposeNextjsPages(cwd: string) {\n const pages = getNextPages(cwd);\n\n const pageModulesMap = {} as Record<string, string>;\n pages.forEach((page) => {\n // Creating a map of pages to modules\n // './pages/storage/index': './pages/storage/index.tsx',\n // './pages/storage/[...slug]': './pages/storage/[...slug].tsx',\n pageModulesMap['./' + sanitizePagePath(page)] = `./${page}`;\n });\n\n return {\n './pages-map': `${__filename}!${__filename}`,\n './pages-map-v2': `${__filename}?v2!${__filename}`,\n ...pageModulesMap,\n };\n}\n\n/**\n * This function gets the root directory of the NextJS pages.\n * It checks if the 'src/pages/' directory exists.\n * If it does, it returns the absolute path and the relative path to this directory.\n * If it doesn't, it returns the absolute path and the relative path to the 'pages/' directory.\n *\n * @param {string} appRoot - The root directory of the application.\n * @returns {[string, string]} The absolute path and the relative path to the pages directory.\n */\nfunction getNextPagesRoot(appRoot: string) {\n let pagesDir = 'src/pages/';\n let absPageDir = `${appRoot}/${pagesDir}`;\n if (!fs.existsSync(absPageDir)) {\n pagesDir = 'pages/';\n absPageDir = `${appRoot}/${pagesDir}`;\n }\n\n return [absPageDir, pagesDir];\n}\n\n/**\n * This function scans the pages directory and returns a list of user defined pages.\n * It excludes special pages like '_app', '_document', '_error', '404', '500', and federation pages.\n *\n * @param {string} rootDir - The root directory of the application.\n * @returns {string[]} The list of user defined pages.\n */\nfunction getNextPages(rootDir: string) {\n const [cwd, pagesDir] = getNextPagesRoot(rootDir);\n\n // scan all files in pages folder except pages/api\n let pageList = fg.sync('**/*.{ts,tsx,js,jsx}', {\n cwd,\n onlyFiles: true,\n ignore: ['api/**'],\n });\n\n // remove specific nextjs pages\n const exclude = [\n /^_app\\..*/, // _app.tsx\n /^_document\\..*/, // _document.tsx\n /^_error\\..*/, // _error.tsx\n /^404\\..*/, // 404.tsx\n /^500\\..*/, // 500.tsx\n /^\\[\\.\\.\\..*\\]\\..*/, // /[...federationPage].tsx\n ];\n pageList = pageList.filter((page) => {\n return !exclude.some((r) => r.test(page));\n });\n\n pageList = pageList.map((page) => `${pagesDir}${page}`);\n\n return pageList;\n}\n\n/**\n * This function sanitizes a page path.\n * It removes the 'src/pages/' prefix and the file extension.\n *\n * @param {string} item - The page path to sanitize.\n * @returns {string} The sanitized page path.\n */\nfunction sanitizePagePath(item: string) {\n return item\n .replace(/^src\\/pages\\//i, 'pages/')\n .replace(/\\.(ts|tsx|js|jsx)$/, '');\n}\n\n/**\n * This function creates a MF map from a list of NextJS pages.\n * It sanitizes the page paths and sorts them using the 'UrlNode' class.\n * Then, it creates a map with the sorted page paths as keys and the original page paths as values.\n *\n * @param {string[]} pages - The list of NextJS pages.\n * @returns {Record<string, string>} The MF map.\n */\nfunction preparePageMap(pages: string[]) {\n const result = {} as Record<string, string>;\n\n const clearedPages = pages.map((p) => `/${sanitizePagePath(p)}`);\n\n // getSortedRoutes @see https://github.com/vercel/next.js/blob/canary/packages/next/shared/lib/router/utils/sorted-routes.ts\n const root = new UrlNode();\n clearedPages.forEach((pagePath) => root.insert(pagePath));\n // Smoosh will then sort those sublevels up to the point where you get the correct route definition priority\n const sortedPages = root.smoosh();\n\n sortedPages.forEach((page) => {\n let key = page\n .replace(/\\[\\.\\.\\.[^\\]]+\\]/gi, '*')\n .replace(/\\[([^\\]]+)\\]/gi, ':$1');\n key = key.replace(/^\\/pages\\//, '/').replace(/\\/index$/, '') || '/';\n result[key] = `.${page}`;\n });\n\n return result;\n}\n\n/**\n * This function creates a MF list from a list of NextJS pages.\n * It sanitizes the page paths and sorts them using the 'UrlNode' class.\n * Then, it creates a map with the sorted page paths as keys and the original page paths as values.\n * Unlike the 'preparePageMap' function, this function does not replace the '[...]' and '[]' parts in the page paths.\n *\n * @param {string[]} pages - The list of NextJS pages.\n * @returns {Record<string, string>} The MF list.\n */\nfunction preparePageMapV2(pages: string[]) {\n const result = {} as Record<string, string>;\n\n const clearedPages = pages.map((p) => `/${sanitizePagePath(p)}`);\n\n // getSortedRoutes @see https://github.com/vercel/next.js/blob/canary/packages/next/shared/lib/router/utils/sorted-routes.ts\n const root = new UrlNode();\n clearedPages.forEach((pagePath) => root.insert(pagePath));\n // Smoosh will then sort those sublevels up to the point where you get the correct route definition priority\n const sortedPages = root.smoosh();\n\n sortedPages.forEach((page) => {\n const key = page.replace(/^\\/pages\\//, '/').replace(/\\/index$/, '') || '/';\n result[key] = `.${page}`;\n });\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,SAAwB,oBAEtB;CAGA,MAAM,OAAO,KAAK,YAAY;CAC9B,MAAM,QAAQ,aAAa,KAAK,YAAY;CAE5C,IAAI,SAAS,EAAE;AAEf,KAAI,OAAO,eAAe,KAAK,MAAM,KAAK,CACxC,UAAS,iBAAiB,MAAM;KAEhC,UAAS,eAAe,MAAM;AAGhC,MAAK,SACH,MACA,+BAA+B,KAAK,UAAU,OAAO,CAAC,KACvD;;;;;;;;;;AAWH,SAAgB,kBAAkB,KAAa;CAC7C,MAAM,QAAQ,aAAa,IAAI;CAE/B,MAAM,iBAAiB,EAAE;AACzB,OAAM,SAAS,SAAS;AAItB,iBAAe,OAAO,iBAAiB,KAAK,IAAI,KAAK;GACrD;AAEF,QAAO;EACL,eAAe,GAAG,WAAW,GAAG;EAChC,kBAAkB,GAAG,WAAW,MAAM;EACtC,GAAG;EACJ;;;;;;;;;;;AAYH,SAAS,iBAAiB,SAAiB;CACzC,IAAI,WAAW;CACf,IAAI,aAAa,GAAG,QAAQ,GAAG;AAC/B,KAAI,CAAC,GAAG,WAAW,WAAW,EAAE;AAC9B,aAAW;AACX,eAAa,GAAG,QAAQ,GAAG;;AAG7B,QAAO,CAAC,YAAY,SAAS;;;;;;;;;AAU/B,SAAS,aAAa,SAAiB;CACrC,MAAM,CAAC,KAAK,YAAY,iBAAiB,QAAQ;CAGjD,IAAI,WAAW,GAAG,KAAK,wBAAwB;EAC7C;EACA,WAAW;EACX,QAAQ,CAAC,SAAS;EACnB,CAAC;CAGF,MAAM,UAAU;EACd;EACA;EACA;EACA;EACA;EACA;EACD;AACD,YAAW,SAAS,QAAQ,SAAS;AACnC,SAAO,CAAC,QAAQ,MAAM,MAAM,EAAE,KAAK,KAAK,CAAC;GACzC;AAEF,YAAW,SAAS,KAAK,SAAS,GAAG,WAAW,OAAO;AAEvD,QAAO;;;;;;;;;AAUT,SAAS,iBAAiB,MAAc;AACtC,QAAO,KACJ,QAAQ,kBAAkB,SAAS,CACnC,QAAQ,sBAAsB,GAAG;;;;;;;;;;AAWtC,SAAS,eAAe,OAAiB;CACvC,MAAM,SAAS,EAAE;CAEjB,MAAM,eAAe,MAAM,KAAK,MAAM,IAAI,iBAAiB,EAAE,GAAG;CAGhE,MAAM,OAAO,IAAI,SAAS;AAC1B,cAAa,SAAS,aAAa,KAAK,OAAO,SAAS,CAAC;AAIzD,CAFoB,KAAK,QAAQ,CAErB,SAAS,SAAS;EAC5B,IAAI,MAAM,KACP,QAAQ,sBAAsB,IAAI,CAClC,QAAQ,kBAAkB,MAAM;AACnC,QAAM,IAAI,QAAQ,cAAc,IAAI,CAAC,QAAQ,YAAY,GAAG,IAAI;AAChE,SAAO,OAAO,IAAI;GAClB;AAEF,QAAO;;;;;;;;;;;AAYT,SAAS,iBAAiB,OAAiB;CACzC,MAAM,SAAS,EAAE;CAEjB,MAAM,eAAe,MAAM,KAAK,MAAM,IAAI,iBAAiB,EAAE,GAAG;CAGhE,MAAM,OAAO,IAAI,SAAS;AAC1B,cAAa,SAAS,aAAa,KAAK,OAAO,SAAS,CAAC;AAIzD,CAFoB,KAAK,QAAQ,CAErB,SAAS,SAAS;EAC5B,MAAM,MAAM,KAAK,QAAQ,cAAc,IAAI,CAAC,QAAQ,YAAY,GAAG,IAAI;AACvE,SAAO,OAAO,IAAI;GAClB;AAEF,QAAO"}
@@ -1,9 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const sdk_1 = require("@module-federation/sdk");
4
- const createBundlerLogger = typeof sdk_1.createInfrastructureLogger === 'function'
5
- ? sdk_1.createInfrastructureLogger
6
- : sdk_1.createLogger;
7
- const logger = createBundlerLogger('[ nextjs-mf ]');
1
+ const require_runtime = require('../_virtual/_rolldown/runtime.js');
2
+ let _module_federation_sdk = require("@module-federation/sdk");
3
+
4
+ //#region src/logger.ts
5
+ const logger = (typeof _module_federation_sdk.createInfrastructureLogger === "function" ? _module_federation_sdk.createInfrastructureLogger : _module_federation_sdk.createLogger)("[ nextjs-mf ]");
6
+
7
+ //#endregion
8
8
  exports.default = logger;
9
9
  //# sourceMappingURL=logger.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":";;AAAA,gDAGgC;AAEhC,MAAM,mBAAmB,GACvB,OAAO,gCAA0B,KAAK,UAAU;IAC9C,CAAC,CAAE,gCAA6D;IAChE,CAAC,CAAC,kBAAY,CAAC;AAEnB,MAAM,MAAM,GAAG,mBAAmB,CAAC,eAAe,CAAC,CAAC;AAEpD,kBAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"logger.js","names":["createInfrastructureLogger","createLogger"],"sources":["../../src/logger.ts"],"sourcesContent":["import {\n createInfrastructureLogger,\n createLogger,\n} from '@module-federation/sdk';\n\nconst createBundlerLogger: typeof createLogger =\n typeof createInfrastructureLogger === 'function'\n ? (createInfrastructureLogger as unknown as typeof createLogger)\n : createLogger;\n\nconst logger = createBundlerLogger('[ nextjs-mf ]');\n\nexport default logger;\n"],"mappings":";;;;AAUA,MAAM,UAJJ,OAAOA,sDAA+B,aACjCA,oDACDC,qCAE6B,gBAAgB"}
@@ -0,0 +1,8 @@
1
+ import { createInfrastructureLogger, createLogger } from "@module-federation/sdk";
2
+
3
+ //#region src/logger.ts
4
+ const logger = (typeof createInfrastructureLogger === "function" ? createInfrastructureLogger : createLogger)("[ nextjs-mf ]");
5
+
6
+ //#endregion
7
+ export { logger as default };
8
+ //# sourceMappingURL=logger.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.mjs","names":[],"sources":["../../src/logger.ts"],"sourcesContent":["import {\n createInfrastructureLogger,\n createLogger,\n} from '@module-federation/sdk';\n\nconst createBundlerLogger: typeof createLogger =\n typeof createInfrastructureLogger === 'function'\n ? (createInfrastructureLogger as unknown as typeof createLogger)\n : createLogger;\n\nconst logger = createBundlerLogger('[ nextjs-mf ]');\n\nexport default logger;\n"],"mappings":";;;AAUA,MAAM,UAJJ,OAAO,+BAA+B,aACjC,6BACD,cAE6B,gBAAgB"}