@@ -19,8 +19,10 @@ use rspack_binding_values::{
1919 JsContextModuleFactoryBeforeResolveDataWrapper , JsContextModuleFactoryBeforeResolveResult ,
2020 JsCreateData , JsExecuteModuleArg , JsFactorizeArgs , JsFactorizeOutput , JsModuleWrapper ,
2121 JsNormalModuleFactoryCreateModuleArgs , JsResolveArgs , JsResolveForSchemeArgs ,
22- JsResolveForSchemeOutput , JsResolveOutput , JsRuntimeGlobals , JsRuntimeModule , JsRuntimeModuleArg ,
23- JsRuntimeRequirementInTreeArg , JsRuntimeRequirementInTreeResult , ToJsCompatSourceOwned ,
22+ JsResolveForSchemeOutput , JsResolveOutput , JsRsdoctorAsset , JsRsdoctorChunkGraph ,
23+ JsRsdoctorModuleGraph , JsRsdoctorModuleSource , JsRuntimeGlobals , JsRuntimeModule ,
24+ JsRuntimeModuleArg , JsRuntimeRequirementInTreeArg , JsRuntimeRequirementInTreeResult ,
25+ ToJsCompatSourceOwned ,
2426} ;
2527use rspack_collections:: IdentifierSet ;
2628use rspack_core:: {
@@ -67,6 +69,12 @@ use rspack_plugin_html::{
6769 HtmlPluginBeforeAssetTagGenerationHook , HtmlPluginBeforeEmit , HtmlPluginBeforeEmitHook ,
6870} ;
6971use rspack_plugin_javascript:: { JavascriptModulesChunkHash , JavascriptModulesChunkHashHook } ;
72+ use rspack_plugin_rsdoctor:: {
73+ RsdoctorAsset , RsdoctorChunkGraph , RsdoctorModuleGraph , RsdoctorModuleSource ,
74+ RsdoctorPluginAssets , RsdoctorPluginAssetsHook , RsdoctorPluginChunkGraph ,
75+ RsdoctorPluginChunkGraphHook , RsdoctorPluginModuleGraph , RsdoctorPluginModuleGraphHook ,
76+ RsdoctorPluginModuleSources , RsdoctorPluginModuleSourcesHook ,
77+ } ;
7078
7179#[ napi( object) ]
7280pub struct JsTap < ' f > {
@@ -386,6 +394,10 @@ pub enum RegisterJsTapKind {
386394 HtmlPluginAfterTemplateExecution ,
387395 HtmlPluginBeforeEmit ,
388396 HtmlPluginAfterEmit ,
397+ RsdoctorPluginModuleGraph ,
398+ RsdoctorPluginChunkGraph ,
399+ RsdoctorPluginModuleSources ,
400+ RsdoctorPluginAssets ,
389401}
390402
391403#[ derive( Default , Clone ) ]
@@ -559,6 +571,7 @@ pub struct RegisterJsTaps {
559571 ts_type = "(stages: Array<number>) => Array<{ function: ((arg: JsChunk) => Buffer); stage: number; }>"
560572 ) ]
561573 pub register_javascript_modules_chunk_hash_taps : RegisterFunction < JsChunkWrapper , Buffer > ,
574+ // html plugin
562575 #[ napi(
563576 ts_type = "(stages: Array<number>) => Array<{ function: ((arg: JsBeforeAssetTagGenerationData) => JsBeforeAssetTagGenerationData); stage: number; }>"
564577 ) ]
@@ -589,6 +602,27 @@ pub struct RegisterJsTaps {
589602 ) ]
590603 pub register_html_plugin_after_emit_taps :
591604 RegisterFunction < JsAfterEmitData , Promise < JsAfterEmitData > > ,
605+ // rsdoctor plugin
606+ #[ napi(
607+ ts_type = "(stages: Array<number>) => Array<{ function: ((arg: JsRsdoctorModuleGraph) => Promise<boolean | undefined>); stage: number; }>"
608+ ) ]
609+ pub register_rsdoctor_plugin_module_graph_taps :
610+ RegisterFunction < JsRsdoctorModuleGraph , Promise < Option < bool > > > ,
611+ #[ napi(
612+ ts_type = "(stages: Array<number>) => Array<{ function: ((arg: JsRsdoctorChunkGraph) => Promise<boolean | undefined>); stage: number; }>"
613+ ) ]
614+ pub register_rsdoctor_plugin_chunk_graph_taps :
615+ RegisterFunction < JsRsdoctorChunkGraph , Promise < Option < bool > > > ,
616+ #[ napi(
617+ ts_type = "(stages: Array<number>) => Array<{ function: ((arg: Vec<JsRsdoctorModuleSource>) => Promise<boolean | undefined>); stage: number; }>"
618+ ) ]
619+ pub register_rsdoctor_plugin_module_sources_taps :
620+ RegisterFunction < Vec < JsRsdoctorModuleSource > , Promise < Option < bool > > > ,
621+ #[ napi(
622+ ts_type = "(stages: Array<number>) => Array<{ function: ((arg: Vec<JsRsdoctorAsset>) => Promise<boolean | undefined>); stage: number; }>"
623+ ) ]
624+ pub register_rsdoctor_plugin_assets_taps :
625+ RegisterFunction < Vec < JsRsdoctorAsset > , Promise < Option < bool > > > ,
592626}
593627
594628/* Compiler Hooks */
@@ -936,6 +970,43 @@ define_register!(
936970 skip = true ,
937971) ;
938972
973+ /* Rsdoctor Plugin Hooks */
974+ define_register ! (
975+ RegisterRsdoctorPluginModuleGraphTaps ,
976+ tap = RsdoctorPluginModuleGraphTap <JsRsdoctorModuleGraph , Promise <Option <bool >>> @ RsdoctorPluginModuleGraphHook ,
977+ cache = true ,
978+ sync = false ,
979+ kind = RegisterJsTapKind :: RsdoctorPluginModuleGraph ,
980+ skip = true ,
981+ ) ;
982+
983+ define_register ! (
984+ RegisterRsdoctorPluginChunkGraphTaps ,
985+ tap = RsdoctorPluginChunkGraphTap <JsRsdoctorChunkGraph , Promise <Option <bool >>> @ RsdoctorPluginChunkGraphHook ,
986+ cache = true ,
987+ sync = false ,
988+ kind = RegisterJsTapKind :: RsdoctorPluginChunkGraph ,
989+ skip = true ,
990+ ) ;
991+
992+ define_register ! (
993+ RegisterRsdoctorPluginAssetsTaps ,
994+ tap = RsdoctorPluginAssetsTap <Vec <JsRsdoctorAsset >, Promise <Option <bool >>> @ RsdoctorPluginAssetsHook ,
995+ cache = true ,
996+ sync = false ,
997+ kind = RegisterJsTapKind :: RsdoctorPluginAssets ,
998+ skip = true ,
999+ ) ;
1000+
1001+ define_register ! (
1002+ RegisterRsdoctorPluginModuleSourcesTaps ,
1003+ tap = RsdoctorPluginModuleSourcesTap <Vec <JsRsdoctorModuleSource >, Promise <Option <bool >>> @ RsdoctorPluginModuleSourcesHook ,
1004+ cache = true ,
1005+ sync = false ,
1006+ kind = RegisterJsTapKind :: RsdoctorPluginModuleSources ,
1007+ skip = true ,
1008+ ) ;
1009+
9391010#[ async_trait]
9401011impl CompilerThisCompilation for CompilerThisCompilationTap {
9411012 async fn run (
@@ -1768,3 +1839,77 @@ impl HtmlPluginAfterEmit for HtmlPluginAfterEmitTap {
17681839 self . stage
17691840 }
17701841}
1842+
1843+ #[ async_trait]
1844+ impl RsdoctorPluginModuleGraph for RsdoctorPluginModuleGraphTap {
1845+ async fn run ( & self , data : & mut RsdoctorModuleGraph ) -> rspack_error:: Result < Option < bool > > {
1846+ let data = std:: mem:: take ( data) ;
1847+ let bail = self
1848+ . function
1849+ . call_with_promise ( JsRsdoctorModuleGraph :: from ( data) )
1850+ . await ?;
1851+ Ok ( bail)
1852+ }
1853+
1854+ fn stage ( & self ) -> i32 {
1855+ self . stage
1856+ }
1857+ }
1858+
1859+ #[ async_trait]
1860+ impl RsdoctorPluginChunkGraph for RsdoctorPluginChunkGraphTap {
1861+ async fn run ( & self , data : & mut RsdoctorChunkGraph ) -> rspack_error:: Result < Option < bool > > {
1862+ let data = std:: mem:: take ( data) ;
1863+ let bail = self
1864+ . function
1865+ . call_with_promise ( JsRsdoctorChunkGraph :: from ( data) )
1866+ . await ?;
1867+ Ok ( bail)
1868+ }
1869+
1870+ fn stage ( & self ) -> i32 {
1871+ self . stage
1872+ }
1873+ }
1874+
1875+ #[ async_trait]
1876+ impl RsdoctorPluginModuleSources for RsdoctorPluginModuleSourcesTap {
1877+ async fn run ( & self , data : & mut Vec < RsdoctorModuleSource > ) -> rspack_error:: Result < Option < bool > > {
1878+ let data = std:: mem:: take ( data) ;
1879+ let bail = self
1880+ . function
1881+ . call_with_promise (
1882+ data
1883+ . into_iter ( )
1884+ . map ( JsRsdoctorModuleSource :: from)
1885+ . collect :: < Vec < _ > > ( ) ,
1886+ )
1887+ . await ?;
1888+ Ok ( bail)
1889+ }
1890+
1891+ fn stage ( & self ) -> i32 {
1892+ self . stage
1893+ }
1894+ }
1895+
1896+ #[ async_trait]
1897+ impl RsdoctorPluginAssets for RsdoctorPluginAssetsTap {
1898+ async fn run ( & self , data : & mut Vec < RsdoctorAsset > ) -> rspack_error:: Result < Option < bool > > {
1899+ let data = std:: mem:: take ( data) ;
1900+ let bail = self
1901+ . function
1902+ . call_with_promise (
1903+ data
1904+ . into_iter ( )
1905+ . map ( JsRsdoctorAsset :: from)
1906+ . collect :: < Vec < _ > > ( ) ,
1907+ )
1908+ . await ?;
1909+ Ok ( bail)
1910+ }
1911+
1912+ fn stage ( & self ) -> i32 {
1913+ self . stage
1914+ }
1915+ }
0 commit comments