diff --git a/.cargo/config.toml b/.cargo/config.toml index 5d02554..9178b3e 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -7,6 +7,8 @@ lint = "clippy --workspace --all-targets -- --deny warnings" # AKA `test-update`, handy cargo rst update without install `cargo-rst` binary t = "test --no-fail-fast" tu = "run -p cargo-rst -- update" +build-wasi = "build --target wasm32-wasi" +build-wasm32 = "build --target wasm32-unknown-unknown" [target.'cfg(all())'] rustflags = [ diff --git a/.gitignore b/.gitignore index fe67a2e..8cb47ea 100644 --- a/.gitignore +++ b/.gitignore @@ -196,4 +196,5 @@ $RECYCLE.BIN/ *.node .rspack_crates/ -node_modules/ \ No newline at end of file +node_modules/ +.idea/ diff --git a/Cargo.toml b/Cargo.toml index 89a6577..0e4c1a5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,9 +10,9 @@ members = [ "crates/swc_env_replacement", "crates/swc_keep_export", "crates/swc_remove_export", - "crates/swc_named_import_transform", "crates/swc_optimize_barrel", - "crates/plugin_specilize_module_name" + "crates/plugin_specilize_module_name", + "crates/swc_plugin_change_package_import", ] resolver = "2" @@ -80,6 +80,7 @@ swc_html = { version = "=0.134.29" } swc_html_minifier = { version = "=0.131.29" } swc_node_comments = { version = "=0.20.9" } tikv-jemallocator = { version = "=0.5.4", features = ["disable_initial_exec_tls"] } +testing = { version = "0.35.13" } [profile.dev] codegen-units = 16 # debug build will cause runtime panic if codegen-unints is default diff --git a/crates/swc_plugin_change_package_import/.gitignore b/crates/swc_plugin_change_package_import/.gitignore new file mode 100644 index 0000000..6bdfa85 --- /dev/null +++ b/crates/swc_plugin_change_package_import/.gitignore @@ -0,0 +1,3 @@ +/target +^target/ +target diff --git a/crates/swc_plugin_change_package_import/Cargo.toml b/crates/swc_plugin_change_package_import/Cargo.toml new file mode 100644 index 0000000..9136d6d --- /dev/null +++ b/crates/swc_plugin_change_package_import/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "swc_plugin_change_package_import" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib", "rlib"] + +[profile.release] +lto = true + +[dependencies] +serde = { workspace = true } +swc_core = { workspace = true, features = [ + "ecma_plugin_transform", + "ecma_ast", + "common", + "ecma_utils", +] } + +[dev-dependencies] +testing = "0.35.11" \ No newline at end of file diff --git a/crates/swc_plugin_change_package_import/package.json b/crates/swc_plugin_change_package_import/package.json new file mode 100644 index 0000000..5c698c2 --- /dev/null +++ b/crates/swc_plugin_change_package_import/package.json @@ -0,0 +1,14 @@ +{ + "name": "plugin_optimize_package_import", + "version": "0.1.0", + "description": "", + "author": "", + "license": "ISC", + "keywords": ["swc-plugin"], + "main": "target/wasm32-wasi/release/plugin_optimize_package_import.wasm", + "scripts": { + "prepublishOnly": "cargo build-wasi --release" + }, + "files": [], + "preferUnplugged": true +} diff --git a/crates/swc_plugin_change_package_import/src/change_package_import.rs b/crates/swc_plugin_change_package_import/src/change_package_import.rs new file mode 100644 index 0000000..48e0bb1 --- /dev/null +++ b/crates/swc_plugin_change_package_import/src/change_package_import.rs @@ -0,0 +1,207 @@ +use crate::config::{Config, ImportType}; +use swc_core::{ + common::{ + DUMMY_SP, + util::{ + take::Take + }, + }, + ecma::{ + ast::*, + atoms::{JsWord}, + visit::{VisitMut, VisitMutWith}, + utils::{quote_str, swc_ecma_ast::ImportSpecifier}, + }, +}; + +pub struct ModuleImportVisitor { + // 用户配置 + pub options: Vec, + // 全新生成的导入声明 + new_stmts: Vec, +} + +impl ModuleImportVisitor { + pub fn new(options: Vec) -> Self { + Self { + options, + new_stmts: vec![], + } + } +} + +impl VisitMut for ModuleImportVisitor { + fn visit_mut_import_decl(&mut self, import_decl: &mut ImportDecl) { + import_decl.visit_mut_children_with(self); + + for option in &self.options { + match option { + Config::LiteralConfig(src) => { + if is_hit_rule(import_decl, option) { + for specifier in &import_decl.specifiers { + match specifier { + ImportSpecifier::Named(named_import_spec) => { + let mut import_new_src = src.clone(); + import_new_src.push_str("/"); + import_new_src.push_str(&get_import_module_name(named_import_spec)); + + self.new_stmts.push(create_default_import_decl(import_new_src, named_import_spec.local.clone())); + } + _ => () + } + } + // 清空当前导入声明,否则会被作为有效的声明添加至 new_stmts 中 + import_decl.take(); + break; + } + } + Config::SpecificConfig(config) => { + if is_hit_rule(import_decl, option) { + let target_fields: Vec<&String> = config.map.keys().clone().collect(); + let mut named_import_spec_copy = import_decl.clone(); + + // 获取未命中规则的导入声明 + named_import_spec_copy.specifiers = named_import_spec_copy.specifiers.into_iter().filter(|specifier| { + match specifier { + ImportSpecifier::Named(named_import_spec) => { + let import_object_name = get_import_module_name(named_import_spec); + !target_fields.contains(&&import_object_name) + } + _ => true + } + }).collect::>(); + + if named_import_spec_copy.specifiers.len() != 0 { + self.new_stmts.push(ModuleItem::ModuleDecl(ModuleDecl::Import(named_import_spec_copy))); + } + + for (target, rules) in config.map.iter() { + for specifier in &import_decl.specifiers { + match specifier { + ImportSpecifier::Named(named_import_spec) => { + let import_object_name = get_import_module_name(named_import_spec); + if target == &import_object_name { + let new_import_decl: ModuleItem; + if rules.import_type.is_none() || match rules.import_type.as_ref().unwrap() { + ImportType::Default => true, + _ => false + } { + // Default import mode + new_import_decl = create_default_import_decl(rules.to.to_string(), named_import_spec.local.clone()); + } else { + // Named import mode + let mut named_import_spec_copy = named_import_spec.clone(); + + if rules.name.is_some() { + named_import_spec_copy.imported = Some(ModuleExportName::Str(Str { + span: named_import_spec.span, + value: rules.name.clone().unwrap().into(), + raw: Some(rules.name.clone().unwrap().clone().into()), + })) + } + + new_import_decl = create_named_import_decl(rules.to.to_string(), vec![ImportSpecifier::Named(named_import_spec_copy)]); + } + + self.new_stmts.push(new_import_decl); + } + } + _ => () + } + } + } + import_decl.take(); + break; + } + } + } + } + + if !is_empty_decl(import_decl) { + self.new_stmts.push(wrap_with_moudle_item(import_decl.clone())); + } + } + + fn visit_mut_module_item(&mut self, n: &mut ModuleItem) { + n.visit_mut_children_with(self); + + if !n.is_module_decl() { + self.new_stmts.push(n.clone()); + } + } + + fn visit_mut_module_items(&mut self, stmts: &mut Vec) { + stmts.visit_mut_children_with(self); + + *stmts = self.new_stmts.clone(); + } +} + +fn is_hit_rule(cur_import: &ImportDecl, rule: &Config) -> bool { + match rule { + Config::LiteralConfig(s) => { + if cur_import.src.value == JsWord::from(s.clone()) { + return true; + } + false + } + Config::SpecificConfig(s) => { + if cur_import.src.value == JsWord::from(s.name.clone()) { + return true; + } + false + } + } +} + +fn is_empty_decl(decl: &ImportDecl) -> bool { + decl.specifiers.len() == 0 && decl.src.value == JsWord::from("".to_string()) +} + +fn get_import_module_name(named_import_spec: &ImportNamedSpecifier) -> String { + if named_import_spec.imported.is_none() { + (&named_import_spec.local.sym).to_string() + } else { + match &named_import_spec.imported.clone().unwrap() { + ModuleExportName::Ident(ident) => { + (&ident.sym).to_string() + } + ModuleExportName::Str(str) => { + (&str.value).to_string() + } + } + } +} + +fn create_default_import_decl(src: String, local: Ident) -> ModuleItem { + wrap_with_moudle_item( + ImportDecl { + src: Box::new(quote_str!(src)), + specifiers: vec![ImportSpecifier::Default( + ImportDefaultSpecifier { + span: DUMMY_SP, + local, + } + )], + span: DUMMY_SP, + type_only: false, + with: None, + } + ) +} + +fn create_named_import_decl(src: String, specifiers: Vec) -> ModuleItem { + wrap_with_moudle_item( + ImportDecl { + src: Box::new(quote_str!(src)), + specifiers, + span: DUMMY_SP, + type_only: false, + with: None, + } + ) +} + +fn wrap_with_moudle_item(import_decl: ImportDecl) -> ModuleItem { + ModuleItem::ModuleDecl(ModuleDecl::Import(import_decl)) +} \ No newline at end of file diff --git a/crates/swc_plugin_change_package_import/src/config.rs b/crates/swc_plugin_change_package_import/src/config.rs new file mode 100644 index 0000000..3f64628 --- /dev/null +++ b/crates/swc_plugin_change_package_import/src/config.rs @@ -0,0 +1,62 @@ +use std::collections::HashMap; + +#[derive(Debug)] +pub enum Config { + /// 配置: + /// ```rs + /// Config::LiteralConfig(String::from("antd")) + /// ``` + /// 效果: + /// ```js + /// import { Button } from "antd"; + /// // ---> + /// import Button from "antd/Button"; + /// ``` + LiteralConfig(String), + /// 配置: + /// ```rs + /// Config::SpecificConfig( + // SpecificConfigs { + // name: String::from("ice"), + // map: HashMap::from([ + // ( + // "a".to_string(), + // MapProperty { + // to: String::from("@ice/x/y"), + // import_type: None, + // name: None, + // } + // ), + // ]), + // } + // ), + /// ``` + /// 效果: + /// ```js + /// import { a } from "ice"; + /// // ---> + /// import a from "@ice/x/y"; + /// ``` + /// + /// 更多配置请参考[文档](https://alidocs.dingtalk.com/i/nodes/20eMKjyp810mMdK4Ho1LpqX7JxAZB1Gv?utm_scene=team_space) + SpecificConfig(SpecificConfigs), +} + +#[derive(Debug)] +pub struct SpecificConfigs { + pub name: String, + pub map: HashMap, +} + +#[derive(Debug)] +pub struct MapProperty { + pub to: String, + pub import_type: Option, + pub name: Option, +} + +#[derive(Debug, PartialEq)] +pub enum ImportType { + Named, + Default, +} diff --git a/crates/swc_plugin_change_package_import/src/lib.rs b/crates/swc_plugin_change_package_import/src/lib.rs new file mode 100644 index 0000000..ed9b552 --- /dev/null +++ b/crates/swc_plugin_change_package_import/src/lib.rs @@ -0,0 +1,5 @@ +mod config; +mod change_package_import; + +pub use config::*; +pub use change_package_import::*; \ No newline at end of file diff --git a/crates/swc_plugin_change_package_import/tests/fixture.rs b/crates/swc_plugin_change_package_import/tests/fixture.rs new file mode 100644 index 0000000..734a934 --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture.rs @@ -0,0 +1,442 @@ +use std::path::PathBuf; +use std::collections::HashMap; +use swc_core::ecma::{ + visit::as_folder, + transforms::testing::{FixtureTestConfig, test_fixture}, +}; +use swc_plugin_change_package_import::{ + ModuleImportVisitor, + Config, + SpecificConfigs, + MapProperty, + ImportType, +}; + +#[testing::fixture("tests/fixture/single_literal_transform/input.js")] +fn test_single_literal_transform(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![Config::LiteralConfig(String::from("y"))])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + +#[testing::fixture("tests/fixture/multi_literal_transform/input.js")] +fn test_multi_literal_transform(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![ + Config::LiteralConfig(String::from("z")), + Config::LiteralConfig(String::from("o")), + ])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + +#[testing::fixture("tests/fixture/single_specific_transform/input.js")] + +fn test_single_specific_transform(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![ + Config::SpecificConfig( + SpecificConfigs { + name: String::from("y"), + map: HashMap::from([ + ( + "x".to_string(), + MapProperty { + to: String::from("m/n"), + import_type: Some(ImportType::Named), + name: Some(String::from("a")), + } + ), + ]), + } + ), + ])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + +#[testing::fixture("tests/fixture/single_specific_transform_2/input.js")] +fn test_single_specific_transform_2(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![ + Config::SpecificConfig( + SpecificConfigs { + name: String::from("y"), + map: HashMap::from([ + ( + "x".to_string(), + MapProperty { + to: String::from("m/n"), + import_type: Some(ImportType::Named), + name: Some(String::from("a")), + } + ), + ]), + } + ), + ])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + +#[testing::fixture("tests/fixture/mix_specific_transform/input.js")] +fn test_mix_specific_transform(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![ + Config::LiteralConfig(String::from("antd")), + Config::SpecificConfig( + SpecificConfigs { + name: String::from("ice"), + map: HashMap::from([ + ( + "a".to_string(), + MapProperty { + to: String::from("@ice/x/y"), + import_type: None, + name: None, + } + ), + ]), + } + ), + ])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + + +#[testing::fixture("tests/fixture/multi_specific_transform/input.js")] +fn test_multi_specific_transform(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![ + Config::SpecificConfig( + SpecificConfigs { + name: String::from("e"), + map: HashMap::from([ + ( + "a".to_string(), + MapProperty { + to: String::from("@e/x"), + import_type: Some(ImportType::Default), + name: None, + } + ), + ( + "b".to_string(), + MapProperty { + to: String::from("e"), + import_type: Some(ImportType::Named), + name: None, + } + ) + ]), + }, + ), + Config::SpecificConfig( + SpecificConfigs { + name: String::from("k"), + map: HashMap::from([ + ( + "j".to_string(), + MapProperty { + to: String::from("@e/k"), + import_type: Some(ImportType::Named), + name: Some(String::from("jj")), + } + ), + ]), + }, + ), + ])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + +#[testing::fixture("tests/fixture/ice_basic_transform/input.js")] +fn test_ice_basic_transform(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![ + Config::SpecificConfig( + SpecificConfigs { + name: String::from("ice"), + map: HashMap::from([ + ( + "runApp".to_string(), + MapProperty { + to: String::from("@ice/runtime"), + import_type: Some(ImportType::Named), + name: None, + } + ), + ]), + } + ), + ])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + +#[testing::fixture("tests/fixture/ice_as_transform/input.js")] +fn test_ice_as_transform(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![ + Config::SpecificConfig( + SpecificConfigs { + name: String::from("ice"), + map: HashMap::from([ + ( + "runApp".to_string(), + MapProperty { + to: String::from("@ice/runtime"), + import_type: Some(ImportType::Named), + name: None, + } + ), + ]), + } + ), + ])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + +#[testing::fixture("tests/fixture/ice_alias_transform/input.js")] +fn test_ice_alias_transform(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![ + Config::SpecificConfig( + SpecificConfigs { + name: String::from("ice"), + map: HashMap::from([ + ( + "Head".to_string(), + MapProperty { + to: String::from("react-helmet"), + import_type: Some(ImportType::Default), + name: Some("Helmet".to_string()), + } + ), + ]), + } + ), + ])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + +#[testing::fixture("tests/fixture/ice_alias_with_as_transform/input.js")] +fn test_ice_alias_with_as_transform(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![ + Config::SpecificConfig( + SpecificConfigs { + name: String::from("ice"), + map: HashMap::from([ + ( + "Head".to_string(), + MapProperty { + to: String::from("react-helmet"), + import_type: Some(ImportType::Default), + name: None, + } + ), + ]), + } + ), + ])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + +#[testing::fixture("tests/fixture/ice_multiple_transform/input.js")] +fn test_ice_multiple_transform(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![ + Config::SpecificConfig( + SpecificConfigs { + name: String::from("ice"), + map: HashMap::from([ + ( + "request".to_string(), + MapProperty { + to: String::from("axios"), + import_type: Some(ImportType::Named), + name: None, + } + ), + ( + "test".to_string(), + MapProperty { + to: String::from("axios"), + import_type: Some(ImportType::Named), + name: None, + } + ), + ( + "store".to_string(), + MapProperty { + to: String::from("@ice/store"), + import_type: Some(ImportType::Default), + name: None, + } + ) + ]), + } + ), + ])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + +#[testing::fixture("tests/fixture/ice_matched_transform/input.js")] +fn test_ice_matched_transform(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![ + Config::SpecificConfig( + SpecificConfigs { + name: String::from("ice"), + map: HashMap::from([ + ( + "runApp".to_string(), + MapProperty { + to: String::from("@ice/runtime"), + import_type: Some(ImportType::Named), + name: None, + } + ), + ]), + } + ), + ])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + +#[testing::fixture("tests/fixture/ice_miss_match_transform/input.js")] +fn test_ice_miss_match_transform(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![ + Config::SpecificConfig( + SpecificConfigs { + name: String::from("ice"), + map: HashMap::from([ + ( + "runApp".to_string(), + MapProperty { + to: String::from("@ice/runtime"), + import_type: Some(ImportType::Named), + name: None, + } + ), + ]), + } + ), + ])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} \ No newline at end of file diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_alias_transform/input.js b/crates/swc_plugin_change_package_import/tests/fixture/ice_alias_transform/input.js new file mode 100644 index 0000000..454e1dd --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/ice_alias_transform/input.js @@ -0,0 +1 @@ +import { Head } from 'ice'; diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_alias_transform/output.js b/crates/swc_plugin_change_package_import/tests/fixture/ice_alias_transform/output.js new file mode 100644 index 0000000..a584f78 --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/ice_alias_transform/output.js @@ -0,0 +1 @@ +import Head from "react-helmet"; diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_alias_with_as_transform/input.js b/crates/swc_plugin_change_package_import/tests/fixture/ice_alias_with_as_transform/input.js new file mode 100644 index 0000000..55079e8 --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/ice_alias_with_as_transform/input.js @@ -0,0 +1 @@ +import { Head as Header } from 'ice'; \ No newline at end of file diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_alias_with_as_transform/output.js b/crates/swc_plugin_change_package_import/tests/fixture/ice_alias_with_as_transform/output.js new file mode 100644 index 0000000..e1e217e --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/ice_alias_with_as_transform/output.js @@ -0,0 +1 @@ +import Header from "react-helmet"; diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_as_transform/input.js b/crates/swc_plugin_change_package_import/tests/fixture/ice_as_transform/input.js new file mode 100644 index 0000000..1240bfe --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/ice_as_transform/input.js @@ -0,0 +1 @@ +import {runApp as run} from 'ice'; \ No newline at end of file diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_as_transform/output.js b/crates/swc_plugin_change_package_import/tests/fixture/ice_as_transform/output.js new file mode 100644 index 0000000..7231e23 --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/ice_as_transform/output.js @@ -0,0 +1 @@ +import { runApp as run } from "@ice/runtime"; \ No newline at end of file diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_basic_transform/input.js b/crates/swc_plugin_change_package_import/tests/fixture/ice_basic_transform/input.js new file mode 100644 index 0000000..0266e48 --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/ice_basic_transform/input.js @@ -0,0 +1 @@ +import {runApp} from "ice"; \ No newline at end of file diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_basic_transform/output.js b/crates/swc_plugin_change_package_import/tests/fixture/ice_basic_transform/output.js new file mode 100644 index 0000000..c1d455e --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/ice_basic_transform/output.js @@ -0,0 +1 @@ +import { runApp } from "@ice/runtime"; \ No newline at end of file diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_matched_transform/input.js b/crates/swc_plugin_change_package_import/tests/fixture/ice_matched_transform/input.js new file mode 100644 index 0000000..3d5422f --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/ice_matched_transform/input.js @@ -0,0 +1 @@ +import { runApp, defineDataLoader } from "ice"; \ No newline at end of file diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_matched_transform/output.js b/crates/swc_plugin_change_package_import/tests/fixture/ice_matched_transform/output.js new file mode 100644 index 0000000..842e852 --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/ice_matched_transform/output.js @@ -0,0 +1,2 @@ +import { defineDataLoader } from "ice"; +import { runApp } from "@ice/runtime"; \ No newline at end of file diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_miss_match_transform/input.js b/crates/swc_plugin_change_package_import/tests/fixture/ice_miss_match_transform/input.js new file mode 100644 index 0000000..bb9c16e --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/ice_miss_match_transform/input.js @@ -0,0 +1 @@ +import { defineDataLoader } from 'ice'; \ No newline at end of file diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_miss_match_transform/output.js b/crates/swc_plugin_change_package_import/tests/fixture/ice_miss_match_transform/output.js new file mode 100644 index 0000000..bb9c16e --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/ice_miss_match_transform/output.js @@ -0,0 +1 @@ +import { defineDataLoader } from 'ice'; \ No newline at end of file diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_multiple_transform/input.js b/crates/swc_plugin_change_package_import/tests/fixture/ice_multiple_transform/input.js new file mode 100644 index 0000000..aa943af --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/ice_multiple_transform/input.js @@ -0,0 +1 @@ +import { request, store, test } from 'ice'; \ No newline at end of file diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_multiple_transform/output.js b/crates/swc_plugin_change_package_import/tests/fixture/ice_multiple_transform/output.js new file mode 100644 index 0000000..a18b3b8 --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/ice_multiple_transform/output.js @@ -0,0 +1,3 @@ +import { request } from "axios"; +import { test } from "axios"; +import store from "@ice/store"; diff --git a/crates/swc_plugin_change_package_import/tests/fixture/mix_specific_transform/input.js b/crates/swc_plugin_change_package_import/tests/fixture/mix_specific_transform/input.js new file mode 100644 index 0000000..5501a2f --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/mix_specific_transform/input.js @@ -0,0 +1,3 @@ +import {Button, Spin} from "antd"; +import {a} from "ice"; +import {isArray} from "lodash"; \ No newline at end of file diff --git a/crates/swc_plugin_change_package_import/tests/fixture/mix_specific_transform/output.js b/crates/swc_plugin_change_package_import/tests/fixture/mix_specific_transform/output.js new file mode 100644 index 0000000..e91db18 --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/mix_specific_transform/output.js @@ -0,0 +1,4 @@ +import Button from "antd/Button"; +import Spin from "antd/Spin"; +import a from "@ice/x/y"; +import { isArray } from "lodash"; diff --git a/crates/swc_plugin_change_package_import/tests/fixture/multi_literal_transform/input.js b/crates/swc_plugin_change_package_import/tests/fixture/multi_literal_transform/input.js new file mode 100644 index 0000000..1814689 --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/multi_literal_transform/input.js @@ -0,0 +1,5 @@ +import a from "b"; +import {x, y} from "z"; +import c from "d"; +import {p, q as r} from "o"; +// import {a, c, d} from "i"; \ No newline at end of file diff --git a/crates/swc_plugin_change_package_import/tests/fixture/multi_literal_transform/output.js b/crates/swc_plugin_change_package_import/tests/fixture/multi_literal_transform/output.js new file mode 100644 index 0000000..5f24479 --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/multi_literal_transform/output.js @@ -0,0 +1,7 @@ +import a from "b"; +import x from "z/x"; +import y from "z/y"; +import c from "d"; +import p from "o/p"; +import r from "o/q"; + // import {a, c, d} from "i"; diff --git a/crates/swc_plugin_change_package_import/tests/fixture/multi_specific_transform/input.js b/crates/swc_plugin_change_package_import/tests/fixture/multi_specific_transform/input.js new file mode 100644 index 0000000..7cb5b8a --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/multi_specific_transform/input.js @@ -0,0 +1,5 @@ +import {a, b, c as d} from "e"; +import {j, q} from "k" +// import "f"; +// import g from "k"; +// import y from "z"; \ No newline at end of file diff --git a/crates/swc_plugin_change_package_import/tests/fixture/multi_specific_transform/output.js b/crates/swc_plugin_change_package_import/tests/fixture/multi_specific_transform/output.js new file mode 100644 index 0000000..732b909 --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/multi_specific_transform/output.js @@ -0,0 +1,7 @@ +import { c as d } from "e"; +import a from "@e/x"; +import { b } from "e"; +import { q } from "k"; // import "f"; + // import g from "k"; + // import y from "z"; +import { jj as j } from "@e/k"; diff --git a/crates/swc_plugin_change_package_import/tests/fixture/single_literal_transform/input.js b/crates/swc_plugin_change_package_import/tests/fixture/single_literal_transform/input.js new file mode 100644 index 0000000..ba453df --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/single_literal_transform/input.js @@ -0,0 +1,3 @@ +import {x} from "y"; +import {p} from "q"; +import j from "k"; \ No newline at end of file diff --git a/crates/swc_plugin_change_package_import/tests/fixture/single_literal_transform/output.js b/crates/swc_plugin_change_package_import/tests/fixture/single_literal_transform/output.js new file mode 100644 index 0000000..4e7ab5e --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/single_literal_transform/output.js @@ -0,0 +1,3 @@ +import x from "y/x"; +import { p } from "q"; +import j from "k"; diff --git a/crates/swc_plugin_change_package_import/tests/fixture/single_specific_transform/input.js b/crates/swc_plugin_change_package_import/tests/fixture/single_specific_transform/input.js new file mode 100644 index 0000000..863b79e --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/single_specific_transform/input.js @@ -0,0 +1 @@ +import { x } from "y"; \ No newline at end of file diff --git a/crates/swc_plugin_change_package_import/tests/fixture/single_specific_transform/output.js b/crates/swc_plugin_change_package_import/tests/fixture/single_specific_transform/output.js new file mode 100644 index 0000000..ea81c65 --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/single_specific_transform/output.js @@ -0,0 +1 @@ +import { a as x } from "m/n"; diff --git a/crates/swc_plugin_change_package_import/tests/fixture/single_specific_transform_2/input.js b/crates/swc_plugin_change_package_import/tests/fixture/single_specific_transform_2/input.js new file mode 100644 index 0000000..2fb4c88 --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/single_specific_transform_2/input.js @@ -0,0 +1 @@ +import {x as k} from "y"; \ No newline at end of file diff --git a/crates/swc_plugin_change_package_import/tests/fixture/single_specific_transform_2/output.js b/crates/swc_plugin_change_package_import/tests/fixture/single_specific_transform_2/output.js new file mode 100644 index 0000000..0f6bab2 --- /dev/null +++ b/crates/swc_plugin_change_package_import/tests/fixture/single_specific_transform_2/output.js @@ -0,0 +1 @@ +import { a as k } from "m/n"; \ No newline at end of file