@module-federation/vite 1.9.8 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.umd.js CHANGED
@@ -342,6 +342,344 @@
342
342
  };
343
343
  }
344
344
 
345
+ function _catch(body, recover) {
346
+ try {
347
+ var result = body();
348
+ } catch (e) {
349
+ return recover(e);
350
+ }
351
+ if (result && result.then) {
352
+ return result.then(void 0, recover);
353
+ }
354
+ return result;
355
+ }
356
+ var DEFAULT_DEV_OPTIONS = {
357
+ disableLiveReload: true,
358
+ disableHotTypesReload: false,
359
+ disableDynamicRemoteTypeHints: false
360
+ };
361
+ var DYNAMIC_HINTS_PLUGIN = '@module-federation/dts-plugin/dynamic-remote-type-hints-plugin';
362
+ var getIPv4 = function getIPv4() {
363
+ return process.env['FEDERATION_IPV4'] || '127.0.0.1';
364
+ };
365
+ var forkDevWorkerPath = function () {
366
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
367
+ return require.resolve('@module-federation/dts-plugin/dist/fork-dev-worker.js');
368
+ }();
369
+ var DevWorker = /*#__PURE__*/function () {
370
+ function DevWorker(options) {
371
+ this.worker = core.rpc.createRpcWorker(forkDevWorkerPath, {}, undefined, false);
372
+ this.worker.connect(options);
373
+ }
374
+ var _proto = DevWorker.prototype;
375
+ _proto.update = function update() {
376
+ var _this$worker$process;
377
+ (_this$worker$process = this.worker.process) == null || _this$worker$process.send == null || _this$worker$process.send({
378
+ type: core.rpc.RpcGMCallTypes.CALL,
379
+ id: this.worker.id,
380
+ args: [undefined, 'update']
381
+ });
382
+ };
383
+ _proto.exit = function exit() {
384
+ this.worker.terminate();
385
+ };
386
+ return DevWorker;
387
+ }();
388
+ var normalizeDevOptions = function normalizeDevOptions(dev) {
389
+ if (dev === false) {
390
+ return false;
391
+ }
392
+ if (dev === true || typeof dev === 'undefined') {
393
+ return _extends({}, DEFAULT_DEV_OPTIONS);
394
+ }
395
+ return _extends({}, DEFAULT_DEV_OPTIONS, dev);
396
+ };
397
+ var buildDtsModuleFederationConfig = function buildDtsModuleFederationConfig(options) {
398
+ var exposes = {};
399
+ Object.entries(options.exposes).forEach(function (_ref) {
400
+ var key = _ref[0],
401
+ value = _ref[1];
402
+ if (typeof value === 'string') {
403
+ exposes[key] = value;
404
+ return;
405
+ }
406
+ var importValue = Array.isArray(value["import"]) ? value["import"][0] : value["import"];
407
+ if (importValue) {
408
+ exposes[key] = importValue;
409
+ }
410
+ });
411
+ var remotes = {};
412
+ Object.entries(options.remotes).forEach(function (_ref2) {
413
+ var _remote$entryGlobalNa, _remote$entryGlobalNa2;
414
+ var key = _ref2[0],
415
+ remote = _ref2[1];
416
+ if (typeof remote === 'string') {
417
+ remotes[key] = remote;
418
+ return;
419
+ }
420
+ if (!remote.entry) {
421
+ return;
422
+ }
423
+ var entryLooksLikeUrl = ((_remote$entryGlobalNa = remote.entryGlobalName) == null ? void 0 : _remote$entryGlobalNa.startsWith('http')) || ((_remote$entryGlobalNa2 = remote.entryGlobalName) == null ? void 0 : _remote$entryGlobalNa2.includes('.json'));
424
+ var entryGlobalName = entryLooksLikeUrl ? remote.name || key : remote.entryGlobalName || remote.name || key;
425
+ remotes[key] = entryGlobalName + "@" + remote.entry;
426
+ });
427
+ return _extends({}, options, {
428
+ exposes: exposes,
429
+ remotes: remotes
430
+ });
431
+ };
432
+ var resolveOutputDir = function resolveOutputDir(config) {
433
+ var outDir = config.build.outDir;
434
+ if (path__namespace.isAbsolute(outDir)) {
435
+ return path__namespace.relative(config.root, outDir);
436
+ }
437
+ return outDir;
438
+ };
439
+ var ensureRuntimePlugin = function ensureRuntimePlugin(options, pluginId) {
440
+ var hasPlugin = options.runtimePlugins.some(function (plugin) {
441
+ if (typeof plugin === 'string') {
442
+ return plugin === pluginId;
443
+ }
444
+ return plugin[0] === pluginId;
445
+ });
446
+ if (!hasPlugin) {
447
+ options.runtimePlugins.push(pluginId);
448
+ }
449
+ };
450
+ var normalizeDevDtsOptions = function normalizeDevDtsOptions(dts, context) {
451
+ var defaultGenerateTypes = {
452
+ compileInChildProcess: true
453
+ };
454
+ var defaultConsumeTypes = {
455
+ consumeAPITypes: true
456
+ };
457
+ return sdk.normalizeOptions(dtsPlugin.isTSProject(dts, context), {
458
+ generateTypes: defaultGenerateTypes,
459
+ consumeTypes: defaultConsumeTypes,
460
+ extraOptions: {},
461
+ displayErrorInTerminal: typeof dts === 'object' && dts ? dts.displayErrorInTerminal : undefined
462
+ }, 'mfOptions.dts')(dts);
463
+ };
464
+ var logDtsError = function logDtsError(error, dtsOptions) {
465
+ if (dtsOptions === false) {
466
+ return;
467
+ }
468
+ if (typeof dtsOptions === 'object' && dtsOptions && dtsOptions.displayErrorInTerminal === false) {
469
+ return;
470
+ }
471
+ console.error(error);
472
+ };
473
+ function pluginDts(options) {
474
+ if (options.dts === false) {
475
+ return [];
476
+ }
477
+ var dtsModuleFederationConfig = buildDtsModuleFederationConfig(options);
478
+ var resolvedConfig;
479
+ var devWorker;
480
+ var normalizedDevOptions;
481
+ var hasGeneratedBundle = false;
482
+ var devPlugin = {
483
+ name: 'module-federation-dts-dev',
484
+ apply: 'serve',
485
+ config: function config(_config) {
486
+ normalizedDevOptions = normalizeDevOptions(options.dev);
487
+ if (!normalizedDevOptions) {
488
+ return;
489
+ }
490
+ if (normalizedDevOptions.disableDynamicRemoteTypeHints) {
491
+ return;
492
+ }
493
+ ensureRuntimePlugin(options, DYNAMIC_HINTS_PLUGIN);
494
+ var define = _config.define ? _extends({}, _config.define) : {};
495
+ if (!('FEDERATION_IPV4' in define)) {
496
+ define.FEDERATION_IPV4 = JSON.stringify(getIPv4());
497
+ }
498
+ _config.define = define;
499
+ },
500
+ configResolved: function configResolved(config) {
501
+ resolvedConfig = config;
502
+ },
503
+ configureServer: function configureServer(server) {
504
+ if (!normalizedDevOptions || !resolvedConfig) {
505
+ return;
506
+ }
507
+ var devOptions = normalizedDevOptions;
508
+ if (devOptions.disableDynamicRemoteTypeHints && devOptions.disableHotTypesReload && devOptions.disableLiveReload) {
509
+ return;
510
+ }
511
+ if (!options.name) {
512
+ throw new Error('name is required if you want to enable dev server!');
513
+ }
514
+ var outputDir = resolveOutputDir(resolvedConfig);
515
+ var normalizedDtsOptions = normalizeDevDtsOptions(options.dts, resolvedConfig.root);
516
+ if (typeof normalizedDtsOptions !== 'object') {
517
+ return;
518
+ }
519
+ var normalizedGenerateTypes = sdk.normalizeOptions(Boolean(normalizedDtsOptions), {
520
+ compileInChildProcess: true
521
+ }, 'mfOptions.dts.generateTypes')(normalizedDtsOptions.generateTypes);
522
+ var remote = normalizedGenerateTypes === false ? undefined : _extends({
523
+ implementation: normalizedDtsOptions.implementation,
524
+ context: resolvedConfig.root,
525
+ outputDir: outputDir,
526
+ moduleFederationConfig: _extends({}, dtsModuleFederationConfig),
527
+ hostRemoteTypesFolder: normalizedGenerateTypes.typesFolder || '@mf-types'
528
+ }, normalizedGenerateTypes, {
529
+ typesFolder: '.dev-server'
530
+ });
531
+ if (remote && !remote.tsConfigPath && typeof normalizedDtsOptions === 'object' && normalizedDtsOptions.tsConfigPath) {
532
+ remote.tsConfigPath = normalizedDtsOptions.tsConfigPath;
533
+ }
534
+ var normalizedConsumeTypes = sdk.normalizeOptions(Boolean(normalizedDtsOptions), {
535
+ consumeAPITypes: true
536
+ }, 'mfOptions.dts.consumeTypes')(normalizedDtsOptions.consumeTypes);
537
+ var host = normalizedConsumeTypes === false ? undefined : _extends({
538
+ implementation: normalizedDtsOptions.implementation,
539
+ context: resolvedConfig.root,
540
+ moduleFederationConfig: dtsModuleFederationConfig,
541
+ typesFolder: normalizedConsumeTypes.typesFolder || '@mf-types',
542
+ abortOnError: false
543
+ }, normalizedConsumeTypes);
544
+ var extraOptions = normalizedDtsOptions.extraOptions || {};
545
+ if (!remote && !host && devOptions.disableLiveReload) {
546
+ return;
547
+ }
548
+ var startDevWorker = function startDevWorker() {
549
+ try {
550
+ var _temp2 = function _temp2() {
551
+ var _server$httpServer;
552
+ devWorker = new DevWorker({
553
+ name: options.name,
554
+ remote: remote,
555
+ host: host ? _extends({}, host, {
556
+ remoteTypeUrls: remoteTypeUrls
557
+ }) : undefined,
558
+ extraOptions: extraOptions,
559
+ disableLiveReload: devOptions.disableLiveReload,
560
+ disableHotTypesReload: devOptions.disableHotTypesReload
561
+ });
562
+ var update = function update() {
563
+ var _devWorker;
564
+ return (_devWorker = devWorker) == null ? void 0 : _devWorker.update();
565
+ };
566
+ server.watcher.on('change', update);
567
+ server.watcher.on('add', update);
568
+ server.watcher.on('unlink', update);
569
+ (_server$httpServer = server.httpServer) == null || _server$httpServer.once('close', function () {
570
+ var _devWorker2;
571
+ (_devWorker2 = devWorker) == null || _devWorker2.exit();
572
+ server.watcher.off('change', update);
573
+ server.watcher.off('add', update);
574
+ server.watcher.off('unlink', update);
575
+ });
576
+ };
577
+ var remoteTypeUrls;
578
+ var _temp = function () {
579
+ if (host) {
580
+ return Promise.resolve(new Promise(function (resolve) {
581
+ dtsPlugin.consumeTypesAPI({
582
+ host: host,
583
+ extraOptions: extraOptions,
584
+ displayErrorInTerminal: normalizedDtsOptions.displayErrorInTerminal
585
+ }, resolve);
586
+ })).then(function (_Promise) {
587
+ remoteTypeUrls = _Promise;
588
+ });
589
+ }
590
+ }();
591
+ return Promise.resolve(_temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp));
592
+ } catch (e) {
593
+ return Promise.reject(e);
594
+ }
595
+ };
596
+ startDevWorker()["catch"](function (error) {
597
+ logDtsError(error, normalizedDtsOptions);
598
+ });
599
+ }
600
+ };
601
+ var buildPlugin = {
602
+ name: 'module-federation-dts-build',
603
+ apply: 'build',
604
+ configResolved: function configResolved(config) {
605
+ resolvedConfig = config;
606
+ },
607
+ generateBundle: function generateBundle() {
608
+ try {
609
+ var _temp6 = function _temp6() {
610
+ var generateOptions;
611
+ try {
612
+ generateOptions = dtsPlugin.normalizeGenerateTypesOptions({
613
+ context: context,
614
+ outputDir: outputDir,
615
+ dtsOptions: normalizedDtsOptions,
616
+ pluginOptions: dtsModuleFederationConfig
617
+ });
618
+ } catch (error) {
619
+ logDtsError(error, normalizedDtsOptions);
620
+ return;
621
+ }
622
+ if (!generateOptions) {
623
+ return;
624
+ }
625
+ var _temp4 = _catch(function () {
626
+ return Promise.resolve(dtsPlugin.generateTypesAPI({
627
+ dtsManagerOptions: generateOptions
628
+ })).then(function () {});
629
+ }, function (error) {
630
+ logDtsError(error, normalizedDtsOptions);
631
+ });
632
+ if (_temp4 && _temp4.then) return _temp4.then(function () {});
633
+ };
634
+ if (hasGeneratedBundle) {
635
+ return Promise.resolve();
636
+ }
637
+ hasGeneratedBundle = true;
638
+ if (!resolvedConfig) {
639
+ return Promise.resolve();
640
+ }
641
+ var normalizedDtsOptions;
642
+ try {
643
+ normalizedDtsOptions = dtsPlugin.normalizeDtsOptions(dtsModuleFederationConfig, resolvedConfig.root);
644
+ } catch (error) {
645
+ logDtsError(error, options.dts);
646
+ return Promise.resolve();
647
+ }
648
+ if (typeof normalizedDtsOptions !== 'object') {
649
+ return Promise.resolve();
650
+ }
651
+ var context = resolvedConfig.root;
652
+ var outputDir = resolveOutputDir(resolvedConfig);
653
+ var consumeOptions;
654
+ try {
655
+ consumeOptions = dtsPlugin.normalizeConsumeTypesOptions({
656
+ context: context,
657
+ dtsOptions: normalizedDtsOptions,
658
+ pluginOptions: dtsModuleFederationConfig
659
+ });
660
+ } catch (error) {
661
+ logDtsError(error, normalizedDtsOptions);
662
+ return Promise.resolve();
663
+ }
664
+ var _temp5 = function (_consumeOptions) {
665
+ if ((_consumeOptions = consumeOptions) != null && (_consumeOptions = _consumeOptions.host) != null && _consumeOptions.typesOnBuild) {
666
+ var _temp3 = _catch(function () {
667
+ return Promise.resolve(dtsPlugin.consumeTypesAPI(consumeOptions)).then(function () {});
668
+ }, function (error) {
669
+ logDtsError(error, normalizedDtsOptions);
670
+ });
671
+ if (_temp3 && _temp3.then) return _temp3.then(function () {});
672
+ }
673
+ }();
674
+ return Promise.resolve(_temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5));
675
+ } catch (e) {
676
+ return Promise.reject(e);
677
+ }
678
+ }
679
+ };
680
+ return [devPlugin, buildPlugin];
681
+ }
682
+
345
683
  function normalizeExposesItem(key, item) {
346
684
  var importPath = '';
347
685
  if (typeof item === 'string') {
@@ -534,7 +872,8 @@
534
872
  ignoreOrigin: options.ignoreOrigin || false,
535
873
  virtualModuleDir: options.virtualModuleDir || '__mf__virtual',
536
874
  hostInitInjectLocation: options.hostInitInjectLocation || 'html',
537
- bundleAllCSS: options.bundleAllCSS || false
875
+ bundleAllCSS: options.bundleAllCSS || false,
876
+ moduleParseTimeout: options.moduleParseTimeout || 10
538
877
  };
539
878
  }
