Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export declare class JsChunk {
getAllInitialChunks(): JsChunk[]
getAllReferencedChunks(): JsChunk[]
groups(): JsChunkGroup[]
getEntryOptions(): EntryOptionsDTO | undefined
}

export declare class JsChunkGraph {
Expand Down
10 changes: 10 additions & 0 deletions crates/rspack_binding_values/src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use napi_derive::napi;
use rspack_core::{Chunk, ChunkUkey, Compilation, CompilationId};
use rspack_napi::OneShotRef;

use crate::compilation::entries::EntryOptionsDTO;
use crate::JsChunkGroupWrapper;

#[napi]
Expand Down Expand Up @@ -234,6 +235,15 @@ impl JsChunk {
.collect::<Vec<_>>(),
)
}

#[napi(ts_return_type = "EntryOptionsDTO | undefined")]
pub fn get_entry_options(&self) -> napi::Result<Option<EntryOptionsDTO>> {
let (compilation, chunk) = self.as_ref()?;

let entry_options = chunk.get_entry_options(&compilation.chunk_group_by_ukey);

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

thread_local! {
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_binding_values/src/compilation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod dependencies;
mod entries;
pub mod entries;

use std::cell::RefCell;
use std::collections::HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it("should compile", function (done) {
done()
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
target: "node",
entry: {
main: {
import: "./index.js",
chunkLoading: "async-node"
}
},
plugins: [
{
/**@param {import("@rspack/core").Compiler} compiler */
apply(compiler) {
compiler.hooks.thisCompilation.tap("test", compilation => {
compilation.hooks.afterSeal.tap("test", () => {
let entrypoint = compilation.entrypoints.get("main");

entrypoint.chunks.forEach(chunk => {
const entryOptions = chunk.getEntryOptions();

expect(entryOptions).not.toBeUndefined();
expect(entryOptions.chunkLoading).toBe("async-node");
});
});
});
}
}
]
};
26 changes: 14 additions & 12 deletions packages/rspack/etc/core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ export class Chunk {
name: Record<string | number, string>;
};
// (undocumented)
getEntryOptions(): Readonly<EntryOptions> | undefined;
// (undocumented)
get groupsIterable(): ReadonlySet<ChunkGroup>;
// (undocumented)
readonly hash?: string;
Expand Down Expand Up @@ -6862,11 +6864,9 @@ export const rspackOptions: z.ZodObject<{
}, "strict", z.ZodTypeAny, {
modules?: boolean | undefined;
chunks?: boolean | undefined;
ids?: boolean | undefined;
runtime?: boolean | undefined;
hash?: boolean | undefined;
all?: boolean | undefined;
version?: boolean | undefined;
runtime?: boolean | undefined;
publicPath?: boolean | undefined;
preset?: boolean | "none" | "verbose" | "normal" | "errors-only" | "errors-warnings" | "minimal" | "detailed" | "summary" | undefined;
assets?: boolean | undefined;
Expand All @@ -6877,10 +6877,12 @@ export const rspackOptions: z.ZodObject<{
errors?: boolean | undefined;
errorsCount?: boolean | undefined;
colors?: boolean | undefined;
hash?: boolean | undefined;
reasons?: boolean | undefined;
outputPath?: boolean | undefined;
chunkModules?: boolean | undefined;
chunkRelations?: boolean | undefined;
ids?: boolean | undefined;
timings?: boolean | undefined;
builtAt?: boolean | undefined;
moduleAssets?: boolean | undefined;
Expand Down Expand Up @@ -6939,11 +6941,9 @@ export const rspackOptions: z.ZodObject<{
}, {
modules?: boolean | undefined;
chunks?: boolean | undefined;
ids?: boolean | undefined;
runtime?: boolean | undefined;
hash?: boolean | undefined;
all?: boolean | undefined;
version?: boolean | undefined;
runtime?: boolean | undefined;
publicPath?: boolean | undefined;
preset?: boolean | "none" | "verbose" | "normal" | "errors-only" | "errors-warnings" | "minimal" | "detailed" | "summary" | undefined;
assets?: boolean | undefined;
Expand All @@ -6954,10 +6954,12 @@ export const rspackOptions: z.ZodObject<{
errors?: boolean | undefined;
errorsCount?: boolean | undefined;
colors?: boolean | undefined;
hash?: boolean | undefined;
reasons?: boolean | undefined;
outputPath?: boolean | undefined;
chunkModules?: boolean | undefined;
chunkRelations?: boolean | undefined;
ids?: boolean | undefined;
timings?: boolean | undefined;
builtAt?: boolean | undefined;
moduleAssets?: boolean | undefined;
Expand Down Expand Up @@ -8644,11 +8646,9 @@ export const rspackOptions: z.ZodObject<{
stats?: boolean | "none" | "verbose" | "normal" | "errors-only" | "errors-warnings" | "minimal" | "detailed" | "summary" | {
modules?: boolean | undefined;
chunks?: boolean | undefined;
ids?: boolean | undefined;
runtime?: boolean | undefined;
hash?: boolean | undefined;
all?: boolean | undefined;
version?: boolean | undefined;
runtime?: boolean | undefined;
publicPath?: boolean | undefined;
preset?: boolean | "none" | "verbose" | "normal" | "errors-only" | "errors-warnings" | "minimal" | "detailed" | "summary" | undefined;
assets?: boolean | undefined;
Expand All @@ -8659,10 +8659,12 @@ export const rspackOptions: z.ZodObject<{
errors?: boolean | undefined;
errorsCount?: boolean | undefined;
colors?: boolean | undefined;
hash?: boolean | undefined;
reasons?: boolean | undefined;
outputPath?: boolean | undefined;
chunkModules?: boolean | undefined;
chunkRelations?: boolean | undefined;
ids?: boolean | undefined;
timings?: boolean | undefined;
builtAt?: boolean | undefined;
moduleAssets?: boolean | undefined;
Expand Down Expand Up @@ -9250,11 +9252,9 @@ export const rspackOptions: z.ZodObject<{
stats?: boolean | "none" | "verbose" | "normal" | "errors-only" | "errors-warnings" | "minimal" | "detailed" | "summary" | {
modules?: boolean | undefined;
chunks?: boolean | undefined;
ids?: boolean | undefined;
runtime?: boolean | undefined;
hash?: boolean | undefined;
all?: boolean | undefined;
version?: boolean | undefined;
runtime?: boolean | undefined;
publicPath?: boolean | undefined;
preset?: boolean | "none" | "verbose" | "normal" | "errors-only" | "errors-warnings" | "minimal" | "detailed" | "summary" | undefined;
assets?: boolean | undefined;
Expand All @@ -9265,10 +9265,12 @@ export const rspackOptions: z.ZodObject<{
errors?: boolean | undefined;
errorsCount?: boolean | undefined;
colors?: boolean | undefined;
hash?: boolean | undefined;
reasons?: boolean | undefined;
outputPath?: boolean | undefined;
chunkModules?: boolean | undefined;
chunkRelations?: boolean | undefined;
ids?: boolean | undefined;
timings?: boolean | undefined;
builtAt?: boolean | undefined;
moduleAssets?: boolean | undefined;
Expand Down
5 changes: 5 additions & 0 deletions packages/rspack/src/Chunk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { JsChunk } from "@rspack/binding";

import { ChunkGroup } from "./ChunkGroup";
import type { EntryOptions } from "./exports";

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

Expand Down Expand Up @@ -194,4 +195,8 @@ export class Chunk {
.map(binding => Chunk.__from_binding(binding))
);
}

getEntryOptions(): Readonly<EntryOptions> | undefined {
return this.#inner.getEntryOptions();
}
}
1 change: 1 addition & 0 deletions website/docs/en/types/chunk.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Chunk = {
getAllAsyncChunks(): Iterable<Chunk>;
getAllInitialChunks(): Iterable<Chunk>;
getAllReferencedChunks(): Iterable<Chunk>;
getEntryOptions(): EntryOptions | undefined;
get groupsIterable(): Iterable<ChunkGroup>;
hash?: Readonly<string>;
hasRuntime(): boolean;
Expand Down
1 change: 1 addition & 0 deletions website/docs/zh/types/chunk.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Chunk = {
getAllAsyncChunks(): Iterable<Chunk>;
getAllInitialChunks(): Iterable<Chunk>;
getAllReferencedChunks(): Iterable<Chunk>;
getEntryOptions(): EntryOptions | undefined;
get groupsIterable(): Iterable<ChunkGroup>;
hash?: Readonly<string>;
hasRuntime(): boolean;
Expand Down