From 617350e79c58b6e01984e3d7c7436d243d0e5cff Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 14 Nov 2024 15:24:25 -0500 Subject: refactor(resolver): move more resolution code into deno_resolver (#26873) Follow-up to cjs refactor. This moves most of the resolution code into the deno_resolver crate. Still pending is the npm resolution code. --- cli/node.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'cli/node.rs') diff --git a/cli/node.rs b/cli/node.rs index 8235745a9..bc39cdbde 100644 --- a/cli/node.rs +++ b/cli/node.rs @@ -7,8 +7,6 @@ use deno_ast::MediaType; use deno_ast::ModuleSpecifier; use deno_core::error::AnyError; use deno_graph::ParsedSourceStore; -use deno_path_util::url_from_file_path; -use deno_path_util::url_to_file_path; use deno_runtime::deno_fs; use deno_runtime::deno_node::DenoFsNodeResolverEnv; use node_resolver::analyze::CjsAnalysis as ExtNodeCjsAnalysis; @@ -22,7 +20,6 @@ use crate::cache::CacheDBHash; use crate::cache::NodeAnalysisCache; use crate::cache::ParsedSourceCache; use crate::resolver::CjsTracker; -use crate::util::fs::canonicalize_path_maybe_not_exists_with_fs; pub type CliNodeCodeTranslator = NodeCodeTranslator; @@ -37,13 +34,9 @@ pub fn resolve_specifier_into_node_modules( specifier: &ModuleSpecifier, fs: &dyn deno_fs::FileSystem, ) -> ModuleSpecifier { - url_to_file_path(specifier) - .ok() - // this path might not exist at the time the graph is being created - // because the node_modules folder might not yet exist - .and_then(|path| canonicalize_path_maybe_not_exists_with_fs(&path, fs).ok()) - .and_then(|path| url_from_file_path(&path).ok()) - .unwrap_or_else(|| specifier.clone()) + node_resolver::resolve_specifier_into_node_modules(specifier, &|path| { + fs.realpath_sync(path).map_err(|err| err.into_io_error()) + }) } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -- cgit v1.2.3