@module-federation/metro 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.
Files changed (126) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/babel-plugin/index.js +115 -0
  4. package/babel-plugin/patch-initialize-core.js +61 -0
  5. package/babel-plugin/patch-require.js +174 -0
  6. package/bootstrap/index.d.ts +1 -0
  7. package/bootstrap/index.js +1 -0
  8. package/dist/babel/transformer.js +15 -0
  9. package/dist/commands/bundle-host/index.d.ts +13 -0
  10. package/dist/commands/bundle-host/index.js +100 -0
  11. package/dist/commands/bundle-host/index.mjs +47 -0
  12. package/dist/commands/bundle-host/options.d.ts +5 -0
  13. package/dist/commands/bundle-host/options.js +43 -0
  14. package/dist/commands/bundle-host/options.mjs +6 -0
  15. package/dist/commands/bundle-host/types.d.ts +22 -0
  16. package/dist/commands/bundle-host/types.js +18 -0
  17. package/dist/commands/bundle-host/types.mjs +1 -0
  18. package/dist/commands/bundle-remote/index.d.ts +12 -0
  19. package/dist/commands/bundle-remote/index.js +241 -0
  20. package/dist/commands/bundle-remote/index.mjs +190 -0
  21. package/dist/commands/bundle-remote/options.d.ts +32 -0
  22. package/dist/commands/bundle-remote/options.js +113 -0
  23. package/dist/commands/bundle-remote/options.mjs +66 -0
  24. package/dist/commands/bundle-remote/types.d.ts +16 -0
  25. package/dist/commands/bundle-remote/types.js +18 -0
  26. package/dist/commands/bundle-remote/types.mjs +1 -0
  27. package/dist/commands/index.d.ts +48 -0
  28. package/dist/commands/index.js +76 -0
  29. package/dist/commands/index.mjs +13 -0
  30. package/dist/commands/types.d.ts +14 -0
  31. package/dist/commands/types.js +18 -0
  32. package/dist/commands/types.mjs +1 -0
  33. package/dist/commands/utils/create-module-path-remapper.d.ts +7 -0
  34. package/dist/commands/utils/create-module-path-remapper.js +68 -0
  35. package/dist/commands/utils/create-module-path-remapper.mjs +31 -0
  36. package/dist/commands/utils/create-resolver.d.ts +20 -0
  37. package/dist/commands/utils/create-resolver.js +61 -0
  38. package/dist/commands/utils/create-resolver.mjs +24 -0
  39. package/dist/commands/utils/get-community-plugin.d.ts +28 -0
  40. package/dist/commands/utils/get-community-plugin.js +53 -0
  41. package/dist/commands/utils/get-community-plugin.mjs +17 -0
  42. package/dist/commands/utils/load-metro-config.d.ts +3 -0
  43. package/dist/commands/utils/load-metro-config.js +85 -0
  44. package/dist/commands/utils/load-metro-config.mjs +41 -0
  45. package/dist/commands/utils/path-utils.d.ts +2 -0
  46. package/dist/commands/utils/path-utils.js +51 -0
  47. package/dist/commands/utils/path-utils.mjs +11 -0
  48. package/dist/commands/utils/save-bundle-and-map.d.ts +5 -0
  49. package/dist/commands/utils/save-bundle-and-map.js +80 -0
  50. package/dist/commands/utils/save-bundle-and-map.mjs +33 -0
  51. package/dist/index.d.ts +2 -0
  52. package/dist/index.js +44 -0
  53. package/dist/index.mjs +3 -0
  54. package/dist/logger.d.ts +2 -0
  55. package/dist/logger.js +43 -0
  56. package/dist/logger.mjs +6 -0
  57. package/dist/modules/HMRClient.ts +31 -0
  58. package/dist/modules/HMRClientShim.ts +1 -0
  59. package/dist/modules/asyncRequire.ts +156 -0
  60. package/dist/modules/asyncStartup.tsx +43 -0
  61. package/dist/modules/getDevServer.ts +15 -0
  62. package/dist/modules/metroCorePlugin.ts +87 -0
  63. package/dist/plugin/babel-transformer.d.ts +11 -0
  64. package/dist/plugin/babel-transformer.js +72 -0
  65. package/dist/plugin/babel-transformer.mjs +25 -0
  66. package/dist/plugin/constants.d.ts +10 -0
  67. package/dist/plugin/constants.js +76 -0
  68. package/dist/plugin/constants.mjs +12 -0
  69. package/dist/plugin/generators.d.ts +13 -0
  70. package/dist/plugin/generators.js +164 -0
  71. package/dist/plugin/generators.mjs +102 -0
  72. package/dist/plugin/helpers.d.ts +8 -0
  73. package/dist/plugin/helpers.js +127 -0
  74. package/dist/plugin/helpers.mjs +58 -0
  75. package/dist/plugin/index.d.ts +11 -0
  76. package/dist/plugin/index.js +219 -0
  77. package/dist/plugin/index.mjs +172 -0
  78. package/dist/plugin/manifest-middleware.d.ts +12 -0
  79. package/dist/plugin/manifest-middleware.js +217 -0
  80. package/dist/plugin/manifest-middleware.mjs +170 -0
  81. package/dist/plugin/manifest.d.ts +16 -0
  82. package/dist/plugin/manifest.js +246 -0
  83. package/dist/plugin/manifest.mjs +185 -0
  84. package/dist/plugin/normalize-extra-options.d.ts +8 -0
  85. package/dist/plugin/normalize-extra-options.js +50 -0
  86. package/dist/plugin/normalize-extra-options.mjs +13 -0
  87. package/dist/plugin/normalize-options.d.ts +7 -0
  88. package/dist/plugin/normalize-options.js +139 -0
  89. package/dist/plugin/normalize-options.mjs +92 -0
  90. package/dist/plugin/resolver.d.ts +26 -0
  91. package/dist/plugin/resolver.js +203 -0
  92. package/dist/plugin/resolver.mjs +159 -0
  93. package/dist/plugin/rewrite-request.d.ts +14 -0
  94. package/dist/plugin/rewrite-request.js +89 -0
  95. package/dist/plugin/rewrite-request.mjs +42 -0
  96. package/dist/plugin/serializer.d.ts +6 -0
  97. package/dist/plugin/serializer.js +191 -0
  98. package/dist/plugin/serializer.mjs +144 -0
  99. package/dist/plugin/validate-options.d.ts +2 -0
  100. package/dist/plugin/validate-options.js +165 -0
  101. package/dist/plugin/validate-options.mjs +117 -0
  102. package/dist/runtime/host-entry.js +3 -0
  103. package/dist/runtime/init-host.js +31 -0
  104. package/dist/runtime/remote-entry.js +57 -0
  105. package/dist/runtime/remote-hmr.js +19 -0
  106. package/dist/runtime/remote-module-registry.js +57 -0
  107. package/dist/runtime/remote-module.js +2 -0
  108. package/dist/types.d.ts +26 -0
  109. package/dist/types.js +18 -0
  110. package/dist/types.mjs +1 -0
  111. package/dist/utils/errors.d.ts +8 -0
  112. package/dist/utils/errors.js +54 -0
  113. package/dist/utils/errors.mjs +14 -0
  114. package/dist/utils/federated-remote-types.d.ts +12 -0
  115. package/dist/utils/federated-remote-types.js +140 -0
  116. package/dist/utils/federated-remote-types.mjs +90 -0
  117. package/dist/utils/index.d.ts +2 -0
  118. package/dist/utils/index.js +47 -0
  119. package/dist/utils/index.mjs +3 -0
  120. package/dist/utils/metro-compat.d.ts +23 -0
  121. package/dist/utils/metro-compat.js +74 -0
  122. package/dist/utils/metro-compat.mjs +26 -0
  123. package/dist/utils/vm-manager.d.ts +21 -0
  124. package/dist/utils/vm-manager.js +118 -0
  125. package/dist/utils/vm-manager.mjs +70 -0
  126. package/package.json +106 -0
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, getters, values)=>{
14
+ var define = (defs, kind)=>{
15
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
+ enumerable: true,
17
+ [kind]: defs[key]
18
+ });
19
+ };
20
+ define(getters, "get");
21
+ define(values, "value");
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
26
+ })();
27
+ (()=>{
28
+ __webpack_require__.r = (exports1)=>{
29
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
30
+ value: 'Module'
31
+ });
32
+ Object.defineProperty(exports1, '__esModule', {
33
+ value: true
34
+ });
35
+ };
36
+ })();
37
+ var __webpack_exports__ = {};
38
+ __webpack_require__.r(__webpack_exports__);
39
+ __webpack_require__.d(__webpack_exports__, {
40
+ createManifestMiddleware: ()=>createManifestMiddleware
41
+ });
42
+ const external_node_fs_namespaceObject = require("node:fs");
43
+ const external_node_path_namespaceObject = require("node:path");
44
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
45
+ const metro_compat_js_namespaceObject = require("../utils/metro-compat.js");
46
+ const external_constants_js_namespaceObject = require("./constants.js");
47
+ const external_generators_js_namespaceObject = require("./generators.js");
48
+ const external_helpers_js_namespaceObject = require("./helpers.js");
49
+ const external_manifest_js_namespaceObject = require("./manifest.js");
50
+ function createManifestMiddleware({ federationConfig, projectRoot, remoteEntryPath, tmpDirPath, vmManager }) {
51
+ const warmups = new Map();
52
+ return (middleware, metroServer)=>{
53
+ const nextMiddleware = middleware;
54
+ return async (req, res, next)=>{
55
+ try {
56
+ const warmupOptions = getManifestWarmupOptions(req.url);
57
+ if (warmupOptions) {
58
+ const warmupKey = JSON.stringify(warmupOptions);
59
+ let warmup = warmups.get(warmupKey);
60
+ if (!warmup) {
61
+ warmup = warmManifestBundles(metroServer, {
62
+ federationConfig,
63
+ host: req.headers.host,
64
+ projectRoot,
65
+ remoteEntryPath,
66
+ tmpDirPath,
67
+ vmManager,
68
+ warmupOptions
69
+ }).finally(()=>{
70
+ warmups.delete(warmupKey);
71
+ });
72
+ warmups.set(warmupKey, warmup);
73
+ }
74
+ await warmup;
75
+ }
76
+ return nextMiddleware(req, res, next);
77
+ } catch (error) {
78
+ next(error instanceof Error ? error : new Error(String(error)));
79
+ }
80
+ };
81
+ };
82
+ }
83
+ function getManifestWarmupOptions(rawUrl) {
84
+ const parsedUrl = new URL(rawUrl ?? '/', 'http://localhost');
85
+ if (parsedUrl.pathname !== `/${external_constants_js_namespaceObject.MANIFEST_FILENAME}`) return null;
86
+ const platform = parsedUrl.searchParams.get('platform');
87
+ if (!platform) return null;
88
+ return {
89
+ dev: getBoolean(parsedUrl.searchParams, 'dev', true),
90
+ excludeSource: getBoolean(parsedUrl.searchParams, 'excludeSource', false),
91
+ minify: getBoolean(parsedUrl.searchParams, 'minify', false),
92
+ platform,
93
+ sourcePaths: parsedUrl.searchParams.get('sourcePaths') ?? void 0
94
+ };
95
+ }
96
+ async function warmManifestBundles(metroServer, { federationConfig, host, projectRoot, remoteEntryPath, tmpDirPath, vmManager, warmupOptions }) {
97
+ for (const request of getBundleWarmupRequests({
98
+ federationConfig,
99
+ projectRoot,
100
+ remoteEntryPath,
101
+ tmpDirPath,
102
+ vmManager
103
+ })){
104
+ if (request.virtualModule) await ensureVirtualModuleReady(request.virtualModule, vmManager);
105
+ await metroServer.build(getBundleOptions(request, host, warmupOptions));
106
+ }
107
+ }
108
+ function getBundleWarmupRequests({ federationConfig, projectRoot, remoteEntryPath, tmpDirPath }) {
109
+ const relativeTmpDirPath = (0, external_helpers_js_namespaceObject.toPosixPath)(external_node_path_default().relative(projectRoot, tmpDirPath));
110
+ const remoteEntryName = (0, external_helpers_js_namespaceObject.removeExtension)(external_node_path_default().basename(remoteEntryPath));
111
+ const relativeRemoteEntryPath = (0, external_helpers_js_namespaceObject.toPosixPath)(external_node_path_default().relative(projectRoot, remoteEntryPath));
112
+ const requests = [
113
+ {
114
+ bundlePath: `${relativeTmpDirPath}/${remoteEntryName}.bundle`,
115
+ entryFile: `./${relativeRemoteEntryPath}`,
116
+ isContainer: true,
117
+ virtualModule: {
118
+ filePath: remoteEntryPath,
119
+ getCode: ()=>(0, external_generators_js_namespaceObject.getRemoteEntryModule)(federationConfig, {
120
+ projectDir: projectRoot,
121
+ tmpDir: tmpDirPath
122
+ })
123
+ }
124
+ }
125
+ ];
126
+ for (const exposePath of Object.values(federationConfig.exposes)){
127
+ const bundlePath = getBundlePathForSource(exposePath);
128
+ requests.push({
129
+ bundlePath,
130
+ entryFile: normalizeEntryFile(exposePath),
131
+ isContainer: false
132
+ });
133
+ }
134
+ for (const [sharedName, sharedConfig] of Object.entries(federationConfig.shared)){
135
+ if (sharedConfig.eager || false === sharedConfig.import) continue;
136
+ const sharedVirtualModulePath = (0, external_manifest_js_namespaceObject.getSharedVirtualModulePath)(tmpDirPath, sharedName);
137
+ const relativeSharedVirtualModulePath = (0, external_helpers_js_namespaceObject.toPosixPath)(external_node_path_default().relative(projectRoot, sharedVirtualModulePath));
138
+ const sharedImportName = getSharedImportName(sharedName, sharedConfig);
139
+ requests.push({
140
+ bundlePath: (0, external_helpers_js_namespaceObject.replaceExtension)(relativeSharedVirtualModulePath, '.bundle'),
141
+ entryFile: normalizeEntryFile(relativeSharedVirtualModulePath),
142
+ isContainer: false,
143
+ virtualModule: {
144
+ filePath: sharedVirtualModulePath,
145
+ getCode: ()=>(0, external_generators_js_namespaceObject.getRemoteModule)(sharedImportName)
146
+ }
147
+ });
148
+ }
149
+ return requests;
150
+ }
151
+ async function ensureVirtualModuleReady(virtualModule, vmManager) {
152
+ const code = virtualModule.getCode();
153
+ await external_node_fs_namespaceObject.promises.mkdir(external_node_path_default().dirname(virtualModule.filePath), {
154
+ recursive: true
155
+ });
156
+ await external_node_fs_namespaceObject.promises.writeFile(virtualModule.filePath, code, 'utf-8');
157
+ vmManager.registerVirtualModule(virtualModule.filePath, ()=>code);
158
+ }
159
+ function getBundleOptions(request, host, warmupOptions) {
160
+ const query = getBundleQuery(warmupOptions, request.isContainer);
161
+ const sourceUrl = getSourceUrl(host, request.bundlePath, query);
162
+ const bundleOptions = {
163
+ ...metro_compat_js_namespaceObject.Server.DEFAULT_BUNDLE_OPTIONS,
164
+ dev: warmupOptions.dev,
165
+ entryFile: request.entryFile,
166
+ excludeSource: warmupOptions.excludeSource,
167
+ lazy: true,
168
+ minify: warmupOptions.minify,
169
+ modulesOnly: !request.isContainer,
170
+ platform: warmupOptions.platform,
171
+ runModule: request.isContainer,
172
+ sourceMapUrl: sourceUrl.replace(/\.bundle(\?)/, '.map$1'),
173
+ sourceUrl
174
+ };
175
+ if (warmupOptions.sourcePaths) bundleOptions.sourcePaths = warmupOptions.sourcePaths;
176
+ return bundleOptions;
177
+ }
178
+ function getBundleQuery(warmupOptions, isContainer) {
179
+ const query = new URLSearchParams();
180
+ query.set('platform', warmupOptions.platform);
181
+ query.set('dev', String(warmupOptions.dev));
182
+ query.set('lazy', 'true');
183
+ query.set('minify', String(warmupOptions.minify));
184
+ query.set('runModule', String(isContainer));
185
+ query.set('modulesOnly', String(!isContainer));
186
+ if (warmupOptions.excludeSource) query.set('excludeSource', 'true');
187
+ if (warmupOptions.sourcePaths) query.set('sourcePaths', warmupOptions.sourcePaths);
188
+ return query;
189
+ }
190
+ function getSourceUrl(host, bundlePath, query) {
191
+ const normalizedBundlePath = bundlePath.startsWith('/') ? bundlePath : `/${bundlePath}`;
192
+ return `http://${host ?? 'localhost'}${normalizedBundlePath}?${query.toString()}`;
193
+ }
194
+ function getBundlePathForSource(sourcePath) {
195
+ const normalized = (0, external_helpers_js_namespaceObject.toPosixPath)(external_node_path_default().normalize(sourcePath));
196
+ const withoutPrefix = normalized.startsWith('./') ? normalized.slice(2) : normalized;
197
+ return (0, external_helpers_js_namespaceObject.replaceExtension)(withoutPrefix, '.bundle');
198
+ }
199
+ function normalizeEntryFile(sourcePath) {
200
+ const normalized = (0, external_helpers_js_namespaceObject.toPosixPath)(external_node_path_default().normalize(sourcePath));
201
+ return normalized.startsWith('./') ? normalized : `./${normalized}`;
202
+ }
203
+ function getSharedImportName(sharedName, sharedConfig) {
204
+ return 'string' == typeof sharedConfig.import ? sharedConfig.import : sharedName;
205
+ }
206
+ function getBoolean(params, key, defaultValue) {
207
+ const value = params.get(key);
208
+ if (null == value) return defaultValue;
209
+ return 'true' === value || '1' === value;
210
+ }
211
+ exports.createManifestMiddleware = __webpack_exports__.createManifestMiddleware;
212
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
213
+ "createManifestMiddleware"
214
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
215
+ Object.defineProperty(exports, '__esModule', {
216
+ value: true
217
+ });
@@ -0,0 +1,170 @@
1
+ import "node:module";
2
+ import { promises } from "node:fs";
3
+ import node_path from "node:path";
4
+ import { Server } from "../utils/metro-compat.mjs";
5
+ import { MANIFEST_FILENAME } from "./constants.mjs";
6
+ import { getRemoteEntryModule, getRemoteModule } from "./generators.mjs";
7
+ import { removeExtension, replaceExtension, toPosixPath } from "./helpers.mjs";
8
+ import { getSharedVirtualModulePath } from "./manifest.mjs";
9
+ function createManifestMiddleware({ federationConfig, projectRoot, remoteEntryPath, tmpDirPath, vmManager }) {
10
+ const warmups = new Map();
11
+ return (middleware, metroServer)=>{
12
+ const nextMiddleware = middleware;
13
+ return async (req, res, next)=>{
14
+ try {
15
+ const warmupOptions = getManifestWarmupOptions(req.url);
16
+ if (warmupOptions) {
17
+ const warmupKey = JSON.stringify(warmupOptions);
18
+ let warmup = warmups.get(warmupKey);
19
+ if (!warmup) {
20
+ warmup = warmManifestBundles(metroServer, {
21
+ federationConfig,
22
+ host: req.headers.host,
23
+ projectRoot,
24
+ remoteEntryPath,
25
+ tmpDirPath,
26
+ vmManager,
27
+ warmupOptions
28
+ }).finally(()=>{
29
+ warmups.delete(warmupKey);
30
+ });
31
+ warmups.set(warmupKey, warmup);
32
+ }
33
+ await warmup;
34
+ }
35
+ return nextMiddleware(req, res, next);
36
+ } catch (error) {
37
+ next(error instanceof Error ? error : new Error(String(error)));
38
+ }
39
+ };
40
+ };
41
+ }
42
+ function getManifestWarmupOptions(rawUrl) {
43
+ const parsedUrl = new URL(rawUrl ?? '/', 'http://localhost');
44
+ if (parsedUrl.pathname !== `/${MANIFEST_FILENAME}`) return null;
45
+ const platform = parsedUrl.searchParams.get('platform');
46
+ if (!platform) return null;
47
+ return {
48
+ dev: getBoolean(parsedUrl.searchParams, 'dev', true),
49
+ excludeSource: getBoolean(parsedUrl.searchParams, 'excludeSource', false),
50
+ minify: getBoolean(parsedUrl.searchParams, 'minify', false),
51
+ platform,
52
+ sourcePaths: parsedUrl.searchParams.get('sourcePaths') ?? void 0
53
+ };
54
+ }
55
+ async function warmManifestBundles(metroServer, { federationConfig, host, projectRoot, remoteEntryPath, tmpDirPath, vmManager, warmupOptions }) {
56
+ for (const request of getBundleWarmupRequests({
57
+ federationConfig,
58
+ projectRoot,
59
+ remoteEntryPath,
60
+ tmpDirPath,
61
+ vmManager
62
+ })){
63
+ if (request.virtualModule) await ensureVirtualModuleReady(request.virtualModule, vmManager);
64
+ await metroServer.build(getBundleOptions(request, host, warmupOptions));
65
+ }
66
+ }
67
+ function getBundleWarmupRequests({ federationConfig, projectRoot, remoteEntryPath, tmpDirPath }) {
68
+ const relativeTmpDirPath = toPosixPath(node_path.relative(projectRoot, tmpDirPath));
69
+ const remoteEntryName = removeExtension(node_path.basename(remoteEntryPath));
70
+ const relativeRemoteEntryPath = toPosixPath(node_path.relative(projectRoot, remoteEntryPath));
71
+ const requests = [
72
+ {
73
+ bundlePath: `${relativeTmpDirPath}/${remoteEntryName}.bundle`,
74
+ entryFile: `./${relativeRemoteEntryPath}`,
75
+ isContainer: true,
76
+ virtualModule: {
77
+ filePath: remoteEntryPath,
78
+ getCode: ()=>getRemoteEntryModule(federationConfig, {
79
+ projectDir: projectRoot,
80
+ tmpDir: tmpDirPath
81
+ })
82
+ }
83
+ }
84
+ ];
85
+ for (const exposePath of Object.values(federationConfig.exposes)){
86
+ const bundlePath = getBundlePathForSource(exposePath);
87
+ requests.push({
88
+ bundlePath,
89
+ entryFile: normalizeEntryFile(exposePath),
90
+ isContainer: false
91
+ });
92
+ }
93
+ for (const [sharedName, sharedConfig] of Object.entries(federationConfig.shared)){
94
+ if (sharedConfig.eager || false === sharedConfig.import) continue;
95
+ const sharedVirtualModulePath = getSharedVirtualModulePath(tmpDirPath, sharedName);
96
+ const relativeSharedVirtualModulePath = toPosixPath(node_path.relative(projectRoot, sharedVirtualModulePath));
97
+ const sharedImportName = getSharedImportName(sharedName, sharedConfig);
98
+ requests.push({
99
+ bundlePath: replaceExtension(relativeSharedVirtualModulePath, '.bundle'),
100
+ entryFile: normalizeEntryFile(relativeSharedVirtualModulePath),
101
+ isContainer: false,
102
+ virtualModule: {
103
+ filePath: sharedVirtualModulePath,
104
+ getCode: ()=>getRemoteModule(sharedImportName)
105
+ }
106
+ });
107
+ }
108
+ return requests;
109
+ }
110
+ async function ensureVirtualModuleReady(virtualModule, vmManager) {
111
+ const code = virtualModule.getCode();
112
+ await promises.mkdir(node_path.dirname(virtualModule.filePath), {
113
+ recursive: true
114
+ });
115
+ await promises.writeFile(virtualModule.filePath, code, 'utf-8');
116
+ vmManager.registerVirtualModule(virtualModule.filePath, ()=>code);
117
+ }
118
+ function getBundleOptions(request, host, warmupOptions) {
119
+ const query = getBundleQuery(warmupOptions, request.isContainer);
120
+ const sourceUrl = getSourceUrl(host, request.bundlePath, query);
121
+ const bundleOptions = {
122
+ ...Server.DEFAULT_BUNDLE_OPTIONS,
123
+ dev: warmupOptions.dev,
124
+ entryFile: request.entryFile,
125
+ excludeSource: warmupOptions.excludeSource,
126
+ lazy: true,
127
+ minify: warmupOptions.minify,
128
+ modulesOnly: !request.isContainer,
129
+ platform: warmupOptions.platform,
130
+ runModule: request.isContainer,
131
+ sourceMapUrl: sourceUrl.replace(/\.bundle(\?)/, '.map$1'),
132
+ sourceUrl
133
+ };
134
+ if (warmupOptions.sourcePaths) bundleOptions.sourcePaths = warmupOptions.sourcePaths;
135
+ return bundleOptions;
136
+ }
137
+ function getBundleQuery(warmupOptions, isContainer) {
138
+ const query = new URLSearchParams();
139
+ query.set('platform', warmupOptions.platform);
140
+ query.set('dev', String(warmupOptions.dev));
141
+ query.set('lazy', 'true');
142
+ query.set('minify', String(warmupOptions.minify));
143
+ query.set('runModule', String(isContainer));
144
+ query.set('modulesOnly', String(!isContainer));
145
+ if (warmupOptions.excludeSource) query.set('excludeSource', 'true');
146
+ if (warmupOptions.sourcePaths) query.set('sourcePaths', warmupOptions.sourcePaths);
147
+ return query;
148
+ }
149
+ function getSourceUrl(host, bundlePath, query) {
150
+ const normalizedBundlePath = bundlePath.startsWith('/') ? bundlePath : `/${bundlePath}`;
151
+ return `http://${host ?? 'localhost'}${normalizedBundlePath}?${query.toString()}`;
152
+ }
153
+ function getBundlePathForSource(sourcePath) {
154
+ const normalized = toPosixPath(node_path.normalize(sourcePath));
155
+ const withoutPrefix = normalized.startsWith('./') ? normalized.slice(2) : normalized;
156
+ return replaceExtension(withoutPrefix, '.bundle');
157
+ }
158
+ function normalizeEntryFile(sourcePath) {
159
+ const normalized = toPosixPath(node_path.normalize(sourcePath));
160
+ return normalized.startsWith('./') ? normalized : `./${normalized}`;
161
+ }
162
+ function getSharedImportName(sharedName, sharedConfig) {
163
+ return 'string' == typeof sharedConfig.import ? sharedConfig.import : sharedName;
164
+ }
165
+ function getBoolean(params, key, defaultValue) {
166
+ const value = params.get(key);
167
+ if (null == value) return defaultValue;
168
+ return 'true' === value || '1' === value;
169
+ }
170
+ export { createManifestMiddleware };
@@ -0,0 +1,16 @@
1
+ import type { ModuleFederationConfigNormalized } from '../types';
2
+ export type BundleHashMap = Map<string, string>;
3
+ export type ManifestGenerationOptions = {
4
+ projectRoot?: string;
5
+ target?: 'development' | 'build';
6
+ tmpDirPath?: string;
7
+ };
8
+ export declare function createManifest(options: ModuleFederationConfigNormalized, mfMetroPath: string, hashesOrOptions?: BundleHashMap | ManifestGenerationOptions, manifestOptions?: ManifestGenerationOptions): string;
9
+ export declare function updateManifest(manifestPath: string, options: ModuleFederationConfigNormalized, hashesOrOptions?: BundleHashMap | ManifestGenerationOptions, manifestOptions?: ManifestGenerationOptions): string;
10
+ /**
11
+ * Compute SHA-256 of bundle code and store the hash for the matching
12
+ * manifest entry (container, exposed, or shared).
13
+ */
14
+ export declare function recordBundleHash(hashes: BundleHashMap, code: string, entryPoint: string, projectRoot: string, config: ModuleFederationConfigNormalized): void;
15
+ export declare function getSharedVirtualModuleName(sharedName: string): string;
16
+ export declare function getSharedVirtualModulePath(tmpDirPath: string, sharedName: string): string;
@@ -0,0 +1,246 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, getters, values)=>{
14
+ var define = (defs, kind)=>{
15
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
+ enumerable: true,
17
+ [kind]: defs[key]
18
+ });
19
+ };
20
+ define(getters, "get");
21
+ define(values, "value");
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
26
+ })();
27
+ (()=>{
28
+ __webpack_require__.r = (exports1)=>{
29
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
30
+ value: 'Module'
31
+ });
32
+ Object.defineProperty(exports1, '__esModule', {
33
+ value: true
34
+ });
35
+ };
36
+ })();
37
+ var __webpack_exports__ = {};
38
+ __webpack_require__.r(__webpack_exports__);
39
+ __webpack_require__.d(__webpack_exports__, {
40
+ createManifest: ()=>createManifest,
41
+ getSharedVirtualModuleName: ()=>getSharedVirtualModuleName,
42
+ getSharedVirtualModulePath: ()=>getSharedVirtualModulePath,
43
+ recordBundleHash: ()=>recordBundleHash,
44
+ updateManifest: ()=>updateManifest
45
+ });
46
+ const external_node_crypto_namespaceObject = require("node:crypto");
47
+ var external_node_crypto_default = /*#__PURE__*/ __webpack_require__.n(external_node_crypto_namespaceObject);
48
+ const external_node_fs_namespaceObject = require("node:fs");
49
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
50
+ const external_node_path_namespaceObject = require("node:path");
51
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
52
+ const external_constants_js_namespaceObject = require("./constants.js");
53
+ const external_helpers_js_namespaceObject = require("./helpers.js");
54
+ function createManifest(options, mfMetroPath, hashesOrOptions, manifestOptions) {
55
+ const { hashes, options: generationOptions } = normalizeManifestArgs(hashesOrOptions, manifestOptions);
56
+ const manifestPath = external_node_path_default().join(mfMetroPath, external_constants_js_namespaceObject.MANIFEST_FILENAME);
57
+ const manifest = generateManifest(options, hashes, generationOptions);
58
+ external_node_fs_default().writeFileSync(manifestPath, JSON.stringify(manifest, void 0, 2));
59
+ return manifestPath;
60
+ }
61
+ function updateManifest(manifestPath, options, hashesOrOptions, manifestOptions) {
62
+ const { hashes, options: generationOptions } = normalizeManifestArgs(hashesOrOptions, manifestOptions);
63
+ const manifest = generateManifest(options, hashes, generationOptions);
64
+ const existingManifest = readManifest(manifestPath);
65
+ if (existingManifest?.metaData?.types) manifest.metaData.types = {
66
+ ...manifest.metaData.types,
67
+ ...existingManifest.metaData.types
68
+ };
69
+ external_node_fs_default().writeFileSync(manifestPath, JSON.stringify(manifest, void 0, 2));
70
+ return manifestPath;
71
+ }
72
+ function recordBundleHash(hashes, code, entryPoint, projectRoot, config) {
73
+ const hash = external_node_crypto_default().createHash('sha256').update(code).digest('hex');
74
+ const key = resolveBundleKey(entryPoint, projectRoot, config);
75
+ if (key) hashes.set(key, hash);
76
+ }
77
+ function generateManifest(config, hashes, manifestOptions = {}) {
78
+ return {
79
+ id: config.name,
80
+ name: config.name,
81
+ metaData: generateMetaData(config, hashes),
82
+ exposes: generateExposes(config, hashes),
83
+ remotes: generateRemotes(config),
84
+ shared: generateShared(config, hashes, manifestOptions)
85
+ };
86
+ }
87
+ function generateMetaData(config, hashes) {
88
+ return {
89
+ name: config.name,
90
+ type: 'app',
91
+ buildInfo: {
92
+ buildVersion: '1.0.0',
93
+ buildName: config.name,
94
+ hash: hashes?.get(`container:${config.name}`) ?? ''
95
+ },
96
+ remoteEntry: {
97
+ name: config.filename,
98
+ path: '',
99
+ type: 'global'
100
+ },
101
+ types: {
102
+ path: '',
103
+ name: '',
104
+ api: '',
105
+ zip: ''
106
+ },
107
+ globalName: config.name,
108
+ pluginVersion: '',
109
+ publicPath: 'auto'
110
+ };
111
+ }
112
+ function generateExposes(config, hashes) {
113
+ return Object.keys(config.exposes).map((expose)=>{
114
+ const formatKey = expose.replace('./', '');
115
+ const assets = getEmptyAssets();
116
+ assets.js.sync.push(config.exposes[expose]);
117
+ return {
118
+ id: `${config.name}:${formatKey}`,
119
+ name: formatKey,
120
+ path: expose,
121
+ assets,
122
+ hash: hashes?.get(`expose:${formatKey}`) ?? ''
123
+ };
124
+ });
125
+ }
126
+ function generateRemotes(config) {
127
+ return Object.keys(config.remotes).map((remote)=>({
128
+ federationContainerName: config.remotes[remote],
129
+ moduleName: remote,
130
+ alias: remote,
131
+ entry: '*'
132
+ }));
133
+ }
134
+ function generateShared(config, hashes, manifestOptions = {}) {
135
+ return Object.keys(config.shared).map((sharedName)=>{
136
+ const assets = getEmptyAssets();
137
+ if (config.shared[sharedName].eager) assets.js.sync.push(config.filename);
138
+ else if (false !== config.shared[sharedName].import) assets.js.sync.push(getSharedAssetPath(sharedName, manifestOptions));
139
+ return {
140
+ id: sharedName,
141
+ name: sharedName,
142
+ version: getManifestVersion(config.shared[sharedName].version),
143
+ requiredVersion: getManifestRequiredVersion(config.shared[sharedName].requiredVersion),
144
+ singleton: config.shared[sharedName].singleton,
145
+ hash: hashes?.get(`shared:${sharedName}`) ?? '',
146
+ assets
147
+ };
148
+ });
149
+ }
150
+ function resolveBundleKey(entryPoint, projectRoot, config) {
151
+ const relPath = (0, external_helpers_js_namespaceObject.toPosixPath)(external_node_path_default().relative(projectRoot, entryPoint));
152
+ const normalizedRel = relPath.startsWith('./') ? relPath.slice(2) : relPath;
153
+ const normalizedRelNoExt = (0, external_helpers_js_namespaceObject.removeExtension)(normalizedRel);
154
+ for (const [exposeKey, exposePath] of Object.entries(config.exposes)){
155
+ const normalizedExpose = (0, external_helpers_js_namespaceObject.toPosixPath)(exposePath.startsWith('./') ? exposePath.slice(2) : exposePath);
156
+ if (normalizedRel === normalizedExpose || normalizedRelNoExt === (0, external_helpers_js_namespaceObject.removeExtension)(normalizedExpose)) return `expose:${exposeKey.replace('./', '')}`;
157
+ }
158
+ if ((0, external_helpers_js_namespaceObject.removeExtension)(external_node_path_default().basename(entryPoint)) === (0, external_helpers_js_namespaceObject.removeExtension)(external_node_path_default().basename(config.filename))) return `container:${config.name}`;
159
+ const virtualSharedKey = resolveDevVirtualSharedKey(entryPoint, projectRoot, config);
160
+ if (virtualSharedKey) return virtualSharedKey;
161
+ const absPath = (0, external_helpers_js_namespaceObject.toPosixPath)(external_node_path_default().resolve(entryPoint));
162
+ const nmMatch = absPath.match(/.*node_modules\/(.+)/);
163
+ if (nmMatch) {
164
+ const modulePath = (0, external_helpers_js_namespaceObject.removeExtension)(nmMatch[1]);
165
+ const sharedKey = findSharedKeyForModulePath(modulePath, config);
166
+ if (sharedKey) return `shared:${sharedKey}`;
167
+ }
168
+ return null;
169
+ }
170
+ function normalizeManifestArgs(hashesOrOptions, manifestOptions) {
171
+ if (hashesOrOptions instanceof Map) return {
172
+ hashes: hashesOrOptions,
173
+ options: manifestOptions ?? {}
174
+ };
175
+ return {
176
+ hashes: void 0,
177
+ options: hashesOrOptions ?? {}
178
+ };
179
+ }
180
+ function readManifest(manifestPath) {
181
+ if (!external_node_fs_default().existsSync(manifestPath)) return;
182
+ return JSON.parse(external_node_fs_default().readFileSync(manifestPath, 'utf-8'));
183
+ }
184
+ function getSharedVirtualModuleName(sharedName) {
185
+ return sharedName.replaceAll('/', '_');
186
+ }
187
+ function getSharedVirtualModulePath(tmpDirPath, sharedName) {
188
+ return external_node_path_default().join(tmpDirPath, 'shared', `${getSharedVirtualModuleName(sharedName)}.js`);
189
+ }
190
+ function getSharedAssetPath(sharedName, manifestOptions) {
191
+ if ('development' === manifestOptions.target && manifestOptions.projectRoot && manifestOptions.tmpDirPath) return (0, external_helpers_js_namespaceObject.toPosixPath)(external_node_path_default().relative(manifestOptions.projectRoot, getSharedVirtualModulePath(manifestOptions.tmpDirPath, sharedName)));
192
+ return `shared/${sharedName}.bundle`;
193
+ }
194
+ function resolveDevVirtualSharedKey(entryPoint, projectRoot, config) {
195
+ const relativePath = (0, external_helpers_js_namespaceObject.toPosixPath)(external_node_path_default().relative(projectRoot, entryPoint));
196
+ const virtualSharedPrefix = `node_modules/${external_constants_js_namespaceObject.TMP_DIR_NAME}/shared/`;
197
+ if (!relativePath.startsWith(virtualSharedPrefix)) return null;
198
+ const virtualModuleName = (0, external_helpers_js_namespaceObject.removeExtension)(relativePath.slice(virtualSharedPrefix.length));
199
+ const sharedKey = Object.keys(config.shared).find((sharedName)=>getSharedVirtualModuleName(sharedName) === virtualModuleName);
200
+ return sharedKey ? `shared:${sharedKey}` : null;
201
+ }
202
+ function findSharedKeyForModulePath(modulePath, config) {
203
+ const sharedEntries = Object.entries(config.shared).map(([sharedName, sharedConfig])=>{
204
+ const importName = 'string' == typeof sharedConfig.import ? sharedConfig.import : sharedName;
205
+ return {
206
+ importName,
207
+ sharedName
208
+ };
209
+ }).sort((a, b)=>b.importName.length - a.importName.length);
210
+ const normalizedModulePath = (0, external_helpers_js_namespaceObject.toPosixPath)(modulePath);
211
+ for (const { importName, sharedName } of sharedEntries)if (normalizedModulePath === importName || normalizedModulePath.startsWith(`${importName}/`)) return sharedName;
212
+ return null;
213
+ }
214
+ function getManifestVersion(version) {
215
+ return 'string' == typeof version ? version : '';
216
+ }
217
+ function getManifestRequiredVersion(requiredVersion) {
218
+ return 'string' == typeof requiredVersion ? requiredVersion : '*';
219
+ }
220
+ function getEmptyAssets() {
221
+ return {
222
+ js: {
223
+ sync: [],
224
+ async: []
225
+ },
226
+ css: {
227
+ sync: [],
228
+ async: []
229
+ }
230
+ };
231
+ }
232
+ exports.createManifest = __webpack_exports__.createManifest;
233
+ exports.getSharedVirtualModuleName = __webpack_exports__.getSharedVirtualModuleName;
234
+ exports.getSharedVirtualModulePath = __webpack_exports__.getSharedVirtualModulePath;
235
+ exports.recordBundleHash = __webpack_exports__.recordBundleHash;
236
+ exports.updateManifest = __webpack_exports__.updateManifest;
237
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
238
+ "createManifest",
239
+ "getSharedVirtualModuleName",
240
+ "getSharedVirtualModulePath",
241
+ "recordBundleHash",
242
+ "updateManifest"
243
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
244
+ Object.defineProperty(exports, '__esModule', {
245
+ value: true
246
+ });