mirror of
https://github.com/swc-project/swc.git
synced 2024-10-04 04:07:18 +03:00
refactor(bindings): Use published swc_core
as interface (#5482)
This commit is contained in:
parent
7b727caa9a
commit
83417b6f75
1720
Cargo.lock
generated
1720
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -48,7 +48,7 @@ tracing-chrome = "0.5.0"
|
||||
tracing-futures = "0.2.5"
|
||||
tracing-subscriber = { version = "0.3.9", features = ["env-filter"] }
|
||||
|
||||
swc_core = { path = "../swc_core", features = [
|
||||
swc_core = { version = "0.7.5", features = [
|
||||
"ast",
|
||||
"common_concurrent",
|
||||
"bundler",
|
||||
|
@ -20,7 +20,7 @@ swc_v2 = []
|
||||
plugin = ["swc_core/plugin_transform_host_js"]
|
||||
|
||||
[dependencies]
|
||||
swc_core = { path = "../swc_core", features = [
|
||||
swc_core = { version = "0.7.5", features = [
|
||||
"common_perf",
|
||||
"binding_macro_wasm",
|
||||
] }
|
||||
|
@ -9,7 +9,7 @@ include = ["Cargo.toml", "src/**/*.rs"]
|
||||
license = "Apache-2.0"
|
||||
name = "swc"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.214.4"
|
||||
version = "0.214.5"
|
||||
|
||||
[lib]
|
||||
bench = false
|
||||
@ -90,7 +90,7 @@ swc_ecma_visit = { version = "0.76.5", path = "../swc_ecma_visit" }
|
||||
swc_error_reporters = { version = "0.11.4", path = "../swc_error_reporters" }
|
||||
swc_node_comments = { version = "0.14.4", path = "../swc_node_comments" }
|
||||
swc_plugin_proxy = { version = "0.18.5", path = "../swc_plugin_proxy", optional = true }
|
||||
swc_plugin_runner = { version = "0.71.6", path = "../swc_plugin_runner", optional = true, default-features = false }
|
||||
swc_plugin_runner = { version = "0.71.7", path = "../swc_plugin_runner", optional = true, default-features = false }
|
||||
swc_timer = { version = "0.15.4", path = "../swc_timer" }
|
||||
swc_visit = { version = "0.5.2", path = "../swc_visit" }
|
||||
tracing = "0.1.32"
|
||||
|
@ -26,7 +26,7 @@ rayon = "1"
|
||||
relative-path = "1.6.1"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = { version = "1", features = ["unbounded_depth"] }
|
||||
swc_core = { version = "0.7.4", path = "../swc_core", features = [
|
||||
swc_core = { version = "0.7.5", features = [
|
||||
"trace_macro",
|
||||
"common_concurrent",
|
||||
"base",
|
||||
|
@ -24,8 +24,8 @@ perf = ["parking_lot"]
|
||||
plugin-base = ["anyhow", "rkyv-impl", "diagnostic-serde"]
|
||||
plugin-mode = ["plugin-base"]
|
||||
plugin-rt = ["plugin-base"]
|
||||
plugin_transform_schema_v1 = []
|
||||
plugin_transform_schema_vtest = []
|
||||
plugin_transform_schema_v1 = ["plugin-base"]
|
||||
plugin_transform_schema_vtest = ["plugin-base"]
|
||||
rkyv-impl = ["rkyv", "bytecheck", "swc_atoms/rkyv-impl"]
|
||||
tty-emitter = ["atty", "termcolor"]
|
||||
|
||||
|
@ -2,3 +2,25 @@ pub mod metadata;
|
||||
#[cfg(feature = "plugin-base")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "plugin-base")))]
|
||||
pub mod serialized;
|
||||
|
||||
/**
|
||||
* Compile-time version constant for the AST struct schema's version.
|
||||
*
|
||||
* NOTE: this is for PARTIAL compatibility only, supporting if AST struct
|
||||
* adds new properties without changing / removing existing properties.
|
||||
*
|
||||
* - When adding a new properties to the AST struct:
|
||||
* 1. Create a new feature flag in cargo.toml
|
||||
* 2. Create a new schema version with new feature flag.
|
||||
* 3. Create a new AST struct with compile time feature flag with newly
|
||||
* added properties. Previous struct should remain with existing feature
|
||||
* flag, or add previous latest feature flag.
|
||||
*
|
||||
* - When removing, or changing existing properties in the AST struct: TBD
|
||||
*/
|
||||
#[cfg(feature = "plugin_transform_schema_v1")]
|
||||
pub const PLUGIN_TRANSFORM_AST_SCHEMA_VERSION: u32 = 1;
|
||||
|
||||
// Reserved for the testing purpose.
|
||||
#[cfg(feature = "plugin_transform_schema_vtest")]
|
||||
pub const PLUGIN_TRANSFORM_AST_SCHEMA_VERSION: u32 = u32::MAX - 1;
|
||||
|
@ -3,28 +3,6 @@ use std::any::type_name;
|
||||
use anyhow::Error;
|
||||
use rkyv::Deserialize;
|
||||
|
||||
/**
|
||||
* Compile-time version constant for the AST struct schema's version.
|
||||
*
|
||||
* NOTE: this is for PARTIAL compatibility only, supporting if AST struct
|
||||
* adds new properties without changing / removing existing properties.
|
||||
*
|
||||
* - When adding a new properties to the AST struct:
|
||||
* 1. Create a new feature flag in cargo.toml
|
||||
* 2. Create a new schema version with new feature flag.
|
||||
* 3. Create a new AST struct with compile time feature flag with newly
|
||||
* added properties. Previous struct should remain with existing feature
|
||||
* flag, or add previous latest feature flag.
|
||||
*
|
||||
* - When removing, or changing existing properties in the AST struct: TBD
|
||||
*/
|
||||
#[cfg(feature = "plugin_transform_schema_v1")]
|
||||
pub const PLUGIN_TRANSFORM_AST_SCHEMA_VERSION: u32 = 1;
|
||||
|
||||
// Reserved for the testing purpose.
|
||||
#[cfg(feature = "plugin_transform_schema_vtest")]
|
||||
pub const PLUGIN_TRANSFORM_AST_SCHEMA_VERSION: u32 = u32::MAX - 1;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
#[cfg_attr(
|
||||
|
@ -6,7 +6,7 @@ edition = "2021"
|
||||
license = "Apache-2.0"
|
||||
name = "swc_core"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.7.5"
|
||||
version = "0.7.6"
|
||||
[package.metadata.docs.rs]
|
||||
features = [
|
||||
"common_perf",
|
||||
@ -225,7 +225,7 @@ wasmer-wasi = { optional = true, version = "2.3.0", default-features = false }
|
||||
|
||||
# swc_* dependencies
|
||||
binding_macros = { optional = true, version = "0.2.3", path = "../binding_macros" }
|
||||
swc = { optional = true, version = "0.214.4", path = "../swc" }
|
||||
swc = { optional = true, version = "0.214.5", path = "../swc" }
|
||||
swc_atoms = { optional = true, version = "0.4.5", path = "../swc_atoms" }
|
||||
swc_bundler = { optional = true, version = "0.177.3", path = "../swc_bundler" }
|
||||
swc_common = { optional = true, version = "0.27.6", path = "../swc_common" }
|
||||
@ -241,11 +241,11 @@ swc_node_base = { optional = true, version = "0.5.5", path = "../s
|
||||
swc_node_bundler = { optional = true, version = "0.0.1", path = "../swc_node_bundler" }
|
||||
swc_nodejs_common = { optional = true, version = "0.0.1", path = "../swc_nodejs_common" }
|
||||
swc_plugin = { optional = true, version = "0.89.0", path = "../swc_plugin" }
|
||||
swc_plugin_macro = { optional = true, version = "0.9.2", path = "../swc_plugin_macro" }
|
||||
swc_plugin_macro = { optional = true, version = "0.9.3", path = "../swc_plugin_macro" }
|
||||
swc_plugin_proxy = { optional = true, version = "0.18.5", path = "../swc_plugin_proxy" }
|
||||
swc_trace_macro = { optional = true, version = "0.1.2", path = "../swc_trace_macro" }
|
||||
# TODO: eventually swc_plugin_runner needs to remove default features
|
||||
swc_plugin_runner = { optional = true, version = "0.71.6", path = "../swc_plugin_runner", default-features = false }
|
||||
swc_plugin_runner = { optional = true, version = "0.71.7", path = "../swc_plugin_runner", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
testing = { version = "0.29.4", path = "../testing" }
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0"
|
||||
name = "swc_plugin_macro"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.9.2"
|
||||
version = "0.9.3"
|
||||
|
||||
[lib]
|
||||
bench = false
|
||||
|
@ -81,7 +81,7 @@ fn handle_func(func: ItemFn) -> TokenStream {
|
||||
|
||||
#[no_mangle]
|
||||
pub fn #transform_schema_version_ident() -> u32 {
|
||||
swc_core::common::plugin::serialized::PLUGIN_TRANSFORM_AST_SCHEMA_VERSION
|
||||
swc_core::common::plugin::PLUGIN_TRANSFORM_AST_SCHEMA_VERSION
|
||||
}
|
||||
|
||||
// Macro to allow compose plugin's transform function without manual pointer operation.
|
||||
|
@ -6,7 +6,7 @@ edition = "2021"
|
||||
license = "Apache-2.0"
|
||||
name = "swc_plugin_runner"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.71.6"
|
||||
version = "0.71.7"
|
||||
|
||||
[lib]
|
||||
bench = false
|
||||
|
@ -2,10 +2,15 @@ use std::sync::Arc;
|
||||
|
||||
use anyhow::{anyhow, Error};
|
||||
use parking_lot::Mutex;
|
||||
#[cfg(any(
|
||||
feature = "plugin_transform_schema_v1",
|
||||
feature = "plugin_transform_schema_vtest"
|
||||
))]
|
||||
use swc_common::plugin::PLUGIN_TRANSFORM_AST_SCHEMA_VERSION;
|
||||
use swc_common::{
|
||||
plugin::{
|
||||
metadata::TransformPluginMetadataContext,
|
||||
serialized::{PluginError, PluginSerializedBytes, PLUGIN_TRANSFORM_AST_SCHEMA_VERSION},
|
||||
serialized::{PluginError, PluginSerializedBytes},
|
||||
},
|
||||
SourceMap,
|
||||
};
|
||||
@ -18,6 +23,13 @@ pub struct TransformExecutor {
|
||||
// Main transform interface plugin exports
|
||||
exported_plugin_transform: wasmer::NativeFunc<(i32, i32, u32, i32), i32>,
|
||||
// Schema version interface exports
|
||||
#[cfg_attr(
|
||||
not(any(
|
||||
feature = "plugin_transform_schema_v1",
|
||||
feature = "plugin_transform_schema_vtest"
|
||||
)),
|
||||
allow(unused)
|
||||
)]
|
||||
exported_plugin_transform_schema_version: wasmer::NativeFunc<(), u32>,
|
||||
// `__free` function automatically exported via swc_plugin sdk to allow deallocation in guest
|
||||
// memory space
|
||||
@ -127,10 +139,13 @@ impl TransformExecutor {
|
||||
* Host should appropriately handle if plugin is not compatible to the
|
||||
* current runtime.
|
||||
*/
|
||||
#[allow(unreachable_code)]
|
||||
pub fn is_transform_schema_compatible(&self) -> Result<bool, Error> {
|
||||
let plugin_schema_version = self.exported_plugin_transform_schema_version.call();
|
||||
|
||||
match plugin_schema_version {
|
||||
#[cfg(any(
|
||||
feature = "plugin_transform_schema_v1",
|
||||
feature = "plugin_transform_schema_vtest"
|
||||
))]
|
||||
return match self.exported_plugin_transform_schema_version.call() {
|
||||
Ok(plugin_schema_version) => {
|
||||
let host_schema_version = PLUGIN_TRANSFORM_AST_SCHEMA_VERSION;
|
||||
|
||||
@ -142,7 +157,16 @@ impl TransformExecutor {
|
||||
}
|
||||
}
|
||||
Err(e) => Err(anyhow!("Failed to call plugin's schema version: {}", e)),
|
||||
}
|
||||
};
|
||||
|
||||
#[cfg(not(all(
|
||||
feature = "plugin_transform_schema_v1",
|
||||
feature = "plugin_transform_schema_vtest"
|
||||
)))]
|
||||
anyhow::bail!(
|
||||
"Plugin runner cannot detect plugin's schema version. Ensure host is compiled with \
|
||||
proper versions"
|
||||
)
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "info", skip_all)]
|
||||
|
@ -1219,7 +1219,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_core"
|
||||
version = "0.7.5"
|
||||
version = "0.7.6"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"swc_atoms",
|
||||
|
Loading…
Reference in New Issue
Block a user