mirror of
https://github.com/swc-project/swc.git
synced 2024-11-22 06:46:41 +03:00
feat(es/plugin): Introduce manual-tokio-runtmie
to swc
crate (#9701)
**Description:** This can cause a problem for Wasm plugin runtimes.
This commit is contained in:
parent
1c3eaf684a
commit
97298c4e36
6
.changeset/shiny-bears-thank.md
Normal file
6
.changeset/shiny-bears-thank.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
swc: patch
|
||||
swc_core: patch
|
||||
---
|
||||
|
||||
feat(es/plugin): Introduce `manual-tokio-runtmie` to `swc` crate
|
@ -47,6 +47,8 @@ plugin_transform_host_js = ["swc_plugin_runner/plugin_transform_host_js"]
|
||||
plugin_transform_host_native = [
|
||||
"swc_plugin_runner/plugin_transform_host_native",
|
||||
]
|
||||
# Do not inject tokio runtime while running plugin transforms
|
||||
manual-tokio-runtmie = []
|
||||
|
||||
[dependencies]
|
||||
anyhow = { workspace = true }
|
||||
|
@ -55,19 +55,19 @@ impl RustPlugins {
|
||||
return Ok(n);
|
||||
}
|
||||
|
||||
let fut = async move {
|
||||
self.apply_inner(n).with_context(|| {
|
||||
format!(
|
||||
"failed to invoke plugin on '{:?}'",
|
||||
self.metadata_context.filename
|
||||
)
|
||||
})
|
||||
};
|
||||
if let Ok(handle) = tokio::runtime::Handle::try_current() {
|
||||
handle.block_on(fut)
|
||||
let filename = self.metadata_context.filename.clone();
|
||||
|
||||
if cfg!(feature = "manual-tokio-runtmie") {
|
||||
self.apply_inner(n)
|
||||
} else {
|
||||
tokio::runtime::Runtime::new().unwrap().block_on(fut)
|
||||
let fut = async move { self.apply_inner(n) };
|
||||
if let Ok(handle) = tokio::runtime::Handle::try_current() {
|
||||
handle.block_on(fut)
|
||||
} else {
|
||||
tokio::runtime::Runtime::new().unwrap().block_on(fut)
|
||||
}
|
||||
}
|
||||
.with_context(|| format!("failed to invoke plugin on '{filename:?}'"))
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "info", skip_all, name = "apply_plugins")]
|
||||
|
Loading…
Reference in New Issue
Block a user