Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions .changeset/large-waves-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_core: patch
swc: patch
---

fix(es/plugin): use `#[cfg]` to avoid compilation error
17 changes: 12 additions & 5 deletions crates/swc/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,30 @@ 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();

if cfg!(feature = "manual-tokio-runtime") {
self.apply_inner(n)
} else {
#[cfg(feature = "manual-tokio-runtime")]
let ret = self
.apply_inner(n)
.with_context(|| format!("failed to invoke plugin on '{filename:?}'"));

#[cfg(not(feature = "manual-tokio-runtime"))]
let ret = {
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