@module-federation/vite 1.9.3 → 1.9.5

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
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('defu'), require('fs'), require('pathe'), require('magic-string'), require('@rollup/pluginutils'), require('estree-walker')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'defu', 'fs', 'pathe', 'magic-string', '@rollup/pluginutils', 'estree-walker'], factory) :
4
- (global = global || self, factory(global.vite = {}, global.defu, global.fs, global.pathe, global.magicString, global.pluginutils, global.estreeWalker));
5
- })(this, (function (exports, defu, fs, path, MagicString, pluginutils, estreeWalker) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('defu'), require('fs'), require('pathe'), require('magic-string'), require('@rollup/pluginutils'), require('estree-walker'), require('@module-federation/sdk'), require('@module-federation/dts-plugin'), require('@module-federation/dts-plugin/core')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'defu', 'fs', 'pathe', 'magic-string', '@rollup/pluginutils', 'estree-walker', '@module-federation/sdk', '@module-federation/dts-plugin', '@module-federation/dts-plugin/core'], factory) :
4
+ (global = global || self, factory(global.vite = {}, global.defu, global.fs, global.pathe, global.magicString, global.pluginutils, global.estreeWalker, global.sdk, global.dtsPlugin, global.core));
5
+ })(this, (function (exports, defu, fs, path, MagicString, pluginutils, estreeWalker, sdk, dtsPlugin, core) {
6
6
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
7
7
 
8
8
  function _interopNamespace(e) {
@@ -145,9 +145,11 @@
145
145
  }
146
146
  },
147
147
  generateBundle: function generateBundle(options, bundle) {
148
+ var _viteConfig$experimen, _viteConfig$experimen2;
148
149
  if (!injectHtml()) return;
149
150
  var file = this.getFileName(emitFileId);
150
- var scriptContent = "\n <script type=\"module\" src=\"" + (viteConfig.base + file) + "\"></script>\n ";
151
+ var path = (_viteConfig$experimen = viteConfig.experimental) != null && _viteConfig$experimen.renderBuiltUrl ? (_viteConfig$experimen2 = viteConfig.experimental) == null ? void 0 : _viteConfig$experimen2.renderBuiltUrl(file) : viteConfig.base + file;
152
+ var scriptContent = "\n <script type=\"module\" src=\"" + path + "\"></script>\n ";
151
153
  for (var _fileName in bundle) {
152
154
  if (_fileName.endsWith('.html')) {
153
155
  var htmlAsset = bundle[_fileName];
@@ -583,6 +585,96 @@
583
585
  fs.writeFileSync(filePath, content);
584
586
  }
585
587
 
588
+ /**
589
+ * Serializes a JavaScript object into a string of source code that can be evaluated.
590
+ * This function is used to create runtime plugin options without relying solely on JSON.stringify,
591
+ * allowing support for non-JSON types like RegExp, Date, Map, Set, and Functions.
592
+ * It also safely handles circular references.
593
+ *
594
+ * @param {Record<string, unknown>} options - The options object to serialize.
595
+ * @returns {string} The resulting JavaScript source code string.
596
+ */
597
+ function serializeRuntimeOptions(options) {
598
+ // Use a WeakSet to track objects already encountered, which helps in detecting circular references.
599
+ var seenObjects = new WeakSet();
600
+ /**
601
+ * Recursive inner function to serialize any value into a source code string.
602
+ */
603
+ function valueToCode(val) {
604
+ // 1. Handle primitive values
605
+ if (val === null) return 'null';
606
+ var type = typeof val;
607
+ if (type === 'string') return JSON.stringify(val);
608
+ if (type === 'number' || type === 'boolean') return String(val);
609
+ if (type === 'undefined') return 'undefined';
610
+ // Handle Symbol
611
+ if (type === 'symbol') {
612
+ var _val$description;
613
+ var desc = (_val$description = val.description) != null ? _val$description : '';
614
+ return "Symbol(" + JSON.stringify(desc) + ")";
615
+ }
616
+ // Handle Function (returns the function's source code)
617
+ if (type === 'function') return val.toString();
618
+ // 2. Handle special built-in objects
619
+ if (val instanceof Date) return "new Date(" + JSON.stringify(val.toISOString()) + ")";
620
+ if (val instanceof RegExp) {
621
+ return "new RegExp(" + JSON.stringify(val.source) + ", " + JSON.stringify(val.flags) + ")";
622
+ }
623
+ // 3. Check for circular references and mark object as seen
624
+ // This applies to objects, arrays, maps, and sets.
625
+ if (type === 'object') {
626
+ if (seenObjects.has(val)) {
627
+ // This object has been seen previously in the recursion path
628
+ return "\"__circular__\"";
629
+ }
630
+ seenObjects.add(val);
631
+ }
632
+ // 4. Handle Array, Map, Set
633
+ if (Array.isArray(val)) {
634
+ // Recursively serialize each element
635
+ return "[" + val.map(valueToCode).join(', ') + "]";
636
+ }
637
+ if (val instanceof Map) {
638
+ // Serialize Map entries into an array of [key, value] pairs
639
+ var entries = Array.from(val.entries()).map(function (_ref) {
640
+ var k = _ref[0],
641
+ v = _ref[1];
642
+ return "[" + valueToCode(k) + ", " + valueToCode(v) + "]";
643
+ });
644
+ return "new Map([" + entries.join(', ') + "])";
645
+ }
646
+ if (val instanceof Set) {
647
+ // Serialize Set values into an array
648
+ var items = Array.from(val.values()).map(valueToCode);
649
+ return "new Set([" + items.join(', ') + "])";
650
+ }
651
+ // 5. Handle plain objects (the default object type)
652
+ if (type === 'object') {
653
+ var properties = [];
654
+ // Iterate over the object's own enumerable properties
655
+ for (var key in val) {
656
+ if (Object.prototype.hasOwnProperty.call(val, key)) {
657
+ // Wrap the key in JSON.stringify to handle non-identifier keys
658
+ properties.push(JSON.stringify(key) + ": " + valueToCode(val[key]));
659
+ }
660
+ }
661
+ return "{" + properties.join(', ') + "}";
662
+ }
663
+ // 6. Fallback case (e.g., BigInt, other object types)
664
+ // Coerce to string and then JSON.stringify that string for safety
665
+ return JSON.stringify(String(val));
666
+ }
667
+ // Start serialization for the top-level object
668
+ var topLevelProps = [];
669
+ // Iterate over the properties of the root 'options' object
670
+ for (var key in options) {
671
+ if (Object.prototype.hasOwnProperty.call(options, key)) {
672
+ topLevelProps.push(JSON.stringify(key) + ": " + valueToCode(options[key]));
673
+ }
674
+ }
675
+ return "{" + topLevelProps.join(', ') + "}";
676
+ }
677
+
586
678
  // Cache root path
587
679
  var rootDir;
588
680
  function findNodeModulesDir(root) {
@@ -819,12 +911,16 @@
819
911
  var REMOTE_ENTRY_ID = 'virtual:mf-REMOTE_ENTRY_ID';
820
912
  function generateRemoteEntry(options) {
821
913
  var pluginImportNames = options.runtimePlugins.map(function (p, i) {
822
- return ["$runtimePlugin_" + i, "import $runtimePlugin_" + i + " from \"" + p + "\";"];
914
+ if (typeof p === 'string') {
915
+ return ["$runtimePlugin_" + i, "import $runtimePlugin_" + i + " from \"" + p + "\";", "undefined"];
916
+ } else {
917
+ return ["$runtimePlugin_" + i, "import $runtimePlugin_" + i + " from \"" + p[0] + "\";", serializeRuntimeOptions(p[1])];
918
+ }
823
919
  });
824
920
  return "\n import {init as runtimeInit, loadRemote} from \"@module-federation/runtime\";\n " + pluginImportNames.map(function (item) {
825
921
  return item[1];
826
922
  }).join('\n') + "\n import exposesMap from \"" + VIRTUAL_EXPOSES + "\"\n import {usedShared, usedRemotes} from \"" + getLocalSharedImportMapPath() + "\"\n import {\n initResolve\n } from \"" + virtualRuntimeInitStatus.getImportId() + "\"\n const initTokens = {}\n const shareScopeName = " + JSON.stringify(options.shareScope) + "\n const mfName = " + JSON.stringify(options.name) + "\n async function init(shared = {}, initScope = []) {\n const initRes = runtimeInit({\n name: mfName,\n remotes: usedRemotes,\n shared: usedShared,\n plugins: [" + pluginImportNames.map(function (item) {
827
- return item[0] + "()";
923
+ return item[0] + "(" + item[2] + ")";
828
924
  }).join(', ') + "],\n " + (options.shareStrategy ? "shareStrategy: '" + options.shareStrategy + "'" : '') + "\n });\n // handling circular init calls\n var initToken = initTokens[shareScopeName];\n if (!initToken)\n initToken = initTokens[shareScopeName] = { from: mfName };\n if (initScope.indexOf(initToken) >= 0) return;\n initScope.push(initToken);\n initRes.initShareScopeMap('" + options.shareScope + "', shared);\n try {\n await Promise.all(await initRes.initializeSharing('" + options.shareScope + "', {\n strategy: '" + options.shareStrategy + "',\n from: \"build\",\n initScope\n }));\n } catch (e) {\n console.error(e)\n }\n initResolve(initRes)\n return initRes\n }\n\n function getExposes(moduleName) {\n if (!(moduleName in exposesMap)) throw new Error(`Module ${moduleName} does not exist in container.`)\n return (exposesMap[moduleName])().then(res => () => res)\n }\n export {\n init,\n getExposes as get\n }\n ";
829
925
  }
830
926
  /**
@@ -1438,6 +1534,317 @@
1438
1534
  };
1439
1535
  }
1440
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 && dtsOptions.displayErrorInTerminal !== false) {
1658
+ console.error(error);
1659
+ }
1660
+ };
1661
+ function pluginDts(options) {
1662
+ if (options.dts === false) {
1663
+ return [];
1664
+ }
1665
+ var dtsModuleFederationConfig = buildDtsModuleFederationConfig(options);
1666
+ var resolvedConfig;
1667
+ var devWorker;
1668
+ var normalizedDevOptions;
1669
+ var devPlugin = {
1670
+ name: 'module-federation-dts-dev',
1671
+ apply: 'serve',
1672
+ config: function config(_config) {
1673
+ normalizedDevOptions = normalizeDevOptions(options.dev);
1674
+ if (!normalizedDevOptions) {
1675
+ return;
1676
+ }
1677
+ if (normalizedDevOptions.disableDynamicRemoteTypeHints) {
1678
+ return;
1679
+ }
1680
+ ensureRuntimePlugin(options, DYNAMIC_HINTS_PLUGIN);
1681
+ var define = _config.define ? _extends({}, _config.define) : {};
1682
+ if (!('FEDERATION_IPV4' in define)) {
1683
+ define.FEDERATION_IPV4 = JSON.stringify(getIPv4());
1684
+ }
1685
+ _config.define = define;
1686
+ },
1687
+ configResolved: function configResolved(config) {
1688
+ resolvedConfig = config;
1689
+ },
1690
+ configureServer: function configureServer(server) {
1691
+ if (!normalizedDevOptions || !resolvedConfig) {
1692
+ return;
1693
+ }
1694
+ var devOptions = normalizedDevOptions;
1695
+ if (devOptions.disableDynamicRemoteTypeHints && devOptions.disableHotTypesReload && devOptions.disableLiveReload) {
1696
+ return;
1697
+ }
1698
+ if (!options.name) {
1699
+ throw new Error('name is required if you want to enable dev server!');
1700
+ }
1701
+ var outputDir = resolveOutputDir(resolvedConfig);
1702
+ var normalizedDtsOptions = normalizeDevDtsOptions(options.dts, resolvedConfig.root);
1703
+ if (typeof normalizedDtsOptions !== 'object') {
1704
+ return;
1705
+ }
1706
+ var normalizedGenerateTypes = sdk.normalizeOptions(Boolean(normalizedDtsOptions), {
1707
+ compileInChildProcess: true
1708
+ }, 'mfOptions.dts.generateTypes')(normalizedDtsOptions.generateTypes);
1709
+ var remote = normalizedGenerateTypes === false ? undefined : _extends({
1710
+ implementation: normalizedDtsOptions.implementation,
1711
+ context: resolvedConfig.root,
1712
+ outputDir: outputDir,
1713
+ moduleFederationConfig: _extends({}, dtsModuleFederationConfig),
1714
+ hostRemoteTypesFolder: normalizedGenerateTypes.typesFolder || '@mf-types'
1715
+ }, normalizedGenerateTypes, {
1716
+ typesFolder: '.dev-server'
1717
+ });
1718
+ if (remote && !remote.tsConfigPath && typeof normalizedDtsOptions === 'object' && normalizedDtsOptions.tsConfigPath) {
1719
+ remote.tsConfigPath = normalizedDtsOptions.tsConfigPath;
1720
+ }
1721
+ var normalizedConsumeTypes = sdk.normalizeOptions(Boolean(normalizedDtsOptions), {
1722
+ consumeAPITypes: true
1723
+ }, 'mfOptions.dts.consumeTypes')(normalizedDtsOptions.consumeTypes);
1724
+ var host = normalizedConsumeTypes === false ? undefined : _extends({
1725
+ implementation: normalizedDtsOptions.implementation,
1726
+ context: resolvedConfig.root,
1727
+ moduleFederationConfig: dtsModuleFederationConfig,
1728
+ typesFolder: normalizedConsumeTypes.typesFolder || '@mf-types',
1729
+ abortOnError: false
1730
+ }, normalizedConsumeTypes);
1731
+ var extraOptions = normalizedDtsOptions.extraOptions || {};
1732
+ if (!remote && !host && devOptions.disableLiveReload) {
1733
+ return;
1734
+ }
1735
+ var startDevWorker = function startDevWorker() {
1736
+ try {
1737
+ var _temp2 = function _temp2() {
1738
+ var _server$httpServer;
1739
+ devWorker = new DevWorker({
1740
+ name: options.name,
1741
+ remote: remote,
1742
+ host: host ? _extends({}, host, {
1743
+ remoteTypeUrls: remoteTypeUrls
1744
+ }) : undefined,
1745
+ extraOptions: extraOptions,
1746
+ disableLiveReload: devOptions.disableLiveReload,
1747
+ disableHotTypesReload: devOptions.disableHotTypesReload
1748
+ });
1749
+ var update = function update() {
1750
+ var _devWorker;
1751
+ return (_devWorker = devWorker) == null ? void 0 : _devWorker.update();
1752
+ };
1753
+ server.watcher.on('change', update);
1754
+ server.watcher.on('add', update);
1755
+ server.watcher.on('unlink', update);
1756
+ (_server$httpServer = server.httpServer) == null || _server$httpServer.once('close', function () {
1757
+ var _devWorker2;
1758
+ (_devWorker2 = devWorker) == null || _devWorker2.exit();
1759
+ server.watcher.off('change', update);
1760
+ server.watcher.off('add', update);
1761
+ server.watcher.off('unlink', update);
1762
+ });
1763
+ };
1764
+ var remoteTypeUrls;
1765
+ var _temp = function () {
1766
+ if (host) {
1767
+ return Promise.resolve(new Promise(function (resolve) {
1768
+ dtsPlugin.consumeTypesAPI({
1769
+ host: host,
1770
+ extraOptions: extraOptions,
1771
+ displayErrorInTerminal: normalizedDtsOptions.displayErrorInTerminal
1772
+ }, resolve);
1773
+ })).then(function (_Promise) {
1774
+ remoteTypeUrls = _Promise;
1775
+ });
1776
+ }
1777
+ }();
1778
+ return Promise.resolve(_temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp));
1779
+ } catch (e) {
1780
+ return Promise.reject(e);
1781
+ }
1782
+ };
1783
+ startDevWorker()["catch"](function (error) {
1784
+ logDtsError(error, normalizedDtsOptions);
1785
+ });
1786
+ }
1787
+ };
1788
+ var buildPlugin = {
1789
+ name: 'module-federation-dts-build',
1790
+ apply: 'build',
1791
+ configResolved: function configResolved(config) {
1792
+ resolvedConfig = config;
1793
+ },
1794
+ closeBundle: function closeBundle() {
1795
+ try {
1796
+ var _temp6 = function _temp6() {
1797
+ var generateOptions = dtsPlugin.normalizeGenerateTypesOptions({
1798
+ context: context,
1799
+ outputDir: outputDir,
1800
+ dtsOptions: normalizedDtsOptions,
1801
+ pluginOptions: dtsModuleFederationConfig
1802
+ });
1803
+ if (!generateOptions) {
1804
+ return;
1805
+ }
1806
+ var _temp4 = _catch(function () {
1807
+ return Promise.resolve(dtsPlugin.generateTypesAPI({
1808
+ dtsManagerOptions: generateOptions
1809
+ })).then(function () {});
1810
+ }, function (error) {
1811
+ logDtsError(error, normalizedDtsOptions);
1812
+ });
1813
+ if (_temp4 && _temp4.then) return _temp4.then(function () {});
1814
+ };
1815
+ if (!resolvedConfig) {
1816
+ return Promise.resolve();
1817
+ }
1818
+ var normalizedDtsOptions = dtsPlugin.normalizeDtsOptions(dtsModuleFederationConfig, resolvedConfig.root);
1819
+ if (typeof normalizedDtsOptions !== 'object') {
1820
+ return Promise.resolve();
1821
+ }
1822
+ var context = resolvedConfig.root;
1823
+ var outputDir = resolveOutputDir(resolvedConfig);
1824
+ var consumeOptions = dtsPlugin.normalizeConsumeTypesOptions({
1825
+ context: context,
1826
+ dtsOptions: normalizedDtsOptions,
1827
+ pluginOptions: dtsModuleFederationConfig
1828
+ });
1829
+ var _temp5 = function (_consumeOptions$host) {
1830
+ if (consumeOptions != null && (_consumeOptions$host = consumeOptions.host) != null && _consumeOptions$host.typesOnBuild) {
1831
+ var _temp3 = _catch(function () {
1832
+ return Promise.resolve(dtsPlugin.consumeTypesAPI(consumeOptions)).then(function () {});
1833
+ }, function (error) {
1834
+ logDtsError(error, normalizedDtsOptions);
1835
+ });
1836
+ if (_temp3 && _temp3.then) return _temp3.then(function () {});
1837
+ }
1838
+ }();
1839
+ return Promise.resolve(_temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5));
1840
+ } catch (e) {
1841
+ return Promise.reject(e);
1842
+ }
1843
+ }
1844
+ };
1845
+ return [devPlugin, buildPlugin];
1846
+ }
1847
+
1441
1848
  /**
1442
1849
  * example:
1443
1850
  * const store = new PromiseStore<number>();
@@ -1615,7 +2022,7 @@
1615
2022
  }
1616
2023
  }, aliasToArrayPlugin, checkAliasConflicts({
1617
2024
  shared: shared
1618
- }), normalizeOptimizeDepsPlugin].concat(addEntry({
2025
+ }), normalizeOptimizeDepsPlugin].concat(pluginDts(options), addEntry({
1619
2026
  entryName: 'remoteEntry',
1620
2027
  entryPath: REMOTE_ENTRY_ID,
1621
2028
  fileName: filename
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'vite';
2
+ import type { NormalizedModuleFederationOptions } from '../utils/normalizeModuleFederationOptions';
3
+ export default function pluginDts(options: NormalizedModuleFederationOptions): Plugin[];
@@ -57,7 +57,7 @@ export type ModuleFederationOptions = {
57
57
  strictVersion?: boolean;
58
58
  import?: sharePlugin.SharedConfig['import'];
59
59
  }> | undefined;
60
- runtimePlugins?: string[];
60
+ runtimePlugins?: Array<string | [string, Record<string, unknown>]>;
61
61
  getPublicPath?: string;
62
62
  implementation?: string;
63
63
  manifest?: ManifestOptions | boolean;
@@ -77,7 +77,7 @@ export interface NormalizedModuleFederationOptions {
77
77
  runtime: any;
78
78
  shareScope: string;
79
79
  shared: NormalizedShared;
80
- runtimePlugins: string[];
80
+ runtimePlugins: Array<string | [string, Record<string, unknown>]>;
81
81
  implementation: string;
82
82
  manifest: ManifestOptions | boolean;
83
83
  dev?: boolean | PluginDevOptions;
@@ -101,22 +101,38 @@ interface PluginDevOptions {
101
101
  disableHotTypesReload?: boolean;
102
102
  disableDynamicRemoteTypeHints?: boolean;
103
103
  }
104
+ interface RemoteTypeUrl {
105
+ alias?: string;
106
+ api: string;
107
+ zip: string;
108
+ }
109
+ interface RemoteTypeUrls {
110
+ [remoteName: string]: RemoteTypeUrl;
111
+ }
104
112
  interface PluginDtsOptions {
105
113
  generateTypes?: boolean | DtsRemoteOptions;
106
114
  consumeTypes?: boolean | DtsHostOptions;
107
115
  tsConfigPath?: string;
116
+ extraOptions?: Record<string, unknown>;
117
+ implementation?: string;
118
+ cwd?: string;
119
+ displayErrorInTerminal?: boolean;
108
120
  }
109
121
  interface DtsRemoteOptions {
110
122
  tsConfigPath?: string;
111
123
  typesFolder?: string;
124
+ compiledTypesFolder?: string;
112
125
  deleteTypesFolder?: boolean;
113
126
  additionalFilesToCompile?: string[];
114
- compilerInstance?: 'tsc' | 'vue-tsc';
127
+ compilerInstance?: 'tsc' | 'vue-tsc' | 'tspc' | string;
115
128
  compileInChildProcess?: boolean;
116
129
  generateAPITypes?: boolean;
117
- extractThirdParty?: boolean;
130
+ extractThirdParty?: boolean | {
131
+ exclude?: Array<string | RegExp>;
132
+ };
118
133
  extractRemoteTypes?: boolean;
119
134
  abortOnError?: boolean;
135
+ deleteTsConfig?: boolean;
120
136
  }
121
137
  interface DtsHostOptions {
122
138
  typesFolder?: string;
@@ -125,6 +141,11 @@ interface DtsHostOptions {
125
141
  deleteTypesFolder?: boolean;
126
142
  maxRetries?: number;
127
143
  consumeAPITypes?: boolean;
144
+ runtimePkgs?: string[];
145
+ remoteTypeUrls?: (() => Promise<RemoteTypeUrls>) | RemoteTypeUrls;
146
+ timeout?: number;
147
+ family?: 4 | 6;
148
+ typesOnBuild?: boolean;
128
149
  }
129
150
  export declare function getNormalizeModuleFederationOptions(): NormalizedModuleFederationOptions;
130
151
  export declare function getNormalizeShareItem(key: string): ShareItem;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Serializes a JavaScript object into a string of source code that can be evaluated.
3
+ * This function is used to create runtime plugin options without relying solely on JSON.stringify,
4
+ * allowing support for non-JSON types like RegExp, Date, Map, Set, and Functions.
5
+ * It also safely handles circular references.
6
+ *
7
+ * @param {Record<string, unknown>} options - The options object to serialize.
8
+ * @returns {string} The resulting JavaScript source code string.
9
+ */
10
+ export declare function serializeRuntimeOptions(options: Record<string, unknown>): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/vite",
3
- "version": "1.9.3",
3
+ "version": "1.9.5",
4
4
  "description": "Vite plugin for Module Federation",
5
5
  "type": "module",
6
6
  "source": "src/index.ts",
@@ -9,22 +9,6 @@
9
9
  "files": [
10
10
  "lib/**/*"
11
11
  ],
12
- "scripts": {
13
- "prepare": "husky install",
14
- "fmt": "prettier --write src",
15
- "fmt.check": "prettier --check src",
16
- "format": "pretty-quick",
17
- "dev": "microbundle watch --no-sourcemap --compress=false",
18
- "build": "rimraf lib && microbundle --no-sourcemap --compress=false",
19
- "dev-rv": "pnpm -filter 'examples-rust-vite*' run dev",
20
- "preview-rv": "pnpm -filter 'examples-rust-vite*' run preview",
21
- "dev-vv": "pnpm -filter 'examples-vite-vite*' run dev",
22
- "dev-nv": "pnpm -filter 'examples-nuxt-vite-host' -filter 'examples-vite-vite-remote' run dev",
23
- "preview-vv": "pnpm -filter 'examples-vite-vite*' run preview",
24
- "multi-example": "pnpm --filter \"multi-example-*\" --parallel run start",
25
- "test": "vitest",
26
- "e2e": "playwright test"
27
- },
28
12
  "repository": {
29
13
  "type": "git",
30
14
  "url": "git+https://github.com/module-federation/vite.git"
@@ -44,8 +28,11 @@
44
28
  "url": "https://github.com/module-federation/vite/issues"
45
29
  },
46
30
  "homepage": "https://github.com/module-federation/vite#readme",
47
- "packageManager": "pnpm@9.1.3",
31
+ "peerDependencies": {
32
+ "vite": "<=6"
33
+ },
48
34
  "dependencies": {
35
+ "@module-federation/dts-plugin": "^0.21.6",
49
36
  "@module-federation/runtime": "^0.21.6",
50
37
  "@module-federation/sdk": "^0.21.6",
51
38
  "@rollup/pluginutils": "^5.1.0",
@@ -67,5 +54,20 @@
67
54
  "vite": "^5.4.3",
68
55
  "vitest": "^2.1.1",
69
56
  "wait-on": "^8.0.1"
57
+ },
58
+ "scripts": {
59
+ "fmt": "prettier --write src",
60
+ "fmt.check": "prettier --check src",
61
+ "format": "pretty-quick",
62
+ "dev": "microbundle watch --no-sourcemap --compress=false",
63
+ "build": "rimraf lib && microbundle --no-sourcemap --compress=false",
64
+ "dev-rv": "pnpm -filter 'examples-rust-vite*' run dev",
65
+ "preview-rv": "pnpm -filter 'examples-rust-vite*' run preview",
66
+ "dev-vv": "pnpm -filter 'examples-vite-vite*' run dev",
67
+ "dev-nv": "pnpm -filter 'examples-nuxt-vite-host' -filter 'examples-vite-vite-remote' run dev",
68
+ "preview-vv": "pnpm -filter 'examples-vite-vite*' run preview",
69
+ "multi-example": "pnpm --filter \"multi-example-*\" --parallel run start",
70
+ "test": "vitest",
71
+ "e2e": "playwright test"
70
72
  }
71
- }
73
+ }