@module-federation/metro 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/babel/transformer.js +1 -1
- package/dist/commands/bundle-host/index.js +3 -1
- package/dist/commands/bundle-host/index.mjs +3 -1
- package/dist/commands/bundle-remote/index.js +19 -7
- package/dist/commands/bundle-remote/index.mjs +19 -7
- package/dist/commands/utils/path-utils.d.ts +2 -0
- package/dist/commands/utils/path-utils.js +47 -0
- package/dist/commands/utils/path-utils.mjs +12 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.js +39 -0
- package/dist/logger.mjs +7 -0
- package/dist/modules/asyncRequire.ts +0 -3
- package/dist/modules/asyncStartup.tsx +1 -0
- package/dist/modules/metroCorePlugin.ts +3 -3
- package/dist/plugin/babel-transformer.js +1 -1
- package/dist/plugin/babel-transformer.mjs +1 -1
- package/dist/plugin/constants.d.ts +1 -0
- package/dist/plugin/constants.js +4 -0
- package/dist/plugin/constants.mjs +2 -1
- package/dist/plugin/generators.js +6 -3
- package/dist/plugin/generators.mjs +6 -3
- package/dist/plugin/helpers.d.ts +1 -0
- package/dist/plugin/helpers.js +11 -5
- package/dist/plugin/helpers.mjs +4 -1
- package/dist/plugin/index.d.ts +2 -0
- package/dist/plugin/index.js +33 -1
- package/dist/plugin/index.mjs +33 -1
- package/dist/plugin/manifest.js +8 -2
- package/dist/plugin/manifest.mjs +8 -2
- package/dist/plugin/normalize-options.js +57 -8
- package/dist/plugin/normalize-options.mjs +57 -8
- package/dist/plugin/resolver.js +1 -1
- package/dist/plugin/resolver.mjs +2 -2
- package/dist/plugin/rewrite-request.d.ts +5 -1
- package/dist/plugin/rewrite-request.js +11 -2
- package/dist/plugin/rewrite-request.mjs +12 -3
- package/dist/plugin/serializer.js +21 -1
- package/dist/plugin/serializer.mjs +21 -1
- package/dist/plugin/validate-options.js +106 -5
- package/dist/plugin/validate-options.mjs +95 -5
- package/dist/types.d.ts +15 -15
- package/dist/utils/federated-remote-types.d.ts +12 -0
- package/dist/utils/federated-remote-types.js +159 -0
- package/dist/utils/federated-remote-types.mjs +91 -0
- package/package.json +7 -3
- package/dist/babel/transformer.d.ts +0 -2
- package/dist/runtime/host-entry.d.ts +0 -1
- package/dist/runtime/init-host.d.ts +0 -1
- package/dist/runtime/remote-entry.d.ts +0 -1
- package/dist/runtime/remote-hmr.d.ts +0 -1
- package/dist/runtime/remote-module-registry.d.ts +0 -7
- package/dist/runtime/remote-module.d.ts +0 -1
|
@@ -47,6 +47,7 @@ const get_community_plugin_js_namespaceObject = require("../utils/get-community-
|
|
|
47
47
|
const load_metro_config_js_namespaceObject = require("../utils/load-metro-config.js");
|
|
48
48
|
var load_metro_config_js_default = /*#__PURE__*/ __webpack_require__.n(load_metro_config_js_namespaceObject);
|
|
49
49
|
const save_bundle_and_map_js_namespaceObject = require("../utils/save-bundle-and-map.js");
|
|
50
|
+
const helpers_js_namespaceObject = require("../../plugin/helpers.js");
|
|
50
51
|
const external_options_js_namespaceObject = require("./options.js");
|
|
51
52
|
var external_options_js_default = /*#__PURE__*/ __webpack_require__.n(external_options_js_namespaceObject);
|
|
52
53
|
async function bundleFederatedHost(_argv, cfg, args) {
|
|
@@ -69,9 +70,10 @@ async function bundleFederatedHost(_argv, cfg, args) {
|
|
|
69
70
|
build: async (server, requestOpts)=>{
|
|
70
71
|
config.server.enhanceMiddleware(server.processRequest, server);
|
|
71
72
|
const resolver = await (0, create_resolver_js_namespaceObject.createResolver)(server, args.platform);
|
|
73
|
+
const relativeHostEntryPath = (0, helpers_js_namespaceObject.toPosixPath)(external_node_path_default().relative(config.projectRoot, hostEntryFilepath));
|
|
72
74
|
resolver.resolve({
|
|
73
75
|
from: config.projectRoot,
|
|
74
|
-
to: `./${
|
|
76
|
+
to: `./${relativeHostEntryPath}`
|
|
75
77
|
});
|
|
76
78
|
return server.build({
|
|
77
79
|
...metro_compat_js_namespaceObject.Server.DEFAULT_BUNDLE_OPTIONS,
|
|
@@ -8,6 +8,7 @@ import { createResolver } from "../utils/create-resolver.mjs";
|
|
|
8
8
|
import { getCommunityCliPlugin } from "../utils/get-community-plugin.mjs";
|
|
9
9
|
import load_metro_config from "../utils/load-metro-config.mjs";
|
|
10
10
|
import { saveBundleAndMap } from "../utils/save-bundle-and-map.mjs";
|
|
11
|
+
import { toPosixPath } from "../../plugin/helpers.mjs";
|
|
11
12
|
import options from "./options.mjs";
|
|
12
13
|
async function bundleFederatedHost(_argv, cfg, args) {
|
|
13
14
|
const logger = cfg.logger ?? console;
|
|
@@ -29,9 +30,10 @@ async function bundleFederatedHost(_argv, cfg, args) {
|
|
|
29
30
|
build: async (server, requestOpts)=>{
|
|
30
31
|
config.server.enhanceMiddleware(server.processRequest, server);
|
|
31
32
|
const resolver = await createResolver(server, args.platform);
|
|
33
|
+
const relativeHostEntryPath = toPosixPath(node_path.relative(config.projectRoot, hostEntryFilepath));
|
|
32
34
|
resolver.resolve({
|
|
33
35
|
from: config.projectRoot,
|
|
34
|
-
to: `./${
|
|
36
|
+
to: `./${relativeHostEntryPath}`
|
|
35
37
|
});
|
|
36
38
|
return server.build({
|
|
37
39
|
...Server.DEFAULT_BUNDLE_OPTIONS,
|
|
@@ -39,17 +39,19 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
39
39
|
const external_node_fs_namespaceObject = require("node:fs");
|
|
40
40
|
const external_node_path_namespaceObject = require("node:path");
|
|
41
41
|
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
42
|
-
const external_node_url_namespaceObject = require("node:url");
|
|
43
42
|
const external_node_util_namespaceObject = require("node:util");
|
|
44
43
|
var external_node_util_default = /*#__PURE__*/ __webpack_require__.n(external_node_util_namespaceObject);
|
|
45
44
|
const external_metro_namespaceObject = require("metro");
|
|
46
45
|
const errors_js_namespaceObject = require("../../utils/errors.js");
|
|
46
|
+
const federated_remote_types_js_namespaceObject = require("../../utils/federated-remote-types.js");
|
|
47
47
|
const metro_compat_js_namespaceObject = require("../../utils/metro-compat.js");
|
|
48
48
|
const create_module_path_remapper_js_namespaceObject = require("../utils/create-module-path-remapper.js");
|
|
49
49
|
const create_resolver_js_namespaceObject = require("../utils/create-resolver.js");
|
|
50
50
|
const load_metro_config_js_namespaceObject = require("../utils/load-metro-config.js");
|
|
51
51
|
var load_metro_config_js_default = /*#__PURE__*/ __webpack_require__.n(load_metro_config_js_namespaceObject);
|
|
52
|
+
const path_utils_js_namespaceObject = require("../utils/path-utils.js");
|
|
52
53
|
const save_bundle_and_map_js_namespaceObject = require("../utils/save-bundle-and-map.js");
|
|
54
|
+
const helpers_js_namespaceObject = require("../../plugin/helpers.js");
|
|
53
55
|
const external_options_js_namespaceObject = require("./options.js");
|
|
54
56
|
var external_options_js_default = /*#__PURE__*/ __webpack_require__.n(external_options_js_namespaceObject);
|
|
55
57
|
const DEFAULT_OUTPUT = 'dist';
|
|
@@ -142,9 +144,10 @@ async function bundleFederatedRemote(_argv, cfg, args) {
|
|
|
142
144
|
isContainerModule: true
|
|
143
145
|
}
|
|
144
146
|
};
|
|
147
|
+
const relativeContainerEntryPath = (0, helpers_js_namespaceObject.toPosixPath)(external_node_path_default().relative(config.projectRoot, containerEntryFilepath));
|
|
145
148
|
resolver.resolve({
|
|
146
149
|
from: config.projectRoot,
|
|
147
|
-
to: `./${
|
|
150
|
+
to: `./${relativeContainerEntryPath}`
|
|
148
151
|
});
|
|
149
152
|
const exposedModules = Object.entries(federationConfig.exposes).map(([moduleName, moduleFilepath])=>[
|
|
150
153
|
moduleName.slice(2),
|
|
@@ -176,11 +179,12 @@ async function bundleFederatedRemote(_argv, cfg, args) {
|
|
|
176
179
|
}).map(([moduleName, { moduleInputFilepath, moduleOutputDir, isContainerModule = false }])=>{
|
|
177
180
|
const moduleBundleName = isContainerModule ? moduleName : `${moduleName}.bundle`;
|
|
178
181
|
const moduleBundleFilepath = external_node_path_default().resolve(moduleOutputDir, moduleBundleName);
|
|
179
|
-
const
|
|
182
|
+
const relativeModuleBundlePath = (0, path_utils_js_namespaceObject.normalizeOutputRelativePath)(external_node_path_default().relative(outputDir, moduleBundleFilepath));
|
|
183
|
+
const moduleBundleUrl = (0, path_utils_js_namespaceObject.toFileSourceUrl)(relativeModuleBundlePath);
|
|
180
184
|
const moduleSourceMapName = `${moduleBundleName}.map`;
|
|
181
185
|
const moduleSourceMapFilepath = external_node_path_default().resolve(moduleOutputDir, moduleSourceMapName);
|
|
182
|
-
const moduleSourceMapUrl = external_node_path_default().relative(outputDir, moduleSourceMapFilepath);
|
|
183
|
-
if (!isContainerModule) modulePathRemapper.addMapping(moduleInputFilepath,
|
|
186
|
+
const moduleSourceMapUrl = (0, path_utils_js_namespaceObject.normalizeOutputRelativePath)(external_node_path_default().relative(outputDir, moduleSourceMapFilepath));
|
|
187
|
+
if (!isContainerModule) modulePathRemapper.addMapping(moduleInputFilepath, relativeModuleBundlePath);
|
|
184
188
|
return {
|
|
185
189
|
targetDir: external_node_path_default().dirname(moduleBundleFilepath),
|
|
186
190
|
requestOpts: getRequestOpts(args, {
|
|
@@ -205,9 +209,17 @@ async function bundleFederatedRemote(_argv, cfg, args) {
|
|
|
205
209
|
const bundle = await buildBundle(server, requestOpts);
|
|
206
210
|
await (0, save_bundle_and_map_js_namespaceObject.saveBundleAndMap)(bundle, saveBundleOpts, logger.info);
|
|
207
211
|
}
|
|
208
|
-
logger.info(`${external_node_util_default().styleText('blue', 'Processing manifest')}`);
|
|
209
212
|
const manifestOutputFilepath = external_node_path_default().resolve(outputDir, 'mf-manifest.json');
|
|
210
|
-
await
|
|
213
|
+
const typesMeta = await (0, federated_remote_types_js_namespaceObject.maybeGenerateFederatedRemoteTypes)({
|
|
214
|
+
federationConfig,
|
|
215
|
+
projectRoot: config.projectRoot,
|
|
216
|
+
outputDir,
|
|
217
|
+
logger
|
|
218
|
+
});
|
|
219
|
+
logger.info(`${external_node_util_default().styleText('blue', 'Processing manifest')}`);
|
|
220
|
+
const rawManifest = JSON.parse(await external_node_fs_namespaceObject.promises.readFile(manifestFilepath, 'utf-8'));
|
|
221
|
+
(0, federated_remote_types_js_namespaceObject.applyTypesMetaToManifest)(rawManifest, typesMeta);
|
|
222
|
+
await external_node_fs_namespaceObject.promises.writeFile(manifestOutputFilepath, JSON.stringify(rawManifest, void 0, 2), 'utf-8');
|
|
211
223
|
logger.info(`Done writing MF Manifest to:\n${external_node_util_default().styleText('dim', manifestOutputFilepath)}`);
|
|
212
224
|
} finally{
|
|
213
225
|
await server.end();
|
|
@@ -2,14 +2,16 @@ import 'module';
|
|
|
2
2
|
/*#__PURE__*/ import.meta.url;
|
|
3
3
|
import { promises } from "node:fs";
|
|
4
4
|
import node_path from "node:path";
|
|
5
|
-
import { pathToFileURL } from "node:url";
|
|
6
5
|
import node_util from "node:util";
|
|
7
6
|
import { CLIError } from "../../utils/errors.mjs";
|
|
7
|
+
import { applyTypesMetaToManifest, maybeGenerateFederatedRemoteTypes } from "../../utils/federated-remote-types.mjs";
|
|
8
8
|
import { Server } from "../../utils/metro-compat.mjs";
|
|
9
9
|
import { createModulePathRemapper } from "../utils/create-module-path-remapper.mjs";
|
|
10
10
|
import { createResolver } from "../utils/create-resolver.mjs";
|
|
11
11
|
import load_metro_config from "../utils/load-metro-config.mjs";
|
|
12
|
+
import { normalizeOutputRelativePath, toFileSourceUrl } from "../utils/path-utils.mjs";
|
|
12
13
|
import { saveBundleAndMap } from "../utils/save-bundle-and-map.mjs";
|
|
14
|
+
import { toPosixPath } from "../../plugin/helpers.mjs";
|
|
13
15
|
import options from "./options.mjs";
|
|
14
16
|
import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "node:module";
|
|
15
17
|
const external_metro_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("metro");
|
|
@@ -103,9 +105,10 @@ async function bundleFederatedRemote(_argv, cfg, args) {
|
|
|
103
105
|
isContainerModule: true
|
|
104
106
|
}
|
|
105
107
|
};
|
|
108
|
+
const relativeContainerEntryPath = toPosixPath(node_path.relative(config.projectRoot, containerEntryFilepath));
|
|
106
109
|
resolver.resolve({
|
|
107
110
|
from: config.projectRoot,
|
|
108
|
-
to: `./${
|
|
111
|
+
to: `./${relativeContainerEntryPath}`
|
|
109
112
|
});
|
|
110
113
|
const exposedModules = Object.entries(federationConfig.exposes).map(([moduleName, moduleFilepath])=>[
|
|
111
114
|
moduleName.slice(2),
|
|
@@ -137,11 +140,12 @@ async function bundleFederatedRemote(_argv, cfg, args) {
|
|
|
137
140
|
}).map(([moduleName, { moduleInputFilepath, moduleOutputDir, isContainerModule = false }])=>{
|
|
138
141
|
const moduleBundleName = isContainerModule ? moduleName : `${moduleName}.bundle`;
|
|
139
142
|
const moduleBundleFilepath = node_path.resolve(moduleOutputDir, moduleBundleName);
|
|
140
|
-
const
|
|
143
|
+
const relativeModuleBundlePath = normalizeOutputRelativePath(node_path.relative(outputDir, moduleBundleFilepath));
|
|
144
|
+
const moduleBundleUrl = toFileSourceUrl(relativeModuleBundlePath);
|
|
141
145
|
const moduleSourceMapName = `${moduleBundleName}.map`;
|
|
142
146
|
const moduleSourceMapFilepath = node_path.resolve(moduleOutputDir, moduleSourceMapName);
|
|
143
|
-
const moduleSourceMapUrl = node_path.relative(outputDir, moduleSourceMapFilepath);
|
|
144
|
-
if (!isContainerModule) modulePathRemapper.addMapping(moduleInputFilepath,
|
|
147
|
+
const moduleSourceMapUrl = normalizeOutputRelativePath(node_path.relative(outputDir, moduleSourceMapFilepath));
|
|
148
|
+
if (!isContainerModule) modulePathRemapper.addMapping(moduleInputFilepath, relativeModuleBundlePath);
|
|
145
149
|
return {
|
|
146
150
|
targetDir: node_path.dirname(moduleBundleFilepath),
|
|
147
151
|
requestOpts: getRequestOpts(args, {
|
|
@@ -166,9 +170,17 @@ async function bundleFederatedRemote(_argv, cfg, args) {
|
|
|
166
170
|
const bundle = await buildBundle(server, requestOpts);
|
|
167
171
|
await saveBundleAndMap(bundle, saveBundleOpts, logger.info);
|
|
168
172
|
}
|
|
169
|
-
logger.info(`${node_util.styleText('blue', 'Processing manifest')}`);
|
|
170
173
|
const manifestOutputFilepath = node_path.resolve(outputDir, 'mf-manifest.json');
|
|
171
|
-
await
|
|
174
|
+
const typesMeta = await maybeGenerateFederatedRemoteTypes({
|
|
175
|
+
federationConfig,
|
|
176
|
+
projectRoot: config.projectRoot,
|
|
177
|
+
outputDir,
|
|
178
|
+
logger
|
|
179
|
+
});
|
|
180
|
+
logger.info(`${node_util.styleText('blue', 'Processing manifest')}`);
|
|
181
|
+
const rawManifest = JSON.parse(await promises.readFile(manifestFilepath, 'utf-8'));
|
|
182
|
+
applyTypesMetaToManifest(rawManifest, typesMeta);
|
|
183
|
+
await promises.writeFile(manifestOutputFilepath, JSON.stringify(rawManifest, void 0, 2), 'utf-8');
|
|
172
184
|
logger.info(`Done writing MF Manifest to:\n${node_util.styleText('dim', manifestOutputFilepath)}`);
|
|
173
185
|
} finally{
|
|
174
186
|
await server.end();
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
normalizeOutputRelativePath: ()=>normalizeOutputRelativePath,
|
|
28
|
+
toFileSourceUrl: ()=>toFileSourceUrl
|
|
29
|
+
});
|
|
30
|
+
const external_node_url_namespaceObject = require("node:url");
|
|
31
|
+
const helpers_js_namespaceObject = require("../../plugin/helpers.js");
|
|
32
|
+
function normalizeOutputRelativePath(relativePath) {
|
|
33
|
+
return (0, helpers_js_namespaceObject.toPosixPath)(relativePath);
|
|
34
|
+
}
|
|
35
|
+
function toFileSourceUrl(relativePath) {
|
|
36
|
+
const normalizedRelativePath = normalizeOutputRelativePath(relativePath);
|
|
37
|
+
return (0, external_node_url_namespaceObject.pathToFileURL)(`/${normalizedRelativePath}`).href;
|
|
38
|
+
}
|
|
39
|
+
exports.normalizeOutputRelativePath = __webpack_exports__.normalizeOutputRelativePath;
|
|
40
|
+
exports.toFileSourceUrl = __webpack_exports__.toFileSourceUrl;
|
|
41
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
42
|
+
"normalizeOutputRelativePath",
|
|
43
|
+
"toFileSourceUrl"
|
|
44
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
45
|
+
Object.defineProperty(exports, '__esModule', {
|
|
46
|
+
value: true
|
|
47
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import 'module';
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { toPosixPath } from "../../plugin/helpers.mjs";
|
|
5
|
+
function normalizeOutputRelativePath(relativePath) {
|
|
6
|
+
return toPosixPath(relativePath);
|
|
7
|
+
}
|
|
8
|
+
function toFileSourceUrl(relativePath) {
|
|
9
|
+
const normalizedRelativePath = normalizeOutputRelativePath(relativePath);
|
|
10
|
+
return pathToFileURL(`/${normalizedRelativePath}`).href;
|
|
11
|
+
}
|
|
12
|
+
export { normalizeOutputRelativePath, toFileSourceUrl };
|
package/dist/logger.d.ts
ADDED
package/dist/logger.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
default: ()=>src_logger
|
|
28
|
+
});
|
|
29
|
+
const sdk_namespaceObject = require("@module-federation/sdk");
|
|
30
|
+
const constants_js_namespaceObject = require("./plugin/constants.js");
|
|
31
|
+
const logger = (0, sdk_namespaceObject.createLogger)(constants_js_namespaceObject.PLUGIN_IDENTIFIER);
|
|
32
|
+
const src_logger = logger;
|
|
33
|
+
exports["default"] = __webpack_exports__["default"];
|
|
34
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
35
|
+
"default"
|
|
36
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
37
|
+
Object.defineProperty(exports, '__esModule', {
|
|
38
|
+
value: true
|
|
39
|
+
});
|
package/dist/logger.mjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import 'module';
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
import { createLogger } from "@module-federation/sdk";
|
|
4
|
+
import { PLUGIN_IDENTIFIER } from "./plugin/constants.mjs";
|
|
5
|
+
const logger = createLogger(PLUGIN_IDENTIFIER);
|
|
6
|
+
const src_logger = logger;
|
|
7
|
+
export { src_logger as default };
|
|
@@ -65,7 +65,6 @@ function buildLoadBundleAsyncWrapper() {
|
|
|
65
65
|
const registry = require('mf:remote-module-registry');
|
|
66
66
|
|
|
67
67
|
const __loadBundleAsync =
|
|
68
|
-
// @ts-expect-error dynamic key access on global object
|
|
69
68
|
globalThis[`${__METRO_GLOBAL_PREFIX__ ?? ''}__loadBundleAsync`];
|
|
70
69
|
|
|
71
70
|
const loadBundleAsync =
|
|
@@ -125,10 +124,8 @@ if (!process.env.EXPO_OS) {
|
|
|
125
124
|
buildAsyncRequire,
|
|
126
125
|
} = require('@expo/metro-runtime/src/async-require/buildAsyncRequire');
|
|
127
126
|
|
|
128
|
-
// @ts-expect-error dynamic key access on global object
|
|
129
127
|
global[`${__METRO_GLOBAL_PREFIX__}__loadBundleAsync`] = buildAsyncRequire();
|
|
130
128
|
}
|
|
131
129
|
|
|
132
|
-
// @ts-expect-error dynamic key access on global object
|
|
133
130
|
global[`${__METRO_GLOBAL_PREFIX__}__loadBundleAsync`] =
|
|
134
131
|
buildLoadBundleAsyncWrapper();
|
|
@@ -2,6 +2,7 @@ import type { Federation } from '@module-federation/runtime';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
|
|
4
4
|
declare global {
|
|
5
|
+
// @ts-expect-error -- Intentional redeclaration for Metro/React Native runtime global.
|
|
5
6
|
// eslint-disable-next-line no-var
|
|
6
7
|
var __DEV__: boolean;
|
|
7
8
|
// eslint-disable-next-line no-var
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
Federation,
|
|
3
|
-
|
|
3
|
+
ModuleFederationRuntimePlugin,
|
|
4
4
|
} from '@module-federation/runtime';
|
|
5
5
|
|
|
6
6
|
declare global {
|
|
7
|
+
// @ts-expect-error -- Intentional redeclaration for Metro/React Native runtime global.
|
|
7
8
|
// eslint-disable-next-line no-var
|
|
8
9
|
var __DEV__: boolean;
|
|
9
10
|
// eslint-disable-next-line no-var
|
|
@@ -42,13 +43,12 @@ const buildUrlForEntryBundle = (entry: string) => {
|
|
|
42
43
|
return entry;
|
|
43
44
|
};
|
|
44
45
|
|
|
45
|
-
const MetroCorePlugin: () =>
|
|
46
|
+
const MetroCorePlugin: () => ModuleFederationRuntimePlugin = () => ({
|
|
46
47
|
name: 'metro-core-plugin',
|
|
47
48
|
loadEntry: async ({ remoteInfo }) => {
|
|
48
49
|
const { entry, entryGlobalName } = remoteInfo;
|
|
49
50
|
|
|
50
51
|
const __loadBundleAsync =
|
|
51
|
-
// @ts-expect-error dynamic key access on global object
|
|
52
52
|
globalThis[`${__METRO_GLOBAL_PREFIX__ ?? ''}__loadBundleAsync`];
|
|
53
53
|
|
|
54
54
|
const loadBundleAsync =
|
|
@@ -55,7 +55,7 @@ function createBabelTransformer({ blacklistedPaths, federationConfig, originalBa
|
|
|
55
55
|
enableInitializeCorePatching ? '@module-federation/metro/babel-plugin/patch-initialize-core' : void 0,
|
|
56
56
|
enableRuntimeRequirePatching ? '@module-federation/metro/babel-plugin/patch-require' : void 0
|
|
57
57
|
].filter(Boolean);
|
|
58
|
-
const babelTransformer = transformerTemplate.replaceAll('__BABEL_TRANSFORMER_PATH__', originalBabelTransformerPath).replaceAll('__BABEL_PLUGINS__', JSON.stringify(plugins));
|
|
58
|
+
const babelTransformer = transformerTemplate.replaceAll('__BABEL_TRANSFORMER_PATH__', JSON.stringify(originalBabelTransformerPath)).replaceAll('__BABEL_PLUGINS__', JSON.stringify(plugins));
|
|
59
59
|
external_node_fs_default().writeFileSync(outputPath, babelTransformer, 'utf-8');
|
|
60
60
|
return outputPath;
|
|
61
61
|
}
|
|
@@ -18,7 +18,7 @@ function createBabelTransformer({ blacklistedPaths, federationConfig, originalBa
|
|
|
18
18
|
enableInitializeCorePatching ? '@module-federation/metro/babel-plugin/patch-initialize-core' : void 0,
|
|
19
19
|
enableRuntimeRequirePatching ? '@module-federation/metro/babel-plugin/patch-require' : void 0
|
|
20
20
|
].filter(Boolean);
|
|
21
|
-
const babelTransformer = transformerTemplate.replaceAll('__BABEL_TRANSFORMER_PATH__', originalBabelTransformerPath).replaceAll('__BABEL_PLUGINS__', JSON.stringify(plugins));
|
|
21
|
+
const babelTransformer = transformerTemplate.replaceAll('__BABEL_TRANSFORMER_PATH__', JSON.stringify(originalBabelTransformerPath)).replaceAll('__BABEL_PLUGINS__', JSON.stringify(plugins));
|
|
22
22
|
node_fs.writeFileSync(outputPath, babelTransformer, 'utf-8');
|
|
23
23
|
return outputPath;
|
|
24
24
|
}
|
|
@@ -2,6 +2,7 @@ export declare const INIT_HOST = "mf:init-host";
|
|
|
2
2
|
export declare const ASYNC_REQUIRE = "mf:async-require";
|
|
3
3
|
export declare const REMOTE_MODULE_REGISTRY = "mf:remote-module-registry";
|
|
4
4
|
export declare const REMOTE_HMR_SETUP = "mf:remote-hmr";
|
|
5
|
+
export declare const PLUGIN_IDENTIFIER = "[ Module Federation Metro ]";
|
|
5
6
|
export declare const DEFAULT_ENTRY_FILENAME = "remoteEntry.bundle";
|
|
6
7
|
export declare const GET_DEV_SERVER_REGEX: RegExp;
|
|
7
8
|
export declare const HMR_CLIENT_REGEX: RegExp;
|
package/dist/plugin/constants.js
CHANGED
|
@@ -30,6 +30,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
30
30
|
HMR_CLIENT_REGEX: ()=>HMR_CLIENT_REGEX,
|
|
31
31
|
INIT_HOST: ()=>INIT_HOST,
|
|
32
32
|
MANIFEST_FILENAME: ()=>MANIFEST_FILENAME,
|
|
33
|
+
PLUGIN_IDENTIFIER: ()=>PLUGIN_IDENTIFIER,
|
|
33
34
|
REMOTE_HMR_SETUP: ()=>REMOTE_HMR_SETUP,
|
|
34
35
|
REMOTE_MODULE_REGISTRY: ()=>REMOTE_MODULE_REGISTRY,
|
|
35
36
|
TMP_DIR_NAME: ()=>TMP_DIR_NAME
|
|
@@ -38,6 +39,7 @@ const INIT_HOST = 'mf:init-host';
|
|
|
38
39
|
const ASYNC_REQUIRE = 'mf:async-require';
|
|
39
40
|
const REMOTE_MODULE_REGISTRY = 'mf:remote-module-registry';
|
|
40
41
|
const REMOTE_HMR_SETUP = 'mf:remote-hmr';
|
|
42
|
+
const PLUGIN_IDENTIFIER = '[ Module Federation Metro ]';
|
|
41
43
|
const DEFAULT_ENTRY_FILENAME = 'remoteEntry.bundle';
|
|
42
44
|
const GET_DEV_SERVER_REGEX = /react-native\/Libraries\/Core\/Devtools\/getDevServer\.js$/;
|
|
43
45
|
const HMR_CLIENT_REGEX = /react-native\/Libraries\/Utilities\/HMRClient\.js$/;
|
|
@@ -49,6 +51,7 @@ exports.GET_DEV_SERVER_REGEX = __webpack_exports__.GET_DEV_SERVER_REGEX;
|
|
|
49
51
|
exports.HMR_CLIENT_REGEX = __webpack_exports__.HMR_CLIENT_REGEX;
|
|
50
52
|
exports.INIT_HOST = __webpack_exports__.INIT_HOST;
|
|
51
53
|
exports.MANIFEST_FILENAME = __webpack_exports__.MANIFEST_FILENAME;
|
|
54
|
+
exports.PLUGIN_IDENTIFIER = __webpack_exports__.PLUGIN_IDENTIFIER;
|
|
52
55
|
exports.REMOTE_HMR_SETUP = __webpack_exports__.REMOTE_HMR_SETUP;
|
|
53
56
|
exports.REMOTE_MODULE_REGISTRY = __webpack_exports__.REMOTE_MODULE_REGISTRY;
|
|
54
57
|
exports.TMP_DIR_NAME = __webpack_exports__.TMP_DIR_NAME;
|
|
@@ -59,6 +62,7 @@ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
|
59
62
|
"HMR_CLIENT_REGEX",
|
|
60
63
|
"INIT_HOST",
|
|
61
64
|
"MANIFEST_FILENAME",
|
|
65
|
+
"PLUGIN_IDENTIFIER",
|
|
62
66
|
"REMOTE_HMR_SETUP",
|
|
63
67
|
"REMOTE_MODULE_REGISTRY",
|
|
64
68
|
"TMP_DIR_NAME"
|
|
@@ -4,9 +4,10 @@ const INIT_HOST = 'mf:init-host';
|
|
|
4
4
|
const ASYNC_REQUIRE = 'mf:async-require';
|
|
5
5
|
const REMOTE_MODULE_REGISTRY = 'mf:remote-module-registry';
|
|
6
6
|
const REMOTE_HMR_SETUP = 'mf:remote-hmr';
|
|
7
|
+
const PLUGIN_IDENTIFIER = '[ Module Federation Metro ]';
|
|
7
8
|
const DEFAULT_ENTRY_FILENAME = 'remoteEntry.bundle';
|
|
8
9
|
const GET_DEV_SERVER_REGEX = /react-native\/Libraries\/Core\/Devtools\/getDevServer\.js$/;
|
|
9
10
|
const HMR_CLIENT_REGEX = /react-native\/Libraries\/Utilities\/HMRClient\.js$/;
|
|
10
11
|
const TMP_DIR_NAME = '.mf-metro';
|
|
11
12
|
const MANIFEST_FILENAME = 'mf-manifest.json';
|
|
12
|
-
export { ASYNC_REQUIRE, DEFAULT_ENTRY_FILENAME, GET_DEV_SERVER_REGEX, HMR_CLIENT_REGEX, INIT_HOST, MANIFEST_FILENAME, REMOTE_HMR_SETUP, REMOTE_MODULE_REGISTRY, TMP_DIR_NAME };
|
|
13
|
+
export { ASYNC_REQUIRE, DEFAULT_ENTRY_FILENAME, GET_DEV_SERVER_REGEX, HMR_CLIENT_REGEX, INIT_HOST, MANIFEST_FILENAME, PLUGIN_IDENTIFIER, REMOTE_HMR_SETUP, REMOTE_MODULE_REGISTRY, TMP_DIR_NAME };
|
|
@@ -44,13 +44,15 @@ const external_node_fs_namespaceObject = require("node:fs");
|
|
|
44
44
|
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
45
45
|
const external_node_path_namespaceObject = require("node:path");
|
|
46
46
|
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
47
|
+
const external_helpers_js_namespaceObject = require("./helpers.js");
|
|
47
48
|
function getRemoteModule(name) {
|
|
48
49
|
const template = getModuleTemplate('remote-module.js');
|
|
49
50
|
return template.replaceAll('__MODULE_ID__', `"${name}"`);
|
|
50
51
|
}
|
|
51
52
|
function getHostEntryModule(_, paths) {
|
|
52
53
|
const template = getModuleTemplate('host-entry.js');
|
|
53
|
-
|
|
54
|
+
const relativeEntryPath = (0, external_helpers_js_namespaceObject.toPosixPath)(external_node_path_default().relative(paths.tmpDir, paths.originalEntry));
|
|
55
|
+
return template.replaceAll('__ENTRYPOINT_IMPORT__', `import './${relativeEntryPath}'`);
|
|
54
56
|
}
|
|
55
57
|
function getInitHostModule(options) {
|
|
56
58
|
const template = getModuleTemplate('init-host.js');
|
|
@@ -71,7 +73,7 @@ function getRemoteHMRSetupModule() {
|
|
|
71
73
|
function generateExposes(exposes, paths) {
|
|
72
74
|
const exposesString = Object.keys(exposes).map((key)=>{
|
|
73
75
|
const importPath = external_node_path_default().join(paths.projectDir, exposes[key]);
|
|
74
|
-
const relativeImportPath = external_node_path_default().relative(paths.tmpDir, importPath);
|
|
76
|
+
const relativeImportPath = (0, external_helpers_js_namespaceObject.toPosixPath)(external_node_path_default().relative(paths.tmpDir, importPath));
|
|
75
77
|
return `"${key}": async () => import("${relativeImportPath}")`;
|
|
76
78
|
});
|
|
77
79
|
return `{${exposesString.join(',')}}`;
|
|
@@ -82,7 +84,8 @@ function generateRuntimePlugins(runtimePlugins) {
|
|
|
82
84
|
runtimePlugins.forEach((plugin, index)=>{
|
|
83
85
|
const pluginName = `plugin${index}`;
|
|
84
86
|
pluginNames.push(`${pluginName}()`);
|
|
85
|
-
|
|
87
|
+
const pluginPath = (0, external_helpers_js_namespaceObject.toPosixPath)(plugin);
|
|
88
|
+
pluginImports.push(`import ${pluginName} from "${pluginPath}";`);
|
|
86
89
|
});
|
|
87
90
|
const imports = pluginImports.join('\n');
|
|
88
91
|
const plugins = `const plugins = [${pluginNames.join(', ')}];`;
|
|
@@ -2,13 +2,15 @@ import __rslib_shim_module__ from 'module';
|
|
|
2
2
|
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
|
|
3
3
|
import node_fs from "node:fs";
|
|
4
4
|
import node_path from "node:path";
|
|
5
|
+
import { toPosixPath } from "./helpers.mjs";
|
|
5
6
|
function getRemoteModule(name) {
|
|
6
7
|
const template = getModuleTemplate('remote-module.js');
|
|
7
8
|
return template.replaceAll('__MODULE_ID__', `"${name}"`);
|
|
8
9
|
}
|
|
9
10
|
function getHostEntryModule(_, paths) {
|
|
10
11
|
const template = getModuleTemplate('host-entry.js');
|
|
11
|
-
|
|
12
|
+
const relativeEntryPath = toPosixPath(node_path.relative(paths.tmpDir, paths.originalEntry));
|
|
13
|
+
return template.replaceAll('__ENTRYPOINT_IMPORT__', `import './${relativeEntryPath}'`);
|
|
12
14
|
}
|
|
13
15
|
function getInitHostModule(options) {
|
|
14
16
|
const template = getModuleTemplate('init-host.js');
|
|
@@ -29,7 +31,7 @@ function getRemoteHMRSetupModule() {
|
|
|
29
31
|
function generateExposes(exposes, paths) {
|
|
30
32
|
const exposesString = Object.keys(exposes).map((key)=>{
|
|
31
33
|
const importPath = node_path.join(paths.projectDir, exposes[key]);
|
|
32
|
-
const relativeImportPath = node_path.relative(paths.tmpDir, importPath);
|
|
34
|
+
const relativeImportPath = toPosixPath(node_path.relative(paths.tmpDir, importPath));
|
|
33
35
|
return `"${key}": async () => import("${relativeImportPath}")`;
|
|
34
36
|
});
|
|
35
37
|
return `{${exposesString.join(',')}}`;
|
|
@@ -40,7 +42,8 @@ function generateRuntimePlugins(runtimePlugins) {
|
|
|
40
42
|
runtimePlugins.forEach((plugin, index)=>{
|
|
41
43
|
const pluginName = `plugin${index}`;
|
|
42
44
|
pluginNames.push(`${pluginName}()`);
|
|
43
|
-
|
|
45
|
+
const pluginPath = toPosixPath(plugin);
|
|
46
|
+
pluginImports.push(`import ${pluginName} from "${pluginPath}";`);
|
|
44
47
|
});
|
|
45
48
|
const imports = pluginImports.join('\n');
|
|
46
49
|
const plugins = `const plugins = [${pluginNames.join(', ')}];`;
|
package/dist/plugin/helpers.d.ts
CHANGED
|
@@ -5,3 +5,4 @@ export declare function removeExtension(filepath: string): string;
|
|
|
5
5
|
export declare function stubHostEntry(hostEntryPath: string): void;
|
|
6
6
|
export declare function stubRemoteEntry(remoteEntryPath: string): void;
|
|
7
7
|
export declare function prepareTmpDir(projectRootPath: string): string;
|
|
8
|
+
export declare function toPosixPath(value: string): string;
|
package/dist/plugin/helpers.js
CHANGED
|
@@ -33,13 +33,14 @@ var __webpack_require__ = {};
|
|
|
33
33
|
var __webpack_exports__ = {};
|
|
34
34
|
__webpack_require__.r(__webpack_exports__);
|
|
35
35
|
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
-
stubHostEntry: ()=>stubHostEntry,
|
|
37
36
|
stubRemoteEntry: ()=>stubRemoteEntry,
|
|
38
|
-
isUsingMFCommand: ()=>isUsingMFCommand,
|
|
39
|
-
isUsingMFBundleCommand: ()=>isUsingMFBundleCommand,
|
|
40
37
|
removeExtension: ()=>removeExtension,
|
|
38
|
+
replaceExtension: ()=>replaceExtension,
|
|
41
39
|
prepareTmpDir: ()=>prepareTmpDir,
|
|
42
|
-
|
|
40
|
+
toPosixPath: ()=>toPosixPath,
|
|
41
|
+
isUsingMFCommand: ()=>isUsingMFCommand,
|
|
42
|
+
stubHostEntry: ()=>stubHostEntry,
|
|
43
|
+
isUsingMFBundleCommand: ()=>isUsingMFBundleCommand
|
|
43
44
|
});
|
|
44
45
|
const external_node_fs_namespaceObject = require("node:fs");
|
|
45
46
|
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
@@ -98,6 +99,9 @@ function prepareTmpDir(projectRootPath) {
|
|
|
98
99
|
});
|
|
99
100
|
return tmpDirPath;
|
|
100
101
|
}
|
|
102
|
+
function toPosixPath(value) {
|
|
103
|
+
return value.replaceAll('\\', '/');
|
|
104
|
+
}
|
|
101
105
|
exports.isUsingMFBundleCommand = __webpack_exports__.isUsingMFBundleCommand;
|
|
102
106
|
exports.isUsingMFCommand = __webpack_exports__.isUsingMFCommand;
|
|
103
107
|
exports.prepareTmpDir = __webpack_exports__.prepareTmpDir;
|
|
@@ -105,6 +109,7 @@ exports.removeExtension = __webpack_exports__.removeExtension;
|
|
|
105
109
|
exports.replaceExtension = __webpack_exports__.replaceExtension;
|
|
106
110
|
exports.stubHostEntry = __webpack_exports__.stubHostEntry;
|
|
107
111
|
exports.stubRemoteEntry = __webpack_exports__.stubRemoteEntry;
|
|
112
|
+
exports.toPosixPath = __webpack_exports__.toPosixPath;
|
|
108
113
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
109
114
|
"isUsingMFBundleCommand",
|
|
110
115
|
"isUsingMFCommand",
|
|
@@ -112,7 +117,8 @@ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
|
112
117
|
"removeExtension",
|
|
113
118
|
"replaceExtension",
|
|
114
119
|
"stubHostEntry",
|
|
115
|
-
"stubRemoteEntry"
|
|
120
|
+
"stubRemoteEntry",
|
|
121
|
+
"toPosixPath"
|
|
116
122
|
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
117
123
|
Object.defineProperty(exports, '__esModule', {
|
|
118
124
|
value: true
|
package/dist/plugin/helpers.mjs
CHANGED
|
@@ -55,4 +55,7 @@ function prepareTmpDir(projectRootPath) {
|
|
|
55
55
|
});
|
|
56
56
|
return tmpDirPath;
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
function toPosixPath(value) {
|
|
59
|
+
return value.replaceAll('\\', '/');
|
|
60
|
+
}
|
|
61
|
+
export { isUsingMFBundleCommand, isUsingMFCommand, prepareTmpDir, removeExtension, replaceExtension, stubHostEntry, stubRemoteEntry, toPosixPath };
|
package/dist/plugin/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { ConfigT } from 'metro-config';
|
|
2
2
|
import type { ModuleFederationConfig, ModuleFederationConfigNormalized, ModuleFederationExtraOptions } from '../types';
|
|
3
|
+
import type { FederatedTypesMeta } from '../utils/federated-remote-types';
|
|
3
4
|
declare global {
|
|
4
5
|
var __METRO_FEDERATION_CONFIG: ModuleFederationConfigNormalized;
|
|
5
6
|
var __METRO_FEDERATION_ORIGINAL_ENTRY_PATH: string | undefined;
|
|
6
7
|
var __METRO_FEDERATION_REMOTE_ENTRY_PATH: string | undefined;
|
|
7
8
|
var __METRO_FEDERATION_MANIFEST_PATH: string | undefined;
|
|
9
|
+
var __METRO_FEDERATION_DTS_ASSETS: FederatedTypesMeta | undefined;
|
|
8
10
|
}
|
|
9
11
|
export declare function withModuleFederation(config: ConfigT, federationOptions: ModuleFederationConfig, extraOptions?: ModuleFederationExtraOptions): ConfigT;
|