Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support more moduleGraph and chunkGraph js api #8833

Draft
wants to merge 42 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e03536a
feat: getBlockChunkGroup
SyMind Dec 24, 2024
7b7ff44
feat: getParentModule
SyMind Dec 24, 2024
3033a1f
Merge remote-tracking branch 'origin' into more-js-api
SyMind Dec 24, 2024
7080cef
fix: namedChunks
SyMind Dec 24, 2024
44c32f1
fix: path join
SyMind Dec 24, 2024
42e8947
Merge branch 'main' into more-js-api
SyMind Dec 24, 2024
dc31e04
fix: global generator
SyMind Dec 24, 2024
2ff8e89
feat: support module.libIdent
SyMind Dec 24, 2024
c07560d
feat: layer support function
SyMind Dec 25, 2024
aa6ce64
fix: get_resolved_module
SyMind Dec 25, 2024
efd8415
feat: getParentBlockIndex
SyMind Dec 25, 2024
f8d092a
feat: dependency supports inheriting hierarchical information
SyMind Dec 25, 2024
fff46b3
feat: support moduleGraph.isAsync
SyMind Dec 25, 2024
9edc315
feat: chunkGroup.childrenIterable
SyMind Dec 25, 2024
f815aeb
fix: dependency and bindingDependencyFactory
SyMind Dec 25, 2024
69ec00e
fix: setbinding for ModuleDependency in addInclude
SyMind Dec 25, 2024
1ad7074
fix: buildinfo
SyMind Dec 26, 2024
3f22b9e
feat: resolvedModule and originModule in connection
SyMind Dec 26, 2024
751225f
feat: support issuerLayer in external function
SyMind Dec 26, 2024
b41a402
fix: remove memoizeValue
SyMind Dec 26, 2024
15b07b6
chore: merge origin main
SyMind Dec 26, 2024
25669cf
fix: alias priority
SyMind Dec 27, 2024
1b19786
feat: dependency.ids
SyMind Dec 27, 2024
fd62ae7
feat: module.resourceResolveData
SyMind Dec 27, 2024
65d184b
Merge branch 'main' into more-js-api
hardfist Dec 28, 2024
de106ff
Merge remote-tracking branch 'origin' into more-js-api
SyMind Dec 29, 2024
7bb8cb7
feat: match_resource
SyMind Dec 30, 2024
88e89b2
feat: set dependencies and includeDependencies in EntryData
SyMind Dec 30, 2024
aad9dce
fix: hack to fix buildInfo in module
SyMind Jan 3, 2025
e42020c
feat: add contextInfo.issuerLayer for nmf resolve hooks
ahabhgk Jan 3, 2025
2302529
fix: alias prioity
SyMind Jan 3, 2025
611bd6a
fix: override alias
SyMind Jan 3, 2025
43406b7
add test for override alias
ahabhgk Jan 3, 2025
0de9320
entrypoints should ordered
ahabhgk Jan 4, 2025
16534d8
fix: add_include clean entry
SyMind Jan 6, 2025
f82d3d6
feat: add constructor name for concatenated module
SyMind Jan 6, 2025
f696097
perf: one shot ref for class instance
SyMind Jan 7, 2025
8ded34b
perf: add_include
SyMind Jan 7, 2025
0496ac8
perf: cache immutable js field
SyMind Jan 7, 2025
81c1a2e
perf: js source map
SyMind Jan 8, 2025
7969ce0
fix incremental forget new entries
ahabhgk Jan 8, 2025
a4d9759
fix module rule use entry func arguments
ahabhgk Jan 9, 2025
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
86 changes: 58 additions & 28 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ export declare class ExternalObject<T> {
[K: symbol]: T
}
}
export declare class EntryDataDto {
get dependencies(): JsDependency[]
get includeDependencies(): JsDependency[]
get options(): EntryOptionsDto
}
export type EntryDataDTO = EntryDataDto

