@module-federation/sdk 0.0.0-next-20250709075526 → 0.0.0-next-20250709090625

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 (36) hide show
  1. package/dist/index.cjs +812 -0
  2. package/dist/index.js +656 -0
  3. package/dist/normalize-webpack-path.cjs +77 -0
  4. package/dist/{normalize-webpack-path.esm.js → normalize-webpack-path.js} +6 -15
  5. package/dist/{src/types → types}/plugins/ModuleFederationPlugin.d.ts +0 -4
  6. package/package.json +16 -22
  7. package/dist/index.cjs.cjs +0 -821
  8. package/dist/index.cjs.d.ts +0 -1
  9. package/dist/index.esm.d.ts +0 -1
  10. package/dist/index.esm.js +0 -771
  11. package/dist/normalize-webpack-path.cjs.cjs +0 -42
  12. package/dist/normalize-webpack-path.cjs.d.ts +0 -1
  13. package/dist/normalize-webpack-path.esm.d.ts +0 -1
  14. package/dist/polyfills.cjs.cjs +0 -14
  15. package/dist/polyfills.esm.js +0 -12
  16. /package/dist/{src/constant.d.ts → constant.d.ts} +0 -0
  17. /package/dist/{src/createModuleFederationConfig.d.ts → createModuleFederationConfig.d.ts} +0 -0
  18. /package/dist/{src/dom.d.ts → dom.d.ts} +0 -0
  19. /package/dist/{src/env.d.ts → env.d.ts} +0 -0
  20. /package/dist/{src/generateSnapshotFromManifest.d.ts → generateSnapshotFromManifest.d.ts} +0 -0
  21. /package/dist/{src/index.d.ts → index.d.ts} +0 -0
  22. /package/dist/{src/logger.d.ts → logger.d.ts} +0 -0
  23. /package/dist/{src/node.d.ts → node.d.ts} +0 -0
  24. /package/dist/{src/normalize-webpack-path.d.ts → normalize-webpack-path.d.ts} +0 -0
  25. /package/dist/{src/normalizeOptions.d.ts → normalizeOptions.d.ts} +0 -0
  26. /package/dist/{src/types → types}/common.d.ts +0 -0
  27. /package/dist/{src/types → types}/hooks.d.ts +0 -0
  28. /package/dist/{src/types → types}/index.d.ts +0 -0
  29. /package/dist/{src/types → types}/manifest.d.ts +0 -0
  30. /package/dist/{src/types → types}/plugins/ContainerPlugin.d.ts +0 -0
  31. /package/dist/{src/types → types}/plugins/ContainerReferencePlugin.d.ts +0 -0
  32. /package/dist/{src/types → types}/plugins/SharePlugin.d.ts +0 -0
  33. /package/dist/{src/types → types}/plugins/index.d.ts +0 -0
  34. /package/dist/{src/types → types}/snapshot.d.ts +0 -0
  35. /package/dist/{src/types → types}/stats.d.ts +0 -0
  36. /package/dist/{src/utils.d.ts → utils.d.ts} +0 -0
