@module-federation/metro 0.0.0-chore-bump-node-22-20260710161714

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/babel-plugin/index.js +115 -0
  4. package/babel-plugin/patch-initialize-core.js +61 -0
  5. package/babel-plugin/patch-require.js +174 -0
  6. package/bootstrap/index.d.ts +1 -0
  7. package/bootstrap/index.js +1 -0
  8. package/dist/babel/transformer.js +15 -0
  9. package/dist/commands/bundle-host/index.d.ts +13 -0
  10. package/dist/commands/bundle-host/index.js +100 -0
  11. package/dist/commands/bundle-host/index.mjs +47 -0
  12. package/dist/commands/bundle-host/options.d.ts +5 -0
  13. package/dist/commands/bundle-host/options.js +43 -0
  14. package/dist/commands/bundle-host/options.mjs +6 -0
  15. package/dist/commands/bundle-host/types.d.ts +22 -0
  16. package/dist/commands/bundle-host/types.js +18 -0
  17. package/dist/commands/bundle-host/types.mjs +1 -0
  18. package/dist/commands/bundle-remote/index.d.ts +12 -0
  19. package/dist/commands/bundle-remote/index.js +241 -0
  20. package/dist/commands/bundle-remote/index.mjs +190 -0
  21. package/dist/commands/bundle-remote/options.d.ts +32 -0
  22. package/dist/commands/bundle-remote/options.js +113 -0
  23. package/dist/commands/bundle-remote/options.mjs +66 -0
  24. package/dist/commands/bundle-remote/types.d.ts +16 -0
  25. package/dist/commands/bundle-remote/types.js +18 -0
  26. package/dist/commands/bundle-remote/types.mjs +1 -0
  27. package/dist/commands/index.d.ts +48 -0
  28. package/dist/commands/index.js +76 -0
  29. package/dist/commands/index.mjs +13 -0
  30. package/dist/commands/types.d.ts +14 -0
  31. package/dist/commands/types.js +18 -0
  32. package/dist/commands/types.mjs +1 -0
  33. package/dist/commands/utils/create-module-path-remapper.d.ts +7 -0
  34. package/dist/commands/utils/create-module-path-remapper.js +68 -0
  35. package/dist/commands/utils/create-module-path-remapper.mjs +31 -0
  36. package/dist/commands/utils/create-resolver.d.ts +20 -0
  37. package/dist/commands/utils/create-resolver.js +61 -0
  38. package/dist/commands/utils/create-resolver.mjs +24 -0
  39. package/dist/commands/utils/get-community-plugin.d.ts +28 -0
  40. package/dist/commands/utils/get-community-plugin.js +53 -0
  41. package/dist/commands/utils/get-community-plugin.mjs +17 -0
  42. package/dist/commands/utils/load-metro-config.d.ts +3 -0
  43. package/dist/commands/utils/load-metro-config.js +85 -0
  44. package/dist/commands/utils/load-metro-config.mjs +41 -0
  45. package/dist/commands/utils/path-utils.d.ts +2 -0
  46. package/dist/commands/utils/path-utils.js +51 -0
  47. package/dist/commands/utils/path-utils.mjs +11 -0
  48. package/dist/commands/utils/save-bundle-and-map.d.ts +5 -0
  49. package/dist/commands/utils/save-bundle-and-map.js +80 -0
  50. package/dist/commands/utils/save-bundle-and-map.mjs +33 -0
  51. package/dist/index.d.ts +2 -0
  52. package/dist/index.js +44 -0
  53. package/dist/index.mjs +3 -0
  54. package/dist/logger.d.ts +2 -0
  55. package/dist/logger.js +43 -0
  56. package/dist/logger.mjs +6 -0
  57. package/dist/modules/HMRClient.ts +31 -0
  58. package/dist/modules/HMRClientShim.ts +1 -0
  59. package/dist/modules/asyncRequire.ts +156 -0
  60. package/dist/modules/asyncStartup.tsx +43 -0
  61. package/dist/modules/getDevServer.ts +15 -0
  62. package/dist/modules/metroCorePlugin.ts +87 -0
  63. package/dist/plugin/babel-transformer.d.ts +11 -0
  64. package/dist/plugin/babel-transformer.js +72 -0
  65. package/dist/plugin/babel-transformer.mjs +25 -0
  66. package/dist/plugin/constants.d.ts +10 -0
  67. package/dist/plugin/constants.js +76 -0
  68. package/dist/plugin/constants.mjs +12 -0
  69. package/dist/plugin/generators.d.ts +13 -0
  70. package/dist/plugin/generators.js +164 -0
  71. package/dist/plugin/generators.mjs +102 -0
  72. package/dist/plugin/helpers.d.ts +8 -0
  73. package/dist/plugin/helpers.js +127 -0
  74. package/dist/plugin/helpers.mjs +58 -0
  75. package/dist/plugin/index.d.ts +11 -0
  76. package/dist/plugin/index.js +219 -0
  77. package/dist/plugin/index.mjs +172 -0
  78. package/dist/plugin/manifest-middleware.d.ts +12 -0
  79. package/dist/plugin/manifest-middleware.js +217 -0
  80. package/dist/plugin/manifest-middleware.mjs +170 -0
  81. package/dist/plugin/manifest.d.ts +16 -0
  82. package/dist/plugin/manifest.js +246 -0
  83. package/dist/plugin/manifest.mjs +185 -0
  84. package/dist/plugin/normalize-extra-options.d.ts +8 -0
  85. package/dist/plugin/normalize-extra-options.js +50 -0
  86. package/dist/plugin/normalize-extra-options.mjs +13 -0
  87. package/dist/plugin/normalize-options.d.ts +7 -0
  88. package/dist/plugin/normalize-options.js +139 -0
  89. package/dist/plugin/normalize-options.mjs +92 -0
  90. package/dist/plugin/resolver.d.ts +26 -0
  91. package/dist/plugin/resolver.js +203 -0
  92. package/dist/plugin/resolver.mjs +159 -0
  93. package/dist/plugin/rewrite-request.d.ts +14 -0
  94. package/dist/plugin/rewrite-request.js +89 -0
  95. package/dist/plugin/rewrite-request.mjs +42 -0
  96. package/dist/plugin/serializer.d.ts +6 -0
  97. package/dist/plugin/serializer.js +191 -0
  98. package/dist/plugin/serializer.mjs +144 -0
  99. package/dist/plugin/validate-options.d.ts +2 -0
  100. package/dist/plugin/validate-options.js +165 -0
  101. package/dist/plugin/validate-options.mjs +117 -0
  102. package/dist/runtime/host-entry.js +3 -0
  103. package/dist/runtime/init-host.js +31 -0
  104. package/dist/runtime/remote-entry.js +57 -0
  105. package/dist/runtime/remote-hmr.js +19 -0
  106. package/dist/runtime/remote-module-registry.js +57 -0
  107. package/dist/runtime/remote-module.js +2 -0
  108. package/dist/types.d.ts +26 -0
  109. package/dist/types.js +18 -0
  110. package/dist/types.mjs +1 -0
  111. package/dist/utils/errors.d.ts +8 -0
  112. package/dist/utils/errors.js +54 -0
  113. package/dist/utils/errors.mjs +14 -0
  114. package/dist/utils/federated-remote-types.d.ts +12 -0
  115. package/dist/utils/federated-remote-types.js +140 -0
  116. package/dist/utils/federated-remote-types.mjs +90 -0
  117. package/dist/utils/index.d.ts +2 -0
  118. package/dist/utils/index.js +47 -0
  119. package/dist/utils/index.mjs +3 -0
  120. package/dist/utils/metro-compat.d.ts +23 -0
  121. package/dist/utils/metro-compat.js +74 -0
  122. package/dist/utils/metro-compat.mjs +26 -0
  123. package/dist/utils/vm-manager.d.ts +21 -0
  124. package/dist/utils/vm-manager.js +118 -0
  125. package/dist/utils/vm-manager.mjs +70 -0
  126. package/package.json +106 -0
