Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions crates/swc/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,27 @@ struct RustPlugins {
impl RustPlugins {
#[cfg(feature = "plugin")]
fn apply(&mut self, n: Program) -> Result<Program, anyhow::Error> {
use anyhow::Context;
if self.plugins.is_none() || self.plugins.as_ref().unwrap().is_empty() {
return Ok(n);
}

let filename = self.metadata_context.filename.clone();
#[cfg(feature = "manual-tokio-runtime")]
let ret = self.apply_inner(n);

if cfg!(feature = "manual-tokio-runtime") {
self.apply_inner(n)
} else {
#[cfg(not(feature = "manual-tokio-runtime"))]
let ret = {
use anyhow::Context;
let filename = self.metadata_context.filename.clone();
let fut = async move { self.apply_inner(n) };
if let Ok(handle) = tokio::runtime::Handle::try_current() {
handle.block_on(fut)
} else {
SHARED_RUNTIME.block_on(fut)
}
}
.with_context(|| format!("failed to invoke plugin on '{filename:?}'"))
.with_context(|| format!("failed to invoke plugin on '{filename:?}'"))
};

ret
}

#[tracing::instrument(level = "info", skip_all, name = "apply_plugins")]
Expand Down
Loading