@module-federation/node 2.7.32 → 2.7.34
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/dist/_virtual/_rolldown/runtime.js +31 -0
- package/dist/_virtual/_rolldown/runtime.mjs +8 -0
- package/dist/plugins/ChunkCorrelationPlugin.js +308 -0
- package/dist/plugins/ChunkCorrelationPlugin.js.map +1 -0
- package/dist/plugins/ChunkCorrelationPlugin.mjs +305 -0
- package/dist/plugins/ChunkCorrelationPlugin.mjs.map +1 -0
- package/dist/src/filesystem/stratagies.d.mts +21 -0
- package/dist/src/filesystem/stratagies.d.ts +10 -7
- package/dist/src/filesystem/stratagies.js +97 -116
- package/dist/src/filesystem/stratagies.js.map +1 -1
- package/dist/src/filesystem/stratagies.mjs +103 -0
- package/dist/src/filesystem/stratagies.mjs.map +1 -0
- package/dist/src/index.d.mts +8 -0
- package/dist/src/index.d.ts +8 -7
- package/dist/src/index.js +16 -22
- package/dist/src/index.mjs +9 -0
- package/dist/src/plugins/AutomaticPublicPathPlugin.d.mts +12 -0
- package/dist/src/plugins/AutomaticPublicPathPlugin.d.ts +9 -7
- package/dist/src/plugins/AutomaticPublicPathPlugin.js +26 -35
- package/dist/src/plugins/AutomaticPublicPathPlugin.js.map +1 -1
- package/dist/src/plugins/AutomaticPublicPathPlugin.mjs +28 -0
- package/dist/src/plugins/AutomaticPublicPathPlugin.mjs.map +1 -0
- package/dist/src/plugins/ChunkCorrelationPlugin.d.mts +5 -0
- package/dist/src/plugins/ChunkCorrelationPlugin.d.ts +4 -61
- package/dist/src/plugins/ChunkCorrelationPlugin.js +8 -440
- package/dist/src/plugins/ChunkCorrelationPlugin.js.map +1 -1
- package/dist/src/plugins/ChunkCorrelationPlugin.mjs +8 -0
- package/dist/src/plugins/ChunkCorrelationPlugin.mjs.map +1 -0
- package/dist/src/plugins/CommonJsChunkLoadingPlugin.d.mts +21 -0
- package/dist/src/plugins/CommonJsChunkLoadingPlugin.d.ts +16 -13
- package/dist/src/plugins/CommonJsChunkLoadingPlugin.js +68 -118
- package/dist/src/plugins/CommonJsChunkLoadingPlugin.js.map +1 -1
- package/dist/src/plugins/CommonJsChunkLoadingPlugin.mjs +70 -0
- package/dist/src/plugins/CommonJsChunkLoadingPlugin.mjs.map +1 -0
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.d.mts +46 -0
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.d.ts +39 -34
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js +110 -126
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js.map +1 -1
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.mjs +111 -0
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.mjs.map +1 -0
- package/dist/src/plugins/EntryChunkTrackerPlugin.d.mts +17 -0
- package/dist/src/plugins/EntryChunkTrackerPlugin.d.ts +14 -10
- package/dist/src/plugins/EntryChunkTrackerPlugin.js +30 -32
- package/dist/src/plugins/EntryChunkTrackerPlugin.js.map +1 -1
- package/dist/src/plugins/EntryChunkTrackerPlugin.mjs +38 -0
- package/dist/src/plugins/EntryChunkTrackerPlugin.mjs.map +1 -0
- package/dist/src/plugins/NodeFederationPlugin.d.mts +54 -0
- package/dist/src/plugins/NodeFederationPlugin.d.ts +33 -26
- package/dist/src/plugins/NodeFederationPlugin.js +72 -84
- package/dist/src/plugins/NodeFederationPlugin.js.map +1 -1
- package/dist/src/plugins/NodeFederationPlugin.mjs +73 -0
- package/dist/src/plugins/NodeFederationPlugin.mjs.map +1 -0
- package/dist/src/plugins/RemotePublicPathRuntimeModule.d.mts +15 -0
- package/dist/src/plugins/RemotePublicPathRuntimeModule.d.ts +12 -8
- package/dist/src/plugins/RemotePublicPathRuntimeModule.js +34 -35
- package/dist/src/plugins/RemotePublicPathRuntimeModule.js.map +1 -1
- package/dist/src/plugins/RemotePublicPathRuntimeModule.mjs +132 -0
- package/dist/src/plugins/RemotePublicPathRuntimeModule.mjs.map +1 -0
- package/dist/src/plugins/StreamingTargetPlugin.d.mts +32 -0
- package/dist/src/plugins/StreamingTargetPlugin.d.ts +19 -16
- package/dist/src/plugins/StreamingTargetPlugin.js +43 -56
- package/dist/src/plugins/StreamingTargetPlugin.js.map +1 -1
- package/dist/src/plugins/StreamingTargetPlugin.mjs +46 -0
- package/dist/src/plugins/StreamingTargetPlugin.mjs.map +1 -0
- package/dist/src/plugins/UniversalFederationPlugin.d.mts +49 -0
- package/dist/src/plugins/UniversalFederationPlugin.d.ts +26 -23
- package/dist/src/plugins/UniversalFederationPlugin.js +62 -81
- package/dist/src/plugins/UniversalFederationPlugin.js.map +1 -1
- package/dist/src/plugins/UniversalFederationPlugin.mjs +65 -0
- package/dist/src/plugins/UniversalFederationPlugin.mjs.map +1 -0
- package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.d.mts +9 -0
- package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.d.ts +6 -3
- package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.js +17 -17
- package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.js.map +1 -1
- package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.mjs +25 -0
- package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.mjs.map +1 -0
- package/dist/src/plugins/webpackChunkUtilities.d.mts +55 -0
- package/dist/src/plugins/webpackChunkUtilities.d.ts +14 -9
- package/dist/src/plugins/webpackChunkUtilities.js +195 -257
- package/dist/src/plugins/webpackChunkUtilities.js.map +1 -1
- package/dist/src/plugins/webpackChunkUtilities.mjs +234 -0
- package/dist/src/plugins/webpackChunkUtilities.mjs.map +1 -0
- package/dist/src/recordDynamicRemoteEntryHashPlugin.d.mts +7 -0
- package/dist/src/recordDynamicRemoteEntryHashPlugin.d.ts +5 -2
- package/dist/src/recordDynamicRemoteEntryHashPlugin.js +24 -61
- package/dist/src/recordDynamicRemoteEntryHashPlugin.js.map +1 -1
- package/dist/src/recordDynamicRemoteEntryHashPlugin.mjs +26 -0
- package/dist/src/recordDynamicRemoteEntryHashPlugin.mjs.map +1 -0
- package/dist/src/runtimePlugin.d.mts +27 -0
- package/dist/src/runtimePlugin.d.ts +24 -19
- package/dist/src/runtimePlugin.js +157 -252
- package/dist/src/runtimePlugin.js.map +1 -1
- package/dist/src/runtimePlugin.mjs +169 -0
- package/dist/src/runtimePlugin.mjs.map +1 -0
- package/dist/src/types/index.d.mts +8 -0
- package/dist/src/types/index.d.ts +8 -3
- package/dist/src/types/index.js +1 -3
- package/dist/src/types/index.mjs +1 -0
- package/dist/src/utils/flush-chunks.d.mts +15 -0
- package/dist/src/utils/flush-chunks.d.ts +7 -3
- package/dist/src/utils/flush-chunks.js +90 -161
- package/dist/src/utils/flush-chunks.js.map +1 -1
- package/dist/src/utils/flush-chunks.mjs +102 -0
- package/dist/src/utils/flush-chunks.mjs.map +1 -0
- package/dist/src/utils/hot-reload.d.mts +16 -0
- package/dist/src/utils/hot-reload.d.ts +14 -10
- package/dist/src/utils/hot-reload.js +178 -264
- package/dist/src/utils/hot-reload.js.map +1 -1
- package/dist/src/utils/hot-reload.mjs +195 -0
- package/dist/src/utils/hot-reload.mjs.map +1 -0
- package/dist/src/utils/index.d.mts +3 -0
- package/dist/src/utils/index.d.ts +3 -2
- package/dist/src/utils/index.js +15 -19
- package/dist/src/utils/index.mjs +4 -0
- package/package.json +65 -15
- package/dist/jest.config.d.ts +0 -11
- package/dist/jest.config.js +0 -19
- package/dist/jest.config.js.map +0 -1
- package/dist/package.json +0 -82
- package/dist/src/index.js.map +0 -1
- package/dist/src/types/index.js.map +0 -1
- package/dist/src/utils/index.js.map +0 -1
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { __commonJSMin } from "../_virtual/_rolldown/runtime.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/plugins/ChunkCorrelationPlugin.js
|
|
4
|
+
var require_ChunkCorrelationPlugin = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
5
|
+
const PLUGIN_NAME = "FederationStatsPlugin";
|
|
6
|
+
/** @typedef {import("./webpack-stats-types").WebpackStats} WebpackStats */
|
|
7
|
+
/** @typedef {import( "./webpack-stats-types").WebpackStatsChunk} WebpackStatsChunk */
|
|
8
|
+
/** @typedef {import("./webpack-stats-types").WebpackStatsModule} WebpackStatsModule */
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {object} SharedDependency
|
|
11
|
+
* @property {string} shareScope
|
|
12
|
+
* @property {string} shareKey
|
|
13
|
+
* @property {string} requiredVersion
|
|
14
|
+
* @property {boolean} strictVersion
|
|
15
|
+
* @property {boolean} singleton
|
|
16
|
+
* @property {boolean} eager
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {object} SharedModule
|
|
20
|
+
* @property {string[]} chunks
|
|
21
|
+
* @property {SharedDependency[]} provides
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* @typedef {object} Exposed
|
|
25
|
+
* @property {string[]} chunks
|
|
26
|
+
* @property {SharedModule[]} sharedModules
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* @typedef {object} FederatedContainer
|
|
30
|
+
* @property {string} remote
|
|
31
|
+
* @property {string} entry
|
|
32
|
+
* @property {SharedModule[]} sharedModules
|
|
33
|
+
* @property {{ [key: string]: Exposed }} exposes
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* @typedef {object} FederatedStats
|
|
37
|
+
* @property {SharedModule[]} sharedModules
|
|
38
|
+
* @property {FederatedContainer[]} federatedModules
|
|
39
|
+
*/
|
|
40
|
+
const concat = (x, y) => x.concat(y);
|
|
41
|
+
const flatMap = (xs, f) => xs.map(f).reduce(concat, []);
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @param {WebpackStats} stats
|
|
45
|
+
* @returns {}
|
|
46
|
+
*/
|
|
47
|
+
function getRemoteModules(stats) {
|
|
48
|
+
return stats.modules.filter((mod) => mod.moduleType === "remote-module").reduce((acc, remoteModule) => {
|
|
49
|
+
acc[remoteModule.nameForCondition] = remoteModule.id;
|
|
50
|
+
return acc;
|
|
51
|
+
}, {});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
*
|
|
55
|
+
* @param {WebpackStats} stats
|
|
56
|
+
* @param {string} exposedFile
|
|
57
|
+
* @returns {WebpackStatsModule[]}
|
|
58
|
+
*/
|
|
59
|
+
function getExposedModules(stats, exposedFile) {
|
|
60
|
+
return stats.modules.filter((mod) => mod.name?.startsWith(exposedFile));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* @param {WebpackStats} stats
|
|
65
|
+
* @param {WebpackStatsModule} mod
|
|
66
|
+
* @returns {Exposed}
|
|
67
|
+
*/
|
|
68
|
+
function getExposed(stats, mod) {
|
|
69
|
+
const chunks = stats.chunks.filter((chunk) => {
|
|
70
|
+
return chunk.modules.find((modsInChunk) => {
|
|
71
|
+
return modsInChunk.id === mod.id && !modsInChunk.dependent;
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
const dependencies = stats.modules.filter((sharedModule) => {
|
|
75
|
+
if (sharedModule.moduleType !== "consume-shared-module") return false;
|
|
76
|
+
return sharedModule.issuerId === mod.id;
|
|
77
|
+
}).map((sharedModule) => {
|
|
78
|
+
return sharedModule.identifier.split("|")[2];
|
|
79
|
+
});
|
|
80
|
+
return flatMap(chunks, (chunk) => ({ [chunk.id]: {
|
|
81
|
+
files: chunk.files.map((f) => `${stats.publicPath === "auto" ? "" : stats.publicPath || ""}${f}`),
|
|
82
|
+
requiredModules: dependencies
|
|
83
|
+
} })).reduce((acc, chunk) => {
|
|
84
|
+
Object.assign(acc, chunk);
|
|
85
|
+
return acc;
|
|
86
|
+
}, {});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
*
|
|
90
|
+
* @param {import("webpack").Module} mod
|
|
91
|
+
* @param {(issuer: string) => boolean} check
|
|
92
|
+
* @returns {boolean}
|
|
93
|
+
*/
|
|
94
|
+
function searchIssuer(mod, check) {
|
|
95
|
+
if (mod.issuer && check(mod.issuer)) return true;
|
|
96
|
+
return !!mod.modules && mod.modules.some((m) => searchIssuer(m, check));
|
|
97
|
+
}
|
|
98
|
+
function searchReason(mod, check) {
|
|
99
|
+
if (mod.reasons && check(mod.reasons)) return true;
|
|
100
|
+
return !!mod.reasons && mod.reasons.some((m) => searchReason(m, check));
|
|
101
|
+
}
|
|
102
|
+
function searchIssuerAndReason(mod, check) {
|
|
103
|
+
const foundIssuer = searchIssuer(mod, (issuer) => check(issuer));
|
|
104
|
+
if (foundIssuer) return foundIssuer;
|
|
105
|
+
return searchReason(mod, (reason) => reason.some((r) => check(r?.moduleIdentifier)));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* @param {import("webpack").Module} mod
|
|
109
|
+
* @param {(issuer: string) => boolean} check
|
|
110
|
+
* @returns {string[]}
|
|
111
|
+
*/
|
|
112
|
+
function getIssuers(mod, check) {
|
|
113
|
+
if (mod.issuer && check(mod.issuer)) return [mod.issuer];
|
|
114
|
+
return mod.modules && mod.modules.filter((m) => searchIssuer(m, check)).map((m) => m.issuer) || [];
|
|
115
|
+
}
|
|
116
|
+
function getIssuersAndReasons(mod, check) {
|
|
117
|
+
if (mod.issuer && check(mod.issuer)) return [mod.issuer];
|
|
118
|
+
if (mod.reasons && searchReason(mod, (reason) => reason.some((r) => check(r?.moduleIdentifier)))) return mod.reasons.filter((r) => {
|
|
119
|
+
return r.moduleIdentifier && check(r.moduleIdentifier);
|
|
120
|
+
}).map((r) => r.moduleIdentifier);
|
|
121
|
+
return mod.modules && mod.modules.filter((m) => searchIssuerAndReason(m, check)).map((m) => {
|
|
122
|
+
return m.issuer || m.reasons.find((r) => check(r?.moduleIdentifier)).moduleIdentifier;
|
|
123
|
+
}) || [];
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* @param {string} issuer
|
|
127
|
+
* @returns {SharedDependency}
|
|
128
|
+
*/
|
|
129
|
+
function parseFederatedIssuer(issuer) {
|
|
130
|
+
const split = issuer?.split("|") || [];
|
|
131
|
+
if (split.length !== 8 || split[0] !== "consume-shared-module") return null;
|
|
132
|
+
const [, shareScope, shareKey, requiredVersion, strictVersion, , singleton, eager] = split;
|
|
133
|
+
return {
|
|
134
|
+
shareScope,
|
|
135
|
+
shareKey,
|
|
136
|
+
requiredVersion,
|
|
137
|
+
strictVersion: JSON.parse(strictVersion),
|
|
138
|
+
singleton: JSON.parse(singleton),
|
|
139
|
+
eager: JSON.parse(eager)
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
*
|
|
144
|
+
* @param {WebpackStats} stats
|
|
145
|
+
* @param {import("webpack").container.ModuleFederationPlugin} federationPlugin
|
|
146
|
+
* @returns {SharedModule[]}
|
|
147
|
+
*/
|
|
148
|
+
function getSharedModules(stats, federationPlugin) {
|
|
149
|
+
return flatMap(stats.chunks.filter((chunk) => {
|
|
150
|
+
if (!stats.entrypoints[federationPlugin.name]) return false;
|
|
151
|
+
return stats.entrypoints[federationPlugin.name].chunks.some((id) => chunk.id === id);
|
|
152
|
+
}), (chunk) => flatMap(chunk.children, (id) => stats.chunks.filter((c) => c.id === id && c.files.length > 0 && c.parents.some((p) => stats.entrypoints[federationPlugin.name].chunks.some((c) => c === p)) && c.modules.some((m) => searchIssuer(m, (issuer) => issuer?.startsWith("consume-shared-module")))))).map((chunk) => ({
|
|
153
|
+
chunks: chunk.files.map((f) => `${stats.publicPath === "auto" ? "" : stats.publicPath || ""}${f}`),
|
|
154
|
+
provides: flatMap(chunk.modules.filter((m) => searchIssuer(m, (issuer) => issuer?.startsWith("consume-shared-module"))), (m) => getIssuers(m, (issuer) => issuer?.startsWith("consume-shared-module"))).map(parseFederatedIssuer).filter((f) => !!f)
|
|
155
|
+
})).filter((c) => c.provides.length > 0);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* @param {WebpackStats} stats
|
|
159
|
+
* @returns {SharedModule[]}
|
|
160
|
+
*/
|
|
161
|
+
function getMainSharedModules(stats) {
|
|
162
|
+
return flatMap(stats.namedChunkGroups["main"] ? flatMap(stats.namedChunkGroups["main"].chunks, (c) => stats.chunks.filter((chunk) => chunk.id === c)) : [], (chunk) => flatMap(chunk.children, (id) => stats.chunks.filter((c) => {
|
|
163
|
+
return c.id === id && c.files.length > 0 && c.modules.some((m) => {
|
|
164
|
+
return searchIssuerAndReason(m, (check) => check?.startsWith("consume-shared-module"));
|
|
165
|
+
});
|
|
166
|
+
}))).map((chunk) => {
|
|
167
|
+
return {
|
|
168
|
+
chunks: chunk.files.map((f) => `${stats.publicPath === "auto" ? "" : stats.publicPath || ""}${f}`),
|
|
169
|
+
provides: flatMap(chunk.modules.filter((m) => searchIssuerAndReason(m, (check) => check?.startsWith("consume-shared-module"))), (m) => getIssuersAndReasons(m, (issuer) => issuer?.startsWith("consume-shared-module"))).map(parseFederatedIssuer).filter((f) => !!f)
|
|
170
|
+
};
|
|
171
|
+
}).filter((c) => c.provides.length > 0);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
*
|
|
175
|
+
* @param {WebpackStats} stats
|
|
176
|
+
* @param {import("webpack").container.ModuleFederationPlugin} federationPlugin
|
|
177
|
+
* @returns {FederatedStats}
|
|
178
|
+
*/
|
|
179
|
+
function getFederationStats(stats, federationPluginOptions) {
|
|
180
|
+
const exposedModules = Object.entries(federationPluginOptions.exposes).reduce((exposedModules, [exposedAs, exposedFile]) => Object.assign(exposedModules, { [exposedAs]: getExposedModules(stats, exposedFile) }), {});
|
|
181
|
+
/** @type {{ [key: string]: Exposed }} */
|
|
182
|
+
const exposes = Object.entries(exposedModules).reduce((exposedChunks, [exposedAs, exposedModules]) => Object.assign(exposedChunks, { [exposedAs]: flatMap(exposedModules, (mod) => getExposed(stats, mod)) }), {});
|
|
183
|
+
/** @type {string} */
|
|
184
|
+
const remote = federationPluginOptions.library?.name || federationPluginOptions.name;
|
|
185
|
+
const sharedModules = getSharedModules(stats, federationPluginOptions);
|
|
186
|
+
const remoteModules = getRemoteModules(stats);
|
|
187
|
+
return {
|
|
188
|
+
remote,
|
|
189
|
+
entry: `${stats.publicPath === "auto" ? "" : stats.publicPath || ""}${stats.assetsByChunkName[remote] && stats.assetsByChunkName[remote].length === 1 ? stats.assetsByChunkName[remote][0] : federationPluginOptions.filename}`,
|
|
190
|
+
sharedModules,
|
|
191
|
+
exposes,
|
|
192
|
+
remoteModules
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* @typedef {object} FederationStatsPluginOptions
|
|
197
|
+
* @property {string | string[]} filename The filename or an array of filenames in the `output.path` directory to write stats to.
|
|
198
|
+
*/
|
|
199
|
+
/**
|
|
200
|
+
* Writes relevant federation stats to a file for further consumption.
|
|
201
|
+
*/
|
|
202
|
+
var FederationStatsPlugin = class {
|
|
203
|
+
/**
|
|
204
|
+
*
|
|
205
|
+
* @param {FederationStatsPluginOptions} options
|
|
206
|
+
*/
|
|
207
|
+
constructor(options) {
|
|
208
|
+
if (!options || !options.filename) throw new Error("filename option is required.");
|
|
209
|
+
this._options = options;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
*
|
|
213
|
+
* @param {import("webpack").Compiler} compiler
|
|
214
|
+
*/
|
|
215
|
+
apply(compiler) {
|
|
216
|
+
const federationPlugins = compiler.options.plugins?.filter((plugin) => [
|
|
217
|
+
"NextFederationPlugin",
|
|
218
|
+
"UniversalFederationPlugin",
|
|
219
|
+
"NodeFederationPlugin",
|
|
220
|
+
"ModuleFederationPlugin"
|
|
221
|
+
].includes(plugin.constructor.name) && plugin?._options?.exposes);
|
|
222
|
+
if (!federationPlugins || federationPlugins.length === 0) return;
|
|
223
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
224
|
+
compilation.hooks.processAssets.tap({
|
|
225
|
+
name: PLUGIN_NAME,
|
|
226
|
+
stage: compilation.constructor.PROCESS_ASSETS_STAGE_REPORT
|
|
227
|
+
}, () => {
|
|
228
|
+
const [federationOpts] = federationPlugins.map((federationPlugin) => federationPlugin?._options);
|
|
229
|
+
let container;
|
|
230
|
+
for (const [name, entry] of compilation.entrypoints) {
|
|
231
|
+
if (container) break;
|
|
232
|
+
federationOpts.name.includes(name) && (container = entry);
|
|
233
|
+
}
|
|
234
|
+
if (!container) return;
|
|
235
|
+
container = container?.getEntrypointChunk();
|
|
236
|
+
const [containerEntryModule] = Array.from(compilation.chunkGraph.getChunkEntryModulesIterable(container));
|
|
237
|
+
const { blocks } = containerEntryModule;
|
|
238
|
+
const exposedResolved = {};
|
|
239
|
+
const builtExposes = {};
|
|
240
|
+
for (let block of blocks) {
|
|
241
|
+
const blockmodule = block;
|
|
242
|
+
for (const dep of blockmodule.dependencies) {
|
|
243
|
+
const connection = compilation.moduleGraph.getConnection(dep);
|
|
244
|
+
if (!connection) continue;
|
|
245
|
+
const { module: module$1 } = connection;
|
|
246
|
+
const moduleChunks = compilation.chunkGraph.getModuleChunksIterable(module$1);
|
|
247
|
+
for (let exposedChunk of moduleChunks) {
|
|
248
|
+
const isForThisRuntime = (typeof exposedChunk.runtime === "string" ? new Set([exposedChunk.runtime]) : exposedChunk.runtime).has(containerEntryModule._name);
|
|
249
|
+
const moduleActuallyNeedsChunk = compilation.chunkGraph.getChunkRootModules(exposedChunk).includes(module$1);
|
|
250
|
+
if (!isForThisRuntime || !moduleActuallyNeedsChunk) continue;
|
|
251
|
+
builtExposes[dep.exposedName] = [...builtExposes[dep.exposedName] || [], ...exposedChunk.files || []];
|
|
252
|
+
}
|
|
253
|
+
exposedResolved[dep.exposedName] = module$1;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
const stats = compilation.getStats().toJson({
|
|
257
|
+
all: false,
|
|
258
|
+
assets: true,
|
|
259
|
+
reasons: true,
|
|
260
|
+
modules: true,
|
|
261
|
+
children: true,
|
|
262
|
+
chunkGroups: true,
|
|
263
|
+
chunkModules: true,
|
|
264
|
+
chunkOrigins: false,
|
|
265
|
+
entrypoints: true,
|
|
266
|
+
namedChunkGroups: false,
|
|
267
|
+
chunkRelations: true,
|
|
268
|
+
chunks: true,
|
|
269
|
+
ids: true,
|
|
270
|
+
nestedModules: false,
|
|
271
|
+
outputPath: true,
|
|
272
|
+
publicPath: true
|
|
273
|
+
});
|
|
274
|
+
const federatedModules = getFederationStats(stats, federationOpts);
|
|
275
|
+
federatedModules.exposes = builtExposes;
|
|
276
|
+
const sharedModules = getMainSharedModules(stats);
|
|
277
|
+
const vendorChunks = /* @__PURE__ */ new Set();
|
|
278
|
+
for (const share of sharedModules) if (share?.chunks) for (const file of share.chunks) vendorChunks.add(file);
|
|
279
|
+
const statsResult = {
|
|
280
|
+
sharedModules,
|
|
281
|
+
federatedModules: [federatedModules]
|
|
282
|
+
};
|
|
283
|
+
const statsJson = JSON.stringify(statsResult);
|
|
284
|
+
const statsBuffer = Buffer.from(statsJson, "utf-8");
|
|
285
|
+
const statsSource = {
|
|
286
|
+
source: () => statsBuffer,
|
|
287
|
+
size: () => statsBuffer.length
|
|
288
|
+
};
|
|
289
|
+
const { filename } = this._options;
|
|
290
|
+
if (Array.isArray(filename)) for (const file of filename) if (compilation.getAsset(file)) compilation.updateAsset(file, statsSource);
|
|
291
|
+
else compilation.emitAsset(file, statsSource);
|
|
292
|
+
else if (compilation.getAsset(filename)) compilation.updateAsset(filename, statsSource);
|
|
293
|
+
else compilation.emitAsset(filename, statsSource);
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
module.exports = FederationStatsPlugin;
|
|
299
|
+
}));
|
|
300
|
+
|
|
301
|
+
//#endregion
|
|
302
|
+
export default require_ChunkCorrelationPlugin();
|
|
303
|
+
|
|
304
|
+
export { require_ChunkCorrelationPlugin };
|
|
305
|
+
//# sourceMappingURL=ChunkCorrelationPlugin.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChunkCorrelationPlugin.mjs","names":["module"],"sources":["../../src/plugins/ChunkCorrelationPlugin.js"],"sourcesContent":["const PLUGIN_NAME = 'FederationStatsPlugin';\n\n/** @typedef {import(\"./webpack-stats-types\").WebpackStats} WebpackStats */\n/** @typedef {import( \"./webpack-stats-types\").WebpackStatsChunk} WebpackStatsChunk */\n/** @typedef {import(\"./webpack-stats-types\").WebpackStatsModule} WebpackStatsModule */\n\n/**\n * @typedef {object} SharedDependency\n * @property {string} shareScope\n * @property {string} shareKey\n * @property {string} requiredVersion\n * @property {boolean} strictVersion\n * @property {boolean} singleton\n * @property {boolean} eager\n */\n\n/**\n * @typedef {object} SharedModule\n * @property {string[]} chunks\n * @property {SharedDependency[]} provides\n */\n\n/**\n * @typedef {object} Exposed\n * @property {string[]} chunks\n * @property {SharedModule[]} sharedModules\n */\n\n/**\n * @typedef {object} FederatedContainer\n * @property {string} remote\n * @property {string} entry\n * @property {SharedModule[]} sharedModules\n * @property {{ [key: string]: Exposed }} exposes\n */\n\n/**\n * @typedef {object} FederatedStats\n * @property {SharedModule[]} sharedModules\n * @property {FederatedContainer[]} federatedModules\n */\n\nconst concat = (x, y) => x.concat(y);\n\nconst flatMap = (xs, f) => xs.map(f).reduce(concat, []);\n\n/**\n *\n * @param {WebpackStats} stats\n * @returns {}\n */\nfunction getRemoteModules(stats) {\n return stats.modules\n .filter((mod) => mod.moduleType === 'remote-module')\n .reduce((acc, remoteModule) => {\n acc[remoteModule.nameForCondition] = remoteModule.id;\n return acc;\n }, {});\n}\n\n/**\n *\n * @param {WebpackStats} stats\n * @param {string} exposedFile\n * @returns {WebpackStatsModule[]}\n */\nfunction getExposedModules(stats, exposedFile) {\n return stats.modules.filter((mod) => mod.name?.startsWith(exposedFile));\n}\n//eslint-disable-next-line @typescript-eslint/no-unused-vars\nfunction getDependenciesOfChunk(stats, chunk) {\n return stats.chunks\n .filter((c) => c.children.includes(chunk.id))\n .reduce((acc, c) => {\n return acc.concat(c.modules);\n }, []);\n}\n\n/**\n *\n * @param {WebpackStats} stats\n * @param {WebpackStatsModule} mod\n * @returns {Exposed}\n */\nfunction getExposed(stats, mod) {\n const chunks = stats.chunks.filter((chunk) => {\n return chunk.modules.find((modsInChunk) => {\n return modsInChunk.id === mod.id && !modsInChunk.dependent;\n });\n });\n const dependencies = stats.modules\n .filter((sharedModule) => {\n if (sharedModule.moduleType !== 'consume-shared-module') {\n return false;\n }\n return sharedModule.issuerId === mod.id;\n })\n .map((sharedModule) => {\n return sharedModule.identifier.split('|')[2];\n });\n\n const flatChunks = flatMap(chunks, (chunk) => ({\n [chunk.id]: {\n files: chunk.files.map(\n (f) =>\n `${stats.publicPath === 'auto' ? '' : stats.publicPath || ''}${f}`,\n ),\n requiredModules: dependencies,\n },\n }));\n\n return flatChunks.reduce((acc, chunk) => {\n Object.assign(acc, chunk);\n return acc;\n }, {});\n}\n\n/**\n *\n * @param {import(\"webpack\").Module} mod\n * @param {(issuer: string) => boolean} check\n * @returns {boolean}\n */\nfunction searchIssuer(mod, check) {\n if (mod.issuer && check(mod.issuer)) {\n return true;\n }\n\n return !!mod.modules && mod.modules.some((m) => searchIssuer(m, check));\n}\n\nfunction searchReason(mod, check) {\n if (mod.reasons && check(mod.reasons)) {\n return true;\n }\n\n return !!mod.reasons && mod.reasons.some((m) => searchReason(m, check));\n}\n\nfunction searchIssuerAndReason(mod, check) {\n const foundIssuer = searchIssuer(mod, (issuer) => check(issuer));\n if (foundIssuer) {\n return foundIssuer;\n }\n return searchReason(mod, (reason) =>\n reason.some((r) => check(r?.moduleIdentifier)),\n );\n}\n\n/**\n * @param {import(\"webpack\").Module} mod\n * @param {(issuer: string) => boolean} check\n * @returns {string[]}\n */\nfunction getIssuers(mod, check) {\n if (mod.issuer && check(mod.issuer)) {\n return [mod.issuer];\n }\n\n return (\n (mod.modules &&\n mod.modules.filter((m) => searchIssuer(m, check)).map((m) => m.issuer)) ||\n []\n );\n}\n\nfunction getIssuersAndReasons(mod, check) {\n if (mod.issuer && check(mod.issuer)) {\n return [mod.issuer];\n }\n if (\n mod.reasons &&\n searchReason(mod, (reason) =>\n reason.some((r) => check(r?.moduleIdentifier)),\n )\n ) {\n return mod.reasons\n .filter((r) => {\n return r.moduleIdentifier && check(r.moduleIdentifier);\n })\n .map((r) => r.moduleIdentifier);\n }\n\n return (\n (mod.modules &&\n mod.modules\n .filter((m) => searchIssuerAndReason(m, check))\n .map((m) => {\n return (\n m.issuer ||\n m.reasons.find((r) => check(r?.moduleIdentifier)).moduleIdentifier\n );\n })) ||\n []\n );\n}\n\n/**\n * @param {string} issuer\n * @returns {SharedDependency}\n */\nfunction parseFederatedIssuer(issuer) {\n const split = issuer?.split('|') || [];\n if (split.length !== 8 || split[0] !== 'consume-shared-module') {\n return null;\n }\n const [\n ,\n shareScope,\n shareKey,\n requiredVersion,\n strictVersion,\n ,\n singleton,\n eager,\n ] = split;\n\n return {\n shareScope,\n shareKey,\n requiredVersion,\n strictVersion: JSON.parse(strictVersion),\n singleton: JSON.parse(singleton),\n eager: JSON.parse(eager),\n };\n}\n\n/**\n *\n * @param {WebpackStats} stats\n * @param {import(\"webpack\").container.ModuleFederationPlugin} federationPlugin\n * @returns {SharedModule[]}\n */\nfunction getSharedModules(stats, federationPlugin) {\n return flatMap(\n stats.chunks.filter((chunk) => {\n if (!stats.entrypoints[federationPlugin.name]) {\n return false;\n }\n return stats.entrypoints[federationPlugin.name].chunks.some(\n (id) => chunk.id === id,\n );\n }),\n (chunk) =>\n flatMap(chunk.children, (id) =>\n stats.chunks.filter(\n (c) =>\n c.id === id &&\n c.files.length > 0 &&\n c.parents.some((p) =>\n stats.entrypoints[federationPlugin.name].chunks.some(\n (c) => c === p,\n ),\n ) &&\n c.modules.some((m) =>\n searchIssuer(m, (issuer) =>\n issuer?.startsWith('consume-shared-module'),\n ),\n ),\n ),\n ),\n )\n .map((chunk) => ({\n chunks: chunk.files.map(\n (f) =>\n `${stats.publicPath === 'auto' ? '' : stats.publicPath || ''}${f}`,\n ),\n provides: flatMap(\n chunk.modules.filter((m) =>\n searchIssuer(m, (issuer) =>\n issuer?.startsWith('consume-shared-module'),\n ),\n ),\n (m) =>\n getIssuers(m, (issuer) =>\n issuer?.startsWith('consume-shared-module'),\n ),\n )\n .map(parseFederatedIssuer)\n .filter((f) => !!f),\n }))\n .filter((c) => c.provides.length > 0);\n}\n\n/**\n * @param {WebpackStats} stats\n * @returns {SharedModule[]}\n */\nfunction getMainSharedModules(stats) {\n const chunks = stats.namedChunkGroups['main']\n ? flatMap(stats.namedChunkGroups['main'].chunks, (c) =>\n stats.chunks.filter((chunk) => chunk.id === c),\n )\n : [];\n\n return flatMap(chunks, (chunk) =>\n flatMap(chunk.children, (id) =>\n stats.chunks.filter((c) => {\n return (\n c.id === id &&\n c.files.length > 0 &&\n c.modules.some((m) => {\n return searchIssuerAndReason(m, (check) =>\n check?.startsWith('consume-shared-module'),\n );\n })\n );\n }),\n ),\n )\n .map((chunk) => {\n return {\n chunks: chunk.files.map(\n (f) =>\n `${stats.publicPath === 'auto' ? '' : stats.publicPath || ''}${f}`,\n ),\n provides: flatMap(\n chunk.modules.filter((m) =>\n searchIssuerAndReason(m, (check) =>\n check?.startsWith('consume-shared-module'),\n ),\n ),\n (m) =>\n getIssuersAndReasons(m, (issuer) =>\n issuer?.startsWith('consume-shared-module'),\n ),\n )\n .map(parseFederatedIssuer)\n .filter((f) => !!f),\n };\n })\n .filter((c) => c.provides.length > 0);\n}\n\n/**\n *\n * @param {WebpackStats} stats\n * @param {import(\"webpack\").container.ModuleFederationPlugin} federationPlugin\n * @returns {FederatedStats}\n */\nfunction getFederationStats(stats, federationPluginOptions) {\n const exposedModules = Object.entries(federationPluginOptions.exposes).reduce(\n (exposedModules, [exposedAs, exposedFile]) =>\n Object.assign(exposedModules, {\n [exposedAs]: getExposedModules(stats, exposedFile),\n }),\n {},\n );\n\n /** @type {{ [key: string]: Exposed }} */\n const exposes = Object.entries(exposedModules).reduce(\n (exposedChunks, [exposedAs, exposedModules]) =>\n Object.assign(exposedChunks, {\n [exposedAs]: flatMap(exposedModules, (mod) => getExposed(stats, mod)),\n }),\n {},\n );\n\n /** @type {string} */\n const remote =\n federationPluginOptions.library?.name || federationPluginOptions.name;\n\n const sharedModules = getSharedModules(stats, federationPluginOptions);\n const remoteModules = getRemoteModules(stats);\n return {\n remote,\n entry: `${stats.publicPath === 'auto' ? '' : stats.publicPath || ''}${\n stats.assetsByChunkName[remote] &&\n stats.assetsByChunkName[remote].length === 1\n ? stats.assetsByChunkName[remote][0]\n : federationPluginOptions.filename\n }`,\n sharedModules,\n exposes,\n remoteModules,\n };\n}\n\n/**\n * @typedef {object} FederationStatsPluginOptions\n * @property {string | string[]} filename The filename or an array of filenames in the `output.path` directory to write stats to.\n */\n\n/**\n * Writes relevant federation stats to a file for further consumption.\n */\nclass FederationStatsPlugin {\n /**\n *\n * @param {FederationStatsPluginOptions} options\n */\n constructor(options) {\n if (!options || !options.filename) {\n throw new Error('filename option is required.');\n }\n\n this._options = options;\n }\n\n /**\n *\n * @param {import(\"webpack\").Compiler} compiler\n */\n apply(compiler) {\n const federationPlugins = compiler.options.plugins?.filter(\n (plugin) =>\n [\n 'NextFederationPlugin',\n 'UniversalFederationPlugin',\n 'NodeFederationPlugin',\n 'ModuleFederationPlugin',\n ].includes(plugin.constructor.name) && plugin?._options?.exposes,\n );\n\n if (!federationPlugins || federationPlugins.length === 0) {\n return;\n }\n\n // This is where the plugin is tapping into the Webpack compilation lifecycle.\n // It's listening to the 'thisCompilation' event, which is triggered once for each new compilation.\n compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {\n // 'processAssets' is a hook that gets triggered when Webpack has finished the compilation\n // and is about to generate the final assets. It allows plugins to do additional processing on the assets.\n compilation.hooks.processAssets.tap(\n {\n name: PLUGIN_NAME,\n stage: compilation.constructor.PROCESS_ASSETS_STAGE_REPORT,\n },\n () => {\n // Extract the options from the federation plugins.\n const [federationOpts] = federationPlugins.map(\n (federationPlugin) => federationPlugin?._options,\n );\n\n let container;\n // Loop through all entry points and if one matches the name of a federation plugin,\n // store the entry point in the 'container' variable.\n for (const [name, entry] of compilation.entrypoints) {\n if (container) {\n break;\n }\n federationOpts.name.includes(name) && (container = entry);\n }\n\n // If no matching entry point was found, exit the function early.\n if (!container) {\n return;\n }\n\n // Get the chunk associated with the entry point.\n container = container?.getEntrypointChunk();\n\n // Get the module associated with the chunk.\n const [containerEntryModule] = Array.from(\n compilation.chunkGraph.getChunkEntryModulesIterable(container),\n );\n\n const { blocks } = containerEntryModule;\n\n const exposedResolved = {};\n const builtExposes = {};\n\n // Iterate over each dependency block associated with the entry module.\n for (let block of blocks) {\n const blockmodule = block;\n\n // Iterate over each dependency within the block.\n for (const dep of blockmodule.dependencies) {\n // Get the module that corresponds to the dependency.\n const connection = compilation.moduleGraph.getConnection(dep);\n if (!connection) {\n continue;\n }\n const { module } = connection;\n\n const moduleChunks =\n compilation.chunkGraph.getModuleChunksIterable(module);\n // Iterate over each chunk associated with the module.\n for (let exposedChunk of moduleChunks) {\n // Determine the runtime for the chunk.\n const runtime =\n typeof exposedChunk.runtime === 'string'\n ? new Set([exposedChunk.runtime])\n : exposedChunk.runtime;\n\n // Check if the chunk is meant for the same runtime as the entry module.\n const isForThisRuntime = runtime.has(\n containerEntryModule._name,\n );\n\n // Get the root modules for the chunk.\n const rootModules =\n compilation.chunkGraph.getChunkRootModules(exposedChunk);\n\n // Check if the module associated with the dependency is one of the root modules for the chunk.\n const moduleActuallyNeedsChunk = rootModules.includes(module);\n\n // If the chunk is not meant for this runtime or the module doesn't need the chunk, skip the rest of this iteration.\n if (!isForThisRuntime || !moduleActuallyNeedsChunk) {\n continue;\n }\n\n // Add the files associated with the chunk to the 'builtExposes' object under the name of the exposed module.\n builtExposes[dep.exposedName] = [\n ...(builtExposes[dep.exposedName] || []),\n ...(exposedChunk.files || []),\n ];\n }\n\n // Add the module to the 'exposedResolved' object under the name of the exposed module.\n exposedResolved[dep.exposedName] = module;\n }\n }\n\n // Generate a JSON object that contains detailed information about the compilation.\n const stats = compilation.getStats().toJson({\n all: false,\n assets: true,\n reasons: true,\n modules: true,\n children: true,\n chunkGroups: true,\n chunkModules: true,\n chunkOrigins: false,\n entrypoints: true,\n namedChunkGroups: false,\n chunkRelations: true,\n chunks: true,\n ids: true,\n nestedModules: false,\n outputPath: true,\n publicPath: true,\n });\n\n // Apply a function 'getFederationStats' on the stats with the federation plugin options as the second argument.\n const federatedModules = getFederationStats(stats, federationOpts);\n\n // Assign the 'builtExposes' object to the 'exposes' property of the 'federatedModules' object.\n federatedModules.exposes = builtExposes;\n\n // Apply a function 'getMainSharedModules' on the stats.\n const sharedModules = getMainSharedModules(stats);\n\n // Create a Set to hold the vendor chunks.\n const vendorChunks = new Set();\n\n // Iterate over the shared modules.\n for (const share of sharedModules) {\n if (share?.chunks) {\n // If a shared module has chunks, add them to the 'vendorChunks' Set.\n for (const file of share.chunks) {\n vendorChunks.add(file);\n }\n }\n }\n\n // Construct an object that contains the shared and federated modules.\n const statsResult = {\n sharedModules,\n federatedModules: [federatedModules],\n };\n\n // Convert the 'statsResult' object to a JSON string.\n const statsJson = JSON.stringify(statsResult);\n\n // Convert the JSON string to a buffer.\n const statsBuffer = Buffer.from(statsJson, 'utf-8');\n\n // Construct an object that represents the source of the final asset.\n const statsSource = {\n source: () => statsBuffer,\n size: () => statsBuffer.length,\n };\n\n // Get the filename of the final asset from the plugin options.\n const { filename } = this._options;\n\n // If filename is an array, loop over it to emit or update assets.\n if (Array.isArray(filename)) {\n for (const file of filename) {\n // Check if an asset with the same filename already exists.\n const asset = compilation.getAsset(file);\n\n // If an asset with the same filename already exists, update it. Otherwise, create a new asset.\n if (asset) {\n compilation.updateAsset(file, statsSource);\n } else {\n compilation.emitAsset(file, statsSource);\n }\n }\n } else {\n // Check if an asset with the same filename already exists.\n const asset = compilation.getAsset(filename);\n\n // If an asset with the same filename already exists, update it. Otherwise, create a new asset.\n if (asset) {\n compilation.updateAsset(filename, statsSource);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MAAM,QAAQ,SAKjB,KAHc,YAAY,SAAS,KAAK,CAItC,aAAY,YAAY,MAAM,YAAY;SAE1C,aAAY,UAAU,MAAM,YAAY;cAK9B,YAAY,SAAS,SAAS,CAI1C,aAAY,YAAY,UAAU,YAAY;SAE9C,aAAY,UAAU,UAAU,YAAY;MAInD;KACD;;;AAIN,QAAO,UAAU"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/filesystem/stratagies.d.ts
|
|
2
|
+
declare function fileSystemRunInContextStrategy(chunkId: string, rootOutputDir: string, remotes: Remotes, callback: CallbackFunction): Promise<void>;
|
|
3
|
+
declare function httpEvalStrategy(chunkName: string, remoteName: string, remotes: Remotes, callback: CallbackFunction): Promise<void>;
|
|
4
|
+
interface Remotes {
|
|
5
|
+
[key: string]: {
|
|
6
|
+
entry: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
type CallbackFunction = (error: Error | null, chunk?: any) => void;
|
|
10
|
+
/**
|
|
11
|
+
* HttpVmStrategy
|
|
12
|
+
* This function is used to execute a chunk of code in a VM using HTTP or HTTPS based on the protocol.
|
|
13
|
+
* @param {string} chunkName - The name of the chunk to be executed.
|
|
14
|
+
* @param {string} remoteName - The name of the remote server.
|
|
15
|
+
* @param {Remotes} remotes - An object containing the remote servers.
|
|
16
|
+
* @param {CallbackFunction} callback - A callback function to be executed after the chunk is executed.
|
|
17
|
+
*/
|
|
18
|
+
declare function httpVmStrategy(chunkName: string, remoteName: string, remotes: Remotes, callback: CallbackFunction): Promise<void>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { fileSystemRunInContextStrategy, httpEvalStrategy, httpVmStrategy };
|
|
21
|
+
//# sourceMappingURL=stratagies.d.mts.map
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/filesystem/stratagies.d.ts
|
|
2
|
+
declare function fileSystemRunInContextStrategy(chunkId: string, rootOutputDir: string, remotes: Remotes, callback: CallbackFunction): Promise<void>;
|
|
3
|
+
declare function httpEvalStrategy(chunkName: string, remoteName: string, remotes: Remotes, callback: CallbackFunction): Promise<void>;
|
|
3
4
|
interface Remotes {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
[key: string]: {
|
|
6
|
+
entry: string;
|
|
7
|
+
};
|
|
7
8
|
}
|
|
8
9
|
type CallbackFunction = (error: Error | null, chunk?: any) => void;
|
|
9
10
|
/**
|
|
@@ -14,5 +15,7 @@ type CallbackFunction = (error: Error | null, chunk?: any) => void;
|
|
|
14
15
|
* @param {Remotes} remotes - An object containing the remote servers.
|
|
15
16
|
* @param {CallbackFunction} callback - A callback function to be executed after the chunk is executed.
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
declare function httpVmStrategy(chunkName: string, remoteName: string, remotes: Remotes, callback: CallbackFunction): Promise<void>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { fileSystemRunInContextStrategy, httpEvalStrategy, httpVmStrategy };
|
|
21
|
+
//# sourceMappingURL=stratagies.d.ts.map
|
|
@@ -1,124 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.httpEvalStrategy = httpEvalStrategy;
|
|
5
|
-
exports.httpVmStrategy = httpVmStrategy;
|
|
6
|
-
//@ts-nocheck
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
//#region src/filesystem/stratagies.ts
|
|
7
4
|
async function fileSystemRunInContextStrategy(chunkId, rootOutputDir, remotes, callback) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
callback(e, null);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
const err = new Error(`File ${filename} does not exist`);
|
|
33
|
-
callback(err, null);
|
|
34
|
-
}
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const vm = require("vm");
|
|
8
|
+
const filename = path.join(__dirname, rootOutputDir + __webpack_require__.u(chunkId));
|
|
9
|
+
if (fs.existsSync(filename)) fs.readFile(filename, "utf-8", (err, content) => {
|
|
10
|
+
if (err) {
|
|
11
|
+
callback(err, null);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const chunk = {};
|
|
15
|
+
try {
|
|
16
|
+
vm.runInThisContext("(function(exports, require, __dirname, __filename) {" + content + "\n})", filename)(chunk, require, path.dirname(filename), filename);
|
|
17
|
+
callback(null, chunk);
|
|
18
|
+
} catch (e) {
|
|
19
|
+
console.log("'runInThisContext threw'", e);
|
|
20
|
+
callback(e, null);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
else callback(/* @__PURE__ */ new Error(`File ${filename} does not exist`), null);
|
|
35
24
|
}
|
|
36
|
-
// HttpEvalStrategy
|
|
37
25
|
async function httpEvalStrategy(chunkName, remoteName, remotes, callback) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
callback(e, null);
|
|
61
|
-
}
|
|
26
|
+
let url;
|
|
27
|
+
try {
|
|
28
|
+
url = new URL(chunkName, __webpack_require__.p);
|
|
29
|
+
} catch (e) {
|
|
30
|
+
console.error("module-federation: failed to construct absolute chunk path of", remoteName, "for", chunkName);
|
|
31
|
+
url = new URL(remotes[remoteName]);
|
|
32
|
+
const getBasenameFromUrl = (url) => {
|
|
33
|
+
const urlParts = url.split("/");
|
|
34
|
+
return urlParts[urlParts.length - 1];
|
|
35
|
+
};
|
|
36
|
+
const fileToReplace = getBasenameFromUrl(url.pathname);
|
|
37
|
+
url.pathname = url.pathname.replace(fileToReplace, chunkName);
|
|
38
|
+
}
|
|
39
|
+
const data = await fetch(url).then((res) => res.text());
|
|
40
|
+
const chunk = {};
|
|
41
|
+
try {
|
|
42
|
+
const urlDirname = url.pathname.split("/").slice(0, -1).join("/");
|
|
43
|
+
eval("(function(exports, require, __dirname, __filename) {" + data + "\n})")(chunk, require, urlDirname, chunkName);
|
|
44
|
+
callback(null, chunk);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
callback(e, null);
|
|
47
|
+
}
|
|
62
48
|
}
|
|
63
49
|
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
50
|
+
* HttpVmStrategy
|
|
51
|
+
* This function is used to execute a chunk of code in a VM using HTTP or HTTPS based on the protocol.
|
|
52
|
+
* @param {string} chunkName - The name of the chunk to be executed.
|
|
53
|
+
* @param {string} remoteName - The name of the remote server.
|
|
54
|
+
* @param {Remotes} remotes - An object containing the remote servers.
|
|
55
|
+
* @param {CallbackFunction} callback - A callback function to be executed after the chunk is executed.
|
|
56
|
+
*/
|
|
71
57
|
async function httpVmStrategy(chunkName, remoteName, remotes, callback) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
catch (err) {
|
|
115
|
-
callback(err, null);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
res.on('error', (err) => {
|
|
119
|
-
callback(err, null);
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
req.on('error', (err) => callback(err, null));
|
|
58
|
+
const http = require("http");
|
|
59
|
+
const https = require("https");
|
|
60
|
+
const vm = require("vm");
|
|
61
|
+
const path = require("path");
|
|
62
|
+
let url;
|
|
63
|
+
const globalThisVal = new Function("return globalThis")();
|
|
64
|
+
try {
|
|
65
|
+
url = new URL(chunkName, __webpack_require__.p);
|
|
66
|
+
} catch (e) {
|
|
67
|
+
console.error("module-federation: failed to construct absolute chunk path of", remoteName, "for", chunkName);
|
|
68
|
+
const container = globalThisVal["__FEDERATION__"]["__INSTANCES__"].find((instance) => {
|
|
69
|
+
if (!instance) return;
|
|
70
|
+
if (!instance.moduleCache.has(remoteName)) return;
|
|
71
|
+
const container = instance.moduleCache.get(remoteName);
|
|
72
|
+
if (!container.remoteInfo) return;
|
|
73
|
+
return container.remoteInfo.entry;
|
|
74
|
+
});
|
|
75
|
+
if (!container) throw new Error("Container not found");
|
|
76
|
+
url = new URL(container.moduleCache.get(remoteName).remoteInfo.entry);
|
|
77
|
+
const fileToReplace = path.basename(url.pathname);
|
|
78
|
+
url.pathname = url.pathname.replace(fileToReplace, chunkName);
|
|
79
|
+
}
|
|
80
|
+
(url.protocol === "https:" ? https : http).get(url.href, (res) => {
|
|
81
|
+
let data = "";
|
|
82
|
+
res.on("data", (chunk) => {
|
|
83
|
+
data += chunk.toString();
|
|
84
|
+
});
|
|
85
|
+
res.on("end", () => {
|
|
86
|
+
const chunk = {};
|
|
87
|
+
const urlDirname = url.pathname.split("/").slice(0, -1).join("/");
|
|
88
|
+
try {
|
|
89
|
+
vm.runInThisContext(`(function(exports, require, __dirname, __filename) {${data}\n})`, chunkName)(chunk, require, urlDirname, chunkName);
|
|
90
|
+
callback(null, chunk);
|
|
91
|
+
} catch (err) {
|
|
92
|
+
callback(err, null);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
res.on("error", (err) => {
|
|
96
|
+
callback(err, null);
|
|
97
|
+
});
|
|
98
|
+
}).on("error", (err) => callback(err, null));
|
|
123
99
|
}
|
|
100
|
+
|
|
101
|
+
//#endregion
|
|
102
|
+
exports.fileSystemRunInContextStrategy = fileSystemRunInContextStrategy;
|
|
103
|
+
exports.httpEvalStrategy = httpEvalStrategy;
|
|
104
|
+
exports.httpVmStrategy = httpVmStrategy;
|
|
124
105
|
//# sourceMappingURL=stratagies.js.map
|