@@ -0,0 +1,185 @@
1
+ import "node:module";
2
+ import node_crypto from "node:crypto";
3
+ import node_fs from "node:fs";
4
+ import node_path from "node:path";
5
+ import { MANIFEST_FILENAME, TMP_DIR_NAME } from "./constants.mjs";
6
+ import { removeExtension, toPosixPath } from "./helpers.mjs";
7
+ function createManifest(options, mfMetroPath, hashesOrOptions, manifestOptions) {
8
+ const { hashes, options: generationOptions } = normalizeManifestArgs(hashesOrOptions, manifestOptions);
9
+ const manifestPath = node_path.join(mfMetroPath, MANIFEST_FILENAME);
10
+ const manifest = generateManifest(options, hashes, generationOptions);
11
+ node_fs.writeFileSync(manifestPath, JSON.stringify(manifest, void 0, 2));
12
+ return manifestPath;
13
+ }
14
+ function updateManifest(manifestPath, options, hashesOrOptions, manifestOptions) {
15
+ const { hashes, options: generationOptions } = normalizeManifestArgs(hashesOrOptions, manifestOptions);
16
+ const manifest = generateManifest(options, hashes, generationOptions);
17
+ const existingManifest = readManifest(manifestPath);
18
+ if (existingManifest?.metaData?.types) manifest.metaData.types = {
19
+ ...manifest.metaData.types,
20
+ ...existingManifest.metaData.types
21
+ };
22
+ node_fs.writeFileSync(manifestPath, JSON.stringify(manifest, void 0, 2));
23
+ return manifestPath;
24
+ }
25
+ function recordBundleHash(hashes, code, entryPoint, projectRoot, config) {
26
+ const hash = node_crypto.createHash('sha256').update(code).digest('hex');
27
+ const key = resolveBundleKey(entryPoint, projectRoot, config);
28
+ if (key) hashes.set(key, hash);
29
+ }
30
+ function generateManifest(config, hashes, manifestOptions = {}) {
31
+ return {
32
+ id: config.name,
33
+ name: config.name,
34
+ metaData: generateMetaData(config, hashes),
35
+ exposes: generateExposes(config, hashes),
36
+ remotes: generateRemotes(config),
37
+ shared: generateShared(config, hashes, manifestOptions)
38
+ };
39
+ }
40
+ function generateMetaData(config, hashes) {
41
+ return {
42
+ name: config.name,
43
+ type: 'app',
44
+ buildInfo: {
45
+ buildVersion: '1.0.0',
46
+ buildName: config.name,
47
+ hash: hashes?.get(`container:${config.name}`) ?? ''
48
+ },
49
+ remoteEntry: {
50
+ name: config.filename,
51
+ path: '',
52
+ type: 'global'
53
+ },
54
+ types: {
55
+ path: '',
56
+ name: '',
57
+ api: '',
58
+ zip: ''
59
+ },
60
+ globalName: config.name,
61
+ pluginVersion: '',
62
+ publicPath: 'auto'
63
+ };
64
+ }
65
+ function generateExposes(config, hashes) {
66
+ return Object.keys(config.exposes).map((expose)=>{
67
+ const formatKey = expose.replace('./', '');
68
+ const assets = getEmptyAssets();
69
+ assets.js.sync.push(config.exposes[expose]);
70
+ return {
71
+ id: `${config.name}:${formatKey}`,
72
+ name: formatKey,
73
+ path: expose,
74
+ assets,
75
+ hash: hashes?.get(`expose:${formatKey}`) ?? ''
76
+ };
77
+ });
78
+ }
79
+ function generateRemotes(config) {
80
+ return Object.keys(config.remotes).map((remote)=>({
81
+ federationContainerName: config.remotes[remote],
82
+ moduleName: remote,
83
+ alias: remote,
84
+ entry: '*'
85
+ }));
86
+ }
87
+ function generateShared(config, hashes, manifestOptions = {}) {
88
+ return Object.keys(config.shared).map((sharedName)=>{
89
+ const assets = getEmptyAssets();
90
+ if (config.shared[sharedName].eager) assets.js.sync.push(config.filename);
91
+ else if (false !== config.shared[sharedName].import) assets.js.sync.push(getSharedAssetPath(sharedName, manifestOptions));
92
+ return {
93
+ id: sharedName,
94
+ name: sharedName,
95
+ version: getManifestVersion(config.shared[sharedName].version),
96
+ requiredVersion: getManifestRequiredVersion(config.shared[sharedName].requiredVersion),
97
+ singleton: config.shared[sharedName].singleton,
98
+ hash: hashes?.get(`shared:${sharedName}`) ?? '',
99
+ assets
100
+ };
101
+ });
102
+ }
103
+ function resolveBundleKey(entryPoint, projectRoot, config) {
104
+ const relPath = toPosixPath(node_path.relative(projectRoot, entryPoint));
105
+ const normalizedRel = relPath.startsWith('./') ? relPath.slice(2) : relPath;
106
+ const normalizedRelNoExt = removeExtension(normalizedRel);
107
+ for (const [exposeKey, exposePath] of Object.entries(config.exposes)){
108
+ const normalizedExpose = toPosixPath(exposePath.startsWith('./') ? exposePath.slice(2) : exposePath);
109
+ if (normalizedRel === normalizedExpose || normalizedRelNoExt === removeExtension(normalizedExpose)) return `expose:${exposeKey.replace('./', '')}`;
110
+ }
111
+ if (removeExtension(node_path.basename(entryPoint)) === removeExtension(node_path.basename(config.filename))) return `container:${config.name}`;
112
+ const virtualSharedKey = resolveDevVirtualSharedKey(entryPoint, projectRoot, config);
113
+ if (virtualSharedKey) return virtualSharedKey;
114
+ const absPath = toPosixPath(node_path.resolve(entryPoint));
115
+ const nmMatch = absPath.match(/.*node_modules\/(.+)/);
116
+ if (nmMatch) {
117
+ const modulePath = removeExtension(nmMatch[1]);
118
+ const sharedKey = findSharedKeyForModulePath(modulePath, config);
119
+ if (sharedKey) return `shared:${sharedKey}`;
120
+ }
121
+ return null;
122
+ }
123
+ function normalizeManifestArgs(hashesOrOptions, manifestOptions) {
124
+ if (hashesOrOptions instanceof Map) return {
125
+ hashes: hashesOrOptions,
126
+ options: manifestOptions ?? {}
127
+ };
128
+ return {
129
+ hashes: void 0,
130
+ options: hashesOrOptions ?? {}
131
+ };
132
+ }
133
+ function readManifest(manifestPath) {
134
+ if (!node_fs.existsSync(manifestPath)) return;
135
+ return JSON.parse(node_fs.readFileSync(manifestPath, 'utf-8'));
136
+ }
137
+ function getSharedVirtualModuleName(sharedName) {
138
+ return sharedName.replaceAll('/', '_');
139
+ }
140
+ function getSharedVirtualModulePath(tmpDirPath, sharedName) {
141
+ return node_path.join(tmpDirPath, 'shared', `${getSharedVirtualModuleName(sharedName)}.js`);
142
+ }
143
+ function getSharedAssetPath(sharedName, manifestOptions) {
144
+ if ('development' === manifestOptions.target && manifestOptions.projectRoot && manifestOptions.tmpDirPath) return toPosixPath(node_path.relative(manifestOptions.projectRoot, getSharedVirtualModulePath(manifestOptions.tmpDirPath, sharedName)));
145
+ return `shared/${sharedName}.bundle`;
146
+ }
147
+ function resolveDevVirtualSharedKey(entryPoint, projectRoot, config) {
148
+ const relativePath = toPosixPath(node_path.relative(projectRoot, entryPoint));
149
+ const virtualSharedPrefix = `node_modules/${TMP_DIR_NAME}/shared/`;
150
+ if (!relativePath.startsWith(virtualSharedPrefix)) return null;
151
+ const virtualModuleName = removeExtension(relativePath.slice(virtualSharedPrefix.length));
152
+ const sharedKey = Object.keys(config.shared).find((sharedName)=>getSharedVirtualModuleName(sharedName) === virtualModuleName);
153
+ return sharedKey ? `shared:${sharedKey}` : null;
154
+ }
155
+ function findSharedKeyForModulePath(modulePath, config) {
156
+ const sharedEntries = Object.entries(config.shared).map(([sharedName, sharedConfig])=>{
157
+ const importName = 'string' == typeof sharedConfig.import ? sharedConfig.import : sharedName;
158
+ return {
159
+ importName,
160
+ sharedName
161
+ };
162
+ }).sort((a, b)=>b.importName.length - a.importName.length);
163
+ const normalizedModulePath = toPosixPath(modulePath);
164
+ for (const { importName, sharedName } of sharedEntries)if (normalizedModulePath === importName || normalizedModulePath.startsWith(`${importName}/`)) return sharedName;
165
+ return null;
166
+ }
167
+ function getManifestVersion(version) {
168
+ return 'string' == typeof version ? version : '';
169
+ }
170
+ function getManifestRequiredVersion(requiredVersion) {
171
+ return 'string' == typeof requiredVersion ? requiredVersion : '*';
172
+ }
173
+ function getEmptyAssets() {
174
+ return {
175
+ js: {
176
+ sync: [],
177
+ async: []
178
+ },
179
+ css: {
180
+ sync: [],
181
+ async: []
182
+ }
183
+ };
184
+ }
185
+ export { createManifest, getSharedVirtualModuleName, getSharedVirtualModulePath, recordBundleHash, updateManifest };
@@ -0,0 +1,8 @@
1
+ import type { ModuleFederationExtraOptions } from '../types';
2
+ export declare function normalizeExtraOptions(extraOptions?: ModuleFederationExtraOptions): {
3
+ flags: {
4
+ unstable_patchHMRClient: boolean;
5
+ unstable_patchInitializeCore: boolean;
6
+ unstable_patchRuntimeRequire: boolean;
7
+ };
8
+ };
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ function normalizeExtraOptions(extraOptions) {
31
+ return {
32
+ ...extraOptions,
33
+ flags: {
34
+ unstable_patchHMRClient: false,
35
+ unstable_patchInitializeCore: false,
36
+ unstable_patchRuntimeRequire: false,
37
+ ...extraOptions?.flags
38
+ }
39
+ };
40
+ }
41
+ __webpack_require__.d(__webpack_exports__, {
42
+ normalizeExtraOptions: ()=>normalizeExtraOptions
43
+ });
44
+ exports.normalizeExtraOptions = __webpack_exports__.normalizeExtraOptions;
45
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
46
+ "normalizeExtraOptions"
47
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
48
+ Object.defineProperty(exports, '__esModule', {
49
+ value: true
50
+ });
@@ -0,0 +1,13 @@
1
+ import "node:module";
2
+ function normalizeExtraOptions(extraOptions) {
3
+ return {
4
+ ...extraOptions,
5
+ flags: {
6
+ unstable_patchHMRClient: false,
7
+ unstable_patchInitializeCore: false,
8
+ unstable_patchRuntimeRequire: false,
9
+ ...extraOptions?.flags
10
+ }
11
+ };
12
+ }
13
+ export { normalizeExtraOptions };
@@ -0,0 +1,7 @@
1
+ import type { ModuleFederationConfig, ModuleFederationConfigNormalized } from '../types';
2
+ interface ProjectConfig {
3
+ projectRoot: string;
4
+ tmpDirPath: string;
5
+ }
6
+ export declare function normalizeOptions(options: ModuleFederationConfig, { projectRoot, tmpDirPath }: ProjectConfig): ModuleFederationConfigNormalized;
7
+ export {};
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, getters, values)=>{
14
+ var define = (defs, kind)=>{
15
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
+ enumerable: true,
17
+ [kind]: defs[key]
18
+ });
19
+ };
20
+ define(getters, "get");
21
+ define(values, "value");
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
26
+ })();
27
+ (()=>{
28
+ __webpack_require__.r = (exports1)=>{
29
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
30
+ value: 'Module'
31
+ });
32
+ Object.defineProperty(exports1, '__esModule', {
33
+ value: true
34
+ });
35
+ };
36
+ })();
37
+ var __webpack_exports__ = {};
38
+ __webpack_require__.r(__webpack_exports__);
39
+ __webpack_require__.d(__webpack_exports__, {
40
+ normalizeOptions: ()=>normalizeOptions
41
+ });
42
+ const external_node_fs_namespaceObject = require("node:fs");
43
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
44
+ const external_node_path_namespaceObject = require("node:path");
45
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
46
+ const external_constants_js_namespaceObject = require("./constants.js");
47
+ const external_helpers_js_namespaceObject = require("./helpers.js");
48
+ function normalizeOptions(options, { projectRoot, tmpDirPath }) {
49
+ const shared = getNormalizedShared(options, projectRoot);
50
+ const remotes = getNormalizedRemotes(options);
51
+ const exposes = getNormalizedExposes(options);
52
+ const shareStrategy = getNormalizedShareStrategy(options);
53
+ const plugins = getNormalizedPlugins(options, tmpDirPath, projectRoot);
54
+ return {
55
+ name: options.name,
56
+ filename: options.filename ?? external_constants_js_namespaceObject.DEFAULT_ENTRY_FILENAME,
57
+ remotes,
58
+ exposes,
59
+ shared,
60
+ shareStrategy,
61
+ plugins,
62
+ dts: options.dts ?? false
63
+ };
64
+ }
65
+ function getNormalizedRemotes(options) {
66
+ return {
67
+ ...options.remotes ?? {}
68
+ };
69
+ }
70
+ function getNormalizedExposes(options) {
71
+ return {
72
+ ...options.exposes ?? {}
73
+ };
74
+ }
75
+ function getNormalizedShared(options, projectRoot) {
76
+ const pkg = getProjectPackageJson(projectRoot);
77
+ const sharedInput = options.shared ?? {};
78
+ const shared = Object.entries(sharedInput).reduce((acc, [sharedName, config])=>{
79
+ if ('string' == typeof config) return acc;
80
+ const metroSharedConfig = {
81
+ ...config
82
+ };
83
+ acc[sharedName] = metroSharedConfig;
84
+ return acc;
85
+ }, {});
86
+ if (!options.exposes) for (const sharedName of Object.keys(shared))shared[sharedName].eager = true;
87
+ for (const sharedName of Object.keys(shared))if (!shared[sharedName].requiredVersion) shared[sharedName].requiredVersion = pkg.dependencies?.[sharedName] || pkg.devDependencies?.[sharedName];
88
+ if (!shared['react-native/Libraries/Network/RCTNetworking']) {
89
+ const reactNativeSharedConfig = shared['react-native'];
90
+ shared['react-native/Libraries/Network/RCTNetworking'] = reactNativeSharedConfig;
91
+ }
92
+ return shared;
93
+ }
94
+ function getNormalizedShareStrategy(options) {
95
+ return options.shareStrategy ?? 'loaded-first';
96
+ }
97
+ function getNormalizedPlugins(options, tmpDirPath, projectRoot) {
98
+ const runtimePlugins = getNormalizedRuntimePlugins(options);
99
+ const plugins = options.plugins ?? [];
100
+ const allPlugins = [
101
+ require.resolve('../modules/metroCorePlugin.ts'),
102
+ ...runtimePlugins,
103
+ ...plugins
104
+ ];
105
+ const deduplicatedPlugins = Array.from(new Set(allPlugins));
106
+ return deduplicatedPlugins.map((pluginPath)=>{
107
+ if (!isLocalPluginPath(pluginPath, projectRoot)) return pluginPath;
108
+ const resolvedPluginPath = external_node_path_default().isAbsolute(pluginPath) ? pluginPath : external_node_path_default().resolve(projectRoot, pluginPath);
109
+ return (0, external_helpers_js_namespaceObject.toPosixPath)(external_node_path_default().relative(tmpDirPath, resolvedPluginPath));
110
+ });
111
+ }
112
+ function isLocalPluginPath(pluginPath, projectRoot) {
113
+ if (external_node_path_default().isAbsolute(pluginPath)) return true;
114
+ if (pluginPath.startsWith('./') || pluginPath.startsWith('../')) return true;
115
+ return external_node_fs_default().existsSync(external_node_path_default().resolve(projectRoot, pluginPath));
116
+ }
117
+ function getNormalizedRuntimePlugins(options) {
118
+ const runtimePlugins = options.runtimePlugins ?? [];
119
+ const normalizedRuntimePlugins = [];
120
+ runtimePlugins.forEach((runtimePlugin)=>{
121
+ if ('string' == typeof runtimePlugin) return void normalizedRuntimePlugins.push(runtimePlugin);
122
+ if (Array.isArray(runtimePlugin)) {
123
+ const [pluginPath] = runtimePlugin;
124
+ if ('string' == typeof pluginPath) normalizedRuntimePlugins.push(pluginPath);
125
+ }
126
+ });
127
+ return normalizedRuntimePlugins;
128
+ }
129
+ function getProjectPackageJson(projectRoot) {
130
+ const packageJsonPath = external_node_path_default().join(projectRoot, 'package.json');
131
+ return JSON.parse(external_node_fs_default().readFileSync(packageJsonPath, 'utf-8'));
132
+ }
133
+ exports.normalizeOptions = __webpack_exports__.normalizeOptions;
134
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
135
+ "normalizeOptions"
136
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
137
+ Object.defineProperty(exports, '__esModule', {
138
+ value: true
139
+ });
@@ -0,0 +1,92 @@
1
+ import __rslib_shim_module__ from "node:module";
2
+ const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
3
+ import node_fs from "node:fs";
4
+ import node_path from "node:path";
5
+ import { DEFAULT_ENTRY_FILENAME } from "./constants.mjs";
6
+ import { toPosixPath } from "./helpers.mjs";
7
+ function normalizeOptions(options, { projectRoot, tmpDirPath }) {
8
+ const shared = getNormalizedShared(options, projectRoot);
9
+ const remotes = getNormalizedRemotes(options);
10
+ const exposes = getNormalizedExposes(options);
11
+ const shareStrategy = getNormalizedShareStrategy(options);
12
+ const plugins = getNormalizedPlugins(options, tmpDirPath, projectRoot);
13
+ return {
14
+ name: options.name,
15
+ filename: options.filename ?? DEFAULT_ENTRY_FILENAME,
16
+ remotes,
17
+ exposes,
18
+ shared,
19
+ shareStrategy,
20
+ plugins,
21
+ dts: options.dts ?? false
22
+ };
23
+ }
24
+ function getNormalizedRemotes(options) {
25
+ return {
26
+ ...options.remotes ?? {}
27
+ };
28
+ }
29
+ function getNormalizedExposes(options) {
30
+ return {
31
+ ...options.exposes ?? {}
32
+ };
33
+ }
34
+ function getNormalizedShared(options, projectRoot) {
35
+ const pkg = getProjectPackageJson(projectRoot);
36
+ const sharedInput = options.shared ?? {};
37
+ const shared = Object.entries(sharedInput).reduce((acc, [sharedName, config])=>{
38
+ if ('string' == typeof config) return acc;
39
+ const metroSharedConfig = {
40
+ ...config
41
+ };
42
+ acc[sharedName] = metroSharedConfig;
43
+ return acc;
44
+ }, {});
45
+ if (!options.exposes) for (const sharedName of Object.keys(shared))shared[sharedName].eager = true;
46
+ for (const sharedName of Object.keys(shared))if (!shared[sharedName].requiredVersion) shared[sharedName].requiredVersion = pkg.dependencies?.[sharedName] || pkg.devDependencies?.[sharedName];
47
+ if (!shared['react-native/Libraries/Network/RCTNetworking']) {
48
+ const reactNativeSharedConfig = shared['react-native'];
49
+ shared['react-native/Libraries/Network/RCTNetworking'] = reactNativeSharedConfig;
50
+ }
51
+ return shared;
52
+ }
53
+ function getNormalizedShareStrategy(options) {
54
+ return options.shareStrategy ?? 'loaded-first';
55
+ }
56
+ function getNormalizedPlugins(options, tmpDirPath, projectRoot) {
57
+ const runtimePlugins = getNormalizedRuntimePlugins(options);
58
+ const plugins = options.plugins ?? [];
59
+ const allPlugins = [
60
+ require.resolve('../modules/metroCorePlugin.ts'),
61
+ ...runtimePlugins,
62
+ ...plugins
63
+ ];
64
+ const deduplicatedPlugins = Array.from(new Set(allPlugins));
65
+ return deduplicatedPlugins.map((pluginPath)=>{
66
+ if (!isLocalPluginPath(pluginPath, projectRoot)) return pluginPath;
67
+ const resolvedPluginPath = node_path.isAbsolute(pluginPath) ? pluginPath : node_path.resolve(projectRoot, pluginPath);
68
+ return toPosixPath(node_path.relative(tmpDirPath, resolvedPluginPath));
69
+ });
70
+ }
71
+ function isLocalPluginPath(pluginPath, projectRoot) {
72
+ if (node_path.isAbsolute(pluginPath)) return true;
73
+ if (pluginPath.startsWith('./') || pluginPath.startsWith('../')) return true;
74
+ return node_fs.existsSync(node_path.resolve(projectRoot, pluginPath));
75
+ }
76
+ function getNormalizedRuntimePlugins(options) {
77
+ const runtimePlugins = options.runtimePlugins ?? [];
78
+ const normalizedRuntimePlugins = [];
79
+ runtimePlugins.forEach((runtimePlugin)=>{
80
+ if ('string' == typeof runtimePlugin) return void normalizedRuntimePlugins.push(runtimePlugin);
81
+ if (Array.isArray(runtimePlugin)) {
82
+ const [pluginPath] = runtimePlugin;
83
+ if ('string' == typeof pluginPath) normalizedRuntimePlugins.push(pluginPath);
84
+ }
85
+ });
86
+ return normalizedRuntimePlugins;
87
+ }
88
+ function getProjectPackageJson(projectRoot) {
89
+ const packageJsonPath = node_path.join(projectRoot, 'package.json');
90
+ return JSON.parse(node_fs.readFileSync(packageJsonPath, 'utf-8'));
91
+ }
92
+ export { normalizeOptions };
@@ -0,0 +1,26 @@
1
+ import type { CustomResolver } from 'metro-resolver';
2
+ import type { ModuleFederationConfigNormalized } from '../types';
3
+ import type { VirtualModuleManager } from '../utils';
4
+ interface CreateResolveRequestOptions {
5
+ isRemote: boolean;
6
+ hacks: {
7
+ patchHMRClient: boolean;
8
+ patchInitializeCore: boolean;
9
+ };
10
+ paths: {
11
+ asyncRequire: string;
12
+ hostEntry: string;
13
+ initHost: string;
14
+ originalEntry: string;
15
+ remoteEntry: string;
16
+ remoteHMRSetup: string;
17
+ remoteModuleRegistry: string;
18
+ projectDir: string;
19
+ tmpDir: string;
20
+ };
21
+ options: ModuleFederationConfigNormalized;
22
+ vmManager: Pick<VirtualModuleManager, 'registerVirtualModule'>;
23
+ customResolver?: CustomResolver;
24
+ }
25
+ export declare function createResolveRequest({ vmManager, options, hacks, paths, isRemote, customResolver, }: CreateResolveRequestOptions): CustomResolver;
26
+ export {};