@module-federation/vite 1.7.1 → 1.7.2

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
@@ -120,7 +120,7 @@
120
120
  emitFileOptions.fileName = fileName;
121
121
  }
122
122
  emitFileId = this.emitFile(emitFileOptions);
123
- if (htmlFilePath) {
123
+ if (htmlFilePath && fs__namespace.existsSync(htmlFilePath)) {
124
124
  var htmlContent = fs__namespace.readFileSync(htmlFilePath, 'utf-8');
125
125
  var scriptRegex = /<script\s+[^>]*src=["']([^"']+)["'][^>]*>/gi;
126
126
  var match;
@@ -159,10 +159,14 @@
159
159
  */
160
160
  function PluginDevProxyModuleTopLevelAwait() {
161
161
  var filterFunction = pluginutils.createFilter();
162
+ var processedFlag = '/* already-processed-by-dev-proxy-module-top-level-await */';
162
163
  return {
163
164
  name: 'dev-proxy-module-top-level-await',
164
165
  apply: 'serve',
165
166
  transform: function transform(code, id) {
167
+ if (code.includes(processedFlag)) {
168
+ return null;
169
+ }
166
170
  if (!code.includes('/*mf top-level-await placeholder replacement mf*/')) {
167
171
  return null;
168
172
  }
@@ -215,8 +219,9 @@
215
219
  }
216
220
  }
217
221
  });
222
+ var transformedCode = magicString.toString();
218
223
  return {
219
- code: magicString.toString(),
224
+ code: processedFlag + "\n" + transformedCode,
220
225
  map: magicString.generateMap({
221
226
  hires: true
222
227
  })
@@ -714,9 +719,9 @@
714
719
  }
715
720
  function generateLocalSharedImportMap() {
716
721
  var options = getNormalizeModuleFederationOptions();
717
- return "\n const importMap = {\n " + Array.from(getUsedShares()).map(function (pkg) {
722
+ return "\n const importMap = {\n " + Array.from(getUsedShares()).sort().map(function (pkg) {
718
723
  return "\n " + JSON.stringify(pkg) + ": async () => {\n let pkg = await import(\"" + getPreBuildLibImportId(pkg) + "\")\n return pkg\n }\n ";
719
- }).join(',') + "\n }\n const usedShared = {\n " + Array.from(getUsedShares()).map(function (key) {
724
+ }).join(',') + "\n }\n const usedShared = {\n " + Array.from(getUsedShares()).sort().map(function (key) {
720
725
  var shareItem = getNormalizeShareItem(key);
721
726
  if (!shareItem) return null;
722
727
  return "\n " + JSON.stringify(key) + ": {\n name: " + JSON.stringify(key) + ",\n version: " + JSON.stringify(shareItem.version) + ",\n scope: [" + JSON.stringify(shareItem.scope) + "],\n loaded: false,\n from: " + JSON.stringify(options.name) + ",\n async get () {\n usedShared[" + JSON.stringify(key) + "].loaded = true\n const {" + JSON.stringify(key) + ": pkgDynamicImport} = importMap \n const res = await pkgDynamicImport()\n const exportModule = {...res}\n // All npm packages pre-built by vite will be converted to esm\n Object.defineProperty(exportModule, \"__esModule\", {\n value: true,\n enumerable: false\n })\n return function () {\n return exportModule\n }\n },\n shareConfig: {\n singleton: " + shareItem.shareConfig.singleton + ",\n requiredVersion: " + JSON.stringify(shareItem.shareConfig.requiredVersion) + "\n }\n }\n ";
@@ -764,6 +769,154 @@
764
769
  writeRuntimeInitStatus();
765
770
  }
766
771
 
772
+ var ASSET_TYPES = ['js', 'css'];
773
+ var LOAD_TIMINGS = ['sync', 'async'];
774
+ var JS_EXTENSIONS = ['.ts', '.tsx', '.jsx', '.mjs', '.cjs'];
775
+ /**
776
+ * Creates an empty asset map structure for tracking JS and CSS assets
777
+ * @returns Initialized asset map with sync/async arrays for JS and CSS
778
+ */
779
+ var createEmptyAssetMap = function createEmptyAssetMap() {
780
+ return {
781
+ js: {
782
+ sync: [],
783
+ async: []
784
+ },
785
+ css: {
786
+ sync: [],
787
+ async: []
788
+ }
789
+ };
790
+ };
791
+ /**
792
+ * Tracks an asset in the preload map with deduplication
793
+ * @param map - The preload map to update
794
+ * @param key - The module key to track under
795
+ * @param fileName - The asset filename to track
796
+ * @param isAsync - Whether the asset is loaded async
797
+ * @param type - The asset type ('js' or 'css')
798
+ */
799
+ var trackAsset = function trackAsset(map, key, fileName, isAsync, type) {
800
+ if (!map[key]) {
801
+ map[key] = createEmptyAssetMap();
802
+ }
803
+ var target = isAsync ? map[key][type].async : map[key][type].sync;
804
+ if (!target.includes(fileName)) {
805
+ target.push(fileName);
806
+ }
807
+ };
808
+ /**
809
+ * Checks if a file is a CSS file by extension
810
+ * @param fileName - The filename to check
811
+ * @returns True if file has a CSS extension (.css, .scss, .less)
812
+ */
813
+ var isCSSFile = function isCSSFile(fileName) {
814
+ return fileName.endsWith('.css') || fileName.endsWith('.scss') || fileName.endsWith('.less');
815
+ };
816
+ /**
817
+ * Collects all CSS assets from the bundle
818
+ * @param bundle - The Rollup output bundle
819
+ * @returns Set of CSS asset filenames
820
+ */
821
+ var collectCssAssets = function collectCssAssets(bundle) {
822
+ var cssAssets = new Set();
823
+ for (var _i = 0, _Object$entries = Object.entries(bundle); _i < _Object$entries.length; _i++) {
824
+ var _Object$entries$_i = _Object$entries[_i],
825
+ fileName = _Object$entries$_i[0],
826
+ fileData = _Object$entries$_i[1];
827
+ if (fileData.type === 'asset' && isCSSFile(fileName)) {
828
+ cssAssets.add(fileName);
829
+ }
830
+ }
831
+ return cssAssets;
832
+ };
833
+ /**
834
+ * Processes module assets and tracks them in the files map
835
+ * @param bundle - The Rollup output bundle
836
+ * @param filesMap - The preload map to populate
837
+ * @param moduleMatcher - Function that matches module paths to keys
838
+ */
839
+ var processModuleAssets = function processModuleAssets(bundle, filesMap, moduleMatcher) {
840
+ for (var _i2 = 0, _Object$entries2 = Object.entries(bundle); _i2 < _Object$entries2.length; _i2++) {
841
+ var _Object$entries2$_i = _Object$entries2[_i2],
842
+ fileName = _Object$entries2$_i[0],
843
+ fileData = _Object$entries2$_i[1];
844
+ if (fileData.type !== 'chunk') continue;
845
+ if (!fileData.modules) continue;
846
+ for (var _i3 = 0, _Object$keys = Object.keys(fileData.modules); _i3 < _Object$keys.length; _i3++) {
847
+ var modulePath = _Object$keys[_i3];
848
+ var matchKey = moduleMatcher(modulePath);
849
+ if (!matchKey) continue;
850
+ // Track main JS chunk
851
+ trackAsset(filesMap, matchKey, fileName, false, 'js');
852
+ // Handle dynamic imports
853
+ if (fileData.dynamicImports) {
854
+ for (var _iterator = _createForOfIteratorHelperLoose(fileData.dynamicImports), _step; !(_step = _iterator()).done;) {
855
+ var dynamicImport = _step.value;
856
+ var importData = bundle[dynamicImport];
857
+ if (!importData) continue;
858
+ var isCss = isCSSFile(dynamicImport);
859
+ trackAsset(filesMap, matchKey, dynamicImport, true, isCss ? 'css' : 'js');
860
+ }
861
+ }
862
+ }
863
+ }
864
+ };
865
+ /**
866
+ * Deduplicates assets in the files map
867
+ * @param filesMap - The preload map to deduplicate
868
+ * @returns New deduplicated preload map
869
+ */
870
+ var deduplicateAssets = function deduplicateAssets(filesMap) {
871
+ var result = {};
872
+ for (var _i4 = 0, _Object$entries3 = Object.entries(filesMap); _i4 < _Object$entries3.length; _i4++) {
873
+ var _Object$entries3$_i = _Object$entries3[_i4],
874
+ key = _Object$entries3$_i[0],
875
+ assetMaps = _Object$entries3$_i[1];
876
+ result[key] = createEmptyAssetMap();
877
+ for (var _i5 = 0, _ASSET_TYPES = ASSET_TYPES; _i5 < _ASSET_TYPES.length; _i5++) {
878
+ var type = _ASSET_TYPES[_i5];
879
+ for (var _i6 = 0, _LOAD_TIMINGS = LOAD_TIMINGS; _i6 < _LOAD_TIMINGS.length; _i6++) {
880
+ var timing = _LOAD_TIMINGS[_i6];
881
+ result[key][type][timing] = Array.from(new Set(assetMaps[type][timing]));
882
+ }
883
+ }
884
+ }
885
+ return result;
886
+ };
887
+ /**
888
+ * Builds a mapping between module files and their share keys
889
+ * @param shareKeys - Set of share keys to map
890
+ * @param resolveFn - Function to resolve module paths
891
+ * @returns Map of file paths to their corresponding share keys
892
+ */
893
+ var buildFileToShareKeyMap = function buildFileToShareKeyMap(shareKeys, resolveFn) {
894
+ try {
895
+ var fileToShareKey = new Map();
896
+ return Promise.resolve(Promise.all(Array.from(shareKeys).map(function (shareKey) {
897
+ return resolveFn(getPreBuildLibImportId(shareKey)).then(function (resolution) {
898
+ var _resolution$id;
899
+ return {
900
+ shareKey: shareKey,
901
+ file: resolution == null || (_resolution$id = resolution.id) == null ? void 0 : _resolution$id.split('?')[0]
902
+ };
903
+ })["catch"](function () {
904
+ return null;
905
+ });
906
+ }))).then(function (resolutions) {
907
+ for (var _iterator2 = _createForOfIteratorHelperLoose(resolutions), _step2; !(_step2 = _iterator2()).done;) {
908
+ var resolution = _step2.value;
909
+ if (resolution != null && resolution.file) {
910
+ fileToShareKey.set(resolution.file, resolution.shareKey);
911
+ }
912
+ }
913
+ return fileToShareKey;
914
+ });
915
+ } catch (e) {
916
+ return Promise.reject(e);
917
+ }
918
+ };
919
+
767
920
  var Manifest = function Manifest() {
768
921
  var mfOptions = getNormalizeModuleFederationOptions();
769
922
  var name = mfOptions.name,
@@ -775,21 +928,43 @@
775
928
  mfManifestName = 'mf-manifest.json';
776
929
  }
777
930
  if (typeof manifestOptions !== 'boolean') {
778
- mfManifestName = path.join((manifestOptions == null ? void 0 : manifestOptions.filePath) || '', (manifestOptions == null ? void 0 : manifestOptions.fileName) || '');
931
+ mfManifestName = path__namespace.join((manifestOptions == null ? void 0 : manifestOptions.filePath) || '', (manifestOptions == null ? void 0 : manifestOptions.fileName) || '');
779
932
  }
780
- var extensions;
781
933
  var root;
782
934
  var remoteEntryFile;
783
935
  var publicPath;
784
936
  var _command;
785
937
  var _originalConfigBase;
786
938
  var viteConfig;
939
+ /**
940
+ * Adds global CSS assets to all module exports
941
+ * @param filesMap - The preload map to update
942
+ * @param cssAssets - Set of CSS asset filenames to add
943
+ */
944
+ var addCssAssetsToAllExports = function addCssAssetsToAllExports(filesMap, cssAssets) {
945
+ Object.keys(filesMap).forEach(function (key) {
946
+ cssAssets.forEach(function (cssAsset) {
947
+ trackAsset(filesMap, key, cssAsset, false, 'css');
948
+ });
949
+ });
950
+ };
787
951
  return [{
788
952
  name: 'module-federation-manifest',
789
953
  apply: 'serve',
954
+ /**
955
+ * Stores resolved Vite config for later use
956
+ */
957
+ /**
958
+ * Finalizes configuration after all plugins are resolved
959
+ * @param config - Fully resolved Vite config
960
+ */
790
961
  configResolved: function configResolved(config) {
791
962
  viteConfig = config;
792
963
  },
964
+ /**
965
+ * Configures dev server middleware to handle manifest requests
966
+ * @param server - Vite dev server instance
967
+ */
793
968
  configureServer: function configureServer(server) {
794
969
  server.middlewares.use(function (req, res, next) {
795
970
  var _req$url;
@@ -837,137 +1012,85 @@
837
1012
  }, {
838
1013
  name: 'module-federation-manifest',
839
1014
  enforce: 'post',
1015
+ /**
1016
+ * Initial plugin configuration
1017
+ * @param config - Vite config object
1018
+ * @param command - Current Vite command (serve/build)
1019
+ */
840
1020
  config: function config(_config, _ref) {
841
1021
  var command = _ref.command;
842
1022
  if (!_config.build) _config.build = {};
843
- if (!_config.build.manifest) _config.build.manifest = _config.build.manifest || !!manifestOptions;
1023
+ if (!_config.build.manifest) {
1024
+ _config.build.manifest = _config.build.manifest || !!manifestOptions;
1025
+ }
844
1026
  _command = command;
845
1027
  _originalConfigBase = _config.base;
846
1028
  },
847
1029
  configResolved: function configResolved(config) {
848
1030
  root = config.root;
849
- extensions = config.resolve.extensions || ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json'];
850
1031
  var base = config.base;
851
1032
  if (_command === 'serve') {
852
1033
  base = (config.server.origin || '') + config.base;
853
1034
  }
854
1035
  publicPath = _originalConfigBase === '' ? 'auto' : base ? base.replace(/\/?$/, '/') : 'auto';
855
1036
  },
1037
+ /**
1038
+ * Generates the module federation manifest file
1039
+ * @param options - Rollup output options
1040
+ * @param bundle - Generated bundle assets
1041
+ */
856
1042
  generateBundle: function generateBundle(options, bundle) {
857
1043
  try {
858
1044
  var _this = this;
859
- // 递归查找模块的同步导入文件
860
- var _findSynchronousImports = function findSynchronousImports(fileName, array) {
861
- var fileData = bundle[fileName];
862
- if (fileData && fileData.type === 'chunk') {
863
- array.push(fileName); // 将当前文件加入预加载列表
864
- // 遍历该文件的同步导入文件
865
- fileData.imports.forEach(function (importedFile) {
866
- if (array.indexOf(importedFile) === -1) {
867
- _findSynchronousImports(importedFile, array); // 递归查找同步导入的文件
868
- }
869
- });
870
- }
871
- };
872
1045
  if (!mfManifestName) return Promise.resolve();
873
- var exposesModules = Object.keys(mfOptions.exposes).map(function (item) {
874
- return mfOptions.exposes[item]["import"];
875
- }); // 获取你提供的 moduleIds
876
- var filesContainingModules = {};
877
- // 帮助函数:检查模块路径是否匹配
878
- var isModuleMatched = function isModuleMatched(relativeModulePath, preloadModule) {
879
- // 先尝试直接匹配
880
- if (relativeModulePath === preloadModule) return true;
881
- // 如果 preloadModule 没有后缀,尝试添加可能的后缀进行匹配
882
- for (var _iterator = _createForOfIteratorHelperLoose(extensions), _step; !(_step = _iterator()).done;) {
883
- var ext = _step.value;
884
- if (relativeModulePath === "" + preloadModule + ext) {
885
- return true;
886
- }
887
- }
888
- return false;
889
- };
890
- // 遍历打包生成的每个文件
1046
+ var filesMap = {};
1047
+ // First pass: Find remoteEntry file
891
1048
  for (var _i = 0, _Object$entries = Object.entries(bundle); _i < _Object$entries.length; _i++) {
892
1049
  var _Object$entries$_i = _Object$entries[_i],
893
- fileName = _Object$entries$_i[0],
1050
+ _ = _Object$entries$_i[0],
894
1051
  fileData = _Object$entries$_i[1];
895
1052
  if (mfOptions.filename.replace(/[\[\]]/g, '_').replace(/\.[^/.]+$/, '') === fileData.name || fileData.name === 'remoteEntry') {
896
1053
  remoteEntryFile = fileData.fileName;
897
- }
898
- if (fileData.type === 'chunk') {
899
- // 遍历该文件的所有模块
900
- for (var _i2 = 0, _Object$keys = Object.keys(fileData.modules); _i2 < _Object$keys.length; _i2++) {
901
- var modulePath = _Object$keys[_i2];
902
- // 将绝对路径转换为相对于 Vite root 的相对路径
903
- var relativeModulePath = path.relative(root, modulePath);
904
- // 检查模块是否在 preloadModules 列表中
905
- for (var _iterator2 = _createForOfIteratorHelperLoose(exposesModules), _step2; !(_step2 = _iterator2()).done;) {
906
- var preloadModule = _step2.value;
907
- var formatPreloadModule = preloadModule.replace('./', '');
908
- if (isModuleMatched(relativeModulePath, formatPreloadModule)) {
909
- var _filesContainingModul;
910
- if (!filesContainingModules[preloadModule]) {
911
- filesContainingModules[preloadModule] = {
912
- sync: [],
913
- async: []
914
- };
915
- }
916
- console.log(Object.keys(fileData.modules));
917
- filesContainingModules[preloadModule].sync.push(fileName);
918
- (_filesContainingModul = filesContainingModules[preloadModule].async).push.apply(_filesContainingModul, fileData.dynamicImports || []);
919
- _findSynchronousImports(fileName, filesContainingModules[preloadModule].sync);
920
- break; // 如果找到匹配,跳出循环
921
- }
922
- }
923
- }
1054
+ break; // We can break early since we only need to find remoteEntry once
924
1055
  }
925
1056
  }
926
- var fileToShareKey = {};
927
- return Promise.resolve(Promise.all(Array.from(getUsedShares()).map(function (shareKey) {
928
- try {
929
- return Promise.resolve(_this.resolve(getPreBuildLibImportId(shareKey))).then(function (_this$resolve) {
930
- var file = _this$resolve.id.split('?')[0];
931
- fileToShareKey[file] = shareKey;
932
- });
933
- } catch (e) {
934
- return Promise.reject(e);
935
- }
936
- }))).then(function () {
937
- // 遍历打包生成的每个文件
938
- for (var _i3 = 0, _Object$entries2 = Object.entries(bundle); _i3 < _Object$entries2.length; _i3++) {
939
- var _Object$entries2$_i = _Object$entries2[_i3],
940
- _fileName = _Object$entries2$_i[0],
941
- _fileData = _Object$entries2$_i[1];
942
- if (_fileData.type === 'chunk') {
943
- // 遍历该文件的所有模块
944
- for (var _i4 = 0, _Object$keys2 = Object.keys(_fileData.modules); _i4 < _Object$keys2.length; _i4++) {
945
- var _modulePath = _Object$keys2[_i4];
946
- var sharedKey = fileToShareKey[_modulePath];
947
- if (sharedKey) {
948
- var _filesContainingModul2;
949
- if (!filesContainingModules[sharedKey]) {
950
- filesContainingModules[sharedKey] = {
951
- sync: [],
952
- async: []
953
- };
954
- }
955
- filesContainingModules[sharedKey].sync.push(_fileName);
956
- (_filesContainingModul2 = filesContainingModules[sharedKey].async).push.apply(_filesContainingModul2, _fileData.dynamicImports || []);
957
- _findSynchronousImports(_fileName, filesContainingModules[sharedKey].sync);
958
- break; // 如果找到匹配,跳出循环
959
- }
960
- }
1057
+ // Second pass: Collect all CSS assets
1058
+ var allCssAssets = collectCssAssets(bundle);
1059
+ var exposesModules = Object.keys(mfOptions.exposes).map(function (item) {
1060
+ return mfOptions.exposes[item]["import"];
1061
+ });
1062
+ // Process exposed modules
1063
+ processModuleAssets(bundle, filesMap, function (modulePath) {
1064
+ var absoluteModulePath = path__namespace.resolve(root, modulePath);
1065
+ return exposesModules.find(function (exposeModule) {
1066
+ var exposePath = path__namespace.resolve(root, exposeModule);
1067
+ // First try exact path match
1068
+ if (absoluteModulePath === exposePath) {
1069
+ return true;
961
1070
  }
962
- }
963
- Object.keys(filesContainingModules).forEach(function (key) {
964
- filesContainingModules[key].sync = Array.from(new Set(filesContainingModules[key].sync));
965
- filesContainingModules[key].async = Array.from(new Set(filesContainingModules[key].async));
1071
+ // Then try path match without known extensions
1072
+ var getPathWithoutKnownExt = function getPathWithoutKnownExt(filePath) {
1073
+ var ext = path__namespace.extname(filePath);
1074
+ return JS_EXTENSIONS.includes(ext) ? path__namespace.join(path__namespace.dirname(filePath), path__namespace.basename(filePath, ext)) : filePath;
1075
+ };
1076
+ var modulePathNoExt = getPathWithoutKnownExt(absoluteModulePath);
1077
+ var exposePathNoExt = getPathWithoutKnownExt(exposePath);
1078
+ return modulePathNoExt === exposePathNoExt;
966
1079
  });
1080
+ });
1081
+ // Process shared modules
1082
+ return Promise.resolve(buildFileToShareKeyMap(getUsedShares(), _this.resolve.bind(_this))).then(function (fileToShareKey) {
1083
+ processModuleAssets(bundle, filesMap, function (modulePath) {
1084
+ return fileToShareKey.get(modulePath);
1085
+ });
1086
+ // Add all CSS assets to every export
1087
+ addCssAssetsToAllExports(filesMap, allCssAssets);
1088
+ // Final deduplication of all assets
1089
+ filesMap = deduplicateAssets(filesMap);
967
1090
  _this.emitFile({
968
1091
  type: 'asset',
969
1092
  fileName: mfManifestName,
970
- source: JSON.stringify(generateMFManifest(filesContainingModules))
1093
+ source: JSON.stringify(generateMFManifest(filesMap))
971
1094
  });
972
1095
  });
973
1096
  } catch (e) {
@@ -975,6 +1098,11 @@
975
1098
  }
976
1099
  }
977
1100
  }];
1101
+ /**
1102
+ * Generates the final manifest JSON structure
1103
+ * @param preloadMap - Map of module assets to include
1104
+ * @returns Complete manifest object
1105
+ */
978
1106
  function generateMFManifest(preloadMap) {
979
1107
  var options = getNormalizeModuleFederationOptions();
980
1108
  var name = options.name;
@@ -983,23 +1111,23 @@
983
1111
  path: '',
984
1112
  type: 'module'
985
1113
  };
986
- var remotes = [];
987
- var usedRemotesMap = getUsedRemotesMap();
988
- Object.keys(usedRemotesMap).forEach(function (remoteKey) {
989
- var usedModules = Array.from(usedRemotesMap[remoteKey]);
990
- usedModules.forEach(function (moduleKey) {
991
- remotes.push({
1114
+ // Process remotes
1115
+ var remotes = Array.from(Object.entries(getUsedRemotesMap())).flatMap(function (_ref2) {
1116
+ var remoteKey = _ref2[0],
1117
+ modules = _ref2[1];
1118
+ return Array.from(modules).map(function (moduleKey) {
1119
+ return {
992
1120
  federationContainerName: options.remotes[remoteKey].entry,
993
1121
  moduleName: moduleKey.replace(remoteKey, '').replace('/', ''),
994
1122
  alias: remoteKey,
995
1123
  entry: '*'
996
- });
1124
+ };
997
1125
  });
998
1126
  });
999
- // @ts-ignore
1127
+ // Process shared dependencies
1000
1128
  var shared = Array.from(getUsedShares()).map(function (shareKey) {
1001
- var _preloadMap$shareKey, _preloadMap$shareKey2;
1002
1129
  var shareItem = getNormalizeShareItem(shareKey);
1130
+ var assets = preloadMap[shareKey] || createEmptyAssetMap();
1003
1131
  return {
1004
1132
  id: name + ":" + shareKey,
1005
1133
  name: shareKey,
@@ -1007,42 +1135,40 @@
1007
1135
  requiredVersion: shareItem.shareConfig.requiredVersion,
1008
1136
  assets: {
1009
1137
  js: {
1010
- async: (preloadMap == null || (_preloadMap$shareKey = preloadMap[shareKey]) == null ? void 0 : _preloadMap$shareKey.async) || [],
1011
- sync: (preloadMap == null || (_preloadMap$shareKey2 = preloadMap[shareKey]) == null ? void 0 : _preloadMap$shareKey2.sync) || []
1138
+ async: assets.js.async,
1139
+ sync: assets.js.sync
1012
1140
  },
1013
1141
  css: {
1014
- async: [],
1015
- sync: []
1142
+ async: assets.css.async,
1143
+ sync: assets.css.sync
1016
1144
  }
1017
1145
  }
1018
1146
  };
1019
- }).filter(function (item) {
1020
- return item;
1021
- });
1022
- var exposes = Object.keys(options.exposes).map(function (key) {
1023
- var _preloadMap$sourceFil, _preloadMap$sourceFil2;
1024
- // assets(.css, .jpg, .svg等)其他资源, 不重要, 暂未处理
1147
+ }).filter(Boolean);
1148
+ // Process exposed modules
1149
+ var exposes = Object.entries(options.exposes).map(function (_ref3) {
1150
+ var key = _ref3[0],
1151
+ value = _ref3[1];
1025
1152
  var formatKey = key.replace('./', '');
1026
- var sourceFile = options.exposes[key]["import"];
1153
+ var sourceFile = value["import"];
1154
+ var assets = preloadMap[sourceFile] || createEmptyAssetMap();
1027
1155
  return {
1028
- id: name + ':' + formatKey,
1156
+ id: name + ":" + formatKey,
1029
1157
  name: formatKey,
1030
1158
  assets: {
1031
1159
  js: {
1032
- async: (preloadMap == null || (_preloadMap$sourceFil = preloadMap[sourceFile]) == null ? void 0 : _preloadMap$sourceFil.async) || [],
1033
- sync: (preloadMap == null || (_preloadMap$sourceFil2 = preloadMap[sourceFile]) == null ? void 0 : _preloadMap$sourceFil2.sync) || []
1160
+ async: assets.js.async,
1161
+ sync: assets.js.sync
1034
1162
  },
1035
1163
  css: {
1036
- sync: [],
1037
- async: []
1164
+ async: assets.css.async,
1165
+ sync: assets.css.sync
1038
1166
  }
1039
1167
  },
1040
1168
  path: key
1041
1169
  };
1042
- }).filter(function (item) {
1043
- return item;
1044
- }); // Filter out any null values
1045
- var result = {
1170
+ }).filter(Boolean);
1171
+ return {
1046
1172
  id: name,
1047
1173
  name: name,
1048
1174
  metaData: _extends({
@@ -1057,8 +1183,6 @@
1057
1183
  types: {
1058
1184
  path: '',
1059
1185
  name: ''
1060
- // "zip": "@mf-types.zip",
1061
- // "api": "@mf-types.d.ts"
1062
1186
  },
1063
1187
  globalName: name,
1064
1188
  pluginVersion: '0.2.5'
@@ -1071,7 +1195,6 @@
1071
1195
  remotes: remotes,
1072
1196
  exposes: exposes
1073
1197
  };
1074
- return result;
1075
1198
  }
1076
1199
  };
1077
1200
 
@@ -1,3 +1,3 @@
1
- import { Manifest, Plugin } from 'vite';
1
+ import { Plugin } from 'vite';
2
2
  declare const Manifest: () => Plugin[];
3
3
  export default Manifest;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,75 @@
1
+ export type OutputBundleItem = {
2
+ type: 'chunk' | 'asset';
3
+ name?: string;
4
+ fileName: string;
5
+ modules?: Record<string, unknown> | undefined;
6
+ dynamicImports?: string[] | undefined;
7
+ };
8
+ export declare const ASSET_TYPES: readonly ["js", "css"];
9
+ export declare const LOAD_TIMINGS: readonly ["sync", "async"];
10
+ export declare const JS_EXTENSIONS: readonly [".ts", ".tsx", ".jsx", ".mjs", ".cjs"];
11
+ export type AssetType = (typeof ASSET_TYPES)[number];
12
+ export type AssetMap = {
13
+ sync: string[];
14
+ async: string[];
15
+ };
16
+ export type PreloadMap = Record<string, {
17
+ [K in (typeof ASSET_TYPES)[number]]: AssetMap;
18
+ }>;
19
+ /**
20
+ * Creates an empty asset map structure for tracking JS and CSS assets
21
+ * @returns Initialized asset map with sync/async arrays for JS and CSS
22
+ */
23
+ export declare const createEmptyAssetMap: () => {
24
+ js: AssetMap;
25
+ css: AssetMap;
26
+ };
27
+ /**
28
+ * Tracks an asset in the preload map with deduplication
29
+ * @param map - The preload map to update
30
+ * @param key - The module key to track under
31
+ * @param fileName - The asset filename to track
32
+ * @param isAsync - Whether the asset is loaded async
33
+ * @param type - The asset type ('js' or 'css')
34
+ */
35
+ export declare const trackAsset: (map: PreloadMap, key: string, fileName: string, isAsync: boolean, type: AssetType) => void;
36
+ /**
37
+ * Checks if a file is a CSS file by extension
38
+ * @param fileName - The filename to check
39
+ * @returns True if file has a CSS extension (.css, .scss, .less)
40
+ */
41
+ export declare const isCSSFile: (fileName: string) => boolean;
42
+ /**
43
+ * Collects all CSS assets from the bundle
44
+ * @param bundle - The Rollup output bundle
45
+ * @returns Set of CSS asset filenames
46
+ */
47
+ export declare const collectCssAssets: (bundle: Record<string, OutputBundleItem>) => Set<string>;
48
+ /**
49
+ * Processes module assets and tracks them in the files map
50
+ * @param bundle - The Rollup output bundle
51
+ * @param filesMap - The preload map to populate
52
+ * @param moduleMatcher - Function that matches module paths to keys
53
+ */
54
+ export declare const processModuleAssets: (bundle: Record<string, OutputBundleItem>, filesMap: PreloadMap, moduleMatcher: (modulePath: string) => string | undefined) => void;
55
+ /**
56
+ * Adds global CSS assets to all module exports
57
+ * @param filesMap - The preload map to update
58
+ * @param cssAssets - Set of CSS asset filenames to add
59
+ */
60
+ export declare const addCssAssetsToAllExports: (filesMap: PreloadMap, cssAssets: Set<string>) => void;
61
+ /**
62
+ * Deduplicates assets in the files map
63
+ * @param filesMap - The preload map to deduplicate
64
+ * @returns New deduplicated preload map
65
+ */
66
+ export declare const deduplicateAssets: (filesMap: PreloadMap) => PreloadMap;
67
+ /**
68
+ * Builds a mapping between module files and their share keys
69
+ * @param shareKeys - Set of share keys to map
70
+ * @param resolveFn - Function to resolve module paths
71
+ * @returns Map of file paths to their corresponding share keys
72
+ */
73
+ export declare const buildFileToShareKeyMap: (shareKeys: Set<string>, resolveFn: (id: string) => Promise<{
74
+ id: string;
75
+ } | null>) => Promise<Map<string, string>>;