swc_plugin_runner/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#![cfg_attr(not(feature = "__rkyv"), allow(warnings))]

use std::sync::Arc;

use swc_common::{plugin::metadata::TransformPluginMetadataContext, SourceMap};
use transform_executor::TransformExecutor;

pub mod cache;
mod host_environment;
#[cfg(feature = "__rkyv")]
mod imported_fn;
#[cfg(feature = "__rkyv")]
mod memory_interop;
pub mod plugin_module_bytes;
mod transform_executor;
pub mod wasix_runtime;

use plugin_module_bytes::PluginModuleBytes;

/**
 * Creates an executor to run plugin binaries.
 */
#[cfg(feature = "__rkyv")]
pub fn create_plugin_transform_executor(
    source_map: &Arc<SourceMap>,
    unresolved_mark: &swc_common::Mark,
    metadata_context: &Arc<TransformPluginMetadataContext>,
    plugin_module: Box<dyn PluginModuleBytes>,
    plugin_config: Option<serde_json::Value>,
    runtime: Option<Arc<dyn wasmer_wasix::Runtime + Send + Sync>>,
) -> TransformExecutor {
    TransformExecutor::new(
        plugin_module,
        source_map,
        unresolved_mark,
        metadata_context,
        plugin_config,
        runtime,
    )
}

#[cfg(not(feature = "__rkyv"))]
pub fn create_plugin_transform_executor(
    source_map: &Arc<SourceMap>,
    unresolved_mark: &swc_common::Mark,
    metadata_context: &Arc<TransformPluginMetadataContext>,
    plugin_module: Box<dyn PluginModuleBytes>,
    plugin_config: Option<serde_json::Value>,
    runtime: Option<()>,
) -> TransformExecutor {
    unimplemented!("Transform plugin cannot be used without serialization support")
}