Skip to content

Commit b8be8be

Browse files
committed
refactor: using build_chunk_graph_artifact
1 parent 7473a29 commit b8be8be

File tree

150 files changed

+2431
-925
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+2431
-925
lines changed

crates/rspack_binding_api/src/chunk.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ pub struct Chunk {
2020
impl Chunk {
2121
fn as_ref(&self) -> napi::Result<(&'static Compilation, &'static rspack_core::Chunk)> {
2222
let compilation = unsafe { self.compilation.as_ref() };
23-
if let Some(chunk) = compilation.chunk_by_ukey.get(&self.chunk_ukey) {
23+
if let Some(chunk) = compilation
24+
.build_chunk_graph_artifact
25+
.chunk_by_ukey
26+
.get(&self.chunk_ukey)
27+
{
2428
Ok((compilation, chunk))
2529
} else {
2630
Err(napi::Error::from_reason(format!(
@@ -163,27 +167,27 @@ impl Chunk {
163167
#[napi]
164168
pub fn is_only_initial(&self) -> napi::Result<bool> {
165169
let (compilation, chunk) = self.as_ref()?;
166-
Ok(chunk.is_only_initial(&compilation.chunk_group_by_ukey))
170+
Ok(chunk.is_only_initial(&compilation.build_chunk_graph_artifact.chunk_group_by_ukey))
167171
}
168172

169173
#[napi]
170174
pub fn can_be_initial(&self) -> napi::Result<bool> {
171175
let (compilation, chunk) = self.as_ref()?;
172-
Ok(chunk.can_be_initial(&compilation.chunk_group_by_ukey))
176+
Ok(chunk.can_be_initial(&compilation.build_chunk_graph_artifact.chunk_group_by_ukey))
173177
}
174178

175179
#[napi]
176180
pub fn has_runtime(&self) -> napi::Result<bool> {
177181
let (compilation, chunk) = self.as_ref()?;
178-
Ok(chunk.has_runtime(&compilation.chunk_group_by_ukey))
182+
Ok(chunk.has_runtime(&compilation.build_chunk_graph_artifact.chunk_group_by_ukey))
179183
}
180184

181185
#[napi(ts_return_type = "Chunk[]")]
182186
pub fn get_all_async_chunks(&self) -> napi::Result<Vec<ChunkWrapper>> {
183187
let (compilation, chunk) = self.as_ref()?;
184188
Ok(
185189
chunk
186-
.get_all_async_chunks(&compilation.chunk_group_by_ukey)
190+
.get_all_async_chunks(&compilation.build_chunk_graph_artifact.chunk_group_by_ukey)
187191
.into_iter()
188192
.map(|chunk_ukey| ChunkWrapper::new(chunk_ukey, compilation))
189193
.collect::<Vec<_>>(),
@@ -195,7 +199,7 @@ impl Chunk {
195199
let (compilation, chunk) = self.as_ref()?;
196200
Ok(
197201
chunk
198-
.get_all_initial_chunks(&compilation.chunk_group_by_ukey)
202+
.get_all_initial_chunks(&compilation.build_chunk_graph_artifact.chunk_group_by_ukey)
199203
.into_iter()
200204
.map(|chunk_ukey| ChunkWrapper::new(chunk_ukey, compilation))
201205
.collect::<Vec<_>>(),
@@ -207,7 +211,7 @@ impl Chunk {
207211
let (compilation, chunk) = self.as_ref()?;
208212
Ok(
209213
chunk
210-
.get_all_referenced_chunks(&compilation.chunk_group_by_ukey)
214+
.get_all_referenced_chunks(&compilation.build_chunk_graph_artifact.chunk_group_by_ukey)
211215
.into_iter()
212216
.map(|chunk_ukey| ChunkWrapper::new(chunk_ukey, compilation))
213217
.collect::<Vec<_>>(),
@@ -220,7 +224,12 @@ impl Chunk {
220224
let mut groups = chunk
221225
.groups()
222226
.iter()
223-
.filter_map(|group| compilation.chunk_group_by_ukey.get(group))
227+
.filter_map(|group| {
228+
compilation
229+
.build_chunk_graph_artifact
230+
.chunk_group_by_ukey
231+
.get(group)
232+
})
224233
.collect::<Vec<_>>();
225234
groups.sort_unstable_by(|a, b| a.index.cmp(&b.index));
226235
Ok(
@@ -235,7 +244,8 @@ impl Chunk {
235244
pub fn get_entry_options(&self) -> napi::Result<Option<EntryOptionsDTO>> {
236245
let (compilation, chunk) = self.as_ref()?;
237246

238-
let entry_options = chunk.get_entry_options(&compilation.chunk_group_by_ukey);
247+
let entry_options =
248+
chunk.get_entry_options(&compilation.build_chunk_graph_artifact.chunk_group_by_ukey);
239249

240250
Ok(entry_options.map(|options| EntryOptionsDTO::new(options.clone())))
241251
}

crates/rspack_binding_api/src/chunk_graph.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ impl ChunkGraph {
4848
let compilation = self.as_ref()?;
4949
Ok(
5050
compilation
51+
.build_chunk_graph_artifact
5152
.chunk_graph
52-
.has_chunk_entry_dependent_chunks(&chunk.chunk_ukey, &compilation.chunk_group_by_ukey),
53+
.has_chunk_entry_dependent_chunks(
54+
&chunk.chunk_ukey,
55+
&compilation.build_chunk_graph_artifact.chunk_group_by_ukey,
56+
),
5357
)
5458
}
5559

@@ -59,6 +63,7 @@ impl ChunkGraph {
5963

6064
let module_graph = compilation.get_module_graph();
6165
let modules = compilation
66+
.build_chunk_graph_artifact
6267
.chunk_graph
6368
.get_chunk_modules(&chunk.chunk_ukey, module_graph);
6469

@@ -80,6 +85,7 @@ impl ChunkGraph {
8085
let compilation = self.as_ref()?;
8186

8287
let modules = compilation
88+
.build_chunk_graph_artifact
8389
.chunk_graph
8490
.get_chunk_entry_modules(&chunk.chunk_ukey);
8591
let module_graph = compilation.get_module_graph();
@@ -98,6 +104,7 @@ impl ChunkGraph {
98104

99105
Ok(
100106
compilation
107+
.build_chunk_graph_artifact
101108
.chunk_graph
102109
.get_number_of_entry_modules(&chunk.chunk_ukey) as u32,
103110
)
@@ -111,11 +118,12 @@ impl ChunkGraph {
111118
let compilation = self.as_ref()?;
112119

113120
let chunks = compilation
121+
.build_chunk_graph_artifact
114122
.chunk_graph
115123
.get_chunk_entry_dependent_chunks_iterable(
116124
&chunk.chunk_ukey,
117-
&compilation.chunk_by_ukey,
118-
&compilation.chunk_group_by_ukey,
125+
&compilation.build_chunk_graph_artifact.chunk_by_ukey,
126+
&compilation.build_chunk_graph_artifact.chunk_group_by_ukey,
119127
);
120128

121129
Ok(
@@ -135,11 +143,14 @@ impl ChunkGraph {
135143
let compilation = self.as_ref()?;
136144
let module_graph = compilation.get_module_graph();
137145

138-
let chunk_modules = compilation.chunk_graph.get_chunk_modules_by_source_type(
139-
&chunk.chunk_ukey,
140-
SourceType::from(source_type.as_str()),
141-
module_graph,
142-
);
146+
let chunk_modules = compilation
147+
.build_chunk_graph_artifact
148+
.chunk_graph
149+
.get_chunk_modules_by_source_type(
150+
&chunk.chunk_ukey,
151+
SourceType::from(source_type.as_str()),
152+
module_graph,
153+
);
143154

144155
Ok(
145156
chunk_modules
@@ -155,6 +166,7 @@ impl ChunkGraph {
155166

156167
Ok(
157168
compilation
169+
.build_chunk_graph_artifact
158170
.chunk_graph
159171
.get_module_chunks(module.identifier)
160172
.iter()
@@ -205,8 +217,12 @@ impl ChunkGraph {
205217
let compilation = self.as_ref()?;
206218
Ok(
207219
compilation
220+
.build_chunk_graph_artifact
208221
.chunk_graph
209-
.get_block_chunk_group(&js_block.block_id, &compilation.chunk_group_by_ukey)
222+
.get_block_chunk_group(
223+
&js_block.block_id,
224+
&compilation.build_chunk_graph_artifact.chunk_group_by_ukey,
225+
)
210226
.map(|chunk_group| ChunkGroupWrapper::new(chunk_group.ukey, compilation)),
211227
)
212228
}

crates/rspack_binding_api/src/chunk_group.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ pub struct ChunkGroup {
2121
impl ChunkGroup {
2222
fn as_ref(&self) -> napi::Result<(&'static Compilation, &'static rspack_core::ChunkGroup)> {
2323
let compilation = unsafe { self.compilation.as_ref() };
24-
if let Some(chunk_group) = compilation.chunk_group_by_ukey.get(&self.chunk_group_ukey) {
24+
if let Some(chunk_group) = compilation
25+
.build_chunk_graph_artifact
26+
.chunk_group_by_ukey
27+
.get(&self.chunk_group_ukey)
28+
{
2529
Ok((compilation, chunk_group))
2630
} else {
2731
Err(napi::Error::from_reason(format!(
@@ -131,7 +135,8 @@ impl ChunkGroup {
131135
#[napi(ts_return_type = "Chunk")]
132136
pub fn get_runtime_chunk(&self) -> napi::Result<ChunkWrapper> {
133137
let (compilation, chunk_group) = self.as_ref()?;
134-
let chunk_ukey = chunk_group.get_runtime_chunk(&compilation.chunk_group_by_ukey);
138+
let chunk_ukey =
139+
chunk_group.get_runtime_chunk(&compilation.build_chunk_graph_artifact.chunk_group_by_ukey);
135140
Ok(ChunkWrapper::new(chunk_ukey, compilation))
136141
}
137142

@@ -151,6 +156,7 @@ impl ChunkGroup {
151156
.iter()
152157
.filter_map(|chunk_ukey| {
153158
compilation
159+
.build_chunk_graph_artifact
154160
.chunk_by_ukey
155161
.get(chunk_ukey)
156162
.map(|chunk| chunk.files().iter())

crates/rspack_binding_api/src/compilation/chunks.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ impl Chunks {
4040
#[napi(getter)]
4141
pub fn size(&self) -> napi::Result<u32> {
4242
let compilation = self.as_ref()?;
43-
Ok(compilation.chunk_by_ukey.len() as u32)
43+
Ok(compilation.build_chunk_graph_artifact.chunk_by_ukey.len() as u32)
4444
}
4545

4646
#[napi(js_name = "_values", ts_return_type = "Chunk[]")]
4747
pub fn values(&self) -> napi::Result<Vec<ChunkWrapper>> {
4848
let compilation = self.as_ref()?;
4949
Ok(
5050
compilation
51+
.build_chunk_graph_artifact
5152
.chunk_by_ukey
5253
.keys()
5354
.map(|chunk_ukey| ChunkWrapper::new(*chunk_ukey, compilation))
@@ -58,6 +59,11 @@ impl Chunks {
5859
#[napi(js_name = "_has")]
5960
pub fn has(&self, chunk: &Chunk) -> napi::Result<bool> {
6061
let compilation = self.as_ref()?;
61-
Ok(compilation.chunk_by_ukey.contains(&chunk.chunk_ukey))
62+
Ok(
63+
compilation
64+
.build_chunk_graph_artifact
65+
.chunk_by_ukey
66+
.contains(&chunk.chunk_ukey),
67+
)
6268
}
6369
}

crates/rspack_binding_api/src/compilation/mod.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,19 +240,33 @@ impl JsCompilation {
240240
pub fn get_named_chunk_keys(&self) -> Result<Vec<String>> {
241241
let compilation = self.as_ref()?;
242242

243-
Ok(compilation.named_chunks.keys().cloned().collect::<Vec<_>>())
243+
Ok(
244+
compilation
245+
.build_chunk_graph_artifact
246+
.named_chunks
247+
.keys()
248+
.cloned()
249+
.collect::<Vec<_>>(),
250+
)
244251
}
245252

246253
#[napi(ts_return_type = "Chunk")]
247254
pub fn get_named_chunk(&self, name: String) -> Result<Option<ChunkWrapper>> {
248255
let compilation = self.as_ref()?;
249256

250-
Ok(compilation.named_chunks.get(&name).and_then(|c| {
257+
Ok(
251258
compilation
252-
.chunk_by_ukey
253-
.get(c)
254-
.map(|chunk| ChunkWrapper::new(chunk.ukey(), compilation))
255-
}))
259+
.build_chunk_graph_artifact
260+
.named_chunks
261+
.get(&name)
262+
.and_then(|c| {
263+
compilation
264+
.build_chunk_graph_artifact
265+
.chunk_by_ukey
266+
.get(c)
267+
.map(|chunk| ChunkWrapper::new(chunk.ukey(), compilation))
268+
}),
269+
)
256270
}
257271

258272
#[napi]
@@ -261,6 +275,7 @@ impl JsCompilation {
261275

262276
Ok(
263277
compilation
278+
.build_chunk_graph_artifact
264279
.named_chunk_groups
265280
.keys()
266281
.cloned()
@@ -273,6 +288,7 @@ impl JsCompilation {
273288
let compilation = self.as_ref()?;
274289
Ok(
275290
compilation
291+
.build_chunk_graph_artifact
276292
.named_chunk_groups
277293
.get(&name)
278294
.map(|ukey| ChunkGroupWrapper::new(*ukey, compilation)),
@@ -394,6 +410,7 @@ impl JsCompilation {
394410

395411
Ok(
396412
compilation
413+
.build_chunk_graph_artifact
397414
.chunk_group_by_ukey
398415
.keys()
399416
.map(|ukey| ChunkGroupWrapper::new(*ukey, compilation))

0 commit comments

Comments
 (0)