package/dist/index.cjs ADDED
@@ -0,0 +1,812 @@
1
+ "use strict";
2
+ var __webpack_modules__ = {
3
+ "./src/node.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
4
+ __webpack_require__.d(__webpack_exports__, {
5
+ C: ()=>createScriptNode,
6
+ q: ()=>loadScriptNode
7
+ });
8
+ function importNodeModule(name) {
9
+ if (!name) throw new Error('import specifier is required');
10
+ const importModule = new Function('name', "return import(name)");
11
+ return importModule(name).then((res)=>res).catch((error)=>{
12
+ console.error(`Error importing module ${name}:`, error);
13
+ throw error;
14
+ });
15
+ }
16
+ const loadNodeFetch = async ()=>{
17
+ const fetchModule = await importNodeModule('node-fetch');
18
+ return fetchModule.default || fetchModule;
19
+ };
20
+ const lazyLoaderHookFetch = async (input, init, loaderHook)=>{
21
+ const hook = (url, init)=>loaderHook.lifecycle.fetch.emit(url, init);
22
+ const res = await hook(input, init || {});
23
+ if (!res || !(res instanceof Response)) {
24
+ const fetchFunction = 'undefined' == typeof fetch ? await loadNodeFetch() : fetch;
25
+ return fetchFunction(input, init || {});
26
+ }
27
+ return res;
28
+ };
29
+ const createScriptNode = 'undefined' == typeof ENV_TARGET || 'web' !== ENV_TARGET ? (url, cb, attrs, loaderHook)=>{
30
+ if (null == loaderHook ? void 0 : loaderHook.createScriptHook) {
31
+ const hookResult = loaderHook.createScriptHook(url);
32
+ if (hookResult && 'object' == typeof hookResult && 'url' in hookResult) url = hookResult.url;
33
+ }
34
+ let urlObj;
35
+ try {
36
+ urlObj = new URL(url);
37
+ } catch (e) {
38
+ console.error('Error constructing URL:', e);
39
+ cb(new Error(`Invalid URL: ${e}`));
40
+ return;
41
+ }
42
+ const getFetch = async ()=>{
43
+ if (null == loaderHook ? void 0 : loaderHook.fetch) return (input, init)=>lazyLoaderHookFetch(input, init, loaderHook);
44
+ return 'undefined' == typeof fetch ? loadNodeFetch() : fetch;
45
+ };
46
+ const handleScriptFetch = async (f, urlObj)=>{
47
+ try {
48
+ var _vm_constants;
49
+ const res = await f(urlObj.href);
50
+ const data = await res.text();
51
+ const [path, vm] = await Promise.all([
52
+ importNodeModule('path'),
53
+ importNodeModule('vm')
54
+ ]);
55
+ const scriptContext = {
56
+ exports: {},
57
+ module: {
58
+ exports: {}
59
+ }
60
+ };
61
+ const urlDirname = urlObj.pathname.split('/').slice(0, -1).join('/');
62
+ const filename = path.basename(urlObj.pathname);
63
+ const script = new vm.Script(`(function(exports, module, require, __dirname, __filename) {${data}\n})`, {
64
+ filename,
65
+ importModuleDynamically: (null == (_vm_constants = vm.constants) ? void 0 : _vm_constants.USE_MAIN_CONTEXT_DEFAULT_LOADER) ?? importNodeModule
66
+ });
67
+ script.runInThisContext()(scriptContext.exports, scriptContext.module, eval('require'), urlDirname, filename);
68
+ const exportedInterface = scriptContext.module.exports || scriptContext.exports;
69
+ if (attrs && exportedInterface && attrs['globalName']) {
70
+ const container = exportedInterface[attrs['globalName']] || exportedInterface;
71
+ cb(void 0, container);
72
+ return;
73
+ }
74
+ cb(void 0, exportedInterface);
75
+ } catch (e) {
76
+ cb(e instanceof Error ? e : new Error(`Script execution error: ${e}`));
77
+ }
78
+ };
79
+ getFetch().then(async (f)=>{
80
+ if ((null == attrs ? void 0 : attrs['type']) === 'esm' || (null == attrs ? void 0 : attrs['type']) === 'module') return loadModule(urlObj.href, {
81
+ fetch: f,
82
+ vm: await importNodeModule('vm')
83
+ }).then(async (module)=>{
84
+ await module.evaluate();
85
+ cb(void 0, module.namespace);
86
+ }).catch((e)=>{
87
+ cb(e instanceof Error ? e : new Error(`Script execution error: ${e}`));
88
+ });
89
+ handleScriptFetch(f, urlObj);
90
+ }).catch((err)=>{
91
+ cb(err);
92
+ });
93
+ } : (url, cb, attrs, loaderHook)=>{
94
+ cb(new Error('createScriptNode is disabled in non-Node.js environment'));
95
+ };
96
+ const loadScriptNode = 'undefined' == typeof ENV_TARGET || 'web' !== ENV_TARGET ? (url, info)=>new Promise((resolve, reject)=>{
97
+ createScriptNode(url, (error, scriptContext)=>{
98
+ if (error) reject(error);
99
+ else {
100
+ var _info_attrs, _info_attrs1;
101
+ const remoteEntryKey = (null == info ? void 0 : null == (_info_attrs = info.attrs) ? void 0 : _info_attrs['globalName']) || `__FEDERATION_${null == info ? void 0 : null == (_info_attrs1 = info.attrs) ? void 0 : _info_attrs1['name']}:custom__`;
102
+ const entryExports = globalThis[remoteEntryKey] = scriptContext;
103
+ resolve(entryExports);
104
+ }
105
+ }, info.attrs, info.loaderHook);
106
+ }) : (url, info)=>{
107
+ throw new Error('loadScriptNode is disabled in non-Node.js environment');
108
+ };
109
+ async function loadModule(url, options) {
110
+ const { fetch: fetch1, vm } = options;
111
+ const response = await fetch1(url);
112
+ const code = await response.text();
113
+ const module = new vm.SourceTextModule(code, {
114
+ importModuleDynamically: async (specifier, script)=>{
115
+ const resolvedUrl = new URL(specifier, url).href;
116
+ return loadModule(resolvedUrl, options);
117
+ }
118
+ });
119
+ await module.link(async (specifier)=>{
120
+ const resolvedUrl = new URL(specifier, url).href;
121
+ const module = await loadModule(resolvedUrl, options);
122
+ return module;
123
+ });
124
+ return module;
125
+ }
126
+ }
127
+ };
128
+ var __webpack_module_cache__ = {};
129
+ function __webpack_require__(moduleId) {
130
+ var cachedModule = __webpack_module_cache__[moduleId];
131
+ if (void 0 !== cachedModule) return cachedModule.exports;
132
+ var module = __webpack_module_cache__[moduleId] = {
133
+ exports: {}
134
+ };
135
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
136
+ return module.exports;
137
+ }
138
+ (()=>{
139
+ __webpack_require__.d = (exports1, definition)=>{
140
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
141
+ enumerable: true,
142
+ get: definition[key]
143
+ });
144
+ };
145
+ })();
146
+ (()=>{
147
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
148
+ })();
149
+ (()=>{
150
+ __webpack_require__.r = (exports1)=>{
151
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
152
+ value: 'Module'
153
+ });
154
+ Object.defineProperty(exports1, '__esModule', {
155
+ value: true
156
+ });
157
+ };
158
+ })();
159
+ var __webpack_exports__ = {};
160
+ (()=>{
161
+ __webpack_require__.r(__webpack_exports__);
162
+ __webpack_require__.d(__webpack_exports__, {
163
+ safeWrapper: ()=>safeWrapper,
164
+ safeToString: ()=>safeToString,
165
+ composeKeyWithSeparator: ()=>composeKeyWithSeparator,
166
+ error: ()=>utils_error,
167
+ getProcessEnv: ()=>getProcessEnv,
168
+ moduleFederationPlugin: ()=>ModuleFederationPlugin_namespaceObject,
169
+ generateExposeFilename: ()=>generateExposeFilename,
170
+ isManifestProvider: ()=>isManifestProvider,
171
+ encodeName: ()=>encodeName,
172
+ BROWSER_LOG_KEY: ()=>BROWSER_LOG_KEY,
173
+ NameTransformSymbol: ()=>NameTransformSymbol,
174
+ logger: ()=>logger,
175
+ MFModuleType: ()=>MFModuleType,
176
+ MFPrefetchCommon: ()=>MFPrefetchCommon,
177
+ createLink: ()=>createLink,
178
+ createScript: ()=>createScript,
179
+ isDebugMode: ()=>isDebugMode,
180
+ generateSnapshotFromManifest: ()=>generateSnapshotFromManifest,
181
+ isRequiredVersion: ()=>isRequiredVersion,
182
+ getResourceUrl: ()=>getResourceUrl,
183
+ TEMP_DIR: ()=>TEMP_DIR,
184
+ normalizeOptions: ()=>normalizeOptions,
185
+ loadScriptNode: ()=>node.q,
186
+ StatsFileName: ()=>StatsFileName,
187
+ assert: ()=>assert,
188
+ MANIFEST_EXT: ()=>MANIFEST_EXT,
189
+ FederationModuleManifest: ()=>FederationModuleManifest,
190
+ MODULE_DEVTOOL_IDENTIFIER: ()=>MODULE_DEVTOOL_IDENTIFIER,
191
+ createLogger: ()=>createLogger,
192
+ loadScript: ()=>loadScript,
193
+ EncodedNameTransformMap: ()=>EncodedNameTransformMap,
194
+ inferAutoPublicPath: ()=>inferAutoPublicPath,
195
+ SEPARATOR: ()=>SEPARATOR,
196
+ sharePlugin: ()=>SharePlugin_namespaceObject,
197
+ ENCODE_NAME_PREFIX: ()=>ENCODE_NAME_PREFIX,
198
+ isBrowserEnv: ()=>isBrowserEnv,
199
+ isStaticResourcesEqual: ()=>isStaticResourcesEqual,
200
+ createScriptNode: ()=>node.C,
201
+ containerReferencePlugin: ()=>ContainerReferencePlugin_namespaceObject,
202
+ simpleJoinRemoteEntry: ()=>simpleJoinRemoteEntry,
203
+ NameTransformMap: ()=>NameTransformMap,
204
+ containerPlugin: ()=>ContainerPlugin_namespaceObject,
205
+ decodeName: ()=>decodeName,
206
+ warn: ()=>warn,
207
+ createModuleFederationConfig: ()=>createModuleFederationConfig,
208
+ generateShareFilename: ()=>generateShareFilename,
209
+ ManifestFileName: ()=>ManifestFileName,
210
+ isReactNativeEnv: ()=>isReactNativeEnv,
211
+ parseEntry: ()=>parseEntry
212
+ });
213
+ var ContainerPlugin_namespaceObject = {};
214
+ __webpack_require__.r(ContainerPlugin_namespaceObject);
215
+ var ContainerReferencePlugin_namespaceObject = {};
216
+ __webpack_require__.r(ContainerReferencePlugin_namespaceObject);
217
+ var ModuleFederationPlugin_namespaceObject = {};
218
+ __webpack_require__.r(ModuleFederationPlugin_namespaceObject);
219
+ var SharePlugin_namespaceObject = {};
220
+ __webpack_require__.r(SharePlugin_namespaceObject);
221
+ const FederationModuleManifest = 'federation-manifest.json';
222
+ const MANIFEST_EXT = '.json';
223
+ const BROWSER_LOG_KEY = 'FEDERATION_DEBUG';
224
+ const NameTransformSymbol = {
225
+ AT: '@',
226
+ HYPHEN: '-',
227
+ SLASH: '/'
228
+ };
229
+ const NameTransformMap = {
230
+ [NameTransformSymbol.AT]: 'scope_',
231
+ [NameTransformSymbol.HYPHEN]: '_',
232
+ [NameTransformSymbol.SLASH]: '__'
233
+ };
234
+ const EncodedNameTransformMap = {
235
+ [NameTransformMap[NameTransformSymbol.AT]]: NameTransformSymbol.AT,
236
+ [NameTransformMap[NameTransformSymbol.HYPHEN]]: NameTransformSymbol.HYPHEN,
237
+ [NameTransformMap[NameTransformSymbol.SLASH]]: NameTransformSymbol.SLASH
238
+ };
239
+ const SEPARATOR = ':';
240
+ const ManifestFileName = 'mf-manifest.json';
241
+ const StatsFileName = 'mf-stats.json';
242
+ const MFModuleType = {
243
+ NPM: 'npm',
244
+ APP: 'app'
245
+ };
246
+ const MODULE_DEVTOOL_IDENTIFIER = '__MF_DEVTOOLS_MODULE_INFO__';
247
+ const ENCODE_NAME_PREFIX = 'ENCODE_NAME_PREFIX';
248
+ const TEMP_DIR = '.federation';
249
+ const MFPrefetchCommon = {
250
+ identifier: 'MFDataPrefetch',
251
+ globalKey: '__PREFETCH__',
252
+ library: 'mf-data-prefetch',
253
+ exportsKey: '__PREFETCH_EXPORTS__',
254
+ fileName: 'bootstrap.js'
255
+ };
256
+ function isBrowserEnv() {
257
+ return 'undefined' != typeof window && void 0 !== window.document;
258
+ }
259
+ function isReactNativeEnv() {
260
+ var _navigator;
261
+ return 'undefined' != typeof navigator && (null == (_navigator = navigator) ? void 0 : _navigator.product) === 'ReactNative';
262
+ }
263
+ function isBrowserDebug() {
264
+ try {
265
+ if (isBrowserEnv() && window.localStorage) return Boolean(localStorage.getItem(BROWSER_LOG_KEY));
266
+ } catch (error) {}
267
+ return false;
268
+ }
269
+ function isDebugMode() {
270
+ if ('undefined' != typeof process && process.env && process.env['FEDERATION_DEBUG']) return Boolean(process.env['FEDERATION_DEBUG']);
271
+ if ('undefined' != typeof FEDERATION_DEBUG && Boolean(FEDERATION_DEBUG)) return true;
272
+ return isBrowserDebug();
273
+ }
274
+ const getProcessEnv = function() {
275
+ return 'undefined' != typeof process && process.env ? process.env : {};
276
+ };
277
+ const LOG_CATEGORY = '[ Federation Runtime ]';
278
+ const parseEntry = (str, devVerOrUrl, separator = SEPARATOR)=>{
279
+ const strSplit = str.split(separator);
280
+ const devVersionOrUrl = 'development' === getProcessEnv()['NODE_ENV'] && devVerOrUrl;
281
+ const defaultVersion = '*';
282
+ const isEntry = (s)=>s.startsWith('http') || s.includes(MANIFEST_EXT);
283
+ if (strSplit.length >= 2) {
284
+ let [name, ...versionOrEntryArr] = strSplit;
285
+ if (str.startsWith(separator)) {
286
+ name = strSplit.slice(0, 2).join(separator);
287
+ versionOrEntryArr = [
288
+ devVersionOrUrl || strSplit.slice(2).join(separator)
289
+ ];
290
+ }
291
+ let versionOrEntry = devVersionOrUrl || versionOrEntryArr.join(separator);
292
+ if (isEntry(versionOrEntry)) return {
293
+ name,
294
+ entry: versionOrEntry
295
+ };
296
+ return {
297
+ name,
298
+ version: versionOrEntry || defaultVersion
299
+ };
300
+ }
301
+ if (1 === strSplit.length) {
302
+ const [name] = strSplit;
303
+ if (devVersionOrUrl && isEntry(devVersionOrUrl)) return {
304
+ name,
305
+ entry: devVersionOrUrl
306
+ };
307
+ return {
308
+ name,
309
+ version: devVersionOrUrl || defaultVersion
310
+ };
311
+ }
312
+ throw `Invalid entry value: ${str}`;
313
+ };
314
+ const composeKeyWithSeparator = function(...args) {
315
+ if (!args.length) return '';
316
+ return args.reduce((sum, cur)=>{
317
+ if (!cur) return sum;
318
+ if (!sum) return cur;
319
+ return `${sum}${SEPARATOR}${cur}`;
320
+ }, '');
321
+ };
322
+ const encodeName = function(name, prefix = '', withExt = false) {
323
+ try {
324
+ const ext = withExt ? '.js' : '';
325
+ return `${prefix}${name.replace(new RegExp(`${NameTransformSymbol.AT}`, 'g'), NameTransformMap[NameTransformSymbol.AT]).replace(new RegExp(`${NameTransformSymbol.HYPHEN}`, 'g'), NameTransformMap[NameTransformSymbol.HYPHEN]).replace(new RegExp(`${NameTransformSymbol.SLASH}`, 'g'), NameTransformMap[NameTransformSymbol.SLASH])}${ext}`;
326
+ } catch (err) {
327
+ throw err;
328
+ }
329
+ };
330
+ const decodeName = function(name, prefix, withExt) {
331
+ try {
332
+ let decodedName = name;
333
+ if (prefix) {
334
+ if (!decodedName.startsWith(prefix)) return decodedName;
335
+ decodedName = decodedName.replace(new RegExp(prefix, 'g'), '');
336
+ }
337
+ decodedName = decodedName.replace(new RegExp(`${NameTransformMap[NameTransformSymbol.AT]}`, 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.AT]]).replace(new RegExp(`${NameTransformMap[NameTransformSymbol.SLASH]}`, 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.SLASH]]).replace(new RegExp(`${NameTransformMap[NameTransformSymbol.HYPHEN]}`, 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.HYPHEN]]);
338
+ if (withExt) decodedName = decodedName.replace('.js', '');
339
+ return decodedName;
340
+ } catch (err) {
341
+ throw err;
342
+ }
343
+ };
344
+ const generateExposeFilename = (exposeName, withExt)=>{
345
+ if (!exposeName) return '';
346
+ let expose = exposeName;
347
+ if ('.' === expose) expose = 'default_export';
348
+ if (expose.startsWith('./')) expose = expose.replace('./', '');
349
+ return encodeName(expose, '__federation_expose_', withExt);
350
+ };
351
+ const generateShareFilename = (pkgName, withExt)=>{
352
+ if (!pkgName) return '';
353
+ return encodeName(pkgName, '__federation_shared_', withExt);
354
+ };
355
+ const getResourceUrl = (module, sourceUrl)=>{
356
+ if ('getPublicPath' in module) {
357
+ let publicPath;
358
+ publicPath = module.getPublicPath.startsWith('function') ? new Function('return ' + module.getPublicPath)()() : new Function(module.getPublicPath)();
359
+ return `${publicPath}${sourceUrl}`;
360
+ }
361
+ if ('publicPath' in module) {
362
+ if (!isBrowserEnv() && !isReactNativeEnv() && 'ssrPublicPath' in module) return `${module.ssrPublicPath}${sourceUrl}`;
363
+ return `${module.publicPath}${sourceUrl}`;
364
+ }
365
+ console.warn('Cannot get resource URL. If in debug mode, please ignore.', module, sourceUrl);
366
+ return '';
367
+ };
368
+ const assert = (condition, msg)=>{
369
+ if (!condition) utils_error(msg);
370
+ };
371
+ const utils_error = (msg)=>{
372
+ throw new Error(`${LOG_CATEGORY}: ${msg}`);
373
+ };
374
+ const warn = (msg)=>{
375
+ console.warn(`${LOG_CATEGORY}: ${msg}`);
376
+ };
377
+ function safeToString(info) {
378
+ try {
379
+ return JSON.stringify(info, null, 2);
380
+ } catch (e) {
381
+ return '';
382
+ }
383
+ }
384
+ const VERSION_PATTERN_REGEXP = /^([\d^=v<>~]|[*xX]$)/;
385
+ function isRequiredVersion(str) {
386
+ return VERSION_PATTERN_REGEXP.test(str);
387
+ }
388
+ const simpleJoinRemoteEntry = (rPath, rName)=>{
389
+ if (!rPath) return rName;
390
+ const transformPath = (str)=>{
391
+ if ('.' === str) return '';
392
+ if (str.startsWith('./')) return str.replace('./', '');
393
+ if (str.startsWith('/')) {
394
+ const strWithoutSlash = str.slice(1);
395
+ if (strWithoutSlash.endsWith('/')) return strWithoutSlash.slice(0, -1);
396
+ return strWithoutSlash;
397
+ }
398
+ return str;
399
+ };
400
+ const transformedPath = transformPath(rPath);
401
+ if (!transformedPath) return rName;
402
+ if (transformedPath.endsWith('/')) return `${transformedPath}${rName}`;
403
+ return `${transformedPath}/${rName}`;
404
+ };
405
+ function inferAutoPublicPath(url) {
406
+ return url.replace(/#.*$/, '').replace(/\?.*$/, '').replace(/\/[^\/]+$/, '/');
407
+ }
408
+ function generateSnapshotFromManifest(manifest, options = {}) {
409
+ var _manifest_metaData, _manifest_metaData1;
410
+ const { remotes = {}, overrides = {}, version } = options;
411
+ let remoteSnapshot;
412
+ const getPublicPath = ()=>{
413
+ if (!('publicPath' in manifest.metaData)) return manifest.metaData.getPublicPath;
414
+ if ('auto' === manifest.metaData.publicPath && version) return inferAutoPublicPath(version);
415
+ return manifest.metaData.publicPath;
416
+ };
417
+ const overridesKeys = Object.keys(overrides);
418
+ let remotesInfo = {};
419
+ if (!Object.keys(remotes).length) {
420
+ var _manifest_remotes;
421
+ remotesInfo = (null == (_manifest_remotes = manifest.remotes) ? void 0 : _manifest_remotes.reduce((res, next)=>{
422
+ let matchedVersion;
423
+ const name = next.federationContainerName;
424
+ matchedVersion = overridesKeys.includes(name) ? overrides[name] : 'version' in next ? next.version : next.entry;
425
+ res[name] = {
426
+ matchedVersion
427
+ };
428
+ return res;
429
+ }, {})) || {};
430
+ }
431
+ Object.keys(remotes).forEach((key)=>remotesInfo[key] = {
432
+ matchedVersion: overridesKeys.includes(key) ? overrides[key] : remotes[key]
433
+ });
434
+ const { remoteEntry: { path: remoteEntryPath, name: remoteEntryName, type: remoteEntryType }, types: remoteTypes, buildInfo: { buildVersion }, globalName, ssrRemoteEntry } = manifest.metaData;
435
+ const { exposes } = manifest;
436
+ let basicRemoteSnapshot = {
437
+ version: version ? version : '',
438
+ buildVersion,
439
+ globalName,
440
+ remoteEntry: simpleJoinRemoteEntry(remoteEntryPath, remoteEntryName),
441
+ remoteEntryType,
442
+ remoteTypes: simpleJoinRemoteEntry(remoteTypes.path, remoteTypes.name),
443
+ remoteTypesZip: remoteTypes.zip || '',
444
+ remoteTypesAPI: remoteTypes.api || '',
445
+ remotesInfo,
446
+ shared: null == manifest ? void 0 : manifest.shared.map((item)=>({
447
+ assets: item.assets,
448
+ sharedName: item.name,
449
+ version: item.version
450
+ })),
451
+ modules: null == exposes ? void 0 : exposes.map((expose)=>({
452
+ moduleName: expose.name,
453
+ modulePath: expose.path,
454
+ assets: expose.assets
455
+ }))
456
+ };
457
+ if (null == (_manifest_metaData = manifest.metaData) ? void 0 : _manifest_metaData.prefetchInterface) {
458
+ const prefetchInterface = manifest.metaData.prefetchInterface;
459
+ basicRemoteSnapshot = {
460
+ ...basicRemoteSnapshot,
461
+ prefetchInterface
462
+ };
463
+ }
464
+ if (null == (_manifest_metaData1 = manifest.metaData) ? void 0 : _manifest_metaData1.prefetchEntry) {
465
+ const { path, name, type } = manifest.metaData.prefetchEntry;
466
+ basicRemoteSnapshot = {
467
+ ...basicRemoteSnapshot,
468
+ prefetchEntry: simpleJoinRemoteEntry(path, name),
469
+ prefetchEntryType: type
470
+ };
471
+ }
472
+ remoteSnapshot = 'publicPath' in manifest.metaData ? {
473
+ ...basicRemoteSnapshot,
474
+ publicPath: getPublicPath(),
475
+ ssrPublicPath: manifest.metaData.ssrPublicPath
476
+ } : {
477
+ ...basicRemoteSnapshot,
478
+ getPublicPath: getPublicPath()
479
+ };
480
+ if (ssrRemoteEntry) {
481
+ const fullSSRRemoteEntry = simpleJoinRemoteEntry(ssrRemoteEntry.path, ssrRemoteEntry.name);
482
+ remoteSnapshot.ssrRemoteEntry = fullSSRRemoteEntry;
483
+ remoteSnapshot.ssrRemoteEntryType = ssrRemoteEntry.type || 'commonjs-module';
484
+ }
485
+ return remoteSnapshot;
486
+ }
487
+ function isManifestProvider(moduleInfo) {
488
+ if ('remoteEntry' in moduleInfo && moduleInfo.remoteEntry.includes(MANIFEST_EXT)) return true;
489
+ return false;
490
+ }
491
+ function _define_property(obj, key, value) {
492
+ if (key in obj) Object.defineProperty(obj, key, {
493
+ value: value,
494
+ enumerable: true,
495
+ configurable: true,
496
+ writable: true
497
+ });
498
+ else obj[key] = value;
499
+ return obj;
500
+ }
501
+ const PREFIX = '[ Module Federation ]';
502
+ class Logger {
503
+ setPrefix(prefix) {
504
+ this.prefix = prefix;
505
+ }
506
+ log(...args) {
507
+ console.log(this.prefix, ...args);
508
+ }
509
+ warn(...args) {
510
+ console.log(this.prefix, ...args);
511
+ }
512
+ error(...args) {
513
+ console.log(this.prefix, ...args);
514
+ }
515
+ success(...args) {
516
+ console.log(this.prefix, ...args);
517
+ }
518
+ info(...args) {
519
+ console.log(this.prefix, ...args);
520
+ }
521
+ ready(...args) {
522
+ console.log(this.prefix, ...args);
523
+ }
524
+ debug(...args) {
525
+ if (isDebugMode()) console.log(this.prefix, ...args);
526
+ }
527
+ constructor(prefix){
528
+ _define_property(this, "prefix", void 0);
529
+ this.prefix = prefix;
530
+ }
531
+ }
532
+ function createLogger(prefix) {
533
+ return new Logger(prefix);
534
+ }
535
+ const logger = createLogger(PREFIX);
536
+ async function safeWrapper(callback, disableWarn) {
537
+ try {
538
+ const res = await callback();
539
+ return res;
540
+ } catch (e) {
541
+ disableWarn || warn(e);
542
+ return;
543
+ }
544
+ }
545
+ function isStaticResourcesEqual(url1, url2) {
546
+ const REG_EXP = /^(https?:)?\/\//i;
547
+ const relativeUrl1 = url1.replace(REG_EXP, '').replace(/\/$/, '');
548
+ const relativeUrl2 = url2.replace(REG_EXP, '').replace(/\/$/, '');
549
+ return relativeUrl1 === relativeUrl2;
550
+ }
551
+ function createScript(info) {
552
+ let script = null;
553
+ let needAttach = true;
554
+ let timeout = 20000;
555
+ let timeoutId;
556
+ const scripts = document.getElementsByTagName("script");
557
+ for(let i = 0; i < scripts.length; i++){
558
+ const s = scripts[i];
559
+ const scriptSrc = s.getAttribute('src');
560
+ if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {
561
+ script = s;
562
+ needAttach = false;
563
+ break;
564
+ }
565
+ }
566
+ if (!script) {
567
+ const attrs = info.attrs;
568
+ script = document.createElement("script");
569
+ script.type = (null == attrs ? void 0 : attrs['type']) === 'module' ? 'module' : "text/javascript";
570
+ let createScriptRes;
571
+ if (info.createScriptHook) {
572
+ createScriptRes = info.createScriptHook(info.url, info.attrs);
573
+ if (createScriptRes instanceof HTMLScriptElement) script = createScriptRes;
574
+ else if ('object' == typeof createScriptRes) {
575
+ if ("script" in createScriptRes && createScriptRes.script) script = createScriptRes.script;
576
+ if ('timeout' in createScriptRes && createScriptRes.timeout) timeout = createScriptRes.timeout;
577
+ }
578
+ }
579
+ if (!script.src) script.src = info.url;
580
+ if (attrs && !createScriptRes) Object.keys(attrs).forEach((name)=>{
581
+ if (script) {
582
+ if ('async' === name || 'defer' === name) script[name] = attrs[name];
583
+ else if (!script.getAttribute(name)) script.setAttribute(name, attrs[name]);
584
+ }
585
+ });
586
+ }
587
+ const onScriptComplete = async (prev, event)=>{
588
+ clearTimeout(timeoutId);
589
+ const onScriptCompleteCallback = ()=>{
590
+ if ((null == event ? void 0 : event.type) === 'error') (null == info ? void 0 : info.onErrorCallback) && (null == info || info.onErrorCallback(event));
591
+ else (null == info ? void 0 : info.cb) && (null == info || info.cb());
592
+ };
593
+ if (script) {
594
+ script.onerror = null;
595
+ script.onload = null;
596
+ safeWrapper(()=>{
597
+ const { needDeleteScript = true } = info;
598
+ if (needDeleteScript) (null == script ? void 0 : script.parentNode) && script.parentNode.removeChild(script);
599
+ });
600
+ if (prev && 'function' == typeof prev) {
601
+ const result = prev(event);
602
+ if (result instanceof Promise) {
603
+ const res = await result;
604
+ onScriptCompleteCallback();
605
+ return res;
606
+ }
607
+ onScriptCompleteCallback();
608
+ return result;
609
+ }
610
+ }
611
+ onScriptCompleteCallback();
612
+ };
613
+ script.onerror = onScriptComplete.bind(null, script.onerror);
614
+ script.onload = onScriptComplete.bind(null, script.onload);
615
+ timeoutId = setTimeout(()=>{
616
+ onScriptComplete(null, new Error(`Remote script "${info.url}" time-outed.`));
617
+ }, timeout);
618
+ return {
619
+ script,
620
+ needAttach
621
+ };
622
+ }
623
+ function createLink(info) {
624
+ let link = null;
625
+ let needAttach = true;
626
+ const links = document.getElementsByTagName('link');
627
+ for(let i = 0; i < links.length; i++){
628
+ const l = links[i];
629
+ const linkHref = l.getAttribute('href');
630
+ const linkRel = l.getAttribute('rel');
631
+ if (linkHref && isStaticResourcesEqual(linkHref, info.url) && linkRel === info.attrs['rel']) {
632
+ link = l;
633
+ needAttach = false;
634
+ break;
635
+ }
636
+ }
637
+ if (!link) {
638
+ link = document.createElement('link');
639
+ link.setAttribute('href', info.url);
640
+ let createLinkRes;
641
+ const attrs = info.attrs;
642
+ if (info.createLinkHook) {
643
+ createLinkRes = info.createLinkHook(info.url, attrs);
644
+ if (createLinkRes instanceof HTMLLinkElement) link = createLinkRes;
645
+ }
646
+ if (attrs && !createLinkRes) Object.keys(attrs).forEach((name)=>{
647
+ if (link && !link.getAttribute(name)) link.setAttribute(name, attrs[name]);
648
+ });
649
+ }
650
+ const onLinkComplete = (prev, event)=>{
651
+ const onLinkCompleteCallback = ()=>{
652
+ if ((null == event ? void 0 : event.type) === 'error') (null == info ? void 0 : info.onErrorCallback) && (null == info || info.onErrorCallback(event));
653
+ else (null == info ? void 0 : info.cb) && (null == info || info.cb());
654
+ };
655
+ if (link) {
656
+ link.onerror = null;
657
+ link.onload = null;
658
+ safeWrapper(()=>{
659
+ const { needDeleteLink = true } = info;
660
+ if (needDeleteLink) (null == link ? void 0 : link.parentNode) && link.parentNode.removeChild(link);
661
+ });
662
+ if (prev) {
663
+ const res = prev(event);
664
+ onLinkCompleteCallback();
665
+ return res;
666
+ }
667
+ }
668
+ onLinkCompleteCallback();
669
+ };
670
+ link.onerror = onLinkComplete.bind(null, link.onerror);
671
+ link.onload = onLinkComplete.bind(null, link.onload);
672
+ return {
673
+ link,
674
+ needAttach
675
+ };
676
+ }
677
+ function loadScript(url, info) {
678
+ const { attrs = {}, createScriptHook } = info;
679
+ return new Promise((resolve, reject)=>{
680
+ const { script, needAttach } = createScript({
681
+ url,
682
+ cb: resolve,
683
+ onErrorCallback: reject,
684
+ attrs: {
685
+ fetchpriority: 'high',
686
+ ...attrs
687
+ },
688
+ createScriptHook,
689
+ needDeleteScript: true
690
+ });
691
+ needAttach && document.head.appendChild(script);
692
+ });
693
+ }
694
+ var node = __webpack_require__("./src/node.ts");
695
+ function normalizeOptions(enableDefault, defaultOptions, key) {
696
+ return function(options) {
697
+ if (false === options) return false;
698
+ if (void 0 === options) if (enableDefault) return defaultOptions;
699
+ else return false;
700
+ if (true === options) return defaultOptions;
701
+ if (options && 'object' == typeof options) return {
702
+ ...defaultOptions,
703
+ ...options
704
+ };
705
+ throw new Error(`Unexpected type for \`${key}\`, expect boolean/undefined/object, got: ${typeof options}`);
706
+ };
707
+ }
708
+ const createModuleFederationConfig = (options)=>options;
709
+ })();
710
+ exports.BROWSER_LOG_KEY = __webpack_exports__.BROWSER_LOG_KEY;
711
+ exports.ENCODE_NAME_PREFIX = __webpack_exports__.ENCODE_NAME_PREFIX;
712
+ exports.EncodedNameTransformMap = __webpack_exports__.EncodedNameTransformMap;
713
+ exports.FederationModuleManifest = __webpack_exports__.FederationModuleManifest;
714
+ exports.MANIFEST_EXT = __webpack_exports__.MANIFEST_EXT;
715
+ exports.MFModuleType = __webpack_exports__.MFModuleType;
716
+ exports.MFPrefetchCommon = __webpack_exports__.MFPrefetchCommon;
717
+ exports.MODULE_DEVTOOL_IDENTIFIER = __webpack_exports__.MODULE_DEVTOOL_IDENTIFIER;
718
+ exports.ManifestFileName = __webpack_exports__.ManifestFileName;
719
+ exports.NameTransformMap = __webpack_exports__.NameTransformMap;
720
+ exports.NameTransformSymbol = __webpack_exports__.NameTransformSymbol;
721
+ exports.SEPARATOR = __webpack_exports__.SEPARATOR;
722
+ exports.StatsFileName = __webpack_exports__.StatsFileName;
723
+ exports.TEMP_DIR = __webpack_exports__.TEMP_DIR;
724
+ exports.assert = __webpack_exports__.assert;
725
+ exports.composeKeyWithSeparator = __webpack_exports__.composeKeyWithSeparator;
726
+ exports.containerPlugin = __webpack_exports__.containerPlugin;
727
+ exports.containerReferencePlugin = __webpack_exports__.containerReferencePlugin;
728
+ exports.createLink = __webpack_exports__.createLink;
729
+ exports.createLogger = __webpack_exports__.createLogger;
730
+ exports.createModuleFederationConfig = __webpack_exports__.createModuleFederationConfig;
731
+ exports.createScript = __webpack_exports__.createScript;
732
+ exports.createScriptNode = __webpack_exports__.createScriptNode;
733
+ exports.decodeName = __webpack_exports__.decodeName;
734
+ exports.encodeName = __webpack_exports__.encodeName;
735
+ exports.error = __webpack_exports__.error;
736
+ exports.generateExposeFilename = __webpack_exports__.generateExposeFilename;
737
+ exports.generateShareFilename = __webpack_exports__.generateShareFilename;
738
+ exports.generateSnapshotFromManifest = __webpack_exports__.generateSnapshotFromManifest;
739
+ exports.getProcessEnv = __webpack_exports__.getProcessEnv;
740
+ exports.getResourceUrl = __webpack_exports__.getResourceUrl;
741
+ exports.inferAutoPublicPath = __webpack_exports__.inferAutoPublicPath;
742
+ exports.isBrowserEnv = __webpack_exports__.isBrowserEnv;
743
+ exports.isDebugMode = __webpack_exports__.isDebugMode;
744
+ exports.isManifestProvider = __webpack_exports__.isManifestProvider;
745
+ exports.isReactNativeEnv = __webpack_exports__.isReactNativeEnv;
746
+ exports.isRequiredVersion = __webpack_exports__.isRequiredVersion;
747
+ exports.isStaticResourcesEqual = __webpack_exports__.isStaticResourcesEqual;
748
+ exports.loadScript = __webpack_exports__.loadScript;
749
+ exports.loadScriptNode = __webpack_exports__.loadScriptNode;
750
+ exports.logger = __webpack_exports__.logger;
751
+ exports.moduleFederationPlugin = __webpack_exports__.moduleFederationPlugin;
752
+ exports.normalizeOptions = __webpack_exports__.normalizeOptions;
753
+ exports.parseEntry = __webpack_exports__.parseEntry;
754
+ exports.safeToString = __webpack_exports__.safeToString;
755
+ exports.safeWrapper = __webpack_exports__.safeWrapper;
756
+ exports.sharePlugin = __webpack_exports__.sharePlugin;
757
+ exports.simpleJoinRemoteEntry = __webpack_exports__.simpleJoinRemoteEntry;
758
+ exports.warn = __webpack_exports__.warn;
759
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
760
+ "BROWSER_LOG_KEY",
761
+ "ENCODE_NAME_PREFIX",
762
+ "EncodedNameTransformMap",
763
+ "FederationModuleManifest",
764
+ "MANIFEST_EXT",
765
+ "MFModuleType",
766
+ "MFPrefetchCommon",
767
+ "MODULE_DEVTOOL_IDENTIFIER",
768
+ "ManifestFileName",
769
+ "NameTransformMap",
770
+ "NameTransformSymbol",
771
+ "SEPARATOR",
772
+ "StatsFileName",
773
+ "TEMP_DIR",
774
+ "assert",
775
+ "composeKeyWithSeparator",
776
+ "containerPlugin",
777
+ "containerReferencePlugin",
778
+ "createLink",
779
+ "createLogger",
780
+ "createModuleFederationConfig",
781
+ "createScript",
782
+ "createScriptNode",
783
+ "decodeName",
784
+ "encodeName",
785
+ "error",
786
+ "generateExposeFilename",
787
+ "generateShareFilename",
788
+ "generateSnapshotFromManifest",
789
+ "getProcessEnv",
790
+ "getResourceUrl",
791
+ "inferAutoPublicPath",
792
+ "isBrowserEnv",
793
+ "isDebugMode",
794
+ "isManifestProvider",
795
+ "isReactNativeEnv",
796
+ "isRequiredVersion",
797
+ "isStaticResourcesEqual",
798
+ "loadScript",
799
+ "loadScriptNode",
800
+ "logger",
801
+ "moduleFederationPlugin",
802
+ "normalizeOptions",
803
+ "parseEntry",
804
+ "safeToString",
805
+ "safeWrapper",
806
+ "sharePlugin",
807
+ "simpleJoinRemoteEntry",
808
+ "warn"
809
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
810
+ Object.defineProperty(exports, '__esModule', {
811
+ value: true
812
+ });