From 6fd025126c3be75a78bc1bae6acc6957061c2832 Mon Sep 17 00:00:00 2001 From: ahaoboy <504595380@qq.com> Date: Mon, 18 Nov 2024 19:57:33 +0800 Subject: [PATCH] improve resolve on windows --- llrt_core/src/module_loader/resolver.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/llrt_core/src/module_loader/resolver.rs b/llrt_core/src/module_loader/resolver.rs index 5c4ea7b5d1..0c41013efc 100644 --- a/llrt_core/src/module_loader/resolver.rs +++ b/llrt_core/src/module_loader/resolver.rs @@ -61,8 +61,8 @@ static FILESYSTEM_ROOT: Lazy> = Lazy::new(|| { #[derive(Debug, Default)] pub struct CustomResolver; - #[allow(clippy::manual_strip)] +#[allow(clippy::bind_instead_of_map)] impl Resolver for CustomResolver { fn resolve(&mut self, ctx: &Ctx, base: &str, name: &str) -> Result { if name.starts_with(CJS_IMPORT_PREFIX) { @@ -73,7 +73,19 @@ impl Resolver for CustomResolver { trace!("Try resolve '{}' from '{}'", name, base); - require_resolve(ctx, name, base, true).map(|name| name.into_owned()) + require_resolve(ctx, name, base, true).and_then(|path| { + #[cfg(windows)] + { + if path.starts_with("llrt:") { + return Ok(path.into_owned()); + } + to_abs_path(path).map(|s| s.to_string()) + } + #[cfg(not(windows))] + { + Ok(path.into_owned()) + } + }) } }