@module-federation/metro 2.0.0 → 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 +5 -4
- package/dist/commands/bundle-host/index.mjs +5 -26
- package/dist/commands/bundle-remote/index.js +22 -11
- package/dist/commands/bundle-remote/index.mjs +22 -32
- package/dist/commands/utils/create-resolver.d.ts +1 -1
- package/dist/commands/utils/get-community-plugin.d.ts +1 -2
- package/dist/commands/utils/get-community-plugin.js +3 -4
- package/dist/commands/utils/get-community-plugin.mjs +3 -4
- 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/commands/utils/save-bundle-and-map.d.ts +1 -1
- package/dist/commands/utils/save-bundle-and-map.js +2 -3
- package/dist/commands/utils/save-bundle-and-map.mjs +2 -25
- 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 +24 -9
- package/dist/plugin/serializer.mjs +24 -31
- 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/dist/utils/metro-compat.d.ts +23 -0
- package/dist/utils/metro-compat.js +70 -0
- package/dist/utils/metro-compat.mjs +26 -0
- package/dist/utils/vm-manager.d.ts +1 -1
- 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
|
@@ -40,14 +40,14 @@ const external_node_path_namespaceObject = require("node:path");
|
|
|
40
40
|
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
41
41
|
const external_node_util_namespaceObject = require("node:util");
|
|
42
42
|
var external_node_util_default = /*#__PURE__*/ __webpack_require__.n(external_node_util_namespaceObject);
|
|
43
|
-
const Server_namespaceObject = require("metro/src/Server");
|
|
44
|
-
var Server_default = /*#__PURE__*/ __webpack_require__.n(Server_namespaceObject);
|
|
45
43
|
const errors_js_namespaceObject = require("../../utils/errors.js");
|
|
44
|
+
const metro_compat_js_namespaceObject = require("../../utils/metro-compat.js");
|
|
46
45
|
const create_resolver_js_namespaceObject = require("../utils/create-resolver.js");
|
|
47
46
|
const get_community_plugin_js_namespaceObject = require("../utils/get-community-plugin.js");
|
|
48
47
|
const load_metro_config_js_namespaceObject = require("../utils/load-metro-config.js");
|
|
49
48
|
var load_metro_config_js_default = /*#__PURE__*/ __webpack_require__.n(load_metro_config_js_namespaceObject);
|
|
50
49
|
const save_bundle_and_map_js_namespaceObject = require("../utils/save-bundle-and-map.js");
|
|
50
|
+
const helpers_js_namespaceObject = require("../../plugin/helpers.js");
|
|
51
51
|
const external_options_js_namespaceObject = require("./options.js");
|
|
52
52
|
var external_options_js_default = /*#__PURE__*/ __webpack_require__.n(external_options_js_namespaceObject);
|
|
53
53
|
async function bundleFederatedHost(_argv, cfg, args) {
|
|
@@ -70,12 +70,13 @@ async function bundleFederatedHost(_argv, cfg, args) {
|
|
|
70
70
|
build: async (server, requestOpts)=>{
|
|
71
71
|
config.server.enhanceMiddleware(server.processRequest, server);
|
|
72
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));
|
|
73
74
|
resolver.resolve({
|
|
74
75
|
from: config.projectRoot,
|
|
75
|
-
to: `./${
|
|
76
|
+
to: `./${relativeHostEntryPath}`
|
|
76
77
|
});
|
|
77
78
|
return server.build({
|
|
78
|
-
...
|
|
79
|
+
...metro_compat_js_namespaceObject.Server.DEFAULT_BUNDLE_OPTIONS,
|
|
79
80
|
...requestOpts
|
|
80
81
|
});
|
|
81
82
|
},
|
|
@@ -3,35 +3,13 @@ import 'module';
|
|
|
3
3
|
import node_path from "node:path";
|
|
4
4
|
import node_util from "node:util";
|
|
5
5
|
import { CLIError } from "../../utils/errors.mjs";
|
|
6
|
+
import { Server } from "../../utils/metro-compat.mjs";
|
|
6
7
|
import { createResolver } from "../utils/create-resolver.mjs";
|
|
7
8
|
import { getCommunityCliPlugin } from "../utils/get-community-plugin.mjs";
|
|
8
9
|
import load_metro_config from "../utils/load-metro-config.mjs";
|
|
9
10
|
import { saveBundleAndMap } from "../utils/save-bundle-and-map.mjs";
|
|
11
|
+
import { toPosixPath } from "../../plugin/helpers.mjs";
|
|
10
12
|
import options from "./options.mjs";
|
|
11
|
-
import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "node:module";
|
|
12
|
-
var __webpack_require__ = {};
|
|
13
|
-
(()=>{
|
|
14
|
-
__webpack_require__.n = (module)=>{
|
|
15
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
16
|
-
__webpack_require__.d(getter, {
|
|
17
|
-
a: getter
|
|
18
|
-
});
|
|
19
|
-
return getter;
|
|
20
|
-
};
|
|
21
|
-
})();
|
|
22
|
-
(()=>{
|
|
23
|
-
__webpack_require__.d = (exports, definition)=>{
|
|
24
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: definition[key]
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
})();
|
|
30
|
-
(()=>{
|
|
31
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
32
|
-
})();
|
|
33
|
-
const Server_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("metro/src/Server");
|
|
34
|
-
var Server_default = /*#__PURE__*/ __webpack_require__.n(Server_namespaceObject);
|
|
35
13
|
async function bundleFederatedHost(_argv, cfg, args) {
|
|
36
14
|
const logger = cfg.logger ?? console;
|
|
37
15
|
global.__METRO_FEDERATION_ORIGINAL_ENTRY_PATH = args.entryFile;
|
|
@@ -52,12 +30,13 @@ async function bundleFederatedHost(_argv, cfg, args) {
|
|
|
52
30
|
build: async (server, requestOpts)=>{
|
|
53
31
|
config.server.enhanceMiddleware(server.processRequest, server);
|
|
54
32
|
const resolver = await createResolver(server, args.platform);
|
|
33
|
+
const relativeHostEntryPath = toPosixPath(node_path.relative(config.projectRoot, hostEntryFilepath));
|
|
55
34
|
resolver.resolve({
|
|
56
35
|
from: config.projectRoot,
|
|
57
|
-
to: `./${
|
|
36
|
+
to: `./${relativeHostEntryPath}`
|
|
58
37
|
});
|
|
59
38
|
return server.build({
|
|
60
|
-
...
|
|
39
|
+
...Server.DEFAULT_BUNDLE_OPTIONS,
|
|
61
40
|
...requestOpts
|
|
62
41
|
});
|
|
63
42
|
},
|
|
@@ -39,24 +39,25 @@ __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
|
-
const Server_namespaceObject = require("metro/src/Server");
|
|
47
|
-
var Server_default = /*#__PURE__*/ __webpack_require__.n(Server_namespaceObject);
|
|
48
45
|
const errors_js_namespaceObject = require("../../utils/errors.js");
|
|
46
|
+
const federated_remote_types_js_namespaceObject = require("../../utils/federated-remote-types.js");
|
|
47
|
+
const metro_compat_js_namespaceObject = require("../../utils/metro-compat.js");
|
|
49
48
|
const create_module_path_remapper_js_namespaceObject = require("../utils/create-module-path-remapper.js");
|
|
50
49
|
const create_resolver_js_namespaceObject = require("../utils/create-resolver.js");
|
|
51
50
|
const load_metro_config_js_namespaceObject = require("../utils/load-metro-config.js");
|
|
52
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");
|
|
53
53
|
const save_bundle_and_map_js_namespaceObject = require("../utils/save-bundle-and-map.js");
|
|
54
|
+
const helpers_js_namespaceObject = require("../../plugin/helpers.js");
|
|
54
55
|
const external_options_js_namespaceObject = require("./options.js");
|
|
55
56
|
var external_options_js_default = /*#__PURE__*/ __webpack_require__.n(external_options_js_namespaceObject);
|
|
56
57
|
const DEFAULT_OUTPUT = 'dist';
|
|
57
58
|
async function buildBundle(server, requestOpts) {
|
|
58
59
|
const bundle = await server.build({
|
|
59
|
-
...
|
|
60
|
+
...metro_compat_js_namespaceObject.Server.DEFAULT_BUNDLE_OPTIONS,
|
|
60
61
|
...requestOpts
|
|
61
62
|
});
|
|
62
63
|
return bundle;
|
|
@@ -132,7 +133,7 @@ async function bundleFederatedRemote(_argv, cfg, args) {
|
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
135
|
});
|
|
135
|
-
const server = new (
|
|
136
|
+
const server = new metro_compat_js_namespaceObject.Server(config);
|
|
136
137
|
config.server.enhanceMiddleware(server.processRequest, server);
|
|
137
138
|
const resolver = await (0, create_resolver_js_namespaceObject.createResolver)(server, args.platform);
|
|
138
139
|
const outputDir = args.output ? external_node_path_default().resolve(external_node_path_default().join(args.output, args.platform)) : external_node_path_default().resolve(config.projectRoot, external_node_path_default().join(DEFAULT_OUTPUT, args.platform));
|
|
@@ -143,9 +144,10 @@ async function bundleFederatedRemote(_argv, cfg, args) {
|
|
|
143
144
|
isContainerModule: true
|
|
144
145
|
}
|
|
145
146
|
};
|
|
147
|
+
const relativeContainerEntryPath = (0, helpers_js_namespaceObject.toPosixPath)(external_node_path_default().relative(config.projectRoot, containerEntryFilepath));
|
|
146
148
|
resolver.resolve({
|
|
147
149
|
from: config.projectRoot,
|
|
148
|
-
to: `./${
|
|
150
|
+
to: `./${relativeContainerEntryPath}`
|
|
149
151
|
});
|
|
150
152
|
const exposedModules = Object.entries(federationConfig.exposes).map(([moduleName, moduleFilepath])=>[
|
|
151
153
|
moduleName.slice(2),
|
|
@@ -177,11 +179,12 @@ async function bundleFederatedRemote(_argv, cfg, args) {
|
|
|
177
179
|
}).map(([moduleName, { moduleInputFilepath, moduleOutputDir, isContainerModule = false }])=>{
|
|
178
180
|
const moduleBundleName = isContainerModule ? moduleName : `${moduleName}.bundle`;
|
|
179
181
|
const moduleBundleFilepath = external_node_path_default().resolve(moduleOutputDir, moduleBundleName);
|
|
180
|
-
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);
|
|
181
184
|
const moduleSourceMapName = `${moduleBundleName}.map`;
|
|
182
185
|
const moduleSourceMapFilepath = external_node_path_default().resolve(moduleOutputDir, moduleSourceMapName);
|
|
183
|
-
const moduleSourceMapUrl = external_node_path_default().relative(outputDir, moduleSourceMapFilepath);
|
|
184
|
-
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);
|
|
185
188
|
return {
|
|
186
189
|
targetDir: external_node_path_default().dirname(moduleBundleFilepath),
|
|
187
190
|
requestOpts: getRequestOpts(args, {
|
|
@@ -206,9 +209,17 @@ async function bundleFederatedRemote(_argv, cfg, args) {
|
|
|
206
209
|
const bundle = await buildBundle(server, requestOpts);
|
|
207
210
|
await (0, save_bundle_and_map_js_namespaceObject.saveBundleAndMap)(bundle, saveBundleOpts, logger.info);
|
|
208
211
|
}
|
|
209
|
-
logger.info(`${external_node_util_default().styleText('blue', 'Processing manifest')}`);
|
|
210
212
|
const manifestOutputFilepath = external_node_path_default().resolve(outputDir, 'mf-manifest.json');
|
|
211
|
-
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');
|
|
212
223
|
logger.info(`Done writing MF Manifest to:\n${external_node_util_default().styleText('dim', manifestOutputFilepath)}`);
|
|
213
224
|
} finally{
|
|
214
225
|
await server.end();
|
|
@@ -2,43 +2,23 @@ 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
|
+
import { Server } from "../../utils/metro-compat.mjs";
|
|
8
9
|
import { createModulePathRemapper } from "../utils/create-module-path-remapper.mjs";
|
|
9
10
|
import { createResolver } from "../utils/create-resolver.mjs";
|
|
10
11
|
import load_metro_config from "../utils/load-metro-config.mjs";
|
|
12
|
+
import { normalizeOutputRelativePath, toFileSourceUrl } from "../utils/path-utils.mjs";
|
|
11
13
|
import { saveBundleAndMap } from "../utils/save-bundle-and-map.mjs";
|
|
14
|
+
import { toPosixPath } from "../../plugin/helpers.mjs";
|
|
12
15
|
import options from "./options.mjs";
|
|
13
16
|
import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "node:module";
|
|
14
|
-
var __webpack_require__ = {};
|
|
15
|
-
(()=>{
|
|
16
|
-
__webpack_require__.n = (module)=>{
|
|
17
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
18
|
-
__webpack_require__.d(getter, {
|
|
19
|
-
a: getter
|
|
20
|
-
});
|
|
21
|
-
return getter;
|
|
22
|
-
};
|
|
23
|
-
})();
|
|
24
|
-
(()=>{
|
|
25
|
-
__webpack_require__.d = (exports, definition)=>{
|
|
26
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
|
|
27
|
-
enumerable: true,
|
|
28
|
-
get: definition[key]
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
})();
|
|
32
|
-
(()=>{
|
|
33
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
34
|
-
})();
|
|
35
17
|
const external_metro_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("metro");
|
|
36
|
-
const Server_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("metro/src/Server");
|
|
37
|
-
var Server_default = /*#__PURE__*/ __webpack_require__.n(Server_namespaceObject);
|
|
38
18
|
const DEFAULT_OUTPUT = 'dist';
|
|
39
19
|
async function buildBundle(server, requestOpts) {
|
|
40
20
|
const bundle = await server.build({
|
|
41
|
-
...
|
|
21
|
+
...Server.DEFAULT_BUNDLE_OPTIONS,
|
|
42
22
|
...requestOpts
|
|
43
23
|
});
|
|
44
24
|
return bundle;
|
|
@@ -114,7 +94,7 @@ async function bundleFederatedRemote(_argv, cfg, args) {
|
|
|
114
94
|
}
|
|
115
95
|
}
|
|
116
96
|
});
|
|
117
|
-
const server = new (
|
|
97
|
+
const server = new Server(config);
|
|
118
98
|
config.server.enhanceMiddleware(server.processRequest, server);
|
|
119
99
|
const resolver = await createResolver(server, args.platform);
|
|
120
100
|
const outputDir = args.output ? node_path.resolve(node_path.join(args.output, args.platform)) : node_path.resolve(config.projectRoot, node_path.join(DEFAULT_OUTPUT, args.platform));
|
|
@@ -125,9 +105,10 @@ async function bundleFederatedRemote(_argv, cfg, args) {
|
|
|
125
105
|
isContainerModule: true
|
|
126
106
|
}
|
|
127
107
|
};
|
|
108
|
+
const relativeContainerEntryPath = toPosixPath(node_path.relative(config.projectRoot, containerEntryFilepath));
|
|
128
109
|
resolver.resolve({
|
|
129
110
|
from: config.projectRoot,
|
|
130
|
-
to: `./${
|
|
111
|
+
to: `./${relativeContainerEntryPath}`
|
|
131
112
|
});
|
|
132
113
|
const exposedModules = Object.entries(federationConfig.exposes).map(([moduleName, moduleFilepath])=>[
|
|
133
114
|
moduleName.slice(2),
|
|
@@ -159,11 +140,12 @@ async function bundleFederatedRemote(_argv, cfg, args) {
|
|
|
159
140
|
}).map(([moduleName, { moduleInputFilepath, moduleOutputDir, isContainerModule = false }])=>{
|
|
160
141
|
const moduleBundleName = isContainerModule ? moduleName : `${moduleName}.bundle`;
|
|
161
142
|
const moduleBundleFilepath = node_path.resolve(moduleOutputDir, moduleBundleName);
|
|
162
|
-
const
|
|
143
|
+
const relativeModuleBundlePath = normalizeOutputRelativePath(node_path.relative(outputDir, moduleBundleFilepath));
|
|
144
|
+
const moduleBundleUrl = toFileSourceUrl(relativeModuleBundlePath);
|
|
163
145
|
const moduleSourceMapName = `${moduleBundleName}.map`;
|
|
164
146
|
const moduleSourceMapFilepath = node_path.resolve(moduleOutputDir, moduleSourceMapName);
|
|
165
|
-
const moduleSourceMapUrl = node_path.relative(outputDir, moduleSourceMapFilepath);
|
|
166
|
-
if (!isContainerModule) modulePathRemapper.addMapping(moduleInputFilepath,
|
|
147
|
+
const moduleSourceMapUrl = normalizeOutputRelativePath(node_path.relative(outputDir, moduleSourceMapFilepath));
|
|
148
|
+
if (!isContainerModule) modulePathRemapper.addMapping(moduleInputFilepath, relativeModuleBundlePath);
|
|
167
149
|
return {
|
|
168
150
|
targetDir: node_path.dirname(moduleBundleFilepath),
|
|
169
151
|
requestOpts: getRequestOpts(args, {
|
|
@@ -188,9 +170,17 @@ async function bundleFederatedRemote(_argv, cfg, args) {
|
|
|
188
170
|
const bundle = await buildBundle(server, requestOpts);
|
|
189
171
|
await saveBundleAndMap(bundle, saveBundleOpts, logger.info);
|
|
190
172
|
}
|
|
191
|
-
logger.info(`${node_util.styleText('blue', 'Processing manifest')}`);
|
|
192
173
|
const manifestOutputFilepath = node_path.resolve(outputDir, 'mf-manifest.json');
|
|
193
|
-
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');
|
|
194
184
|
logger.info(`Done writing MF Manifest to:\n${node_util.styleText('dim', manifestOutputFilepath)}`);
|
|
195
185
|
} finally{
|
|
196
186
|
await server.end();
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { ConfigT } from 'metro-config';
|
|
2
|
-
import type Server from 'metro
|
|
3
|
-
import type { OutputOptions, RequestOptions } from 'metro/src/shared/types';
|
|
2
|
+
import type { OutputOptions, RequestOptions, Server } from '../../utils/metro-compat';
|
|
4
3
|
interface Command {
|
|
5
4
|
name: string;
|
|
6
5
|
description: string;
|
|
@@ -28,18 +28,17 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
28
28
|
});
|
|
29
29
|
const errors_js_namespaceObject = require("../../utils/errors.js");
|
|
30
30
|
function getCommunityCliPlugin(reactNativePath) {
|
|
31
|
-
let
|
|
31
|
+
let communityCliPluginPath;
|
|
32
32
|
try {
|
|
33
|
-
|
|
33
|
+
communityCliPluginPath = require.resolve('@react-native/community-cli-plugin', {
|
|
34
34
|
paths: [
|
|
35
35
|
reactNativePath ?? require.resolve('react-native')
|
|
36
36
|
]
|
|
37
37
|
});
|
|
38
|
-
communityCliPlugin = require(communityCliPluginPath);
|
|
39
38
|
} catch {
|
|
40
39
|
throw new errors_js_namespaceObject.CLIError('Community CLI plugin is not installed.');
|
|
41
40
|
}
|
|
42
|
-
return
|
|
41
|
+
return require(communityCliPluginPath);
|
|
43
42
|
}
|
|
44
43
|
exports.getCommunityCliPlugin = __webpack_exports__.getCommunityCliPlugin;
|
|
45
44
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
@@ -2,17 +2,16 @@ import __rslib_shim_module__ from 'module';
|
|
|
2
2
|
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
|
|
3
3
|
import { CLIError } from "../../utils/errors.mjs";
|
|
4
4
|
function getCommunityCliPlugin(reactNativePath) {
|
|
5
|
-
let
|
|
5
|
+
let communityCliPluginPath;
|
|
6
6
|
try {
|
|
7
|
-
|
|
7
|
+
communityCliPluginPath = require.resolve('@react-native/community-cli-plugin', {
|
|
8
8
|
paths: [
|
|
9
9
|
reactNativePath ?? require.resolve('react-native')
|
|
10
10
|
]
|
|
11
11
|
});
|
|
12
|
-
communityCliPlugin = require(communityCliPluginPath);
|
|
13
12
|
} catch {
|
|
14
13
|
throw new CLIError('Community CLI plugin is not installed.');
|
|
15
14
|
}
|
|
16
|
-
return
|
|
15
|
+
return require(communityCliPluginPath);
|
|
17
16
|
}
|
|
18
17
|
export { getCommunityCliPlugin };
|
|
@@ -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 };
|
|
@@ -38,11 +38,10 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
38
38
|
const external_node_fs_namespaceObject = require("node:fs");
|
|
39
39
|
const external_node_util_namespaceObject = require("node:util");
|
|
40
40
|
var external_node_util_default = /*#__PURE__*/ __webpack_require__.n(external_node_util_namespaceObject);
|
|
41
|
-
const
|
|
42
|
-
var relativizeSourceMap_default = /*#__PURE__*/ __webpack_require__.n(relativizeSourceMap_namespaceObject);
|
|
41
|
+
const metro_compat_js_namespaceObject = require("../../utils/metro-compat.js");
|
|
43
42
|
function relativizeSerializedMap(map, sourceMapSourcesRoot) {
|
|
44
43
|
const sourceMap = JSON.parse(map);
|
|
45
|
-
|
|
44
|
+
(0, metro_compat_js_namespaceObject.relativizeSourceMapInline)(sourceMap, sourceMapSourcesRoot);
|
|
46
45
|
return JSON.stringify(sourceMap);
|
|
47
46
|
}
|
|
48
47
|
async function saveBundleAndMap(bundle, options, log) {
|
|
@@ -2,33 +2,10 @@ import 'module';
|
|
|
2
2
|
/*#__PURE__*/ import.meta.url;
|
|
3
3
|
import { promises } from "node:fs";
|
|
4
4
|
import node_util from "node:util";
|
|
5
|
-
import {
|
|
6
|
-
var __webpack_require__ = {};
|
|
7
|
-
(()=>{
|
|
8
|
-
__webpack_require__.n = (module)=>{
|
|
9
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
10
|
-
__webpack_require__.d(getter, {
|
|
11
|
-
a: getter
|
|
12
|
-
});
|
|
13
|
-
return getter;
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
|
-
(()=>{
|
|
17
|
-
__webpack_require__.d = (exports, definition)=>{
|
|
18
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: definition[key]
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
})();
|
|
24
|
-
(()=>{
|
|
25
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
26
|
-
})();
|
|
27
|
-
const relativizeSourceMap_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("metro/src/lib/relativizeSourceMap");
|
|
28
|
-
var relativizeSourceMap_default = /*#__PURE__*/ __webpack_require__.n(relativizeSourceMap_namespaceObject);
|
|
5
|
+
import { relativizeSourceMapInline } from "../../utils/metro-compat.mjs";
|
|
29
6
|
function relativizeSerializedMap(map, sourceMapSourcesRoot) {
|
|
30
7
|
const sourceMap = JSON.parse(map);
|
|
31
|
-
|
|
8
|
+
relativizeSourceMapInline(sourceMap, sourceMapSourcesRoot);
|
|
32
9
|
return JSON.stringify(sourceMap);
|
|
33
10
|
}
|
|
34
11
|
async function saveBundleAndMap(bundle, options, log) {
|
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;
|