Skip to content

Commit

Permalink
REFACTOR use rolldown to replace SWC for bundler (#362)
Browse files Browse the repository at this point in the history
* REFACTOR use rolldown to replace SWC for bundler

* remove redundant

* simplify alias plugin

* clippy

* doc
  • Loading branch information
Charlie-XIAO authored Jan 14, 2025
1 parent a2c486c commit 7ebfc6b
Show file tree
Hide file tree
Showing 11 changed files with 2,077 additions and 1,529 deletions.
3,027 changes: 1,906 additions & 1,121 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ repository = "https://github.com/CSCI-SHU-410-SE-Project/Deskulpt"
[workspace.dependencies]
anyhow = "1.0.87"
bincode = "1.3.3"
path-clean = "1.0.1"
dunce = "1.0.5"
objc2 = "0.5.2"
once_cell = "1.20.2"
open = "5.3.1"
oxc = "0.43.0"
path-clean = "1.0.1"
rolldown = { git = "https://github.com/rolldown/rolldown.git", tag = "v1.0.0-beta.1" }
rolldown_common = { git = "https://github.com/rolldown/rolldown.git", tag = "v1.0.0-beta.1" }
serde = "1.0.210"
serde_json = "1.0.128"
swc_core = "9.0.6"
tauri = "2.2.0"
tauri-build = "2.0.4"
tauri-plugin-clipboard-manager = "2.2.0"
Expand Down
5 changes: 4 additions & 1 deletion crates/deskulpt-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ repository = { workspace = true }
[dependencies]
anyhow = { workspace = true }
bincode = { workspace = true }
dunce = { workspace = true }
once_cell = { workspace = true }
open = { workspace = true }
oxc = { workspace = true }
path-clean = { workspace = true }
rolldown = { workspace = true }
rolldown_common = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
swc_core = { workspace = true, features = ["__common", "bundler", "ecma_ast", "ecma_codegen", "ecma_loader", "ecma_parser", "ecma_transforms_react", "ecma_transforms_typescript", "ecma_visit"] }
tauri = { workspace = true, features = ["tray-icon"] }
tauri-plugin-global-shortcut = { workspace = true }
tempfile = { workspace = true }
Expand Down
60 changes: 60 additions & 0 deletions crates/deskulpt-core/src/bundler/alias.rs
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()
})
})?)
}
}
259 changes: 0 additions & 259 deletions crates/deskulpt-core/src/bundler/common.rs

This file was deleted.

Loading

0 comments on commit 7ebfc6b

Please sign in to comment.