@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.
- package/dist/LICENSE +21 -0
- package/dist/_virtual/_rolldown/runtime.js +29 -0
- package/dist/_virtual/_rolldown/runtime.mjs +8 -0
- package/dist/client/UrlNode.js +89 -147
- package/dist/client/UrlNode.js.map +1 -1
- package/dist/client/UrlNode.mjs +91 -0
- package/dist/client/UrlNode.mjs.map +1 -0
- package/dist/src/federation-noop.d.mts +1 -0
- package/dist/src/federation-noop.d.ts +1 -0
- package/dist/src/federation-noop.js +17 -0
- package/dist/src/federation-noop.js.map +1 -1
- package/dist/src/federation-noop.mjs +23 -0
- package/dist/src/federation-noop.mjs.map +1 -0
- package/dist/src/index.d.mts +2 -0
- package/dist/src/index.d.ts +2 -3
- package/dist/src/index.js +13 -11
- package/dist/src/index.js.map +1 -1
- package/dist/src/index.mjs +8 -0
- package/dist/src/index.mjs.map +1 -0
- package/dist/src/internal.js +140 -243
- package/dist/src/internal.js.map +1 -1
- package/dist/src/internal.mjs +152 -0
- package/dist/src/internal.mjs.map +1 -0
- package/dist/src/loaders/fixImageLoader.d.mts +27 -0
- package/dist/src/loaders/fixImageLoader.d.ts +8 -3
- package/dist/src/loaders/fixImageLoader.js +91 -103
- package/dist/src/loaders/fixImageLoader.js.map +1 -1
- package/dist/src/loaders/fixImageLoader.mjs +101 -0
- package/dist/src/loaders/fixImageLoader.mjs.map +1 -0
- package/dist/src/loaders/fixUrlLoader.d.mts +16 -0
- package/dist/src/loaders/fixUrlLoader.d.ts +5 -2
- package/dist/src/loaders/fixUrlLoader.js +17 -19
- package/dist/src/loaders/fixUrlLoader.js.map +1 -1
- package/dist/src/loaders/fixUrlLoader.mjs +19 -0
- package/dist/src/loaders/fixUrlLoader.mjs.map +1 -0
- package/dist/src/loaders/helpers.js +72 -124
- package/dist/src/loaders/helpers.js.map +1 -1
- package/dist/src/loaders/helpers.mjs +79 -0
- package/dist/src/loaders/helpers.mjs.map +1 -0
- package/dist/src/loaders/nextPageMapLoader.d.mts +29 -0
- package/dist/src/loaders/nextPageMapLoader.d.ts +10 -5
- package/dist/src/loaders/nextPageMapLoader.js +126 -144
- package/dist/src/loaders/nextPageMapLoader.js.map +1 -1
- package/dist/src/loaders/nextPageMapLoader.mjs +143 -0
- package/dist/src/loaders/nextPageMapLoader.mjs.map +1 -0
- package/dist/src/logger.js +7 -7
- package/dist/src/logger.js.map +1 -1
- package/dist/src/logger.mjs +8 -0
- package/dist/src/logger.mjs.map +1 -0
- package/dist/src/plugins/CopyFederationPlugin.js +64 -71
- package/dist/src/plugins/CopyFederationPlugin.js.map +1 -1
- package/dist/src/plugins/CopyFederationPlugin.mjs +65 -0
- package/dist/src/plugins/CopyFederationPlugin.mjs.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.js +36 -53
- package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.js.map +1 -1
- package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.mjs +40 -0
- package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.mjs.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.js +103 -121
- package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.js.map +1 -1
- package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.mjs +111 -0
- package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.mjs.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/index.d.mts +31 -0
- package/dist/src/plugins/NextFederationPlugin/index.d.ts +27 -23
- package/dist/src/plugins/NextFederationPlugin/index.js +151 -181
- package/dist/src/plugins/NextFederationPlugin/index.js.map +1 -1
- package/dist/src/plugins/NextFederationPlugin/index.mjs +153 -0
- package/dist/src/plugins/NextFederationPlugin/index.mjs.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/next-fragments.d.mts +18 -0
- package/dist/src/plugins/NextFederationPlugin/next-fragments.d.ts +16 -18
- package/dist/src/plugins/NextFederationPlugin/next-fragments.js +58 -93
- package/dist/src/plugins/NextFederationPlugin/next-fragments.js.map +1 -1
- package/dist/src/plugins/NextFederationPlugin/next-fragments.mjs +63 -0
- package/dist/src/plugins/NextFederationPlugin/next-fragments.mjs.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/set-options.js +17 -19
- package/dist/src/plugins/NextFederationPlugin/set-options.js.map +1 -1
- package/dist/src/plugins/NextFederationPlugin/set-options.mjs +19 -0
- package/dist/src/plugins/NextFederationPlugin/set-options.mjs.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/validate-options.js +30 -38
- package/dist/src/plugins/NextFederationPlugin/validate-options.js.map +1 -1
- package/dist/src/plugins/NextFederationPlugin/validate-options.mjs +35 -0
- package/dist/src/plugins/NextFederationPlugin/validate-options.mjs.map +1 -0
- package/dist/src/plugins/container/InvertedContainerPlugin.js +23 -25
- package/dist/src/plugins/container/InvertedContainerPlugin.js.map +1 -1
- package/dist/src/plugins/container/InvertedContainerPlugin.mjs +27 -0
- package/dist/src/plugins/container/InvertedContainerPlugin.mjs.map +1 -0
- package/dist/src/plugins/container/InvertedContainerRuntimeModule.js +55 -67
- package/dist/src/plugins/container/InvertedContainerRuntimeModule.js.map +1 -1
- package/dist/src/plugins/container/InvertedContainerRuntimeModule.mjs +57 -0
- package/dist/src/plugins/container/InvertedContainerRuntimeModule.mjs.map +1 -0
- package/dist/src/plugins/container/runtimePlugin.d.mts +7 -0
- package/dist/src/plugins/container/runtimePlugin.d.ts +6 -2
- package/dist/src/plugins/container/runtimePlugin.js +167 -0
- package/dist/src/plugins/container/runtimePlugin.js.map +1 -1
- package/dist/src/plugins/container/runtimePlugin.mjs +166 -0
- package/dist/src/plugins/container/runtimePlugin.mjs.map +1 -0
- package/dist/utils/flushedChunks.d.mts +29 -0
- package/dist/utils/flushedChunks.d.ts +12 -5
- package/dist/utils/flushedChunks.js +32 -72
- package/dist/utils/flushedChunks.js.map +1 -1
- package/dist/utils/flushedChunks.mjs +35 -0
- package/dist/utils/flushedChunks.mjs.map +1 -0
- package/dist/utils/index.d.mts +14 -0
- package/dist/utils/index.d.ts +8 -14
- package/dist/utils/index.js +27 -62
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +22 -0
- package/dist/utils/index.mjs.map +1 -0
- package/package.json +34 -10
- package/dist/client/UrlNode.d.ts +0 -17
- package/dist/node.d.ts +0 -1
- package/dist/node.js +0 -18
- package/dist/node.js.map +0 -1
- package/dist/package.json +0 -80
- package/dist/src/federation-noop.cjs +0 -15
- package/dist/src/internal.d.ts +0 -50
- package/dist/src/loaders/helpers.d.ts +0 -17
- package/dist/src/logger.d.ts +0 -2
- package/dist/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.d.ts +0 -5
- package/dist/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.js +0 -19
- package/dist/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.js.map +0 -1
- package/dist/src/plugins/CopyFederationPlugin.d.ts +0 -20
- package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.d.ts +0 -23
- package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.d.ts +0 -36
- package/dist/src/plugins/NextFederationPlugin/regex-equal.d.ts +0 -14
- package/dist/src/plugins/NextFederationPlugin/regex-equal.js +0 -25
- package/dist/src/plugins/NextFederationPlugin/regex-equal.js.map +0 -1
- package/dist/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.d.ts +0 -8
- package/dist/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js +0 -34
- package/dist/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js.map +0 -1
- package/dist/src/plugins/NextFederationPlugin/set-options.d.ts +0 -16
- package/dist/src/plugins/NextFederationPlugin/validate-options.d.ts +0 -25
- package/dist/src/plugins/container/InvertedContainerPlugin.d.ts +0 -5
- package/dist/src/plugins/container/InvertedContainerRuntimeModule.d.ts +0 -11
- package/dist/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.d.ts +0 -39
- package/dist/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.js +0 -78
- package/dist/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.js.map +0 -1
- package/dist/src/plugins/container/runtimePlugin.cjs +0 -219
- package/dist/src/plugins/container/types.d.ts +0 -2
- package/dist/src/plugins/container/types.js +0 -3
- package/dist/src/plugins/container/types.js.map +0 -1
- package/dist/src/types.d.ts +0 -28
- package/dist/src/types.js +0 -3
- package/dist/src/types.js.map +0 -1
|
@@ -1,166 +1,148 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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","
|
|
1
|
+
{"version":3,"file":"nextPageMapLoader.js","names":["fg","UrlNode"],"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,WAAG,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,WAAWA,kBAAG,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,IAAIC,yBAAS;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,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"}
|
package/dist/src/logger.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
package/dist/src/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","
|
|
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"}
|