@module-federation/manifest 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ManifestManager.js +161 -0
- package/dist/ManifestManager.mjs +100 -0
- package/dist/ModuleHandler.js +512 -0
- package/dist/ModuleHandler.mjs +446 -0
- package/dist/StatsManager.js +514 -0
- package/dist/StatsManager.mjs +456 -0
- package/dist/StatsPlugin.js +171 -0
- package/dist/StatsPlugin.mjs +112 -0
- package/dist/constants.js +54 -0
- package/dist/constants.mjs +6 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +126 -0
- package/dist/index.mjs +18 -0
- package/dist/logger.js +80 -0
- package/dist/logger.mjs +19 -0
- package/dist/types.js +31 -0
- package/dist/types.mjs +4 -0
- package/dist/utils.js +296 -0
- package/dist/utils.mjs +220 -0
- package/package.json +14 -9
- package/dist/index.cjs.js +0 -1225
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.esm.js +0 -1221
- package/dist/index.esm.js.map +0 -1
- package/dist/src/index.d.ts +0 -4
- /package/dist/{src/ManifestManager.d.ts → ManifestManager.d.ts} +0 -0
- /package/dist/{src/ModuleHandler.d.ts → ModuleHandler.d.ts} +0 -0
- /package/dist/{src/StatsManager.d.ts → StatsManager.d.ts} +0 -0
- /package/dist/{src/StatsPlugin.d.ts → StatsPlugin.d.ts} +0 -0
- /package/dist/{src/constants.d.ts → constants.d.ts} +0 -0
- /package/dist/{src/logger.d.ts → logger.d.ts} +0 -0
- /package/dist/{src/types.d.ts → types.d.ts} +0 -0
- /package/dist/{src/utils.d.ts → utils.d.ts} +0 -0
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { MFPrefetchCommon, composeKeyWithSeparator, encodeName, getManifestFileName } from "@module-federation/sdk";
|
|
4
|
+
import { assert, findChunk, getAssetsByChunk, getAssetsByChunkIDs, getFileNameWithOutExt, getSharedModules, getTypesMetaInfo } from "./utils.mjs";
|
|
5
|
+
import logger from "./logger.mjs";
|
|
6
|
+
import { ContainerManager, PKGJsonManager, RemoteManager, SharedManager, UNKNOWN_MODULE_NAME, utils } from "@module-federation/managers";
|
|
7
|
+
import { HOT_UPDATE_SUFFIX } from "./constants.mjs";
|
|
8
|
+
import { ModuleHandler, getExposeItem, getExposeName, getShareItem } from "./ModuleHandler.mjs";
|
|
9
|
+
|
|
10
|
+
;// CONCATENATED MODULE: external "fs"
|
|
11
|
+
|
|
12
|
+
;// CONCATENATED MODULE: external "path"
|
|
13
|
+
|
|
14
|
+
;// CONCATENATED MODULE: external "@module-federation/sdk"
|
|
15
|
+
|
|
16
|
+
;// CONCATENATED MODULE: external "./utils.mjs"
|
|
17
|
+
|
|
18
|
+
;// CONCATENATED MODULE: external "./logger.mjs"
|
|
19
|
+
|
|
20
|
+
;// CONCATENATED MODULE: external "@module-federation/managers"
|
|
21
|
+
|
|
22
|
+
;// CONCATENATED MODULE: external "./constants.mjs"
|
|
23
|
+
|
|
24
|
+
;// CONCATENATED MODULE: external "./ModuleHandler.mjs"
|
|
25
|
+
|
|
26
|
+
;// CONCATENATED MODULE: ./src/StatsManager.ts
|
|
27
|
+
/* eslint-disable max-lines-per-function */ /* eslint-disable @typescript-eslint/member-ordering */ /* eslint-disable max-depth */
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class StatsManager {
|
|
36
|
+
getBuildInfo(context, target) {
|
|
37
|
+
const rootPath = context || process.cwd();
|
|
38
|
+
const pkg = this._pkgJsonManager.readPKGJson(rootPath);
|
|
39
|
+
const statsBuildInfo = {
|
|
40
|
+
buildVersion: utils.getBuildVersion(rootPath),
|
|
41
|
+
buildName: utils.getBuildName() || pkg['name']
|
|
42
|
+
};
|
|
43
|
+
if (this._sharedManager.enableTreeShaking) {
|
|
44
|
+
statsBuildInfo.target = target ? Array.isArray(target) ? target : [
|
|
45
|
+
target
|
|
46
|
+
] : [];
|
|
47
|
+
statsBuildInfo.plugins = this._options.treeShakingSharedPlugins || [];
|
|
48
|
+
statsBuildInfo.excludePlugins = this._options.treeShakingSharedExcludePlugins || [];
|
|
49
|
+
}
|
|
50
|
+
return statsBuildInfo;
|
|
51
|
+
}
|
|
52
|
+
get fileName() {
|
|
53
|
+
return getManifestFileName(this._options.manifest).statsFileName;
|
|
54
|
+
}
|
|
55
|
+
setMetaDataPublicPath(metaData, compiler) {
|
|
56
|
+
if (this._options.getPublicPath) {
|
|
57
|
+
if ('publicPath' in metaData) {
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
delete metaData.publicPath;
|
|
60
|
+
}
|
|
61
|
+
metaData.getPublicPath = this._options.getPublicPath;
|
|
62
|
+
} else {
|
|
63
|
+
metaData.publicPath = this.getPublicPath(compiler);
|
|
64
|
+
}
|
|
65
|
+
return metaData;
|
|
66
|
+
}
|
|
67
|
+
_getMetaData(compiler, compilation, extraOptions) {
|
|
68
|
+
var _this__options_library, _this__options;
|
|
69
|
+
const { context } = compiler.options;
|
|
70
|
+
const { _options: { name } } = this;
|
|
71
|
+
const buildInfo = this.getBuildInfo(context, compilation.options.target || '');
|
|
72
|
+
const type = this._pkgJsonManager.getExposeGarfishModuleType(context || process.cwd());
|
|
73
|
+
const getRemoteEntryName = ()=>{
|
|
74
|
+
if (!this._containerManager.enable) {
|
|
75
|
+
return '';
|
|
76
|
+
}
|
|
77
|
+
assert(name, 'name is required');
|
|
78
|
+
const remoteEntryPoint = compilation.entrypoints.get(name);
|
|
79
|
+
assert(remoteEntryPoint, 'Can not get remoteEntry entryPoint!');
|
|
80
|
+
const remoteEntryNameChunk = compilation.namedChunks.get(name);
|
|
81
|
+
assert(remoteEntryNameChunk, 'Can not get remoteEntry chunk!');
|
|
82
|
+
const files = Array.from(remoteEntryNameChunk.files).filter((f)=>!f.includes(HOT_UPDATE_SUFFIX) && !f.endsWith('.css'));
|
|
83
|
+
assert(files.length > 0, 'no files found for remoteEntry chunk');
|
|
84
|
+
assert(files.length === 1, `remoteEntry chunk should not have multiple files!, current files: ${files.join(',')}`);
|
|
85
|
+
const remoteEntryName = files[0];
|
|
86
|
+
return remoteEntryName;
|
|
87
|
+
};
|
|
88
|
+
const globalName = this._containerManager.globalEntryName;
|
|
89
|
+
assert(globalName, 'Can not get library.name, please ensure you have set library.name and the type is "string" !');
|
|
90
|
+
assert(this._pluginVersion, 'Can not get pluginVersion, please ensure you have set pluginVersion !');
|
|
91
|
+
const metaData = {
|
|
92
|
+
name: name,
|
|
93
|
+
type,
|
|
94
|
+
buildInfo,
|
|
95
|
+
remoteEntry: {
|
|
96
|
+
name: getRemoteEntryName(),
|
|
97
|
+
path: '',
|
|
98
|
+
// same as the types supported by runtime, currently only global/var/script is supported
|
|
99
|
+
type: ((_this__options = this._options) === null || _this__options === void 0 ? void 0 : (_this__options_library = _this__options.library) === null || _this__options_library === void 0 ? void 0 : _this__options_library.type) || 'global'
|
|
100
|
+
},
|
|
101
|
+
types: getTypesMetaInfo(this._options, compiler.context),
|
|
102
|
+
globalName: globalName,
|
|
103
|
+
pluginVersion: this._pluginVersion
|
|
104
|
+
};
|
|
105
|
+
let prefetchInterface = false;
|
|
106
|
+
const prefetchFilePath = path.resolve(compiler.options.context || process.cwd(), `node_modules/.mf/${encodeName(name)}/${MFPrefetchCommon.fileName}`);
|
|
107
|
+
const existPrefetch = fs.existsSync(prefetchFilePath);
|
|
108
|
+
if (existPrefetch) {
|
|
109
|
+
const content = fs.readFileSync(prefetchFilePath).toString();
|
|
110
|
+
if (content) {
|
|
111
|
+
prefetchInterface = true;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
metaData.prefetchInterface = prefetchInterface;
|
|
115
|
+
return this.setMetaDataPublicPath(metaData, compiler);
|
|
116
|
+
}
|
|
117
|
+
_getFilteredModules(stats) {
|
|
118
|
+
const filteredModules = stats.modules.filter((module)=>{
|
|
119
|
+
if (!module || !module.name) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
const array = [
|
|
123
|
+
module.name.includes('container entry'),
|
|
124
|
+
module.name.includes('remote '),
|
|
125
|
+
module.name.includes('shared module '),
|
|
126
|
+
module.name.includes('provide module ')
|
|
127
|
+
];
|
|
128
|
+
return array.some((item)=>item);
|
|
129
|
+
});
|
|
130
|
+
return filteredModules;
|
|
131
|
+
}
|
|
132
|
+
_getModuleAssets(compilation, entryPointNames) {
|
|
133
|
+
const { chunks } = compilation;
|
|
134
|
+
const { exposeFileNameImportMap } = this._containerManager;
|
|
135
|
+
const assets = {};
|
|
136
|
+
chunks.forEach((chunk)=>{
|
|
137
|
+
if (typeof chunk.name === 'string' && exposeFileNameImportMap[chunk.name]) {
|
|
138
|
+
// TODO: support multiple import
|
|
139
|
+
const exposeKey = exposeFileNameImportMap[chunk.name][0];
|
|
140
|
+
assets[getFileNameWithOutExt(exposeKey)] = getAssetsByChunk(chunk, entryPointNames);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return assets;
|
|
144
|
+
}
|
|
145
|
+
_getProvideSharedAssets(compilation, stats, entryPointNames) {
|
|
146
|
+
const sharedModules = stats.modules.filter((module)=>{
|
|
147
|
+
if (!module || !module.name) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
const array = [
|
|
151
|
+
module.name.includes('consume shared module ')
|
|
152
|
+
];
|
|
153
|
+
return array.some((item)=>item);
|
|
154
|
+
});
|
|
155
|
+
const manifestOverrideChunkIDMap = {};
|
|
156
|
+
const effectiveSharedModules = getSharedModules(stats, sharedModules);
|
|
157
|
+
effectiveSharedModules.forEach((item)=>{
|
|
158
|
+
const [sharedModuleName, sharedModule] = item;
|
|
159
|
+
if (!manifestOverrideChunkIDMap[sharedModuleName]) {
|
|
160
|
+
manifestOverrideChunkIDMap[sharedModuleName] = {
|
|
161
|
+
async: new Set(),
|
|
162
|
+
sync: new Set()
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
sharedModule.chunks.forEach((chunkID)=>{
|
|
166
|
+
const chunk = findChunk(chunkID, compilation.chunks);
|
|
167
|
+
manifestOverrideChunkIDMap[sharedModuleName].sync.add(chunkID);
|
|
168
|
+
if (!chunk) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
[
|
|
172
|
+
...chunk.groupsIterable
|
|
173
|
+
].forEach((group)=>{
|
|
174
|
+
if (group.name && !entryPointNames.includes(group.name)) {
|
|
175
|
+
manifestOverrideChunkIDMap[sharedModuleName].sync.add(group.id);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
const assets = {
|
|
181
|
+
js: {
|
|
182
|
+
async: [],
|
|
183
|
+
sync: []
|
|
184
|
+
},
|
|
185
|
+
css: {
|
|
186
|
+
async: [],
|
|
187
|
+
sync: []
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
Object.keys(manifestOverrideChunkIDMap).forEach((override)=>{
|
|
191
|
+
const asyncAssets = getAssetsByChunkIDs(compilation, {
|
|
192
|
+
[override]: manifestOverrideChunkIDMap[override].async
|
|
193
|
+
});
|
|
194
|
+
const syncAssets = getAssetsByChunkIDs(compilation, {
|
|
195
|
+
[override]: manifestOverrideChunkIDMap[override].sync
|
|
196
|
+
});
|
|
197
|
+
assets[override] = {
|
|
198
|
+
js: {
|
|
199
|
+
async: asyncAssets[override].js,
|
|
200
|
+
sync: syncAssets[override].js
|
|
201
|
+
},
|
|
202
|
+
css: {
|
|
203
|
+
async: asyncAssets[override].css,
|
|
204
|
+
sync: syncAssets[override].css
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
});
|
|
208
|
+
return assets;
|
|
209
|
+
}
|
|
210
|
+
async _generateStats(compiler, compilation, extraOptions) {
|
|
211
|
+
try {
|
|
212
|
+
const { name, manifest: manifestOptions = {}, exposes = {} } = this._options;
|
|
213
|
+
const metaData = this._getMetaData(compiler, compilation, extraOptions);
|
|
214
|
+
const stats = {
|
|
215
|
+
id: name,
|
|
216
|
+
name: name,
|
|
217
|
+
metaData,
|
|
218
|
+
shared: [],
|
|
219
|
+
remotes: [],
|
|
220
|
+
exposes: []
|
|
221
|
+
};
|
|
222
|
+
if (typeof manifestOptions === 'object' && manifestOptions.disableAssetsAnalyze) {
|
|
223
|
+
const remotes = this._remoteManager.statsRemoteWithEmptyUsedIn;
|
|
224
|
+
stats.remotes = remotes;
|
|
225
|
+
stats.exposes = Object.keys(exposes).map((exposeKey)=>{
|
|
226
|
+
return getExposeItem({
|
|
227
|
+
exposeKey,
|
|
228
|
+
name: name,
|
|
229
|
+
file: {
|
|
230
|
+
import: exposes[exposeKey].import
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
stats.shared = Object.entries(this._sharedManager.normalizedOptions).reduce((sum, cur)=>{
|
|
235
|
+
const [pkgName, normalizedShareOptions] = cur;
|
|
236
|
+
sum.push(getShareItem({
|
|
237
|
+
pkgName,
|
|
238
|
+
normalizedShareOptions,
|
|
239
|
+
pkgVersion: normalizedShareOptions.version || UNKNOWN_MODULE_NAME,
|
|
240
|
+
hostName: name
|
|
241
|
+
}));
|
|
242
|
+
return sum;
|
|
243
|
+
}, []);
|
|
244
|
+
return stats;
|
|
245
|
+
}
|
|
246
|
+
const liveStats = compilation.getStats();
|
|
247
|
+
const statsOptions = {
|
|
248
|
+
all: false,
|
|
249
|
+
modules: true,
|
|
250
|
+
builtAt: true,
|
|
251
|
+
hash: true,
|
|
252
|
+
ids: true,
|
|
253
|
+
version: true,
|
|
254
|
+
entrypoints: true,
|
|
255
|
+
assets: false,
|
|
256
|
+
chunks: false,
|
|
257
|
+
reasons: true
|
|
258
|
+
};
|
|
259
|
+
if (this._bundler === 'webpack') {
|
|
260
|
+
statsOptions['cached'] = true;
|
|
261
|
+
}
|
|
262
|
+
statsOptions['cachedModules'] = true;
|
|
263
|
+
const webpackStats = liveStats.toJson(statsOptions);
|
|
264
|
+
const filteredModules = this._getFilteredModules(webpackStats);
|
|
265
|
+
const moduleHandler = new ModuleHandler(this._options, filteredModules, {
|
|
266
|
+
bundler: this._bundler
|
|
267
|
+
});
|
|
268
|
+
const { remotes, exposesMap, sharedMap } = moduleHandler.collect();
|
|
269
|
+
const entryPointNames = [
|
|
270
|
+
...compilation.entrypoints.values()
|
|
271
|
+
].map((e)=>e.name).filter((v)=>!!v);
|
|
272
|
+
await Promise.all([
|
|
273
|
+
new Promise((resolve)=>{
|
|
274
|
+
const sharedAssets = this._getProvideSharedAssets(compilation, webpackStats, entryPointNames);
|
|
275
|
+
Object.keys(sharedMap).forEach((sharedKey)=>{
|
|
276
|
+
const assets = sharedAssets[sharedKey];
|
|
277
|
+
if (assets) {
|
|
278
|
+
sharedMap[sharedKey].assets = assets;
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
resolve();
|
|
282
|
+
}),
|
|
283
|
+
new Promise((resolve)=>{
|
|
284
|
+
const moduleAssets = this._getModuleAssets(compilation, entryPointNames);
|
|
285
|
+
Object.keys(exposesMap).forEach((exposeKey)=>{
|
|
286
|
+
const assets = moduleAssets[exposeKey];
|
|
287
|
+
if (assets) {
|
|
288
|
+
exposesMap[exposeKey].assets = assets;
|
|
289
|
+
}
|
|
290
|
+
exposesMap[exposeKey].requires = Array.from(new Set(exposesMap[exposeKey].requires));
|
|
291
|
+
});
|
|
292
|
+
resolve();
|
|
293
|
+
})
|
|
294
|
+
]);
|
|
295
|
+
await Promise.all([
|
|
296
|
+
new Promise((resolve)=>{
|
|
297
|
+
const remoteMemo = new Set();
|
|
298
|
+
stats.remotes = remotes.map((remote)=>{
|
|
299
|
+
remoteMemo.add(remote.federationContainerName);
|
|
300
|
+
return {
|
|
301
|
+
...remote,
|
|
302
|
+
usedIn: Array.from(remote.usedIn.values())
|
|
303
|
+
};
|
|
304
|
+
});
|
|
305
|
+
const statsRemoteWithEmptyUsedIn = this._remoteManager.statsRemoteWithEmptyUsedIn;
|
|
306
|
+
statsRemoteWithEmptyUsedIn.forEach((remoteInfo)=>{
|
|
307
|
+
if (!remoteMemo.has(remoteInfo.federationContainerName)) {
|
|
308
|
+
stats.remotes.push(remoteInfo);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
resolve();
|
|
312
|
+
}),
|
|
313
|
+
new Promise((resolve)=>{
|
|
314
|
+
stats.shared = Object.values(sharedMap).map((shared)=>({
|
|
315
|
+
...shared,
|
|
316
|
+
usedIn: Array.from(shared.usedIn)
|
|
317
|
+
}));
|
|
318
|
+
resolve();
|
|
319
|
+
})
|
|
320
|
+
]);
|
|
321
|
+
await new Promise((resolve)=>{
|
|
322
|
+
const sharedAssets = stats.shared.reduce((sum, shared)=>{
|
|
323
|
+
const { js, css } = shared.assets;
|
|
324
|
+
[
|
|
325
|
+
...js.sync,
|
|
326
|
+
...js.async,
|
|
327
|
+
...css.async,
|
|
328
|
+
css.sync
|
|
329
|
+
].forEach((asset)=>{
|
|
330
|
+
sum.add(asset);
|
|
331
|
+
});
|
|
332
|
+
return sum;
|
|
333
|
+
}, new Set());
|
|
334
|
+
const { fileExposeKeyMap } = this._containerManager;
|
|
335
|
+
stats.exposes = [];
|
|
336
|
+
Object.entries(fileExposeKeyMap).forEach(([exposeFileWithoutExt, exposeKeySet])=>{
|
|
337
|
+
const expose = exposesMap[exposeFileWithoutExt] || {
|
|
338
|
+
assets: {
|
|
339
|
+
js: {
|
|
340
|
+
sync: [],
|
|
341
|
+
async: []
|
|
342
|
+
},
|
|
343
|
+
css: {
|
|
344
|
+
sync: [],
|
|
345
|
+
async: []
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
exposeKeySet.forEach((exposeKey)=>{
|
|
350
|
+
const { js, css } = expose.assets;
|
|
351
|
+
const exposeModuleName = getExposeName(exposeKey);
|
|
352
|
+
stats.exposes.push({
|
|
353
|
+
...expose,
|
|
354
|
+
path: exposeKey,
|
|
355
|
+
id: composeKeyWithSeparator(this._options.name, exposeModuleName),
|
|
356
|
+
name: exposeModuleName,
|
|
357
|
+
assets: {
|
|
358
|
+
js: {
|
|
359
|
+
sync: js.sync.filter((asset)=>!sharedAssets.has(asset)),
|
|
360
|
+
async: js.async.filter((asset)=>!sharedAssets.has(asset))
|
|
361
|
+
},
|
|
362
|
+
css: {
|
|
363
|
+
sync: css.sync.filter((asset)=>!sharedAssets.has(asset)),
|
|
364
|
+
async: css.async.filter((asset)=>!sharedAssets.has(asset))
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
Object.values(exposesMap).map((expose)=>{
|
|
371
|
+
const { js, css } = expose.assets;
|
|
372
|
+
return {
|
|
373
|
+
...expose,
|
|
374
|
+
assets: {
|
|
375
|
+
js: {
|
|
376
|
+
sync: js.sync.filter((asset)=>!sharedAssets.has(asset)),
|
|
377
|
+
async: js.async.filter((asset)=>!sharedAssets.has(asset))
|
|
378
|
+
},
|
|
379
|
+
css: {
|
|
380
|
+
sync: css.sync.filter((asset)=>!sharedAssets.has(asset)),
|
|
381
|
+
async: css.async.filter((asset)=>!sharedAssets.has(asset))
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
});
|
|
386
|
+
resolve();
|
|
387
|
+
});
|
|
388
|
+
return stats;
|
|
389
|
+
} catch (err) {
|
|
390
|
+
throw err;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
getPublicPath(compiler) {
|
|
394
|
+
if (this._publicPath) {
|
|
395
|
+
return this._publicPath;
|
|
396
|
+
}
|
|
397
|
+
const { output: { publicPath: originalPublicPath } } = compiler.options;
|
|
398
|
+
let publicPath = originalPublicPath;
|
|
399
|
+
this._publicPath = publicPath;
|
|
400
|
+
return publicPath;
|
|
401
|
+
}
|
|
402
|
+
init(options, { pluginVersion, bundler }) {
|
|
403
|
+
this._options = options;
|
|
404
|
+
this._pluginVersion = pluginVersion;
|
|
405
|
+
this._bundler = bundler;
|
|
406
|
+
this._containerManager = new ContainerManager();
|
|
407
|
+
this._containerManager.init(options);
|
|
408
|
+
this._remoteManager = new RemoteManager();
|
|
409
|
+
this._remoteManager.init(options);
|
|
410
|
+
this._sharedManager = new SharedManager();
|
|
411
|
+
this._sharedManager.init(options);
|
|
412
|
+
}
|
|
413
|
+
updateStats(stats, compiler) {
|
|
414
|
+
const { metaData } = stats;
|
|
415
|
+
if (!metaData.types) {
|
|
416
|
+
metaData.types = getTypesMetaInfo(this._options, compiler.context);
|
|
417
|
+
}
|
|
418
|
+
if (!metaData.pluginVersion) {
|
|
419
|
+
metaData.pluginVersion = this._pluginVersion;
|
|
420
|
+
}
|
|
421
|
+
this.setMetaDataPublicPath(metaData, compiler);
|
|
422
|
+
// rspack not support legacy prefetch, and this field should be removed in the future
|
|
423
|
+
metaData.prefetchInterface = false;
|
|
424
|
+
return stats;
|
|
425
|
+
}
|
|
426
|
+
async generateStats(compiler, compilation) {
|
|
427
|
+
try {
|
|
428
|
+
const stats = await this._generateStats(compiler, compilation);
|
|
429
|
+
return stats;
|
|
430
|
+
} catch (err) {
|
|
431
|
+
throw err;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
validate(compiler) {
|
|
435
|
+
const { output: { publicPath } } = compiler.options;
|
|
436
|
+
if (typeof publicPath !== 'string') {
|
|
437
|
+
logger.warn(`Manifest will not generate, because publicPath can only be string, but got '${publicPath}'`);
|
|
438
|
+
return false;
|
|
439
|
+
} else if (publicPath === 'auto') {
|
|
440
|
+
logger.warn(`Manifest will use absolute path resolution via its host at runtime, reason: publicPath='${publicPath}'`);
|
|
441
|
+
return true;
|
|
442
|
+
}
|
|
443
|
+
return true;
|
|
444
|
+
}
|
|
445
|
+
constructor(){
|
|
446
|
+
this._options = {};
|
|
447
|
+
this._bundler = 'webpack';
|
|
448
|
+
this._containerManager = new ContainerManager();
|
|
449
|
+
this._remoteManager = new RemoteManager();
|
|
450
|
+
this._sharedManager = new SharedManager();
|
|
451
|
+
this._pkgJsonManager = new PKGJsonManager();
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
export { StatsManager };
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
3
|
+
return typeof document === 'undefined'
|
|
4
|
+
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
5
|
+
: (document.currentScript && document.currentScript.src) ||
|
|
6
|
+
new URL('main.js', document.baseURI).href;
|
|
7
|
+
})();
|
|
8
|
+
;
|
|
9
|
+
// The require scope
|
|
10
|
+
var __webpack_require__ = {};
|
|
11
|
+
|
|
12
|
+
/************************************************************************/
|
|
13
|
+
// webpack/runtime/compat_get_default_export
|
|
14
|
+
(() => {
|
|
15
|
+
// getDefaultExport function for compatibility with non-ESM modules
|
|
16
|
+
__webpack_require__.n = (module) => {
|
|
17
|
+
var getter = module && module.__esModule ?
|
|
18
|
+
() => (module['default']) :
|
|
19
|
+
() => (module);
|
|
20
|
+
__webpack_require__.d(getter, { a: getter });
|
|
21
|
+
return getter;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
})();
|
|
25
|
+
// webpack/runtime/define_property_getters
|
|
26
|
+
(() => {
|
|
27
|
+
__webpack_require__.d = (exports, definition) => {
|
|
28
|
+
for(var key in definition) {
|
|
29
|
+
if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
30
|
+
Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
// webpack/runtime/has_own_property
|
|
36
|
+
(() => {
|
|
37
|
+
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
38
|
+
})();
|
|
39
|
+
// webpack/runtime/make_namespace_object
|
|
40
|
+
(() => {
|
|
41
|
+
// define __esModule on exports
|
|
42
|
+
__webpack_require__.r = (exports) => {
|
|
43
|
+
if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
44
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
45
|
+
}
|
|
46
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
47
|
+
};
|
|
48
|
+
})();
|
|
49
|
+
/************************************************************************/
|
|
50
|
+
var __webpack_exports__ = {};
|
|
51
|
+
// ESM COMPAT FLAG
|
|
52
|
+
__webpack_require__.r(__webpack_exports__);
|
|
53
|
+
|
|
54
|
+
// EXPORTS
|
|
55
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
56
|
+
StatsPlugin: () => (/* binding */ StatsPlugin)
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
;// CONCATENATED MODULE: external "@module-federation/sdk"
|
|
60
|
+
const sdk_namespaceObject = require("@module-federation/sdk");
|
|
61
|
+
;// CONCATENATED MODULE: external "./ManifestManager.js"
|
|
62
|
+
const external_ManifestManager_js_namespaceObject = require("./ManifestManager.js");
|
|
63
|
+
;// CONCATENATED MODULE: external "./StatsManager.js"
|
|
64
|
+
const external_StatsManager_js_namespaceObject = require("./StatsManager.js");
|
|
65
|
+
;// CONCATENATED MODULE: external "./constants.js"
|
|
66
|
+
const external_constants_js_namespaceObject = require("./constants.js");
|
|
67
|
+
;// CONCATENATED MODULE: external "./logger.js"
|
|
68
|
+
const external_logger_js_namespaceObject = require("./logger.js");
|
|
69
|
+
var external_logger_js_default = /*#__PURE__*/__webpack_require__.n(external_logger_js_namespaceObject);
|
|
70
|
+
;// CONCATENATED MODULE: ./src/StatsPlugin.ts
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class StatsPlugin {
|
|
77
|
+
apply(compiler) {
|
|
78
|
+
(0,sdk_namespaceObject.bindLoggerToCompiler)((external_logger_js_default()), compiler, external_constants_js_namespaceObject.PLUGIN_IDENTIFIER);
|
|
79
|
+
if (!this._enable) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const res = this._statsManager.validate(compiler);
|
|
83
|
+
if (!res) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
compiler.hooks.thisCompilation.tap('generateStats', (compilation)=>{
|
|
87
|
+
compilation.hooks.processAssets.tapPromise({
|
|
88
|
+
name: 'generateStats',
|
|
89
|
+
// @ts-ignore use runtime variable in case peer dep not installed
|
|
90
|
+
stage: compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
|
|
91
|
+
}, async ()=>{
|
|
92
|
+
if (this._options.manifest !== false) {
|
|
93
|
+
const existedStats = compilation.getAsset(this._statsManager.fileName);
|
|
94
|
+
// new rspack should hit
|
|
95
|
+
if (existedStats) {
|
|
96
|
+
let updatedStats = this._statsManager.updateStats(JSON.parse(existedStats.source.source().toString()), compiler);
|
|
97
|
+
if (typeof this._options.manifest === 'object' && this._options.manifest.additionalData) {
|
|
98
|
+
updatedStats = await this._options.manifest.additionalData({
|
|
99
|
+
stats: updatedStats,
|
|
100
|
+
compiler,
|
|
101
|
+
compilation,
|
|
102
|
+
bundler: this._bundler
|
|
103
|
+
}) || updatedStats;
|
|
104
|
+
}
|
|
105
|
+
compilation.updateAsset(this._statsManager.fileName, new compiler.webpack.sources.RawSource(JSON.stringify(updatedStats, null, 2)));
|
|
106
|
+
const updatedManifest = this._manifestManager.updateManifest({
|
|
107
|
+
compilation,
|
|
108
|
+
stats: updatedStats,
|
|
109
|
+
publicPath: this._statsManager.getPublicPath(compiler),
|
|
110
|
+
compiler,
|
|
111
|
+
bundler: this._bundler
|
|
112
|
+
});
|
|
113
|
+
const source = new compiler.webpack.sources.RawSource(JSON.stringify(updatedManifest, null, 2));
|
|
114
|
+
compilation.updateAsset(this._manifestManager.fileName, source);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
// webpack + legacy rspack
|
|
118
|
+
let stats = await this._statsManager.generateStats(compiler, compilation);
|
|
119
|
+
if (typeof this._options.manifest === 'object' && this._options.manifest.additionalData) {
|
|
120
|
+
stats = await this._options.manifest.additionalData({
|
|
121
|
+
stats,
|
|
122
|
+
compiler,
|
|
123
|
+
compilation,
|
|
124
|
+
bundler: this._bundler
|
|
125
|
+
}) || stats;
|
|
126
|
+
}
|
|
127
|
+
const manifest = await this._manifestManager.generateManifest({
|
|
128
|
+
compilation,
|
|
129
|
+
stats: stats,
|
|
130
|
+
publicPath: this._statsManager.getPublicPath(compiler),
|
|
131
|
+
compiler,
|
|
132
|
+
bundler: this._bundler
|
|
133
|
+
});
|
|
134
|
+
compilation.emitAsset(this._statsManager.fileName, new compiler.webpack.sources.RawSource(JSON.stringify(stats, null, 2)));
|
|
135
|
+
compilation.emitAsset(this._manifestManager.fileName, new compiler.webpack.sources.RawSource(JSON.stringify(manifest, null, 2)));
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
constructor(options, { pluginVersion, bundler }){
|
|
141
|
+
this.name = 'StatsPlugin';
|
|
142
|
+
this._options = {};
|
|
143
|
+
this._statsManager = new external_StatsManager_js_namespaceObject.StatsManager();
|
|
144
|
+
this._manifestManager = new external_ManifestManager_js_namespaceObject.ManifestManager();
|
|
145
|
+
this._enable = true;
|
|
146
|
+
this._bundler = 'webpack';
|
|
147
|
+
try {
|
|
148
|
+
this._options = options;
|
|
149
|
+
this._bundler = bundler;
|
|
150
|
+
this._statsManager.init(this._options, {
|
|
151
|
+
pluginVersion,
|
|
152
|
+
bundler
|
|
153
|
+
});
|
|
154
|
+
this._manifestManager.init(this._options);
|
|
155
|
+
} catch (err) {
|
|
156
|
+
if (err instanceof Error) {
|
|
157
|
+
err.message = `[ ${external_constants_js_namespaceObject.PLUGIN_IDENTIFIER} ]: Manifest will not generate, because: ${err.message}`;
|
|
158
|
+
}
|
|
159
|
+
external_logger_js_default().error(err);
|
|
160
|
+
this._enable = false;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
exports.StatsPlugin = __webpack_exports__.StatsPlugin;
|
|
166
|
+
for(var __webpack_i__ in __webpack_exports__) {
|
|
167
|
+
if(["StatsPlugin"].indexOf(__webpack_i__) === -1) {
|
|
168
|
+
exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|