Skip to content

Commit dd0cdc1

Browse files
hardfist9aoy
andauthored
fix: banner shouldn't be injected to asset (#3809)
* chore: banner shouldn't be injected to asset * fix: distinguish auxiliaryFiles and files * fix: add auxiliaryFiles to stats --------- Co-authored-by: gaoyuan.1226 <[email protected]>
1 parent 77239ce commit dd0cdc1

File tree

20 files changed

+435
-7
lines changed

20 files changed

+435
-7
lines changed

crates/node_binding/binding.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ export interface JsStatsAssetsByChunkName {
305305
export interface JsStatsChunk {
306306
type: string
307307
files: Array<string>
308+
auxiliaryFiles: Array<string>
308309
id: string
309310
entry: boolean
310311
initial: boolean

crates/node_binding/src/js_values/stats.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ impl From<rspack_core::StatsModuleReason> for JsStatsModuleReason {
180180
pub struct JsStatsChunk {
181181
pub r#type: &'static str,
182182
pub files: Vec<String>,
183+
pub auxiliary_files: Vec<String>,
183184
pub id: String,
184185
pub entry: bool,
185186
pub initial: bool,
@@ -197,6 +198,7 @@ impl TryFrom<rspack_core::StatsChunk<'_>> for JsStatsChunk {
197198
Ok(Self {
198199
r#type: stats.r#type,
199200
files: stats.files,
201+
auxiliary_files: stats.auxiliary_files,
200202
id: stats.id,
201203
entry: stats.entry,
202204
initial: stats.initial,

crates/rspack_core/src/chunk.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub struct Chunk {
3030
pub ids: Vec<String>,
3131
pub id_name_hints: HashSet<String>,
3232
pub files: HashSet<String>,
33+
pub auxiliary_files: HashSet<String>,
3334
pub groups: HashSet<ChunkGroupUkey>,
3435
pub runtime: RuntimeSpec,
3536
pub kind: ChunkKind,
@@ -56,6 +57,7 @@ impl Chunk {
5657
ids: vec![],
5758
id_name_hints: Default::default(),
5859
files: Default::default(),
60+
auxiliary_files: Default::default(),
5961
groups: Default::default(),
6062
runtime: HashSet::default(),
6163
kind,

crates/rspack_core/src/compiler/compilation.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ impl Compilation {
236236
}
237237
self.chunk_by_ukey.iter_mut().for_each(|(_, chunk)| {
238238
chunk.files.remove(filename);
239+
chunk.auxiliary_files.remove(filename);
239240
});
240241
}
241242
}
@@ -247,6 +248,10 @@ impl Compilation {
247248
if chunk.files.remove(filename) {
248249
chunk.files.insert(new_name.clone());
249250
}
251+
252+
if chunk.auxiliary_files.remove(filename) {
253+
chunk.auxiliary_files.insert(new_name.clone());
254+
}
250255
});
251256
}
252257
}
@@ -920,7 +925,12 @@ impl Compilation {
920925
.chunk_by_ukey
921926
.get_mut(&chunk_ukey)
922927
.unwrap_or_else(|| panic!("chunk({chunk_ukey:?}) should be in chunk_by_ukey",));
923-
current_chunk.files.insert(filename.clone());
928+
929+
if file_manifest.auxiliary {
930+
current_chunk.auxiliary_files.insert(filename.clone());
931+
} else {
932+
current_chunk.files.insert(filename.clone());
933+
}
924934

925935
self.emit_asset(
926936
filename.clone(),

crates/rspack_core/src/plugin/api.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,15 +414,16 @@ pub struct RenderManifestEntry {
414414
pub(crate) info: AssetInfo,
415415
// pub identifier: String,
416416
// hash?: string;
417-
// auxiliary?: boolean;
417+
pub(crate) auxiliary: bool,
418418
}
419419

420420
impl RenderManifestEntry {
421-
pub fn new(source: BoxSource, filename: String, info: AssetInfo) -> Self {
421+
pub fn new(source: BoxSource, filename: String, info: AssetInfo, auxiliary: bool) -> Self {
422422
Self {
423423
source,
424424
filename,
425425
info,
426+
auxiliary,
426427
}
427428
}
428429

crates/rspack_core/src/stats.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ impl Stats<'_> {
4343
let chunks = compilation_file_to_chunks.entry(file).or_default();
4444
chunks.push(chunk);
4545
}
46+
47+
for file in &chunk.auxiliary_files {
48+
let chunks = compilation_file_to_chunks.entry(file).or_default();
49+
chunks.push(chunk);
50+
}
4651
}
4752

4853
let mut assets: HashMap<&String, StatsAsset> = HashMap::from_iter(
@@ -157,6 +162,10 @@ impl Stats<'_> {
157162
.map(|c| -> Result<_> {
158163
let mut files = Vec::from_iter(c.files.iter().cloned());
159164
files.sort_unstable();
165+
166+
let mut auxiliary_files = Vec::from_iter(c.auxiliary_files.iter().cloned());
167+
auxiliary_files.sort_unstable();
168+
160169
let chunk_modules = if chunk_modules {
161170
let chunk_modules = self
162171
.compilation
@@ -181,6 +190,7 @@ impl Stats<'_> {
181190
Ok(StatsChunk {
182191
r#type: "chunk",
183192
files,
193+
auxiliary_files,
184194
id: c.expect_id().to_string(),
185195
names: c.name.clone().map(|n| vec![n]).unwrap_or_default(),
186196
entry: c.has_entry_module(&self.compilation.chunk_graph),
@@ -540,6 +550,7 @@ pub struct StatsModule<'a> {
540550
pub struct StatsChunk<'a> {
541551
pub r#type: &'static str,
542552
pub files: Vec<String>,
553+
pub auxiliary_files: Vec<String>,
543554
pub id: String,
544555
pub entry: bool,
545556
pub initial: bool,

crates/rspack_plugin_asset/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,12 @@ impl Plugin for AssetPlugin {
542542
.get::<CodeGenerationDataAssetInfo>()
543543
.expect("should have asset_info")
544544
.inner();
545-
RenderManifestEntry::new(source, asset_filename.to_owned(), asset_info.to_owned())
545+
RenderManifestEntry::new(
546+
source,
547+
asset_filename.to_owned(),
548+
asset_info.to_owned(),
549+
true,
550+
)
546551
});
547552

548553
Ok(result)

crates/rspack_plugin_css/src/plugin/impl_plugin_for_css_plugin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ impl Plugin for CssPlugin {
245245
source.boxed(),
246246
output_path,
247247
asset_info,
248+
false,
248249
)])
249250
}
250251

crates/rspack_plugin_devtool/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![feature(let_chains)]
22

3+
use std::collections::HashSet;
34
use std::{hash::Hash, path::Path};
45

56
use dashmap::DashMap;
@@ -176,14 +177,19 @@ impl Plugin for DevtoolPlugin {
176177
.boxed(),
177178
);
178179
args.compilation.emit_asset(filename, asset);
180+
// TODO
181+
// chunk.auxiliary_files.add(filename);
179182
} else {
180183
let mut source_map_filename = filename.to_owned() + ".map";
181184
// TODO(ahabhgk): refactor remove the for loop
182185
// https://webpack.docschina.org/configuration/output/#outputsourcemapfilename
183186
if args.compilation.options.devtool.source_map() {
184187
let source_map_filename_config = &args.compilation.options.output.source_map_filename;
185188
for chunk in args.compilation.chunk_by_ukey.values() {
186-
for file in &chunk.files {
189+
let files: HashSet<String> =
190+
chunk.files.union(&chunk.auxiliary_files).cloned().collect();
191+
192+
for file in &files {
187193
if file == &filename {
188194
let source_type = if is_css {
189195
&SourceType::Css

crates/rspack_plugin_javascript/src/plugin/impl_plugin_for_js_plugin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ impl Plugin for JsPlugin {
181181
source,
182182
output_path,
183183
asset_info,
184+
false,
184185
)])
185186
}
186187

crates/rspack_plugin_wasm/src/wasm_plugin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl Plugin for AsyncWasmPlugin {
8383
.get(&m.identifier())
8484
.map(|s| s.clone())
8585
.expect("should have wasm_filename");
86-
RenderManifestEntry::new(source, output_path, asset_info)
86+
RenderManifestEntry::new(source, output_path, asset_info, false)
8787
});
8888

8989
Ok(result)

packages/rspack/tests/Stats.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ describe("Stats", () => {
5050
},
5151
"chunks": [
5252
{
53+
"auxiliaryFiles": [],
5354
"children": [],
5455
"entry": true,
5556
"files": [

0 commit comments

Comments
 (0)