Skip to content

Commit

Permalink
fix(es/modules): Fix resolution of jsc.paths with exact match (#8685)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #8668
  • Loading branch information
kdy1 authored Mar 4, 2024
1 parent 147e7d0 commit 08ed0fb
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 1 deletion.
11 changes: 11 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8668/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"baseUrl": "./",
"paths": {
"$utils": [
"./src/utils.ts"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { str } from "$utils";
console.log(str);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const str = "";
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { str } from "../../utils";
console.log(str);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export var str = "";
11 changes: 10 additions & 1 deletion crates/swc_ecma_loader/src/resolvers/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,16 @@ where

if let Ok(res) = self.resolve(&self.base_url_filename, &format!("./{}", &to[0]))
{
return Ok(res);
return Ok(Resolution {
slug: match &res.filename {
FileName::Real(p) => p
.file_stem()
.filter(|&s| s != "index")
.map(|v| v.to_string_lossy().into()),
_ => None,
},
..res
});
}

return Ok(Resolution {
Expand Down

0 comments on commit 08ed0fb

Please sign in to comment.