@module-federation/vite 1.20.1 → 1.20.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.js
CHANGED
|
@@ -933,7 +933,8 @@ function isNuxtClientBase(base) {
|
|
|
933
933
|
return getBasePath$2(base).endsWith("/_nuxt");
|
|
934
934
|
}
|
|
935
935
|
function normalizeNodeModulePath(source) {
|
|
936
|
-
|
|
936
|
+
const queryIndex = source.indexOf("?");
|
|
937
|
+
return (queryIndex === -1 ? source : source.slice(0, queryIndex)).replace(/\\/g, "/");
|
|
937
938
|
}
|
|
938
939
|
function isNodeModulePath(source) {
|
|
939
940
|
return source.includes("/node_modules/") || source.includes("\\node_modules\\");
|
|
@@ -1914,6 +1915,9 @@ ${exportStatement}
|
|
|
1914
1915
|
}
|
|
1915
1916
|
//#endregion
|
|
1916
1917
|
//#region src/utils/treeShaking.ts
|
|
1918
|
+
function shouldAnalyzeSharedExports(shareItem) {
|
|
1919
|
+
return !!(shareItem && (shareItem.shareConfig.treeShaking || shareItem.shareConfig.import === false));
|
|
1920
|
+
}
|
|
1917
1921
|
const legacyTreeShakingState = {
|
|
1918
1922
|
inferredUsage: /* @__PURE__ */ new Map(),
|
|
1919
1923
|
buildMode: false
|
|
@@ -1987,12 +1991,12 @@ function getExportRecords(sharedKey, request, options) {
|
|
|
1987
1991
|
* fallback lookup across keys keeps aliases/backwards-compatible callers
|
|
1988
1992
|
* working, while still keeping each concrete request's exports isolated.
|
|
1989
1993
|
*/
|
|
1990
|
-
function
|
|
1994
|
+
function getSharedExportUsage(request, shareItem, sharedKey, options) {
|
|
1991
1995
|
const treeShaking = shareItem?.shareConfig.treeShaking;
|
|
1992
|
-
if (!
|
|
1996
|
+
if (!shouldAnalyzeSharedExports(shareItem) || !getTreeShakingState(options).buildMode) return;
|
|
1993
1997
|
const records = getExportRecords(sharedKey, request, options);
|
|
1994
1998
|
if (records.some((record) => record.requiresFullBundle)) return { kind: "full" };
|
|
1995
|
-
const configured = treeShaking
|
|
1999
|
+
const configured = treeShaking?.usedExports ?? [];
|
|
1996
2000
|
const result = new Set(configured);
|
|
1997
2001
|
records.forEach((record) => record.usedExports.forEach((name) => result.add(name)));
|
|
1998
2002
|
if (result.size > 0) return {
|
|
@@ -2004,6 +2008,10 @@ function getTreeShakingExportUsage(request, shareItem, sharedKey, options) {
|
|
|
2004
2008
|
usedExports: []
|
|
2005
2009
|
} : { kind: "unknown" };
|
|
2006
2010
|
}
|
|
2011
|
+
function getTreeShakingExportUsage(request, shareItem, sharedKey, options) {
|
|
2012
|
+
if (!shareItem?.shareConfig.treeShaking) return void 0;
|
|
2013
|
+
return getSharedExportUsage(request, shareItem, sharedKey, options);
|
|
2014
|
+
}
|
|
2007
2015
|
function getModuleSource(node) {
|
|
2008
2016
|
if (!node || typeof node !== "object") return void 0;
|
|
2009
2017
|
const source = node;
|
|
@@ -2118,8 +2126,8 @@ function collectReExport(node, source, record, markUnsafe) {
|
|
|
2118
2126
|
*
|
|
2119
2127
|
* Parsing the module avoids treating import-looking text in comments, strings,
|
|
2120
2128
|
* templates, or regular expressions as real dependencies. If parsing fails,
|
|
2121
|
-
* every configured
|
|
2122
|
-
* full
|
|
2129
|
+
* every configured share whose exports are analyzed is conservatively marked
|
|
2130
|
+
* as requiring its full export surface instead of guessing from source text.
|
|
2123
2131
|
*
|
|
2124
2132
|
* Generated federation wrappers are excluded because their imports describe
|
|
2125
2133
|
* the wrapper implementation, not the consumer's requirements.
|
|
@@ -2132,13 +2140,13 @@ function collectTreeShakingImports(code, id, shared, findSharedKey, record, mark
|
|
|
2132
2140
|
ast = parseAst(code);
|
|
2133
2141
|
} catch {
|
|
2134
2142
|
Object.entries(shared).forEach(([sharedKey, shareItem]) => {
|
|
2135
|
-
if (shareItem
|
|
2143
|
+
if (shouldAnalyzeSharedExports(shareItem)) markUnsafe(sharedKey, "*");
|
|
2136
2144
|
});
|
|
2137
2145
|
return;
|
|
2138
2146
|
}
|
|
2139
2147
|
const matchShared = (source) => {
|
|
2140
2148
|
const sharedKey = findSharedKey(source, shared);
|
|
2141
|
-
return sharedKey && shared[sharedKey]
|
|
2149
|
+
return sharedKey && shouldAnalyzeSharedExports(shared[sharedKey]) ? sharedKey : void 0;
|
|
2142
2150
|
};
|
|
2143
2151
|
const recordSource = (names, source) => {
|
|
2144
2152
|
const sharedKey = matchShared(source);
|
|
@@ -2709,7 +2717,22 @@ function getNamedExportsViaRegex(source, filePath, visited, scanState = { comple
|
|
|
2709
2717
|
}
|
|
2710
2718
|
return Array.from(names);
|
|
2711
2719
|
}
|
|
2720
|
+
/**
|
|
2721
|
+
* Reading a module's export names runs its top-level code inside the build
|
|
2722
|
+
* process, and getPackageNamedExports deliberately resolves the browser entry.
|
|
2723
|
+
* A browser entry may open a handle Node never closes — react-dom/server.browser
|
|
2724
|
+
* holds a module-scope MessageChannel — and one ref'd handle keeps the event loop
|
|
2725
|
+
* alive forever, so `vite build` writes a correct bundle and then never exits.
|
|
2726
|
+
*
|
|
2727
|
+
* Unref'ing whatever the require created is safe here because the module is
|
|
2728
|
+
* loaded purely to read Object.keys off it and is never used afterwards. The
|
|
2729
|
+
* handle list is undocumented, so its absence degrades to the previous behaviour
|
|
2730
|
+
* rather than failing the build. Side effects that are not handles (an exit
|
|
2731
|
+
* listener, a global mutation) are still not contained.
|
|
2732
|
+
*/
|
|
2712
2733
|
function getRequiredNamedExports(specifier) {
|
|
2734
|
+
const getActiveHandles = process._getActiveHandles;
|
|
2735
|
+
const handlesBeforeRequire = typeof getActiveHandles === "function" ? new Set(getActiveHandles.call(process)) : void 0;
|
|
2713
2736
|
try {
|
|
2714
2737
|
const mod = createRequire$1(pathToFileURL(path$1.join(getPackageDetectionCwd(), "package.json")))(specifier);
|
|
2715
2738
|
const runtimeNamedKeys = Object.keys(mod).filter((key) => key !== "default" && key !== "__esModule");
|
|
@@ -2717,6 +2740,12 @@ function getRequiredNamedExports(specifier) {
|
|
|
2717
2740
|
return runtimeNamedKeys;
|
|
2718
2741
|
} catch {
|
|
2719
2742
|
return;
|
|
2743
|
+
} finally {
|
|
2744
|
+
if (handlesBeforeRequire && typeof getActiveHandles === "function") for (const handle of getActiveHandles.call(process)) {
|
|
2745
|
+
if (handlesBeforeRequire.has(handle)) continue;
|
|
2746
|
+
const unref = handle?.unref;
|
|
2747
|
+
if (typeof unref === "function") unref.call(handle);
|
|
2748
|
+
}
|
|
2720
2749
|
}
|
|
2721
2750
|
}
|
|
2722
2751
|
function getPackageNamedExports(pkg, exportConditions = DEFAULT_SHARED_EXPORT_CONDITIONS) {
|
|
@@ -3272,6 +3301,12 @@ function generateDeferredHostProvidedExports(namedExports, pkg, cacheDescriptor,
|
|
|
3272
3301
|
}
|
|
3273
3302
|
export { __mf_default as default };${namedExportLine}`;
|
|
3274
3303
|
}
|
|
3304
|
+
function selectImportFalseNamedExports(detectedNamedExports, usage) {
|
|
3305
|
+
if (!detectedNamedExports || usage?.kind !== "exports") return detectedNamedExports ?? [];
|
|
3306
|
+
const usedNamedExports = new Set(usage.usedExports.filter((name) => name !== "default"));
|
|
3307
|
+
if ([...usedNamedExports].some((name) => !detectedNamedExports.includes(name))) return detectedNamedExports;
|
|
3308
|
+
return detectedNamedExports.filter((name) => usedNamedExports.has(name));
|
|
3309
|
+
}
|
|
3275
3310
|
function generateShareModuleUnwrapCode({ source, preserveNamedExports, stopWithReturn }) {
|
|
3276
3311
|
return `let current = ${source};
|
|
3277
3312
|
for (let i = 0; i < 5; i++) {
|
|
@@ -3294,7 +3329,7 @@ const normalizeLocalShareModuleCode = `const __mfNormalizeShareModule = (mod) =>
|
|
|
3294
3329
|
? Object.assign({}, normalized)
|
|
3295
3330
|
: normalized;
|
|
3296
3331
|
};`;
|
|
3297
|
-
function writeLoadShareModule(pkg, shareItem, command, _isRolldown, options, exportConditions) {
|
|
3332
|
+
function writeLoadShareModule(pkg, shareItem, command, _isRolldown, options, exportConditions, importFalseExportUsage) {
|
|
3298
3333
|
const resolvedOptions = options ?? getNormalizeModuleFederationOptions();
|
|
3299
3334
|
const { loadShareCacheMap } = getSharedVirtualModuleState(options);
|
|
3300
3335
|
if (!loadShareCacheMap[pkg]) loadShareCacheMap[pkg] = createScopedSharedVirtualModule(pkg, LOAD_SHARE_TAG, options);
|
|
@@ -3305,7 +3340,7 @@ function writeLoadShareModule(pkg, shareItem, command, _isRolldown, options, exp
|
|
|
3305
3340
|
const treeShakingConsumer = command === "build" && shareItem.shareConfig.treeShaking ? resolvedOptions.name : void 0;
|
|
3306
3341
|
if (shareItem.shareConfig.import === false) {
|
|
3307
3342
|
const detectedNamedExports = getPackageNamedExports(pkg, exportConditions);
|
|
3308
|
-
const namedExports = detectedNamedExports
|
|
3343
|
+
const namedExports = selectImportFalseNamedExports(detectedNamedExports, importFalseExportUsage);
|
|
3309
3344
|
let exportLine;
|
|
3310
3345
|
if (namedExports.length > 0) exportLine = generateDeferredHostProvidedExports(namedExports, pkg, cacheDescriptor, treeShakingConsumer);
|
|
3311
3346
|
else {
|
|
@@ -3592,7 +3627,7 @@ function generateLocalSharedImportMap(options) {
|
|
|
3592
3627
|
if (!remote) return null;
|
|
3593
3628
|
return `
|
|
3594
3629
|
{
|
|
3595
|
-
alias: ${JSON.stringify(
|
|
3630
|
+
alias: ${JSON.stringify(key)},
|
|
3596
3631
|
entryGlobalName: ${JSON.stringify(remote.entryGlobalName)},
|
|
3597
3632
|
name: ${JSON.stringify(options ? getRuntimeRemoteAlias(key, options) : remote.name)},
|
|
3598
3633
|
type: ${JSON.stringify(remote.type)},
|
|
@@ -5074,6 +5109,8 @@ function getRemoteVirtualModule(remote, command, enableSsrInit = false, consumer
|
|
|
5074
5109
|
}
|
|
5075
5110
|
const usedRemotesMap = {};
|
|
5076
5111
|
const usedRemotesByOptions = /* @__PURE__ */ new WeakMap();
|
|
5112
|
+
const dynamicRemotesByOptions = /* @__PURE__ */ new WeakMap();
|
|
5113
|
+
const staticRemotesByOptions = /* @__PURE__ */ new WeakMap();
|
|
5077
5114
|
function getScopedUsedRemotesMap(options) {
|
|
5078
5115
|
let scoped = usedRemotesByOptions.get(options);
|
|
5079
5116
|
if (!scoped) {
|
|
@@ -5094,6 +5131,25 @@ function getUsedRemotesMap(options) {
|
|
|
5094
5131
|
if (options) return getScopedUsedRemotesMap(options);
|
|
5095
5132
|
return usedRemotesMap;
|
|
5096
5133
|
}
|
|
5134
|
+
function markDynamicRemote(remote, options) {
|
|
5135
|
+
let remotes = dynamicRemotesByOptions.get(options);
|
|
5136
|
+
if (!remotes) {
|
|
5137
|
+
remotes = /* @__PURE__ */ new Set();
|
|
5138
|
+
dynamicRemotesByOptions.set(options, remotes);
|
|
5139
|
+
}
|
|
5140
|
+
remotes.add(remote);
|
|
5141
|
+
}
|
|
5142
|
+
function markStaticRemote(remote, options) {
|
|
5143
|
+
let remotes = staticRemotesByOptions.get(options);
|
|
5144
|
+
if (!remotes) {
|
|
5145
|
+
remotes = /* @__PURE__ */ new Set();
|
|
5146
|
+
staticRemotesByOptions.set(options, remotes);
|
|
5147
|
+
}
|
|
5148
|
+
remotes.add(remote);
|
|
5149
|
+
}
|
|
5150
|
+
function isDynamicOnlyRemote(remote, options) {
|
|
5151
|
+
return (dynamicRemotesByOptions.get(options)?.has(remote) ?? false) && !(staticRemotesByOptions.get(options)?.has(remote) ?? false);
|
|
5152
|
+
}
|
|
5097
5153
|
function getRemoteAliasFromId(id, remotes) {
|
|
5098
5154
|
return Object.keys(remotes).filter((name) => id === name || id.startsWith(name + "/")).sort((a, b) => b.length - a.length)[0];
|
|
5099
5155
|
}
|
|
@@ -5278,7 +5334,7 @@ function generateRemotes(id, command, enableSsrInit = false, consumer = "unified
|
|
|
5278
5334
|
const registerRemoteCode = isLoadedFirst && remote ? `runtime.registerRemotes([${JSON.stringify({
|
|
5279
5335
|
entryGlobalName: remote.entryGlobalName,
|
|
5280
5336
|
name: options ? runtimeRemoteAlias : remote.name,
|
|
5281
|
-
alias:
|
|
5337
|
+
alias: remoteAlias,
|
|
5282
5338
|
type: remote.type,
|
|
5283
5339
|
entry: remote.entry,
|
|
5284
5340
|
shareScope: remote.shareScope ?? "default"
|
|
@@ -5516,7 +5572,7 @@ const __mfCurrentScript = document.currentScript;
|
|
|
5516
5572
|
const entryImportDeclaration = isEncodedVirtualEntry ? `const __mfEntryUrl = ${JSON.stringify(entrySrc)};
|
|
5517
5573
|
` : "";
|
|
5518
5574
|
const entryImportExpression = isEncodedVirtualEntry ? "import(/* @vite-ignore */ __mfEntryUrl)" : importExpression(entrySrc);
|
|
5519
|
-
const remotePreloads = !options?.skipRemotePreload && (federationOptions ?? getNormalizeModuleFederationOptions())?.shareStrategy !== "loaded-first" ? Object.entries(getUsedRemotesMap(federationOptions)).flatMap(([, remotes]) => Array.from(remotes)).sort().map((remote) => `__mfPreloadRemote(${JSON.stringify(getRuntimeRemoteId(remote, (federationOptions ?? getNormalizeModuleFederationOptions()).remotes, federationOptions))}, ${JSON.stringify(remote)})`).join(",") : "";
|
|
5575
|
+
const remotePreloads = !options?.skipRemotePreload && (federationOptions ?? getNormalizeModuleFederationOptions())?.shareStrategy !== "loaded-first" ? Object.entries(getUsedRemotesMap(federationOptions)).flatMap(([, remotes]) => Array.from(remotes)).filter((remote) => !federationOptions || !isDynamicOnlyRemote(remote, federationOptions)).sort().map((remote) => `__mfPreloadRemote(${JSON.stringify(getRuntimeRemoteId(remote, (federationOptions ?? getNormalizeModuleFederationOptions()).remotes, federationOptions))}, ${JSON.stringify(remote)})`).join(",") : "";
|
|
5520
5576
|
const remoteCachePrefix = getRuntimeRemoteCachePrefix(federationOptions);
|
|
5521
5577
|
const preloadBlock = remotePreloads ? `
|
|
5522
5578
|
const runtime = await initHost();
|
|
@@ -7771,116 +7827,174 @@ function getStatsFileName(manifestFileName) {
|
|
|
7771
7827
|
}
|
|
7772
7828
|
//#endregion
|
|
7773
7829
|
//#region src/plugins/pluginModuleParseEnd.ts
|
|
7774
|
-
|
|
7775
|
-
|
|
7776
|
-
|
|
7777
|
-
|
|
7778
|
-
|
|
7779
|
-
|
|
7780
|
-
|
|
7781
|
-
|
|
7782
|
-
|
|
7783
|
-
|
|
7784
|
-
|
|
7785
|
-
|
|
7786
|
-
|
|
7787
|
-
|
|
7788
|
-
|
|
7789
|
-
|
|
7790
|
-
|
|
7791
|
-
|
|
7792
|
-
|
|
7793
|
-
|
|
7794
|
-
|
|
7795
|
-
|
|
7796
|
-
|
|
7797
|
-
|
|
7798
|
-
|
|
7799
|
-
|
|
7800
|
-
|
|
7801
|
-
|
|
7802
|
-
|
|
7803
|
-
|
|
7804
|
-
|
|
7805
|
-
|
|
7830
|
+
function createModuleParseController() {
|
|
7831
|
+
return {
|
|
7832
|
+
resolve: null,
|
|
7833
|
+
parseTimeout: null,
|
|
7834
|
+
settleTimeout: null,
|
|
7835
|
+
parsePromise: Promise.resolve({
|
|
7836
|
+
complete: false,
|
|
7837
|
+
reason: "initial"
|
|
7838
|
+
}),
|
|
7839
|
+
parseStartSet: /* @__PURE__ */ new Set(),
|
|
7840
|
+
parseEndSet: /* @__PURE__ */ new Set(),
|
|
7841
|
+
discardWarned: false,
|
|
7842
|
+
externalSet: /* @__PURE__ */ new Set(),
|
|
7843
|
+
resolutionProbed: /* @__PURE__ */ new Set(),
|
|
7844
|
+
lastLoadedModule: "",
|
|
7845
|
+
lastParsedModule: ""
|
|
7846
|
+
};
|
|
7847
|
+
}
|
|
7848
|
+
function clearParseTimeout(controller) {
|
|
7849
|
+
if (controller.parseTimeout) {
|
|
7850
|
+
clearTimeout(controller.parseTimeout);
|
|
7851
|
+
controller.parseTimeout = null;
|
|
7852
|
+
}
|
|
7853
|
+
}
|
|
7854
|
+
function clearSettleTimeout(controller) {
|
|
7855
|
+
if (controller.settleTimeout) {
|
|
7856
|
+
clearTimeout(controller.settleTimeout);
|
|
7857
|
+
controller.settleTimeout = null;
|
|
7858
|
+
}
|
|
7859
|
+
}
|
|
7860
|
+
function resetParseState(controller) {
|
|
7861
|
+
clearParseTimeout(controller);
|
|
7862
|
+
clearSettleTimeout(controller);
|
|
7863
|
+
controller.parseStartSet = /* @__PURE__ */ new Set();
|
|
7864
|
+
controller.parseEndSet = /* @__PURE__ */ new Set();
|
|
7865
|
+
controller.externalSet = /* @__PURE__ */ new Set();
|
|
7866
|
+
controller.resolutionProbed = /* @__PURE__ */ new Set();
|
|
7867
|
+
controller.discardWarned = false;
|
|
7868
|
+
controller.lastLoadedModule = "";
|
|
7869
|
+
controller.lastParsedModule = "";
|
|
7870
|
+
controller.parsePromise = new Promise((resolve) => {
|
|
7871
|
+
controller.resolve = (result) => {
|
|
7872
|
+
clearParseTimeout(controller);
|
|
7873
|
+
clearSettleTimeout(controller);
|
|
7874
|
+
resolve(result);
|
|
7806
7875
|
};
|
|
7807
7876
|
});
|
|
7808
7877
|
}
|
|
7809
|
-
function setParseTimeout(timeout) {
|
|
7810
|
-
if (!
|
|
7878
|
+
function setParseTimeout(controller, timeout) {
|
|
7879
|
+
if (!controller.parseTimeout) controller.parseTimeout = setTimeout(() => {
|
|
7811
7880
|
mfWarn(`Parse timeout (${timeout}s) - forcing resolve`);
|
|
7812
|
-
|
|
7881
|
+
controller.resolve?.({
|
|
7882
|
+
complete: false,
|
|
7883
|
+
reason: "timeout"
|
|
7884
|
+
});
|
|
7813
7885
|
}, timeout * 1e3);
|
|
7814
7886
|
}
|
|
7815
|
-
function resetIdleTimeout(timeout) {
|
|
7816
|
-
clearParseTimeout();
|
|
7817
|
-
|
|
7818
|
-
const pendingModules = Array.from(parseStartSet).filter((moduleId) => !parseEndSet.has(moduleId));
|
|
7819
|
-
mfWarn(`moduleParseIdleTimeout: no module activity for ${timeout}s, forcing resolve. Some shared/remote dependencies may be missing. Consider increasing moduleParseIdleTimeout. Tracked modules: ${parseEndSet.size}/${parseStartSet.size}.` + (lastLoadedModule ? ` Last loaded: ${lastLoadedModule}.` : "") + (lastParsedModule ? ` Last parsed: ${lastParsedModule}.` : "") + (pendingModules.length ? ` Pending modules: ${pendingModules.slice(0, 10).join(", ")}` : ""));
|
|
7820
|
-
|
|
7887
|
+
function resetIdleTimeout(controller, timeout) {
|
|
7888
|
+
clearParseTimeout(controller);
|
|
7889
|
+
controller.parseTimeout = setTimeout(() => {
|
|
7890
|
+
const pendingModules = Array.from(controller.parseStartSet).filter((moduleId) => !controller.parseEndSet.has(moduleId));
|
|
7891
|
+
mfWarn(`moduleParseIdleTimeout: no module activity for ${timeout}s, forcing resolve. Some shared/remote dependencies may be missing. Consider increasing moduleParseIdleTimeout. Tracked modules: ${controller.parseEndSet.size}/${controller.parseStartSet.size}.` + (controller.lastLoadedModule ? ` Last loaded: ${controller.lastLoadedModule}.` : "") + (controller.lastParsedModule ? ` Last parsed: ${controller.lastParsedModule}.` : "") + (pendingModules.length ? ` Pending modules: ${pendingModules.slice(0, 10).join(", ")}` : ""));
|
|
7892
|
+
controller.resolve?.({
|
|
7893
|
+
complete: false,
|
|
7894
|
+
reason: "idle-timeout"
|
|
7895
|
+
});
|
|
7821
7896
|
}, timeout * 1e3);
|
|
7822
7897
|
}
|
|
7823
|
-
function scheduleParseCompletionCheck() {
|
|
7824
|
-
clearSettleTimeout();
|
|
7825
|
-
|
|
7826
|
-
|
|
7827
|
-
if (parseStartSet.size > 0 && Array.from(parseStartSet).every((moduleId) => parseEndSet.has(moduleId)))
|
|
7898
|
+
function scheduleParseCompletionCheck(controller) {
|
|
7899
|
+
clearSettleTimeout(controller);
|
|
7900
|
+
controller.settleTimeout = setTimeout(() => {
|
|
7901
|
+
controller.settleTimeout = null;
|
|
7902
|
+
if (controller.parseStartSet.size > 0 && Array.from(controller.parseStartSet).every((moduleId) => controller.parseEndSet.has(moduleId))) controller.resolve?.({
|
|
7903
|
+
complete: true,
|
|
7904
|
+
reason: "graph-complete"
|
|
7905
|
+
});
|
|
7828
7906
|
}, 10);
|
|
7829
7907
|
}
|
|
7830
|
-
function
|
|
7908
|
+
function matchesExternal(external, id, importer) {
|
|
7909
|
+
if (!external) return false;
|
|
7910
|
+
if (typeof external === "function") return external(id, importer, true) === true;
|
|
7911
|
+
return (Array.isArray(external) ? external : [external]).some((entry) => {
|
|
7912
|
+
if (typeof entry === "string") return entry === id;
|
|
7913
|
+
entry.lastIndex = 0;
|
|
7914
|
+
return entry.test(id);
|
|
7915
|
+
});
|
|
7916
|
+
}
|
|
7917
|
+
function getConfiguredInputImports(input) {
|
|
7918
|
+
if (typeof input === "string") return [input];
|
|
7919
|
+
if (Array.isArray(input)) return input.filter((entry) => typeof entry === "string");
|
|
7920
|
+
if (!input || typeof input !== "object") return [];
|
|
7921
|
+
return Object.values(input).filter((entry) => typeof entry === "string");
|
|
7922
|
+
}
|
|
7923
|
+
function pluginModuleParseEnd_default(excludeFn, options, controller = createModuleParseController()) {
|
|
7831
7924
|
const idleTimeout = options.moduleParseIdleTimeout ?? options.moduleParseTimeout;
|
|
7832
|
-
|
|
7833
|
-
|
|
7834
|
-
|
|
7835
|
-
|
|
7836
|
-
|
|
7837
|
-
|
|
7925
|
+
let configuredInputImports = [];
|
|
7926
|
+
let configuredExternal;
|
|
7927
|
+
return [{
|
|
7928
|
+
enforce: "pre",
|
|
7929
|
+
name: "parseStart",
|
|
7930
|
+
apply: "build",
|
|
7931
|
+
configResolved(config) {
|
|
7932
|
+
const buildOptions = config.build;
|
|
7933
|
+
configuredInputImports = getConfiguredInputImports(buildOptions.rollupOptions.input ?? buildOptions.rolldownOptions?.input);
|
|
7934
|
+
configuredExternal = buildOptions.rollupOptions.external ?? buildOptions.rolldownOptions?.external;
|
|
7935
|
+
},
|
|
7936
|
+
async buildStart() {
|
|
7937
|
+
resetParseState(controller);
|
|
7938
|
+
if (idleTimeout) resetIdleTimeout(controller, idleTimeout);
|
|
7939
|
+
else if (options.moduleParseTimeout) setParseTimeout(controller, options.moduleParseTimeout);
|
|
7940
|
+
const entryImports = /* @__PURE__ */ new Set([...options.exposedModuleImports || [], ...configuredInputImports]);
|
|
7941
|
+
for (const importSource of entryImports) {
|
|
7942
|
+
const resolved = await this.resolve(importSource);
|
|
7943
|
+
if (resolved && !resolved.external && !excludeFn(resolved.id)) controller.parseStartSet.add(resolved.id);
|
|
7838
7944
|
}
|
|
7839
7945
|
},
|
|
7840
|
-
{
|
|
7841
|
-
|
|
7842
|
-
|
|
7843
|
-
|
|
7844
|
-
|
|
7845
|
-
|
|
7846
|
-
|
|
7847
|
-
|
|
7848
|
-
|
|
7849
|
-
|
|
7850
|
-
|
|
7946
|
+
load(id) {
|
|
7947
|
+
controller.lastLoadedModule = id;
|
|
7948
|
+
if (excludeFn(id)) return;
|
|
7949
|
+
clearSettleTimeout(controller);
|
|
7950
|
+
if (idleTimeout) resetIdleTimeout(controller, idleTimeout);
|
|
7951
|
+
controller.parseStartSet.add(id);
|
|
7952
|
+
}
|
|
7953
|
+
}, {
|
|
7954
|
+
enforce: "post",
|
|
7955
|
+
name: "parseEnd",
|
|
7956
|
+
apply: "build",
|
|
7957
|
+
moduleParsed(module) {
|
|
7958
|
+
clearSettleTimeout(controller);
|
|
7959
|
+
const id = module.id;
|
|
7960
|
+
controller.lastParsedModule = id;
|
|
7961
|
+
if (idleTimeout) resetIdleTimeout(controller, idleTimeout);
|
|
7962
|
+
const parsedModule = module;
|
|
7963
|
+
const addPendingResolutions = (resolutions) => {
|
|
7964
|
+
for (const resolution of resolutions || []) if (!resolution.external && !excludeFn(resolution.id)) controller.parseStartSet.add(resolution.id);
|
|
7965
|
+
};
|
|
7966
|
+
const probeExternal = (pendingId) => {
|
|
7967
|
+
if (typeof this.resolve !== "function") return;
|
|
7968
|
+
if (controller.resolutionProbed.has(pendingId)) return;
|
|
7969
|
+
controller.resolutionProbed.add(pendingId);
|
|
7970
|
+
this.resolve(pendingId, id, { skipSelf: true }).then((resolved) => {
|
|
7971
|
+
if (!resolved?.external) return;
|
|
7972
|
+
controller.externalSet.add(pendingId);
|
|
7973
|
+
controller.parseStartSet.delete(pendingId);
|
|
7974
|
+
scheduleParseCompletionCheck(controller);
|
|
7975
|
+
}).catch(() => {});
|
|
7976
|
+
};
|
|
7977
|
+
const addPendingIds = (ids) => {
|
|
7978
|
+
for (const pendingId of ids || []) {
|
|
7979
|
+
if (!this.getModuleInfo(pendingId) || controller.externalSet.has(pendingId) || matchesExternal(configuredExternal, pendingId, id) || excludeFn(pendingId)) continue;
|
|
7980
|
+
controller.parseStartSet.add(pendingId);
|
|
7981
|
+
if (!controller.parseEndSet.has(pendingId)) probeExternal(pendingId);
|
|
7851
7982
|
}
|
|
7852
|
-
}
|
|
7853
|
-
|
|
7854
|
-
|
|
7855
|
-
|
|
7856
|
-
|
|
7857
|
-
|
|
7858
|
-
|
|
7859
|
-
}
|
|
7983
|
+
};
|
|
7984
|
+
addPendingResolutions(parsedModule.importedIdResolutions);
|
|
7985
|
+
addPendingResolutions(parsedModule.dynamicallyImportedIdResolutions);
|
|
7986
|
+
if (parsedModule.importedIdResolutions === void 0) addPendingIds(module.importedIds);
|
|
7987
|
+
if (parsedModule.dynamicallyImportedIdResolutions === void 0) addPendingIds(module.dynamicallyImportedIds);
|
|
7988
|
+
if (!excludeFn(id)) controller.parseEndSet.add(id);
|
|
7989
|
+
scheduleParseCompletionCheck(controller);
|
|
7860
7990
|
},
|
|
7861
|
-
{
|
|
7862
|
-
|
|
7863
|
-
|
|
7864
|
-
|
|
7865
|
-
|
|
7866
|
-
clearSettleTimeout();
|
|
7867
|
-
const id = module.id;
|
|
7868
|
-
lastParsedModule = id;
|
|
7869
|
-
if (idleTimeout) resetIdleTimeout(idleTimeout);
|
|
7870
|
-
const parsedModule = module;
|
|
7871
|
-
const addPendingResolutions = (resolutions) => {
|
|
7872
|
-
for (const resolution of resolutions || []) if (!resolution.external && !excludeFn(resolution.id)) parseStartSet.add(resolution.id);
|
|
7873
|
-
};
|
|
7874
|
-
addPendingResolutions(parsedModule.importedIdResolutions);
|
|
7875
|
-
addPendingResolutions(parsedModule.dynamicallyImportedIdResolutions);
|
|
7876
|
-
if (!excludeFn(id)) parseEndSet.add(id);
|
|
7877
|
-
scheduleParseCompletionCheck();
|
|
7878
|
-
},
|
|
7879
|
-
buildEnd() {
|
|
7880
|
-
_resolve?.(1);
|
|
7881
|
-
}
|
|
7991
|
+
buildEnd() {
|
|
7992
|
+
controller.resolve?.({
|
|
7993
|
+
complete: false,
|
|
7994
|
+
reason: "build-end"
|
|
7995
|
+
});
|
|
7882
7996
|
}
|
|
7883
|
-
];
|
|
7997
|
+
}];
|
|
7884
7998
|
}
|
|
7885
7999
|
//#endregion
|
|
7886
8000
|
//#region src/plugins/pluginProxyRemoteEntry.ts
|
|
@@ -7890,7 +8004,7 @@ function resolveDevHashEntryFileName(fileName) {
|
|
|
7890
8004
|
const baseName = path$1.basename(normalized);
|
|
7891
8005
|
return path$1.extname(baseName) ? normalized : `${normalized}.js`;
|
|
7892
8006
|
}
|
|
7893
|
-
function pluginProxyRemoteEntry_default({ options, remoteEntryId, virtualExposesId }) {
|
|
8007
|
+
function pluginProxyRemoteEntry_default({ options, remoteEntryId, virtualExposesId, getParsePromise = () => Promise.resolve() }) {
|
|
7894
8008
|
let viteConfig, _command, root, originalConfigBase;
|
|
7895
8009
|
let exposeRemoteDependencies = {};
|
|
7896
8010
|
let exposeRemoteDependenciesDirty = true;
|
|
@@ -8000,7 +8114,7 @@ function pluginProxyRemoteEntry_default({ options, remoteEntryId, virtualExposes
|
|
|
8000
8114
|
}
|
|
8001
8115
|
},
|
|
8002
8116
|
async load(id) {
|
|
8003
|
-
if (id === remoteEntryId) return
|
|
8117
|
+
if (id === remoteEntryId) return getParsePromise().then((_) => generateRemoteEntry(options, virtualExposesId, _command));
|
|
8004
8118
|
if (id === virtualExposesId) {
|
|
8005
8119
|
await refreshExposeRemoteDependencies(this);
|
|
8006
8120
|
return generateExposes(options, exposeRemoteDependencies, _command, reactIslandExposes);
|
|
@@ -8010,7 +8124,7 @@ function pluginProxyRemoteEntry_default({ options, remoteEntryId, virtualExposes
|
|
|
8010
8124
|
async transform(code, id) {
|
|
8011
8125
|
return mapCodeToCodeWithSourcemap(await (async () => {
|
|
8012
8126
|
if (!filterId(id)) return;
|
|
8013
|
-
if (id.includes(remoteEntryId)) return
|
|
8127
|
+
if (id.includes(remoteEntryId)) return getParsePromise().then((_) => generateRemoteEntry(options, virtualExposesId, _command));
|
|
8014
8128
|
if (id === virtualExposesId) {
|
|
8015
8129
|
await refreshExposeRemoteDependencies(this);
|
|
8016
8130
|
return generateExposes(options, exposeRemoteDependencies, _command, reactIslandExposes);
|
|
@@ -8167,6 +8281,41 @@ function pluginProxyRemotes_default(options) {
|
|
|
8167
8281
|
};
|
|
8168
8282
|
}
|
|
8169
8283
|
//#endregion
|
|
8284
|
+
//#region src/plugins/pluginReactMixedModeGuard.ts
|
|
8285
|
+
const REACT_DEVELOPMENT_RUNTIME = /[\\/]react[\\/]cjs[\\/]react(?:-jsx-(?:dev-)?runtime)?\.development\.js$/;
|
|
8286
|
+
const UNSAFE_GET_OWNER = "return null === dispatcher ? null : dispatcher.getOwner();";
|
|
8287
|
+
const SAFE_GET_OWNER = "return typeof dispatcher?.getOwner === \"function\" ? dispatcher.getOwner() : null;";
|
|
8288
|
+
const REACT_MIXED_MODE_ROLLDOWN_PLUGIN = "module-federation:react-mixed-mode-rolldown";
|
|
8289
|
+
const REACT_MIXED_MODE_ESBUILD_PLUGIN = "module-federation:react-mixed-mode-esbuild";
|
|
8290
|
+
function patchReactDevelopmentRuntime(code, id) {
|
|
8291
|
+
if (!REACT_DEVELOPMENT_RUNTIME.test(id)) return;
|
|
8292
|
+
const patched = code.replaceAll(UNSAFE_GET_OWNER, SAFE_GET_OWNER);
|
|
8293
|
+
return patched === code ? void 0 : patched;
|
|
8294
|
+
}
|
|
8295
|
+
function createRolldownReactMixedModeGuard() {
|
|
8296
|
+
return {
|
|
8297
|
+
name: REACT_MIXED_MODE_ROLLDOWN_PLUGIN,
|
|
8298
|
+
transform(code, id) {
|
|
8299
|
+
return patchReactDevelopmentRuntime(code, id);
|
|
8300
|
+
}
|
|
8301
|
+
};
|
|
8302
|
+
}
|
|
8303
|
+
function createEsbuildReactMixedModeGuard() {
|
|
8304
|
+
return {
|
|
8305
|
+
name: REACT_MIXED_MODE_ESBUILD_PLUGIN,
|
|
8306
|
+
setup(build) {
|
|
8307
|
+
build.onLoad({ filter: REACT_DEVELOPMENT_RUNTIME }, (args) => {
|
|
8308
|
+
const patched = patchReactDevelopmentRuntime(readFileSync$1(args.path, "utf8"), args.path);
|
|
8309
|
+
if (patched === void 0) return;
|
|
8310
|
+
return {
|
|
8311
|
+
contents: patched,
|
|
8312
|
+
loader: "js"
|
|
8313
|
+
};
|
|
8314
|
+
});
|
|
8315
|
+
}
|
|
8316
|
+
};
|
|
8317
|
+
}
|
|
8318
|
+
//#endregion
|
|
8170
8319
|
//#region src/utils/PromiseStore.ts
|
|
8171
8320
|
/**
|
|
8172
8321
|
* example:
|
|
@@ -8311,7 +8460,7 @@ function excludeSharedSubDependencies(shared) {
|
|
|
8311
8460
|
}
|
|
8312
8461
|
}
|
|
8313
8462
|
function proxySharedModule(options) {
|
|
8314
|
-
const { shared = {}, federationOptions } = options;
|
|
8463
|
+
const { shared = {}, federationOptions, getParsePromise = () => Promise.resolve() } = options;
|
|
8315
8464
|
let _config;
|
|
8316
8465
|
let _command = "serve";
|
|
8317
8466
|
let useDirectReactImport = false;
|
|
@@ -8320,6 +8469,7 @@ function proxySharedModule(options) {
|
|
|
8320
8469
|
let devServer;
|
|
8321
8470
|
const materializedLoadShareSources = /* @__PURE__ */ new Set();
|
|
8322
8471
|
const emittedTreeShakingProviders = /* @__PURE__ */ new Set();
|
|
8472
|
+
const hasAnalyzableShares = Object.values(shared).some((share) => shouldAnalyzeSharedExports(share));
|
|
8323
8473
|
const normalizeTreeShakingOutputPath = (value) => {
|
|
8324
8474
|
const normalized = normalizePathForImport(value);
|
|
8325
8475
|
if (path$1.posix.isAbsolute(normalized) || /^[A-Za-z]:\//.test(normalized) || normalized.split("/").includes("..")) throw new Error(`Invalid treeShakingDir "${value}": absolute paths and parent segments are not allowed.`);
|
|
@@ -8364,7 +8514,7 @@ function proxySharedModule(options) {
|
|
|
8364
8514
|
if (source === getLocalSharedImportMapPath(federationOptions)) return getResolvedLocalSharedImportMapId(federationOptions);
|
|
8365
8515
|
},
|
|
8366
8516
|
load(id) {
|
|
8367
|
-
if (id === getResolvedLocalSharedImportMapId(federationOptions)) return
|
|
8517
|
+
if (id === getResolvedLocalSharedImportMapId(federationOptions)) return getParsePromise().then((_) => {
|
|
8368
8518
|
refreshTreeShakingModules(federationOptions);
|
|
8369
8519
|
const providerPackages = /* @__PURE__ */ new Set([...Object.keys(shared).filter((pkg) => !pkg.endsWith("/")), ...getUsedShares(federationOptions)]);
|
|
8370
8520
|
for (const pkg of providerPackages) {
|
|
@@ -8419,10 +8569,10 @@ function proxySharedModule(options) {
|
|
|
8419
8569
|
refreshTreeShakingModules(federationOptions);
|
|
8420
8570
|
},
|
|
8421
8571
|
shouldTransformCachedModule() {
|
|
8422
|
-
return _command === "build" &&
|
|
8572
|
+
return _command === "build" && hasAnalyzableShares;
|
|
8423
8573
|
},
|
|
8424
8574
|
transform(code, id) {
|
|
8425
|
-
if (_command !== "build" || !
|
|
8575
|
+
if (_command !== "build" || !hasAnalyzableShares) return;
|
|
8426
8576
|
collectTreeShakingImports(code, id, shared, findSharedKeyForSource, (sharedKey, exports, request) => recordTreeShakingExports(sharedKey, exports, request, federationOptions), (sharedKey, request) => markTreeShakingPackageUnsafe(sharedKey, request, federationOptions));
|
|
8427
8577
|
refreshTreeShakingModules(federationOptions);
|
|
8428
8578
|
}
|
|
@@ -8526,6 +8676,15 @@ const JS_EXTENSIONS_RE = /\.(?:[mc]?[jt]sx?|vue|svelte)(?:\?|$)/;
|
|
|
8526
8676
|
function isAstNode(value) {
|
|
8527
8677
|
return !!value && typeof value === "object" && typeof value.type === "string";
|
|
8528
8678
|
}
|
|
8679
|
+
function findStaticRemoteSources(code, isRemoteImport) {
|
|
8680
|
+
const codePositions = createCodePositionMap(code);
|
|
8681
|
+
const sources = /* @__PURE__ */ new Set();
|
|
8682
|
+
for (const pattern of [/\b(?:import|export)\s+[^;]*?\bfrom\s*["']([^"']+)["']/g, /\bimport\s*["']([^"']+)["']/g]) for (const match of code.matchAll(pattern)) {
|
|
8683
|
+
const source = match[1];
|
|
8684
|
+
if (codePositions[match.index] && isRemoteImport(source)) sources.add(source);
|
|
8685
|
+
}
|
|
8686
|
+
return sources;
|
|
8687
|
+
}
|
|
8529
8688
|
function walkAST(root, visitor) {
|
|
8530
8689
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
8531
8690
|
function visit(node) {
|
|
@@ -8678,6 +8837,7 @@ async function collectFromAST(ast, code, isRemoteImport) {
|
|
|
8678
8837
|
if (!value || !isRemoteImport(value)) return;
|
|
8679
8838
|
result.push({
|
|
8680
8839
|
kind: "dynamic",
|
|
8840
|
+
source: value,
|
|
8681
8841
|
start: node.start,
|
|
8682
8842
|
end: node.end,
|
|
8683
8843
|
originalText: code.slice(node.start, node.end)
|
|
@@ -8756,6 +8916,7 @@ function collectFromRegex(code, isRemoteImport) {
|
|
|
8756
8916
|
if (!isRemoteImport(source)) continue;
|
|
8757
8917
|
result.push({
|
|
8758
8918
|
kind: "dynamic",
|
|
8919
|
+
source,
|
|
8759
8920
|
start: match.index,
|
|
8760
8921
|
end: match.index + full.length,
|
|
8761
8922
|
originalText: full
|
|
@@ -8782,6 +8943,7 @@ function pluginRemoteNamedExports(options) {
|
|
|
8782
8943
|
if (!JS_EXTENSIONS_RE.test(id)) return;
|
|
8783
8944
|
if (!remoteNames.some((name) => code.includes(name))) return;
|
|
8784
8945
|
const matchesRemoteImport = (source) => isRemoteImport(source, id);
|
|
8946
|
+
for (const source of findStaticRemoteSources(code, matchesRemoteImport)) markStaticRemote(source, options);
|
|
8785
8947
|
let imports;
|
|
8786
8948
|
try {
|
|
8787
8949
|
imports = await collectFromAST(this.parse(code), code, matchesRemoteImport);
|
|
@@ -8790,6 +8952,7 @@ function pluginRemoteNamedExports(options) {
|
|
|
8790
8952
|
imports = collectFromRegex(code, matchesRemoteImport);
|
|
8791
8953
|
}
|
|
8792
8954
|
if (!imports) return;
|
|
8955
|
+
for (const remoteImport of imports) if (remoteImport.kind === "dynamic") markDynamicRemote(remoteImport.source, options);
|
|
8793
8956
|
return applyRewrites(code, imports, id);
|
|
8794
8957
|
}
|
|
8795
8958
|
};
|
|
@@ -9624,6 +9787,7 @@ function includeLinkedSharedEntries(optimizeDeps, shared, projectRoot, exposes,
|
|
|
9624
9787
|
function createEarlyVirtualModulesPlugin(options) {
|
|
9625
9788
|
const { shared, remotes } = options;
|
|
9626
9789
|
const isLitShare = (pkg) => pkg === "lit" || pkg.startsWith("lit/");
|
|
9790
|
+
const shouldGuardReactMixedMode = Object.keys(remotes ?? {}).length > 0 && shared?.react?.shareConfig.singleton === true;
|
|
9627
9791
|
return {
|
|
9628
9792
|
name: "vite:module-federation-early-init",
|
|
9629
9793
|
enforce: "pre",
|
|
@@ -9651,6 +9815,7 @@ function createEarlyVirtualModulesPlugin(options) {
|
|
|
9651
9815
|
if (isRolldown) {
|
|
9652
9816
|
optimizeDeps.rolldownOptions ??= {};
|
|
9653
9817
|
optimizeDeps.rolldownOptions.plugins ??= [];
|
|
9818
|
+
if (shouldGuardReactMixedMode) optimizeDeps.rolldownOptions.plugins.push(createRolldownReactMixedModeGuard());
|
|
9654
9819
|
optimizeDeps.rolldownOptions.plugins.push({
|
|
9655
9820
|
name: "module-federation:optimize-shared-resolver",
|
|
9656
9821
|
load(id) {
|
|
@@ -9695,6 +9860,7 @@ function createEarlyVirtualModulesPlugin(options) {
|
|
|
9695
9860
|
} else {
|
|
9696
9861
|
optimizeDeps.esbuildOptions ??= {};
|
|
9697
9862
|
optimizeDeps.esbuildOptions.plugins ??= [];
|
|
9863
|
+
if (shouldGuardReactMixedMode) optimizeDeps.esbuildOptions.plugins.push(createEsbuildReactMixedModeGuard());
|
|
9698
9864
|
optimizeDeps.esbuildOptions.plugins.push({
|
|
9699
9865
|
name: "module-federation:optimize-shared-proxy",
|
|
9700
9866
|
setup(build) {
|
|
@@ -9877,6 +10043,14 @@ function federation(mfUserOptions) {
|
|
|
9877
10043
|
if (!name) throw createModuleFederationError("name is required");
|
|
9878
10044
|
const remoteEntryId = getRemoteEntryId(options);
|
|
9879
10045
|
const virtualExposesId = getVirtualExposesId(options);
|
|
10046
|
+
const moduleParseController = createModuleParseController();
|
|
10047
|
+
const moduleParsePlugins = pluginModuleParseEnd_default((id) => {
|
|
10048
|
+
return id.includes(getHostAutoInitImportId(options)) || id.includes(remoteEntryId) || id.includes(virtualExposesId) || id.includes("virtual:mf-localSharedImportMap") || id.includes("__loadShare__") || id.includes("__prebuild__") || id.includes("__treeShakingProvider__") || id.includes("__mf_tree_shaking_graph__");
|
|
10049
|
+
}, {
|
|
10050
|
+
moduleParseTimeout: options.moduleParseTimeout,
|
|
10051
|
+
moduleParseIdleTimeout: options.moduleParseIdleTimeout,
|
|
10052
|
+
exposedModuleImports: Object.values(options.exposes).map((expose) => expose.import)
|
|
10053
|
+
}, moduleParseController);
|
|
9880
10054
|
let command;
|
|
9881
10055
|
let desiredRolldownOutput;
|
|
9882
10056
|
let isSsrBuild = false;
|
|
@@ -9908,7 +10082,7 @@ function federation(mfUserOptions) {
|
|
|
9908
10082
|
writePreBuildLibPath(pkg, shared[key], options, getLoadHookExportConditions(context, loadOptions));
|
|
9909
10083
|
return "refreshed";
|
|
9910
10084
|
};
|
|
9911
|
-
const refreshLoadShareModuleForEnvironment = (id, context, loadOptions) => {
|
|
10085
|
+
const refreshLoadShareModuleForEnvironment = (id, context, loadOptions, importFalseExportUsage) => {
|
|
9912
10086
|
const pkg = getCachedLoadSharePkg(id);
|
|
9913
10087
|
if (!pkg) return "not-applicable";
|
|
9914
10088
|
const key = findSharedKey(pkg, shared);
|
|
@@ -9916,9 +10090,26 @@ function federation(mfUserOptions) {
|
|
|
9916
10090
|
const requestedModule = VirtualModule.findById(id);
|
|
9917
10091
|
const ownedModule = VirtualModule.findById(getLoadShareModulePath(pkg, false, options));
|
|
9918
10092
|
if (!requestedModule || requestedModule !== ownedModule) return "not-owned";
|
|
9919
|
-
writeLoadShareModule(pkg, shared[key], command, getIsRolldown(context), options, getLoadHookExportConditions(context, loadOptions));
|
|
10093
|
+
writeLoadShareModule(pkg, shared[key], command, getIsRolldown(context), options, getLoadHookExportConditions(context, loadOptions), importFalseExportUsage);
|
|
9920
10094
|
return "refreshed";
|
|
9921
10095
|
};
|
|
10096
|
+
const getCompleteImportFalseExportUsage = (id) => {
|
|
10097
|
+
if (command !== "build") return void 0;
|
|
10098
|
+
const pkg = getCachedLoadSharePkg(id);
|
|
10099
|
+
if (!pkg) return void 0;
|
|
10100
|
+
const key = findSharedKey(pkg, shared);
|
|
10101
|
+
if (!key || shared[key].shareConfig.import !== false) return void 0;
|
|
10102
|
+
return moduleParseController.parsePromise.then((completion) => {
|
|
10103
|
+
if (!completion.complete) {
|
|
10104
|
+
if (!moduleParseController.discardWarned) {
|
|
10105
|
+
moduleParseController.discardWarned = true;
|
|
10106
|
+
mfWarn(`import: false shared export analysis was discarded (reason: ${completion.reason}) — falling back to the complete export surface, so shared consumers keep every detected named export.` + (completion.reason === "idle-timeout" || completion.reason === "timeout" ? " If the build is simply slow, increasing moduleParseIdleTimeout may let the analysis finish." : ""));
|
|
10107
|
+
}
|
|
10108
|
+
return;
|
|
10109
|
+
}
|
|
10110
|
+
return getSharedExportUsage(pkg, shared[key], key, options);
|
|
10111
|
+
});
|
|
10112
|
+
};
|
|
9922
10113
|
return [
|
|
9923
10114
|
{
|
|
9924
10115
|
name: "vite:module-federation-virtual-modules",
|
|
@@ -10024,20 +10215,16 @@ function federation(mfUserOptions) {
|
|
|
10024
10215
|
pluginProxyRemoteEntry_default({
|
|
10025
10216
|
options,
|
|
10026
10217
|
remoteEntryId,
|
|
10027
|
-
virtualExposesId
|
|
10218
|
+
virtualExposesId,
|
|
10219
|
+
getParsePromise: () => moduleParseController.parsePromise
|
|
10028
10220
|
}),
|
|
10029
10221
|
pluginProxyRemotes_default(options),
|
|
10030
10222
|
pluginRemoteNamedExports(options),
|
|
10031
|
-
...
|
|
10032
|
-
return id.includes(getHostAutoInitImportId(options)) || id.includes(remoteEntryId) || id.includes(virtualExposesId) || id.includes(getLocalSharedImportMapPath(options)) || id.includes("__loadShare__") || id.includes("__prebuild__") || id.includes("__treeShakingProvider__") || id.includes("__mf_tree_shaking_graph__");
|
|
10033
|
-
}, {
|
|
10034
|
-
moduleParseTimeout: options.moduleParseTimeout,
|
|
10035
|
-
moduleParseIdleTimeout: options.moduleParseIdleTimeout,
|
|
10036
|
-
exposedModuleImports: Object.values(options.exposes).map((expose) => expose.import)
|
|
10037
|
-
}),
|
|
10223
|
+
...moduleParsePlugins,
|
|
10038
10224
|
...proxySharedModule({
|
|
10039
10225
|
shared,
|
|
10040
|
-
federationOptions: options
|
|
10226
|
+
federationOptions: options,
|
|
10227
|
+
getParsePromise: () => moduleParseController.parsePromise
|
|
10041
10228
|
}),
|
|
10042
10229
|
{
|
|
10043
10230
|
name: "module-federation-esm-shims",
|
|
@@ -10165,8 +10352,9 @@ function federation(mfUserOptions) {
|
|
|
10165
10352
|
}
|
|
10166
10353
|
},
|
|
10167
10354
|
load(id, loadOptions) {
|
|
10168
|
-
|
|
10169
|
-
if (id.includes("__loadShare__") &&
|
|
10355
|
+
const loadVirtualModule = (importFalseExportUsage) => {
|
|
10356
|
+
if (!id.includes("__loadShare__") && !id.includes("__loadRemote__")) return;
|
|
10357
|
+
if (id.includes("__loadShare__") && refreshLoadShareModuleForEnvironment(id, this, loadOptions, importFalseExportUsage) === "not-owned") return;
|
|
10170
10358
|
const virtualModule = VirtualModule.findById(id);
|
|
10171
10359
|
if (!virtualModule?.code) return null;
|
|
10172
10360
|
let code = virtualModule.code;
|
|
@@ -10183,7 +10371,10 @@ function federation(mfUserOptions) {
|
|
|
10183
10371
|
code,
|
|
10184
10372
|
syntheticNamedExports: "__moduleExports"
|
|
10185
10373
|
};
|
|
10186
|
-
}
|
|
10374
|
+
};
|
|
10375
|
+
const pendingImportFalseExportUsage = id.includes("__loadShare__") ? getCompleteImportFalseExportUsage(id) : void 0;
|
|
10376
|
+
if (pendingImportFalseExportUsage) return pendingImportFalseExportUsage.then(loadVirtualModule);
|
|
10377
|
+
return loadVirtualModule();
|
|
10187
10378
|
},
|
|
10188
10379
|
generateBundle(_outputOptions, bundle, _isWrite) {
|
|
10189
10380
|
for (const [fileName, chunk] of Object.entries(bundle)) {
|
|
@@ -140,12 +140,13 @@ const runnerCache = /* @__PURE__ */ new Map();
|
|
|
140
140
|
* exist.
|
|
141
141
|
*/
|
|
142
142
|
async function getModuleRunnerModule() {
|
|
143
|
+
const moduleRunnerId = ["vite", "module-runner"].join("/");
|
|
143
144
|
try {
|
|
144
145
|
const { createRequire } = await nodeImport("module");
|
|
145
|
-
return createRequire(import.meta.url)(
|
|
146
|
+
return createRequire(import.meta.url)(moduleRunnerId);
|
|
146
147
|
} catch {}
|
|
147
148
|
try {
|
|
148
|
-
return await
|
|
149
|
+
return await nodeImport(moduleRunnerId);
|
|
149
150
|
} catch {
|
|
150
151
|
return null;
|
|
151
152
|
}
|
|
@@ -572,7 +573,7 @@ async function importTempModule(filePath, versionKey) {
|
|
|
572
573
|
}
|
|
573
574
|
let warnedVmUnavailable = false;
|
|
574
575
|
async function tryVmStrategy(ssrEntry, options) {
|
|
575
|
-
const { loadViaVmStrategy, isVmStrategyAvailable } = await import("./ssrVmStrategy-
|
|
576
|
+
const { loadViaVmStrategy, isVmStrategyAvailable } = await import("./ssrVmStrategy-B34y11HE.js");
|
|
576
577
|
if (!await isVmStrategyAvailable()) {
|
|
577
578
|
if (!warnedVmUnavailable) {
|
|
578
579
|
warnedVmUnavailable = true;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as readResponseTextBounded, n as neutralizeBrowserPreloadHelpers, s as fetchWithTimeout, t as SsrEntryHttpError } from "./ssrEntryLoader-
|
|
1
|
+
import { c as readResponseTextBounded, n as neutralizeBrowserPreloadHelpers, s as fetchWithTimeout, t as SsrEntryHttpError } from "./ssrEntryLoader-gVPDPAE8.js";
|
|
2
2
|
//#region src/utils/ssrVmStrategy.ts
|
|
3
3
|
/**
|
|
4
4
|
* vm.SourceTextModule strategy for loading remote SSR entries.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as ssrEntryLoaderPlugin, n as neutralizeBrowserPreloadHelpers, r as revalidate, t as SsrEntryHttpError } from "../ssrEntryLoader-
|
|
1
|
+
import { i as ssrEntryLoaderPlugin, n as neutralizeBrowserPreloadHelpers, r as revalidate, t as SsrEntryHttpError } from "../ssrEntryLoader-gVPDPAE8.js";
|
|
2
2
|
export { SsrEntryHttpError, ssrEntryLoaderPlugin as default, neutralizeBrowserPreloadHelpers, revalidate };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/vite",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.2",
|
|
4
4
|
"description": "Vite plugin for Module Federation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -90,7 +90,41 @@
|
|
|
90
90
|
"rollup": "4.62.3",
|
|
91
91
|
"tsdown": "0.22.14",
|
|
92
92
|
"typescript": "7.0.2",
|
|
93
|
-
"vite": "8.
|
|
94
|
-
"vitest": "4.
|
|
93
|
+
"vite": "8.2.0",
|
|
94
|
+
"vitest": "4.1.10"
|
|
95
|
+
},
|
|
96
|
+
"pnpm": {
|
|
97
|
+
"overrides": {
|
|
98
|
+
"@babel/core@<7.29.6": "7.29.6",
|
|
99
|
+
"@babel/helpers@<7.26.10": "7.29.7",
|
|
100
|
+
"@babel/plugin-transform-modules-systemjs@<7.29.4": "7.29.4",
|
|
101
|
+
"@babel/runtime@<7.26.10": "7.29.7",
|
|
102
|
+
"adm-zip@<0.6.0": "0.6.0",
|
|
103
|
+
"ajv@>=6.0.0 <6.14.0": "6.14.0",
|
|
104
|
+
"ajv@>=8.0.0 <8.18.0": "8.20.0",
|
|
105
|
+
"body-parser@<1.20.6": "1.20.6",
|
|
106
|
+
"cross-spawn@<7.0.5": "7.0.6",
|
|
107
|
+
"esbuild@<0.28.1": "0.28.1",
|
|
108
|
+
"fast-uri@>=3.0.0 <3.1.4": "3.1.4",
|
|
109
|
+
"follow-redirects@<1.16.0": "1.16.0",
|
|
110
|
+
"http-proxy-middleware@>=2.0.0 <2.0.10": "2.0.10",
|
|
111
|
+
"immutable@<4.3.9": "4.3.9",
|
|
112
|
+
"js-yaml@>=4.0.0 <4.3.0": "4.3.0",
|
|
113
|
+
"lodash@<4.18.0": "4.18.1",
|
|
114
|
+
"path-to-regexp@<0.1.13": "0.1.13",
|
|
115
|
+
"postcss@<8.5.18": "8.5.25",
|
|
116
|
+
"qs@>=6.0.0 <6.15.2": "6.15.2",
|
|
117
|
+
"serialize-javascript@<7.0.5": "7.0.5",
|
|
118
|
+
"shell-quote@<1.9.0": "1.10.0",
|
|
119
|
+
"sucrase@<3.35.1": "3.35.1",
|
|
120
|
+
"undici@>=7.0.0 <7.28.0": "7.28.0",
|
|
121
|
+
"uuid@<11.1.1": "11.1.1",
|
|
122
|
+
"webpack-dev-server@<5.2.6": "5.2.6",
|
|
123
|
+
"webpack@<5.104.1": "5.109.2",
|
|
124
|
+
"websocket-driver@<0.7.5": "0.7.5",
|
|
125
|
+
"ws@>=8.0.0 <8.21.0": "8.21.0",
|
|
126
|
+
"yaml@>=1.0.0 <1.10.3": "1.10.3",
|
|
127
|
+
"yaml@>=2.0.0 <2.8.3": "2.8.3"
|
|
128
|
+
}
|
|
95
129
|
}
|
|
96
|
-
}
|
|
130
|
+
}
|