summaryrefslogtreecommitdiff
path: root/cli/node/mod.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2022-11-28 17:48:56 -0500
committerGitHub <noreply@github.com>2022-11-28 17:48:56 -0500
commitd3299c2d6c036d3f016ef1abbe9c06e9b1656fd0 (patch)
tree3dfc98c52907465a20fe490b8e648d3180cfc4ba /cli/node/mod.rs
parent2d4c46c975eb916dc622cc729a1a8d397582a76f (diff)
fix(npm): don't resolve JS files when resolving types (#16854)
Closes #16851
Diffstat (limited to 'cli/node/mod.rs')
-rw-r--r--cli/node/mod.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/cli/node/mod.rs b/cli/node/mod.rs
index fa6f0bdda..60b46a445 100644
--- a/cli/node/mod.rs
+++ b/cli/node/mod.rs
@@ -492,7 +492,10 @@ pub fn node_resolve(
let path = url.to_file_path().unwrap();
// todo(16370): the module kind is not correct here. I think we need
// typescript to tell us if the referrer is esm or cjs
- let path = path_to_declaration_path(path, NodeModuleKind::Esm);
+ let path = match path_to_declaration_path(path, NodeModuleKind::Esm) {
+ Some(path) => path,
+ None => return Ok(None),
+ };
ModuleSpecifier::from_file_path(path).unwrap()
}
};
@@ -532,7 +535,10 @@ pub fn node_resolve_npm_reference(
let resolved_path = match mode {
NodeResolutionMode::Execution => resolved_path,
NodeResolutionMode::Types => {
- path_to_declaration_path(resolved_path, node_module_kind)
+ match path_to_declaration_path(resolved_path, node_module_kind) {
+ Some(path) => path,
+ None => return Ok(None),
+ }
}
};
let url = ModuleSpecifier::from_file_path(resolved_path).unwrap();
@@ -794,7 +800,9 @@ fn module_resolve(
// should use the value provided by typescript instead
let declaration_path =
path_to_declaration_path(file_path, NodeModuleKind::Esm);
- Some(ModuleSpecifier::from_file_path(declaration_path).unwrap())
+ declaration_path.map(|declaration_path| {
+ ModuleSpecifier::from_file_path(declaration_path).unwrap()
+ })
} else {
Some(resolved_specifier)
}