-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
REFACTOR use rolldown to replace SWC for bundler (#362)
* REFACTOR use rolldown to replace SWC for bundler * remove redundant * simplify alias plugin * clippy * doc
- Loading branch information
1 parent
a2c486c
commit 7ebfc6b
Showing
11 changed files
with
2,077 additions
and
1,529 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//! Deskulpt alias plugin for rolldown. | ||
use std::borrow::Cow; | ||
use std::collections::HashMap; | ||
use std::sync::Arc; | ||
|
||
use rolldown::plugin::{ | ||
HookResolveIdArgs, HookResolveIdOutput, HookResolveIdReturn, Plugin, PluginContext, | ||
PluginContextResolveOptions, | ||
}; | ||
|
||
/// Deskulpt alias plugin. | ||
/// | ||
/// This is a simplified version of the rolldown built-in alias plugin since we | ||
/// only need a subset of its functionalities. | ||
/// | ||
/// Based on the given alias mapping, this plugin will replace the original | ||
/// imports with the aliased imports. Note that the aliased imports need to be | ||
/// either resolvable or externalized to avoid bundling errors. | ||
#[derive(Debug)] | ||
pub struct AliasPlugin( | ||
/// The alias mapping from original imports to aliased imports. | ||
pub HashMap<String, String>, | ||
); | ||
|
||
impl Plugin for AliasPlugin { | ||
fn name(&self) -> Cow<'static, str> { | ||
Cow::Borrowed("deskulpt:alias") | ||
} | ||
|
||
async fn resolve_id( | ||
&self, | ||
ctx: &PluginContext, | ||
args: &HookResolveIdArgs<'_>, | ||
) -> HookResolveIdReturn { | ||
let importee = args.specifier; | ||
let update_id = match self.0.get(importee) { | ||
Some(alias) => alias, | ||
None => return Ok(None), | ||
}; | ||
|
||
Ok(ctx | ||
.resolve( | ||
update_id, | ||
None, | ||
Some(PluginContextResolveOptions { | ||
import_kind: args.kind, | ||
skip_self: true, | ||
custom: Arc::clone(&args.custom), | ||
}), | ||
) | ||
.await? | ||
.map(|resolved_id| { | ||
Some(HookResolveIdOutput { | ||
id: resolved_id.id.to_string(), | ||
..Default::default() | ||
}) | ||
})?) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.