export declare class EntryOptionsDto {
get name(): string | undefined
set name(name: string | undefined)
Expand Down Expand Up @@ -76,13 +69,15 @@ export declare class JsChunkGraph {
getChunkModulesIterableBySourceType(chunk: JsChunk, sourceType: string): JsModule[]
getModuleChunks(module: JsModule): JsChunk[]
getModuleId(jsModule: JsModule): string | null
getBlockChunkGroup(jsBlock: JsDependenciesBlock): JsChunkGroup | null
}

export declare class JsChunkGroup {
get chunks(): JsChunk[]
get index(): number | undefined
get name(): string | undefined
get origins(): Array<JsChunkGroupOrigin>
get childrenIterable(): JsChunkGroup[]
isInitial(): boolean
getParents(): JsChunkGroup[]
getRuntimeChunk(): JsChunk
Expand All @@ -99,7 +94,7 @@ export declare class JsCompilation {
getOptimizationBailout(): Array<JsStatsOptimizationBailout>
getChunks(): JsChunk[]
getNamedChunkKeys(): Array<string>
getNamedChunk(name: string): JsChunk
getNamedChunk(name: string): JsChunk | null
getNamedChunkGroupKeys(): Array<string>
getNamedChunkGroup(name: string): JsChunkGroup
setAssetSource(name: string, source: JsCompatSource): void
Expand All @@ -110,7 +105,7 @@ export declare class JsCompilation {
emitAsset(filename: string, source: JsCompatSource, assetInfo: JsAssetInfo): void
deleteAsset(filename: string): void
renameAsset(filename: string, newName: string): void
get entrypoints(): Record<string, JsChunkGroup>
get entrypoints(): JsChunkGroup[]
get chunkGroups(): JsChunkGroup[]
get hash(): string | null
dependencies(): JsDependencies
Expand Down Expand Up @@ -140,7 +135,7 @@ export declare class JsCompilation {
addRuntimeModule(chunk: JsChunk, runtimeModule: JsAddingRuntimeModule): void
get moduleGraph(): JsModuleGraph
get chunkGraph(): JsChunkGraph
addInclude(args: [string, RawDependency, JsEntryOptions | undefined][], callback: (errMsg: Error | null, results: [string | null, JsModule][]) => void): void
addInclude(args: [string, RawDependency, RawEntryOptions | undefined][], callback: (errMsg: Error | null, results: [string | null, JsDependency | null, JsModule | null][]) => void): void
}

export declare class JsContextModuleFactoryAfterResolveData {
Expand Down Expand Up @@ -194,17 +189,26 @@ export declare class JsDependency {
get request(): string | undefined
get critical(): boolean
set critical(val: boolean)
get ids(): Array<string> | undefined
}

export declare class JsEntries {
clear(): void
get size(): number
has(key: string): boolean
set(key: string, value: JsEntryData | EntryDataDto): void
set(key: string, value: RawEntryData): void
delete(key: string): boolean
get(key: string): EntryDataDto | undefined
get(key: string): JsEntryData | undefined
keys(): Array<string>
values(): Array<EntryDataDto>
values(): Array<JsEntryData>
}

export declare class JsEntryData {
get dependencies(): JsDependency[]
set dependencies(dependencies: Array<JsDependency>)
get includeDependencies(): JsDependency[]
set includeDependencies(dependencies: Array<JsDependency>)
get options(): EntryOptionsDto
}

export declare class JsExportsInfo {
Expand All @@ -215,23 +219,28 @@ export declare class JsExportsInfo {
}

export declare class JsModule {
get context(): string | undefined
get constructorName(): string
get context(): string | null
get originalSource(): JsCompatSource | undefined
get resource(): string | undefined
get resource(): string | null
get moduleIdentifier(): string
get nameForCondition(): string | undefined
get request(): string | undefined
get request(): string | null
get userRequest(): string | undefined
set userRequest(val: string)
get rawRequest(): string | undefined
get rawRequest(): string | null
get factoryMeta(): JsFactoryMeta | undefined
get type(): string
get layer(): string | undefined
get layer(): string | null
get blocks(): JsDependenciesBlock[]
get dependencies(): JsDependency[]
size(ty?: string | undefined | null): number
get modules(): JsModule[] | undefined
get useSourceMap(): boolean
libIdent(options: JsLibIdentOptions): string | null
get resourceResolveData(): JsResourceData | null
get matchResource(): string | null
get loaders(): Array<string> | undefined
}

export declare class JsModuleGraph {
Expand All @@ -243,11 +252,16 @@ export declare class JsModuleGraph {
getConnection(dependency: JsDependency): JsModuleGraphConnection | null
getOutgoingConnections(module: JsModule): JsModuleGraphConnection[]
getIncomingConnections(module: JsModule): JsModuleGraphConnection[]
getParentModule(jsDependency: JsDependency): JsModule | null
getParentBlockIndex(jsDependency: JsDependency): number
isAsync(module: JsModule): boolean
}

export declare class JsModuleGraphConnection {
get dependency(): JsDependency
get module(): JsModule | null
get resolvedModule(): JsModule | null
get originModule(): JsModule | null
}

export declare class JsResolver {
Expand Down Expand Up @@ -402,6 +416,7 @@ export interface JsAfterResolveData {
request: string
context: string
issuer: string
issuerLayer?: string
fileDependencies: Array<string>
contextDependencies: Array<string>
missingDependencies: Array<string>
Expand Down Expand Up @@ -504,6 +519,7 @@ export interface JsBeforeResolveArgs {
request: string
context: string
issuer: string
issuerLayer?: string
}

export interface JsBuildMeta {
Expand Down Expand Up @@ -613,12 +629,6 @@ export interface JsDiagnosticLocation {
length: number
}

export interface JsEntryData {
dependencies: Array<JsDependency>
includeDependencies: Array<JsDependency>
options: JsEntryOptions
}

export interface JsEntryOptions {
name?: string
runtime?: false | string
Expand Down Expand Up @@ -660,6 +670,7 @@ export interface JsFactorizeArgs {
request: string
context: string
issuer: string
issuerLayer?: string
}

export interface JsFactoryMeta {
Expand Down Expand Up @@ -687,6 +698,10 @@ export interface JsHtmlPluginTag {
asset?: string
}

export interface JsLibIdentOptions {
context: string
}

export interface JsLibraryAuxiliaryComment {
root?: string
commonjs?: string
Expand Down Expand Up @@ -718,15 +733,13 @@ export interface JsLibraryOptions {

export interface JsLoaderContext {
resourceData: Readonly<JsResourceData>
/** Will be deprecated. Use module.module_identifier instead */
_moduleIdentifier: Readonly<string>
_module: JsModule
hot: Readonly<boolean>
/** Content maybe empty in pitching stage */
content: null | Buffer
content: null | Buffer | string
additionalData?: any
__internal__parseMeta: Record<string, string>
sourceMap?: Buffer
sourceMap?: JsSourceMap
cacheable: boolean
fileDependencies: Array<string>
contextDependencies: Array<string>
Expand Down Expand Up @@ -791,6 +804,7 @@ export interface JsResolveArgs {
request: string
context: string
issuer: string
issuerLayer?: string
}

export interface JsResolveForSchemeArgs {
Expand Down Expand Up @@ -854,6 +868,16 @@ export interface JsRuntimeRequirementInTreeResult {
runtimeRequirements: JsRuntimeGlobals
}

export interface JsSourceMap {
version: number
file?: string
sources: Array<string>
sourcesContent?: Array<string>
names: Array<string>
mappings: string
sourceRoot?: string
}

export interface JsStatsAsset {
type: string
name: string
Expand Down Expand Up @@ -1361,6 +1385,12 @@ export interface RawDynamicEntryPluginOptions {
entry: () => Promise<RawEntryDynamicResult[]>
}

export interface RawEntryData {
dependencies: Array<JsDependency>
includeDependencies: Array<JsDependency>
options: JsEntryOptions
}

export interface RawEntryDynamicResult {
import: Array<string>
options: JsEntryOptions
Expand Down
4 changes: 4 additions & 0 deletions crates/node_binding/src/plugins/interceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,7 @@ impl NormalModuleFactoryBeforeResolve for NormalModuleFactoryBeforeResolveTap {
.as_ref()
.map(|issuer| issuer.to_string())
.unwrap_or_default(),
issuer_layer: data.issuer_layer.clone(),
})
.await
{
Expand Down Expand Up @@ -1424,6 +1425,7 @@ impl NormalModuleFactoryFactorize for NormalModuleFactoryFactorizeTap {
.as_ref()
.map(|issuer| issuer.to_string())
.unwrap_or_default(),
issuer_layer: data.issuer_layer.clone(),
})
.await
{
Expand Down Expand Up @@ -1461,6 +1463,7 @@ impl NormalModuleFactoryResolve for NormalModuleFactoryResolveTap {
.as_ref()
.map(|issuer| issuer.to_string())
.unwrap_or_default(),
issuer_layer: data.issuer_layer.clone(),
})
.await
{
Expand Down Expand Up @@ -1523,6 +1526,7 @@ impl NormalModuleFactoryAfterResolve for NormalModuleFactoryAfterResolveTap {
.as_ref()
.map(|issuer| issuer.to_string())
.unwrap_or_default(),
issuer_layer: data.issuer_layer.clone(),
file_dependencies: data
.file_dependencies
.clone()
Expand Down
18 changes: 17 additions & 1 deletion crates/rspack_binding_values/src/chunk_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use napi::Result;
use napi_derive::napi;
use rspack_core::{ChunkGraph, Compilation, SourceType};

use crate::{JsChunk, JsChunkWrapper, JsModule, JsModuleWrapper};
use crate::{
JsChunk, JsChunkGroupWrapper, JsChunkWrapper, JsDependenciesBlock, JsModule, JsModuleWrapper,
};

#[napi]
pub struct JsChunkGraph {
Expand Down Expand Up @@ -127,4 +129,18 @@ impl JsChunkGraph {
.map(|module_id| module_id.as_str()),
)
}

#[napi(ts_return_type = "JsChunkGroup | null")]
pub fn get_block_chunk_group(
&self,
js_block: &JsDependenciesBlock,
) -> napi::Result<Option<JsChunkGroupWrapper>> {
let compilation = self.as_ref()?;
Ok(
compilation
.chunk_graph
.get_block_chunk_group(&js_block.block_id, &compilation.chunk_group_by_ukey)
.map(|chunk_group| JsChunkGroupWrapper::new(chunk_group.ukey, compilation)),
)
}
}
14 changes: 11 additions & 3 deletions crates/rspack_binding_values/src/chunk_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,18 @@ impl JsChunkGroup {

Ok(js_origins)
}
}

#[napi]
impl JsChunkGroup {
#[napi(getter, ts_return_type = "JsChunkGroup[]")]
pub fn children_iterable(&self) -> napi::Result<Vec<JsChunkGroupWrapper>> {
let (compilation, chunk_graph) = self.as_ref()?;
Ok(
chunk_graph
.children_iterable()
.map(|ukey| JsChunkGroupWrapper::new(*ukey, compilation))
.collect::<Vec<_>>(),
)
}

#[napi]
pub fn is_initial(&self) -> napi::Result<bool> {
let (_, chunk_graph) = self.as_ref()?;
Expand Down
Loading