Skip to content

Commit 1a73dd4

Browse files
committed
chore: daily development
1 parent 491a0a7 commit 1a73dd4

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

.swcrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"experimental":{
55
"plugins": [
66
["./swc_plugin_istanbul.wasm",{
7-
"unstableExclude": ["**/node_modules/**"],
7+
"unstableExclude": ["node_modules/**"],
88
"dsn":"http://localhost:3000",
99
"reporter":"1",
1010
"instrumentCwd":"./src",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swc-plugin-istanbul",
3-
"version": "0.0.1-beta.1",
3+
"version": "0.0.1-beta.2",
44
"description": "A SWC plugin cooperates with istanbul to report the coverage",
55
"main": "swc_plugin_istanbul.wasm",
66
"scripts": {

src/lib.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::path::Path;
12
use swc_core::{
23
ecma::{ast::Program, visit::*},
34
plugin::{
@@ -41,12 +42,30 @@ fn initialize_instrumentation_log(log_options: &InstrumentLogOptions) {
4142
#[plugin_transform]
4243
pub fn process(program: Program, metadata: TransformPluginProgramMetadata) -> Program {
4344
let filename = metadata.get_context(&TransformPluginMetadataContextKind::Filename);
45+
let cwd = metadata.get_context(&TransformPluginMetadataContextKind::Cwd);
46+
4447
let filename = if let Some(filename) = filename.as_deref() {
4548
filename
4649
} else {
4750
"unknown.js"
4851
};
4952

53+
let cwd = if let Some(cwd) = cwd.as_deref() {
54+
cwd
55+
} else {
56+
""
57+
};
58+
59+
let relative_filename = Path::new(filename)
60+
.strip_prefix(Path::new(cwd))
61+
.ok()
62+
.and_then(|p| p.to_str())
63+
.unwrap_or(filename);
64+
65+
println!("relative_filename: {}", relative_filename);
66+
println!("filename: {}", filename);
67+
println!("cwd: {}", cwd);
68+
5069
let plugin_config = metadata.get_transform_plugin_config();
5170
let instrument_options: InstrumentOptions = if let Some(plugin_config) = plugin_config {
5271
serde_json::from_str(&plugin_config).unwrap_or_else(|f| {
@@ -64,8 +83,8 @@ pub fn process(program: Program, metadata: TransformPluginProgramMetadata) -> Pr
6483
if let Some(exclude) = &instrument_options.unstable_exclude {
6584
match wax::any(exclude.iter().map(|s| s.as_ref()).collect::<Vec<&str>>()) {
6685
Ok(p) => {
67-
if p.is_match(filename) {
68-
println!("File is excluded from coverage: {}", filename);
86+
if p.is_match(relative_filename) {
87+
println!("File is excluded from coverage: {}", relative_filename);
6988
return program;
7089
}
7190
}

0 commit comments

Comments
 (0)