Skip to content

Commit 1371747

Browse files
committed
fix(sb_graph): checking whether the path is relative and unix format while reading module path
(cherry picked from commit 999f625653b456d2ddf049f19ff147c5a3d27095)
1 parent 473aa8b commit 1371747

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
@@ -134,21 +134,34 @@ pub struct ExtractEszipPayload {
134134
pub folder: PathBuf,
135135
}
136136

137+
fn ensure_unix_relative_path(path: &Path) -> &Path {
138+
assert!(path.is_relative());
139+
assert!(!path.to_string_lossy().starts_with("\\"));
140+
path
141+
}
142+
137143
fn create_module_path(global_specifier: &str, entry_path: &Path, output_folder: &Path) -> PathBuf {
138144
let cleaned_specifier = global_specifier.replace(entry_path.to_str().unwrap(), "");
139145
let module_path = PathBuf::from(cleaned_specifier);
140146

141147
if let Some(parent) = module_path.parent() {
142148
if parent.parent().is_some() {
143-
let output_folder_and_mod_folder =
144-
output_folder.join(parent.strip_prefix("/").unwrap());
149+
let output_folder_and_mod_folder = output_folder.join(
150+
parent
151+
.strip_prefix("/")
152+
.unwrap_or_else(|_| ensure_unix_relative_path(parent)),
153+
);
145154
if !output_folder_and_mod_folder.exists() {
146155
create_dir_all(&output_folder_and_mod_folder).unwrap();
147156
}
148157
}
149158
}
150159

151-
output_folder.join(module_path.strip_prefix("/").unwrap())
160+
output_folder.join(
161+
module_path
162+
.strip_prefix("/")
163+
.unwrap_or_else(|_| ensure_unix_relative_path(&module_path)),
164+
)
152165
}
153166

154167
async fn extract_modules(

0 commit comments

Comments
 (0)