From 498f0ebdd7a959fc8037feb3e94964971f51c82f Mon Sep 17 00:00:00 2001 From: Nyannyacha Date: Wed, 12 Feb 2025 08:47:19 +0000 Subject: [PATCH] fix: convert file path with special characters to url correctly --- crates/graph/graph_util.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/graph/graph_util.rs b/crates/graph/graph_util.rs index ed2aed361..0603d5092 100644 --- a/crates/graph/graph_util.rs +++ b/crates/graph/graph_util.rs @@ -2,7 +2,7 @@ use crate::emitter::EmitterFactory; use crate::graph_fs::DenoGraphFsAdapter; use crate::jsr::CliJsrUrlProvider; use crate::resolver::CliGraphResolver; -use anyhow::Context; +use anyhow::{anyhow, Context}; use deno_core::error::{custom_error, AnyError}; use deno_core::parking_lot::Mutex; use deno_core::{FastString, ModuleSpecifier}; @@ -413,10 +413,9 @@ pub async fn create_graph( specifier } else { let binding = std::fs::canonicalize(&file).context("failed to read path")?; - let specifier = binding.to_str().context("failed to convert path to str")?; - let format_specifier = format!("file:///{}", specifier); - ModuleSpecifier::parse(&format_specifier).context("failed to parse specifier")? + ModuleSpecifier::from_file_path(binding) + .map_err(|_| anyhow!("failed to parse specifier"))? }; let builder = ModuleGraphBuilder::new(emitter_factory, false);