Skip to content

Commit 54310cd

Browse files
committed
chore: adjust
1 parent fcdfcf2 commit 54310cd

File tree

4 files changed

+49
-36
lines changed

4 files changed

+49
-36
lines changed

packages/manifest/src/ManifestManager.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
import { isDev } from './utils';
1212
import logger from './logger';
1313
import type { Compilation, Compiler } from 'webpack';
14-
import { ManifestInfo } from './types';
1514

1615
interface GenerateManifestOptions {
1716
compilation: Compilation;
@@ -33,16 +32,13 @@ class ManifestManager {
3332
return getManifestFileName(this._options.manifest).manifestFileName;
3433
}
3534

36-
updateManifest(options: GenerateManifestOptions): void {
37-
const { compilation, compiler } = options;
35+
updateManifest(options: GenerateManifestOptions): Manifest {
3836
const manifest = this.generateManifest(options);
39-
const source = new compiler.webpack.sources.RawSource(
40-
JSON.stringify(manifest, null, 2),
41-
);
42-
compilation.updateAsset(this.fileName, source);
37+
38+
return manifest;
4339
}
4440

45-
async generateManifest(options: GenerateManifestOptions): Promise<Manifest> {
41+
generateManifest(options: GenerateManifestOptions): Manifest {
4642
const { publicPath, stats, compiler } = options;
4743
// Initialize manifest with required properties from stats
4844
const { id, name, metaData } = stats;

packages/manifest/src/StatsManager.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -529,11 +529,7 @@ class StatsManager {
529529
this._sharedManager.init(options);
530530
}
531531

532-
updateStats(
533-
stats: Stats,
534-
compiler: Compiler,
535-
compilation: Compilation,
536-
): Stats {
532+
updateStats(stats: Stats, compiler: Compiler): Stats {
537533
const { metaData } = stats;
538534
if (!metaData.types) {
539535
metaData.types = getTypesMetaInfo(this._options, compiler.context);
@@ -545,10 +541,6 @@ class StatsManager {
545541
// rspack not support legacy prefetch, and this field should be removed in the future
546542
metaData.prefetchInterface = false;
547543

548-
compilation.updateAsset(
549-
this.fileName,
550-
new compiler.webpack.sources.RawSource(JSON.stringify(stats, null, 2)),
551-
);
552544
return stats;
553545
}
554546

packages/manifest/src/StatsPlugin.ts

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { ManifestManager } from './ManifestManager';
77
import { StatsManager } from './StatsManager';
88
import { PLUGIN_IDENTIFIER } from './constants';
99
import logger from './logger';
10-
import { StatsInfo, ManifestInfo, ResourceInfo } from './types';
1110

1211
export class StatsPlugin implements WebpackPluginInstance {
1312
readonly name = 'StatsPlugin';
@@ -62,26 +61,63 @@ export class StatsPlugin implements WebpackPluginInstance {
6261
);
6362
// new rspack should hit
6463
if (existedStats) {
65-
const updatedStats = this._statsManager.updateStats(
64+
let updatedStats = this._statsManager.updateStats(
6665
JSON.parse(existedStats.source.source().toString()),
6766
compiler,
68-
compilation,
6967
);
70-
this._manifestManager.updateManifest({
68+
if (
69+
typeof this._options.manifest === 'object' &&
70+
this._options.manifest.additionalData
71+
) {
72+
updatedStats =
73+
(await this._options.manifest.additionalData({
74+
stats: updatedStats,
75+
compiler,
76+
compilation,
77+
bundler: this._bundler,
78+
})) || updatedStats;
79+
}
80+
81+
compilation.updateAsset(
82+
this._statsManager.fileName,
83+
new compiler.webpack.sources.RawSource(
84+
JSON.stringify(updatedStats, null, 2),
85+
),
86+
);
87+
const updatedManifest = this._manifestManager.updateManifest({
7188
compilation,
7289
stats: updatedStats,
7390
publicPath: this._statsManager.getPublicPath(compiler),
7491
compiler,
7592
bundler: this._bundler,
7693
});
94+
const source = new compiler.webpack.sources.RawSource(
95+
JSON.stringify(updatedManifest, null, 2),
96+
);
97+
compilation.updateAsset(this._manifestManager.fileName, source);
98+
7799
return;
78100
}
79101

80102
// webpack + legacy rspack
81-
const stats = await this._statsManager.generateStats(
103+
let stats = await this._statsManager.generateStats(
82104
compiler,
83105
compilation,
84106
);
107+
108+
if (
109+
typeof this._options.manifest === 'object' &&
110+
this._options.manifest.additionalData
111+
) {
112+
stats =
113+
(await this._options.manifest.additionalData({
114+
stats,
115+
compiler,
116+
compilation,
117+
bundler: this._bundler,
118+
})) || stats;
119+
}
120+
85121
const manifest = await this._manifestManager.generateManifest({
86122
compilation,
87123
stats: stats,
@@ -90,18 +126,6 @@ export class StatsPlugin implements WebpackPluginInstance {
90126
bundler: this._bundler,
91127
});
92128

93-
if (
94-
typeof this._options.manifest === 'object' &&
95-
this._options.manifest.additionalData
96-
) {
97-
await this._options.manifest.additionalData({
98-
stats,
99-
compiler,
100-
compilation,
101-
manifest,
102-
bundler: this._bundler,
103-
});
104-
}
105129
compilation.emitAsset(
106130
this._statsManager.fileName,
107131
new compiler.webpack.sources.RawSource(

packages/sdk/src/types/plugins/ModuleFederationPlugin.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ export type DataPrefetch = boolean;
115115

116116
export interface AdditionalDataOptions {
117117
stats: Stats;
118-
manifest?: Manifest;
119118
compiler: webpack.Compiler;
120119
compilation: webpack.Compilation;
121120
bundler: 'webpack' | 'rspack';
@@ -124,7 +123,9 @@ export interface PluginManifestOptions {
124123
filePath?: string;
125124
disableAssetsAnalyze?: boolean;
126125
fileName?: string;
127-
additionalData?: (options: AdditionalDataOptions) => Promise<void> | void;
126+
additionalData?: (
127+
options: AdditionalDataOptions,
128+
) => Promise<void | Stats> | Stats | void;
128129
}
129130

130131
export interface PluginDevOptions {

0 commit comments

Comments
 (0)