Skip to content

Commit 7a5631d

Browse files
authored
Ignore path more aggressive (#60)
1 parent d868ae8 commit 7a5631d

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/lib.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,29 @@ pub fn process_transform(program: Program, _metadata: TransformPluginProgramMeta
4040
let cwd = &raw_cwd.replace('\\', "/");
4141
let path = &raw_path.replace('\\', "/");
4242

43-
let relative_path = path
44-
.strip_prefix(cwd)
45-
.unwrap_or_else(|| panic!("Unhandled path: cwd: {}, path: {}", cwd, path));
43+
if let Some(relative_path) = path.strip_prefix(cwd) {
44+
let dir_type =
45+
if relative_path.starts_with("/pages") || relative_path.starts_with("/src/pages") {
46+
DirType::Page
47+
} else if relative_path.starts_with("/app") || relative_path.starts_with("/src/app") {
48+
DirType::App
49+
} else {
50+
// not page or app
51+
return program;
52+
};
4653

47-
let dir_type = if relative_path.starts_with("/pages") || relative_path.starts_with("/src/pages")
48-
{
49-
DirType::Page
50-
} else if relative_path.starts_with("/app") || relative_path.starts_with("/src/app") {
51-
DirType::App
52-
} else {
53-
// not page or app
54-
return program;
55-
};
56-
57-
let config = serde_json::from_str::<Config>(
58-
&_metadata
59-
.get_transform_plugin_config()
60-
.unwrap_or_else(|| "{}".to_string()),
61-
)
62-
.expect("Failed to parse plugin config");
54+
let config = serde_json::from_str::<Config>(
55+
&_metadata
56+
.get_transform_plugin_config()
57+
.unwrap_or_else(|| "{}".to_string()),
58+
)
59+
.expect("Failed to parse plugin config");
6360

64-
match dir_type {
65-
DirType::Page => program.fold_with(&mut as_folder(transform_page(config))),
66-
DirType::App => program.fold_with(&mut as_folder(transform_app(config))),
61+
match dir_type {
62+
DirType::Page => program.fold_with(&mut as_folder(transform_page(config))),
63+
DirType::App => program.fold_with(&mut as_folder(transform_app(config))),
64+
}
65+
} else {
66+
program
6767
}
6868
}

0 commit comments

Comments
 (0)