Skip to content

Commit

Permalink
node: support implicit js extensions in path resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
y21 committed Jan 18, 2024
1 parent 50e4b50 commit fbbebb2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions crates/dash_node_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down

0 comments on commit fbbebb2

Please sign in to comment.