@module-federation/nextjs-mf 0.0.0-chore-bump-node-22-20260710161714
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/LICENSE +21 -0
- package/README.md +5 -0
- 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 +92 -0
- package/dist/client/UrlNode.js.map +1 -0
- 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 -0
- 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 -0
- package/dist/src/index.js +14 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/index.mjs +8 -0
- package/dist/src/index.mjs.map +1 -0
- package/dist/src/internal.js +152 -0
- package/dist/src/internal.js.map +1 -0
- 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 +27 -0
- package/dist/src/loaders/fixImageLoader.js +104 -0
- package/dist/src/loaders/fixImageLoader.js.map +1 -0
- 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 +16 -0
- package/dist/src/loaders/fixUrlLoader.js +22 -0
- package/dist/src/loaders/fixUrlLoader.js.map +1 -0
- package/dist/src/loaders/fixUrlLoader.mjs +19 -0
- package/dist/src/loaders/fixUrlLoader.mjs.map +1 -0
- package/dist/src/loaders/helpers.js +82 -0
- package/dist/src/loaders/helpers.js.map +1 -0
- 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 +29 -0
- package/dist/src/loaders/nextPageMapLoader.js +148 -0
- package/dist/src/loaders/nextPageMapLoader.js.map +1 -0
- package/dist/src/loaders/nextPageMapLoader.mjs +143 -0
- package/dist/src/loaders/nextPageMapLoader.mjs.map +1 -0
- package/dist/src/logger.js +9 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/logger.mjs +8 -0
- package/dist/src/logger.mjs.map +1 -0
- package/dist/src/plugins/CopyFederationPlugin.js +67 -0
- package/dist/src/plugins/CopyFederationPlugin.js.map +1 -0
- 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 +41 -0
- package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.js.map +1 -0
- 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 +117 -0
- package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.js.map +1 -0
- 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 +31 -0
- package/dist/src/plugins/NextFederationPlugin/index.js +156 -0
- package/dist/src/plugins/NextFederationPlugin/index.js.map +1 -0
- 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 +18 -0
- package/dist/src/plugins/NextFederationPlugin/next-fragments.js +65 -0
- package/dist/src/plugins/NextFederationPlugin/next-fragments.js.map +1 -0
- 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 +20 -0
- package/dist/src/plugins/NextFederationPlugin/set-options.js.map +1 -0
- 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 +37 -0
- package/dist/src/plugins/NextFederationPlugin/validate-options.js.map +1 -0
- 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 +26 -0
- package/dist/src/plugins/container/InvertedContainerPlugin.js.map +1 -0
- 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 +57 -0
- package/dist/src/plugins/container/InvertedContainerRuntimeModule.js.map +1 -0
- 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 -0
- package/dist/src/plugins/container/runtimePlugin.js +168 -0
- package/dist/src/plugins/container/runtimePlugin.js.map +1 -0
- package/dist/src/plugins/container/runtimePlugin.mjs +167 -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 +29 -0
- package/dist/utils/flushedChunks.js +37 -0
- package/dist/utils/flushedChunks.js.map +1 -0
- 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 +14 -0
- package/dist/utils/index.js +31 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +22 -0
- package/dist/utils/index.mjs.map +1 -0
- package/package.json +106 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","names":[],"sources":["../../../src/loaders/helpers.ts"],"sourcesContent":["import type {\n RuleSetRule,\n RuleSetCondition,\n RuleSetConditionAbsolute,\n RuleSetUseItem,\n} from 'webpack';\n\nexport function injectRuleLoader(rule: any, loader: RuleSetUseItem = {}) {\n if (rule !== '...') {\n const _rule = rule as {\n loader?: string;\n use?: (RuleSetUseItem | string)[];\n options?: any;\n };\n if (_rule.loader) {\n _rule.use = [loader, { loader: _rule.loader, options: _rule.options }];\n delete _rule.loader;\n delete _rule.options;\n } else if (_rule.use) {\n _rule.use = [loader, ...(_rule.use as any[])];\n }\n }\n}\n\n/**\n * This function checks if the current module rule has a loader with the provided name.\n *\n * @param {RuleSetRule} rule - The current module rule.\n * @param {string} loaderName - The name of the loader to check.\n * @returns {boolean} Returns true if the current module rule has a loader with the provided name, otherwise false.\n */\nexport function hasLoader(rule: RuleSetRule, loaderName: string) {\n //@ts-ignore\n if (rule !== '...') {\n const _rule = rule as {\n loader?: string;\n use?: (RuleSetUseItem | string)[];\n options?: any;\n };\n if (_rule.loader === loaderName) {\n return true;\n } else if (_rule.use && Array.isArray(_rule.use)) {\n for (let i = 0; i < _rule.use.length; i++) {\n const loader = _rule.use[i];\n if (\n typeof loader !== 'string' &&\n typeof loader !== 'function' &&\n loader.loader &&\n (loader.loader === loaderName ||\n loader.loader.includes(`/${loaderName}/`))\n ) {\n return true;\n } else if (typeof loader === 'string') {\n if (loader === loaderName || loader.includes(`/${loaderName}/`)) {\n return true;\n }\n }\n }\n }\n }\n return false;\n}\n\ninterface Resource {\n path: string;\n layer?: string;\n issuerLayer?: string;\n}\n\nfunction matchesCondition(\n condition:\n | RuleSetCondition\n | RuleSetConditionAbsolute\n | RuleSetRule\n | undefined,\n resource: Resource,\n currentPath: string,\n): boolean {\n if (condition instanceof RegExp) {\n return condition.test(resource.path);\n } else if (typeof condition === 'string') {\n return resource.path.includes(condition);\n } else if (typeof condition === 'function') {\n return condition(resource.path);\n } else if (typeof condition === 'object') {\n if ('test' in condition && condition.test) {\n const tests = Array.isArray(condition.test)\n ? condition.test\n : [condition.test];\n if (\n !tests.some((test: RuleSetCondition) =>\n matchesCondition(test, resource, currentPath),\n )\n ) {\n return false;\n }\n }\n if ('include' in condition && condition.include) {\n const includes = Array.isArray(condition.include)\n ? condition.include\n : [condition.include];\n if (\n !includes.some((include: RuleSetCondition) =>\n matchesCondition(include, resource, currentPath),\n )\n ) {\n return false;\n }\n }\n if ('exclude' in condition && condition.exclude) {\n const excludes = Array.isArray(condition.exclude)\n ? condition.exclude\n : [condition.exclude];\n if (\n excludes.some((exclude: RuleSetCondition) =>\n matchesCondition(exclude, resource, currentPath),\n )\n ) {\n return false;\n }\n }\n if ('and' in condition && condition.and) {\n return condition.and.every((cond: RuleSetCondition) =>\n matchesCondition(cond, resource, currentPath),\n );\n }\n if ('or' in condition && condition.or) {\n return condition.or.some((cond: RuleSetCondition) =>\n matchesCondition(cond, resource, currentPath),\n );\n }\n if ('not' in condition && condition.not) {\n return !matchesCondition(condition.not, resource, currentPath);\n }\n if ('layer' in condition && condition.layer) {\n if (\n !resource.layer ||\n !matchesCondition(\n condition.layer,\n { path: resource.layer },\n currentPath,\n )\n ) {\n return false;\n }\n }\n if ('issuerLayer' in condition && condition.issuerLayer) {\n if (\n !resource.issuerLayer ||\n !matchesCondition(\n condition.issuerLayer,\n { path: resource.issuerLayer },\n currentPath,\n )\n ) {\n return false;\n }\n }\n }\n return true;\n}\n\nexport function findLoaderForResource(\n rules: RuleSetRule[],\n resource: Resource,\n path: string[] = [],\n): RuleSetRule | null {\n let lastMatchedRule: RuleSetRule | null = null;\n for (let i = 0; i < rules.length; i++) {\n const rule = rules[i];\n const currentPath = [...path, `rules[${i}]`];\n if (rule.oneOf) {\n for (let j = 0; j < rule.oneOf.length; j++) {\n const subRule = rule.oneOf[j];\n const subPath = [...currentPath, `oneOf[${j}]`];\n\n if (\n subRule &&\n matchesCondition(subRule, resource, subPath.join('->'))\n ) {\n return subRule;\n }\n }\n } else if (\n rule &&\n matchesCondition(rule, resource, currentPath.join(' -> '))\n ) {\n lastMatchedRule = rule;\n }\n }\n return lastMatchedRule;\n}\n"],"mappings":";;AAOA,SAAgB,iBAAiB,MAAW,SAAyB,EAAE,EAAE;AACvE,KAAI,SAAS,OAAO;EAClB,MAAM,QAAQ;AAKd,MAAI,MAAM,QAAQ;AAChB,SAAM,MAAM,CAAC,QAAQ;IAAE,QAAQ,MAAM;IAAQ,SAAS,MAAM;IAAS,CAAC;AACtE,UAAO,MAAM;AACb,UAAO,MAAM;aACJ,MAAM,IACf,OAAM,MAAM,CAAC,QAAQ,GAAI,MAAM,IAAc;;;;;;;;;;AAYnD,SAAgB,UAAU,MAAmB,YAAoB;AAE/D,KAAI,SAAS,OAAO;EAClB,MAAM,QAAQ;AAKd,MAAI,MAAM,WAAW,WACnB,QAAO;WACE,MAAM,OAAO,MAAM,QAAQ,MAAM,IAAI,CAC9C,MAAK,IAAI,IAAI,GAAG,IAAI,MAAM,IAAI,QAAQ,KAAK;GACzC,MAAM,SAAS,MAAM,IAAI;AACzB,OACE,OAAO,WAAW,YAClB,OAAO,WAAW,cAClB,OAAO,WACN,OAAO,WAAW,cACjB,OAAO,OAAO,SAAS,IAAI,WAAW,GAAG,EAE3C,QAAO;YACE,OAAO,WAAW,UAC3B;QAAI,WAAW,cAAc,OAAO,SAAS,IAAI,WAAW,GAAG,CAC7D,QAAO;;;;AAMjB,QAAO;;AAST,SAAS,iBACP,WAKA,UACA,aACS;AACT,KAAI,qBAAqB,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AO;;AAGT,SAAgB,sBACd,OACA,UACA,OAAiB,EAAE,EACC;CACpB,IAAI,kBAAsC;AAC1C,MAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;EACrC,MAAM,OAAO,MAAM;EACnB,MAAM,cAAc,CAAC,GAAG,MAAM,SAAS,EAAE,GAAG;AAC5C,MAAI,KAAK,MACP,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,MAAM,QAAQ,KAAK;GAC1C,MAAM,UAAU,KAAK,MAAM;GAC3B,MAAM,UAAU,CAAC,GAAG,aAAa,SAAS,EAAE,GAAG;AAE/C,OACE,WACA,iBAAiB,SAAS,UAAU,QAAQ,KAAK,KAAK,CAAC,CAEvD,QAAO;;WAIX,QACA,iBAAiB,MAAM,UAAU,YAAY,KAAK,OAAO,CAAC,CAE1D,mBAAkB;;AAGtB,QAAO"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
//#region src/loaders/helpers.ts
|
|
2
|
+
function injectRuleLoader(rule, loader = {}) {
|
|
3
|
+
if (rule !== "...") {
|
|
4
|
+
const _rule = rule;
|
|
5
|
+
if (_rule.loader) {
|
|
6
|
+
_rule.use = [loader, {
|
|
7
|
+
loader: _rule.loader,
|
|
8
|
+
options: _rule.options
|
|
9
|
+
}];
|
|
10
|
+
delete _rule.loader;
|
|
11
|
+
delete _rule.options;
|
|
12
|
+
} else if (_rule.use) _rule.use = [loader, ..._rule.use];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* This function checks if the current module rule has a loader with the provided name.
|
|
17
|
+
*
|
|
18
|
+
* @param {RuleSetRule} rule - The current module rule.
|
|
19
|
+
* @param {string} loaderName - The name of the loader to check.
|
|
20
|
+
* @returns {boolean} Returns true if the current module rule has a loader with the provided name, otherwise false.
|
|
21
|
+
*/
|
|
22
|
+
function hasLoader(rule, loaderName) {
|
|
23
|
+
if (rule !== "...") {
|
|
24
|
+
const _rule = rule;
|
|
25
|
+
if (_rule.loader === loaderName) return true;
|
|
26
|
+
else if (_rule.use && Array.isArray(_rule.use)) for (let i = 0; i < _rule.use.length; i++) {
|
|
27
|
+
const loader = _rule.use[i];
|
|
28
|
+
if (typeof loader !== "string" && typeof loader !== "function" && loader.loader && (loader.loader === loaderName || loader.loader.includes(`/${loaderName}/`))) return true;
|
|
29
|
+
else if (typeof loader === "string") {
|
|
30
|
+
if (loader === loaderName || loader.includes(`/${loaderName}/`)) return true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
function matchesCondition(condition, resource, currentPath) {
|
|
37
|
+
if (condition instanceof RegExp) return condition.test(resource.path);
|
|
38
|
+
else if (typeof condition === "string") return resource.path.includes(condition);
|
|
39
|
+
else if (typeof condition === "function") return condition(resource.path);
|
|
40
|
+
else if (typeof condition === "object") {
|
|
41
|
+
if ("test" in condition && condition.test) {
|
|
42
|
+
if (!(Array.isArray(condition.test) ? condition.test : [condition.test]).some((test) => matchesCondition(test, resource, currentPath))) return false;
|
|
43
|
+
}
|
|
44
|
+
if ("include" in condition && condition.include) {
|
|
45
|
+
if (!(Array.isArray(condition.include) ? condition.include : [condition.include]).some((include) => matchesCondition(include, resource, currentPath))) return false;
|
|
46
|
+
}
|
|
47
|
+
if ("exclude" in condition && condition.exclude) {
|
|
48
|
+
if ((Array.isArray(condition.exclude) ? condition.exclude : [condition.exclude]).some((exclude) => matchesCondition(exclude, resource, currentPath))) return false;
|
|
49
|
+
}
|
|
50
|
+
if ("and" in condition && condition.and) return condition.and.every((cond) => matchesCondition(cond, resource, currentPath));
|
|
51
|
+
if ("or" in condition && condition.or) return condition.or.some((cond) => matchesCondition(cond, resource, currentPath));
|
|
52
|
+
if ("not" in condition && condition.not) return !matchesCondition(condition.not, resource, currentPath);
|
|
53
|
+
if ("layer" in condition && condition.layer) {
|
|
54
|
+
if (!resource.layer || !matchesCondition(condition.layer, { path: resource.layer }, currentPath)) return false;
|
|
55
|
+
}
|
|
56
|
+
if ("issuerLayer" in condition && condition.issuerLayer) {
|
|
57
|
+
if (!resource.issuerLayer || !matchesCondition(condition.issuerLayer, { path: resource.issuerLayer }, currentPath)) return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
function findLoaderForResource(rules, resource, path = []) {
|
|
63
|
+
let lastMatchedRule = null;
|
|
64
|
+
for (let i = 0; i < rules.length; i++) {
|
|
65
|
+
const rule = rules[i];
|
|
66
|
+
const currentPath = [...path, `rules[${i}]`];
|
|
67
|
+
if (rule.oneOf) for (let j = 0; j < rule.oneOf.length; j++) {
|
|
68
|
+
const subRule = rule.oneOf[j];
|
|
69
|
+
const subPath = [...currentPath, `oneOf[${j}]`];
|
|
70
|
+
if (subRule && matchesCondition(subRule, resource, subPath.join("->"))) return subRule;
|
|
71
|
+
}
|
|
72
|
+
else if (rule && matchesCondition(rule, resource, currentPath.join(" -> "))) lastMatchedRule = rule;
|
|
73
|
+
}
|
|
74
|
+
return lastMatchedRule;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
export { findLoaderForResource, hasLoader, injectRuleLoader };
|
|
79
|
+
//# sourceMappingURL=helpers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.mjs","names":[],"sources":["../../../src/loaders/helpers.ts"],"sourcesContent":["import type {\n RuleSetRule,\n RuleSetCondition,\n RuleSetConditionAbsolute,\n RuleSetUseItem,\n} from 'webpack';\n\nexport function injectRuleLoader(rule: any, loader: RuleSetUseItem = {}) {\n if (rule !== '...') {\n const _rule = rule as {\n loader?: string;\n use?: (RuleSetUseItem | string)[];\n options?: any;\n };\n if (_rule.loader) {\n _rule.use = [loader, { loader: _rule.loader, options: _rule.options }];\n delete _rule.loader;\n delete _rule.options;\n } else if (_rule.use) {\n _rule.use = [loader, ...(_rule.use as any[])];\n }\n }\n}\n\n/**\n * This function checks if the current module rule has a loader with the provided name.\n *\n * @param {RuleSetRule} rule - The current module rule.\n * @param {string} loaderName - The name of the loader to check.\n * @returns {boolean} Returns true if the current module rule has a loader with the provided name, otherwise false.\n */\nexport function hasLoader(rule: RuleSetRule, loaderName: string) {\n //@ts-ignore\n if (rule !== '...') {\n const _rule = rule as {\n loader?: string;\n use?: (RuleSetUseItem | string)[];\n options?: any;\n };\n if (_rule.loader === loaderName) {\n return true;\n } else if (_rule.use && Array.isArray(_rule.use)) {\n for (let i = 0; i < _rule.use.length; i++) {\n const loader = _rule.use[i];\n if (\n typeof loader !== 'string' &&\n typeof loader !== 'function' &&\n loader.loader &&\n (loader.loader === loaderName ||\n loader.loader.includes(`/${loaderName}/`))\n ) {\n return true;\n } else if (typeof loader === 'string') {\n if (loader === loaderName || loader.includes(`/${loaderName}/`)) {\n return true;\n }\n }\n }\n }\n }\n return false;\n}\n\ninterface Resource {\n path: string;\n layer?: string;\n issuerLayer?: string;\n}\n\nfunction matchesCondition(\n condition:\n | RuleSetCondition\n | RuleSetConditionAbsolute\n | RuleSetRule\n | undefined,\n resource: Resource,\n currentPath: string,\n): boolean {\n if (condition instanceof RegExp) {\n return condition.test(resource.path);\n } else if (typeof condition === 'string') {\n return resource.path.includes(condition);\n } else if (typeof condition === 'function') {\n return condition(resource.path);\n } else if (typeof condition === 'object') {\n if ('test' in condition && condition.test) {\n const tests = Array.isArray(condition.test)\n ? condition.test\n : [condition.test];\n if (\n !tests.some((test: RuleSetCondition) =>\n matchesCondition(test, resource, currentPath),\n )\n ) {\n return false;\n }\n }\n if ('include' in condition && condition.include) {\n const includes = Array.isArray(condition.include)\n ? condition.include\n : [condition.include];\n if (\n !includes.some((include: RuleSetCondition) =>\n matchesCondition(include, resource, currentPath),\n )\n ) {\n return false;\n }\n }\n if ('exclude' in condition && condition.exclude) {\n const excludes = Array.isArray(condition.exclude)\n ? condition.exclude\n : [condition.exclude];\n if (\n excludes.some((exclude: RuleSetCondition) =>\n matchesCondition(exclude, resource, currentPath),\n )\n ) {\n return false;\n }\n }\n if ('and' in condition && condition.and) {\n return condition.and.every((cond: RuleSetCondition) =>\n matchesCondition(cond, resource, currentPath),\n );\n }\n if ('or' in condition && condition.or) {\n return condition.or.some((cond: RuleSetCondition) =>\n matchesCondition(cond, resource, currentPath),\n );\n }\n if ('not' in condition && condition.not) {\n return !matchesCondition(condition.not, resource, currentPath);\n }\n if ('layer' in condition && condition.layer) {\n if (\n !resource.layer ||\n !matchesCondition(\n condition.layer,\n { path: resource.layer },\n currentPath,\n )\n ) {\n return false;\n }\n }\n if ('issuerLayer' in condition && condition.issuerLayer) {\n if (\n !resource.issuerLayer ||\n !matchesCondition(\n condition.issuerLayer,\n { path: resource.issuerLayer },\n currentPath,\n )\n ) {\n return false;\n }\n }\n }\n return true;\n}\n\nexport function findLoaderForResource(\n rules: RuleSetRule[],\n resource: Resource,\n path: string[] = [],\n): RuleSetRule | null {\n let lastMatchedRule: RuleSetRule | null = null;\n for (let i = 0; i < rules.length; i++) {\n const rule = rules[i];\n const currentPath = [...path, `rules[${i}]`];\n if (rule.oneOf) {\n for (let j = 0; j < rule.oneOf.length; j++) {\n const subRule = rule.oneOf[j];\n const subPath = [...currentPath, `oneOf[${j}]`];\n\n if (\n subRule &&\n matchesCondition(subRule, resource, subPath.join('->'))\n ) {\n return subRule;\n }\n }\n } else if (\n rule &&\n matchesCondition(rule, resource, currentPath.join(' -> '))\n ) {\n lastMatchedRule = rule;\n }\n }\n return lastMatchedRule;\n}\n"],"mappings":";AAOA,SAAgB,iBAAiB,MAAW,SAAyB,EAAE,EAAE;AACvE,KAAI,SAAS,OAAO;EAClB,MAAM,QAAQ;AAKd,MAAI,MAAM,QAAQ;AAChB,SAAM,MAAM,CAAC,QAAQ;IAAE,QAAQ,MAAM;IAAQ,SAAS,MAAM;IAAS,CAAC;AACtE,UAAO,MAAM;AACb,UAAO,MAAM;aACJ,MAAM,IACf,OAAM,MAAM,CAAC,QAAQ,GAAI,MAAM,IAAc;;;;;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extJS pages.
|
|
6
|
+
* This function is the main entry point for the loader.
|
|
7
|
+
* It gets the options passed to the loader and prepares the pages map.
|
|
8
|
+
* If the 'v2' option is passed, it prepares the pages map using the 'preparePageMapV2' function.
|
|
9
|
+
* Otherwise, it uses the 'preparePageMap' function.
|
|
10
|
+
* Finally, it calls the loader's callback function with the prepared pages map.
|
|
11
|
+
*
|
|
12
|
+
* @param {LoaderContext<Record<string, unknown>>} this - The loader context.
|
|
13
|
+
*/
|
|
14
|
+
declare function nextPageMapLoader(this: LoaderContext<Record<string, unknown>>): void;
|
|
15
|
+
/**
|
|
16
|
+
* Webpack config generator for `exposes` option.
|
|
17
|
+
* This function generates the webpack config for the 'exposes' option.
|
|
18
|
+
* It creates a map of pages to modules and returns an object with the pages map and the pages map v2.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} cwd - The current working directory.
|
|
21
|
+
* @returns {Record<string, string>} The webpack config for the 'exposes' option.
|
|
22
|
+
*/
|
|
23
|
+
declare function exposeNextjsPages(cwd: string): {
|
|
24
|
+
'./pages-map': string;
|
|
25
|
+
'./pages-map-v2': string;
|
|
26
|
+
};
|
|
27
|
+
//#endregion
|
|
28
|
+
export { nextPageMapLoader as default, exposeNextjsPages };
|
|
29
|
+
//# sourceMappingURL=nextPageMapLoader.d.mts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { LoaderContext } from "webpack";
|
|
2
|
+
|
|
3
|
+
//#region src/loaders/nextPageMapLoader.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Webpack loader which prepares MF map for NextJS pages.
|
|
6
|
+
* This function is the main entry point for the loader.
|
|
7
|
+
* It gets the options passed to the loader and prepares the pages map.
|
|
8
|
+
* If the 'v2' option is passed, it prepares the pages map using the 'preparePageMapV2' function.
|
|
9
|
+
* Otherwise, it uses the 'preparePageMap' function.
|
|
10
|
+
* Finally, it calls the loader's callback function with the prepared pages map.
|
|
11
|
+
*
|
|
12
|
+
* @param {LoaderContext<Record<string, unknown>>} this - The loader context.
|
|
13
|
+
*/
|
|
14
|
+
declare function nextPageMapLoader(this: LoaderContext<Record<string, unknown>>): void;
|
|
15
|
+
/**
|
|
16
|
+
* Webpack config generator for `exposes` option.
|
|
17
|
+
* This function generates the webpack config for the 'exposes' option.
|
|
18
|
+
* It creates a map of pages to modules and returns an object with the pages map and the pages map v2.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} cwd - The current working directory.
|
|
21
|
+
* @returns {Record<string, string>} The webpack config for the 'exposes' option.
|
|
22
|
+
*/
|
|
23
|
+
declare function exposeNextjsPages(cwd: string): {
|
|
24
|
+
'./pages-map': string;
|
|
25
|
+
'./pages-map-v2': string;
|
|
26
|
+
};
|
|
27
|
+
//#endregion
|
|
28
|
+
export { nextPageMapLoader as default, exposeNextjsPages };
|
|
29
|
+
//# sourceMappingURL=nextPageMapLoader.d.ts.map
|
|
@@ -0,0 +1,148 @@
|
|
|
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
|
|
10
|
+
/**
|
|
11
|
+
* Webpack loader which prepares MF map for NextJS pages.
|
|
12
|
+
* This function is the main entry point for the loader.
|
|
13
|
+
* It gets the options passed to the loader and prepares the pages map.
|
|
14
|
+
* If the 'v2' option is passed, it prepares the pages map using the 'preparePageMapV2' function.
|
|
15
|
+
* Otherwise, it uses the 'preparePageMap' function.
|
|
16
|
+
* Finally, it calls the loader's callback function with the prepared pages map.
|
|
17
|
+
*
|
|
18
|
+
* @param {LoaderContext<Record<string, unknown>>} this - The loader context.
|
|
19
|
+
*/
|
|
20
|
+
function nextPageMapLoader() {
|
|
21
|
+
const 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)} };`);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
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
|
+
*/
|
|
36
|
+
function exposeNextjsPages(cwd) {
|
|
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
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
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
|
+
*/
|
|
57
|
+
function getNextPagesRoot(appRoot) {
|
|
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];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
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
|
+
*/
|
|
73
|
+
function getNextPages(rootDir) {
|
|
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;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
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
|
+
*/
|
|
101
|
+
function sanitizePagePath(item) {
|
|
102
|
+
return item.replace(/^src\/pages\//i, "pages/").replace(/\.(ts|tsx|js|jsx)$/, "");
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
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
|
+
*/
|
|
112
|
+
function preparePageMap(pages) {
|
|
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;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
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
|
+
*/
|
|
133
|
+
function preparePageMapV2(pages) {
|
|
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;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
//#endregion
|
|
146
|
+
exports.default = nextPageMapLoader;
|
|
147
|
+
exports.exposeNextjsPages = exposeNextjsPages;
|
|
148
|
+
//# sourceMappingURL=nextPageMapLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,Q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
|
+
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
|
+
exports.default = logger;
|
|
9
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
2
|
+
const require_logger = require('../logger.js');
|
|
3
|
+
let path = require("path");
|
|
4
|
+
path = require_runtime.__toESM(path);
|
|
5
|
+
let fs = require("fs");
|
|
6
|
+
let _module_federation_sdk = require("@module-federation/sdk");
|
|
7
|
+
|
|
8
|
+
//#region src/plugins/CopyFederationPlugin.ts
|
|
9
|
+
/**
|
|
10
|
+
* Plugin to copy build output files.
|
|
11
|
+
* @class
|
|
12
|
+
*/
|
|
13
|
+
var CopyBuildOutputPlugin = class {
|
|
14
|
+
/**
|
|
15
|
+
* @param {boolean} isServer - Indicates if the current environment is server.
|
|
16
|
+
* @constructor
|
|
17
|
+
*/
|
|
18
|
+
constructor(isServer) {
|
|
19
|
+
this.isServer = isServer;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Applies the plugin to the compiler.
|
|
23
|
+
* @param {Compiler} compiler - The webpack compiler object.
|
|
24
|
+
* @method
|
|
25
|
+
*/
|
|
26
|
+
apply(compiler) {
|
|
27
|
+
(0, _module_federation_sdk.bindLoggerToCompiler)(require_logger.default, compiler, "CopyBuildOutputPlugin");
|
|
28
|
+
/**
|
|
29
|
+
* Copies files from source to destination.
|
|
30
|
+
* @param {string} source - The source directory.
|
|
31
|
+
* @param {string} destination - The destination directory.
|
|
32
|
+
* @async
|
|
33
|
+
* @function
|
|
34
|
+
*/
|
|
35
|
+
const copyFiles = async (source, destination) => {
|
|
36
|
+
const files = await fs.promises.readdir(source);
|
|
37
|
+
await Promise.all(files.map(async (file) => {
|
|
38
|
+
const sourcePath = path.default.join(source, file);
|
|
39
|
+
const destinationPath = path.default.join(destination, file);
|
|
40
|
+
if ((await fs.promises.lstat(sourcePath)).isDirectory()) {
|
|
41
|
+
await fs.promises.mkdir(destinationPath, { recursive: true });
|
|
42
|
+
await copyFiles(sourcePath, destinationPath);
|
|
43
|
+
} else await fs.promises.copyFile(sourcePath, destinationPath);
|
|
44
|
+
}));
|
|
45
|
+
};
|
|
46
|
+
compiler.hooks.afterEmit.tapPromise("CopyBuildOutputPlugin", async (compilation) => {
|
|
47
|
+
const { outputPath } = compiler;
|
|
48
|
+
const outputString = outputPath.split("server")[0];
|
|
49
|
+
const isProd = compiler.options.mode === "production";
|
|
50
|
+
if (!isProd && !this.isServer) return;
|
|
51
|
+
const serverLoc = path.default.join(outputString, this.isServer && isProd ? "/ssr" : "/static/ssr");
|
|
52
|
+
const servingLoc = path.default.join(outputPath, "ssr");
|
|
53
|
+
await fs.promises.mkdir(serverLoc, { recursive: true });
|
|
54
|
+
const sourcePath = this.isServer ? outputPath : servingLoc;
|
|
55
|
+
try {
|
|
56
|
+
await fs.promises.access(sourcePath);
|
|
57
|
+
await copyFiles(sourcePath, serverLoc);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
require_logger.default.error(`File at ${sourcePath} does not exist.`);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
exports.default = CopyBuildOutputPlugin;
|
|
67
|
+
//# sourceMappingURL=CopyFederationPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CopyFederationPlugin.js","names":["logger"],"sources":["../../../src/plugins/CopyFederationPlugin.ts"],"sourcesContent":["import { promises as fs } from 'fs';\nimport path from 'path';\nimport type { Compilation, Compiler, WebpackPluginInstance } from 'webpack';\nimport { bindLoggerToCompiler } from '@module-federation/sdk';\nimport logger from '../logger';\n\n/**\n * Plugin to copy build output files.\n * @class\n */\nclass CopyBuildOutputPlugin implements WebpackPluginInstance {\n private isServer: boolean;\n\n /**\n * @param {boolean} isServer - Indicates if the current environment is server.\n * @constructor\n */\n constructor(isServer: boolean) {\n this.isServer = isServer;\n }\n\n /**\n * Applies the plugin to the compiler.\n * @param {Compiler} compiler - The webpack compiler object.\n * @method\n */\n apply(compiler: Compiler): void {\n bindLoggerToCompiler(logger, compiler, 'CopyBuildOutputPlugin');\n /**\n * Copies files from source to destination.\n * @param {string} source - The source directory.\n * @param {string} destination - The destination directory.\n * @async\n * @function\n */\n const copyFiles = async (\n source: string,\n destination: string,\n ): Promise<void> => {\n const files = await fs.readdir(source);\n\n await Promise.all(\n files.map(async (file) => {\n const sourcePath = path.join(source, file);\n const destinationPath = path.join(destination, file);\n\n if ((await fs.lstat(sourcePath)).isDirectory()) {\n await fs.mkdir(destinationPath, { recursive: true });\n await copyFiles(sourcePath, destinationPath);\n } else {\n await fs.copyFile(sourcePath, destinationPath);\n }\n }),\n );\n };\n\n compiler.hooks.afterEmit.tapPromise(\n 'CopyBuildOutputPlugin',\n async (compilation: Compilation) => {\n const { outputPath } = compiler;\n const outputString = outputPath.split('server')[0];\n const isProd = compiler.options.mode === 'production';\n\n if (!isProd && !this.isServer) {\n return;\n }\n\n const serverLoc = path.join(\n outputString,\n this.isServer && isProd ? '/ssr' : '/static/ssr',\n );\n const servingLoc = path.join(outputPath, 'ssr');\n\n await fs.mkdir(serverLoc, { recursive: true });\n\n const sourcePath = this.isServer ? outputPath : servingLoc;\n\n try {\n await fs.access(sourcePath);\n // If the promise resolves, the file exists and you can proceed with copying.\n await copyFiles(sourcePath, serverLoc);\n } catch (error) {\n // If the promise rejects, the file does not exist.\n logger.error(`File at ${sourcePath} does not exist.`);\n }\n },\n );\n }\n}\n\nexport default CopyBuildOutputPlugin;\n"],"mappings":";;;;;;;;;;;;AAUA,IAAM,wBAAN,MAA6D;;;;;CAO3D,YAAY,UAAmB;AAC7B,OAAK,WAAW;;;;;;;CAQlB,MAAM,UAA0B;AAC9B,mDAAqBA,wBAAQ,UAAU,wBAAwB;;;;;;;;EAQ/D,MAAM,YAAY,OAChB,QACA,gBACkB;GAClB,MAAM,QAAQ,MAAM,YAAG,QAAQ,OAAO;AAEtC,SAAM,QAAQ,IACZ,MAAM,IAAI,OAAO,SAAS;IACxB,MAAM,aAAa,aAAK,KAAK,QAAQ,KAAK;IAC1C,MAAM,kBAAkB,aAAK,KAAK,aAAa,KAAK;AAEpD,SAAK,MAAM,YAAG,MAAM,WAAW,EAAE,aAAa,EAAE;AAC9C,WAAM,YAAG,MAAM,iBAAiB,EAAE,WAAW,MAAM,CAAC;AACpD,WAAM,UAAU,YAAY,gBAAgB;UAE5C,OAAM,YAAG,SAAS,YAAY,gBAAgB;KAEhD,CACH;;AAGH,WAAS,MAAM,UAAU,WACvB,yBACA,OAAO,gBAA6B;GAClC,MAAM,EAAE,eAAe;GACvB,MAAM,eAAe,WAAW,MAAM,SAAS,CAAC;GAChD,MAAM,SAAS,SAAS,QAAQ,SAAS;AAEzC,OAAI,CAAC,UAAU,CAAC,KAAK,SACnB;GAGF,MAAM,YAAY,aAAK,KACrB,cACA,KAAK,YAAY,SAAS,SAAS,cACpC;GACD,MAAM,aAAa,aAAK,KAAK,YAAY,MAAM;AAE/C,SAAM,YAAG,MAAM,WAAW,EAAE,WAAW,MAAM,CAAC;GAE9C,MAAM,aAAa,KAAK,WAAW,aAAa;AAEhD,OAAI;AACF,UAAM,YAAG,OAAO,WAAW;AAE3B,UAAM,UAAU,YAAY,UAAU;YAC/B,OAAO;AAEd,2BAAO,MAAM,WAAW,WAAW,kBAAkB;;IAG1D"}
|