Skip to content

Commit

Permalink
Merge branch 'master' into feat/bump-rspack
Browse files Browse the repository at this point in the history
  • Loading branch information
ClarkXia committed Feb 18, 2024
2 parents aecb435 + aeb3079 commit 2c22c01
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/loader_barrel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
lazy_static = "1.4.0"
serde_json = "1.0.100"
serde_json = { workspace = true }
futures = { workspace = true }
regex = { workspace = true }
anyhow = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion crates/loader_compilation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ rspack_regex = { path = "../.rspack_crates/rspack_regex" }
rspack_util = { path = "../.rspack_crates/rspack_util" }
regex = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = "1.0.100"
serde_json = { workspace = true }
swc_config = { workspace = true }
swc_core = { workspace = true, features = [
"base",
Expand All @@ -34,6 +34,7 @@ swc_env_replacement = { path = "../swc_env_replacement" }
swc_keep_export = { path = "../swc_keep_export" }
swc_remove_export = { path = "../swc_remove_export" }
swc_named_import_transform = { path = "../swc_named_import_transform" }
swc_change_package_import = { path = "../swc_change_package_import" }

[dev-dependencies]
indexmap = { workspace = true }
Expand Down
10 changes: 9 additions & 1 deletion crates/loader_compilation/src/transform.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::path::Path;

use anyhow::{Context, Error};
use either::Either;
use serde::Deserialize;
Expand All @@ -9,6 +8,7 @@ use swc_env_replacement::env_replacement;
use swc_keep_export::keep_export;
use swc_named_import_transform::{named_import_transform, TransformConfig};
use swc_remove_export::remove_export;
use swc_change_package_import::{change_package_import, Config as ImportConfig, SpecificConfigs};

macro_rules! either {
($config:expr, $f:expr) => {
Expand Down Expand Up @@ -85,6 +85,7 @@ pub struct TransformFeatureOptions {
pub keep_export: Option<Vec<String>>,
pub remove_export: Option<Vec<String>>,
pub optimize_import: Option<Vec<String>>,
pub import_config: Option<Vec<SpecificConfigs>>,
}

pub(crate) fn transform<'a>(
Expand All @@ -98,6 +99,13 @@ pub(crate) fn transform<'a>(
packages: options.clone(),
})
}),
either!(
feature_options.import_config,
|options: &Vec<SpecificConfigs>| {
let import_config = options.to_vec();
change_package_import(import_config.into_iter().map(ImportConfig::SpecificConfig).collect())
}
),
either!(
Some(&vec!["@uni/env".to_string(), "universal-env".to_string()]),
|options: &Vec<String>| { env_replacement(options.clone()) }
Expand Down
1 change: 1 addition & 0 deletions crates/swc_change_package_import/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
serde = { workspace = true }
serde_json = { workspace = true }
swc_core = { workspace = true, features = [
"base",
"ecma_ast",
Expand Down
4 changes: 4 additions & 0 deletions crates/swc_change_package_import/src/change_package_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ pub struct ModuleImportVisitor {
pub options: Vec<Config>,
}

pub fn change_package_import(options: Vec<Config>) -> impl Fold {
ModuleImportVisitor::new(options)
}

impl ModuleImportVisitor {
pub fn new(options: Vec<Config>) -> Self {
Self { options }
Expand Down
9 changes: 5 additions & 4 deletions crates/swc_change_package_import/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use serde::{Deserialize, Serialize};

#[derive(Debug)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub enum Config {
/// 配置:
/// ```rs
Expand Down Expand Up @@ -42,20 +43,20 @@ pub enum Config {
SpecificConfig(SpecificConfigs),
}

#[derive(Debug)]
#[derive(Debug, Clone ,Serialize, Deserialize)]
pub struct SpecificConfigs {
pub name: String,
pub map: HashMap<String, MapProperty>,
}

#[derive(Debug)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MapProperty {
pub to: String,
pub import_type: Option<ImportType>,
pub name: Option<String>,
}

#[derive(Debug, PartialEq)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum ImportType {
Named,
Default,
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_optimize_barrel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
serde_json = "1.0.100"
serde_json = { workspace = true }
serde = { workspace = true, features = ["derive"] }
swc_core = { workspace = true, features = [
"base",
Expand Down

0 comments on commit 2c22c01

Please sign in to comment.