Skip to content

Commit 25dfa12

Browse files
authored
Merge pull request #253 from nyannyacha/sb-graph-module-path
fix(sb_graph): checking whether the path is relative and unix format while reading module path
2 parents d94ad2a + 5fa91e0 commit 25dfa12

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

crates/sb_graph/lib.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,34 @@ pub struct ExtractEszipPayload {
144144
pub folder: PathBuf,
145145
}
146146

147+
fn ensure_unix_relative_path(path: &Path) -> &Path {
148+
assert!(path.is_relative());
149+
assert!(!path.to_string_lossy().starts_with('\\'));
150+
path
151+
}
152+
147153
fn create_module_path(global_specifier: &str, entry_path: &Path, output_folder: &Path) -> PathBuf {
148154
let cleaned_specifier = global_specifier.replace(entry_path.to_str().unwrap(), "");
149155
let module_path = PathBuf::from(cleaned_specifier);
150156

151157
if let Some(parent) = module_path.parent() {
152158
if parent.parent().is_some() {
153-
let output_folder_and_mod_folder =
154-
output_folder.join(parent.strip_prefix("/").unwrap());
159+
let output_folder_and_mod_folder = output_folder.join(
160+
parent
161+
.strip_prefix("/")
162+
.unwrap_or_else(|_| ensure_unix_relative_path(parent)),
163+
);
155164
if !output_folder_and_mod_folder.exists() {
156165
create_dir_all(&output_folder_and_mod_folder).unwrap();
157166
}
158167
}
159168
}
160169

161-
output_folder.join(module_path.strip_prefix("/").unwrap())
170+
output_folder.join(
171+
module_path
172+
.strip_prefix("/")
173+
.unwrap_or_else(|_| ensure_unix_relative_path(&module_path)),
174+
)
162175
}
163176

164177
async fn extract_modules(

0 commit comments

Comments
 (0)