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