refactor(plugin/api): Expand the proxy crate (#4290)

This commit is contained in:
OJ Kwon 2022-04-09 00:47:43 -07:00 committed by GitHub
parent 6fe4ee79be
commit cf7ca5076a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 40 additions and 28 deletions

24
Cargo.lock generated
View File

@ -2857,7 +2857,7 @@ dependencies = [
"swc_error_reporters",
"swc_node_base",
"swc_node_comments",
"swc_plugin_comments",
"swc_plugin_proxy",
"swc_plugin_runner",
"swc_visit",
"testing",
@ -3855,17 +3855,8 @@ dependencies = [
"swc_ecma_quote",
"swc_ecma_utils",
"swc_ecma_visit",
"swc_plugin_comments",
"swc_plugin_macro",
]
[[package]]
name = "swc_plugin_comments"
version = "0.1.2"
dependencies = [
"better_scoped_tls",
"rkyv",
"swc_common",
"swc_plugin_proxy",
]
[[package]]
@ -3877,6 +3868,15 @@ dependencies = [
"syn",
]
[[package]]
name = "swc_plugin_proxy"
version = "0.1.2"
dependencies = [
"better_scoped_tls",
"rkyv",
"swc_common",
]
[[package]]
name = "swc_plugin_runner"
version = "0.50.4"
@ -3892,7 +3892,7 @@ dependencies = [
"swc_ecma_loader",
"swc_ecma_parser",
"swc_ecma_visit",
"swc_plugin_comments",
"swc_plugin_proxy",
"testing",
"tracing",
"wasmer",

View File

@ -15,7 +15,7 @@ members = [
"crates/swc_plugin_macro",
"crates/swc_plugin_runner",
"crates/swc_plugin_testing",
"crates/swc_plugin_comments",
"crates/swc_plugin_proxy",
"crates/swc_timer",
"crates/swc_webpack_ast",
"crates/wasm",

View File

@ -28,7 +28,7 @@ concurrent = [
]
debug = ["swc_ecma_visit/debug"]
node = ["napi", "napi-derive"]
plugin = ["swc_plugin_runner", "swc_plugin_comments/plugin-rt"]
plugin = ["swc_plugin_runner", "swc_plugin_proxy/plugin-rt"]
[dependencies]
ahash = "0.7.4"
@ -81,7 +81,7 @@ swc_ecma_visit = {version = "0.61.0", path = "../swc_ecma_visit"}
swc_ecmascript = {version = "0.143.0", path = "../swc_ecmascript"}
swc_error_reporters = {version = "0.1.0", path = "../swc_error_reporters"}
swc_node_comments = {version = "0.4.0", path = "../swc_node_comments"}
swc_plugin_comments = {version = "0.1.1", path = "../swc_plugin_comments", optional = true}
swc_plugin_proxy = {version = "0.1.1", path = "../swc_plugin_proxy", optional = true}
swc_plugin_runner = {version = "0.50.0", path = "../swc_plugin_runner", optional = true, default-features = false}
swc_visit = {version = "0.3.0", path = "../swc_visit"}
tracing = "0.1.32"

View File

@ -84,8 +84,8 @@ impl RustPlugins {
let should_enable_comments_proxy = self.comments.is_some();
// Set comments once per whole plugin transform execution.
swc_plugin_comments::COMMENTS.set(
&swc_plugin_comments::HostCommentsStorage {
swc_plugin_proxy::COMMENTS.set(
&swc_plugin_proxy::HostCommentsStorage {
inner: self.comments.clone(),
},
|| {
@ -163,8 +163,8 @@ impl RustPlugins {
let should_enable_comments_proxy = self.comments.is_some();
swc_plugin_comments::COMMENTS.set(
&swc_plugin_comments::HostCommentsStorage {
swc_plugin_proxy::COMMENTS.set(
&swc_plugin_proxy::HostCommentsStorage {
inner: self.comments.clone(),
},
|| {

View File

@ -29,7 +29,7 @@ swc_ecma_ast = { version = "0.75.0", path = "../swc_ecma_ast", features = [
swc_ecma_quote = { version = "0.11.0", path = "../swc_ecma_quote", optional = true }
swc_ecma_visit = { version = "0.61.0", path = "../swc_ecma_visit" }
swc_ecma_utils = { version = "0.79.0", path = "../swc_ecma_utils" }
swc_plugin_comments = { version = "0.1.1", path = "../swc_plugin_comments", features = [
swc_plugin_proxy = { version = "0.1.1", path = "../swc_plugin_proxy", features = [
"plugin-mode",
] }
swc_plugin_macro = { version = "0.4.0", path = "../swc_plugin_macro" }

View File

@ -8,7 +8,7 @@ pub use swc_common::{
pub mod comments {
pub use swc_common::comments::{Comment, CommentKind, Comments};
pub use swc_plugin_comments::PluginCommentsProxy;
pub use swc_plugin_proxy::PluginCommentsProxy;
}
pub mod source_map {
@ -43,10 +43,10 @@ pub mod errors {
pub mod environment {
pub use crate::handler::*;
}
use swc_plugin_comments::PluginCommentsProxy;
// We don't set target cfg as it'll block macro expansions
// in ide (i.e rust-analyzer) or non-wasm target `cargo check`
pub use swc_plugin_macro::plugin_transform;
use swc_plugin_proxy::PluginCommentsProxy;
#[cfg(target_arch = "wasm32")]
mod allocation;
#[cfg(target_arch = "wasm32")]

View File

@ -1,9 +1,9 @@
[package]
authors = ["강동윤 <kdy1997.dev@gmail.com>", "OJ Kwon <kwon.ohjoong@gmail.com>"]
description = "Internal sharable storage for the comments between host to the plugin"
description = "Proxy structs to the hosts original structs for the plugin"
edition = "2021"
license = "Apache-2.0"
name = "swc_plugin_comments"
name = "swc_plugin_proxy"
repository = "https://github.com/swc-project/swc.git"
version = "0.1.2"

View File

@ -1,8 +1,8 @@
mod host_comments_storage;
mod plugin_comments_proxy;
#[cfg(feature = "plugin-rt")]
pub use host_comments_storage::{HostCommentsStorage, COMMENTS};
mod plugin_comments_proxy;
pub use plugin_comments_proxy::CommentsVecPtr;
#[cfg(feature = "plugin-mode")]
pub use plugin_comments_proxy::PluginCommentsProxy;

View File

@ -0,0 +1,9 @@
mod comments;
mod source_map;
pub use comments::CommentsVecPtr;
#[cfg(feature = "plugin-mode")]
pub use comments::PluginCommentsProxy;
#[cfg(feature = "plugin-rt")]
pub use comments::{HostCommentsStorage, COMMENTS};
#[cfg(feature = "plugin-mode")]
pub use source_map::PluginSourceMapProxy;

View File

@ -0,0 +1,2 @@
mod plugin_source_map_proxy;
pub use plugin_source_map_proxy::PluginSourceMapProxy;

View File

@ -0,0 +1 @@
pub struct PluginSourceMapProxy {}

View File

@ -33,7 +33,7 @@ swc_common = { version = "0.17.20", path = "../swc_common", features = [
swc_ecma_ast = { version = "0.75.0", path = "../swc_ecma_ast", features = [
"rkyv-impl",
] }
swc_plugin_comments = { version = "0.1.1", path = "../swc_plugin_comments", features = [
swc_plugin_proxy = { version = "0.1.1", path = "../swc_plugin_proxy", features = [
"plugin-rt",
] }
tracing = "0.1.32"

View File

@ -6,7 +6,7 @@ use swc_common::{
plugin::Serialized,
BytePos,
};
use swc_plugin_comments::{CommentsVecPtr, COMMENTS};
use swc_plugin_proxy::{CommentsVecPtr, COMMENTS};
use wasmer::{LazyInit, Memory, NativeFunc};
use crate::memory_interop::{copy_bytes_into_host, write_into_memory_view};