Skip to content

Commit 9cbeb80

Browse files
authored
feat: add chunk.getEntryOptions() (#9093)
1 parent 8477ca6 commit 9cbeb80

File tree

9 files changed

+65
-13
lines changed

9 files changed

+65
-13
lines changed

crates/node_binding/binding.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export declare class JsChunk {
6767
getAllInitialChunks(): JsChunk[]
6868
getAllReferencedChunks(): JsChunk[]
6969
groups(): JsChunkGroup[]
70+
getEntryOptions(): EntryOptionsDTO | undefined
7071
}
7172

7273
export declare class JsChunkGraph {

crates/rspack_binding_values/src/chunk.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use napi_derive::napi;
55
use rspack_core::{Chunk, ChunkUkey, Compilation, CompilationId};
66
use rspack_napi::OneShotRef;
77

8+
use crate::compilation::entries::EntryOptionsDTO;
89
use crate::JsChunkGroupWrapper;
910

1011
#[napi]
@@ -234,6 +235,15 @@ impl JsChunk {
234235
.collect::<Vec<_>>(),
235236
)
236237
}
238+
239+
#[napi(ts_return_type = "EntryOptionsDTO | undefined")]
240+
pub fn get_entry_options(&self) -> napi::Result<Option<EntryOptionsDTO>> {
241+
let (compilation, chunk) = self.as_ref()?;
242+
243+
let entry_options = chunk.get_entry_options(&compilation.chunk_group_by_ukey);
244+
245+
Ok(entry_options.map(|options| EntryOptionsDTO::new(options.clone())))
246+
}
237247
}
238248

