Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/module): Fix logic for exact matches in jsc.paths #7860

Merged
merged 6 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7829/1/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"module": {
"type": "es6"
},
"jsc": {
"baseUrl": ".",
"target": "es2020",
"parser": {
"syntax": "typescript",
"decorators": true,
"importMeta": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"keepClassNames": true,
"paths": {
"@my/pkg": [
"libs/pkg/src/index.ts"
],
}
}
}
4 changes: 4 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7829/1/input/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { fn } from '@my/pkg';


console.log(fn)
2 changes: 2 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7829/1/output/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { fn } from "./libs/pkg/src";
console.log(fn);
24 changes: 24 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7829/2/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"module": {
"type": "es6"
},
"jsc": {
"baseUrl": ".",
"target": "es2020",
"parser": {
"syntax": "typescript",
"decorators": true,
"importMeta": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"keepClassNames": true,
"paths": {
"@my/pkg": [
"libs/pkg/src/index.js"
],
}
}
}
4 changes: 4 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7829/2/input/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { fn } from '@my/pkg';


console.log(fn)
2 changes: 2 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7829/2/output/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { fn } from "./libs/pkg/src/index.js";
console.log(fn);
25 changes: 5 additions & 20 deletions crates/swc_ecma_loader/src/resolvers/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,27 +259,12 @@ where
return Ok(FileName::Real(tp.into()));
}

if self.base_url_filename == *base {
// Prevent infinite loop

let replaced = self.base_url.join(&to[0]);
if replaced.exists() {
return Ok(FileName::Real(replaced));
}

return self
.invoke_inner_resolver(base, &format!("./{}", &to[0]))
.with_context(|| {
format!(
"tried to resolve `{}` because `{}` was exactly matched",
to[0], from
)
});
} else {
return self
.resolve(&self.base_url_filename, &format!("./{}", &to[0]))
.context("failed to resolve using jsc.baseUrl as base");
if let Ok(res) = self.resolve(&self.base_url_filename, &format!("./{}", &to[0]))
{
return Ok(res);
}

return Ok(FileName::Real(self.base_url.join(&to[0])));
}
}
}
Expand Down