@module-federation/vite 1.9.0 → 1.9.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.cjs +103 -52
- package/lib/index.esm.js +103 -52
- package/lib/index.modern.js +82 -25
- package/lib/index.umd.js +103 -52
- package/lib/plugins/__tests__/pluginCheckAliasConflicts.test.d.ts +1 -0
- package/lib/plugins/pluginCheckAliasConflicts.d.ts +9 -0
- package/package.json +17 -19
- package/lib/utils/logUtils.d.ts +0 -1
package/lib/index.cjs
CHANGED
|
@@ -171,6 +171,101 @@ var addEntry = function addEntry(_ref) {
|
|
|
171
171
|
}];
|
|
172
172
|
};
|
|
173
173
|
|
|
174
|
+
function _arrayLikeToArray(r, a) {
|
|
175
|
+
(null == a || a > r.length) && (a = r.length);
|
|
176
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
177
|
+
return n;
|
|
178
|
+
}
|
|
179
|
+
function _createForOfIteratorHelperLoose(r, e) {
|
|
180
|
+
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
181
|
+
if (t) return (t = t.call(r)).next.bind(t);
|
|
182
|
+
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
|
|
183
|
+
t && (r = t);
|
|
184
|
+
var o = 0;
|
|
185
|
+
return function () {
|
|
186
|
+
return o >= r.length ? {
|
|
187
|
+
done: !0
|
|
188
|
+
} : {
|
|
189
|
+
done: !1,
|
|
190
|
+
value: r[o++]
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
195
|
+
}
|
|
196
|
+
function _extends() {
|
|
197
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
198
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
199
|
+
var t = arguments[e];
|
|
200
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
201
|
+
}
|
|
202
|
+
return n;
|
|
203
|
+
}, _extends.apply(null, arguments);
|
|
204
|
+
}
|
|
205
|
+
function _unsupportedIterableToArray(r, a) {
|
|
206
|
+
if (r) {
|
|
207
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
208
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
209
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Check if user-defined alias conflicts with shared modules
|
|
215
|
+
* This should run after aliasToArrayPlugin to ensure alias is an array
|
|
216
|
+
*/
|
|
217
|
+
function checkAliasConflicts(options) {
|
|
218
|
+
var _options$shared = options.shared,
|
|
219
|
+
shared = _options$shared === void 0 ? {} : _options$shared;
|
|
220
|
+
var sharedKeys = Object.keys(shared);
|
|
221
|
+
return {
|
|
222
|
+
name: 'check-alias-conflicts',
|
|
223
|
+
configResolved: function configResolved(config) {
|
|
224
|
+
var _config$resolve;
|
|
225
|
+
if (sharedKeys.length === 0) return;
|
|
226
|
+
var userAliases = ((_config$resolve = config.resolve) == null ? void 0 : _config$resolve.alias) || [];
|
|
227
|
+
var conflicts = [];
|
|
228
|
+
for (var _i = 0, _sharedKeys = sharedKeys; _i < _sharedKeys.length; _i++) {
|
|
229
|
+
var sharedKey = _sharedKeys[_i];
|
|
230
|
+
for (var _iterator = _createForOfIteratorHelperLoose(userAliases), _step; !(_step = _iterator()).done;) {
|
|
231
|
+
var aliasEntry = _step.value;
|
|
232
|
+
var findPattern = aliasEntry.find;
|
|
233
|
+
var replacement = aliasEntry.replacement;
|
|
234
|
+
// Skip if replacement is not a string (e.g., customResolver)
|
|
235
|
+
if (typeof replacement !== 'string') continue;
|
|
236
|
+
// Skip Module Federation internal aliases (used for proxying shared modules)
|
|
237
|
+
// These are generated with replacement '$1' and should not trigger warnings
|
|
238
|
+
if (replacement === '$1') continue;
|
|
239
|
+
// Check if alias pattern matches the shared module
|
|
240
|
+
var isMatch = false;
|
|
241
|
+
if (typeof findPattern === 'string') {
|
|
242
|
+
isMatch = findPattern === sharedKey || sharedKey.startsWith(findPattern + '/');
|
|
243
|
+
} else if (findPattern instanceof RegExp) {
|
|
244
|
+
isMatch = findPattern.test(sharedKey);
|
|
245
|
+
}
|
|
246
|
+
if (isMatch) {
|
|
247
|
+
conflicts.push({
|
|
248
|
+
sharedModule: sharedKey,
|
|
249
|
+
alias: String(findPattern),
|
|
250
|
+
target: replacement
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (conflicts.length > 0) {
|
|
256
|
+
config.logger.warn('\n[Module Federation] Detected alias conflicts with shared modules:');
|
|
257
|
+
conflicts.forEach(function (_ref) {
|
|
258
|
+
var sharedModule = _ref.sharedModule,
|
|
259
|
+
alias = _ref.alias,
|
|
260
|
+
target = _ref.target;
|
|
261
|
+
config.logger.warn(" - Shared module \"" + sharedModule + "\" is aliased by \"" + alias + "\" to \"" + target + "\"");
|
|
262
|
+
});
|
|
263
|
+
config.logger.warn(" This may cause runtime errors as the shared module will bypass Module Federation's sharing mechanism.");
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
174
269
|
/**
|
|
175
270
|
* Solve the problem that dev mode dependency prebunding does not support top-level await syntax
|
|
176
271
|
*/
|
|
@@ -247,51 +342,6 @@ function PluginDevProxyModuleTopLevelAwait() {
|
|
|
247
342
|
};
|
|
248
343
|
}
|
|
249
344
|
|
|
250
|
-
function _arrayLikeToArray(r, a) {
|
|
251
|
-
(null == a || a > r.length) && (a = r.length);
|
|
252
|
-
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
253
|
-
return n;
|
|
254
|
-
}
|
|
255
|
-
function _createForOfIteratorHelperLoose(r, e) {
|
|
256
|
-
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
257
|
-
if (t) return (t = t.call(r)).next.bind(t);
|
|
258
|
-
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
|
|
259
|
-
t && (r = t);
|
|
260
|
-
var o = 0;
|
|
261
|
-
return function () {
|
|
262
|
-
return o >= r.length ? {
|
|
263
|
-
done: !0
|
|
264
|
-
} : {
|
|
265
|
-
done: !1,
|
|
266
|
-
value: r[o++]
|
|
267
|
-
};
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
271
|
-
}
|
|
272
|
-
function _extends() {
|
|
273
|
-
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
274
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
275
|
-
var t = arguments[e];
|
|
276
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
277
|
-
}
|
|
278
|
-
return n;
|
|
279
|
-
}, _extends.apply(null, arguments);
|
|
280
|
-
}
|
|
281
|
-
function _unsupportedIterableToArray(r, a) {
|
|
282
|
-
if (r) {
|
|
283
|
-
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
284
|
-
var t = {}.toString.call(r).slice(8, -1);
|
|
285
|
-
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
var warn = function warn(message) {
|
|
290
|
-
return message.split('\n').forEach(function (msg) {
|
|
291
|
-
return console.warn('\x1b[33m%s\x1b[0m', msg);
|
|
292
|
-
});
|
|
293
|
-
};
|
|
294
|
-
|
|
295
345
|
function normalizeExposesItem(key, item) {
|
|
296
346
|
var importPath = '';
|
|
297
347
|
if (typeof item === 'string') {
|
|
@@ -460,9 +510,6 @@ function getNormalizeShareItem(key) {
|
|
|
460
510
|
return shareItem;
|
|
461
511
|
}
|
|
462
512
|
function normalizeModuleFederationOptions(options) {
|
|
463
|
-
if (options.getPublicPath) {
|
|
464
|
-
warn("We are ignoring the getPublicPath options because they are natively supported by Vite\nwith the \"experimental.renderBuiltUrl\" configuration https://vitejs.dev/guide/build#advanced-base-options");
|
|
465
|
-
}
|
|
466
513
|
if (options.virtualModuleDir && options.virtualModuleDir.includes('/')) {
|
|
467
514
|
throw new Error("Invalid virtualModuleDir: \"" + options.virtualModuleDir + "\". " + "The virtualModuleDir option cannot contain slashes (/). " + "Please use a single directory name like '__mf__virtual__your_app_name'.");
|
|
468
515
|
}
|
|
@@ -671,7 +718,9 @@ function generateExposes() {
|
|
|
671
718
|
|
|
672
719
|
var virtualRuntimeInitStatus = new VirtualModule('runtimeInit');
|
|
673
720
|
function writeRuntimeInitStatus() {
|
|
674
|
-
|
|
721
|
+
// Use globalThis singleton to ensure only one initPromise exists
|
|
722
|
+
var globalKey = "__mf_init__" + virtualRuntimeInitStatus.getImportId() + "__";
|
|
723
|
+
virtualRuntimeInitStatus.writeSync("\n const globalKey = " + JSON.stringify(globalKey) + "\n if (!globalThis[globalKey]) {\n let initResolve, initReject\n const initPromise = new Promise((re, rj) => {\n initResolve = re\n initReject = rj\n })\n globalThis[globalKey] = {\n initPromise,\n initResolve,\n initReject\n }\n }\n module.exports = globalThis[globalKey]\n ");
|
|
675
724
|
}
|
|
676
725
|
|
|
677
726
|
var cacheRemoteMap = {};
|
|
@@ -695,7 +744,7 @@ function getUsedRemotesMap() {
|
|
|
695
744
|
return usedRemotesMap;
|
|
696
745
|
}
|
|
697
746
|
function generateRemotes(id, command) {
|
|
698
|
-
return "\n const {
|
|
747
|
+
return "\n const {initPromise} = require(\"" + virtualRuntimeInitStatus.getImportId() + "\")\n const res = initPromise.then(runtime => runtime.loadRemote(" + JSON.stringify(id) + "))\n const exportModule = " + (command !== 'build' ? '/*mf top-level-await placeholder replacement mf*/' : 'await ') + "initPromise.then(_ => res)\n module.exports = exportModule\n ";
|
|
699
748
|
}
|
|
700
749
|
|
|
701
750
|
/**
|
|
@@ -724,7 +773,7 @@ function getLoadShareModulePath(pkg) {
|
|
|
724
773
|
return filepath;
|
|
725
774
|
}
|
|
726
775
|
function writeLoadShareModule(pkg, shareItem, command) {
|
|
727
|
-
loadShareCacheMap[pkg].writeSync("\n
|
|
776
|
+
loadShareCacheMap[pkg].writeSync("\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 {initPromise} = require(\"" + virtualRuntimeInitStatus.getImportId() + "\")\n const res = initPromise.then(runtime => runtime.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 }))\n const exportModule = " + (command !== 'build' ? '/*mf top-level-await placeholder replacement mf*/' : 'await ') + "res.then(factory => factory())\n module.exports = exportModule\n ");
|
|
728
777
|
}
|
|
729
778
|
|
|
730
779
|
var usedShares = new Set();
|
|
@@ -1566,7 +1615,9 @@ function federation(mfUserOptions) {
|
|
|
1566
1615
|
VirtualModule.ensureVirtualPackageExists();
|
|
1567
1616
|
initVirtualModules();
|
|
1568
1617
|
}
|
|
1569
|
-
}, aliasToArrayPlugin,
|
|
1618
|
+
}, aliasToArrayPlugin, checkAliasConflicts({
|
|
1619
|
+
shared: shared
|
|
1620
|
+
}), normalizeOptimizeDepsPlugin].concat(addEntry({
|
|
1570
1621
|
entryName: 'remoteEntry',
|
|
1571
1622
|
entryPath: REMOTE_ENTRY_ID,
|
|
1572
1623
|
fileName: filename
|
package/lib/index.esm.js
CHANGED
|
@@ -147,6 +147,101 @@ var addEntry = function addEntry(_ref) {
|
|
|
147
147
|
}];
|
|
148
148
|
};
|
|
149
149
|
|
|
150
|
+
function _arrayLikeToArray(r, a) {
|
|
151
|
+
(null == a || a > r.length) && (a = r.length);
|
|
152
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
153
|
+
return n;
|
|
154
|
+
}
|
|
155
|
+
function _createForOfIteratorHelperLoose(r, e) {
|
|
156
|
+
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
157
|
+
if (t) return (t = t.call(r)).next.bind(t);
|
|
158
|
+
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
|
|
159
|
+
t && (r = t);
|
|
160
|
+
var o = 0;
|
|
161
|
+
return function () {
|
|
162
|
+
return o >= r.length ? {
|
|
163
|
+
done: !0
|
|
164
|
+
} : {
|
|
165
|
+
done: !1,
|
|
166
|
+
value: r[o++]
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
171
|
+
}
|
|
172
|
+
function _extends() {
|
|
173
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
174
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
175
|
+
var t = arguments[e];
|
|
176
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
177
|
+
}
|
|
178
|
+
return n;
|
|
179
|
+
}, _extends.apply(null, arguments);
|
|
180
|
+
}
|
|
181
|
+
function _unsupportedIterableToArray(r, a) {
|
|
182
|
+
if (r) {
|
|
183
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
184
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
185
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Check if user-defined alias conflicts with shared modules
|
|
191
|
+
* This should run after aliasToArrayPlugin to ensure alias is an array
|
|
192
|
+
*/
|
|
193
|
+
function checkAliasConflicts(options) {
|
|
194
|
+
var _options$shared = options.shared,
|
|
195
|
+
shared = _options$shared === void 0 ? {} : _options$shared;
|
|
196
|
+
var sharedKeys = Object.keys(shared);
|
|
197
|
+
return {
|
|
198
|
+
name: 'check-alias-conflicts',
|
|
199
|
+
configResolved: function configResolved(config) {
|
|
200
|
+
var _config$resolve;
|
|
201
|
+
if (sharedKeys.length === 0) return;
|
|
202
|
+
var userAliases = ((_config$resolve = config.resolve) == null ? void 0 : _config$resolve.alias) || [];
|
|
203
|
+
var conflicts = [];
|
|
204
|
+
for (var _i = 0, _sharedKeys = sharedKeys; _i < _sharedKeys.length; _i++) {
|
|
205
|
+
var sharedKey = _sharedKeys[_i];
|
|
206
|
+
for (var _iterator = _createForOfIteratorHelperLoose(userAliases), _step; !(_step = _iterator()).done;) {
|
|
207
|
+
var aliasEntry = _step.value;
|
|
208
|
+
var findPattern = aliasEntry.find;
|
|
209
|
+
var replacement = aliasEntry.replacement;
|
|
210
|
+
// Skip if replacement is not a string (e.g., customResolver)
|
|
211
|
+
if (typeof replacement !== 'string') continue;
|
|
212
|
+
// Skip Module Federation internal aliases (used for proxying shared modules)
|
|
213
|
+
// These are generated with replacement '$1' and should not trigger warnings
|
|
214
|
+
if (replacement === '$1') continue;
|
|
215
|
+
// Check if alias pattern matches the shared module
|
|
216
|
+
var isMatch = false;
|
|
217
|
+
if (typeof findPattern === 'string') {
|
|
218
|
+
isMatch = findPattern === sharedKey || sharedKey.startsWith(findPattern + '/');
|
|
219
|
+
} else if (findPattern instanceof RegExp) {
|
|
220
|
+
isMatch = findPattern.test(sharedKey);
|
|
221
|
+
}
|
|
222
|
+
if (isMatch) {
|
|
223
|
+
conflicts.push({
|
|
224
|
+
sharedModule: sharedKey,
|
|
225
|
+
alias: String(findPattern),
|
|
226
|
+
target: replacement
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (conflicts.length > 0) {
|
|
232
|
+
config.logger.warn('\n[Module Federation] Detected alias conflicts with shared modules:');
|
|
233
|
+
conflicts.forEach(function (_ref) {
|
|
234
|
+
var sharedModule = _ref.sharedModule,
|
|
235
|
+
alias = _ref.alias,
|
|
236
|
+
target = _ref.target;
|
|
237
|
+
config.logger.warn(" - Shared module \"" + sharedModule + "\" is aliased by \"" + alias + "\" to \"" + target + "\"");
|
|
238
|
+
});
|
|
239
|
+
config.logger.warn(" This may cause runtime errors as the shared module will bypass Module Federation's sharing mechanism.");
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
150
245
|
/**
|
|
151
246
|
* Solve the problem that dev mode dependency prebunding does not support top-level await syntax
|
|
152
247
|
*/
|
|
@@ -223,51 +318,6 @@ function PluginDevProxyModuleTopLevelAwait() {
|
|
|
223
318
|
};
|
|
224
319
|
}
|
|
225
320
|
|
|
226
|
-
function _arrayLikeToArray(r, a) {
|
|
227
|
-
(null == a || a > r.length) && (a = r.length);
|
|
228
|
-
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
229
|
-
return n;
|
|
230
|
-
}
|
|
231
|
-
function _createForOfIteratorHelperLoose(r, e) {
|
|
232
|
-
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
233
|
-
if (t) return (t = t.call(r)).next.bind(t);
|
|
234
|
-
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
|
|
235
|
-
t && (r = t);
|
|
236
|
-
var o = 0;
|
|
237
|
-
return function () {
|
|
238
|
-
return o >= r.length ? {
|
|
239
|
-
done: !0
|
|
240
|
-
} : {
|
|
241
|
-
done: !1,
|
|
242
|
-
value: r[o++]
|
|
243
|
-
};
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
247
|
-
}
|
|
248
|
-
function _extends() {
|
|
249
|
-
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
250
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
251
|
-
var t = arguments[e];
|
|
252
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
253
|
-
}
|
|
254
|
-
return n;
|
|
255
|
-
}, _extends.apply(null, arguments);
|
|
256
|
-
}
|
|
257
|
-
function _unsupportedIterableToArray(r, a) {
|
|
258
|
-
if (r) {
|
|
259
|
-
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
260
|
-
var t = {}.toString.call(r).slice(8, -1);
|
|
261
|
-
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
var warn = function warn(message) {
|
|
266
|
-
return message.split('\n').forEach(function (msg) {
|
|
267
|
-
return console.warn('\x1b[33m%s\x1b[0m', msg);
|
|
268
|
-
});
|
|
269
|
-
};
|
|
270
|
-
|
|
271
321
|
function normalizeExposesItem(key, item) {
|
|
272
322
|
var importPath = '';
|
|
273
323
|
if (typeof item === 'string') {
|
|
@@ -436,9 +486,6 @@ function getNormalizeShareItem(key) {
|
|
|
436
486
|
return shareItem;
|
|
437
487
|
}
|
|
438
488
|
function normalizeModuleFederationOptions(options) {
|
|
439
|
-
if (options.getPublicPath) {
|
|
440
|
-
warn("We are ignoring the getPublicPath options because they are natively supported by Vite\nwith the \"experimental.renderBuiltUrl\" configuration https://vitejs.dev/guide/build#advanced-base-options");
|
|
441
|
-
}
|
|
442
489
|
if (options.virtualModuleDir && options.virtualModuleDir.includes('/')) {
|
|
443
490
|
throw new Error("Invalid virtualModuleDir: \"" + options.virtualModuleDir + "\". " + "The virtualModuleDir option cannot contain slashes (/). " + "Please use a single directory name like '__mf__virtual__your_app_name'.");
|
|
444
491
|
}
|
|
@@ -647,7 +694,9 @@ function generateExposes() {
|
|
|
647
694
|
|
|
648
695
|
var virtualRuntimeInitStatus = new VirtualModule('runtimeInit');
|
|
649
696
|
function writeRuntimeInitStatus() {
|
|
650
|
-
|
|
697
|
+
// Use globalThis singleton to ensure only one initPromise exists
|
|
698
|
+
var globalKey = "__mf_init__" + virtualRuntimeInitStatus.getImportId() + "__";
|
|
699
|
+
virtualRuntimeInitStatus.writeSync("\n const globalKey = " + JSON.stringify(globalKey) + "\n if (!globalThis[globalKey]) {\n let initResolve, initReject\n const initPromise = new Promise((re, rj) => {\n initResolve = re\n initReject = rj\n })\n globalThis[globalKey] = {\n initPromise,\n initResolve,\n initReject\n }\n }\n module.exports = globalThis[globalKey]\n ");
|
|
651
700
|
}
|
|
652
701
|
|
|
653
702
|
var cacheRemoteMap = {};
|
|
@@ -671,7 +720,7 @@ function getUsedRemotesMap() {
|
|
|
671
720
|
return usedRemotesMap;
|
|
672
721
|
}
|
|
673
722
|
function generateRemotes(id, command) {
|
|
674
|
-
return "\n const {
|
|
723
|
+
return "\n const {initPromise} = require(\"" + virtualRuntimeInitStatus.getImportId() + "\")\n const res = initPromise.then(runtime => runtime.loadRemote(" + JSON.stringify(id) + "))\n const exportModule = " + (command !== 'build' ? '/*mf top-level-await placeholder replacement mf*/' : 'await ') + "initPromise.then(_ => res)\n module.exports = exportModule\n ";
|
|
675
724
|
}
|
|
676
725
|
|
|
677
726
|
/**
|
|
@@ -700,7 +749,7 @@ function getLoadShareModulePath(pkg) {
|
|
|
700
749
|
return filepath;
|
|
701
750
|
}
|
|
702
751
|
function writeLoadShareModule(pkg, shareItem, command) {
|
|
703
|
-
loadShareCacheMap[pkg].writeSync("\n
|
|
752
|
+
loadShareCacheMap[pkg].writeSync("\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 {initPromise} = require(\"" + virtualRuntimeInitStatus.getImportId() + "\")\n const res = initPromise.then(runtime => runtime.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 }))\n const exportModule = " + (command !== 'build' ? '/*mf top-level-await placeholder replacement mf*/' : 'await ') + "res.then(factory => factory())\n module.exports = exportModule\n ");
|
|
704
753
|
}
|
|
705
754
|
|
|
706
755
|
var usedShares = new Set();
|
|
@@ -1542,7 +1591,9 @@ function federation(mfUserOptions) {
|
|
|
1542
1591
|
VirtualModule.ensureVirtualPackageExists();
|
|
1543
1592
|
initVirtualModules();
|
|
1544
1593
|
}
|
|
1545
|
-
}, aliasToArrayPlugin,
|
|
1594
|
+
}, aliasToArrayPlugin, checkAliasConflicts({
|
|
1595
|
+
shared: shared
|
|
1596
|
+
}), normalizeOptimizeDepsPlugin].concat(addEntry({
|
|
1546
1597
|
entryName: 'remoteEntry',
|
|
1547
1598
|
entryPath: REMOTE_ENTRY_ID,
|
|
1548
1599
|
fileName: filename
|
package/lib/index.modern.js
CHANGED
|
@@ -147,6 +147,62 @@ const addEntry = ({
|
|
|
147
147
|
}];
|
|
148
148
|
};
|
|
149
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Check if user-defined alias conflicts with shared modules
|
|
152
|
+
* This should run after aliasToArrayPlugin to ensure alias is an array
|
|
153
|
+
*/
|
|
154
|
+
function checkAliasConflicts(options) {
|
|
155
|
+
const {
|
|
156
|
+
shared = {}
|
|
157
|
+
} = options;
|
|
158
|
+
const sharedKeys = Object.keys(shared);
|
|
159
|
+
return {
|
|
160
|
+
name: 'check-alias-conflicts',
|
|
161
|
+
configResolved(config) {
|
|
162
|
+
var _config$resolve;
|
|
163
|
+
if (sharedKeys.length === 0) return;
|
|
164
|
+
const userAliases = ((_config$resolve = config.resolve) == null ? void 0 : _config$resolve.alias) || [];
|
|
165
|
+
const conflicts = [];
|
|
166
|
+
for (const sharedKey of sharedKeys) {
|
|
167
|
+
for (const aliasEntry of userAliases) {
|
|
168
|
+
const findPattern = aliasEntry.find;
|
|
169
|
+
const replacement = aliasEntry.replacement;
|
|
170
|
+
// Skip if replacement is not a string (e.g., customResolver)
|
|
171
|
+
if (typeof replacement !== 'string') continue;
|
|
172
|
+
// Skip Module Federation internal aliases (used for proxying shared modules)
|
|
173
|
+
// These are generated with replacement '$1' and should not trigger warnings
|
|
174
|
+
if (replacement === '$1') continue;
|
|
175
|
+
// Check if alias pattern matches the shared module
|
|
176
|
+
let isMatch = false;
|
|
177
|
+
if (typeof findPattern === 'string') {
|
|
178
|
+
isMatch = findPattern === sharedKey || sharedKey.startsWith(findPattern + '/');
|
|
179
|
+
} else if (findPattern instanceof RegExp) {
|
|
180
|
+
isMatch = findPattern.test(sharedKey);
|
|
181
|
+
}
|
|
182
|
+
if (isMatch) {
|
|
183
|
+
conflicts.push({
|
|
184
|
+
sharedModule: sharedKey,
|
|
185
|
+
alias: String(findPattern),
|
|
186
|
+
target: replacement
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (conflicts.length > 0) {
|
|
192
|
+
config.logger.warn('\n[Module Federation] Detected alias conflicts with shared modules:');
|
|
193
|
+
conflicts.forEach(({
|
|
194
|
+
sharedModule,
|
|
195
|
+
alias,
|
|
196
|
+
target
|
|
197
|
+
}) => {
|
|
198
|
+
config.logger.warn(` - Shared module "${sharedModule}" is aliased by "${alias}" to "${target}"`);
|
|
199
|
+
});
|
|
200
|
+
config.logger.warn(" This may cause runtime errors as the shared module will bypass Module Federation's sharing mechanism.");
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
150
206
|
/**
|
|
151
207
|
* Solve the problem that dev mode dependency prebunding does not support top-level await syntax
|
|
152
208
|
*/
|
|
@@ -239,8 +295,6 @@ function _extends() {
|
|
|
239
295
|
}, _extends.apply(null, arguments);
|
|
240
296
|
}
|
|
241
297
|
|
|
242
|
-
const warn = message => message.split('\n').forEach(msg => console.warn('\x1b[33m%s\x1b[0m', msg));
|
|
243
|
-
|
|
244
298
|
function normalizeExposesItem(key, item) {
|
|
245
299
|
let importPath = '';
|
|
246
300
|
if (typeof item === 'string') {
|
|
@@ -405,9 +459,6 @@ function getNormalizeShareItem(key) {
|
|
|
405
459
|
return shareItem;
|
|
406
460
|
}
|
|
407
461
|
function normalizeModuleFederationOptions(options) {
|
|
408
|
-
if (options.getPublicPath) {
|
|
409
|
-
warn(`We are ignoring the getPublicPath options because they are natively supported by Vite\nwith the "experimental.renderBuiltUrl" configuration https://vitejs.dev/guide/build#advanced-base-options`);
|
|
410
|
-
}
|
|
411
462
|
if (options.virtualModuleDir && options.virtualModuleDir.includes('/')) {
|
|
412
463
|
throw new Error(`Invalid virtualModuleDir: "${options.virtualModuleDir}". ` + `The virtualModuleDir option cannot contain slashes (/). ` + `Please use a single directory name like '__mf__virtual__your_app_name'.`);
|
|
413
464
|
}
|
|
@@ -617,17 +668,23 @@ function generateExposes() {
|
|
|
617
668
|
|
|
618
669
|
const virtualRuntimeInitStatus = new VirtualModule('runtimeInit');
|
|
619
670
|
function writeRuntimeInitStatus() {
|
|
671
|
+
// Use globalThis singleton to ensure only one initPromise exists
|
|
672
|
+
const globalKey = `__mf_init__${virtualRuntimeInitStatus.getImportId()}__`;
|
|
620
673
|
virtualRuntimeInitStatus.writeSync(`
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
initResolve
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
674
|
+
const globalKey = ${JSON.stringify(globalKey)}
|
|
675
|
+
if (!globalThis[globalKey]) {
|
|
676
|
+
let initResolve, initReject
|
|
677
|
+
const initPromise = new Promise((re, rj) => {
|
|
678
|
+
initResolve = re
|
|
679
|
+
initReject = rj
|
|
680
|
+
})
|
|
681
|
+
globalThis[globalKey] = {
|
|
682
|
+
initPromise,
|
|
683
|
+
initResolve,
|
|
684
|
+
initReject
|
|
685
|
+
}
|
|
630
686
|
}
|
|
687
|
+
module.exports = globalThis[globalKey]
|
|
631
688
|
`);
|
|
632
689
|
}
|
|
633
690
|
|
|
@@ -653,9 +710,8 @@ function getUsedRemotesMap() {
|
|
|
653
710
|
}
|
|
654
711
|
function generateRemotes(id, command) {
|
|
655
712
|
return `
|
|
656
|
-
const {loadRemote} = require("@module-federation/runtime")
|
|
657
713
|
const {initPromise} = require("${virtualRuntimeInitStatus.getImportId()}")
|
|
658
|
-
const res = initPromise.then(
|
|
714
|
+
const res = initPromise.then(runtime => runtime.loadRemote(${JSON.stringify(id)}))
|
|
659
715
|
const exportModule = ${command !== 'build' ? '/*mf top-level-await placeholder replacement mf*/' : 'await '}initPromise.then(_ => res)
|
|
660
716
|
module.exports = exportModule
|
|
661
717
|
`;
|
|
@@ -688,18 +744,17 @@ function getLoadShareModulePath(pkg) {
|
|
|
688
744
|
}
|
|
689
745
|
function writeLoadShareModule(pkg, shareItem, command) {
|
|
690
746
|
loadShareCacheMap[pkg].writeSync(`
|
|
691
|
-
|
|
692
747
|
;() => import(${JSON.stringify(getPreBuildLibImportId(pkg))}).catch(() => {});
|
|
693
748
|
// dev uses dynamic import to separate chunks
|
|
694
749
|
${command !== 'build' ? `;() => import(${JSON.stringify(pkg)}).catch(() => {});` : ''}
|
|
695
|
-
const {loadShare} = require("@module-federation/runtime")
|
|
696
750
|
const {initPromise} = require("${virtualRuntimeInitStatus.getImportId()}")
|
|
697
|
-
const res = initPromise.then(
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
751
|
+
const res = initPromise.then(runtime => runtime.loadShare(${JSON.stringify(pkg)}, {
|
|
752
|
+
customShareInfo: {shareConfig:{
|
|
753
|
+
singleton: ${shareItem.shareConfig.singleton},
|
|
754
|
+
strictVersion: ${shareItem.shareConfig.strictVersion},
|
|
755
|
+
requiredVersion: ${JSON.stringify(shareItem.shareConfig.requiredVersion)}
|
|
756
|
+
}}
|
|
757
|
+
}))
|
|
703
758
|
const exportModule = ${command !== 'build' ? '/*mf top-level-await placeholder replacement mf*/' : 'await '}res.then(factory => factory())
|
|
704
759
|
module.exports = exportModule
|
|
705
760
|
`);
|
|
@@ -1606,7 +1661,9 @@ function federation(mfUserOptions) {
|
|
|
1606
1661
|
VirtualModule.ensureVirtualPackageExists();
|
|
1607
1662
|
initVirtualModules();
|
|
1608
1663
|
}
|
|
1609
|
-
}, aliasToArrayPlugin,
|
|
1664
|
+
}, aliasToArrayPlugin, checkAliasConflicts({
|
|
1665
|
+
shared
|
|
1666
|
+
}), normalizeOptimizeDepsPlugin, ...addEntry({
|
|
1610
1667
|
entryName: 'remoteEntry',
|
|
1611
1668
|
entryPath: REMOTE_ENTRY_ID,
|
|
1612
1669
|
fileName: filename
|
package/lib/index.umd.js
CHANGED
|
@@ -169,6 +169,101 @@
|
|
|
169
169
|
}];
|
|
170
170
|
};
|
|
171
171
|
|
|
172
|
+
function _arrayLikeToArray(r, a) {
|
|
173
|
+
(null == a || a > r.length) && (a = r.length);
|
|
174
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
175
|
+
return n;
|
|
176
|
+
}
|
|
177
|
+
function _createForOfIteratorHelperLoose(r, e) {
|
|
178
|
+
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
179
|
+
if (t) return (t = t.call(r)).next.bind(t);
|
|
180
|
+
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
|
|
181
|
+
t && (r = t);
|
|
182
|
+
var o = 0;
|
|
183
|
+
return function () {
|
|
184
|
+
return o >= r.length ? {
|
|
185
|
+
done: !0
|
|
186
|
+
} : {
|
|
187
|
+
done: !1,
|
|
188
|
+
value: r[o++]
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
193
|
+
}
|
|
194
|
+
function _extends() {
|
|
195
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
196
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
197
|
+
var t = arguments[e];
|
|
198
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
199
|
+
}
|
|
200
|
+
return n;
|
|
201
|
+
}, _extends.apply(null, arguments);
|
|
202
|
+
}
|
|
203
|
+
function _unsupportedIterableToArray(r, a) {
|
|
204
|
+
if (r) {
|
|
205
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
206
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
207
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Check if user-defined alias conflicts with shared modules
|
|
213
|
+
* This should run after aliasToArrayPlugin to ensure alias is an array
|
|
214
|
+
*/
|
|
215
|
+
function checkAliasConflicts(options) {
|
|
216
|
+
var _options$shared = options.shared,
|
|
217
|
+
shared = _options$shared === void 0 ? {} : _options$shared;
|
|
218
|
+
var sharedKeys = Object.keys(shared);
|
|
219
|
+
return {
|
|
220
|
+
name: 'check-alias-conflicts',
|
|
221
|
+
configResolved: function configResolved(config) {
|
|
222
|
+
var _config$resolve;
|
|
223
|
+
if (sharedKeys.length === 0) return;
|
|
224
|
+
var userAliases = ((_config$resolve = config.resolve) == null ? void 0 : _config$resolve.alias) || [];
|
|
225
|
+
var conflicts = [];
|
|
226
|
+
for (var _i = 0, _sharedKeys = sharedKeys; _i < _sharedKeys.length; _i++) {
|
|
227
|
+
var sharedKey = _sharedKeys[_i];
|
|
228
|
+
for (var _iterator = _createForOfIteratorHelperLoose(userAliases), _step; !(_step = _iterator()).done;) {
|
|
229
|
+
var aliasEntry = _step.value;
|
|
230
|
+
var findPattern = aliasEntry.find;
|
|
231
|
+
var replacement = aliasEntry.replacement;
|
|
232
|
+
// Skip if replacement is not a string (e.g., customResolver)
|
|
233
|
+
if (typeof replacement !== 'string') continue;
|
|
234
|
+
// Skip Module Federation internal aliases (used for proxying shared modules)
|
|
235
|
+
// These are generated with replacement '$1' and should not trigger warnings
|
|
236
|
+
if (replacement === '$1') continue;
|
|
237
|
+
// Check if alias pattern matches the shared module
|
|
238
|
+
var isMatch = false;
|
|
239
|
+
if (typeof findPattern === 'string') {
|
|
240
|
+
isMatch = findPattern === sharedKey || sharedKey.startsWith(findPattern + '/');
|
|
241
|
+
} else if (findPattern instanceof RegExp) {
|
|
242
|
+
isMatch = findPattern.test(sharedKey);
|
|
243
|
+
}
|
|
244
|
+
if (isMatch) {
|
|
245
|
+
conflicts.push({
|
|
246
|
+
sharedModule: sharedKey,
|
|
247
|
+
alias: String(findPattern),
|
|
248
|
+
target: replacement
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (conflicts.length > 0) {
|
|
254
|
+
config.logger.warn('\n[Module Federation] Detected alias conflicts with shared modules:');
|
|
255
|
+
conflicts.forEach(function (_ref) {
|
|
256
|
+
var sharedModule = _ref.sharedModule,
|
|
257
|
+
alias = _ref.alias,
|
|
258
|
+
target = _ref.target;
|
|
259
|
+
config.logger.warn(" - Shared module \"" + sharedModule + "\" is aliased by \"" + alias + "\" to \"" + target + "\"");
|
|
260
|
+
});
|
|
261
|
+
config.logger.warn(" This may cause runtime errors as the shared module will bypass Module Federation's sharing mechanism.");
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
172
267
|
/**
|
|
173
268
|
* Solve the problem that dev mode dependency prebunding does not support top-level await syntax
|
|
174
269
|
*/
|
|
@@ -245,51 +340,6 @@
|
|
|
245
340
|
};
|
|
246
341
|
}
|
|
247
342
|
|
|
248
|
-
function _arrayLikeToArray(r, a) {
|
|
249
|
-
(null == a || a > r.length) && (a = r.length);
|
|
250
|
-
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
251
|
-
return n;
|
|
252
|
-
}
|
|
253
|
-
function _createForOfIteratorHelperLoose(r, e) {
|
|
254
|
-
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
255
|
-
if (t) return (t = t.call(r)).next.bind(t);
|
|
256
|
-
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
|
|
257
|
-
t && (r = t);
|
|
258
|
-
var o = 0;
|
|
259
|
-
return function () {
|
|
260
|
-
return o >= r.length ? {
|
|
261
|
-
done: !0
|
|
262
|
-
} : {
|
|
263
|
-
done: !1,
|
|
264
|
-
value: r[o++]
|
|
265
|
-
};
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
269
|
-
}
|
|
270
|
-
function _extends() {
|
|
271
|
-
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
272
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
273
|
-
var t = arguments[e];
|
|
274
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
275
|
-
}
|
|
276
|
-
return n;
|
|
277
|
-
}, _extends.apply(null, arguments);
|
|
278
|
-
}
|
|
279
|
-
function _unsupportedIterableToArray(r, a) {
|
|
280
|
-
if (r) {
|
|
281
|
-
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
282
|
-
var t = {}.toString.call(r).slice(8, -1);
|
|
283
|
-
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
var warn = function warn(message) {
|
|
288
|
-
return message.split('\n').forEach(function (msg) {
|
|
289
|
-
return console.warn('\x1b[33m%s\x1b[0m', msg);
|
|
290
|
-
});
|
|
291
|
-
};
|
|
292
|
-
|
|
293
343
|
function normalizeExposesItem(key, item) {
|
|
294
344
|
var importPath = '';
|
|
295
345
|
if (typeof item === 'string') {
|
|
@@ -458,9 +508,6 @@
|
|
|
458
508
|
return shareItem;
|
|
459
509
|
}
|
|
460
510
|
function normalizeModuleFederationOptions(options) {
|
|
461
|
-
if (options.getPublicPath) {
|
|
462
|
-
warn("We are ignoring the getPublicPath options because they are natively supported by Vite\nwith the \"experimental.renderBuiltUrl\" configuration https://vitejs.dev/guide/build#advanced-base-options");
|
|
463
|
-
}
|
|
464
511
|
if (options.virtualModuleDir && options.virtualModuleDir.includes('/')) {
|
|
465
512
|
throw new Error("Invalid virtualModuleDir: \"" + options.virtualModuleDir + "\". " + "The virtualModuleDir option cannot contain slashes (/). " + "Please use a single directory name like '__mf__virtual__your_app_name'.");
|
|
466
513
|
}
|
|
@@ -669,7 +716,9 @@
|
|
|
669
716
|
|
|
670
717
|
var virtualRuntimeInitStatus = new VirtualModule('runtimeInit');
|
|
671
718
|
function writeRuntimeInitStatus() {
|
|
672
|
-
|
|
719
|
+
// Use globalThis singleton to ensure only one initPromise exists
|
|
720
|
+
var globalKey = "__mf_init__" + virtualRuntimeInitStatus.getImportId() + "__";
|
|
721
|
+
virtualRuntimeInitStatus.writeSync("\n const globalKey = " + JSON.stringify(globalKey) + "\n if (!globalThis[globalKey]) {\n let initResolve, initReject\n const initPromise = new Promise((re, rj) => {\n initResolve = re\n initReject = rj\n })\n globalThis[globalKey] = {\n initPromise,\n initResolve,\n initReject\n }\n }\n module.exports = globalThis[globalKey]\n ");
|
|
673
722
|
}
|
|
674
723
|
|
|
675
724
|
var cacheRemoteMap = {};
|
|
@@ -693,7 +742,7 @@
|
|
|
693
742
|
return usedRemotesMap;
|
|
694
743
|
}
|
|
695
744
|
function generateRemotes(id, command) {
|
|
696
|
-
return "\n const {
|
|
745
|
+
return "\n const {initPromise} = require(\"" + virtualRuntimeInitStatus.getImportId() + "\")\n const res = initPromise.then(runtime => runtime.loadRemote(" + JSON.stringify(id) + "))\n const exportModule = " + (command !== 'build' ? '/*mf top-level-await placeholder replacement mf*/' : 'await ') + "initPromise.then(_ => res)\n module.exports = exportModule\n ";
|
|
697
746
|
}
|
|
698
747
|
|
|
699
748
|
/**
|
|
@@ -722,7 +771,7 @@
|
|
|
722
771
|
return filepath;
|
|
723
772
|
}
|
|
724
773
|
function writeLoadShareModule(pkg, shareItem, command) {
|
|
725
|
-
loadShareCacheMap[pkg].writeSync("\n
|
|
774
|
+
loadShareCacheMap[pkg].writeSync("\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 {initPromise} = require(\"" + virtualRuntimeInitStatus.getImportId() + "\")\n const res = initPromise.then(runtime => runtime.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 }))\n const exportModule = " + (command !== 'build' ? '/*mf top-level-await placeholder replacement mf*/' : 'await ') + "res.then(factory => factory())\n module.exports = exportModule\n ");
|
|
726
775
|
}
|
|
727
776
|
|
|
728
777
|
var usedShares = new Set();
|
|
@@ -1564,7 +1613,9 @@
|
|
|
1564
1613
|
VirtualModule.ensureVirtualPackageExists();
|
|
1565
1614
|
initVirtualModules();
|
|
1566
1615
|
}
|
|
1567
|
-
}, aliasToArrayPlugin,
|
|
1616
|
+
}, aliasToArrayPlugin, checkAliasConflicts({
|
|
1617
|
+
shared: shared
|
|
1618
|
+
}), normalizeOptimizeDepsPlugin].concat(addEntry({
|
|
1568
1619
|
entryName: 'remoteEntry',
|
|
1569
1620
|
entryPath: REMOTE_ENTRY_ID,
|
|
1570
1621
|
fileName: filename
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
import { NormalizedShared } from '../utils/normalizeModuleFederationOptions';
|
|
3
|
+
/**
|
|
4
|
+
* Check if user-defined alias conflicts with shared modules
|
|
5
|
+
* This should run after aliasToArrayPlugin to ensure alias is an array
|
|
6
|
+
*/
|
|
7
|
+
export declare function checkAliasConflicts(options: {
|
|
8
|
+
shared?: NormalizedShared;
|
|
9
|
+
}): Plugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/vite",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.2",
|
|
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,7 +28,6 @@
|
|
|
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",
|
|
48
31
|
"dependencies": {
|
|
49
32
|
"@module-federation/runtime": "^0.18.3",
|
|
50
33
|
"@module-federation/sdk": "^0.18.3",
|
|
@@ -67,5 +50,20 @@
|
|
|
67
50
|
"vite": "^5.4.3",
|
|
68
51
|
"vitest": "^2.1.1",
|
|
69
52
|
"wait-on": "^8.0.1"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"fmt": "prettier --write src",
|
|
56
|
+
"fmt.check": "prettier --check src",
|
|
57
|
+
"format": "pretty-quick",
|
|
58
|
+
"dev": "microbundle watch --no-sourcemap --compress=false",
|
|
59
|
+
"build": "rimraf lib && microbundle --no-sourcemap --compress=false",
|
|
60
|
+
"dev-rv": "pnpm -filter 'examples-rust-vite*' run dev",
|
|
61
|
+
"preview-rv": "pnpm -filter 'examples-rust-vite*' run preview",
|
|
62
|
+
"dev-vv": "pnpm -filter 'examples-vite-vite*' run dev",
|
|
63
|
+
"dev-nv": "pnpm -filter 'examples-nuxt-vite-host' -filter 'examples-vite-vite-remote' run dev",
|
|
64
|
+
"preview-vv": "pnpm -filter 'examples-vite-vite*' run preview",
|
|
65
|
+
"multi-example": "pnpm --filter \"multi-example-*\" --parallel run start",
|
|
66
|
+
"test": "vitest",
|
|
67
|
+
"e2e": "playwright test"
|
|
70
68
|
}
|
|
71
|
-
}
|
|
69
|
+
}
|
package/lib/utils/logUtils.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const warn: (message: string) => void;
|