From 67dc853592ae25f306930afff2ea760d1e9c55f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Allen=20Zhang=20=28=E5=BC=A0=E6=B6=9B=29?= Date: Wed, 23 Oct 2024 19:22:03 +0800 Subject: [PATCH] feat: update --- plugins/swc-plugin-canyon/package.json | 2 +- plugins/swc-plugin-canyon/src/lib.rs | 28 +++++++++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/plugins/swc-plugin-canyon/package.json b/plugins/swc-plugin-canyon/package.json index 69789daa..bf2fa94e 100644 --- a/plugins/swc-plugin-canyon/package.json +++ b/plugins/swc-plugin-canyon/package.json @@ -1,6 +1,6 @@ { "name": "swc-plugin-canyon", - "version": "0.0.2-alpha.23", + "version": "0.0.2-alpha.24", "description": "A SWC plugin cooperates with istanbul to report the coverage", "main": "swc_plugin_canyon.wasm", "scripts": { diff --git a/plugins/swc-plugin-canyon/src/lib.rs b/plugins/swc-plugin-canyon/src/lib.rs index d36fff24..c21671e1 100644 --- a/plugins/swc-plugin-canyon/src/lib.rs +++ b/plugins/swc-plugin-canyon/src/lib.rs @@ -30,6 +30,7 @@ pub struct Config { pub branch: Option, pub sha: Option, pub projectID: Option, + pub compareTarget: Option, } impl Default for Config { @@ -41,6 +42,7 @@ impl Default for Config { branch: None, sha: None, projectID: None, + compareTarget: None, } } } @@ -79,15 +81,16 @@ impl VisitMut for TransformVisitor { let branch = self.config.branch.clone().unwrap_or("-".to_string()); let sha = self.config.sha.clone().unwrap_or("-".to_string()); let projectID = self.config.projectID.clone().unwrap_or("-".to_string()); + let compareTarget = self.config.compareTarget.clone().unwrap_or("-".to_string()); // 打印出这些 - println!("dsn: {}", dsn); - println!("reporter: {}", reporter); - println!("instrumentCwd: {}", instrumentCwd); - println!("branch: {}", branch); - println!("sha: {}", sha); - println!("projectID: {}", projectID); + // println!("dsn: {}", dsn); + // println!("reporter: {}", reporter); + // println!("instrumentCwd: {}", instrumentCwd); + // println!("branch: {}", branch); + // println!("sha: {}", sha); + // println!("projectID: {}", projectID); let object_lit = Expr::Object(ObjectLit { props: vec![ @@ -120,6 +123,11 @@ impl VisitMut for TransformVisitor { key: PropName::Ident(Ident::from(Ident::new("projectID".into(), Default::default()))), value: Box::new(Expr::Lit(Lit::Str(projectID.into()))), }).into(), + + Prop::KeyValue(KeyValueProp { + key: PropName::Ident(Ident::from(Ident::new("compareTarget".into(), Default::default()))), + value: Box::new(Expr::Lit(Lit::Str(compareTarget.into()))), + }).into(), ], span: Default::default(), }); @@ -164,15 +172,15 @@ pub fn process_transform(program: Program, metadata: TransformPluginProgramMetad .unwrap_or_default(); // Use default if config is None // 打印config - println!("config: {:?}", config); + // println!("config: {:?}", config); // 使用TransformPluginProgramMetadata获取环境变量 let env = metadata.get_context(&TransformPluginMetadataContextKind::Env).unwrap_or("-".to_string()); let filename = metadata.get_context(&TransformPluginMetadataContextKind::Filename).unwrap_or("-".to_string()); let cwd = metadata.get_context(&TransformPluginMetadataContextKind::Cwd).unwrap_or("-".to_string()); - println!("env: {}", env); - println!("filename: {}", filename); - println!("cwd: {}", cwd); + // println!("env: {}", env); + // println!("filename: {}", filename); + // println!("cwd: {}", cwd); program.fold_with(&mut as_folder(TransformVisitor { injected: false, config })) }