From 1416713cb3af8a952b1ae9952091706e2540341c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 16 Nov 2022 20:41:27 +0100 Subject: fix(npm): using types for packages with subpath (#16656) For CommonJS packages we were not trying different extensions for files specified as subpath of the package ([package_name]/[subpath]). This commit fixes that. --- cli/node/mod.rs | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) (limited to 'cli/node') diff --git a/cli/node/mod.rs b/cli/node/mod.rs index 7bb28d984..9ab4574ef 100644 --- a/cli/node/mod.rs +++ b/cli/node/mod.rs @@ -25,6 +25,7 @@ use deno_runtime::deno_node::legacy_main_resolve; use deno_runtime::deno_node::package_exports_resolve; use deno_runtime::deno_node::package_imports_resolve; use deno_runtime::deno_node::package_resolve; +use deno_runtime::deno_node::path_to_declaration_path; use deno_runtime::deno_node::NodeModuleKind; use deno_runtime::deno_node::PackageJson; use deno_runtime::deno_node::PathClean; @@ -548,34 +549,6 @@ fn mode_conditions(mode: NodeResolutionMode) -> &'static [&'static str] { } } -/// Checks if the resolved file has a corresponding declaration file. -fn path_to_declaration_path( - path: PathBuf, - referrer_kind: NodeModuleKind, -) -> PathBuf { - let lowercase_path = path.to_string_lossy().to_lowercase(); - if lowercase_path.ends_with(".d.ts") - || lowercase_path.ends_with(".d.cts") - || lowercase_path.ends_with(".d.ts") - { - return path; - } - let specific_dts_path = match referrer_kind { - NodeModuleKind::Cjs => path.with_extension("d.cts"), - NodeModuleKind::Esm => path.with_extension("d.mts"), - }; - if specific_dts_path.exists() { - specific_dts_path - } else { - let dts_path = path.with_extension("d.ts"); - if dts_path.exists() { - dts_path - } else { - path - } - } -} - pub fn node_resolve_binary_export( pkg_req: &NpmPackageReq, bin_name: Option<&str>, -- cgit v1.2.3