@module-federation/vite 1.0.0-alpha-1aa30c0 → 1.0.0-alpha-2f53b4e

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.cjs CHANGED
@@ -309,6 +309,13 @@ function removePathFromNpmPackage(packageString) {
309
309
  // Return the matched package name or the original string if no match is found
310
310
  return match ? match[0] : packageString;
311
311
  }
312
+ function getExtFromNpmPackage(packageString) {
313
+ var pkgName = removePathFromNpmPackage(packageString);
314
+ var subpath = packageString.replace(pkgName, "");
315
+ var parts = subpath.split('.');
316
+ var ext = parts.length > 1 ? "." + parts.pop() : undefined;
317
+ return ext;
318
+ }
312
319
 
313
320
  var nodeModulesDir = function findNodeModulesDir(startDir) {
314
321
  if (startDir === void 0) {
@@ -337,27 +344,34 @@ fs.writeFileSync(path.resolve(nodeModulesDir, virtualPackageName, "package.json"
337
344
  * Physically generate files as virtual modules under node_modules/__mf__virtual/*
338
345
  */
339
346
  var VirtualModule = /*#__PURE__*/function () {
340
- function VirtualModule(name) {
347
+ function VirtualModule(name, ext) {
348
+ if (ext === void 0) {
349
+ ext = ".js";
350
+ }
341
351
  this.originName = void 0;
342
352
  this.inited = false;
353
+ this.ext = void 0;
343
354
  this.originName = name;
355
+ this.ext = ext;
344
356
  }
345
357
  var _proto = VirtualModule.prototype;
346
358
  _proto.getPath = function getPath() {
347
359
  return path.resolve(nodeModulesDir, this.getImportId());
348
360
  };
349
361
  _proto.getImportId = function getImportId() {
350
- return virtualPackageName + "/" + packageNameEncode(this.originName);
362
+ var _getNormalizeModuleFe = getNormalizeModuleFederationOptions(),
363
+ name = _getNormalizeModuleFe.name;
364
+ return virtualPackageName + "/" + packageNameEncode(name) + "-" + packageNameEncode(this.originName) + this.ext;
351
365
  };
352
366
  _proto.writeSync = function writeSync(code, force) {
353
367
  if (!force && this.inited) return;
354
368
  if (!this.inited) {
355
369
  this.inited = true;
356
370
  }
357
- fs.writeFileSync(this.getPath() + ".js", code);
371
+ fs.writeFileSync(this.getPath(), code);
358
372
  };
359
373
  _proto.write = function write(code) {
360
- fs.writeFile(this.getPath() + ".js", code, function () {});
374
+ fs.writeFile(this.getPath(), code, function () {});
361
375
  };
362
376
  return VirtualModule;
363
377
  }();
@@ -434,11 +448,11 @@ var writeLocalSharedImportMap = function writeLocalSharedImportMap() {
434
448
  var preBuildCacheMap = {};
435
449
  var PREBUILD_TAG = "__prebuild__";
436
450
  function writePreBuildLibPath(pkg) {
437
- if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = new VirtualModule(PREBUILD_TAG + pkg);
451
+ if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = new VirtualModule(PREBUILD_TAG + pkg, getExtFromNpmPackage(pkg));
438
452
  preBuildCacheMap[pkg].writeSync("");
439
453
  }
440
454
  function getPreBuildLibImportId(pkg) {
441
- if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = new VirtualModule(PREBUILD_TAG + pkg);
455
+ if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = new VirtualModule(PREBUILD_TAG + pkg, getExtFromNpmPackage(pkg));
442
456
  var importId = preBuildCacheMap[pkg].getImportId();
443
457
  return importId;
444
458
  }
@@ -448,7 +462,6 @@ function addShare(pkg) {
448
462
  }
449
463
  // *** Expose locally provided shared modules here
450
464
  var localSharedImportMapModule = new VirtualModule("localSharedImportMap");
451
- localSharedImportMapModule.writeSync("");
452
465
  function getLocalSharedImportMapPath() {
453
466
  if (process.platform === "win32") {
454
467
  return getLocalSharedImportMapPath_windows();
@@ -484,17 +497,49 @@ function generateRemoteEntry(options) {
484
497
  }).join(', ') + "]\n });\n initRes.initShareScopeMap('" + options.shareScope + "', shared);\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 ";
485
498
  }
486
499
  var wrapRemoteEntryModule = new VirtualModule("wrapRemoteEntry");
487
- wrapRemoteEntryModule.writeSync("\nimport {init, get} from \"" + REMOTE_ENTRY_ID + "\"\nexport {init, get}\n");
488
- var WRAP_REMOTE_ENTRY_QUERY_STR = wrapRemoteEntryModule.getImportId();
489
- var WRAP_REMOTE_ENTRY_PATH = wrapRemoteEntryModule.getPath();
500
+ function writeWrapRemoteEntry() {
501
+ wrapRemoteEntryModule.writeSync("\n import {init, get} from \"" + REMOTE_ENTRY_ID + "\"\n export {init, get}\n ");
502
+ }
503
+ function getWrapRemoteEntryImportId() {
504
+ return wrapRemoteEntryModule.getImportId();
505
+ }
506
+ function getWrapRemoteEntryPath() {
507
+ return wrapRemoteEntryModule.getPath();
508
+ }
490
509
  /**
491
510
  * Inject entry file, automatically init when used as host,
492
511
  * and will not inject remoteEntry
493
512
  */
494
513
  var hostAutoInitModule = new VirtualModule("hostAutoInit");
495
- hostAutoInitModule.writeSync("\n import {init} from \"" + REMOTE_ENTRY_ID + "\"\n init()\n ");
496
- var HOST_AUTO_INIT_QUERY_STR = hostAutoInitModule.getImportId();
497
- var HOST_AUTO_INIT_PATH = hostAutoInitModule.getPath();
514
+ function writeHostAutoInit() {
515
+ hostAutoInitModule.writeSync("\n import {init} from \"" + REMOTE_ENTRY_ID + "\"\n init()\n ");
516
+ }
517
+ function getHostAutoInitImportId() {
518
+ return hostAutoInitModule.getImportId();
519
+ }
520
+ function getHostAutoInitPath() {
521
+ return hostAutoInitModule.getPath();
522
+ }
523
+
524
+ var remoteVirtualModule = new VirtualModule("remoteModule");
525
+ function writeRemote() {
526
+ remoteVirtualModule.writeSync("");
527
+ }
528
+ function generateRemotes(id, command) {
529
+ return {
530
+ code: "\n import {loadRemote} from \"@module-federation/runtime\"\n const exportModule = await loadRemote(" + JSON.stringify(id) + ")\n " + (command === "build" && "\n export default 'default' in (exportModule || {}) ? exportModule.default : undefined\n export const __mf__dynamicExports = exportModule\n " || "") + "\n " + (command !== "build" && "\n export default exportModule\n " || "") + "\n ",
531
+ map: null,
532
+ // TODO: vite dev mode invalid, use optimizeDeps.needsInterop
533
+ syntheticNamedExports: '__mf__dynamicExports'
534
+ };
535
+ }
536
+
537
+ function initVirtualModules() {
538
+ writeLocalSharedImportMap();
539
+ writeWrapRemoteEntry();
540
+ writeHostAutoInit();
541
+ writeRemote();
542
+ }
498
543
 
499
544
  var filter$1 = pluginutils.createFilter();
500
545
  function pluginProxyRemoteEntry () {
@@ -525,17 +570,6 @@ function pluginProxyRemoteEntry () {
525
570
  };
526
571
  }
527
572
 
528
- var remoteVirtualModule = new VirtualModule("remoteModule");
529
- remoteVirtualModule.writeSync("");
530
- function generateRemotes(id, command) {
531
- return {
532
- code: "\n import {loadRemote} from \"@module-federation/runtime\"\n const exportModule = await loadRemote(" + JSON.stringify(id) + ")\n " + (command === "build" && "\n export default 'default' in (exportModule || {}) ? exportModule.default : undefined\n export const __mf__dynamicExports = exportModule\n " || "") + "\n " + (command !== "build" && "\n export default exportModule\n " || "") + "\n ",
533
- map: null,
534
- // TODO: vite dev mode invalid, use optimizeDeps.needsInterop
535
- syntheticNamedExports: '__mf__dynamicExports'
536
- };
537
- }
538
-
539
573
  var filter = pluginutils.createFilter();
540
574
  function pluginProxyRemotes (options) {
541
575
  var command;
@@ -701,25 +735,29 @@ function proxySharedModule(options) {
701
735
  var savePrebuild = new PromiseStore();
702
736
  (_config$resolve$alias2 = _config.resolve.alias).push.apply(_config$resolve$alias2, Object.keys(shared).map(function (key) {
703
737
  return command === "build" ? {
704
- find: new RegExp(virtualPackageName + "/" + PREBUILD_TAG + "(.+)"),
705
- replacement: function replacement(_, $1) {
706
- return packageNameDecode($1);
738
+ find: new RegExp("(.*" + PREBUILD_TAG + "(.+))"),
739
+ replacement: function replacement($1) {
740
+ $1 = $1.replace(/\.[^.]+$/, "");
741
+ var pkgName = packageNameDecode($1.split(PREBUILD_TAG)[1]);
742
+ return packageNameDecode(pkgName);
707
743
  }
708
744
  } : {
709
- find: new RegExp(virtualPackageName + "/" + PREBUILD_TAG + "(.+)"),
745
+ find: new RegExp("(.*" + PREBUILD_TAG + "(.+))"),
710
746
  replacement: "$1",
711
747
  customResolver: function customResolver(source, importer) {
712
748
  try {
713
749
  var _this = this;
750
+ source = source.replace(/\.[^.]+$/, "");
751
+ var pkgName = packageNameDecode(source.split(PREBUILD_TAG)[1]);
714
752
  if (importer.includes(LOAD_SHARE_TAG)) {
715
753
  // save pre-bunding module id
716
- savePrebuild.set(source, _this.resolve(packageNameDecode(source)).then(function (item) {
754
+ savePrebuild.set(pkgName, _this.resolve(pkgName).then(function (item) {
717
755
  return item.id;
718
756
  }));
719
757
  }
720
758
  // Fix localSharedImportMap import id
721
759
  var _resolve = _this.resolve;
722
- return Promise.resolve(savePrebuild.get(source)).then(function (_savePrebuild$get) {
760
+ return Promise.resolve(savePrebuild.get(pkgName)).then(function (_savePrebuild$get) {
723
761
  return Promise.resolve(_resolve.call(_this, _savePrebuild$get));
724
762
  });
725
763
  } catch (e) {
@@ -838,6 +876,8 @@ var normalizeOptimizeDepsPlugin = {
838
876
  _config.optimizeDeps = {};
839
877
  optimizeDeps = _config.optimizeDeps;
840
878
  }
879
+ // todo: fix this workaround
880
+ optimizeDeps.force = true;
841
881
  if (!optimizeDeps.include) optimizeDeps.include = [];
842
882
  if (!optimizeDeps.needsInterop) optimizeDeps.needsInterop = [];
843
883
  }
@@ -845,19 +885,20 @@ var normalizeOptimizeDepsPlugin = {
845
885
 
846
886
  function federation(mfUserOptions) {
847
887
  var options = normalizeModuleFederationOptions(mfUserOptions);
888
+ initVirtualModules();
848
889
  var name = options.name,
849
890
  shared = options.shared,
850
891
  filename = options.filename;
851
892
  if (!name) throw new Error("name is required");
852
893
  return [aliasToArrayPlugin, normalizeOptimizeDepsPlugin].concat(addEntry({
853
894
  entryName: 'remoteEntry',
854
- entryPath: WRAP_REMOTE_ENTRY_PATH,
895
+ entryPath: getWrapRemoteEntryPath(),
855
896
  fileName: filename
856
897
  }), addEntry({
857
898
  entryName: 'hostInit',
858
- entryPath: HOST_AUTO_INIT_PATH
899
+ entryPath: getHostAutoInitPath()
859
900
  }), [pluginProxyRemoteEntry(), pluginProxyRemotes(options)], pluginModuleParseEnd(function (id) {
860
- return id.includes(HOST_AUTO_INIT_QUERY_STR) || id.includes(WRAP_REMOTE_ENTRY_QUERY_STR) || id.includes(REMOTE_ENTRY_ID) || id.includes(getLocalSharedImportMapPath());
901
+ return id.includes(getHostAutoInitImportId()) || id.includes(getWrapRemoteEntryImportId()) || id.includes(REMOTE_ENTRY_ID) || id.includes(getLocalSharedImportMapPath());
861
902
  }), proxySharedModule({
862
903
  shared: shared
863
904
  }), [{
package/lib/index.esm.js CHANGED
@@ -286,6 +286,13 @@ function removePathFromNpmPackage(packageString) {
286
286
  // Return the matched package name or the original string if no match is found
287
287
  return match ? match[0] : packageString;
288
288
  }
289
+ function getExtFromNpmPackage(packageString) {
290
+ var pkgName = removePathFromNpmPackage(packageString);
291
+ var subpath = packageString.replace(pkgName, "");
292
+ var parts = subpath.split('.');
293
+ var ext = parts.length > 1 ? "." + parts.pop() : undefined;
294
+ return ext;
295
+ }
289
296
 
290
297
  var nodeModulesDir = function findNodeModulesDir(startDir) {
291
298
  if (startDir === void 0) {
@@ -314,27 +321,34 @@ writeFileSync(resolve(nodeModulesDir, virtualPackageName, "package.json"), JSON.
314
321
  * Physically generate files as virtual modules under node_modules/__mf__virtual/*
315
322
  */
316
323
  var VirtualModule = /*#__PURE__*/function () {
317
- function VirtualModule(name) {
324
+ function VirtualModule(name, ext) {
325
+ if (ext === void 0) {
326
+ ext = ".js";
327
+ }
318
328
  this.originName = void 0;
319
329
  this.inited = false;
330
+ this.ext = void 0;
320
331
  this.originName = name;
332
+ this.ext = ext;
321
333
  }
322
334
  var _proto = VirtualModule.prototype;
323
335
  _proto.getPath = function getPath() {
324
336
  return resolve(nodeModulesDir, this.getImportId());
325
337
  };
326
338
  _proto.getImportId = function getImportId() {
327
- return virtualPackageName + "/" + packageNameEncode(this.originName);
339
+ var _getNormalizeModuleFe = getNormalizeModuleFederationOptions(),
340
+ name = _getNormalizeModuleFe.name;
341
+ return virtualPackageName + "/" + packageNameEncode(name) + "-" + packageNameEncode(this.originName) + this.ext;
328
342
  };
329
343
  _proto.writeSync = function writeSync(code, force) {
330
344
  if (!force && this.inited) return;
331
345
  if (!this.inited) {
332
346
  this.inited = true;
333
347
  }
334
- writeFileSync(this.getPath() + ".js", code);
348
+ writeFileSync(this.getPath(), code);
335
349
  };
336
350
  _proto.write = function write(code) {
337
- writeFile(this.getPath() + ".js", code, function () {});
351
+ writeFile(this.getPath(), code, function () {});
338
352
  };
339
353
  return VirtualModule;
340
354
  }();
@@ -411,11 +425,11 @@ var writeLocalSharedImportMap = function writeLocalSharedImportMap() {
411
425
  var preBuildCacheMap = {};
412
426
  var PREBUILD_TAG = "__prebuild__";
413
427
  function writePreBuildLibPath(pkg) {
414
- if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = new VirtualModule(PREBUILD_TAG + pkg);
428
+ if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = new VirtualModule(PREBUILD_TAG + pkg, getExtFromNpmPackage(pkg));
415
429
  preBuildCacheMap[pkg].writeSync("");
416
430
  }
417
431
  function getPreBuildLibImportId(pkg) {
418
- if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = new VirtualModule(PREBUILD_TAG + pkg);
432
+ if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = new VirtualModule(PREBUILD_TAG + pkg, getExtFromNpmPackage(pkg));
419
433
  var importId = preBuildCacheMap[pkg].getImportId();
420
434
  return importId;
421
435
  }
@@ -425,7 +439,6 @@ function addShare(pkg) {
425
439
  }
426
440
  // *** Expose locally provided shared modules here
427
441
  var localSharedImportMapModule = new VirtualModule("localSharedImportMap");
428
- localSharedImportMapModule.writeSync("");
429
442
  function getLocalSharedImportMapPath() {
430
443
  if (process.platform === "win32") {
431
444
  return getLocalSharedImportMapPath_windows();
@@ -461,17 +474,49 @@ function generateRemoteEntry(options) {
461
474
  }).join(', ') + "]\n });\n initRes.initShareScopeMap('" + options.shareScope + "', shared);\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 ";
462
475
  }
463
476
  var wrapRemoteEntryModule = new VirtualModule("wrapRemoteEntry");
464
- wrapRemoteEntryModule.writeSync("\nimport {init, get} from \"" + REMOTE_ENTRY_ID + "\"\nexport {init, get}\n");
465
- var WRAP_REMOTE_ENTRY_QUERY_STR = wrapRemoteEntryModule.getImportId();
466
- var WRAP_REMOTE_ENTRY_PATH = wrapRemoteEntryModule.getPath();
477
+ function writeWrapRemoteEntry() {
478
+ wrapRemoteEntryModule.writeSync("\n import {init, get} from \"" + REMOTE_ENTRY_ID + "\"\n export {init, get}\n ");
479
+ }
480
+ function getWrapRemoteEntryImportId() {
481
+ return wrapRemoteEntryModule.getImportId();
482
+ }
483
+ function getWrapRemoteEntryPath() {
484
+ return wrapRemoteEntryModule.getPath();
485
+ }
467
486
  /**
468
487
  * Inject entry file, automatically init when used as host,
469
488
  * and will not inject remoteEntry
470
489
  */
471
490
  var hostAutoInitModule = new VirtualModule("hostAutoInit");
472
- hostAutoInitModule.writeSync("\n import {init} from \"" + REMOTE_ENTRY_ID + "\"\n init()\n ");
473
- var HOST_AUTO_INIT_QUERY_STR = hostAutoInitModule.getImportId();
474
- var HOST_AUTO_INIT_PATH = hostAutoInitModule.getPath();
491
+ function writeHostAutoInit() {
492
+ hostAutoInitModule.writeSync("\n import {init} from \"" + REMOTE_ENTRY_ID + "\"\n init()\n ");
493
+ }
494
+ function getHostAutoInitImportId() {
495
+ return hostAutoInitModule.getImportId();
496
+ }
497
+ function getHostAutoInitPath() {
498
+ return hostAutoInitModule.getPath();
499
+ }
500
+
501
+ var remoteVirtualModule = new VirtualModule("remoteModule");
502
+ function writeRemote() {
503
+ remoteVirtualModule.writeSync("");
504
+ }
505
+ function generateRemotes(id, command) {
506
+ return {
507
+ code: "\n import {loadRemote} from \"@module-federation/runtime\"\n const exportModule = await loadRemote(" + JSON.stringify(id) + ")\n " + (command === "build" && "\n export default 'default' in (exportModule || {}) ? exportModule.default : undefined\n export const __mf__dynamicExports = exportModule\n " || "") + "\n " + (command !== "build" && "\n export default exportModule\n " || "") + "\n ",
508
+ map: null,
509
+ // TODO: vite dev mode invalid, use optimizeDeps.needsInterop
510
+ syntheticNamedExports: '__mf__dynamicExports'
511
+ };
512
+ }
513
+
514
+ function initVirtualModules() {
515
+ writeLocalSharedImportMap();
516
+ writeWrapRemoteEntry();
517
+ writeHostAutoInit();
518
+ writeRemote();
519
+ }
475
520
 
476
521
  var filter$1 = createFilter();
477
522
  function pluginProxyRemoteEntry () {
@@ -502,17 +547,6 @@ function pluginProxyRemoteEntry () {
502
547
  };
503
548
  }
504
549
 
505
- var remoteVirtualModule = new VirtualModule("remoteModule");
506
- remoteVirtualModule.writeSync("");
507
- function generateRemotes(id, command) {
508
- return {
509
- code: "\n import {loadRemote} from \"@module-federation/runtime\"\n const exportModule = await loadRemote(" + JSON.stringify(id) + ")\n " + (command === "build" && "\n export default 'default' in (exportModule || {}) ? exportModule.default : undefined\n export const __mf__dynamicExports = exportModule\n " || "") + "\n " + (command !== "build" && "\n export default exportModule\n " || "") + "\n ",
510
- map: null,
511
- // TODO: vite dev mode invalid, use optimizeDeps.needsInterop
512
- syntheticNamedExports: '__mf__dynamicExports'
513
- };
514
- }
515
-
516
550
  var filter = createFilter();
517
551
  function pluginProxyRemotes (options) {
518
552
  var command;
@@ -678,25 +712,29 @@ function proxySharedModule(options) {
678
712
  var savePrebuild = new PromiseStore();
679
713
  (_config$resolve$alias2 = _config.resolve.alias).push.apply(_config$resolve$alias2, Object.keys(shared).map(function (key) {
680
714
  return command === "build" ? {
681
- find: new RegExp(virtualPackageName + "/" + PREBUILD_TAG + "(.+)"),
682
- replacement: function replacement(_, $1) {
683
- return packageNameDecode($1);
715
+ find: new RegExp("(.*" + PREBUILD_TAG + "(.+))"),
716
+ replacement: function replacement($1) {
717
+ $1 = $1.replace(/\.[^.]+$/, "");
718
+ var pkgName = packageNameDecode($1.split(PREBUILD_TAG)[1]);
719
+ return packageNameDecode(pkgName);
684
720
  }
685
721
  } : {
686
- find: new RegExp(virtualPackageName + "/" + PREBUILD_TAG + "(.+)"),
722
+ find: new RegExp("(.*" + PREBUILD_TAG + "(.+))"),
687
723
  replacement: "$1",
688
724
  customResolver: function customResolver(source, importer) {
689
725
  try {
690
726
  var _this = this;
727
+ source = source.replace(/\.[^.]+$/, "");
728
+ var pkgName = packageNameDecode(source.split(PREBUILD_TAG)[1]);
691
729
  if (importer.includes(LOAD_SHARE_TAG)) {
692
730
  // save pre-bunding module id
693
- savePrebuild.set(source, _this.resolve(packageNameDecode(source)).then(function (item) {
731
+ savePrebuild.set(pkgName, _this.resolve(pkgName).then(function (item) {
694
732
  return item.id;
695
733
  }));
696
734
  }
697
735
  // Fix localSharedImportMap import id
698
736
  var _resolve = _this.resolve;
699
- return Promise.resolve(savePrebuild.get(source)).then(function (_savePrebuild$get) {
737
+ return Promise.resolve(savePrebuild.get(pkgName)).then(function (_savePrebuild$get) {
700
738
  return Promise.resolve(_resolve.call(_this, _savePrebuild$get));
701
739
  });
702
740
  } catch (e) {
@@ -815,6 +853,8 @@ var normalizeOptimizeDepsPlugin = {
815
853
  _config.optimizeDeps = {};
816
854
  optimizeDeps = _config.optimizeDeps;
817
855
  }
856
+ // todo: fix this workaround
857
+ optimizeDeps.force = true;
818
858
  if (!optimizeDeps.include) optimizeDeps.include = [];
819
859
  if (!optimizeDeps.needsInterop) optimizeDeps.needsInterop = [];
820
860
  }
@@ -822,19 +862,20 @@ var normalizeOptimizeDepsPlugin = {
822
862
 
823
863
  function federation(mfUserOptions) {
824
864
  var options = normalizeModuleFederationOptions(mfUserOptions);
865
+ initVirtualModules();
825
866
  var name = options.name,
826
867
  shared = options.shared,
827
868
  filename = options.filename;
828
869
  if (!name) throw new Error("name is required");
829
870
  return [aliasToArrayPlugin, normalizeOptimizeDepsPlugin].concat(addEntry({
830
871
  entryName: 'remoteEntry',
831
- entryPath: WRAP_REMOTE_ENTRY_PATH,
872
+ entryPath: getWrapRemoteEntryPath(),
832
873
  fileName: filename
833
874
  }), addEntry({
834
875
  entryName: 'hostInit',
835
- entryPath: HOST_AUTO_INIT_PATH
876
+ entryPath: getHostAutoInitPath()
836
877
  }), [pluginProxyRemoteEntry(), pluginProxyRemotes(options)], pluginModuleParseEnd(function (id) {
837
- return id.includes(HOST_AUTO_INIT_QUERY_STR) || id.includes(WRAP_REMOTE_ENTRY_QUERY_STR) || id.includes(REMOTE_ENTRY_ID) || id.includes(getLocalSharedImportMapPath());
878
+ return id.includes(getHostAutoInitImportId()) || id.includes(getWrapRemoteEntryImportId()) || id.includes(REMOTE_ENTRY_ID) || id.includes(getLocalSharedImportMapPath());
838
879
  }), proxySharedModule({
839
880
  shared: shared
840
881
  }), [{
@@ -291,6 +291,13 @@ function removePathFromNpmPackage(packageString) {
291
291
  // Return the matched package name or the original string if no match is found
292
292
  return match ? match[0] : packageString;
293
293
  }
294
+ function getExtFromNpmPackage(packageString) {
295
+ const pkgName = removePathFromNpmPackage(packageString);
296
+ const subpath = packageString.replace(pkgName, "");
297
+ const parts = subpath.split('.');
298
+ const ext = parts.length > 1 ? "." + parts.pop() : undefined;
299
+ return ext;
300
+ }
294
301
 
295
302
  const nodeModulesDir = function findNodeModulesDir(startDir = process.cwd()) {
296
303
  let currentDir = startDir;
@@ -316,26 +323,31 @@ writeFileSync(resolve(nodeModulesDir, virtualPackageName, "package.json"), JSON.
316
323
  * Physically generate files as virtual modules under node_modules/__mf__virtual/*
317
324
  */
318
325
  class VirtualModule {
319
- constructor(name) {
326
+ constructor(name, ext = ".js") {
320
327
  this.originName = void 0;
321
328
  this.inited = false;
329
+ this.ext = void 0;
322
330
  this.originName = name;
331
+ this.ext = ext;
323
332
  }
324
333
  getPath() {
325
334
  return resolve(nodeModulesDir, this.getImportId());
326
335
  }
327
336
  getImportId() {
328
- return `${virtualPackageName}/${packageNameEncode(this.originName)}`;
337
+ const {
338
+ name
339
+ } = getNormalizeModuleFederationOptions();
340
+ return `${virtualPackageName}/${packageNameEncode(name)}-${packageNameEncode(this.originName)}${this.ext}`;
329
341
  }
330
342
  writeSync(code, force) {
331
343
  if (!force && this.inited) return;
332
344
  if (!this.inited) {
333
345
  this.inited = true;
334
346
  }
335
- writeFileSync(this.getPath() + ".js", code);
347
+ writeFileSync(this.getPath(), code);
336
348
  }
337
349
  write(code) {
338
- writeFile(this.getPath() + ".js", code, function () {});
350
+ writeFile(this.getPath(), code, function () {});
339
351
  }
340
352
  }
341
353
 
@@ -369,11 +381,11 @@ function createFile(filePath, content) {
369
381
  const preBuildCacheMap = {};
370
382
  const PREBUILD_TAG = "__prebuild__";
371
383
  function writePreBuildLibPath(pkg) {
372
- if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = new VirtualModule(PREBUILD_TAG + pkg);
384
+ if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = new VirtualModule(PREBUILD_TAG + pkg, getExtFromNpmPackage(pkg));
373
385
  preBuildCacheMap[pkg].writeSync("");
374
386
  }
375
387
  function getPreBuildLibImportId(pkg) {
376
- if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = new VirtualModule(PREBUILD_TAG + pkg);
388
+ if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = new VirtualModule(PREBUILD_TAG + pkg, getExtFromNpmPackage(pkg));
377
389
  const importId = preBuildCacheMap[pkg].getImportId();
378
390
  return importId;
379
391
  }
@@ -383,7 +395,6 @@ function addShare(pkg) {
383
395
  }
384
396
  // *** Expose locally provided shared modules here
385
397
  const localSharedImportMapModule = new VirtualModule("localSharedImportMap");
386
- localSharedImportMapModule.writeSync("");
387
398
  function getLocalSharedImportMapPath() {
388
399
  if (process.platform === "win32") {
389
400
  return getLocalSharedImportMapPath_windows();
@@ -531,23 +542,65 @@ function generateRemoteEntry(options) {
531
542
  `;
532
543
  }
533
544
  const wrapRemoteEntryModule = new VirtualModule("wrapRemoteEntry");
534
- wrapRemoteEntryModule.writeSync(`
535
- import {init, get} from "${REMOTE_ENTRY_ID}"
536
- export {init, get}
537
- `);
538
- const WRAP_REMOTE_ENTRY_QUERY_STR = wrapRemoteEntryModule.getImportId();
539
- const WRAP_REMOTE_ENTRY_PATH = wrapRemoteEntryModule.getPath();
545
+ function writeWrapRemoteEntry() {
546
+ wrapRemoteEntryModule.writeSync(`
547
+ import {init, get} from "${REMOTE_ENTRY_ID}"
548
+ export {init, get}
549
+ `);
550
+ }
551
+ function getWrapRemoteEntryImportId() {
552
+ return wrapRemoteEntryModule.getImportId();
553
+ }
554
+ function getWrapRemoteEntryPath() {
555
+ return wrapRemoteEntryModule.getPath();
556
+ }
540
557
  /**
541
558
  * Inject entry file, automatically init when used as host,
542
559
  * and will not inject remoteEntry
543
560
  */
544
561
  const hostAutoInitModule = new VirtualModule("hostAutoInit");
545
- hostAutoInitModule.writeSync(`
562
+ function writeHostAutoInit() {
563
+ hostAutoInitModule.writeSync(`
546
564
  import {init} from "${REMOTE_ENTRY_ID}"
547
565
  init()
548
566
  `);
549
- const HOST_AUTO_INIT_QUERY_STR = hostAutoInitModule.getImportId();
550
- const HOST_AUTO_INIT_PATH = hostAutoInitModule.getPath();
567
+ }
568
+ function getHostAutoInitImportId() {
569
+ return hostAutoInitModule.getImportId();
570
+ }
571
+ function getHostAutoInitPath() {
572
+ return hostAutoInitModule.getPath();
573
+ }
574
+
575
+ const remoteVirtualModule = new VirtualModule("remoteModule");
576
+ function writeRemote() {
577
+ remoteVirtualModule.writeSync("");
578
+ }
579
+ function generateRemotes(id, command) {
580
+ return {
581
+ code: `
582
+ import {loadRemote} from "@module-federation/runtime"
583
+ const exportModule = await loadRemote(${JSON.stringify(id)})
584
+ ${command === "build" && `
585
+ export default 'default' in (exportModule || {}) ? exportModule.default : undefined
586
+ export const __mf__dynamicExports = exportModule
587
+ ` || ""}
588
+ ${command !== "build" && `
589
+ export default exportModule
590
+ ` || ""}
591
+ `,
592
+ map: null,
593
+ // TODO: vite dev mode invalid, use optimizeDeps.needsInterop
594
+ syntheticNamedExports: '__mf__dynamicExports'
595
+ };
596
+ }
597
+
598
+ function initVirtualModules() {
599
+ writeLocalSharedImportMap();
600
+ writeWrapRemoteEntry();
601
+ writeHostAutoInit();
602
+ writeRemote();
603
+ }
551
604
 
552
605
  const filter$1 = createFilter();
553
606
  function pluginProxyRemoteEntry () {
@@ -573,27 +626,6 @@ function pluginProxyRemoteEntry () {
573
626
  };
574
627
  }
575
628
 
576
- const remoteVirtualModule = new VirtualModule("remoteModule");
577
- remoteVirtualModule.writeSync("");
578
- function generateRemotes(id, command) {
579
- return {
580
- code: `
581
- import {loadRemote} from "@module-federation/runtime"
582
- const exportModule = await loadRemote(${JSON.stringify(id)})
583
- ${command === "build" && `
584
- export default 'default' in (exportModule || {}) ? exportModule.default : undefined
585
- export const __mf__dynamicExports = exportModule
586
- ` || ""}
587
- ${command !== "build" && `
588
- export default exportModule
589
- ` || ""}
590
- `,
591
- map: null,
592
- // TODO: vite dev mode invalid, use optimizeDeps.needsInterop
593
- syntheticNamedExports: '__mf__dynamicExports'
594
- };
595
- }
596
-
597
629
  const filter = createFilter();
598
630
  function pluginProxyRemotes (options) {
599
631
  let command;
@@ -750,20 +782,24 @@ function proxySharedModule(options) {
750
782
  const savePrebuild = new PromiseStore();
751
783
  config.resolve.alias.push(...Object.keys(shared).map(key => {
752
784
  return command === "build" ? {
753
- find: new RegExp(`${virtualPackageName}/${PREBUILD_TAG}(.+)`),
754
- replacement: function (_, $1) {
755
- return packageNameDecode($1);
785
+ find: new RegExp(`(.*${PREBUILD_TAG}(.+))`),
786
+ replacement: function ($1) {
787
+ $1 = $1.replace(/\.[^.]+$/, "");
788
+ const pkgName = packageNameDecode($1.split(PREBUILD_TAG)[1]);
789
+ return packageNameDecode(pkgName);
756
790
  }
757
791
  } : {
758
- find: new RegExp(`${virtualPackageName}/${PREBUILD_TAG}(.+)`),
792
+ find: new RegExp(`(.*${PREBUILD_TAG}(.+))`),
759
793
  replacement: "$1",
760
794
  async customResolver(source, importer) {
795
+ source = source.replace(/\.[^.]+$/, "");
796
+ const pkgName = packageNameDecode(source.split(PREBUILD_TAG)[1]);
761
797
  if (importer.includes(LOAD_SHARE_TAG)) {
762
798
  // save pre-bunding module id
763
- savePrebuild.set(source, this.resolve(packageNameDecode(source)).then(item => item.id));
799
+ savePrebuild.set(pkgName, this.resolve(pkgName).then(item => item.id));
764
800
  }
765
801
  // Fix localSharedImportMap import id
766
- return await this.resolve(await savePrebuild.get(source));
802
+ return await this.resolve(await savePrebuild.get(pkgName));
767
803
  }
768
804
  };
769
805
  }));
@@ -887,6 +923,8 @@ var normalizeOptimizeDepsPlugin = {
887
923
  config.optimizeDeps = {};
888
924
  optimizeDeps = config.optimizeDeps;
889
925
  }
926
+ // todo: fix this workaround
927
+ optimizeDeps.force = true;
890
928
  if (!optimizeDeps.include) optimizeDeps.include = [];
891
929
  if (!optimizeDeps.needsInterop) optimizeDeps.needsInterop = [];
892
930
  }
@@ -894,6 +932,7 @@ var normalizeOptimizeDepsPlugin = {
894
932
 
895
933
  function federation(mfUserOptions) {
896
934
  const options = normalizeModuleFederationOptions(mfUserOptions);
935
+ initVirtualModules();
897
936
  const {
898
937
  name,
899
938
  remotes,
@@ -903,13 +942,13 @@ function federation(mfUserOptions) {
903
942
  if (!name) throw new Error("name is required");
904
943
  return [aliasToArrayPlugin, normalizeOptimizeDepsPlugin, ...addEntry({
905
944
  entryName: 'remoteEntry',
906
- entryPath: WRAP_REMOTE_ENTRY_PATH,
945
+ entryPath: getWrapRemoteEntryPath(),
907
946
  fileName: filename
908
947
  }), ...addEntry({
909
948
  entryName: 'hostInit',
910
- entryPath: HOST_AUTO_INIT_PATH
949
+ entryPath: getHostAutoInitPath()
911
950
  }), pluginProxyRemoteEntry(), pluginProxyRemotes(options), ...pluginModuleParseEnd(id => {
912
- return id.includes(HOST_AUTO_INIT_QUERY_STR) || id.includes(WRAP_REMOTE_ENTRY_QUERY_STR) || id.includes(REMOTE_ENTRY_ID) || id.includes(getLocalSharedImportMapPath());
951
+ return id.includes(getHostAutoInitImportId()) || id.includes(getWrapRemoteEntryImportId()) || id.includes(REMOTE_ENTRY_ID) || id.includes(getLocalSharedImportMapPath());
913
952
  }), ...proxySharedModule({
914
953
  shared
915
954
  }), {
package/lib/index.umd.js CHANGED
@@ -307,6 +307,13 @@
307
307
  // Return the matched package name or the original string if no match is found
308
308
  return match ? match[0] : packageString;
309
309
  }
310
+ function getExtFromNpmPackage(packageString) {
311
+ var pkgName = removePathFromNpmPackage(packageString);
312
+ var subpath = packageString.replace(pkgName, "");
313
+ var parts = subpath.split('.');
314
+ var ext = parts.length > 1 ? "." + parts.pop() : undefined;
315
+ return ext;
316
+ }
310
317
 
311
318
  var nodeModulesDir = function findNodeModulesDir(startDir) {
312
319
  if (startDir === void 0) {
@@ -335,27 +342,34 @@
335
342
  * Physically generate files as virtual modules under node_modules/__mf__virtual/*
336
343
  */
337
344
  var VirtualModule = /*#__PURE__*/function () {
338
- function VirtualModule(name) {
345
+ function VirtualModule(name, ext) {
346
+ if (ext === void 0) {
347
+ ext = ".js";
348
+ }
339
349
  this.originName = void 0;
340
350
  this.inited = false;
351
+ this.ext = void 0;
341
352
  this.originName = name;
353
+ this.ext = ext;
342
354
  }
343
355
  var _proto = VirtualModule.prototype;
344
356
  _proto.getPath = function getPath() {
345
357
  return path.resolve(nodeModulesDir, this.getImportId());
346
358
  };
347
359
  _proto.getImportId = function getImportId() {
348
- return virtualPackageName + "/" + packageNameEncode(this.originName);
360
+ var _getNormalizeModuleFe = getNormalizeModuleFederationOptions(),
361
+ name = _getNormalizeModuleFe.name;
362
+ return virtualPackageName + "/" + packageNameEncode(name) + "-" + packageNameEncode(this.originName) + this.ext;
349
363
  };
350
364
  _proto.writeSync = function writeSync(code, force) {
351
365
  if (!force && this.inited) return;
352
366
  if (!this.inited) {
353
367
  this.inited = true;
354
368
  }
355
- fs.writeFileSync(this.getPath() + ".js", code);
369
+ fs.writeFileSync(this.getPath(), code);
356
370
  };
357
371
  _proto.write = function write(code) {
358
- fs.writeFile(this.getPath() + ".js", code, function () {});
372
+ fs.writeFile(this.getPath(), code, function () {});
359
373
  };
360
374
  return VirtualModule;
361
375
  }();
@@ -432,11 +446,11 @@
432
446
  var preBuildCacheMap = {};
433
447
  var PREBUILD_TAG = "__prebuild__";
434
448
  function writePreBuildLibPath(pkg) {
435
- if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = new VirtualModule(PREBUILD_TAG + pkg);
449
+ if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = new VirtualModule(PREBUILD_TAG + pkg, getExtFromNpmPackage(pkg));
436
450
  preBuildCacheMap[pkg].writeSync("");
437
451
  }
438
452
  function getPreBuildLibImportId(pkg) {
439
- if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = new VirtualModule(PREBUILD_TAG + pkg);
453
+ if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = new VirtualModule(PREBUILD_TAG + pkg, getExtFromNpmPackage(pkg));
440
454
  var importId = preBuildCacheMap[pkg].getImportId();
441
455
  return importId;
442
456
  }
@@ -446,7 +460,6 @@
446
460
  }
447
461
  // *** Expose locally provided shared modules here
448
462
  var localSharedImportMapModule = new VirtualModule("localSharedImportMap");
449
- localSharedImportMapModule.writeSync("");
450
463
  function getLocalSharedImportMapPath() {
451
464
  if (process.platform === "win32") {
452
465
  return getLocalSharedImportMapPath_windows();
@@ -482,17 +495,49 @@
482
495
  }).join(', ') + "]\n });\n initRes.initShareScopeMap('" + options.shareScope + "', shared);\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 ";
483
496
  }
484
497
  var wrapRemoteEntryModule = new VirtualModule("wrapRemoteEntry");
485
- wrapRemoteEntryModule.writeSync("\nimport {init, get} from \"" + REMOTE_ENTRY_ID + "\"\nexport {init, get}\n");
486
- var WRAP_REMOTE_ENTRY_QUERY_STR = wrapRemoteEntryModule.getImportId();
487
- var WRAP_REMOTE_ENTRY_PATH = wrapRemoteEntryModule.getPath();
498
+ function writeWrapRemoteEntry() {
499
+ wrapRemoteEntryModule.writeSync("\n import {init, get} from \"" + REMOTE_ENTRY_ID + "\"\n export {init, get}\n ");
500
+ }
501
+ function getWrapRemoteEntryImportId() {
502
+ return wrapRemoteEntryModule.getImportId();
503
+ }
504
+ function getWrapRemoteEntryPath() {
505
+ return wrapRemoteEntryModule.getPath();
506
+ }
488
507
  /**
489
508
  * Inject entry file, automatically init when used as host,
490
509
  * and will not inject remoteEntry
491
510
  */
492
511
  var hostAutoInitModule = new VirtualModule("hostAutoInit");
493
- hostAutoInitModule.writeSync("\n import {init} from \"" + REMOTE_ENTRY_ID + "\"\n init()\n ");
494
- var HOST_AUTO_INIT_QUERY_STR = hostAutoInitModule.getImportId();
495
- var HOST_AUTO_INIT_PATH = hostAutoInitModule.getPath();
512
+ function writeHostAutoInit() {
513
+ hostAutoInitModule.writeSync("\n import {init} from \"" + REMOTE_ENTRY_ID + "\"\n init()\n ");
514
+ }
515
+ function getHostAutoInitImportId() {
516
+ return hostAutoInitModule.getImportId();
517
+ }
518
+ function getHostAutoInitPath() {
519
+ return hostAutoInitModule.getPath();
520
+ }
521
+
522
+ var remoteVirtualModule = new VirtualModule("remoteModule");
523
+ function writeRemote() {
524
+ remoteVirtualModule.writeSync("");
525
+ }
526
+ function generateRemotes(id, command) {
527
+ return {
528
+ code: "\n import {loadRemote} from \"@module-federation/runtime\"\n const exportModule = await loadRemote(" + JSON.stringify(id) + ")\n " + (command === "build" && "\n export default 'default' in (exportModule || {}) ? exportModule.default : undefined\n export const __mf__dynamicExports = exportModule\n " || "") + "\n " + (command !== "build" && "\n export default exportModule\n " || "") + "\n ",
529
+ map: null,
530
+ // TODO: vite dev mode invalid, use optimizeDeps.needsInterop
531
+ syntheticNamedExports: '__mf__dynamicExports'
532
+ };
533
+ }
534
+
535
+ function initVirtualModules() {
536
+ writeLocalSharedImportMap();
537
+ writeWrapRemoteEntry();
538
+ writeHostAutoInit();
539
+ writeRemote();
540
+ }
496
541
 
497
542
  var filter$1 = pluginutils.createFilter();
498
543
  function pluginProxyRemoteEntry () {
@@ -523,17 +568,6 @@
523
568
  };
524
569
  }
525
570
 
526
- var remoteVirtualModule = new VirtualModule("remoteModule");
527
- remoteVirtualModule.writeSync("");
528
- function generateRemotes(id, command) {
529
- return {
530
- code: "\n import {loadRemote} from \"@module-federation/runtime\"\n const exportModule = await loadRemote(" + JSON.stringify(id) + ")\n " + (command === "build" && "\n export default 'default' in (exportModule || {}) ? exportModule.default : undefined\n export const __mf__dynamicExports = exportModule\n " || "") + "\n " + (command !== "build" && "\n export default exportModule\n " || "") + "\n ",
531
- map: null,
532
- // TODO: vite dev mode invalid, use optimizeDeps.needsInterop
533
- syntheticNamedExports: '__mf__dynamicExports'
534
- };
535
- }
536
-
537
571
  var filter = pluginutils.createFilter();
538
572
  function pluginProxyRemotes (options) {
539
573
  var command;
@@ -699,25 +733,29 @@
699
733
  var savePrebuild = new PromiseStore();
700
734
  (_config$resolve$alias2 = _config.resolve.alias).push.apply(_config$resolve$alias2, Object.keys(shared).map(function (key) {
701
735
  return command === "build" ? {
702
- find: new RegExp(virtualPackageName + "/" + PREBUILD_TAG + "(.+)"),
703
- replacement: function replacement(_, $1) {
704
- return packageNameDecode($1);
736
+ find: new RegExp("(.*" + PREBUILD_TAG + "(.+))"),
737
+ replacement: function replacement($1) {
738
+ $1 = $1.replace(/\.[^.]+$/, "");
739
+ var pkgName = packageNameDecode($1.split(PREBUILD_TAG)[1]);
740
+ return packageNameDecode(pkgName);
705
741
  }
706
742
  } : {
707
- find: new RegExp(virtualPackageName + "/" + PREBUILD_TAG + "(.+)"),
743
+ find: new RegExp("(.*" + PREBUILD_TAG + "(.+))"),
708
744
  replacement: "$1",
709
745
  customResolver: function customResolver(source, importer) {
710
746
  try {
711
747
  var _this = this;
748
+ source = source.replace(/\.[^.]+$/, "");
749
+ var pkgName = packageNameDecode(source.split(PREBUILD_TAG)[1]);
712
750
  if (importer.includes(LOAD_SHARE_TAG)) {
713
751
  // save pre-bunding module id
714
- savePrebuild.set(source, _this.resolve(packageNameDecode(source)).then(function (item) {
752
+ savePrebuild.set(pkgName, _this.resolve(pkgName).then(function (item) {
715
753
  return item.id;
716
754
  }));
717
755
  }
718
756
  // Fix localSharedImportMap import id
719
757
  var _resolve = _this.resolve;
720
- return Promise.resolve(savePrebuild.get(source)).then(function (_savePrebuild$get) {
758
+ return Promise.resolve(savePrebuild.get(pkgName)).then(function (_savePrebuild$get) {
721
759
  return Promise.resolve(_resolve.call(_this, _savePrebuild$get));
722
760
  });
723
761
  } catch (e) {
@@ -836,6 +874,8 @@
836
874
  _config.optimizeDeps = {};
837
875
  optimizeDeps = _config.optimizeDeps;
838
876
  }
877
+ // todo: fix this workaround
878
+ optimizeDeps.force = true;
839
879
  if (!optimizeDeps.include) optimizeDeps.include = [];
840
880
  if (!optimizeDeps.needsInterop) optimizeDeps.needsInterop = [];
841
881
  }
@@ -843,19 +883,20 @@
843
883
 
844
884
  function federation(mfUserOptions) {
845
885
  var options = normalizeModuleFederationOptions(mfUserOptions);
886
+ initVirtualModules();
846
887
  var name = options.name,
847
888
  shared = options.shared,
848
889
  filename = options.filename;
849
890
  if (!name) throw new Error("name is required");
850
891
  return [aliasToArrayPlugin, normalizeOptimizeDepsPlugin].concat(addEntry({
851
892
  entryName: 'remoteEntry',
852
- entryPath: WRAP_REMOTE_ENTRY_PATH,
893
+ entryPath: getWrapRemoteEntryPath(),
853
894
  fileName: filename
854
895
  }), addEntry({
855
896
  entryName: 'hostInit',
856
- entryPath: HOST_AUTO_INIT_PATH
897
+ entryPath: getHostAutoInitPath()
857
898
  }), [pluginProxyRemoteEntry(), pluginProxyRemotes(options)], pluginModuleParseEnd(function (id) {
858
- return id.includes(HOST_AUTO_INIT_QUERY_STR) || id.includes(WRAP_REMOTE_ENTRY_QUERY_STR) || id.includes(REMOTE_ENTRY_ID) || id.includes(getLocalSharedImportMapPath());
899
+ return id.includes(getHostAutoInitImportId()) || id.includes(getWrapRemoteEntryImportId()) || id.includes(REMOTE_ENTRY_ID) || id.includes(getLocalSharedImportMapPath());
859
900
  }), proxySharedModule({
860
901
  shared: shared
861
902
  }), [{
@@ -5,7 +5,8 @@ export declare const virtualPackageName = "__mf__virtual";
5
5
  export default class VirtualModule {
6
6
  originName: string;
7
7
  inited: boolean;
8
- constructor(name: string);
8
+ ext: string;
9
+ constructor(name: string, ext?: string);
9
10
  getPath(): string;
10
11
  getImportId(): string;
11
12
  writeSync(code: string, force?: boolean): void;
@@ -15,3 +15,4 @@ export declare function packageNameEncode(name: string): string;
15
15
  */
16
16
  export declare function packageNameDecode(global: string): string;
17
17
  export declare function removePathFromNpmPackage(packageString: string): string;
18
+ export declare function getExtFromNpmPackage(packageString: string): string | undefined;
@@ -0,0 +1,4 @@
1
+ export { generateRemoteEntry, getHostAutoInitImportId, getHostAutoInitPath, getWrapRemoteEntryImportId, getWrapRemoteEntryPath, REMOTE_ENTRY_ID } from "./virtualRemoteEntry";
2
+ export { generateRemotes, remoteVirtualModule } from "./virtualRemotes";
3
+ export { addShare, generateLocalSharedImportMap, getLoadShareModulePath, getLocalSharedImportMapPath, getPreBuildLibImportId, LOAD_SHARE_TAG, localSharedImportMapModule, PREBUILD_TAG, writeLoadShareModule, writeLocalSharedImportMap, writePreBuildLibPath } from "./virtualShared_preBuild";
4
+ export declare function initVirtualModules(): void;
@@ -1,7 +1,9 @@
1
1
  import { NormalizedModuleFederationOptions } from '../utils/normalizeModuleFederationOptions';
2
2
  export declare const REMOTE_ENTRY_ID = "REMOTE_ENTRY_ID";
3
3
  export declare function generateRemoteEntry(options: NormalizedModuleFederationOptions): string;
4
- export declare const WRAP_REMOTE_ENTRY_QUERY_STR: string;
5
- export declare const WRAP_REMOTE_ENTRY_PATH: string;
6
- export declare const HOST_AUTO_INIT_QUERY_STR: string;
7
- export declare const HOST_AUTO_INIT_PATH: string;
4
+ export declare function writeWrapRemoteEntry(): void;
5
+ export declare function getWrapRemoteEntryImportId(): string;
6
+ export declare function getWrapRemoteEntryPath(): string;
7
+ export declare function writeHostAutoInit(): void;
8
+ export declare function getHostAutoInitImportId(): string;
9
+ export declare function getHostAutoInitPath(): string;
@@ -1,5 +1,6 @@
1
1
  import VirtualModule from "../utils/VirtualModule";
2
2
  export declare const remoteVirtualModule: VirtualModule;
3
+ export declare function writeRemote(): void;
3
4
  export declare function generateRemotes(id: string, command: string): {
4
5
  code: string;
5
6
  map: null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/vite",
3
- "version": "1.0.0-alpha-1aa30c0",
3
+ "version": "1.0.0-alpha-2f53b4e",
4
4
  "description": "Vite plugin for Module Federation",
5
5
  "type": "module",
6
6
  "source": "src/index.ts",
@@ -16,7 +16,8 @@
16
16
  "build": "rimraf lib && microbundle --no-sourcemap --compress=false",
17
17
  "dev-rv": "pnpm -filter 'examples-rust-vite*' run dev",
18
18
  "dev-vv": "pnpm -filter 'examples-vite-vite*' run dev",
19
- "preview-vv": "pnpm -filter 'examples-vite-vite*' run preview"
19
+ "dev-nv": "pnpm -filter 'examples-nuxt-vite-host' -filter 'examples-vite-vite-remote' run dev",
20
+ "preview-vv": "pnpm -filter 'examples-vite-vite*' run preview"
20
21
  },
21
22
  "repository": {
22
23
  "type": "git",
@@ -39,7 +40,7 @@
39
40
  "homepage": "https://github.com/module-federation/vite#readme",
40
41
  "packageManager": "pnpm@9.1.3",
41
42
  "dependencies": {
42
- "@module-federation/runtime": "^0.5.0",
43
+ "@module-federation/runtime": "^0.6.0",
43
44
  "@rollup/pluginutils": "^5.1.0",
44
45
  "estree-walker": "^2",
45
46
  "magic-string": "^0.30.11",
@@ -52,6 +53,6 @@
52
53
  "mime-types": "^2.1.35",
53
54
  "pretty-quick": "^4.0.0",
54
55
  "rimraf": "^6.0.1",
55
- "vite": "^5.4.1"
56
+ "vite": "^5.4.3"
56
57
  }
57
58
  }