@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,497 @@
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') return;
138
+ // Support split chunks caused by splitChunks.maxSize:
139
+ // A chunk named "__federation_expose_Foo" may be split into
140
+ // "__federation_expose_Foo-<hash>" chunks, so we match both exact
141
+ // and prefix+dash patterns.
142
+ const matchedKey = exposeFileNameImportMap[chunk.name] !== undefined ? chunk.name : Object.keys(exposeFileNameImportMap).find((key)=>chunk.name.startsWith(key + '-'));
143
+ if (!matchedKey) return;
144
+ // TODO: support multiple import
145
+ const exposeKey = exposeFileNameImportMap[matchedKey][0];
146
+ const assetKey = getFileNameWithOutExt(exposeKey);
147
+ const chunkAssets = getAssetsByChunk(chunk, entryPointNames);
148
+ if (!assets[assetKey]) {
149
+ assets[assetKey] = chunkAssets;
150
+ } else {
151
+ // Merge split chunk assets, deduplicating with Set
152
+ assets[assetKey] = {
153
+ js: {
154
+ sync: [
155
+ ...new Set([
156
+ ...assets[assetKey].js.sync,
157
+ ...chunkAssets.js.sync
158
+ ])
159
+ ],
160
+ async: [
161
+ ...new Set([
162
+ ...assets[assetKey].js.async,
163
+ ...chunkAssets.js.async
164
+ ])
165
+ ]
166
+ },
167
+ css: {
168
+ sync: [
169
+ ...new Set([
170
+ ...assets[assetKey].css.sync,
171
+ ...chunkAssets.css.sync
172
+ ])
173
+ ],
174
+ async: [
175
+ ...new Set([
176
+ ...assets[assetKey].css.async,
177
+ ...chunkAssets.css.async
178
+ ])
179
+ ]
180
+ }
181
+ };
182
+ }
183
+ });
184
+ return assets;
185
+ }
186
+ _getProvideSharedAssets(compilation, stats, entryPointNames) {
187
+ const sharedModules = stats.modules.filter((module)=>{
188
+ if (!module || !module.name) {
189
+ return false;
190
+ }
191
+ const array = [
192
+ module.name.includes('consume shared module ')
193
+ ];
194
+ return array.some((item)=>item);
195
+ });
196
+ const manifestOverrideChunkIDMap = {};
197
+ const effectiveSharedModules = getSharedModules(stats, sharedModules);
198
+ effectiveSharedModules.forEach((item)=>{
199
+ const [sharedModuleName, sharedModule] = item;
200
+ if (!manifestOverrideChunkIDMap[sharedModuleName]) {
201
+ manifestOverrideChunkIDMap[sharedModuleName] = {
202
+ async: new Set(),
203
+ sync: new Set()
204
+ };
205
+ }
206
+ sharedModule.chunks.forEach((chunkID)=>{
207
+ const chunk = findChunk(chunkID, compilation.chunks);
208
+ manifestOverrideChunkIDMap[sharedModuleName].sync.add(chunkID);
209
+ if (!chunk) {
210
+ return;
211
+ }
212
+ [
213
+ ...chunk.groupsIterable
214
+ ].forEach((group)=>{
215
+ if (group.name && !entryPointNames.includes(group.name)) {
216
+ manifestOverrideChunkIDMap[sharedModuleName].sync.add(group.id);
217
+ }
218
+ });
219
+ });
220
+ });
221
+ const assets = {
222
+ js: {
223
+ async: [],
224
+ sync: []
225
+ },
226
+ css: {
227
+ async: [],
228
+ sync: []
229
+ }
230
+ };
231
+ Object.keys(manifestOverrideChunkIDMap).forEach((override)=>{
232
+ const asyncAssets = getAssetsByChunkIDs(compilation, {
233
+ [override]: manifestOverrideChunkIDMap[override].async
234
+ });
235
+ const syncAssets = getAssetsByChunkIDs(compilation, {
236
+ [override]: manifestOverrideChunkIDMap[override].sync
237
+ });
238
+ assets[override] = {
239
+ js: {
240
+ async: asyncAssets[override].js,
241
+ sync: syncAssets[override].js
242
+ },
243
+ css: {
244
+ async: asyncAssets[override].css,
245
+ sync: syncAssets[override].css
246
+ }
247
+ };
248
+ });
249
+ return assets;
250
+ }
251
+ async _generateStats(compiler, compilation, extraOptions) {
252
+ try {
253
+ const { name, manifest: manifestOptions = {}, exposes = {} } = this._options;
254
+ const metaData = this._getMetaData(compiler, compilation, extraOptions);
255
+ const stats = {
256
+ id: name,
257
+ name: name,
258
+ metaData,
259
+ shared: [],
260
+ remotes: [],
261
+ exposes: []
262
+ };
263
+ if (typeof manifestOptions === 'object' && manifestOptions.disableAssetsAnalyze) {
264
+ const remotes = this._remoteManager.statsRemoteWithEmptyUsedIn;
265
+ stats.remotes = remotes;
266
+ stats.exposes = Object.keys(exposes).map((exposeKey)=>{
267
+ return getExposeItem({
268
+ exposeKey,
269
+ name: name,
270
+ file: {
271
+ import: exposes[exposeKey].import
272
+ }
273
+ });
274
+ });
275
+ stats.shared = Object.entries(this._sharedManager.normalizedOptions).reduce((sum, cur)=>{
276
+ const [pkgName, normalizedShareOptions] = cur;
277
+ sum.push(getShareItem({
278
+ pkgName,
279
+ normalizedShareOptions,
280
+ pkgVersion: normalizedShareOptions.version || UNKNOWN_MODULE_NAME,
281
+ hostName: name
282
+ }));
283
+ return sum;
284
+ }, []);
285
+ return stats;
286
+ }
287
+ const liveStats = compilation.getStats();
288
+ const statsOptions = {
289
+ all: false,
290
+ modules: true,
291
+ builtAt: true,
292
+ hash: true,
293
+ ids: true,
294
+ version: true,
295
+ entrypoints: true,
296
+ assets: false,
297
+ chunks: false,
298
+ reasons: true
299
+ };
300
+ if (this._bundler === 'webpack') {
301
+ statsOptions['cached'] = true;
302
+ }
303
+ statsOptions['cachedModules'] = true;
304
+ const webpackStats = liveStats.toJson(statsOptions);
305
+ const filteredModules = this._getFilteredModules(webpackStats);
306
+ const moduleHandler = new ModuleHandler(this._options, filteredModules, {
307
+ bundler: this._bundler
308
+ });
309
+ const { remotes, exposesMap, sharedMap } = moduleHandler.collect();
310
+ const entryPointNames = [
311
+ ...compilation.entrypoints.values()
312
+ ].map((e)=>e.name).filter((v)=>!!v);
313
+ await Promise.all([
314
+ new Promise((resolve)=>{
315
+ const sharedAssets = this._getProvideSharedAssets(compilation, webpackStats, entryPointNames);
316
+ Object.keys(sharedMap).forEach((sharedKey)=>{
317
+ const assets = sharedAssets[sharedKey];
318
+ if (assets) {
319
+ sharedMap[sharedKey].assets = assets;
320
+ }
321
+ });
322
+ resolve();
323
+ }),
324
+ new Promise((resolve)=>{
325
+ const moduleAssets = this._getModuleAssets(compilation, entryPointNames);
326
+ Object.keys(exposesMap).forEach((exposeKey)=>{
327
+ const assets = moduleAssets[exposeKey];
328
+ if (assets) {
329
+ exposesMap[exposeKey].assets = assets;
330
+ }
331
+ exposesMap[exposeKey].requires = Array.from(new Set(exposesMap[exposeKey].requires));
332
+ });
333
+ resolve();
334
+ })
335
+ ]);
336
+ await Promise.all([
337
+ new Promise((resolve)=>{
338
+ const remoteMemo = new Set();
339
+ stats.remotes = remotes.map((remote)=>{
340
+ remoteMemo.add(remote.federationContainerName);
341
+ return {
342
+ ...remote,
343
+ usedIn: Array.from(remote.usedIn.values())
344
+ };
345
+ });
346
+ const statsRemoteWithEmptyUsedIn = this._remoteManager.statsRemoteWithEmptyUsedIn;
347
+ statsRemoteWithEmptyUsedIn.forEach((remoteInfo)=>{
348
+ if (!remoteMemo.has(remoteInfo.federationContainerName)) {
349
+ stats.remotes.push(remoteInfo);
350
+ }
351
+ });
352
+ resolve();
353
+ }),
354
+ new Promise((resolve)=>{
355
+ stats.shared = Object.values(sharedMap).map((shared)=>({
356
+ ...shared,
357
+ usedIn: Array.from(shared.usedIn)
358
+ }));
359
+ resolve();
360
+ })
361
+ ]);
362
+ await new Promise((resolve)=>{
363
+ const sharedAssets = stats.shared.reduce((sum, shared)=>{
364
+ const { js, css } = shared.assets;
365
+ [
366
+ ...js.sync,
367
+ ...js.async,
368
+ ...css.async,
369
+ css.sync
370
+ ].forEach((asset)=>{
371
+ sum.add(asset);
372
+ });
373
+ return sum;
374
+ }, new Set());
375
+ const { fileExposeKeyMap } = this._containerManager;
376
+ stats.exposes = [];
377
+ Object.entries(fileExposeKeyMap).forEach(([exposeFileWithoutExt, exposeKeySet])=>{
378
+ const expose = exposesMap[exposeFileWithoutExt] || {
379
+ assets: {
380
+ js: {
381
+ sync: [],
382
+ async: []
383
+ },
384
+ css: {
385
+ sync: [],
386
+ async: []
387
+ }
388
+ }
389
+ };
390
+ exposeKeySet.forEach((exposeKey)=>{
391
+ const { js, css } = expose.assets;
392
+ const exposeModuleName = getExposeName(exposeKey);
393
+ stats.exposes.push({
394
+ ...expose,
395
+ path: exposeKey,
396
+ id: composeKeyWithSeparator(this._options.name, exposeModuleName),
397
+ name: exposeModuleName,
398
+ assets: {
399
+ js: {
400
+ sync: js.sync.filter((asset)=>!sharedAssets.has(asset)),
401
+ async: js.async.filter((asset)=>!sharedAssets.has(asset))
402
+ },
403
+ css: {
404
+ sync: css.sync.filter((asset)=>!sharedAssets.has(asset)),
405
+ async: css.async.filter((asset)=>!sharedAssets.has(asset))
406
+ }
407
+ }
408
+ });
409
+ });
410
+ });
411
+ Object.values(exposesMap).map((expose)=>{
412
+ const { js, css } = expose.assets;
413
+ return {
414
+ ...expose,
415
+ assets: {
416
+ js: {
417
+ sync: js.sync.filter((asset)=>!sharedAssets.has(asset)),
418
+ async: js.async.filter((asset)=>!sharedAssets.has(asset))
419
+ },
420
+ css: {
421
+ sync: css.sync.filter((asset)=>!sharedAssets.has(asset)),
422
+ async: css.async.filter((asset)=>!sharedAssets.has(asset))
423
+ }
424
+ }
425
+ };
426
+ });
427
+ resolve();
428
+ });
429
+ return stats;
430
+ } catch (err) {
431
+ throw err;
432
+ }
433
+ }
434
+ getPublicPath(compiler) {
435
+ if (this._publicPath) {
436
+ return this._publicPath;
437
+ }
438
+ const { output: { publicPath: originalPublicPath } } = compiler.options;
439
+ let publicPath = originalPublicPath;
440
+ this._publicPath = publicPath;
441
+ return publicPath;
442
+ }
443
+ init(options, { pluginVersion, bundler }) {
444
+ this._options = options;
445
+ this._pluginVersion = pluginVersion;
446
+ this._bundler = bundler;
447
+ this._containerManager = new ContainerManager();
448
+ this._containerManager.init(options);
449
+ this._remoteManager = new RemoteManager();
450
+ this._remoteManager.init(options);
451
+ this._sharedManager = new SharedManager();
452
+ this._sharedManager.init(options);
453
+ }
454
+ updateStats(stats, compiler) {
455
+ const { metaData } = stats;
456
+ if (!metaData.types) {
457
+ metaData.types = getTypesMetaInfo(this._options, compiler.context);
458
+ }
459
+ if (!metaData.pluginVersion) {
460
+ metaData.pluginVersion = this._pluginVersion;
461
+ }
462
+ this.setMetaDataPublicPath(metaData, compiler);
463
+ // rspack not support legacy prefetch, and this field should be removed in the future
464
+ metaData.prefetchInterface = false;
465
+ return stats;
466
+ }
467
+ async generateStats(compiler, compilation) {
468
+ try {
469
+ const stats = await this._generateStats(compiler, compilation);
470
+ return stats;
471
+ } catch (err) {
472
+ throw err;
473
+ }
474
+ }
475
+ validate(compiler) {
476
+ const { output: { publicPath } } = compiler.options;
477
+ if (typeof publicPath !== 'string') {
478
+ logger.warn(`Manifest will not generate, because publicPath can only be string, but got '${publicPath}'`);
479
+ return false;
480
+ } else if (publicPath === 'auto') {
481
+ logger.warn(`Manifest will use absolute path resolution via its host at runtime, reason: publicPath='${publicPath}'`);
482
+ return true;
483
+ }
484
+ return true;
485
+ }
486
+ constructor(){
487
+ this._options = {};
488
+ this._bundler = 'webpack';
489
+ this._containerManager = new ContainerManager();
490
+ this._remoteManager = new RemoteManager();
491
+ this._sharedManager = new SharedManager();
492
+ this._pkgJsonManager = new PKGJsonManager();
493
+ }
494
+ }
495
+
496
+
497
+ export { StatsManager };
@@ -0,0 +1,15 @@
1
+ import { Compiler, WebpackPluginInstance } from 'webpack';
2
+ import { moduleFederationPlugin } from '@module-federation/sdk';
3
+ export declare class StatsPlugin implements WebpackPluginInstance {
4
+ readonly name = "StatsPlugin";
5
+ private _options;
6
+ private _statsManager;
7
+ private _manifestManager;
8
+ private _enable;
9
+ private _bundler;
10
+ constructor(options: moduleFederationPlugin.ModuleFederationPluginOptions, { pluginVersion, bundler, }: {
11
+ pluginVersion: string;
12
+ bundler: 'webpack' | 'rspack';
13
+ });
14
+ apply(compiler: Compiler): void;
15
+ }
@@ -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 });