239249
thread_local! {

crates/rspack_binding_values/src/compilation/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
mod dependencies;
2-
mod entries;
2+
pub mod entries;
33

44
use std::cell::RefCell;
55
use std::collections::HashMap;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
it("should compile", function (done) {
2+
done()
3+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/** @type {import("@rspack/core").Configuration} */
2+
module.exports = {
3+
target: "node",
4+
entry: {
5+
main: {
6+
import: "./index.js",
7+
chunkLoading: "async-node"
8+
}
9+
},
10+
plugins: [
11+
{
12+
/**@param {import("@rspack/core").Compiler} compiler */
13+
apply(compiler) {
14+
compiler.hooks.thisCompilation.tap("test", compilation => {
15+
compilation.hooks.afterSeal.tap("test", () => {
16+
let entrypoint = compilation.entrypoints.get("main");
17+
18+
entrypoint.chunks.forEach(chunk => {
19+
const entryOptions = chunk.getEntryOptions();
20+
21+
expect(entryOptions).not.toBeUndefined();
22+
expect(entryOptions.chunkLoading).toBe("async-node");
23+
});
24+
});
25+
});
26+
}
27+
}
28+
]
29+
};

packages/rspack/etc/core.api.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,8 @@ export class Chunk {
461461
name: Record<string | number, string>;
462462
};
463463
// (undocumented)
464+
getEntryOptions(): Readonly<EntryOptions> | undefined;
465+
// (undocumented)
464466
get groupsIterable(): ReadonlySet<ChunkGroup>;
465467
// (undocumented)
466468
readonly hash?: string;
@@ -6862,11 +6864,9 @@ export const rspackOptions: z.ZodObject<{
68626864
}, "strict", z.ZodTypeAny, {
68636865
modules?: boolean | undefined;
68646866
chunks?: boolean | undefined;
6865-
ids?: boolean | undefined;
6866-
runtime?: boolean | undefined;
6867-
hash?: boolean | undefined;
68686867
all?: boolean | undefined;
68696868
version?: boolean | undefined;
6869+
runtime?: boolean | undefined;
68706870
publicPath?: boolean | undefined;
68716871
preset?: boolean | "none" | "verbose" | "normal" | "errors-only" | "errors-warnings" | "minimal" | "detailed" | "summary" | undefined;
68726872
assets?: boolean | undefined;
@@ -6877,10 +6877,12 @@ export const rspackOptions: z.ZodObject<{
68776877
errors?: boolean | undefined;
68786878
errorsCount?: boolean | undefined;
68796879
colors?: boolean | undefined;
6880+
hash?: boolean | undefined;
68806881
reasons?: boolean | undefined;
68816882
outputPath?: boolean | undefined;
68826883
chunkModules?: boolean | undefined;
68836884
chunkRelations?: boolean | undefined;
6885+
ids?: boolean | undefined;
68846886
timings?: boolean | undefined;
68856887
builtAt?: boolean | undefined;
68866888
moduleAssets?: boolean | undefined;
@@ -6939,11 +6941,9 @@ export const rspackOptions: z.ZodObject<{
69396941
}, {
69406942
modules?: boolean | undefined;
69416943
chunks?: boolean | undefined;
6942-
ids?: boolean | undefined;
6943-
runtime?: boolean | undefined;
6944-
hash?: boolean | undefined;
69456944
all?: boolean | undefined;
69466945
version?: boolean | undefined;
6946+
runtime?: boolean | undefined;
69476947
publicPath?: boolean | undefined;
69486948
preset?: boolean | "none" | "verbose" | "normal" | "errors-only" | "errors-warnings" | "minimal" | "detailed" | "summary" | undefined;
69496949
assets?: boolean | undefined;
@@ -6954,10 +6954,12 @@ export const rspackOptions: z.ZodObject<{
69546954
errors?: boolean | undefined;
69556955
errorsCount?: boolean | undefined;
69566956
colors?: boolean | undefined;
6957+
hash?: boolean | undefined;
69576958
reasons?: boolean | undefined;
69586959
outputPath?: boolean | undefined;
69596960
chunkModules?: boolean | undefined;
69606961
chunkRelations?: boolean | undefined;
6962+
ids?: boolean | undefined;
69616963
timings?: boolean | undefined;
69626964
builtAt?: boolean | undefined;
69636965
moduleAssets?: boolean | undefined;
@@ -8644,11 +8646,9 @@ export const rspackOptions: z.ZodObject<{
86448646
stats?: boolean | "none" | "verbose" | "normal" | "errors-only" | "errors-warnings" | "minimal" | "detailed" | "summary" | {
86458647
modules?: boolean | undefined;
86468648
chunks?: boolean | undefined;
8647-
ids?: boolean | undefined;
8648-
runtime?: boolean | undefined;
8649-
hash?: boolean | undefined;
86508649
all?: boolean | undefined;
86518650
version?: boolean | undefined;
8651+
runtime?: boolean | undefined;
86528652
publicPath?: boolean | undefined;
86538653
preset?: boolean | "none" | "verbose" | "normal" | "errors-only" | "errors-warnings" | "minimal" | "detailed" | "summary" | undefined;
86548654
assets?: boolean | undefined;
@@ -8659,10 +8659,12 @@ export const rspackOptions: z.ZodObject<{
86598659
errors?: boolean | undefined;
86608660
errorsCount?: boolean | undefined;
86618661
colors?: boolean | undefined;
8662+
hash?: boolean | undefined;
86628663
reasons?: boolean | undefined;
86638664
outputPath?: boolean | undefined;
86648665
chunkModules?: boolean | undefined;
86658666
chunkRelations?: boolean | undefined;
8667+
ids?: boolean | undefined;
86668668
timings?: boolean | undefined;
86678669
builtAt?: boolean | undefined;
86688670
moduleAssets?: boolean | undefined;
@@ -9250,11 +9252,9 @@ export const rspackOptions: z.ZodObject<{
92509252
stats?: boolean | "none" | "verbose" | "normal" | "errors-only" | "errors-warnings" | "minimal" | "detailed" | "summary" | {
92519253
modules?: boolean | undefined;
92529254
chunks?: boolean | undefined;
9253-
ids?: boolean | undefined;
9254-
runtime?: boolean | undefined;
9255-
hash?: boolean | undefined;
92569255
all?: boolean | undefined;
92579256
version?: boolean | undefined;
9257+
runtime?: boolean | undefined;
92589258
publicPath?: boolean | undefined;
92599259
preset?: boolean | "none" | "verbose" | "normal" | "errors-only" | "errors-warnings" | "minimal" | "detailed" | "summary" | undefined;
92609260
assets?: boolean | undefined;
@@ -9265,10 +9265,12 @@ export const rspackOptions: z.ZodObject<{
92659265
errors?: boolean | undefined;
92669266
errorsCount?: boolean | undefined;
92679267
colors?: boolean | undefined;
9268+
hash?: boolean | undefined;
92689269
reasons?: boolean | undefined;
92699270
outputPath?: boolean | undefined;
92709271
chunkModules?: boolean | undefined;
92719272
chunkRelations?: boolean | undefined;
9273+
ids?: boolean | undefined;
92729274
timings?: boolean | undefined;
92739275
builtAt?: boolean | undefined;
92749276
moduleAssets?: boolean | undefined;

packages/rspack/src/Chunk.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { JsChunk } from "@rspack/binding";
22

33
import { ChunkGroup } from "./ChunkGroup";
4+
import type { EntryOptions } from "./exports";
45

56
const CHUNK_MAPPINGS = new WeakMap<JsChunk, Chunk>();
67

@@ -194,4 +195,8 @@ export class Chunk {
194195
.map(binding => Chunk.__from_binding(binding))
195196
);
196197
}
198+
199+
getEntryOptions(): Readonly<EntryOptions> | undefined {
200+
return this.#inner.getEntryOptions();
201+
}
197202
}

website/docs/en/types/chunk.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Chunk = {
1212
getAllAsyncChunks(): Iterable<Chunk>;
1313
getAllInitialChunks(): Iterable<Chunk>;
1414
getAllReferencedChunks(): Iterable<Chunk>;
15+
getEntryOptions(): EntryOptions | undefined;
1516
get groupsIterable(): Iterable<ChunkGroup>;
1617
hash?: Readonly<string>;
1718
hasRuntime(): boolean;

website/docs/zh/types/chunk.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Chunk = {
1212
getAllAsyncChunks(): Iterable<Chunk>;
1313
getAllInitialChunks(): Iterable<Chunk>;
1414
getAllReferencedChunks(): Iterable<Chunk>;
15+
getEntryOptions(): EntryOptions | undefined;
1516
get groupsIterable(): Iterable<ChunkGroup>;
1617
hash?: Readonly<string>;
1718
hasRuntime(): boolean;

0 commit comments

Comments
 (0)