@module-federation/metro 0.0.0-next-20250827124348
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.d.ts +2 -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 +95 -0
- package/dist/commands/bundle-host/index.mjs +69 -0
- package/dist/commands/bundle-host/options.d.ts +5 -0
- package/dist/commands/bundle-host/options.js +39 -0
- package/dist/commands/bundle-host/options.mjs +7 -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 +2 -0
- package/dist/commands/bundle-remote/index.d.ts +12 -0
- package/dist/commands/bundle-remote/index.js +226 -0
- package/dist/commands/bundle-remote/index.mjs +200 -0
- package/dist/commands/bundle-remote/options.d.ts +32 -0
- package/dist/commands/bundle-remote/options.js +109 -0
- package/dist/commands/bundle-remote/options.mjs +67 -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 +2 -0
- package/dist/commands/index.d.ts +48 -0
- package/dist/commands/index.js +72 -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 +2 -0
- package/dist/commands/utils/create-module-path-remapper.d.ts +7 -0
- package/dist/commands/utils/create-module-path-remapper.js +64 -0
- package/dist/commands/utils/create-module-path-remapper.mjs +32 -0
- package/dist/commands/utils/create-resolver.d.ts +20 -0
- package/dist/commands/utils/create-resolver.js +57 -0
- package/dist/commands/utils/create-resolver.mjs +25 -0
- package/dist/commands/utils/get-community-plugin.d.ts +29 -0
- package/dist/commands/utils/get-community-plugin.js +50 -0
- package/dist/commands/utils/get-community-plugin.mjs +18 -0
- package/dist/commands/utils/load-metro-config.d.ts +3 -0
- package/dist/commands/utils/load-metro-config.js +84 -0
- package/dist/commands/utils/load-metro-config.mjs +43 -0
- package/dist/commands/utils/save-bundle-and-map.d.ts +5 -0
- package/dist/commands/utils/save-bundle-and-map.js +77 -0
- package/dist/commands/utils/save-bundle-and-map.mjs +57 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +40 -0
- package/dist/index.mjs +5 -0
- package/dist/modules/HMRClient.ts +31 -0
- package/dist/modules/HMRClientShim.ts +1 -0
- package/dist/modules/asyncRequire.ts +134 -0
- package/dist/modules/asyncStartup.tsx +38 -0
- package/dist/modules/getDevServer.ts +15 -0
- package/dist/modules/metroCorePlugin.ts +83 -0
- package/dist/plugin/babel-transformer.d.ts +11 -0
- package/dist/plugin/babel-transformer.js +68 -0
- package/dist/plugin/babel-transformer.mjs +25 -0
- package/dist/plugin/constants.d.ts +9 -0
- package/dist/plugin/constants.js +68 -0
- package/dist/plugin/constants.mjs +12 -0
- package/dist/plugin/generators.d.ts +13 -0
- package/dist/plugin/generators.js +157 -0
- package/dist/plugin/generators.mjs +99 -0
- package/dist/plugin/helpers.d.ts +7 -0
- package/dist/plugin/helpers.js +119 -0
- package/dist/plugin/helpers.mjs +58 -0
- package/dist/plugin/index.d.ts +9 -0
- package/dist/plugin/index.js +167 -0
- package/dist/plugin/index.mjs +124 -0
- package/dist/plugin/manifest.d.ts +3 -0
- package/dist/plugin/manifest.js +146 -0
- package/dist/plugin/manifest.mjs +100 -0
- package/dist/plugin/normalize-extra-options.d.ts +8 -0
- package/dist/plugin/normalize-extra-options.js +46 -0
- package/dist/plugin/normalize-extra-options.mjs +14 -0
- package/dist/plugin/normalize-options.d.ts +7 -0
- package/dist/plugin/normalize-options.js +89 -0
- package/dist/plugin/normalize-options.mjs +46 -0
- package/dist/plugin/resolver.d.ts +25 -0
- package/dist/plugin/resolver.js +199 -0
- package/dist/plugin/resolver.mjs +160 -0
- package/dist/plugin/rewrite-request.d.ts +10 -0
- package/dist/plugin/rewrite-request.js +76 -0
- package/dist/plugin/rewrite-request.mjs +34 -0
- package/dist/plugin/serializer.d.ts +5 -0
- package/dist/plugin/serializer.js +171 -0
- package/dist/plugin/serializer.mjs +151 -0
- package/dist/plugin/validate-options.d.ts +2 -0
- package/dist/plugin/validate-options.js +61 -0
- package/dist/plugin/validate-options.mjs +29 -0
- package/dist/runtime/host-entry.d.ts +1 -0
- package/dist/runtime/host-entry.js +3 -0
- package/dist/runtime/init-host.d.ts +1 -0
- package/dist/runtime/init-host.js +31 -0
- package/dist/runtime/remote-entry.d.ts +1 -0
- package/dist/runtime/remote-entry.js +57 -0
- package/dist/runtime/remote-hmr.d.ts +1 -0
- package/dist/runtime/remote-hmr.js +19 -0
- package/dist/runtime/remote-module-registry.d.ts +7 -0
- package/dist/runtime/remote-module-registry.js +57 -0
- package/dist/runtime/remote-module.d.ts +1 -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 +2 -0
- package/dist/utils/errors.d.ts +8 -0
- package/dist/utils/errors.js +50 -0
- package/dist/utils/errors.mjs +15 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +43 -0
- package/dist/utils/index.mjs +5 -0
- package/dist/utils/vm-manager.d.ts +21 -0
- package/dist/utils/vm-manager.js +116 -0
- package/dist/utils/vm-manager.mjs +73 -0
- package/package.json +91 -0
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
ASYNC_REQUIRE: ()=>ASYNC_REQUIRE,
|
|
28
|
+
DEFAULT_ENTRY_FILENAME: ()=>DEFAULT_ENTRY_FILENAME,
|
|
29
|
+
GET_DEV_SERVER_REGEX: ()=>GET_DEV_SERVER_REGEX,
|
|
30
|
+
HMR_CLIENT_REGEX: ()=>HMR_CLIENT_REGEX,
|
|
31
|
+
INIT_HOST: ()=>INIT_HOST,
|
|
32
|
+
MANIFEST_FILENAME: ()=>MANIFEST_FILENAME,
|
|
33
|
+
REMOTE_HMR_SETUP: ()=>REMOTE_HMR_SETUP,
|
|
34
|
+
REMOTE_MODULE_REGISTRY: ()=>REMOTE_MODULE_REGISTRY,
|
|
35
|
+
TMP_DIR_NAME: ()=>TMP_DIR_NAME
|
|
36
|
+
});
|
|
37
|
+
const INIT_HOST = 'mf:init-host';
|
|
38
|
+
const ASYNC_REQUIRE = 'mf:async-require';
|
|
39
|
+
const REMOTE_MODULE_REGISTRY = 'mf:remote-module-registry';
|
|
40
|
+
const REMOTE_HMR_SETUP = 'mf:remote-hmr';
|
|
41
|
+
const DEFAULT_ENTRY_FILENAME = 'remoteEntry.bundle';
|
|
42
|
+
const GET_DEV_SERVER_REGEX = /react-native\/Libraries\/Core\/Devtools\/getDevServer\.js$/;
|
|
43
|
+
const HMR_CLIENT_REGEX = /react-native\/Libraries\/Utilities\/HMRClient\.js$/;
|
|
44
|
+
const TMP_DIR_NAME = '.mf-metro';
|
|
45
|
+
const MANIFEST_FILENAME = 'mf-manifest.json';
|
|
46
|
+
exports.ASYNC_REQUIRE = __webpack_exports__.ASYNC_REQUIRE;
|
|
47
|
+
exports.DEFAULT_ENTRY_FILENAME = __webpack_exports__.DEFAULT_ENTRY_FILENAME;
|
|
48
|
+
exports.GET_DEV_SERVER_REGEX = __webpack_exports__.GET_DEV_SERVER_REGEX;
|
|
49
|
+
exports.HMR_CLIENT_REGEX = __webpack_exports__.HMR_CLIENT_REGEX;
|
|
50
|
+
exports.INIT_HOST = __webpack_exports__.INIT_HOST;
|
|
51
|
+
exports.MANIFEST_FILENAME = __webpack_exports__.MANIFEST_FILENAME;
|
|
52
|
+
exports.REMOTE_HMR_SETUP = __webpack_exports__.REMOTE_HMR_SETUP;
|
|
53
|
+
exports.REMOTE_MODULE_REGISTRY = __webpack_exports__.REMOTE_MODULE_REGISTRY;
|
|
54
|
+
exports.TMP_DIR_NAME = __webpack_exports__.TMP_DIR_NAME;
|
|
55
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
56
|
+
"ASYNC_REQUIRE",
|
|
57
|
+
"DEFAULT_ENTRY_FILENAME",
|
|
58
|
+
"GET_DEV_SERVER_REGEX",
|
|
59
|
+
"HMR_CLIENT_REGEX",
|
|
60
|
+
"INIT_HOST",
|
|
61
|
+
"MANIFEST_FILENAME",
|
|
62
|
+
"REMOTE_HMR_SETUP",
|
|
63
|
+
"REMOTE_MODULE_REGISTRY",
|
|
64
|
+
"TMP_DIR_NAME"
|
|
65
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
66
|
+
Object.defineProperty(exports, '__esModule', {
|
|
67
|
+
value: true
|
|
68
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import 'module';
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
const INIT_HOST = 'mf:init-host';
|
|
4
|
+
const ASYNC_REQUIRE = 'mf:async-require';
|
|
5
|
+
const REMOTE_MODULE_REGISTRY = 'mf:remote-module-registry';
|
|
6
|
+
const REMOTE_HMR_SETUP = 'mf:remote-hmr';
|
|
7
|
+
const DEFAULT_ENTRY_FILENAME = 'remoteEntry.bundle';
|
|
8
|
+
const GET_DEV_SERVER_REGEX = /react-native\/Libraries\/Core\/Devtools\/getDevServer\.js$/;
|
|
9
|
+
const HMR_CLIENT_REGEX = /react-native\/Libraries\/Utilities\/HMRClient\.js$/;
|
|
10
|
+
const TMP_DIR_NAME = '.mf-metro';
|
|
11
|
+
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 };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ModuleFederationConfigNormalized } from '../types';
|
|
2
|
+
export declare function getRemoteModule(name: string): string;
|
|
3
|
+
export declare function getHostEntryModule(_: ModuleFederationConfigNormalized, paths: {
|
|
4
|
+
originalEntry: string;
|
|
5
|
+
tmpDir: string;
|
|
6
|
+
}): string;
|
|
7
|
+
export declare function getInitHostModule(options: ModuleFederationConfigNormalized): string;
|
|
8
|
+
export declare function getRemoteEntryModule(options: ModuleFederationConfigNormalized, paths: {
|
|
9
|
+
tmpDir: string;
|
|
10
|
+
projectDir: string;
|
|
11
|
+
}): string;
|
|
12
|
+
export declare function getRemoteModuleRegistryModule(): string;
|
|
13
|
+
export declare function getRemoteHMRSetupModule(): string;
|
|
@@ -0,0 +1,157 @@
|
|
|
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, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
getRemoteModuleRegistryModule: ()=>getRemoteModuleRegistryModule,
|
|
37
|
+
getRemoteEntryModule: ()=>getRemoteEntryModule,
|
|
38
|
+
getInitHostModule: ()=>getInitHostModule,
|
|
39
|
+
getHostEntryModule: ()=>getHostEntryModule,
|
|
40
|
+
getRemoteHMRSetupModule: ()=>getRemoteHMRSetupModule,
|
|
41
|
+
getRemoteModule: ()=>getRemoteModule
|
|
42
|
+
});
|
|
43
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
44
|
+
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
45
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
46
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
47
|
+
function getRemoteModule(name) {
|
|
48
|
+
const template = getModuleTemplate('remote-module.js');
|
|
49
|
+
return template.replaceAll('__MODULE_ID__', `"${name}"`);
|
|
50
|
+
}
|
|
51
|
+
function getHostEntryModule(_, paths) {
|
|
52
|
+
const template = getModuleTemplate('host-entry.js');
|
|
53
|
+
return template.replaceAll('__ENTRYPOINT_IMPORT__', `import './${external_node_path_default().relative(paths.tmpDir, paths.originalEntry)}'`);
|
|
54
|
+
}
|
|
55
|
+
function getInitHostModule(options) {
|
|
56
|
+
const template = getModuleTemplate('init-host.js');
|
|
57
|
+
return template.replaceAll('__NAME__', JSON.stringify(options.name)).replaceAll('__REMOTES__', generateRemotes(options.remotes)).replaceAll('__SHARED__', generateShared(options)).replaceAll('__SHARE_STRATEGY__', JSON.stringify(options.shareStrategy)).replaceAll('__PLUGINS__', generateRuntimePlugins(options.plugins));
|
|
58
|
+
}
|
|
59
|
+
function getRemoteEntryModule(options, paths) {
|
|
60
|
+
const template = getModuleTemplate('remote-entry.js');
|
|
61
|
+
return template.replaceAll('__NAME__', JSON.stringify(options.name)).replaceAll('__EXPOSES_MAP__', generateExposes(options.exposes, paths)).replaceAll('__REMOTES__', generateRemotes(options.remotes)).replaceAll('__SHARED__', generateShared(options)).replaceAll('__SHARE_STRATEGY__', JSON.stringify(options.shareStrategy)).replaceAll('__PLUGINS__', generateRuntimePlugins(options.plugins));
|
|
62
|
+
}
|
|
63
|
+
function getRemoteModuleRegistryModule() {
|
|
64
|
+
const template = getModuleTemplate('remote-module-registry.js');
|
|
65
|
+
return template.replaceAll('__EARLY_MODULE_TEST__', '/^react(-native(\\/|$)|$)/');
|
|
66
|
+
}
|
|
67
|
+
function getRemoteHMRSetupModule() {
|
|
68
|
+
const template = getModuleTemplate('remote-hmr.js');
|
|
69
|
+
return template;
|
|
70
|
+
}
|
|
71
|
+
function generateExposes(exposes, paths) {
|
|
72
|
+
const exposesString = Object.keys(exposes).map((key)=>{
|
|
73
|
+
const importPath = external_node_path_default().join(paths.projectDir, exposes[key]);
|
|
74
|
+
const relativeImportPath = external_node_path_default().relative(paths.tmpDir, importPath);
|
|
75
|
+
return `"${key}": async () => import("${relativeImportPath}")`;
|
|
76
|
+
});
|
|
77
|
+
return `{${exposesString.join(',')}}`;
|
|
78
|
+
}
|
|
79
|
+
function generateRuntimePlugins(runtimePlugins) {
|
|
80
|
+
const pluginNames = [];
|
|
81
|
+
const pluginImports = [];
|
|
82
|
+
runtimePlugins.forEach((plugin, index)=>{
|
|
83
|
+
const pluginName = `plugin${index}`;
|
|
84
|
+
pluginNames.push(`${pluginName}()`);
|
|
85
|
+
pluginImports.push(`import ${pluginName} from "${plugin}";`);
|
|
86
|
+
});
|
|
87
|
+
const imports = pluginImports.join('\n');
|
|
88
|
+
const plugins = `const plugins = [${pluginNames.join(', ')}];`;
|
|
89
|
+
return `${imports}\n${plugins}`;
|
|
90
|
+
}
|
|
91
|
+
function generateRemotes(remotes = {}) {
|
|
92
|
+
const remotesEntries = [];
|
|
93
|
+
for (const [remoteAlias, remoteEntry] of Object.entries(remotes)){
|
|
94
|
+
const remoteEntryParts = remoteEntry.split('@');
|
|
95
|
+
const remoteName = remoteEntryParts[0];
|
|
96
|
+
const remoteEntryUrl = remoteEntryParts.slice(1).join('@');
|
|
97
|
+
remotesEntries.push(`{
|
|
98
|
+
alias: "${remoteAlias}",
|
|
99
|
+
name: "${remoteName}",
|
|
100
|
+
entry: "${remoteEntryUrl}",
|
|
101
|
+
entryGlobalName: "${remoteName}",
|
|
102
|
+
type: "var"
|
|
103
|
+
}`);
|
|
104
|
+
}
|
|
105
|
+
return `[${remotesEntries.join(',\n')}]`;
|
|
106
|
+
}
|
|
107
|
+
function generateShared(options) {
|
|
108
|
+
const shared = Object.keys(options.shared).reduce((acc, name)=>{
|
|
109
|
+
acc[name] = `__SHARED_${name}__`;
|
|
110
|
+
return acc;
|
|
111
|
+
}, {});
|
|
112
|
+
let sharedString = JSON.stringify(shared);
|
|
113
|
+
for (const name of Object.keys(options.shared)){
|
|
114
|
+
const sharedConfig = options.shared[name];
|
|
115
|
+
const entry = getSharedModuleEntry(name, sharedConfig);
|
|
116
|
+
sharedString = sharedString.replaceAll(`"__SHARED_${name}__"`, entry);
|
|
117
|
+
}
|
|
118
|
+
return sharedString;
|
|
119
|
+
}
|
|
120
|
+
function getSharedModuleEntry(name, options) {
|
|
121
|
+
const template = {
|
|
122
|
+
version: options.version,
|
|
123
|
+
scope: 'default',
|
|
124
|
+
shareConfig: {
|
|
125
|
+
singleton: options.singleton,
|
|
126
|
+
eager: options.eager,
|
|
127
|
+
requiredVersion: options.requiredVersion
|
|
128
|
+
},
|
|
129
|
+
get: options.eager ? '__GET_SYNC_PLACEHOLDER__' : '__GET_ASYNC_PLACEHOLDER__'
|
|
130
|
+
};
|
|
131
|
+
const templateString = JSON.stringify(template);
|
|
132
|
+
return templateString.replaceAll('"__GET_SYNC_PLACEHOLDER__"', `() => () => require("${name}")`).replaceAll('"__GET_ASYNC_PLACEHOLDER__"', `async () => import("${name}").then((m) => () => m)`);
|
|
133
|
+
}
|
|
134
|
+
function resolveRuntimeModule(moduleName) {
|
|
135
|
+
return require.resolve(`../runtime/${moduleName}`);
|
|
136
|
+
}
|
|
137
|
+
function getModuleTemplate(moduleName) {
|
|
138
|
+
const templatePath = resolveRuntimeModule(moduleName);
|
|
139
|
+
return external_node_fs_default().readFileSync(templatePath, 'utf-8');
|
|
140
|
+
}
|
|
141
|
+
exports.getHostEntryModule = __webpack_exports__.getHostEntryModule;
|
|
142
|
+
exports.getInitHostModule = __webpack_exports__.getInitHostModule;
|
|
143
|
+
exports.getRemoteEntryModule = __webpack_exports__.getRemoteEntryModule;
|
|
144
|
+
exports.getRemoteHMRSetupModule = __webpack_exports__.getRemoteHMRSetupModule;
|
|
145
|
+
exports.getRemoteModule = __webpack_exports__.getRemoteModule;
|
|
146
|
+
exports.getRemoteModuleRegistryModule = __webpack_exports__.getRemoteModuleRegistryModule;
|
|
147
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
148
|
+
"getHostEntryModule",
|
|
149
|
+
"getInitHostModule",
|
|
150
|
+
"getRemoteEntryModule",
|
|
151
|
+
"getRemoteHMRSetupModule",
|
|
152
|
+
"getRemoteModule",
|
|
153
|
+
"getRemoteModuleRegistryModule"
|
|
154
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
155
|
+
Object.defineProperty(exports, '__esModule', {
|
|
156
|
+
value: true
|
|
157
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import __rslib_shim_module__ from 'module';
|
|
2
|
+
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
|
|
3
|
+
import node_fs from "node:fs";
|
|
4
|
+
import node_path from "node:path";
|
|
5
|
+
function getRemoteModule(name) {
|
|
6
|
+
const template = getModuleTemplate('remote-module.js');
|
|
7
|
+
return template.replaceAll('__MODULE_ID__', `"${name}"`);
|
|
8
|
+
}
|
|
9
|
+
function getHostEntryModule(_, paths) {
|
|
10
|
+
const template = getModuleTemplate('host-entry.js');
|
|
11
|
+
return template.replaceAll('__ENTRYPOINT_IMPORT__', `import './${node_path.relative(paths.tmpDir, paths.originalEntry)}'`);
|
|
12
|
+
}
|
|
13
|
+
function getInitHostModule(options) {
|
|
14
|
+
const template = getModuleTemplate('init-host.js');
|
|
15
|
+
return template.replaceAll('__NAME__', JSON.stringify(options.name)).replaceAll('__REMOTES__', generateRemotes(options.remotes)).replaceAll('__SHARED__', generateShared(options)).replaceAll('__SHARE_STRATEGY__', JSON.stringify(options.shareStrategy)).replaceAll('__PLUGINS__', generateRuntimePlugins(options.plugins));
|
|
16
|
+
}
|
|
17
|
+
function getRemoteEntryModule(options, paths) {
|
|
18
|
+
const template = getModuleTemplate('remote-entry.js');
|
|
19
|
+
return template.replaceAll('__NAME__', JSON.stringify(options.name)).replaceAll('__EXPOSES_MAP__', generateExposes(options.exposes, paths)).replaceAll('__REMOTES__', generateRemotes(options.remotes)).replaceAll('__SHARED__', generateShared(options)).replaceAll('__SHARE_STRATEGY__', JSON.stringify(options.shareStrategy)).replaceAll('__PLUGINS__', generateRuntimePlugins(options.plugins));
|
|
20
|
+
}
|
|
21
|
+
function getRemoteModuleRegistryModule() {
|
|
22
|
+
const template = getModuleTemplate('remote-module-registry.js');
|
|
23
|
+
return template.replaceAll('__EARLY_MODULE_TEST__', '/^react(-native(\\/|$)|$)/');
|
|
24
|
+
}
|
|
25
|
+
function getRemoteHMRSetupModule() {
|
|
26
|
+
const template = getModuleTemplate('remote-hmr.js');
|
|
27
|
+
return template;
|
|
28
|
+
}
|
|
29
|
+
function generateExposes(exposes, paths) {
|
|
30
|
+
const exposesString = Object.keys(exposes).map((key)=>{
|
|
31
|
+
const importPath = node_path.join(paths.projectDir, exposes[key]);
|
|
32
|
+
const relativeImportPath = node_path.relative(paths.tmpDir, importPath);
|
|
33
|
+
return `"${key}": async () => import("${relativeImportPath}")`;
|
|
34
|
+
});
|
|
35
|
+
return `{${exposesString.join(',')}}`;
|
|
36
|
+
}
|
|
37
|
+
function generateRuntimePlugins(runtimePlugins) {
|
|
38
|
+
const pluginNames = [];
|
|
39
|
+
const pluginImports = [];
|
|
40
|
+
runtimePlugins.forEach((plugin, index)=>{
|
|
41
|
+
const pluginName = `plugin${index}`;
|
|
42
|
+
pluginNames.push(`${pluginName}()`);
|
|
43
|
+
pluginImports.push(`import ${pluginName} from "${plugin}";`);
|
|
44
|
+
});
|
|
45
|
+
const imports = pluginImports.join('\n');
|
|
46
|
+
const plugins = `const plugins = [${pluginNames.join(', ')}];`;
|
|
47
|
+
return `${imports}\n${plugins}`;
|
|
48
|
+
}
|
|
49
|
+
function generateRemotes(remotes = {}) {
|
|
50
|
+
const remotesEntries = [];
|
|
51
|
+
for (const [remoteAlias, remoteEntry] of Object.entries(remotes)){
|
|
52
|
+
const remoteEntryParts = remoteEntry.split('@');
|
|
53
|
+
const remoteName = remoteEntryParts[0];
|
|
54
|
+
const remoteEntryUrl = remoteEntryParts.slice(1).join('@');
|
|
55
|
+
remotesEntries.push(`{
|
|
56
|
+
alias: "${remoteAlias}",
|
|
57
|
+
name: "${remoteName}",
|
|
58
|
+
entry: "${remoteEntryUrl}",
|
|
59
|
+
entryGlobalName: "${remoteName}",
|
|
60
|
+
type: "var"
|
|
61
|
+
}`);
|
|
62
|
+
}
|
|
63
|
+
return `[${remotesEntries.join(',\n')}]`;
|
|
64
|
+
}
|
|
65
|
+
function generateShared(options) {
|
|
66
|
+
const shared = Object.keys(options.shared).reduce((acc, name)=>{
|
|
67
|
+
acc[name] = `__SHARED_${name}__`;
|
|
68
|
+
return acc;
|
|
69
|
+
}, {});
|
|
70
|
+
let sharedString = JSON.stringify(shared);
|
|
71
|
+
for (const name of Object.keys(options.shared)){
|
|
72
|
+
const sharedConfig = options.shared[name];
|
|
73
|
+
const entry = getSharedModuleEntry(name, sharedConfig);
|
|
74
|
+
sharedString = sharedString.replaceAll(`"__SHARED_${name}__"`, entry);
|
|
75
|
+
}
|
|
76
|
+
return sharedString;
|
|
77
|
+
}
|
|
78
|
+
function getSharedModuleEntry(name, options) {
|
|
79
|
+
const template = {
|
|
80
|
+
version: options.version,
|
|
81
|
+
scope: 'default',
|
|
82
|
+
shareConfig: {
|
|
83
|
+
singleton: options.singleton,
|
|
84
|
+
eager: options.eager,
|
|
85
|
+
requiredVersion: options.requiredVersion
|
|
86
|
+
},
|
|
87
|
+
get: options.eager ? '__GET_SYNC_PLACEHOLDER__' : '__GET_ASYNC_PLACEHOLDER__'
|
|
88
|
+
};
|
|
89
|
+
const templateString = JSON.stringify(template);
|
|
90
|
+
return templateString.replaceAll('"__GET_SYNC_PLACEHOLDER__"', `() => () => require("${name}")`).replaceAll('"__GET_ASYNC_PLACEHOLDER__"', `async () => import("${name}").then((m) => () => m)`);
|
|
91
|
+
}
|
|
92
|
+
function resolveRuntimeModule(moduleName) {
|
|
93
|
+
return require.resolve(`../runtime/${moduleName}`);
|
|
94
|
+
}
|
|
95
|
+
function getModuleTemplate(moduleName) {
|
|
96
|
+
const templatePath = resolveRuntimeModule(moduleName);
|
|
97
|
+
return node_fs.readFileSync(templatePath, 'utf-8');
|
|
98
|
+
}
|
|
99
|
+
export { getHostEntryModule, getInitHostModule, getRemoteEntryModule, getRemoteHMRSetupModule, getRemoteModule, getRemoteModuleRegistryModule };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function isUsingMFCommand(command?: string): boolean;
|
|
2
|
+
export declare function isUsingMFBundleCommand(command?: string): boolean;
|
|
3
|
+
export declare function replaceExtension(filepath: string, extension: string): string;
|
|
4
|
+
export declare function removeExtension(filepath: string): string;
|
|
5
|
+
export declare function stubHostEntry(hostEntryPath: string): void;
|
|
6
|
+
export declare function stubRemoteEntry(remoteEntryPath: string): void;
|
|
7
|
+
export declare function prepareTmpDir(projectRootPath: string): string;
|
|
@@ -0,0 +1,119 @@
|
|
|
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, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
stubHostEntry: ()=>stubHostEntry,
|
|
37
|
+
stubRemoteEntry: ()=>stubRemoteEntry,
|
|
38
|
+
isUsingMFCommand: ()=>isUsingMFCommand,
|
|
39
|
+
isUsingMFBundleCommand: ()=>isUsingMFBundleCommand,
|
|
40
|
+
removeExtension: ()=>removeExtension,
|
|
41
|
+
prepareTmpDir: ()=>prepareTmpDir,
|
|
42
|
+
replaceExtension: ()=>replaceExtension
|
|
43
|
+
});
|
|
44
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
45
|
+
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
46
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
47
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
48
|
+
const external_constants_js_namespaceObject = require("./constants.js");
|
|
49
|
+
function isUsingMFCommand(command = process.argv[2]) {
|
|
50
|
+
const allowedCommands = [
|
|
51
|
+
'start',
|
|
52
|
+
'bundle-mf-host',
|
|
53
|
+
'bundle-mf-remote'
|
|
54
|
+
];
|
|
55
|
+
return allowedCommands.includes(command);
|
|
56
|
+
}
|
|
57
|
+
function isUsingMFBundleCommand(command = process.argv[2]) {
|
|
58
|
+
const allowedCommands = [
|
|
59
|
+
'bundle-mf-host',
|
|
60
|
+
'bundle-mf-remote'
|
|
61
|
+
];
|
|
62
|
+
return allowedCommands.includes(command);
|
|
63
|
+
}
|
|
64
|
+
function replaceExtension(filepath, extension) {
|
|
65
|
+
const { dir, name } = external_node_path_default().parse(filepath);
|
|
66
|
+
return external_node_path_default().format({
|
|
67
|
+
dir,
|
|
68
|
+
name,
|
|
69
|
+
ext: extension
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function removeExtension(filepath) {
|
|
73
|
+
return replaceExtension(filepath, '');
|
|
74
|
+
}
|
|
75
|
+
function stubHostEntry(hostEntryPath) {
|
|
76
|
+
const stub = '// host entry stub';
|
|
77
|
+
external_node_fs_default().mkdirSync(external_node_path_default().dirname(hostEntryPath), {
|
|
78
|
+
recursive: true
|
|
79
|
+
});
|
|
80
|
+
external_node_fs_default().writeFileSync(hostEntryPath, stub, 'utf-8');
|
|
81
|
+
}
|
|
82
|
+
function stubRemoteEntry(remoteEntryPath) {
|
|
83
|
+
const stub = '// remote entry stub';
|
|
84
|
+
external_node_fs_default().mkdirSync(external_node_path_default().dirname(remoteEntryPath), {
|
|
85
|
+
recursive: true
|
|
86
|
+
});
|
|
87
|
+
external_node_fs_default().writeFileSync(remoteEntryPath, stub, 'utf-8');
|
|
88
|
+
}
|
|
89
|
+
function prepareTmpDir(projectRootPath) {
|
|
90
|
+
const nodeModulesPath = external_node_path_default().resolve(projectRootPath, 'node_modules');
|
|
91
|
+
const tmpDirPath = external_node_path_default().join(nodeModulesPath, external_constants_js_namespaceObject.TMP_DIR_NAME);
|
|
92
|
+
external_node_fs_default().rmSync(tmpDirPath, {
|
|
93
|
+
recursive: true,
|
|
94
|
+
force: true
|
|
95
|
+
});
|
|
96
|
+
external_node_fs_default().mkdirSync(tmpDirPath, {
|
|
97
|
+
recursive: true
|
|
98
|
+
});
|
|
99
|
+
return tmpDirPath;
|
|
100
|
+
}
|
|
101
|
+
exports.isUsingMFBundleCommand = __webpack_exports__.isUsingMFBundleCommand;
|
|
102
|
+
exports.isUsingMFCommand = __webpack_exports__.isUsingMFCommand;
|
|
103
|
+
exports.prepareTmpDir = __webpack_exports__.prepareTmpDir;
|
|
104
|
+
exports.removeExtension = __webpack_exports__.removeExtension;
|
|
105
|
+
exports.replaceExtension = __webpack_exports__.replaceExtension;
|
|
106
|
+
exports.stubHostEntry = __webpack_exports__.stubHostEntry;
|
|
107
|
+
exports.stubRemoteEntry = __webpack_exports__.stubRemoteEntry;
|
|
108
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
109
|
+
"isUsingMFBundleCommand",
|
|
110
|
+
"isUsingMFCommand",
|
|
111
|
+
"prepareTmpDir",
|
|
112
|
+
"removeExtension",
|
|
113
|
+
"replaceExtension",
|
|
114
|
+
"stubHostEntry",
|
|
115
|
+
"stubRemoteEntry"
|
|
116
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
117
|
+
Object.defineProperty(exports, '__esModule', {
|
|
118
|
+
value: true
|
|
119
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import 'module';
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
import node_fs from "node:fs";
|
|
4
|
+
import node_path from "node:path";
|
|
5
|
+
import { TMP_DIR_NAME } from "./constants.mjs";
|
|
6
|
+
function isUsingMFCommand(command = process.argv[2]) {
|
|
7
|
+
const allowedCommands = [
|
|
8
|
+
'start',
|
|
9
|
+
'bundle-mf-host',
|
|
10
|
+
'bundle-mf-remote'
|
|
11
|
+
];
|
|
12
|
+
return allowedCommands.includes(command);
|
|
13
|
+
}
|
|
14
|
+
function isUsingMFBundleCommand(command = process.argv[2]) {
|
|
15
|
+
const allowedCommands = [
|
|
16
|
+
'bundle-mf-host',
|
|
17
|
+
'bundle-mf-remote'
|
|
18
|
+
];
|
|
19
|
+
return allowedCommands.includes(command);
|
|
20
|
+
}
|
|
21
|
+
function replaceExtension(filepath, extension) {
|
|
22
|
+
const { dir, name } = node_path.parse(filepath);
|
|
23
|
+
return node_path.format({
|
|
24
|
+
dir,
|
|
25
|
+
name,
|
|
26
|
+
ext: extension
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function removeExtension(filepath) {
|
|
30
|
+
return replaceExtension(filepath, '');
|
|
31
|
+
}
|
|
32
|
+
function stubHostEntry(hostEntryPath) {
|
|
33
|
+
const stub = '// host entry stub';
|
|
34
|
+
node_fs.mkdirSync(node_path.dirname(hostEntryPath), {
|
|
35
|
+
recursive: true
|
|
36
|
+
});
|
|
37
|
+
node_fs.writeFileSync(hostEntryPath, stub, 'utf-8');
|
|
38
|
+
}
|
|
39
|
+
function stubRemoteEntry(remoteEntryPath) {
|
|
40
|
+
const stub = '// remote entry stub';
|
|
41
|
+
node_fs.mkdirSync(node_path.dirname(remoteEntryPath), {
|
|
42
|
+
recursive: true
|
|
43
|
+
});
|
|
44
|
+
node_fs.writeFileSync(remoteEntryPath, stub, 'utf-8');
|
|
45
|
+
}
|
|
46
|
+
function prepareTmpDir(projectRootPath) {
|
|
47
|
+
const nodeModulesPath = node_path.resolve(projectRootPath, 'node_modules');
|
|
48
|
+
const tmpDirPath = node_path.join(nodeModulesPath, TMP_DIR_NAME);
|
|
49
|
+
node_fs.rmSync(tmpDirPath, {
|
|
50
|
+
recursive: true,
|
|
51
|
+
force: true
|
|
52
|
+
});
|
|
53
|
+
node_fs.mkdirSync(tmpDirPath, {
|
|
54
|
+
recursive: true
|
|
55
|
+
});
|
|
56
|
+
return tmpDirPath;
|
|
57
|
+
}
|
|
58
|
+
export { isUsingMFBundleCommand, isUsingMFCommand, prepareTmpDir, removeExtension, replaceExtension, stubHostEntry, stubRemoteEntry };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ConfigT } from 'metro-config';
|
|
2
|
+
import type { ModuleFederationConfig, ModuleFederationConfigNormalized, ModuleFederationExtraOptions } from '../types';
|
|
3
|
+
declare global {
|
|
4
|
+
var __METRO_FEDERATION_CONFIG: ModuleFederationConfigNormalized;
|
|
5
|
+
var __METRO_FEDERATION_ORIGINAL_ENTRY_PATH: string | undefined;
|
|
6
|
+
var __METRO_FEDERATION_REMOTE_ENTRY_PATH: string | undefined;
|
|
7
|
+
var __METRO_FEDERATION_MANIFEST_PATH: string | undefined;
|
|
8
|
+
}
|
|
9
|
+
export declare function withModuleFederation(config: ConfigT, federationOptions: ModuleFederationConfig, extraOptions?: ModuleFederationExtraOptions): ConfigT;
|