@depup/module-federation__manifest 2.2.2-depup.0

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.
@@ -0,0 +1,555 @@
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
+ StatsManager: () => (/* binding */ StatsManager)
57
+ });
58
+
59
+ ;// CONCATENATED MODULE: external "fs"
60
+ const external_fs_namespaceObject = require("fs");
61
+ var external_fs_default = /*#__PURE__*/__webpack_require__.n(external_fs_namespaceObject);
62
+ ;// CONCATENATED MODULE: external "path"
63
+ const external_path_namespaceObject = require("path");
64
+ var external_path_default = /*#__PURE__*/__webpack_require__.n(external_path_namespaceObject);
65
+ ;// CONCATENATED MODULE: external "@module-federation/sdk"
66
+ const sdk_namespaceObject = require("@module-federation/sdk");
67
+ ;// CONCATENATED MODULE: external "./utils.js"
68
+ const external_utils_js_namespaceObject = require("./utils.js");
69
+ ;// CONCATENATED MODULE: external "./logger.js"
70
+ const external_logger_js_namespaceObject = require("./logger.js");
71
+ var external_logger_js_default = /*#__PURE__*/__webpack_require__.n(external_logger_js_namespaceObject);
72
+ ;// CONCATENATED MODULE: external "@module-federation/managers"
73
+ const managers_namespaceObject = require("@module-federation/managers");
74
+ ;// CONCATENATED MODULE: external "./constants.js"
75
+ const external_constants_js_namespaceObject = require("./constants.js");
76
+ ;// CONCATENATED MODULE: external "./ModuleHandler.js"
77
+ const external_ModuleHandler_js_namespaceObject = require("./ModuleHandler.js");
78
+ ;// CONCATENATED MODULE: ./src/StatsManager.ts
79
+ /* eslint-disable max-lines-per-function */ /* eslint-disable @typescript-eslint/member-ordering */ /* eslint-disable max-depth */
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+ class StatsManager {
88
+ getBuildInfo(context, target) {
89
+ const rootPath = context || process.cwd();
90
+ const pkg = this._pkgJsonManager.readPKGJson(rootPath);
91
+ const statsBuildInfo = {
92
+ buildVersion: managers_namespaceObject.utils.getBuildVersion(rootPath),
93
+ buildName: managers_namespaceObject.utils.getBuildName() || pkg['name']
94
+ };
95
+ if (this._sharedManager.enableTreeShaking) {
96
+ statsBuildInfo.target = target ? Array.isArray(target) ? target : [
97
+ target
98
+ ] : [];
99
+ statsBuildInfo.plugins = this._options.treeShakingSharedPlugins || [];
100
+ statsBuildInfo.excludePlugins = this._options.treeShakingSharedExcludePlugins || [];
101
+ }
102
+ return statsBuildInfo;
103
+ }
104
+ get fileName() {
105
+ return (0,sdk_namespaceObject.getManifestFileName)(this._options.manifest).statsFileName;
106
+ }
107
+ setMetaDataPublicPath(metaData, compiler) {
108
+ if (this._options.getPublicPath) {
109
+ if ('publicPath' in metaData) {
110
+ // @ts-ignore
111
+ delete metaData.publicPath;
112
+ }
113
+ metaData.getPublicPath = this._options.getPublicPath;
114
+ } else {
115
+ metaData.publicPath = this.getPublicPath(compiler);
116
+ }
117
+ return metaData;
118
+ }
119
+ _getMetaData(compiler, compilation, extraOptions) {
120
+ var _this__options_library, _this__options;
121
+ const { context } = compiler.options;
122
+ const { _options: { name } } = this;
123
+ const buildInfo = this.getBuildInfo(context, compilation.options.target || '');
124
+ const type = this._pkgJsonManager.getExposeGarfishModuleType(context || process.cwd());
125
+ const getRemoteEntryName = ()=>{
126
+ if (!this._containerManager.enable) {
127
+ return '';
128
+ }
129
+ (0,external_utils_js_namespaceObject.assert)(name, 'name is required');
130
+ const remoteEntryPoint = compilation.entrypoints.get(name);
131
+ (0,external_utils_js_namespaceObject.assert)(remoteEntryPoint, 'Can not get remoteEntry entryPoint!');
132
+ const remoteEntryNameChunk = compilation.namedChunks.get(name);
133
+ (0,external_utils_js_namespaceObject.assert)(remoteEntryNameChunk, 'Can not get remoteEntry chunk!');
134
+ const files = Array.from(remoteEntryNameChunk.files).filter((f)=>!f.includes(external_constants_js_namespaceObject.HOT_UPDATE_SUFFIX) && !f.endsWith('.css'));
135
+ (0,external_utils_js_namespaceObject.assert)(files.length > 0, 'no files found for remoteEntry chunk');
136
+ (0,external_utils_js_namespaceObject.assert)(files.length === 1, `remoteEntry chunk should not have multiple files!, current files: ${files.join(',')}`);
137
+ const remoteEntryName = files[0];
138
+ return remoteEntryName;
139
+ };
140
+ const globalName = this._containerManager.globalEntryName;
141
+ (0,external_utils_js_namespaceObject.assert)(globalName, 'Can not get library.name, please ensure you have set library.name and the type is "string" !');
142
+ (0,external_utils_js_namespaceObject.assert)(this._pluginVersion, 'Can not get pluginVersion, please ensure you have set pluginVersion !');
143
+ const metaData = {
144
+ name: name,
145
+ type,
146
+ buildInfo,
147
+ remoteEntry: {
148
+ name: getRemoteEntryName(),
149
+ path: '',
150
+ // same as the types supported by runtime, currently only global/var/script is supported
151
+ 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'
152
+ },
153
+ types: (0,external_utils_js_namespaceObject.getTypesMetaInfo)(this._options, compiler.context),
154
+ globalName: globalName,
155
+ pluginVersion: this._pluginVersion
156
+ };
157
+ let prefetchInterface = false;
158
+ const prefetchFilePath = external_path_default().resolve(compiler.options.context || process.cwd(), `node_modules/.mf/${(0,sdk_namespaceObject.encodeName)(name)}/${sdk_namespaceObject.MFPrefetchCommon.fileName}`);
159
+ const existPrefetch = external_fs_default().existsSync(prefetchFilePath);
160
+ if (existPrefetch) {
161
+ const content = external_fs_default().readFileSync(prefetchFilePath).toString();
162
+ if (content) {
163
+ prefetchInterface = true;
164
+ }
165
+ }
166
+ metaData.prefetchInterface = prefetchInterface;
167
+ return this.setMetaDataPublicPath(metaData, compiler);
168
+ }
169
+ _getFilteredModules(stats) {
170
+ const filteredModules = stats.modules.filter((module)=>{
171
+ if (!module || !module.name) {
172
+ return false;
173
+ }
174
+ const array = [
175
+ module.name.includes('container entry'),
176
+ module.name.includes('remote '),
177
+ module.name.includes('shared module '),
178
+ module.name.includes('provide module ')
179
+ ];
180
+ return array.some((item)=>item);
181
+ });
182
+ return filteredModules;
183
+ }
184
+ _getModuleAssets(compilation, entryPointNames) {
185
+ const { chunks } = compilation;
186
+ const { exposeFileNameImportMap } = this._containerManager;
187
+ const assets = {};
188
+ chunks.forEach((chunk)=>{
189
+ if (typeof chunk.name !== 'string') return;
190
+ // Support split chunks caused by splitChunks.maxSize:
191
+ // A chunk named "__federation_expose_Foo" may be split into
192
+ // "__federation_expose_Foo-<hash>" chunks, so we match both exact
193
+ // and prefix+dash patterns.
194
+ const matchedKey = exposeFileNameImportMap[chunk.name] !== undefined ? chunk.name : Object.keys(exposeFileNameImportMap).find((key)=>chunk.name.startsWith(key + '-'));
195
+ if (!matchedKey) return;
196
+ // TODO: support multiple import
197
+ const exposeKey = exposeFileNameImportMap[matchedKey][0];
198
+ const assetKey = (0,external_utils_js_namespaceObject.getFileNameWithOutExt)(exposeKey);
199
+ const chunkAssets = (0,external_utils_js_namespaceObject.getAssetsByChunk)(chunk, entryPointNames);
200
+ if (!assets[assetKey]) {
201
+ assets[assetKey] = chunkAssets;
202
+ } else {
203
+ // Merge split chunk assets, deduplicating with Set
204
+ assets[assetKey] = {
205
+ js: {
206
+ sync: [
207
+ ...new Set([
208
+ ...assets[assetKey].js.sync,
209
+ ...chunkAssets.js.sync
210
+ ])
211
+ ],
212
+ async: [
213
+ ...new Set([
214
+ ...assets[assetKey].js.async,
215
+ ...chunkAssets.js.async
216
+ ])
217
+ ]
218
+ },
219
+ css: {
220
+ sync: [
221
+ ...new Set([
222
+ ...assets[assetKey].css.sync,
223
+ ...chunkAssets.css.sync
224
+ ])
225
+ ],
226
+ async: [
227
+ ...new Set([
228
+ ...assets[assetKey].css.async,
229
+ ...chunkAssets.css.async
230
+ ])
231
+ ]
232
+ }
233
+ };
234
+ }
235
+ });
236
+ return assets;
237
+ }
238
+ _getProvideSharedAssets(compilation, stats, entryPointNames) {
239
+ const sharedModules = stats.modules.filter((module)=>{
240
+ if (!module || !module.name) {
241
+ return false;
242
+ }
243
+ const array = [
244
+ module.name.includes('consume shared module ')
245
+ ];
246
+ return array.some((item)=>item);
247
+ });
248
+ const manifestOverrideChunkIDMap = {};
249
+ const effectiveSharedModules = (0,external_utils_js_namespaceObject.getSharedModules)(stats, sharedModules);
250
+ effectiveSharedModules.forEach((item)=>{
251
+ const [sharedModuleName, sharedModule] = item;
252
+ if (!manifestOverrideChunkIDMap[sharedModuleName]) {
253
+ manifestOverrideChunkIDMap[sharedModuleName] = {
254
+ async: new Set(),
255
+ sync: new Set()
256
+ };
257
+ }
258
+ sharedModule.chunks.forEach((chunkID)=>{
259
+ const chunk = (0,external_utils_js_namespaceObject.findChunk)(chunkID, compilation.chunks);
260
+ manifestOverrideChunkIDMap[sharedModuleName].sync.add(chunkID);
261
+ if (!chunk) {
262
+ return;
263
+ }
264
+ [
265
+ ...chunk.groupsIterable
266
+ ].forEach((group)=>{
267
+ if (group.name && !entryPointNames.includes(group.name)) {
268
+ manifestOverrideChunkIDMap[sharedModuleName].sync.add(group.id);
269
+ }
270
+ });
271
+ });
272
+ });
273
+ const assets = {
274
+ js: {
275
+ async: [],
276
+ sync: []
277
+ },
278
+ css: {
279
+ async: [],
280
+ sync: []
281
+ }
282
+ };
283
+ Object.keys(manifestOverrideChunkIDMap).forEach((override)=>{
284
+ const asyncAssets = (0,external_utils_js_namespaceObject.getAssetsByChunkIDs)(compilation, {
285
+ [override]: manifestOverrideChunkIDMap[override].async
286
+ });
287
+ const syncAssets = (0,external_utils_js_namespaceObject.getAssetsByChunkIDs)(compilation, {
288
+ [override]: manifestOverrideChunkIDMap[override].sync
289
+ });
290
+ assets[override] = {
291
+ js: {
292
+ async: asyncAssets[override].js,
293
+ sync: syncAssets[override].js
294
+ },
295
+ css: {
296
+ async: asyncAssets[override].css,
297
+ sync: syncAssets[override].css
298
+ }
299
+ };
300
+ });
301
+ return assets;
302
+ }
303
+ async _generateStats(compiler, compilation, extraOptions) {
304
+ try {
305
+ const { name, manifest: manifestOptions = {}, exposes = {} } = this._options;
306
+ const metaData = this._getMetaData(compiler, compilation, extraOptions);
307
+ const stats = {
308
+ id: name,
309
+ name: name,
310
+ metaData,
311
+ shared: [],
312
+ remotes: [],
313
+ exposes: []
314
+ };
315
+ if (typeof manifestOptions === 'object' && manifestOptions.disableAssetsAnalyze) {
316
+ const remotes = this._remoteManager.statsRemoteWithEmptyUsedIn;
317
+ stats.remotes = remotes;
318
+ stats.exposes = Object.keys(exposes).map((exposeKey)=>{
319
+ return (0,external_ModuleHandler_js_namespaceObject.getExposeItem)({
320
+ exposeKey,
321
+ name: name,
322
+ file: {
323
+ import: exposes[exposeKey].import
324
+ }
325
+ });
326
+ });
327
+ stats.shared = Object.entries(this._sharedManager.normalizedOptions).reduce((sum, cur)=>{
328
+ const [pkgName, normalizedShareOptions] = cur;
329
+ sum.push((0,external_ModuleHandler_js_namespaceObject.getShareItem)({
330
+ pkgName,
331
+ normalizedShareOptions,
332
+ pkgVersion: normalizedShareOptions.version || managers_namespaceObject.UNKNOWN_MODULE_NAME,
333
+ hostName: name
334
+ }));
335
+ return sum;
336
+ }, []);
337
+ return stats;
338
+ }
339
+ const liveStats = compilation.getStats();
340
+ const statsOptions = {
341
+ all: false,
342
+ modules: true,
343
+ builtAt: true,
344
+ hash: true,
345
+ ids: true,
346
+ version: true,
347
+ entrypoints: true,
348
+ assets: false,
349
+ chunks: false,
350
+ reasons: true
351
+ };
352
+ if (this._bundler === 'webpack') {
353
+ statsOptions['cached'] = true;
354
+ }
355
+ statsOptions['cachedModules'] = true;
356
+ const webpackStats = liveStats.toJson(statsOptions);
357
+ const filteredModules = this._getFilteredModules(webpackStats);
358
+ const moduleHandler = new external_ModuleHandler_js_namespaceObject.ModuleHandler(this._options, filteredModules, {
359
+ bundler: this._bundler
360
+ });
361
+ const { remotes, exposesMap, sharedMap } = moduleHandler.collect();
362
+ const entryPointNames = [
363
+ ...compilation.entrypoints.values()
364
+ ].map((e)=>e.name).filter((v)=>!!v);
365
+ await Promise.all([
366
+ new Promise((resolve)=>{
367
+ const sharedAssets = this._getProvideSharedAssets(compilation, webpackStats, entryPointNames);
368
+ Object.keys(sharedMap).forEach((sharedKey)=>{
369
+ const assets = sharedAssets[sharedKey];
370
+ if (assets) {
371
+ sharedMap[sharedKey].assets = assets;
372
+ }
373
+ });
374
+ resolve();
375
+ }),
376
+ new Promise((resolve)=>{
377
+ const moduleAssets = this._getModuleAssets(compilation, entryPointNames);
378
+ Object.keys(exposesMap).forEach((exposeKey)=>{
379
+ const assets = moduleAssets[exposeKey];
380
+ if (assets) {
381
+ exposesMap[exposeKey].assets = assets;
382
+ }
383
+ exposesMap[exposeKey].requires = Array.from(new Set(exposesMap[exposeKey].requires));
384
+ });
385
+ resolve();
386
+ })
387
+ ]);
388
+ await Promise.all([
389
+ new Promise((resolve)=>{
390
+ const remoteMemo = new Set();
391
+ stats.remotes = remotes.map((remote)=>{
392
+ remoteMemo.add(remote.federationContainerName);
393
+ return {
394
+ ...remote,
395
+ usedIn: Array.from(remote.usedIn.values())
396
+ };
397
+ });
398
+ const statsRemoteWithEmptyUsedIn = this._remoteManager.statsRemoteWithEmptyUsedIn;
399
+ statsRemoteWithEmptyUsedIn.forEach((remoteInfo)=>{
400
+ if (!remoteMemo.has(remoteInfo.federationContainerName)) {
401
+ stats.remotes.push(remoteInfo);
402
+ }
403
+ });
404
+ resolve();
405
+ }),
406
+ new Promise((resolve)=>{
407
+ stats.shared = Object.values(sharedMap).map((shared)=>({
408
+ ...shared,
409
+ usedIn: Array.from(shared.usedIn)
410
+ }));
411
+ resolve();
412
+ })
413
+ ]);
414
+ await new Promise((resolve)=>{
415
+ const sharedAssets = stats.shared.reduce((sum, shared)=>{
416
+ const { js, css } = shared.assets;
417
+ [
418
+ ...js.sync,
419
+ ...js.async,
420
+ ...css.async,
421
+ css.sync
422
+ ].forEach((asset)=>{
423
+ sum.add(asset);
424
+ });
425
+ return sum;
426
+ }, new Set());
427
+ const { fileExposeKeyMap } = this._containerManager;
428
+ stats.exposes = [];
429
+ Object.entries(fileExposeKeyMap).forEach(([exposeFileWithoutExt, exposeKeySet])=>{
430
+ const expose = exposesMap[exposeFileWithoutExt] || {
431
+ assets: {
432
+ js: {
433
+ sync: [],
434
+ async: []
435
+ },
436
+ css: {
437
+ sync: [],
438
+ async: []
439
+ }
440
+ }
441
+ };
442
+ exposeKeySet.forEach((exposeKey)=>{
443
+ const { js, css } = expose.assets;
444
+ const exposeModuleName = (0,external_ModuleHandler_js_namespaceObject.getExposeName)(exposeKey);
445
+ stats.exposes.push({
446
+ ...expose,
447
+ path: exposeKey,
448
+ id: (0,sdk_namespaceObject.composeKeyWithSeparator)(this._options.name, exposeModuleName),
449
+ name: exposeModuleName,
450
+ assets: {
451
+ js: {
452
+ sync: js.sync.filter((asset)=>!sharedAssets.has(asset)),
453
+ async: js.async.filter((asset)=>!sharedAssets.has(asset))
454
+ },
455
+ css: {
456
+ sync: css.sync.filter((asset)=>!sharedAssets.has(asset)),
457
+ async: css.async.filter((asset)=>!sharedAssets.has(asset))
458
+ }
459
+ }
460
+ });
461
+ });
462
+ });
463
+ Object.values(exposesMap).map((expose)=>{
464
+ const { js, css } = expose.assets;
465
+ return {
466
+ ...expose,
467
+ assets: {
468
+ js: {
469
+ sync: js.sync.filter((asset)=>!sharedAssets.has(asset)),
470
+ async: js.async.filter((asset)=>!sharedAssets.has(asset))
471
+ },
472
+ css: {
473
+ sync: css.sync.filter((asset)=>!sharedAssets.has(asset)),
474
+ async: css.async.filter((asset)=>!sharedAssets.has(asset))
475
+ }
476
+ }
477
+ };
478
+ });
479
+ resolve();
480
+ });
481
+ return stats;
482
+ } catch (err) {
483
+ throw err;
484
+ }
485
+ }
486
+ getPublicPath(compiler) {
487
+ if (this._publicPath) {
488
+ return this._publicPath;
489
+ }
490
+ const { output: { publicPath: originalPublicPath } } = compiler.options;
491
+ let publicPath = originalPublicPath;
492
+ this._publicPath = publicPath;
493
+ return publicPath;
494
+ }
495
+ init(options, { pluginVersion, bundler }) {
496
+ this._options = options;
497
+ this._pluginVersion = pluginVersion;
498
+ this._bundler = bundler;
499
+ this._containerManager = new managers_namespaceObject.ContainerManager();
500
+ this._containerManager.init(options);
501
+ this._remoteManager = new managers_namespaceObject.RemoteManager();
502
+ this._remoteManager.init(options);
503
+ this._sharedManager = new managers_namespaceObject.SharedManager();
504
+ this._sharedManager.init(options);
505
+ }
506
+ updateStats(stats, compiler) {
507
+ const { metaData } = stats;
508
+ if (!metaData.types) {
509
+ metaData.types = (0,external_utils_js_namespaceObject.getTypesMetaInfo)(this._options, compiler.context);
510
+ }
511
+ if (!metaData.pluginVersion) {
512
+ metaData.pluginVersion = this._pluginVersion;
513
+ }
514
+ this.setMetaDataPublicPath(metaData, compiler);
515
+ // rspack not support legacy prefetch, and this field should be removed in the future
516
+ metaData.prefetchInterface = false;
517
+ return stats;
518
+ }
519
+ async generateStats(compiler, compilation) {
520
+ try {
521
+ const stats = await this._generateStats(compiler, compilation);
522
+ return stats;
523
+ } catch (err) {
524
+ throw err;
525
+ }
526
+ }
527
+ validate(compiler) {
528
+ const { output: { publicPath } } = compiler.options;
529
+ if (typeof publicPath !== 'string') {
530
+ external_logger_js_default().warn(`Manifest will not generate, because publicPath can only be string, but got '${publicPath}'`);
531
+ return false;
532
+ } else if (publicPath === 'auto') {
533
+ external_logger_js_default().warn(`Manifest will use absolute path resolution via its host at runtime, reason: publicPath='${publicPath}'`);
534
+ return true;
535
+ }
536
+ return true;
537
+ }
538
+ constructor(){
539
+ this._options = {};
540
+ this._bundler = 'webpack';
541
+ this._containerManager = new managers_namespaceObject.ContainerManager();
542
+ this._remoteManager = new managers_namespaceObject.RemoteManager();
543
+ this._sharedManager = new managers_namespaceObject.SharedManager();
544
+ this._pkgJsonManager = new managers_namespaceObject.PKGJsonManager();
545
+ }
546
+ }
547
+
548
+
549
+ exports.StatsManager = __webpack_exports__.StatsManager;
550
+ for(var __webpack_i__ in __webpack_exports__) {
551
+ if(["StatsManager"].indexOf(__webpack_i__) === -1) {
552
+ exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
553
+ }
554
+ }
555
+ Object.defineProperty(exports, '__esModule', { value: true });