@module-federation/vite 1.8.0 → 1.8.1
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 +15 -3
- package/lib/index.esm.js +15 -3
- package/lib/index.modern.js +12 -3
- package/lib/index.umd.js +15 -3
- package/lib/utils/VirtualModule.d.ts +1 -0
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -556,6 +556,16 @@ var cacheMap = {};
|
|
|
556
556
|
/**
|
|
557
557
|
* Physically generate files as virtual modules under node_modules/__mf__virtual/*
|
|
558
558
|
*/
|
|
559
|
+
function assertModuleFound(tag, str) {
|
|
560
|
+
if (str === void 0) {
|
|
561
|
+
str = '';
|
|
562
|
+
}
|
|
563
|
+
var module = VirtualModule.findModule(tag, str);
|
|
564
|
+
if (!module) {
|
|
565
|
+
throw new Error("Module Federation shared module '" + str + "' not found. Please ensure it's installed as a dependency in your package.json.");
|
|
566
|
+
}
|
|
567
|
+
return module;
|
|
568
|
+
}
|
|
559
569
|
var VirtualModule = /*#__PURE__*/function () {
|
|
560
570
|
function VirtualModule(name, tag, suffix) {
|
|
561
571
|
if (tag === void 0) {
|
|
@@ -695,7 +705,7 @@ function getLoadShareModulePath(pkg) {
|
|
|
695
705
|
return filepath;
|
|
696
706
|
}
|
|
697
707
|
function writeLoadShareModule(pkg, shareItem, command) {
|
|
698
|
-
loadShareCacheMap[pkg].writeSync("\n
|
|
708
|
+
loadShareCacheMap[pkg].writeSync("\n\n ;() => import(" + JSON.stringify(getPreBuildLibImportId(pkg)) + ").catch(() => {});\n // dev uses dynamic import to separate chunks\n " + (command !== 'build' ? ";() => import(" + JSON.stringify(pkg) + ").catch(() => {});" : '') + "\n const {loadShare} = require(\"@module-federation/runtime\")\n const {initPromise} = require(\"" + virtualRuntimeInitStatus.getImportId() + "\")\n const res = initPromise.then(_ => loadShare(" + JSON.stringify(pkg) + ", {\n customShareInfo: {shareConfig:{\n singleton: " + shareItem.shareConfig.singleton + ",\n strictVersion: " + shareItem.shareConfig.strictVersion + ",\n requiredVersion: " + JSON.stringify(shareItem.shareConfig.requiredVersion) + "\n }}}))\n const exportModule = " + (command !== 'build' ? '/*mf top-level-await placeholder replacement mf*/' : 'await ') + "res.then(factory => factory())\n module.exports = exportModule\n ");
|
|
699
709
|
}
|
|
700
710
|
|
|
701
711
|
var usedShares = new Set();
|
|
@@ -1450,7 +1460,8 @@ function proxySharedModule(options) {
|
|
|
1450
1460
|
return command === 'build' ? {
|
|
1451
1461
|
find: new RegExp("(.*" + PREBUILD_TAG + ".*)"),
|
|
1452
1462
|
replacement: function replacement($1) {
|
|
1453
|
-
var
|
|
1463
|
+
var module = assertModuleFound(PREBUILD_TAG, $1);
|
|
1464
|
+
var pkgName = module.name;
|
|
1454
1465
|
return pkgName;
|
|
1455
1466
|
}
|
|
1456
1467
|
} : {
|
|
@@ -1459,7 +1470,8 @@ function proxySharedModule(options) {
|
|
|
1459
1470
|
customResolver: function customResolver(source, importer) {
|
|
1460
1471
|
try {
|
|
1461
1472
|
var _this = this;
|
|
1462
|
-
var
|
|
1473
|
+
var module = assertModuleFound(PREBUILD_TAG, source);
|
|
1474
|
+
var pkgName = module.name;
|
|
1463
1475
|
return Promise.resolve(_this.resolve(pkgName, importer).then(function (item) {
|
|
1464
1476
|
return item.id;
|
|
1465
1477
|
})).then(function (result) {
|
package/lib/index.esm.js
CHANGED
|
@@ -532,6 +532,16 @@ var cacheMap = {};
|
|
|
532
532
|
/**
|
|
533
533
|
* Physically generate files as virtual modules under node_modules/__mf__virtual/*
|
|
534
534
|
*/
|
|
535
|
+
function assertModuleFound(tag, str) {
|
|
536
|
+
if (str === void 0) {
|
|
537
|
+
str = '';
|
|
538
|
+
}
|
|
539
|
+
var module = VirtualModule.findModule(tag, str);
|
|
540
|
+
if (!module) {
|
|
541
|
+
throw new Error("Module Federation shared module '" + str + "' not found. Please ensure it's installed as a dependency in your package.json.");
|
|
542
|
+
}
|
|
543
|
+
return module;
|
|
544
|
+
}
|
|
535
545
|
var VirtualModule = /*#__PURE__*/function () {
|
|
536
546
|
function VirtualModule(name, tag, suffix) {
|
|
537
547
|
if (tag === void 0) {
|
|
@@ -671,7 +681,7 @@ function getLoadShareModulePath(pkg) {
|
|
|
671
681
|
return filepath;
|
|
672
682
|
}
|
|
673
683
|
function writeLoadShareModule(pkg, shareItem, command) {
|
|
674
|
-
loadShareCacheMap[pkg].writeSync("\n
|
|
684
|
+
loadShareCacheMap[pkg].writeSync("\n\n ;() => import(" + JSON.stringify(getPreBuildLibImportId(pkg)) + ").catch(() => {});\n // dev uses dynamic import to separate chunks\n " + (command !== 'build' ? ";() => import(" + JSON.stringify(pkg) + ").catch(() => {});" : '') + "\n const {loadShare} = require(\"@module-federation/runtime\")\n const {initPromise} = require(\"" + virtualRuntimeInitStatus.getImportId() + "\")\n const res = initPromise.then(_ => loadShare(" + JSON.stringify(pkg) + ", {\n customShareInfo: {shareConfig:{\n singleton: " + shareItem.shareConfig.singleton + ",\n strictVersion: " + shareItem.shareConfig.strictVersion + ",\n requiredVersion: " + JSON.stringify(shareItem.shareConfig.requiredVersion) + "\n }}}))\n const exportModule = " + (command !== 'build' ? '/*mf top-level-await placeholder replacement mf*/' : 'await ') + "res.then(factory => factory())\n module.exports = exportModule\n ");
|
|
675
685
|
}
|
|
676
686
|
|
|
677
687
|
var usedShares = new Set();
|
|
@@ -1426,7 +1436,8 @@ function proxySharedModule(options) {
|
|
|
1426
1436
|
return command === 'build' ? {
|
|
1427
1437
|
find: new RegExp("(.*" + PREBUILD_TAG + ".*)"),
|
|
1428
1438
|
replacement: function replacement($1) {
|
|
1429
|
-
var
|
|
1439
|
+
var module = assertModuleFound(PREBUILD_TAG, $1);
|
|
1440
|
+
var pkgName = module.name;
|
|
1430
1441
|
return pkgName;
|
|
1431
1442
|
}
|
|
1432
1443
|
} : {
|
|
@@ -1435,7 +1446,8 @@ function proxySharedModule(options) {
|
|
|
1435
1446
|
customResolver: function customResolver(source, importer) {
|
|
1436
1447
|
try {
|
|
1437
1448
|
var _this = this;
|
|
1438
|
-
var
|
|
1449
|
+
var module = assertModuleFound(PREBUILD_TAG, source);
|
|
1450
|
+
var pkgName = module.name;
|
|
1439
1451
|
return Promise.resolve(_this.resolve(pkgName, importer).then(function (item) {
|
|
1440
1452
|
return item.id;
|
|
1441
1453
|
})).then(function (result) {
|
package/lib/index.modern.js
CHANGED
|
@@ -500,6 +500,13 @@ const cacheMap = {};
|
|
|
500
500
|
/**
|
|
501
501
|
* Physically generate files as virtual modules under node_modules/__mf__virtual/*
|
|
502
502
|
*/
|
|
503
|
+
function assertModuleFound(tag, str = '') {
|
|
504
|
+
const module = VirtualModule.findModule(tag, str);
|
|
505
|
+
if (!module) {
|
|
506
|
+
throw new Error(`Module Federation shared module '${str}' not found. Please ensure it's installed as a dependency in your package.json.`);
|
|
507
|
+
}
|
|
508
|
+
return module;
|
|
509
|
+
}
|
|
503
510
|
class VirtualModule {
|
|
504
511
|
/**
|
|
505
512
|
* Set the root path for finding node_modules
|
|
@@ -663,7 +670,7 @@ function getLoadShareModulePath(pkg) {
|
|
|
663
670
|
}
|
|
664
671
|
function writeLoadShareModule(pkg, shareItem, command) {
|
|
665
672
|
loadShareCacheMap[pkg].writeSync(`
|
|
666
|
-
|
|
673
|
+
|
|
667
674
|
;() => import(${JSON.stringify(getPreBuildLibImportId(pkg))}).catch(() => {});
|
|
668
675
|
// dev uses dynamic import to separate chunks
|
|
669
676
|
${command !== 'build' ? `;() => import(${JSON.stringify(pkg)}).catch(() => {});` : ''}
|
|
@@ -1486,14 +1493,16 @@ function proxySharedModule(options) {
|
|
|
1486
1493
|
return command === 'build' ? {
|
|
1487
1494
|
find: new RegExp(`(.*${PREBUILD_TAG}.*)`),
|
|
1488
1495
|
replacement: function ($1) {
|
|
1489
|
-
const
|
|
1496
|
+
const module = assertModuleFound(PREBUILD_TAG, $1);
|
|
1497
|
+
const pkgName = module.name;
|
|
1490
1498
|
return pkgName;
|
|
1491
1499
|
}
|
|
1492
1500
|
} : {
|
|
1493
1501
|
find: new RegExp(`(.*${PREBUILD_TAG}.*)`),
|
|
1494
1502
|
replacement: '$1',
|
|
1495
1503
|
async customResolver(source, importer) {
|
|
1496
|
-
const
|
|
1504
|
+
const module = assertModuleFound(PREBUILD_TAG, source);
|
|
1505
|
+
const pkgName = module.name;
|
|
1497
1506
|
const result = await this.resolve(pkgName, importer).then(item => item.id);
|
|
1498
1507
|
if (!result.includes(_config.cacheDir)) {
|
|
1499
1508
|
// save pre-bunding module id
|
package/lib/index.umd.js
CHANGED
|
@@ -554,6 +554,16 @@
|
|
|
554
554
|
/**
|
|
555
555
|
* Physically generate files as virtual modules under node_modules/__mf__virtual/*
|
|
556
556
|
*/
|
|
557
|
+
function assertModuleFound(tag, str) {
|
|
558
|
+
if (str === void 0) {
|
|
559
|
+
str = '';
|
|
560
|
+
}
|
|
561
|
+
var module = VirtualModule.findModule(tag, str);
|
|
562
|
+
if (!module) {
|
|
563
|
+
throw new Error("Module Federation shared module '" + str + "' not found. Please ensure it's installed as a dependency in your package.json.");
|
|
564
|
+
}
|
|
565
|
+
return module;
|
|
566
|
+
}
|
|
557
567
|
var VirtualModule = /*#__PURE__*/function () {
|
|
558
568
|
function VirtualModule(name, tag, suffix) {
|
|
559
569
|
if (tag === void 0) {
|
|
@@ -693,7 +703,7 @@
|
|
|
693
703
|
return filepath;
|
|
694
704
|
}
|
|
695
705
|
function writeLoadShareModule(pkg, shareItem, command) {
|
|
696
|
-
loadShareCacheMap[pkg].writeSync("\n
|
|
706
|
+
loadShareCacheMap[pkg].writeSync("\n\n ;() => import(" + JSON.stringify(getPreBuildLibImportId(pkg)) + ").catch(() => {});\n // dev uses dynamic import to separate chunks\n " + (command !== 'build' ? ";() => import(" + JSON.stringify(pkg) + ").catch(() => {});" : '') + "\n const {loadShare} = require(\"@module-federation/runtime\")\n const {initPromise} = require(\"" + virtualRuntimeInitStatus.getImportId() + "\")\n const res = initPromise.then(_ => loadShare(" + JSON.stringify(pkg) + ", {\n customShareInfo: {shareConfig:{\n singleton: " + shareItem.shareConfig.singleton + ",\n strictVersion: " + shareItem.shareConfig.strictVersion + ",\n requiredVersion: " + JSON.stringify(shareItem.shareConfig.requiredVersion) + "\n }}}))\n const exportModule = " + (command !== 'build' ? '/*mf top-level-await placeholder replacement mf*/' : 'await ') + "res.then(factory => factory())\n module.exports = exportModule\n ");
|
|
697
707
|
}
|
|
698
708
|
|
|
699
709
|
var usedShares = new Set();
|
|
@@ -1448,7 +1458,8 @@
|
|
|
1448
1458
|
return command === 'build' ? {
|
|
1449
1459
|
find: new RegExp("(.*" + PREBUILD_TAG + ".*)"),
|
|
1450
1460
|
replacement: function replacement($1) {
|
|
1451
|
-
var
|
|
1461
|
+
var module = assertModuleFound(PREBUILD_TAG, $1);
|
|
1462
|
+
var pkgName = module.name;
|
|
1452
1463
|
return pkgName;
|
|
1453
1464
|
}
|
|
1454
1465
|
} : {
|
|
@@ -1457,7 +1468,8 @@
|
|
|
1457
1468
|
customResolver: function customResolver(source, importer) {
|
|
1458
1469
|
try {
|
|
1459
1470
|
var _this = this;
|
|
1460
|
-
var
|
|
1471
|
+
var module = assertModuleFound(PREBUILD_TAG, source);
|
|
1472
|
+
var pkgName = module.name;
|
|
1461
1473
|
return Promise.resolve(_this.resolve(pkgName, importer).then(function (item) {
|
|
1462
1474
|
return item.id;
|
|
1463
1475
|
})).then(function (result) {
|
|
@@ -2,6 +2,7 @@ export declare function getSuffix(name: string): string;
|
|
|
2
2
|
/**
|
|
3
3
|
* Physically generate files as virtual modules under node_modules/__mf__virtual/*
|
|
4
4
|
*/
|
|
5
|
+
export declare function assertModuleFound(tag: string, str?: string): VirtualModule;
|
|
5
6
|
export default class VirtualModule {
|
|
6
7
|
name: string;
|
|
7
8
|
tag: string;
|