540
879
 
@@ -1400,15 +1739,28 @@
1400
1739
  }
1401
1740
  };
1402
1741
 
1403
- var _resolve,
1404
- promise = new Promise(function (resolve, reject) {
1405
- _resolve = resolve;
1406
- });
1742
+ var _resolve, _parseTimeout;
1743
+ var promise = new Promise(function (resolve, reject) {
1744
+ _resolve = function _resolve(v) {
1745
+ clearTimeout(_parseTimeout);
1746
+ _parseTimeout = null;
1747
+ resolve(v);
1748
+ };
1749
+ });
1750
+ function setParseTimeout(timeout) {
1751
+ if (!_parseTimeout) {
1752
+ _parseTimeout = setTimeout(function () {
1753
+ console.warn("Parse timeout (" + timeout + "s) - forcing resolve");
1754
+ _resolve(1);
1755
+ }, timeout * 1000);
1756
+ }
1757
+ }
1407
1758
  var parsePromise = promise;
1408
1759
  var exposesParseEnd = false;
1409
1760
  var parseStartSet = new Set();
1410
1761
  var parseEndSet = new Set();
1411
- function pluginModuleParseEnd (excludeFn) {
1762
+ function pluginModuleParseEnd (excludeFn, options) {
1763
+ setParseTimeout(options.moduleParseTimeout);
1412
1764
  return [{
1413
1765
  name: '_',
1414
1766
  apply: 'serve',
@@ -1429,447 +1781,109 @@
1429
1781
  }, {
1430
1782
  enforce: 'post',
1431
1783
  name: 'parseEnd',
1432
- apply: 'build',
1433
- moduleParsed: function moduleParsed(module) {
1434
- var id = module.id;
1435
- if (id === VIRTUAL_EXPOSES) {
1436
- // When the entry JS file is empty and only contains exposes export code, it’s necessary to wait for the exposes modules to be resolved in order to collect the dependencies being used.
1437
- exposesParseEnd = true;
1438
- }
1439
- if (excludeFn(id)) {
1440
- return;
1441
- }
1442
- parseEndSet.add(id);
1443
- if (exposesParseEnd && parseStartSet.size === parseEndSet.size) {
1444
- _resolve(1);
1445
- }
1446
- }
1447
- }];
1448
- }
1449
-
1450
- var filter = pluginutils.createFilter();
1451
- function pluginProxyRemoteEntry () {
1452
- var viteConfig, _command;
1453
- return {
1454
- name: 'proxyRemoteEntry',
1455
- enforce: 'post',
1456
- configResolved: function configResolved(config) {
1457
- viteConfig = config;
1458
- },
1459
- config: function config(_config, _ref) {
1460
- var command = _ref.command;
1461
- _command = command;
1462
- },
1463
- resolveId: function resolveId(id) {
1464
- if (id === REMOTE_ENTRY_ID) {
1465
- return REMOTE_ENTRY_ID;
1466
- }
1467
- if (id === VIRTUAL_EXPOSES) {
1468
- return VIRTUAL_EXPOSES;
1469
- }
1470
- if (_command === 'serve' && id.includes(getHostAutoInitPath())) {
1471
- return id;
1472
- }
1473
- },
1474
- load: function load(id) {
1475
- if (id === REMOTE_ENTRY_ID) {
1476
- return parsePromise.then(function (_) {
1477
- return generateRemoteEntry(getNormalizeModuleFederationOptions());
1478
- });
1479
- }
1480
- if (id === VIRTUAL_EXPOSES) {
1481
- return generateExposes();
1482
- }
1483
- if (_command === 'serve' && id.includes(getHostAutoInitPath())) {
1484
- return id;
1485
- }
1486
- },
1487
- transform: function transform(code, id) {
1488
- var transformedCode = function () {
1489
- if (!filter(id)) return;
1490
- if (id.includes(REMOTE_ENTRY_ID)) {
1491
- return parsePromise.then(function (_) {
1492
- return generateRemoteEntry(getNormalizeModuleFederationOptions());
1493
- });
1494
- }
1495
- if (id === VIRTUAL_EXPOSES) {
1496
- return generateExposes();
1497
- }
1498
- if (id.includes(getHostAutoInitPath())) {
1499
- var options = getNormalizeModuleFederationOptions();
1500
- if (_command === 'serve') {
1501
- var _viteConfig$server, _viteConfig$server2;
1502
- var host = typeof ((_viteConfig$server = viteConfig.server) == null ? void 0 : _viteConfig$server.host) === 'string' && viteConfig.server.host !== '0.0.0.0' ? viteConfig.server.host : 'localhost';
1503
- var publicPath = JSON.stringify(resolvePublicPath(options, viteConfig.base) + options.filename);
1504
- return "\n const origin = (window && " + !options.ignoreOrigin + ") ? window.origin : \"//" + host + ":" + ((_viteConfig$server2 = viteConfig.server) == null ? void 0 : _viteConfig$server2.port) + "\"\n const remoteEntryPromise = await import(origin + " + publicPath + ")\n // __tla only serves as a hack for vite-plugin-top-level-await.\n Promise.resolve(remoteEntryPromise)\n .then(remoteEntry => {\n return Promise.resolve(remoteEntry.__tla)\n .then(remoteEntry.init).catch(remoteEntry.init)\n })\n ";
1505
- }
1506
- return code;
1507
- }
1508
- }();
1509
- return mapCodeToCodeWithSourcemap(transformedCode);
1510
- }
1511
- };
1512
- }
1513
-
1514
- pluginutils.createFilter();
1515
- function pluginProxyRemotes (options) {
1516
- var remotes = options.remotes;
1517
- return {
1518
- name: 'proxyRemotes',
1519
- config: function config(_config, _ref) {
1520
- var _command = _ref.command;
1521
- Object.keys(remotes).forEach(function (key) {
1522
- var remote = remotes[key];
1523
- _config.resolve.alias.push({
1524
- find: new RegExp("^(" + remote.name + "(/.*|$))"),
1525
- replacement: '$1',
1526
- customResolver: function customResolver(source) {
1527
- var remoteModule = getRemoteVirtualModule(source, _command);
1528
- addUsedRemote(remote.name, source);
1529
- return remoteModule.getPath();
1530
- }
1531
- });
1532
- });
1533
- }
1534
- };
1535
- }
1536
-
1537
- function _catch(body, recover) {
1538
- try {
1539
- var result = body();
1540
- } catch (e) {
1541
- return recover(e);
1542
- }
1543
- if (result && result.then) {
1544
- return result.then(void 0, recover);
1545
- }
1546
- return result;
1547
- }
1548
- var DEFAULT_DEV_OPTIONS = {
1549
- disableLiveReload: true,
1550
- disableHotTypesReload: false,
1551
- disableDynamicRemoteTypeHints: false
1552
- };
1553
- var DYNAMIC_HINTS_PLUGIN = '@module-federation/dts-plugin/dynamic-remote-type-hints-plugin';
1554
- var getIPv4 = function getIPv4() {
1555
- return process.env['FEDERATION_IPV4'] || '127.0.0.1';
1556
- };
1557
- var forkDevWorkerPath = function () {
1558
- // eslint-disable-next-line @typescript-eslint/no-var-requires
1559
- return require.resolve('@module-federation/dts-plugin/dist/fork-dev-worker.js');
1560
- }();
1561
- var DevWorker = /*#__PURE__*/function () {
1562
- function DevWorker(options) {
1563
- this.worker = core.rpc.createRpcWorker(forkDevWorkerPath, {}, undefined, false);
1564
- this.worker.connect(options);
1565
- }
1566
- var _proto = DevWorker.prototype;
1567
- _proto.update = function update() {
1568
- var _this$worker$process;
1569
- (_this$worker$process = this.worker.process) == null || _this$worker$process.send == null || _this$worker$process.send({
1570
- type: core.rpc.RpcGMCallTypes.CALL,
1571
- id: this.worker.id,
1572
- args: [undefined, 'update']
1573
- });
1574
- };
1575
- _proto.exit = function exit() {
1576
- this.worker.terminate();
1577
- };
1578
- return DevWorker;
1579
- }();
1580
- var normalizeDevOptions = function normalizeDevOptions(dev) {
1581
- if (dev === false) {
1582
- return false;
1583
- }
1584
- if (dev === true || typeof dev === 'undefined') {
1585
- return _extends({}, DEFAULT_DEV_OPTIONS);
1586
- }
1587
- return _extends({}, DEFAULT_DEV_OPTIONS, dev);
1588
- };
1589
- var buildDtsModuleFederationConfig = function buildDtsModuleFederationConfig(options) {
1590
- var exposes = {};
1591
- Object.entries(options.exposes).forEach(function (_ref) {
1592
- var key = _ref[0],
1593
- value = _ref[1];
1594
- if (typeof value === 'string') {
1595
- exposes[key] = value;
1596
- return;
1597
- }
1598
- var importValue = Array.isArray(value["import"]) ? value["import"][0] : value["import"];
1599
- if (importValue) {
1600
- exposes[key] = importValue;
1601
- }
1602
- });
1603
- var remotes = {};
1604
- Object.entries(options.remotes).forEach(function (_ref2) {
1605
- var _remote$entryGlobalNa, _remote$entryGlobalNa2;
1606
- var key = _ref2[0],
1607
- remote = _ref2[1];
1608
- if (typeof remote === 'string') {
1609
- remotes[key] = remote;
1610
- return;
1611
- }
1612
- if (!remote.entry) {
1613
- return;
1614
- }
1615
- var entryLooksLikeUrl = ((_remote$entryGlobalNa = remote.entryGlobalName) == null ? void 0 : _remote$entryGlobalNa.startsWith('http')) || ((_remote$entryGlobalNa2 = remote.entryGlobalName) == null ? void 0 : _remote$entryGlobalNa2.includes('.json'));
1616
- var entryGlobalName = entryLooksLikeUrl ? remote.name || key : remote.entryGlobalName || remote.name || key;
1617
- remotes[key] = entryGlobalName + "@" + remote.entry;
1618
- });
1619
- return _extends({}, options, {
1620
- exposes: exposes,
1621
- remotes: remotes
1622
- });
1623
- };
1624
- var resolveOutputDir = function resolveOutputDir(config) {
1625
- var outDir = config.build.outDir;
1626
- if (path__namespace.isAbsolute(outDir)) {
1627
- return path__namespace.relative(config.root, outDir);
1628
- }
1629
- return outDir;
1630
- };
1631
- var ensureRuntimePlugin = function ensureRuntimePlugin(options, pluginId) {
1632
- var hasPlugin = options.runtimePlugins.some(function (plugin) {
1633
- if (typeof plugin === 'string') {
1634
- return plugin === pluginId;
1635
- }
1636
- return plugin[0] === pluginId;
1637
- });
1638
- if (!hasPlugin) {
1639
- options.runtimePlugins.push(pluginId);
1640
- }
1641
- };
1642
- var normalizeDevDtsOptions = function normalizeDevDtsOptions(dts, context) {
1643
- var defaultGenerateTypes = {
1644
- compileInChildProcess: true
1645
- };
1646
- var defaultConsumeTypes = {
1647
- consumeAPITypes: true
1648
- };
1649
- return sdk.normalizeOptions(dtsPlugin.isTSProject(dts, context), {
1650
- generateTypes: defaultGenerateTypes,
1651
- consumeTypes: defaultConsumeTypes,
1652
- extraOptions: {},
1653
- displayErrorInTerminal: typeof dts === 'object' && dts ? dts.displayErrorInTerminal : undefined
1654
- }, 'mfOptions.dts')(dts);
1655
- };
1656
- var logDtsError = function logDtsError(error, dtsOptions) {
1657
- if (dtsOptions === false) {
1658
- return;
1659
- }
1660
- if (typeof dtsOptions === 'object' && dtsOptions && dtsOptions.displayErrorInTerminal === false) {
1661
- return;
1662
- }
1663
- console.error(error);
1664
- };
1665
- function pluginDts(options) {
1666
- if (options.dts === false) {
1667
- return [];
1668
- }
1669
- var dtsModuleFederationConfig = buildDtsModuleFederationConfig(options);
1670
- var resolvedConfig;
1671
- var devWorker;
1672
- var normalizedDevOptions;
1673
- var hasGeneratedBundle = false;
1674
- var devPlugin = {
1675
- name: 'module-federation-dts-dev',
1676
- apply: 'serve',
1677
- config: function config(_config) {
1678
- normalizedDevOptions = normalizeDevOptions(options.dev);
1679
- if (!normalizedDevOptions) {
1680
- return;
1784
+ apply: 'build',
1785
+ moduleParsed: function moduleParsed(module) {
1786
+ var id = module.id;
1787
+ if (id === VIRTUAL_EXPOSES) {
1788
+ // When the entry JS file is empty and only contains exposes export code, it’s necessary to wait for the exposes modules to be resolved in order to collect the dependencies being used.
1789
+ exposesParseEnd = true;
1681
1790
  }
1682
- if (normalizedDevOptions.disableDynamicRemoteTypeHints) {
1791
+ if (excludeFn(id)) {
1683
1792
  return;
1684
1793
  }
1685
- ensureRuntimePlugin(options, DYNAMIC_HINTS_PLUGIN);
1686
- var define = _config.define ? _extends({}, _config.define) : {};
1687
- if (!('FEDERATION_IPV4' in define)) {
1688
- define.FEDERATION_IPV4 = JSON.stringify(getIPv4());
1794
+ parseEndSet.add(id);
1795
+ if (exposesParseEnd && parseStartSet.size === parseEndSet.size) {
1796
+ _resolve(1);
1689
1797
  }
1690
- _config.define = define;
1691
- },
1798
+ }
1799
+ }];
1800
+ }
1801
+
1802
+ var filter = pluginutils.createFilter();
1803
+ function pluginProxyRemoteEntry () {
1804
+ var viteConfig, _command;
1805
+ return {
1806
+ name: 'proxyRemoteEntry',
1807
+ enforce: 'post',
1692
1808
  configResolved: function configResolved(config) {
1693
- resolvedConfig = config;
1809
+ viteConfig = config;
1694
1810
  },
1695
- configureServer: function configureServer(server) {
1696
- if (!normalizedDevOptions || !resolvedConfig) {
1697
- return;
1811
+ config: function config(_config, _ref) {
1812
+ var command = _ref.command;
1813
+ _command = command;
1814
+ },
1815
+ resolveId: function resolveId(id) {
1816
+ if (id === REMOTE_ENTRY_ID) {
1817
+ return REMOTE_ENTRY_ID;
1698
1818
  }
1699
- var devOptions = normalizedDevOptions;
1700
- if (devOptions.disableDynamicRemoteTypeHints && devOptions.disableHotTypesReload && devOptions.disableLiveReload) {
1701
- return;
1819
+ if (id === VIRTUAL_EXPOSES) {
1820
+ return VIRTUAL_EXPOSES;
1702
1821
  }
1703
- if (!options.name) {
1704
- throw new Error('name is required if you want to enable dev server!');
1822
+ if (_command === 'serve' && id.includes(getHostAutoInitPath())) {
1823
+ return id;
1705
1824
  }
1706
- var outputDir = resolveOutputDir(resolvedConfig);
1707
- var normalizedDtsOptions = normalizeDevDtsOptions(options.dts, resolvedConfig.root);
1708
- if (typeof normalizedDtsOptions !== 'object') {
1709
- return;
1825
+ },
1826
+ load: function load(id) {
1827
+ if (id === REMOTE_ENTRY_ID) {
1828
+ return parsePromise.then(function (_) {
1829
+ return generateRemoteEntry(getNormalizeModuleFederationOptions());
1830
+ });
1710
1831
  }
1711
- var normalizedGenerateTypes = sdk.normalizeOptions(Boolean(normalizedDtsOptions), {
1712
- compileInChildProcess: true
1713
- }, 'mfOptions.dts.generateTypes')(normalizedDtsOptions.generateTypes);
1714
- var remote = normalizedGenerateTypes === false ? undefined : _extends({
1715
- implementation: normalizedDtsOptions.implementation,
1716
- context: resolvedConfig.root,
1717
- outputDir: outputDir,
1718
- moduleFederationConfig: _extends({}, dtsModuleFederationConfig),
1719
- hostRemoteTypesFolder: normalizedGenerateTypes.typesFolder || '@mf-types'
1720
- }, normalizedGenerateTypes, {
1721
- typesFolder: '.dev-server'
1722
- });
1723
- if (remote && !remote.tsConfigPath && typeof normalizedDtsOptions === 'object' && normalizedDtsOptions.tsConfigPath) {
1724
- remote.tsConfigPath = normalizedDtsOptions.tsConfigPath;
1832
+ if (id === VIRTUAL_EXPOSES) {
1833
+ return generateExposes();
1725
1834
  }
1726
- var normalizedConsumeTypes = sdk.normalizeOptions(Boolean(normalizedDtsOptions), {
1727
- consumeAPITypes: true
1728
- }, 'mfOptions.dts.consumeTypes')(normalizedDtsOptions.consumeTypes);
1729
- var host = normalizedConsumeTypes === false ? undefined : _extends({
1730
- implementation: normalizedDtsOptions.implementation,
1731
- context: resolvedConfig.root,
1732
- moduleFederationConfig: dtsModuleFederationConfig,
1733
- typesFolder: normalizedConsumeTypes.typesFolder || '@mf-types',
1734
- abortOnError: false
1735
- }, normalizedConsumeTypes);
1736
- var extraOptions = normalizedDtsOptions.extraOptions || {};
1737
- if (!remote && !host && devOptions.disableLiveReload) {
1738
- return;
1835
+ if (_command === 'serve' && id.includes(getHostAutoInitPath())) {
1836
+ return id;
1739
1837
  }
1740
- var startDevWorker = function startDevWorker() {
1741
- try {
1742
- var _temp2 = function _temp2() {
1743
- var _server$httpServer;
1744
- devWorker = new DevWorker({
1745
- name: options.name,
1746
- remote: remote,
1747
- host: host ? _extends({}, host, {
1748
- remoteTypeUrls: remoteTypeUrls
1749
- }) : undefined,
1750
- extraOptions: extraOptions,
1751
- disableLiveReload: devOptions.disableLiveReload,
1752
- disableHotTypesReload: devOptions.disableHotTypesReload
1753
- });
1754
- var update = function update() {
1755
- var _devWorker;
1756
- return (_devWorker = devWorker) == null ? void 0 : _devWorker.update();
1757
- };
1758
- server.watcher.on('change', update);
1759
- server.watcher.on('add', update);
1760
- server.watcher.on('unlink', update);
1761
- (_server$httpServer = server.httpServer) == null || _server$httpServer.once('close', function () {
1762
- var _devWorker2;
1763
- (_devWorker2 = devWorker) == null || _devWorker2.exit();
1764
- server.watcher.off('change', update);
1765
- server.watcher.off('add', update);
1766
- server.watcher.off('unlink', update);
1767
- });
1768
- };
1769
- var remoteTypeUrls;
1770
- var _temp = function () {
1771
- if (host) {
1772
- return Promise.resolve(new Promise(function (resolve) {
1773
- dtsPlugin.consumeTypesAPI({
1774
- host: host,
1775
- extraOptions: extraOptions,
1776
- displayErrorInTerminal: normalizedDtsOptions.displayErrorInTerminal
1777
- }, resolve);
1778
- })).then(function (_Promise) {
1779
- remoteTypeUrls = _Promise;
1780
- });
1781
- }
1782
- }();
1783
- return Promise.resolve(_temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp));
1784
- } catch (e) {
1785
- return Promise.reject(e);
1786
- }
1787
- };
1788
- startDevWorker()["catch"](function (error) {
1789
- logDtsError(error, normalizedDtsOptions);
1790
- });
1791
- }
1792
- };
1793
- var buildPlugin = {
1794
- name: 'module-federation-dts-build',
1795
- apply: 'build',
1796
- configResolved: function configResolved(config) {
1797
- resolvedConfig = config;
1798
1838
  },
1799
- generateBundle: function generateBundle() {
1800
- try {
1801
- var _temp6 = function _temp6() {
1802
- var generateOptions;
1803
- try {
1804
- generateOptions = dtsPlugin.normalizeGenerateTypesOptions({
1805
- context: context,
1806
- outputDir: outputDir,
1807
- dtsOptions: normalizedDtsOptions,
1808
- pluginOptions: dtsModuleFederationConfig
1809
- });
1810
- } catch (error) {
1811
- logDtsError(error, normalizedDtsOptions);
1812
- return;
1813
- }
1814
- if (!generateOptions) {
1815
- return;
1816
- }
1817
- var _temp4 = _catch(function () {
1818
- return Promise.resolve(dtsPlugin.generateTypesAPI({
1819
- dtsManagerOptions: generateOptions
1820
- })).then(function () {});
1821
- }, function (error) {
1822
- logDtsError(error, normalizedDtsOptions);
1839
+ transform: function transform(code, id) {
1840
+ var transformedCode = function () {
1841
+ if (!filter(id)) return;
1842
+ if (id.includes(REMOTE_ENTRY_ID)) {
1843
+ return parsePromise.then(function (_) {
1844
+ return generateRemoteEntry(getNormalizeModuleFederationOptions());
1823
1845
  });
1824
- if (_temp4 && _temp4.then) return _temp4.then(function () {});
1825
- };
1826
- if (hasGeneratedBundle) {
1827
- return Promise.resolve();
1828
- }
1829
- hasGeneratedBundle = true;
1830
- if (!resolvedConfig) {
1831
- return Promise.resolve();
1832
- }
1833
- var normalizedDtsOptions;
1834
- try {
1835
- normalizedDtsOptions = dtsPlugin.normalizeDtsOptions(dtsModuleFederationConfig, resolvedConfig.root);
1836
- } catch (error) {
1837
- logDtsError(error, options.dts);
1838
- return Promise.resolve();
1839
1846
  }
1840
- if (typeof normalizedDtsOptions !== 'object') {
1841
- return Promise.resolve();
1847
+ if (id === VIRTUAL_EXPOSES) {
1848
+ return generateExposes();
1842
1849
  }
1843
- var context = resolvedConfig.root;
1844
- var outputDir = resolveOutputDir(resolvedConfig);
1845
- var consumeOptions;
1846
- try {
1847
- consumeOptions = dtsPlugin.normalizeConsumeTypesOptions({
1848
- context: context,
1849
- dtsOptions: normalizedDtsOptions,
1850
- pluginOptions: dtsModuleFederationConfig
1851
- });
1852
- } catch (error) {
1853
- logDtsError(error, normalizedDtsOptions);
1854
- return Promise.resolve();
1850
+ if (id.includes(getHostAutoInitPath())) {
1851
+ var options = getNormalizeModuleFederationOptions();
1852
+ if (_command === 'serve') {
1853
+ var _viteConfig$server, _viteConfig$server2;
1854
+ var host = typeof ((_viteConfig$server = viteConfig.server) == null ? void 0 : _viteConfig$server.host) === 'string' && viteConfig.server.host !== '0.0.0.0' ? viteConfig.server.host : 'localhost';
1855
+ var publicPath = JSON.stringify(resolvePublicPath(options, viteConfig.base) + options.filename);
1856
+ return "\n const origin = (window && " + !options.ignoreOrigin + ") ? window.origin : \"//" + host + ":" + ((_viteConfig$server2 = viteConfig.server) == null ? void 0 : _viteConfig$server2.port) + "\"\n const remoteEntryPromise = await import(origin + " + publicPath + ")\n // __tla only serves as a hack for vite-plugin-top-level-await.\n Promise.resolve(remoteEntryPromise)\n .then(remoteEntry => {\n return Promise.resolve(remoteEntry.__tla)\n .then(remoteEntry.init).catch(remoteEntry.init)\n })\n ";
1857
+ }
1858
+ return code;
1855
1859
  }
1856
- var _temp5 = function (_consumeOptions) {
1857
- if ((_consumeOptions = consumeOptions) != null && (_consumeOptions = _consumeOptions.host) != null && _consumeOptions.typesOnBuild) {
1858
- var _temp3 = _catch(function () {
1859
- return Promise.resolve(dtsPlugin.consumeTypesAPI(consumeOptions)).then(function () {});
1860
- }, function (error) {
1861
- logDtsError(error, normalizedDtsOptions);
1862
- });
1863
- if (_temp3 && _temp3.then) return _temp3.then(function () {});
1860
+ }();
1861
+ return mapCodeToCodeWithSourcemap(transformedCode);
1862
+ }
1863
+ };
1864
+ }
1865
+
1866
+ pluginutils.createFilter();
1867
+ function pluginProxyRemotes (options) {
1868
+ var remotes = options.remotes;
1869
+ return {
1870
+ name: 'proxyRemotes',
1871
+ config: function config(_config, _ref) {
1872
+ var _command = _ref.command;
1873
+ Object.keys(remotes).forEach(function (key) {
1874
+ var remote = remotes[key];
1875
+ _config.resolve.alias.push({
1876
+ find: new RegExp("^(" + remote.name + "(/.*|$))"),
1877
+ replacement: '$1',
1878
+ customResolver: function customResolver(source) {
1879
+ var remoteModule = getRemoteVirtualModule(source, _command);
1880
+ addUsedRemote(remote.name, source);
1881
+ return remoteModule.getPath();
1864
1882
  }
1865
- }();
1866
- return Promise.resolve(_temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5));
1867
- } catch (e) {
1868
- return Promise.reject(e);
1869
- }
1883
+ });
1884
+ });
1870
1885
  }
1871
1886
  };
1872
- return [devPlugin, buildPlugin];
1873
1887
  }
1874
1888
 
1875
1889
  /**
@@ -2062,6 +2076,8 @@
2062
2076
  entryPath: VIRTUAL_EXPOSES
2063
2077
  }), [pluginProxyRemoteEntry(), pluginProxyRemotes(options)], pluginModuleParseEnd(function (id) {
2064
2078
  return id.includes(getHostAutoInitImportId()) || id.includes(REMOTE_ENTRY_ID) || id.includes(VIRTUAL_EXPOSES) || id.includes(getLocalSharedImportMapPath());
2079
+ }, {
2080
+ moduleParseTimeout: options.moduleParseTimeout
2065
2081
  }), proxySharedModule({
2066
2082
  shared: shared
2067
2083
  }), [PluginDevProxyModuleTopLevelAwait(), {