@@ -17,7 +17,7 @@ use turbopack_ecmascript::{CustomTransformer, TransformContext};
1717pub struct SwcPluginModule (
1818 #[ turbo_tasks( trace_ignore, debug_ignore) ]
1919 #[ cfg( feature = "swc_ecma_transform_plugin" ) ]
20- pub swc_core:: plugin_runner:: plugin_module_bytes:: RawPluginModuleBytes ,
20+ pub swc_core:: plugin_runner:: plugin_module_bytes:: CompiledPluginModuleBytes ,
2121 // Dummy field to avoid turbo_tasks macro complaining about empty struct.
2222 // This is because we can't import CompiledPluginModuleBytes by default, it should be only
2323 // available for the target / platforms that support swc plugins (which can build wasmer)
@@ -28,10 +28,14 @@ impl SwcPluginModule {
2828 pub fn new ( plugin_name : & str , plugin_bytes : Vec < u8 > ) -> Self {
2929 #[ cfg( feature = "swc_ecma_transform_plugin" ) ]
3030 {
31- use swc_core:: plugin_runner:: plugin_module_bytes:: RawPluginModuleBytes ;
32- Self ( RawPluginModuleBytes :: new (
33- plugin_name. to_string ( ) ,
34- plugin_bytes,
31+ use swc_core:: plugin_runner:: plugin_module_bytes:: {
32+ CompiledPluginModuleBytes , RawPluginModuleBytes ,
33+ } ;
34+ use swc_plugin_backend_wasmer:: WasmerRuntime ;
35+
36+ Self ( CompiledPluginModuleBytes :: from_raw_module (
37+ & WasmerRuntime ,
38+ RawPluginModuleBytes :: new ( plugin_name. to_string ( ) , plugin_bytes) ,
3539 ) )
3640 }
3741
@@ -128,19 +132,22 @@ impl CustomTransformer for SwcEcmaTransformPluginsTransformer {
128132 } ,
129133 ecma:: ast:: Module ,
130134 plugin:: proxies:: { COMMENTS , HostCommentsStorage } ,
131- plugin_runner:: plugin_module_bytes:: PluginModuleBytes ,
132135 } ;
133-
134- let mut plugins = vec ! [ ] ;
135- for ( plugin_module, config) in & self . plugins {
136- let plugin_module = & plugin_module. await ?. 0 ;
137-
138- plugins. push ( (
139- plugin_module. get_module_name ( ) . to_string ( ) ,
140- config. clone ( ) ,
141- Box :: new ( plugin_module. clone ( ) ) ,
142- ) ) ;
143- }
136+ use swc_plugin_backend_wasmer:: WasmerRuntime ;
137+ use turbo_tasks:: TryJoinIterExt ;
138+
139+ let plugins = self
140+ . plugins
141+ . iter ( )
142+ . map ( async |( plugin_module, config) | {
143+ let plugin_module = plugin_module. await ?;
144+ Ok ( (
145+ config. clone ( ) ,
146+ Box :: new ( plugin_module. 0 . clone_module ( & WasmerRuntime ) ) ,
147+ ) )
148+ } )
149+ . try_join ( )
150+ . await ?;
144151
145152 let should_enable_comments_proxy =
146153 !ctx. comments . leading . is_empty ( ) && !ctx. comments . trailing . is_empty ( ) ;
@@ -195,7 +202,7 @@ impl CustomTransformer for SwcEcmaTransformPluginsTransformer {
195202 // Note: This doesn't mean plugin won't perform any se/deserialization: it
196203 // still have to construct from raw bytes internally to perform actual
197204 // transform.
198- for ( _plugin_name , plugin_config, plugin_module) in plugins. drain ( .. ) {
205+ for ( plugin_config, plugin_module) in plugins {
199206 let mut transform_plugin_executor =
200207 swc_core:: plugin_runner:: create_plugin_transform_executor (
201208 ctx. source_map ,
@@ -204,7 +211,7 @@ impl CustomTransformer for SwcEcmaTransformPluginsTransformer {
204211 None ,
205212 plugin_module,
206213 Some ( plugin_config) ,
207- Arc :: new ( swc_plugin_backend_wasmer :: WasmerRuntime ) ,
214+ Arc :: new ( WasmerRuntime ) ,
208215 ) ;
209216
210217 serialized_program = transform_plugin_executor
0 commit comments