@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.
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/babel-plugin/index.js +115 -0
- package/babel-plugin/patch-initialize-core.js +61 -0
- package/babel-plugin/patch-require.js +174 -0
- package/bootstrap/index.d.ts +1 -0
- package/bootstrap/index.js +1 -0
- package/dist/babel/transformer.js +15 -0
- package/dist/commands/bundle-host/index.d.ts +13 -0
- package/dist/commands/bundle-host/index.js +100 -0
- package/dist/commands/bundle-host/index.mjs +47 -0
- package/dist/commands/bundle-host/options.d.ts +5 -0
- package/dist/commands/bundle-host/options.js +43 -0
- package/dist/commands/bundle-host/options.mjs +6 -0
- package/dist/commands/bundle-host/types.d.ts +22 -0
- package/dist/commands/bundle-host/types.js +18 -0
- package/dist/commands/bundle-host/types.mjs +1 -0
- package/dist/commands/bundle-remote/index.d.ts +12 -0
- package/dist/commands/bundle-remote/index.js +241 -0
- package/dist/commands/bundle-remote/index.mjs +190 -0
- package/dist/commands/bundle-remote/options.d.ts +32 -0
- package/dist/commands/bundle-remote/options.js +113 -0
- package/dist/commands/bundle-remote/options.mjs +66 -0
- package/dist/commands/bundle-remote/types.d.ts +16 -0
- package/dist/commands/bundle-remote/types.js +18 -0
- package/dist/commands/bundle-remote/types.mjs +1 -0
- package/dist/commands/index.d.ts +48 -0
- package/dist/commands/index.js +76 -0
- package/dist/commands/index.mjs +13 -0
- package/dist/commands/types.d.ts +14 -0
- package/dist/commands/types.js +18 -0
- package/dist/commands/types.mjs +1 -0
- package/dist/commands/utils/create-module-path-remapper.d.ts +7 -0
- package/dist/commands/utils/create-module-path-remapper.js +68 -0
- package/dist/commands/utils/create-module-path-remapper.mjs +31 -0
- package/dist/commands/utils/create-resolver.d.ts +20 -0
- package/dist/commands/utils/create-resolver.js +61 -0
- package/dist/commands/utils/create-resolver.mjs +24 -0
- package/dist/commands/utils/get-community-plugin.d.ts +28 -0
- package/dist/commands/utils/get-community-plugin.js +53 -0
- package/dist/commands/utils/get-community-plugin.mjs +17 -0
- package/dist/commands/utils/load-metro-config.d.ts +3 -0
- package/dist/commands/utils/load-metro-config.js +85 -0
- package/dist/commands/utils/load-metro-config.mjs +41 -0
- package/dist/commands/utils/path-utils.d.ts +2 -0
- package/dist/commands/utils/path-utils.js +51 -0
- package/dist/commands/utils/path-utils.mjs +11 -0
- package/dist/commands/utils/save-bundle-and-map.d.ts +5 -0
- package/dist/commands/utils/save-bundle-and-map.js +80 -0
- package/dist/commands/utils/save-bundle-and-map.mjs +33 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +44 -0
- package/dist/index.mjs +3 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.js +43 -0
- package/dist/logger.mjs +6 -0
- package/dist/modules/HMRClient.ts +31 -0
- package/dist/modules/HMRClientShim.ts +1 -0
- package/dist/modules/asyncRequire.ts +156 -0
- package/dist/modules/asyncStartup.tsx +43 -0
- package/dist/modules/getDevServer.ts +15 -0
- package/dist/modules/metroCorePlugin.ts +87 -0
- package/dist/plugin/babel-transformer.d.ts +11 -0
- package/dist/plugin/babel-transformer.js +72 -0
- package/dist/plugin/babel-transformer.mjs +25 -0
- package/dist/plugin/constants.d.ts +10 -0
- package/dist/plugin/constants.js +76 -0
- package/dist/plugin/constants.mjs +12 -0
- package/dist/plugin/generators.d.ts +13 -0
- package/dist/plugin/generators.js +164 -0
- package/dist/plugin/generators.mjs +102 -0
- package/dist/plugin/helpers.d.ts +8 -0
- package/dist/plugin/helpers.js +127 -0
- package/dist/plugin/helpers.mjs +58 -0
- package/dist/plugin/index.d.ts +11 -0
- package/dist/plugin/index.js +219 -0
- package/dist/plugin/index.mjs +172 -0
- package/dist/plugin/manifest-middleware.d.ts +12 -0
- package/dist/plugin/manifest-middleware.js +217 -0
- package/dist/plugin/manifest-middleware.mjs +170 -0
- package/dist/plugin/manifest.d.ts +16 -0
- package/dist/plugin/manifest.js +246 -0
- package/dist/plugin/manifest.mjs +185 -0
- package/dist/plugin/normalize-extra-options.d.ts +8 -0
- package/dist/plugin/normalize-extra-options.js +50 -0
- package/dist/plugin/normalize-extra-options.mjs +13 -0
- package/dist/plugin/normalize-options.d.ts +7 -0
- package/dist/plugin/normalize-options.js +139 -0
- package/dist/plugin/normalize-options.mjs +92 -0
- package/dist/plugin/resolver.d.ts +26 -0
- package/dist/plugin/resolver.js +203 -0
- package/dist/plugin/resolver.mjs +159 -0
- package/dist/plugin/rewrite-request.d.ts +14 -0
- package/dist/plugin/rewrite-request.js +89 -0
- package/dist/plugin/rewrite-request.mjs +42 -0
- package/dist/plugin/serializer.d.ts +6 -0
- package/dist/plugin/serializer.js +191 -0
- package/dist/plugin/serializer.mjs +144 -0
- package/dist/plugin/validate-options.d.ts +2 -0
- package/dist/plugin/validate-options.js +165 -0
- package/dist/plugin/validate-options.mjs +117 -0
- package/dist/runtime/host-entry.js +3 -0
- package/dist/runtime/init-host.js +31 -0
- package/dist/runtime/remote-entry.js +57 -0
- package/dist/runtime/remote-hmr.js +19 -0
- package/dist/runtime/remote-module-registry.js +57 -0
- package/dist/runtime/remote-module.js +2 -0
- package/dist/types.d.ts +26 -0
- package/dist/types.js +18 -0
- package/dist/types.mjs +1 -0
- package/dist/utils/errors.d.ts +8 -0
- package/dist/utils/errors.js +54 -0
- package/dist/utils/errors.mjs +14 -0
- package/dist/utils/federated-remote-types.d.ts +12 -0
- package/dist/utils/federated-remote-types.js +140 -0
- package/dist/utils/federated-remote-types.mjs +90 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +47 -0
- package/dist/utils/index.mjs +3 -0
- package/dist/utils/metro-compat.d.ts +23 -0
- package/dist/utils/metro-compat.js +74 -0
- package/dist/utils/metro-compat.mjs +26 -0
- package/dist/utils/vm-manager.d.ts +21 -0
- package/dist/utils/vm-manager.js +118 -0
- package/dist/utils/vm-manager.mjs +70 -0
- package/package.json +106 -0
|
@@ -0,0 +1,203 @@
|
|
|
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
|
+
createResolveRequest: ()=>createResolveRequest
|
|
41
|
+
});
|
|
42
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
43
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
44
|
+
const external_constants_js_namespaceObject = require("./constants.js");
|
|
45
|
+
const external_generators_js_namespaceObject = require("./generators.js");
|
|
46
|
+
const external_helpers_js_namespaceObject = require("./helpers.js");
|
|
47
|
+
function createResolveRequest({ vmManager, options, hacks, paths, isRemote, customResolver }) {
|
|
48
|
+
const hostEntryPathRegex = getEntryPathRegex({
|
|
49
|
+
entry: paths.hostEntry,
|
|
50
|
+
projectDir: paths.projectDir
|
|
51
|
+
});
|
|
52
|
+
const remoteEntryPathRegex = getEntryPathRegex({
|
|
53
|
+
entry: paths.remoteEntry,
|
|
54
|
+
projectDir: paths.projectDir
|
|
55
|
+
});
|
|
56
|
+
return function(context, moduleName, platform) {
|
|
57
|
+
if (moduleName.match(hostEntryPathRegex)) {
|
|
58
|
+
const hostEntryGenerator = ()=>(0, external_generators_js_namespaceObject.getHostEntryModule)(options, {
|
|
59
|
+
originalEntry: paths.originalEntry,
|
|
60
|
+
tmpDir: paths.tmpDir
|
|
61
|
+
});
|
|
62
|
+
vmManager.registerVirtualModule(paths.hostEntry, hostEntryGenerator);
|
|
63
|
+
return {
|
|
64
|
+
type: 'sourceFile',
|
|
65
|
+
filePath: paths.hostEntry
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (moduleName.match(remoteEntryPathRegex)) {
|
|
69
|
+
const remoteEntryGenerator = ()=>(0, external_generators_js_namespaceObject.getRemoteEntryModule)(options, {
|
|
70
|
+
tmpDir: paths.tmpDir,
|
|
71
|
+
projectDir: paths.projectDir
|
|
72
|
+
});
|
|
73
|
+
vmManager.registerVirtualModule(paths.remoteEntry, remoteEntryGenerator);
|
|
74
|
+
return {
|
|
75
|
+
type: 'sourceFile',
|
|
76
|
+
filePath: paths.remoteEntry
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
if (moduleName === external_constants_js_namespaceObject.INIT_HOST) {
|
|
80
|
+
const initHostGenerator = ()=>(0, external_generators_js_namespaceObject.getInitHostModule)(options);
|
|
81
|
+
vmManager.registerVirtualModule(paths.initHost, initHostGenerator);
|
|
82
|
+
return {
|
|
83
|
+
type: 'sourceFile',
|
|
84
|
+
filePath: paths.initHost
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
if (moduleName === external_constants_js_namespaceObject.REMOTE_MODULE_REGISTRY) {
|
|
88
|
+
const registryGenerator = ()=>(0, external_generators_js_namespaceObject.getRemoteModuleRegistryModule)();
|
|
89
|
+
vmManager.registerVirtualModule(paths.remoteModuleRegistry, registryGenerator);
|
|
90
|
+
return {
|
|
91
|
+
type: 'sourceFile',
|
|
92
|
+
filePath: paths.remoteModuleRegistry
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (moduleName === external_constants_js_namespaceObject.REMOTE_HMR_SETUP) {
|
|
96
|
+
const remoteHMRSetupGenerator = ()=>(0, external_generators_js_namespaceObject.getRemoteHMRSetupModule)();
|
|
97
|
+
vmManager.registerVirtualModule(paths.remoteHMRSetup, remoteHMRSetupGenerator);
|
|
98
|
+
return {
|
|
99
|
+
type: 'sourceFile',
|
|
100
|
+
filePath: paths.remoteHMRSetup
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (moduleName === external_constants_js_namespaceObject.ASYNC_REQUIRE) return {
|
|
104
|
+
type: 'sourceFile',
|
|
105
|
+
filePath: paths.asyncRequire
|
|
106
|
+
};
|
|
107
|
+
if ([
|
|
108
|
+
paths.initHost
|
|
109
|
+
].includes(context.originModulePath)) return customResolver ? customResolver(context, moduleName, platform) : context.resolveRequest(context, moduleName, platform);
|
|
110
|
+
if ([
|
|
111
|
+
paths.remoteEntry
|
|
112
|
+
].includes(context.originModulePath)) {
|
|
113
|
+
const sharedModule = options.shared[moduleName];
|
|
114
|
+
if (sharedModule && false === sharedModule.import) {
|
|
115
|
+
const sharedPath = getSharedPath(moduleName, paths.tmpDir);
|
|
116
|
+
return {
|
|
117
|
+
type: 'sourceFile',
|
|
118
|
+
filePath: sharedPath
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return customResolver ? customResolver(context, moduleName, platform) : context.resolveRequest(context, moduleName, platform);
|
|
122
|
+
}
|
|
123
|
+
for (const remoteName of Object.keys(options.remotes))if (moduleName.startsWith(remoteName + '/')) {
|
|
124
|
+
const remotePath = getRemoteModulePath(moduleName, paths.tmpDir);
|
|
125
|
+
const remoteGenerator = ()=>(0, external_generators_js_namespaceObject.getRemoteModule)(moduleName);
|
|
126
|
+
vmManager.registerVirtualModule(remotePath, remoteGenerator);
|
|
127
|
+
return {
|
|
128
|
+
type: 'sourceFile',
|
|
129
|
+
filePath: remotePath
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
for (const sharedName of Object.keys(options.shared)){
|
|
133
|
+
const importName = options.shared[sharedName].import || sharedName;
|
|
134
|
+
if (moduleName === importName) {
|
|
135
|
+
const sharedPath = getSharedPath(sharedName, paths.tmpDir);
|
|
136
|
+
const sharedGenerator = ()=>(0, external_generators_js_namespaceObject.getRemoteModule)(importName);
|
|
137
|
+
vmManager.registerVirtualModule(sharedPath, sharedGenerator);
|
|
138
|
+
return {
|
|
139
|
+
type: 'sourceFile',
|
|
140
|
+
filePath: sharedPath
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (isRemote && moduleName.endsWith('getDevServer')) {
|
|
145
|
+
const res = customResolver ? customResolver(context, moduleName, platform) : context.resolveRequest(context, moduleName, platform);
|
|
146
|
+
const from = external_constants_js_namespaceObject.GET_DEV_SERVER_REGEX;
|
|
147
|
+
const to = resolveModule('getDevServer.ts');
|
|
148
|
+
return replaceModule(from, to)(res);
|
|
149
|
+
}
|
|
150
|
+
if ((0, external_helpers_js_namespaceObject.isUsingMFBundleCommand)() && moduleName.endsWith('HMRClient')) {
|
|
151
|
+
const res = customResolver ? customResolver(context, moduleName, platform) : context.resolveRequest(context, moduleName, platform);
|
|
152
|
+
const from = external_constants_js_namespaceObject.HMR_CLIENT_REGEX;
|
|
153
|
+
const to = resolveModule('HMRClientShim.ts');
|
|
154
|
+
return replaceModule(from, to)(res);
|
|
155
|
+
}
|
|
156
|
+
if (hacks.patchHMRClient && moduleName.endsWith('HMRClient') && context.originModulePath !== resolveModule('HMRClient.ts')) {
|
|
157
|
+
const res = customResolver ? customResolver(context, moduleName, platform) : context.resolveRequest(context, moduleName, platform);
|
|
158
|
+
const from = external_constants_js_namespaceObject.HMR_CLIENT_REGEX;
|
|
159
|
+
const to = resolveModule('HMRClient.ts');
|
|
160
|
+
return replaceModule(from, to)(res);
|
|
161
|
+
}
|
|
162
|
+
return customResolver ? customResolver(context, moduleName, platform) : context.resolveRequest(context, moduleName, platform);
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function getSharedPath(name, dir) {
|
|
166
|
+
const sharedModuleName = name.replaceAll('/', '_');
|
|
167
|
+
const sharedModuleDir = external_node_path_default().join(dir, 'shared');
|
|
168
|
+
return external_node_path_default().join(sharedModuleDir, `${sharedModuleName}.js`);
|
|
169
|
+
}
|
|
170
|
+
function getRemoteModulePath(name, dir) {
|
|
171
|
+
const remoteModuleName = name.replaceAll('/', '_');
|
|
172
|
+
const remoteModuleDir = external_node_path_default().join(dir, 'remote');
|
|
173
|
+
return external_node_path_default().join(remoteModuleDir, `${remoteModuleName}.js`);
|
|
174
|
+
}
|
|
175
|
+
function resolveModule(moduleName) {
|
|
176
|
+
return external_node_path_default().resolve(__dirname, `../modules/${moduleName}`);
|
|
177
|
+
}
|
|
178
|
+
function replaceModule(from, to) {
|
|
179
|
+
return (resolved)=>{
|
|
180
|
+
if ('sourceFile' === resolved.type && from.test((0, external_helpers_js_namespaceObject.toPosixPath)(resolved.filePath))) {
|
|
181
|
+
if (null === to) return {
|
|
182
|
+
type: 'empty'
|
|
183
|
+
};
|
|
184
|
+
return {
|
|
185
|
+
type: 'sourceFile',
|
|
186
|
+
filePath: to
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
return resolved;
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function getEntryPathRegex(paths) {
|
|
193
|
+
const relativeEntryPath = external_node_path_default().relative(paths.projectDir, paths.entry);
|
|
194
|
+
const entryName = (0, external_helpers_js_namespaceObject.toPosixPath)((0, external_helpers_js_namespaceObject.removeExtension)(relativeEntryPath));
|
|
195
|
+
return new RegExp(`^\\./${entryName}(\\.js)?$`);
|
|
196
|
+
}
|
|
197
|
+
exports.createResolveRequest = __webpack_exports__.createResolveRequest;
|
|
198
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
199
|
+
"createResolveRequest"
|
|
200
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
201
|
+
Object.defineProperty(exports, '__esModule', {
|
|
202
|
+
value: true
|
|
203
|
+
});
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
import { ASYNC_REQUIRE, GET_DEV_SERVER_REGEX, HMR_CLIENT_REGEX, INIT_HOST, REMOTE_HMR_SETUP, REMOTE_MODULE_REGISTRY } from "./constants.mjs";
|
|
4
|
+
import { getHostEntryModule, getInitHostModule, getRemoteEntryModule, getRemoteHMRSetupModule, getRemoteModule, getRemoteModuleRegistryModule } from "./generators.mjs";
|
|
5
|
+
import { isUsingMFBundleCommand, removeExtension, toPosixPath } from "./helpers.mjs";
|
|
6
|
+
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
7
|
+
import { dirname as __rspack_dirname } from "node:path";
|
|
8
|
+
var __rspack_import_meta_dirname__ = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
|
|
9
|
+
function createResolveRequest({ vmManager, options, hacks, paths, isRemote, customResolver }) {
|
|
10
|
+
const hostEntryPathRegex = getEntryPathRegex({
|
|
11
|
+
entry: paths.hostEntry,
|
|
12
|
+
projectDir: paths.projectDir
|
|
13
|
+
});
|
|
14
|
+
const remoteEntryPathRegex = getEntryPathRegex({
|
|
15
|
+
entry: paths.remoteEntry,
|
|
16
|
+
projectDir: paths.projectDir
|
|
17
|
+
});
|
|
18
|
+
return function(context, moduleName, platform) {
|
|
19
|
+
if (moduleName.match(hostEntryPathRegex)) {
|
|
20
|
+
const hostEntryGenerator = ()=>getHostEntryModule(options, {
|
|
21
|
+
originalEntry: paths.originalEntry,
|
|
22
|
+
tmpDir: paths.tmpDir
|
|
23
|
+
});
|
|
24
|
+
vmManager.registerVirtualModule(paths.hostEntry, hostEntryGenerator);
|
|
25
|
+
return {
|
|
26
|
+
type: 'sourceFile',
|
|
27
|
+
filePath: paths.hostEntry
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (moduleName.match(remoteEntryPathRegex)) {
|
|
31
|
+
const remoteEntryGenerator = ()=>getRemoteEntryModule(options, {
|
|
32
|
+
tmpDir: paths.tmpDir,
|
|
33
|
+
projectDir: paths.projectDir
|
|
34
|
+
});
|
|
35
|
+
vmManager.registerVirtualModule(paths.remoteEntry, remoteEntryGenerator);
|
|
36
|
+
return {
|
|
37
|
+
type: 'sourceFile',
|
|
38
|
+
filePath: paths.remoteEntry
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (moduleName === INIT_HOST) {
|
|
42
|
+
const initHostGenerator = ()=>getInitHostModule(options);
|
|
43
|
+
vmManager.registerVirtualModule(paths.initHost, initHostGenerator);
|
|
44
|
+
return {
|
|
45
|
+
type: 'sourceFile',
|
|
46
|
+
filePath: paths.initHost
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (moduleName === REMOTE_MODULE_REGISTRY) {
|
|
50
|
+
const registryGenerator = ()=>getRemoteModuleRegistryModule();
|
|
51
|
+
vmManager.registerVirtualModule(paths.remoteModuleRegistry, registryGenerator);
|
|
52
|
+
return {
|
|
53
|
+
type: 'sourceFile',
|
|
54
|
+
filePath: paths.remoteModuleRegistry
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (moduleName === REMOTE_HMR_SETUP) {
|
|
58
|
+
const remoteHMRSetupGenerator = ()=>getRemoteHMRSetupModule();
|
|
59
|
+
vmManager.registerVirtualModule(paths.remoteHMRSetup, remoteHMRSetupGenerator);
|
|
60
|
+
return {
|
|
61
|
+
type: 'sourceFile',
|
|
62
|
+
filePath: paths.remoteHMRSetup
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (moduleName === ASYNC_REQUIRE) return {
|
|
66
|
+
type: 'sourceFile',
|
|
67
|
+
filePath: paths.asyncRequire
|
|
68
|
+
};
|
|
69
|
+
if ([
|
|
70
|
+
paths.initHost
|
|
71
|
+
].includes(context.originModulePath)) return customResolver ? customResolver(context, moduleName, platform) : context.resolveRequest(context, moduleName, platform);
|
|
72
|
+
if ([
|
|
73
|
+
paths.remoteEntry
|
|
74
|
+
].includes(context.originModulePath)) {
|
|
75
|
+
const sharedModule = options.shared[moduleName];
|
|
76
|
+
if (sharedModule && false === sharedModule.import) {
|
|
77
|
+
const sharedPath = getSharedPath(moduleName, paths.tmpDir);
|
|
78
|
+
return {
|
|
79
|
+
type: 'sourceFile',
|
|
80
|
+
filePath: sharedPath
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return customResolver ? customResolver(context, moduleName, platform) : context.resolveRequest(context, moduleName, platform);
|
|
84
|
+
}
|
|
85
|
+
for (const remoteName of Object.keys(options.remotes))if (moduleName.startsWith(remoteName + '/')) {
|
|
86
|
+
const remotePath = getRemoteModulePath(moduleName, paths.tmpDir);
|
|
87
|
+
const remoteGenerator = ()=>getRemoteModule(moduleName);
|
|
88
|
+
vmManager.registerVirtualModule(remotePath, remoteGenerator);
|
|
89
|
+
return {
|
|
90
|
+
type: 'sourceFile',
|
|
91
|
+
filePath: remotePath
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
for (const sharedName of Object.keys(options.shared)){
|
|
95
|
+
const importName = options.shared[sharedName].import || sharedName;
|
|
96
|
+
if (moduleName === importName) {
|
|
97
|
+
const sharedPath = getSharedPath(sharedName, paths.tmpDir);
|
|
98
|
+
const sharedGenerator = ()=>getRemoteModule(importName);
|
|
99
|
+
vmManager.registerVirtualModule(sharedPath, sharedGenerator);
|
|
100
|
+
return {
|
|
101
|
+
type: 'sourceFile',
|
|
102
|
+
filePath: sharedPath
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (isRemote && moduleName.endsWith('getDevServer')) {
|
|
107
|
+
const res = customResolver ? customResolver(context, moduleName, platform) : context.resolveRequest(context, moduleName, platform);
|
|
108
|
+
const from = GET_DEV_SERVER_REGEX;
|
|
109
|
+
const to = resolveModule('getDevServer.ts');
|
|
110
|
+
return replaceModule(from, to)(res);
|
|
111
|
+
}
|
|
112
|
+
if (isUsingMFBundleCommand() && moduleName.endsWith('HMRClient')) {
|
|
113
|
+
const res = customResolver ? customResolver(context, moduleName, platform) : context.resolveRequest(context, moduleName, platform);
|
|
114
|
+
const from = HMR_CLIENT_REGEX;
|
|
115
|
+
const to = resolveModule('HMRClientShim.ts');
|
|
116
|
+
return replaceModule(from, to)(res);
|
|
117
|
+
}
|
|
118
|
+
if (hacks.patchHMRClient && moduleName.endsWith('HMRClient') && context.originModulePath !== resolveModule('HMRClient.ts')) {
|
|
119
|
+
const res = customResolver ? customResolver(context, moduleName, platform) : context.resolveRequest(context, moduleName, platform);
|
|
120
|
+
const from = HMR_CLIENT_REGEX;
|
|
121
|
+
const to = resolveModule('HMRClient.ts');
|
|
122
|
+
return replaceModule(from, to)(res);
|
|
123
|
+
}
|
|
124
|
+
return customResolver ? customResolver(context, moduleName, platform) : context.resolveRequest(context, moduleName, platform);
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function getSharedPath(name, dir) {
|
|
128
|
+
const sharedModuleName = name.replaceAll('/', '_');
|
|
129
|
+
const sharedModuleDir = node_path.join(dir, 'shared');
|
|
130
|
+
return node_path.join(sharedModuleDir, `${sharedModuleName}.js`);
|
|
131
|
+
}
|
|
132
|
+
function getRemoteModulePath(name, dir) {
|
|
133
|
+
const remoteModuleName = name.replaceAll('/', '_');
|
|
134
|
+
const remoteModuleDir = node_path.join(dir, 'remote');
|
|
135
|
+
return node_path.join(remoteModuleDir, `${remoteModuleName}.js`);
|
|
136
|
+
}
|
|
137
|
+
function resolveModule(moduleName) {
|
|
138
|
+
return node_path.resolve(__rspack_import_meta_dirname__, `../modules/${moduleName}`);
|
|
139
|
+
}
|
|
140
|
+
function replaceModule(from, to) {
|
|
141
|
+
return (resolved)=>{
|
|
142
|
+
if ('sourceFile' === resolved.type && from.test(toPosixPath(resolved.filePath))) {
|
|
143
|
+
if (null === to) return {
|
|
144
|
+
type: 'empty'
|
|
145
|
+
};
|
|
146
|
+
return {
|
|
147
|
+
type: 'sourceFile',
|
|
148
|
+
filePath: to
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
return resolved;
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function getEntryPathRegex(paths) {
|
|
155
|
+
const relativeEntryPath = node_path.relative(paths.projectDir, paths.entry);
|
|
156
|
+
const entryName = toPosixPath(removeExtension(relativeEntryPath));
|
|
157
|
+
return new RegExp(`^\\./${entryName}(\\.js)?$`);
|
|
158
|
+
}
|
|
159
|
+
export { createResolveRequest };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ConfigT } from 'metro-config';
|
|
2
|
+
type CreateRewriteRequestOptions = {
|
|
3
|
+
config: ConfigT;
|
|
4
|
+
originalEntryFilename: string;
|
|
5
|
+
remoteEntryFilename: string;
|
|
6
|
+
manifestPath: string;
|
|
7
|
+
tmpDirPath: string;
|
|
8
|
+
getDtsAssetNames?: () => {
|
|
9
|
+
zipName?: string;
|
|
10
|
+
apiFileName?: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export declare function createRewriteRequest({ config, originalEntryFilename, remoteEntryFilename, manifestPath, tmpDirPath, getDtsAssetNames, }: CreateRewriteRequestOptions): (url: string) => string;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
createRewriteRequest: ()=>createRewriteRequest
|
|
41
|
+
});
|
|
42
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
43
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
44
|
+
const external_constants_js_namespaceObject = require("./constants.js");
|
|
45
|
+
const external_helpers_js_namespaceObject = require("./helpers.js");
|
|
46
|
+
function createRewriteRequest({ config, originalEntryFilename, remoteEntryFilename, manifestPath, tmpDirPath, getDtsAssetNames }) {
|
|
47
|
+
const hostEntryName = (0, external_helpers_js_namespaceObject.removeExtension)(originalEntryFilename);
|
|
48
|
+
const remoteEntryName = (0, external_helpers_js_namespaceObject.removeExtension)(remoteEntryFilename);
|
|
49
|
+
const relativeTmpDirPath = external_node_path_default().relative(config.projectRoot, tmpDirPath).split(external_node_path_default().sep).join(external_node_path_default().posix.sep);
|
|
50
|
+
const hostEntryPathRegex = getEntryPathRegex(hostEntryName);
|
|
51
|
+
const remoteEntryPathRegex = getEntryPathRegex(remoteEntryName);
|
|
52
|
+
return function(url) {
|
|
53
|
+
const root = config.projectRoot;
|
|
54
|
+
const { pathname } = new URL(url, 'protocol://host');
|
|
55
|
+
if (pathname.match(hostEntryPathRegex)) {
|
|
56
|
+
const target = `${relativeTmpDirPath}/${hostEntryName}`;
|
|
57
|
+
return url.replace(hostEntryName, target);
|
|
58
|
+
}
|
|
59
|
+
if (pathname.match(remoteEntryPathRegex)) {
|
|
60
|
+
const target = `${relativeTmpDirPath}/${remoteEntryName}`;
|
|
61
|
+
return url.replace(remoteEntryName, target);
|
|
62
|
+
}
|
|
63
|
+
if (pathname.startsWith(`/${external_constants_js_namespaceObject.MANIFEST_FILENAME}`)) {
|
|
64
|
+
const target = (0, external_helpers_js_namespaceObject.toPosixPath)(manifestPath.replace(root, '[metro-project]'));
|
|
65
|
+
return url.replace(external_constants_js_namespaceObject.MANIFEST_FILENAME, target);
|
|
66
|
+
}
|
|
67
|
+
const dtsAssets = getDtsAssetNames?.();
|
|
68
|
+
const dtsAssetName = [
|
|
69
|
+
dtsAssets?.zipName,
|
|
70
|
+
dtsAssets?.apiFileName
|
|
71
|
+
].filter((value)=>Boolean(value)).find((value)=>pathname === `/${value}`);
|
|
72
|
+
if (dtsAssetName) {
|
|
73
|
+
const target = `${relativeTmpDirPath}/${dtsAssetName}`;
|
|
74
|
+
return url.replace(dtsAssetName, target);
|
|
75
|
+
}
|
|
76
|
+
if (config.server.rewriteRequestUrl) return config.server.rewriteRequestUrl(url);
|
|
77
|
+
return url;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function getEntryPathRegex(entryFilename) {
|
|
81
|
+
return new RegExp(`^\\/${entryFilename}(\\.js)?(\\.bundle)$`);
|
|
82
|
+
}
|
|
83
|
+
exports.createRewriteRequest = __webpack_exports__.createRewriteRequest;
|
|
84
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
85
|
+
"createRewriteRequest"
|
|
86
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
87
|
+
Object.defineProperty(exports, '__esModule', {
|
|
88
|
+
value: true
|
|
89
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
import { MANIFEST_FILENAME } from "./constants.mjs";
|
|
4
|
+
import { removeExtension, toPosixPath } from "./helpers.mjs";
|
|
5
|
+
function createRewriteRequest({ config, originalEntryFilename, remoteEntryFilename, manifestPath, tmpDirPath, getDtsAssetNames }) {
|
|
6
|
+
const hostEntryName = removeExtension(originalEntryFilename);
|
|
7
|
+
const remoteEntryName = removeExtension(remoteEntryFilename);
|
|
8
|
+
const relativeTmpDirPath = node_path.relative(config.projectRoot, tmpDirPath).split(node_path.sep).join(node_path.posix.sep);
|
|
9
|
+
const hostEntryPathRegex = getEntryPathRegex(hostEntryName);
|
|
10
|
+
const remoteEntryPathRegex = getEntryPathRegex(remoteEntryName);
|
|
11
|
+
return function(url) {
|
|
12
|
+
const root = config.projectRoot;
|
|
13
|
+
const { pathname } = new URL(url, 'protocol://host');
|
|
14
|
+
if (pathname.match(hostEntryPathRegex)) {
|
|
15
|
+
const target = `${relativeTmpDirPath}/${hostEntryName}`;
|
|
16
|
+
return url.replace(hostEntryName, target);
|
|
17
|
+
}
|
|
18
|
+
if (pathname.match(remoteEntryPathRegex)) {
|
|
19
|
+
const target = `${relativeTmpDirPath}/${remoteEntryName}`;
|
|
20
|
+
return url.replace(remoteEntryName, target);
|
|
21
|
+
}
|
|
22
|
+
if (pathname.startsWith(`/${MANIFEST_FILENAME}`)) {
|
|
23
|
+
const target = toPosixPath(manifestPath.replace(root, '[metro-project]'));
|
|
24
|
+
return url.replace(MANIFEST_FILENAME, target);
|
|
25
|
+
}
|
|
26
|
+
const dtsAssets = getDtsAssetNames?.();
|
|
27
|
+
const dtsAssetName = [
|
|
28
|
+
dtsAssets?.zipName,
|
|
29
|
+
dtsAssets?.apiFileName
|
|
30
|
+
].filter((value)=>Boolean(value)).find((value)=>pathname === `/${value}`);
|
|
31
|
+
if (dtsAssetName) {
|
|
32
|
+
const target = `${relativeTmpDirPath}/${dtsAssetName}`;
|
|
33
|
+
return url.replace(dtsAssetName, target);
|
|
34
|
+
}
|
|
35
|
+
if (config.server.rewriteRequestUrl) return config.server.rewriteRequestUrl(url);
|
|
36
|
+
return url;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function getEntryPathRegex(entryFilename) {
|
|
40
|
+
return new RegExp(`^\\/${entryFilename}(\\.js)?(\\.bundle)$`);
|
|
41
|
+
}
|
|
42
|
+
export { createRewriteRequest };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SerializerConfigT } from 'metro-config';
|
|
2
|
+
import type { ModuleFederationConfigNormalized } from '../types';
|
|
3
|
+
import { type ManifestGenerationOptions } from './manifest';
|
|
4
|
+
type CustomSerializer = SerializerConfigT['customSerializer'];
|
|
5
|
+
export declare function getModuleFederationSerializer(mfConfig: ModuleFederationConfigNormalized, isUsingMFBundleCommand: boolean, manifestPath?: string, manifestOptions?: ManifestGenerationOptions): CustomSerializer;
|
|
6
|
+
export {};
|