From fbbebb2b1cac119d3ad36c522a2016e1e70d5061 Mon Sep 17 00:00:00 2001 From: y21 <30553356+y21@users.noreply.github.com> Date: Fri, 19 Jan 2024 00:20:53 +0100 Subject: [PATCH] node: support implicit js extensions in path resolution --- crates/dash_node_impl/src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/dash_node_impl/src/lib.rs b/crates/dash_node_impl/src/lib.rs index 0a35d4dc..dbd161c5 100644 --- a/crates/dash_node_impl/src/lib.rs +++ b/crates/dash_node_impl/src/lib.rs @@ -162,10 +162,13 @@ impl Object for RequireFunction { throw!(scope, Error, "require() expects a string argument"); }; let exports = scope.intern("exports"); - let arg = arg.res(scope); - + let mut arg = arg.res(scope).to_owned(); let is_path = matches!(arg.chars().next(), Some('.' | '/' | '~')); if is_path { + if !arg.ends_with(".js") { + arg += ".js"; + } + let canonicalized_path = match self.current_dir.join(arg).canonicalize() { Ok(v) => v, Err(err) => throw!(scope, Error, err.to_string()),