@@ -4,18 +4,18 @@ use std::sync::Arc;
44
55use anyhow:: { Context , Result } ;
66use common:: {
7- comments:: Comments ,
7+ comments:: SingleThreadedComments ,
88 errors:: Handler ,
99 plugin:: { metadata:: TransformPluginMetadataContext , serialized:: PluginSerializedBytes } ,
1010 Mark , SourceFile , GLOBALS ,
1111} ;
12- use par_iter:: iter:: { IndexedParallelIterator , IntoParallelRefIterator , ParallelIterator } ;
1312use rustc_hash:: FxHashMap ;
1413use serde:: Deserialize ;
1514use swc_config:: IsModule ;
1615use swc_ecma_ast:: EsVersion ;
1716use swc_ecma_parser:: Syntax ;
1817use swc_ecma_transforms:: resolver;
18+ use swc_plugin_proxy:: HostCommentsStorage ;
1919
2020use crate :: {
2121 config:: ErrorFormat ,
@@ -30,7 +30,7 @@ impl Compiler {
3030 fm : Arc < SourceFile > ,
3131 handler : & Handler ,
3232 opts : & WasmAnalysisOptions ,
33- comments : & dyn Comments ,
33+ comments : & SingleThreadedComments ,
3434 ) -> Result < String > {
3535 if cfg ! ( feature = "manual-tokio-runtime" ) {
3636 self . run_wasm_analysis_inner ( fm. clone ( ) , handler, opts, comments)
@@ -52,7 +52,7 @@ impl Compiler {
5252 fm : Arc < SourceFile > ,
5353 handler : & Handler ,
5454 opts : & WasmAnalysisOptions ,
55- comments : & dyn Comments ,
55+ comments : & SingleThreadedComments ,
5656 ) -> Result < String > {
5757 compile_wasm_plugins ( opts. cache_root . as_deref ( ) , & opts. plugins ) ?;
5858
@@ -91,15 +91,15 @@ impl Compiler {
9191
9292 let result = opts
9393 . plugins
94- . par_iter ( )
95- . with_min_len ( 1 )
94+ . iter ( )
9695 . map ( |p| {
9796 GLOBALS . set ( globals, || {
9897 self . inovke_wasm_analysis_plugin (
9998 & serialized,
10099 unresolved_mark,
101100 & transform_metadata_context,
102101 p,
102+ comments,
103103 )
104104 } )
105105 } )
@@ -119,55 +119,64 @@ impl Compiler {
119119 unresolved_mark : Mark ,
120120 transform_metadata_context : & Arc < TransformPluginMetadataContext > ,
121121 p : & PluginConfig ,
122+ comments : & SingleThreadedComments ,
122123 ) -> Result < FxHashMap < String , String > > {
123- let plugin_module_bytes = crate :: config:: PLUGIN_MODULE_CACHE
124- . inner
125- . get ( )
126- . unwrap ( )
127- . lock ( )
128- . get ( & p. 0 )
129- . expect ( "plugin module should be loaded" ) ;
130-
131- let plugin_name = plugin_module_bytes. get_module_name ( ) . to_string ( ) ;
132- let runtime = swc_plugin_runner:: wasix_runtime:: build_wasi_runtime (
133- crate :: config:: PLUGIN_MODULE_CACHE
134- . inner
135- . get ( )
136- . unwrap ( )
137- . lock ( )
138- . get_fs_cache_root ( )
139- . map ( std:: path:: PathBuf :: from) ,
140- ) ;
141- let mut transform_plugin_executor = swc_plugin_runner:: create_plugin_transform_executor (
142- & self . cm ,
143- & unresolved_mark,
144- transform_metadata_context,
145- plugin_module_bytes,
146- Some ( p. 1 . clone ( ) ) ,
147- runtime,
148- ) ;
149-
150- let span = tracing:: span!(
151- tracing:: Level :: INFO ,
152- "execute_plugin_runner" ,
153- plugin_module = p. 0 . as_str( )
124+ swc_plugin_proxy:: COMMENTS . set (
125+ & HostCommentsStorage {
126+ inner : Some ( comments. clone ( ) ) ,
127+ } ,
128+ || {
129+ let plugin_module_bytes = crate :: config:: PLUGIN_MODULE_CACHE
130+ . inner
131+ . get ( )
132+ . unwrap ( )
133+ . lock ( )
134+ . get ( & p. 0 )
135+ . expect ( "plugin module should be loaded" ) ;
136+
137+ let plugin_name = plugin_module_bytes. get_module_name ( ) . to_string ( ) ;
138+ let runtime = swc_plugin_runner:: wasix_runtime:: build_wasi_runtime (
139+ crate :: config:: PLUGIN_MODULE_CACHE
140+ . inner
141+ . get ( )
142+ . unwrap ( )
143+ . lock ( )
144+ . get_fs_cache_root ( )
145+ . map ( std:: path:: PathBuf :: from) ,
146+ ) ;
147+ let mut transform_plugin_executor =
148+ swc_plugin_runner:: create_plugin_transform_executor (
149+ & self . cm ,
150+ & unresolved_mark,
151+ transform_metadata_context,
152+ plugin_module_bytes,
153+ Some ( p. 1 . clone ( ) ) ,
154+ runtime,
155+ ) ;
156+
157+ let span = tracing:: span!(
158+ tracing:: Level :: INFO ,
159+ "execute_plugin_runner" ,
160+ plugin_module = p. 0 . as_str( )
161+ )
162+ . entered ( ) ;
163+
164+ let ( result, output) = swc_transform_common:: output:: capture ( || {
165+ transform_plugin_executor
166+ . transform ( serialized, Some ( true ) )
167+ . with_context ( || {
168+ format ! (
169+ "failed to invoke `{}` as js analysis plugin at {}" ,
170+ & p. 0 , plugin_name
171+ )
172+ } )
173+ } ) ;
174+ result?;
175+ drop ( span) ;
176+
177+ Ok ( output)
178+ } ,
154179 )
155- . entered ( ) ;
156-
157- let ( result, output) = swc_transform_common:: output:: capture ( || {
158- transform_plugin_executor
159- . transform ( serialized, Some ( true ) )
160- . with_context ( || {
161- format ! (
162- "failed to invoke `{}` as js analysis plugin at {}" ,
163- & p. 0 , plugin_name
164- )
165- } )
166- } ) ;
167- result?;
168- drop ( span) ;
169-
170- Ok ( output)
171180 }
172181}
173182
0 commit comments